ソースを参照

1.의료진 메뉴얼 교체, 2.환자리스트 엑셀다운로드 추가(테스트)

huiwon.seo 4 年 前
コミット
a9e16322ee

+ 13 - 0
pom.xml

@@ -112,6 +112,19 @@
             <artifactId>json-simple</artifactId>
             <version>1.1</version>
         </dependency>
+        
+        <!-- 엑셀 제어(xls) maven setting -->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>3.12</version>
+        </dependency>
+        <!-- 엑셀 제어(xlsx) maven setting-->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>3.9</version>
+        </dependency>
 	</dependencies>
 
 	<build>

+ 72 - 0
src/main/java/com/lemon/lifecenter/common/LifeCenterFileDownload.java

@@ -0,0 +1,72 @@
+package com.lemon.lifecenter.common;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.util.FileCopyUtils;
+
+public class LifeCenterFileDownload {
+//    protected static Log downloadLog = LogFactory.getLog("fileDownload");
+
+    public LifeCenterFileDownload() {}
+
+    public static void download(HttpServletRequest request, HttpServletResponse response, String path, String downName) {
+        try {
+//            downloadLog.info("DownloadPath : " + path);
+
+            if( path.trim().equals( "" ) ) {
+                throw new Exception( "file not found" );
+            } else {
+                File file = new File(path);
+
+                if (file.exists()) {
+                    int fileSize = (int) file.length();
+
+                    downName = downName.replace(" ", "_");
+                    response.setContentType("apllication/download; charset=utf-8");
+                    response.setContentLength(fileSize);
+                    response.setHeader("Content-Transfer-Encoding", "binary");
+                    response.setHeader("Content-Disposition",
+                            "attachment; filename=\"" + java.net.URLEncoder.encode(downName, "utf-8") + "\";");
+
+                    OutputStream os = response.getOutputStream();
+                    FileInputStream is = new FileInputStream(file);
+
+                    FileCopyUtils.copy(is, os);
+
+                    is.close();
+                    os.flush();
+                    os.close();
+                } else {
+                    throw new Exception("file not found");
+                }
+            }
+        } catch (FileNotFoundException e) {
+            alertNotFound(response);
+        } catch (IOException e) {
+            alertNotFound(response);
+        } catch (Exception e) {
+            alertNotFound(response);
+        }
+    }
+
+    private static void alertNotFound(HttpServletResponse response) {
+        response.setContentType("text/html; charset=UTF-8");
+        PrintWriter out;
+
+        try {
+            out = response.getWriter();
+            out.println("<script>alert('삭제되거나 존재하지 않는 파일 입니다.');self.close();</script>");
+            out.flush();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 256 - 8
src/main/java/com/lemon/lifecenter/controller/PatientController.java

@@ -1,5 +1,10 @@
 package com.lemon.lifecenter.controller;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -7,6 +12,16 @@ import java.util.List;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -23,6 +38,7 @@ import org.springframework.web.servlet.ModelAndView;
 
 import com.lemon.lifecenter.common.LifeCenterConfigVO;
 import com.lemon.lifecenter.common.LifeCenterController;
+import com.lemon.lifecenter.common.LifeCenterFileDownload;
 import com.lemon.lifecenter.common.LifeCenterFunction;
 import com.lemon.lifecenter.common.LifeCenterPaging;
 import com.lemon.lifecenter.common.LifeCenterSessionController;
@@ -31,6 +47,7 @@ import com.lemon.lifecenter.dto.PatientDTO;
 import com.lemon.lifecenter.service.CenterService;
 import com.lemon.lifecenter.service.PatientService;
 
+
 @Controller
 @RequestMapping("/patient")
 //@DependsOn(value = {"LifeCenterPaging"})
@@ -49,9 +66,6 @@ public class PatientController extends LifeCenterController {
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     @RequestMapping("/list")
-//    @ModelAttribute("dto") final ASiboDTO dto,
-//    @RequestParam( value="k", required=true ) String k
-//    @RequestParam( value="type", required=false, defaultValue="" ) String type
     public ModelAndView patientList(
             @RequestParam(value="inputState", required=false, defaultValue="ALL") String inputState,
             @RequestParam(value="patientName", required=false, defaultValue="") String patientName,
@@ -90,15 +104,10 @@ public class PatientController extends LifeCenterController {
         
         ModelAndView mv = setMV("patient/list");
         
-        System.out.println( "PatientController config.pageGroupSize : " + config.pageGroupSize );
-        
         String param = "patientName=" + patientName + "&inputState=" + inputState + "&startDate=" + startDate + "&endDate=" + endDate;
         paging = LifeCenterPaging.getInstance();
         paging.paging(config, total, page, param);
         
-//        startDate = startDate.equals( "" ) ? LifeCenterFunction.getNow( "yyyy-MM-dd" ) : startDate;
-//        endDate   = endDate.equals( "" )   ? LifeCenterFunction.getNow( "yyyy-MM-dd" ) : endDate;
-        
         mv.addObject("inputState", inputState);
         mv.addObject("patientName", patientName);
         mv.addObject("total", total);
@@ -415,4 +424,243 @@ public class PatientController extends LifeCenterController {
         return object.toString();
     }
     
+    
+    
+    @RequestMapping( value="/excel", method=RequestMethod.POST )
+    public void getPatientList(
+          @RequestParam(value="inputState", required=false, defaultValue="ALL") String inputState,
+          @RequestParam(value="patientName", required=false, defaultValue="") String patientName,
+          @RequestParam(value="startDate", required=false, defaultValue="") String startDate,
+          @RequestParam(value="endDate", required=false, defaultValue="") String endDate,
+          @RequestParam(value="page", required=false, defaultValue="1") int page,
+          HttpServletRequest request,HttpServletResponse response ) {
+      
+        String sesCenterCode = LifeCenterSessionController.getSession(request, "sesCenterCode");
+        String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
+
+        // 권한이 SYSTEM일경우
+
+        PatientDTO dto = new PatientDTO();
+
+        dto.setCenterCode(Integer.parseInt(sesCenterCode));
+        dto.setGroupIdx(Integer.valueOf(sesGroupIdx));
+        dto.setPatientName(patientName);
+        dto.setState(inputState);
+        dto.setStartDate(startDate);
+        dto.setEndDate(endDate);
+
+        int total = patientService.selectPatientCount(dto);
+        List<PatientDTO> result = new ArrayList<PatientDTO>();
+
+        if (total > 0) {
+            dto.setLimit( 1 );
+            dto.setLimitMax( total );
+            
+            result = patientService.selectPatietList(dto);
+
+            for (PatientDTO temp : result) {
+                result.get(result.indexOf(temp)).setSymptomContent(LifeCenterFunction.getSymptom(temp));
+            }
+        }
+        
+        getPatientListExcel(request, response, result );
+    }
+    
+    
+    private void getPatientListExcel(HttpServletRequest request, HttpServletResponse response, List<PatientDTO> data ) {
+        Workbook workbook = new XSSFWorkbook();
+        Sheet sheet1 = workbook.createSheet("firstSheet");
+        DecimalFormat df = new DecimalFormat("#,###");
+
+        //1.셀 스타일 및 폰트 설정
+        CellStyle styleOfBoardFillFontBlackBold16 = workbook.createCellStyle();
+        //정렬
+        styleOfBoardFillFontBlackBold16.setAlignment(CellStyle.ALIGN_CENTER); //가운데 정렬
+        styleOfBoardFillFontBlackBold16.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //높이 가운데 정렬
+        //배경색
+        styleOfBoardFillFontBlackBold16.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
+        styleOfBoardFillFontBlackBold16.setFillPattern(CellStyle.SOLID_FOREGROUND);
+        //테두리 선 (우,좌,위,아래)
+        styleOfBoardFillFontBlackBold16.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        styleOfBoardFillFontBlackBold16.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        styleOfBoardFillFontBlackBold16.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        styleOfBoardFillFontBlackBold16.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        //폰트 설정
+        Font fontOfGothicBlackBold16 = workbook.createFont();
+//        fontOfGothicBlackBold16.setFontName("나눔고딕"); //글씨체
+        fontOfGothicBlackBold16.setFontHeight((short)(10*20)); //사이즈
+        fontOfGothicBlackBold16.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
+        styleOfBoardFillFontBlackBold16.setFont(fontOfGothicBlackBold16);
+        
+        int i = 1;
+        Row row = sheet1.createRow(0);
+        Cell cell1 = row.createCell(0);
+        Cell cell2 = row.createCell(1);
+        Cell cell3 = row.createCell(2);
+        Cell cell4 = row.createCell(3);
+        Cell cell5 = row.createCell(4);
+        Cell cell6 = row.createCell(5);
+        Cell cell7 = row.createCell(6);
+        Cell cell8 = row.createCell(7);
+        Cell cell9 = row.createCell(8);
+        Cell cell10 = row.createCell(9);
+        Cell cell11 = row.createCell(10);
+        Cell cell12 = row.createCell(11);
+        Cell cell13 = row.createCell(12);
+        Cell cell14 = row.createCell(13);
+
+        cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell8.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell9.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell10.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell11.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell12.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell13.setCellStyle(styleOfBoardFillFontBlackBold16);
+        cell14.setCellStyle(styleOfBoardFillFontBlackBold16);
+        
+        
+        sheet1.setColumnWidth( 0, 5000); //센터명
+        sheet1.setColumnWidth( 1, 3000); //환자명
+        sheet1.setColumnWidth( 2, 4000); //동호실
+        sheet1.setColumnWidth( 3, 1500); //성별
+        sheet1.setColumnWidth( 4, 1500); //나이
+        sheet1.setColumnWidth( 5, 3500); //입소일자
+        sheet1.setColumnWidth( 6, 3500); //상태변경일
+        sheet1.setColumnWidth( 7, 3800); //상태
+        sheet1.setColumnWidth( 8, 6000); //체온
+        sheet1.setColumnWidth( 9, 10000); //혈압
+        sheet1.setColumnWidth( 10, 6200); //맥박
+        sheet1.setColumnWidth( 11, 6200); //산소포화도
+        sheet1.setColumnWidth( 12, 7000); //혈당
+        sheet1.setColumnWidth( 13, 14000); //임상증상
+        
+        
+        cell1.setCellValue("생활치료센터명");
+        cell2.setCellValue("환자명");
+        cell3.setCellValue("동,호실");
+        cell4.setCellValue("성별");
+        cell5.setCellValue("나이");
+        cell6.setCellValue("입소일자");
+        cell7.setCellValue("상태 변경일");
+        cell8.setCellValue("상태");
+        cell9.setCellValue("체온");
+        cell10.setCellValue("혈압");
+        cell11.setCellValue("맥박");
+        cell12.setCellValue("산소포화도");
+        cell13.setCellValue("혈당");
+        cell14.setCellValue("임상증상");
+        
+        for (PatientDTO dto : data) {
+            row = sheet1.createRow(i);
+            cell1 = row.createCell(0);
+            cell2 = row.createCell(1);
+            cell3 = row.createCell(2);
+            cell4 = row.createCell(3);
+            cell5 = row.createCell(4);
+            cell6 = row.createCell(5);
+            cell7 = row.createCell(6);
+            cell8 = row.createCell(7);
+            cell9 = row.createCell(8);
+            cell10 = row.createCell(9);
+            cell11 = row.createCell(10);
+            cell12 = row.createCell(11);
+            cell13 = row.createCell(12);
+            cell14 = row.createCell(13);
+            
+            String patientName = dto.getPatientName();
+            String roomWard    = ( dto.getRoomNumber() == null || dto.getRoomNumber().equals( "" ) ) ? "" : dto.getRoomNumber()+"동 ";
+            roomWard += ( dto.getWardNumber() == null || dto.getWardNumber().equals( "" ) ) ? "" : dto.getWardNumber()+"호";
+            
+            String gender      = dto.getGender();
+            String age         = dto.getAge();
+            
+            String hospitalizationDate = dto.getHospitalizationDate();
+            String disisolationDate    = dto.getDisisolationDate();
+            String state               = dto.getState();
+            
+            String temperature                      = dto.getTemperature();
+            String temperatureCreateDate            = dto.getTemperatureCreateDate();
+            
+            String systolicBloodPressure            = dto.getSystolicBloodPressure();
+            String systolicBloodPressureCreateDate  = dto.getSystolicBloodPressureCreateDate();
+            
+            String diastolicBloodPressure           = dto.getDiastolicBloodPressure();
+            String diastolicBloodPressureCreateDate = dto.getDiastolicBloodPressureCreateDate();
+            
+            String pulseRate                        = dto.getPulseRate();
+            String pulseRateCreateDate              = dto.getPulseRateCreateDate();
+            
+            String oxygenSaturation                 = dto.getOxygenSaturation();
+            String oxygenSaturationCreateDate       = dto.getOxygenSaturationCreateDate();
+            
+            String bloodSugar                       = dto.getBloodSugar();
+            String bloodSugarCreateDate             = dto.getBloodSugarCreateDate();
+            
+            String notMeasured = "-";
+            String symptomDate = dto.getCreateDate();
+            String symptomContent = dto.getSymptomContent();
+//            String symptom = LifeCenterFunction.getSymptom( dto );
+            String centerName = dto.getCenterName();
+            
+            cell1.setCellValue( centerName );
+            cell2.setCellValue( patientName );
+            cell3.setCellValue( roomWard );
+            cell4.setCellValue( gender );
+            cell5.setCellValue( age );
+            cell6.setCellValue( hospitalizationDate );
+            cell7.setCellValue( disisolationDate );
+            cell8.setCellValue( state );
+            cell9.setCellValue( ( temperature == null || temperature.equals("") ) ? notMeasured : temperature + " ˚C (" + temperatureCreateDate + ")" );
+            cell10.setCellValue( ( systolicBloodPressure == null || systolicBloodPressure.equals("") ) ? notMeasured : systolicBloodPressure + " mmHg / " + diastolicBloodPressure + " mmHg (" + systolicBloodPressureCreateDate + ")" );
+            cell11.setCellValue( ( pulseRate == null || pulseRate.equals("") ) ? notMeasured : pulseRate + " bpm (" + pulseRateCreateDate + ")" );
+            cell12.setCellValue( ( oxygenSaturation == null || oxygenSaturation.equals("") ) ? notMeasured : oxygenSaturation + " % (" + oxygenSaturationCreateDate + ")" );
+            cell13.setCellValue( ( bloodSugar == null || bloodSugar.equals("") ) ? notMeasured : bloodSugar + " mg/dL (" + bloodSugarCreateDate + ")" );
+            cell14.setCellValue( ( symptomContent == null || symptomDate == null || symptomContent.equals("")  || symptomDate.equals( "" ) ) ? notMeasured : symptomContent + " (" + symptomDate + ")" );
+
+            i++;
+        }
+
+        row = sheet1.createRow(i);
+        cell1 = row.createCell(2);
+        cell2 = row.createCell(3);
+        cell3 = row.createCell(4);
+        cell4 = row.createCell(5);
+        cell5 = row.createCell(6);
+        cell6 = row.createCell(7);
+        cell7 = row.createCell(8);
+        cell8 = row.createCell(9);
+        cell9 = row.createCell(10);
+        cell10 = row.createCell(11);
+        cell11 = row.createCell(12);
+        cell12 = row.createCell(13);
+        cell13 = row.createCell(14);
+        cell14 = row.createCell(15);
+        
+        try {
+            File file = new File(".");
+            String rootPath = file.getAbsolutePath();
+            System.out.println("현재 프로젝트의 경로 : "+rootPath );
+
+            String tempPath = "../excel-temp/testExcel.xlsx";
+            String downName = LifeCenterFunction.getNow() + " 환자리스트.xlsx";
+            File xlsFile = new File(tempPath);
+            FileOutputStream fileOut = new FileOutputStream(xlsFile);
+            workbook.write(fileOut);
+
+            LifeCenterFileDownload.download(request, response, tempPath, downName);
+
+            xlsFile.delete();
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    
 }

+ 15 - 0
src/main/webapp/WEB-INF/jsp/patient/list.jsp

@@ -101,6 +101,20 @@ $(function() {
         $("input[name='endDate']").val( endDate );
     }
 });
+
+function getExcel(){
+    var newForm = $( "#searchForm" ).clone();
+    
+    newForm.attr( "id", "excelForm" );
+    newForm.attr( "method", "post" );
+    newForm.attr( "action", "./excel" );
+    newForm.attr( "target", "_blank" );
+    newForm.hide();
+    
+    $( document.body ).append( newForm );
+    newForm.submit();
+    $( "#excelForm" ).remove();
+}
 </script>
 <style>
 /* tr.phr-info td{vertical-align:top !important;} */
@@ -199,6 +213,7 @@ tr.phr-info td span.no-data{color:#999999;}
                                             <fmt:formatNumber value="${total}" pattern="#,###" />
                                         </div>
                                         <div class="col-6 text-right">
+                                            <button class="btn btn-success" onclick="getExcel();" style="display:none;">Excel 다운로드</button>
                                             <a class="btn btn-primary" target="_blank" href="/store/manual/survey">입소자 문진표 서식 다운로드</a>
                                             <c:if test="${sesGroupIdx ne '1'}">
                                                 <button class="btn btn-primary" onclick="location.href='./new';">신규환자등록</button>

BIN
src/main/webapp/resources/download/manual/manual_staff.pdf


+ 46 - 19
src/main/webapp/resources/js/common/common.js

@@ -34,7 +34,7 @@ $(function(){
     }, "1900-01-01 이전 날짜는 입력하실 수 없습니다." );
     
     $.validator.addMethod( "maxDate",  function( value, element ) {
-        return (this.optional(element) || new Date(value) <= new Date()) && ( this.optional(element) || /[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/.test(value) );
+        return ( this.optional(element) || new Date(value).format("yyyy-MM-dd") <= new Date().format("yyyy-MM-dd") ) && ( this.optional(element) || /[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/.test(value) );
     }, "현재보다 미래 날짜는 입력하실 수 없습니다." );
     
     $("form input:text").keydown(function(evt) {
@@ -44,23 +44,6 @@ $(function(){
     });
 });
 
-function getNowYmd(){
-    var date = new Date(); 
-    var year = date.getFullYear(); 
-    var month = new String(date.getMonth()+1); 
-    var day = new String(date.getDate()); 
-    
-    // 한자리수일 경우 0을 채워준다. 
-    if(month.length == 1){ 
-      month = "0" + month; 
-    }
-     
-    if(day.length == 1){ 
-      day = "0" + day; 
-    } 
-    return year + "-" + month + "-" + day;
-}
-
 function getAjax( url, vv, success, error, done ){
   $.ajax({
     url      : url,
@@ -243,4 +226,48 @@ function inputYMDNumber(obj) {
     } else {
         return false;
     }
-}
+}
+
+function getNowYmd(){
+    var date = new Date(); 
+    var year = date.getFullYear(); 
+    var month = new String(date.getMonth()+1); 
+    var day = new String(date.getDate()); 
+    
+    // 한자리수일 경우 0을 채워준다. 
+    if(month.length == 1){ 
+      month = "0" + month; 
+    }
+     
+    if(day.length == 1){ 
+      day = "0" + day; 
+    } 
+    return year + "-" + month + "-" + day;
+}
+
+Date.prototype.format = function(f) {
+    if (!this.valueOf()) return " ";
+ 
+    var weekName = ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"];
+    var d = this;
+     
+    return f.replace(/(yyyy|yy|MM|dd|E|hh|mm|ss|a\/p)/gi, function($1) {
+        switch ($1) {
+            case "yyyy": return d.getFullYear();
+            case "yy": return (d.getFullYear() % 1000).zf(2);
+            case "MM": return (d.getMonth() + 1).zf(2);
+            case "dd": return d.getDate().zf(2);
+            case "E": return weekName[d.getDay()];
+            case "HH": return d.getHours().zf(2);
+            case "hh": return ((h = d.getHours() % 12) ? h : 12).zf(2);
+            case "mm": return d.getMinutes().zf(2);
+            case "ss": return d.getSeconds().zf(2);
+            case "a/p": return d.getHours() < 12 ? "오전" : "오후";
+            default: return $1;
+        }
+    });
+};
+ 
+String.prototype.string = function(len){var s = '', i = 0; while (i++ < len) { s += this; } return s;};
+String.prototype.zf = function(len){return "0".string(len - this.length) + this;};
+Number.prototype.zf = function(len){return this.toString().zf(len);};