|
@@ -1,10 +1,27 @@
|
|
|
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.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
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.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -18,6 +35,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import com.lemon.lifecenter.common.LifeCenterController;
|
|
|
+import com.lemon.lifecenter.common.LifeCenterFileDownload;
|
|
|
import com.lemon.lifecenter.common.LifeCenterFunction;
|
|
|
import com.lemon.lifecenter.common.LifeCenterSessionController;
|
|
|
import com.lemon.lifecenter.dto.LoginDTO;
|
|
@@ -142,6 +160,30 @@ public class ClinicController extends LifeCenterController {
|
|
|
return mv;
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping("/excel")
|
|
|
+ public void getPatientList(
|
|
|
+ @RequestParam(value="phrType", required=true, defaultValue="temperature") String phrType,
|
|
|
+ @RequestParam(value="patientIdx", required=true, defaultValue="") int patientIdx,
|
|
|
+ HttpServletRequest request, HttpServletResponse response ) {
|
|
|
+
|
|
|
+ PatientDTO patientDto = new PatientDTO();
|
|
|
+ patientDto.setPatientIdx(patientIdx);
|
|
|
+ patientDto = patientService.selectPatientOne(patientDto);
|
|
|
+
|
|
|
+ PatientPHRHistoryDTO dto = new PatientPHRHistoryDTO();
|
|
|
+ dto.setPhrType(phrType);
|
|
|
+ dto.setPatientIdx(patientIdx);
|
|
|
+
|
|
|
+ int total = phrService.selectPHRHistoryCount(dto);
|
|
|
+ List<PatientPHRHistoryDTO> result = new ArrayList<PatientPHRHistoryDTO>();
|
|
|
+
|
|
|
+ if (total > 0) {
|
|
|
+ result = phrService.selectPHRHistoryList(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ getPhrDataListExcel(request, response, patientDto, phrType, result);
|
|
|
+ }
|
|
|
+
|
|
|
@RequestMapping("/api/state")
|
|
|
public @ResponseBody List<PatientPHRLatestDTO> state(HttpServletRequest request,
|
|
|
@RequestParam(value = "page", required = true, defaultValue = "1") int page,
|
|
@@ -264,4 +306,149 @@ public class ClinicController extends LifeCenterController {
|
|
|
return json.toString();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void getPhrDataListExcel(HttpServletRequest request, HttpServletResponse response, PatientDTO patientDto, String phrType, List<PatientPHRHistoryDTO> 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);
|
|
|
+
|
|
|
+ cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
|
|
|
+ cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
|
|
|
+ cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
|
|
|
+ cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
|
|
|
+
|
|
|
+ sheet1.setColumnWidth( 0, 5000); //환자명
|
|
|
+ sheet1.setColumnWidth( 1, 5000); //기록일시
|
|
|
+ sheet1.setColumnWidth( 2, 3000); //값
|
|
|
+ sheet1.setColumnWidth( 3, 4000); //기록자
|
|
|
+
|
|
|
+ cell1.setCellValue("환자명");
|
|
|
+ cell2.setCellValue("기록일시");
|
|
|
+ if (phrType.equals("temperature")) {
|
|
|
+ cell3.setCellValue("체온");
|
|
|
+ }
|
|
|
+ else if (phrType.equals("bloodPressure")) {
|
|
|
+ cell3.setCellValue("혈압");
|
|
|
+ }
|
|
|
+ else if (phrType.equals("oxygenSaturation")) {
|
|
|
+ cell3.setCellValue("산소포화도");
|
|
|
+ }
|
|
|
+ else if (phrType.equals("pulseRate")) {
|
|
|
+ cell3.setCellValue("맥박");
|
|
|
+ }
|
|
|
+ else if (phrType.equals("bloodSugar")) {
|
|
|
+ cell3.setCellValue("혈당");
|
|
|
+ }
|
|
|
+ cell4.setCellValue("기록자");
|
|
|
+
|
|
|
+ for (PatientPHRHistoryDTO dto : data) {
|
|
|
+ row = sheet1.createRow(i);
|
|
|
+ cell1 = row.createCell(0);
|
|
|
+ cell2 = row.createCell(1);
|
|
|
+ cell3 = row.createCell(2);
|
|
|
+ cell4 = row.createCell(3);
|
|
|
+
|
|
|
+ // 일시
|
|
|
+ String createDate = null;
|
|
|
+ SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ try {
|
|
|
+ Date t = originalFormat.parse(dto.getCreateDate());
|
|
|
+ createDate = targetFormat.format(t);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ createDate = dto.getCreateDate();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 값
|
|
|
+ String phrValue = "";
|
|
|
+ String phrValue2 = "";
|
|
|
+ if (phrType.equals("temperature")) {
|
|
|
+ phrValue = String.format("%.1f", dto.getPhrValue());
|
|
|
+ phrValue2 = String.format("%.1f", dto.getPhrValue2());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ phrValue = String.format("%.0f", dto.getPhrValue());
|
|
|
+ phrValue2 = String.format("%.0f", dto.getPhrValue2());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 기록자
|
|
|
+ String recordedByName = dto.getRecordedByName();
|
|
|
+
|
|
|
+ cell1.setCellValue( patientDto.getPatientName() );
|
|
|
+ cell2.setCellValue( createDate );
|
|
|
+ if (phrType.equals("bloodPressure")) {
|
|
|
+ cell3.setCellValue( phrValue + "/" + phrValue2 );
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ cell3.setCellValue( phrValue );
|
|
|
+ }
|
|
|
+ cell4.setCellValue( recordedByName );
|
|
|
+
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+
|
|
|
+ row = sheet1.createRow(i);
|
|
|
+ cell1 = row.createCell(2);
|
|
|
+ cell2 = row.createCell(3);
|
|
|
+ cell3 = row.createCell(4);
|
|
|
+ cell4 = row.createCell(4);
|
|
|
+
|
|
|
+ try {
|
|
|
+// File file = new File(".");
|
|
|
+// String rootPath = file.getAbsolutePath();
|
|
|
+// System.out.println("현재 프로젝트의 경로 : "+rootPath );
|
|
|
+
|
|
|
+ // JBOSS에서 구동시 /home1/jboss/jboss-eap-7.3/domain/test/excel-temp 경로에 저장이됨
|
|
|
+ String directoryName = "../excel-temp/";
|
|
|
+ File directory = new File(directoryName);
|
|
|
+ if (! directory.exists()) {
|
|
|
+ directory.mkdir();
|
|
|
+ }
|
|
|
+
|
|
|
+ String timestamp = LifeCenterFunction.getNow("yyyyMMdd_HHmmss");
|
|
|
+ String downName = Integer.toString(patientDto.getPatientIdx()) + "_" + phrType + "_" + timestamp + ".xlsx";
|
|
|
+ String tempPath = directoryName + downName;
|
|
|
+
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|