ClinicController.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. package com.lemon.lifecenter.controller;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import java.util.List;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import org.apache.poi.hssf.usermodel.HSSFCellStyle;
  13. import org.apache.poi.ss.usermodel.Cell;
  14. import org.apache.poi.ss.usermodel.CellStyle;
  15. import org.apache.poi.ss.usermodel.Font;
  16. import org.apache.poi.ss.usermodel.IndexedColors;
  17. import org.apache.poi.ss.usermodel.Row;
  18. import org.apache.poi.ss.usermodel.Sheet;
  19. import org.apache.poi.ss.usermodel.Workbook;
  20. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  21. import org.json.JSONObject;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Controller;
  26. import org.springframework.web.bind.annotation.ModelAttribute;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RequestMethod;
  29. import org.springframework.web.bind.annotation.RequestParam;
  30. import org.springframework.web.bind.annotation.ResponseBody;
  31. import org.springframework.web.servlet.ModelAndView;
  32. import com.lemon.lifecenter.common.LifeCenterController;
  33. import com.lemon.lifecenter.common.LifeCenterFileDownload;
  34. import com.lemon.lifecenter.common.LifeCenterFunction;
  35. import com.lemon.lifecenter.common.LifeCenterSessionController;
  36. import com.lemon.lifecenter.dto.PatientDTO;
  37. import com.lemon.lifecenter.dto.PatientMemoDTO;
  38. import com.lemon.lifecenter.dto.PatientPHRHistoryDTO;
  39. import com.lemon.lifecenter.dto.PatientPHRLatestDTO;
  40. import com.lemon.lifecenter.dto.PatientSymptomSimDTO;
  41. import com.lemon.lifecenter.service.ClinicService;
  42. import com.lemon.lifecenter.service.PHRService;
  43. import com.lemon.lifecenter.service.PatientService;
  44. @Controller
  45. @RequestMapping("/clinic")
  46. public class ClinicController extends LifeCenterController {
  47. @Autowired
  48. private ClinicService clinicService;
  49. @Autowired
  50. private PHRService phrService;
  51. @Autowired
  52. private PatientService patientService;
  53. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  54. @RequestMapping("/state")
  55. public ModelAndView clinicState(HttpServletRequest request,
  56. @RequestParam(value = "page", required = true, defaultValue = "1") int page,
  57. @RequestParam(value = "size", required = true, defaultValue = "30") int pageSize,
  58. @RequestParam(value = "searchText", required = false, defaultValue = "") String searchText) {
  59. String centerCode = LifeCenterSessionController.getSession( request, "sesCenterCode" );
  60. PatientPHRLatestDTO dto = new PatientPHRLatestDTO();
  61. dto.setLimit((Integer.valueOf(page) - 1) * pageSize);
  62. dto.setLimitMax(pageSize);
  63. dto.setCenterCode(centerCode);
  64. dto.setSearchText(searchText);
  65. int total = clinicService.selectPHRLatestCount(dto);
  66. // 서버사이드 렌더링 안함
  67. // List<PatientPHRLatestDTO> result = new ArrayList<PatientPHRLatestDTO>();
  68. //
  69. // if (total > 0) {
  70. // result = clinicService.selectPHRLatestList(dto);
  71. // }
  72. ModelAndView mv = setMV("clinic/state");
  73. mv.addObject("page", page);
  74. mv.addObject("searchText", searchText);
  75. mv.addObject("total", total);
  76. // mv.addObject("items", result);
  77. return mv;
  78. }
  79. @RequestMapping("/info")
  80. public ModelAndView patientInfo(
  81. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx,
  82. @RequestParam(value = "refererSearch", required = false, defaultValue = "") String refererSearch,
  83. @RequestParam(value = "refererPage", required = false, defaultValue = "") String refererPage) {
  84. // 환자정보
  85. PatientDTO patientDto = new PatientDTO();
  86. patientDto.setPatientIdx(patientIdx);
  87. patientDto = patientService.selectPatientOne(patientDto);
  88. String jumin = patientDto.getJumin();
  89. jumin = LifeCenterFunction.changeJuminToBirthday(jumin);
  90. patientDto.setJumin(jumin);
  91. patientDto.setPatientPhone(LifeCenterFunction.phone(patientDto.getPatientPhone()));
  92. patientDto.setGuardianPhone(LifeCenterFunction.phone(patientDto.getGuardianPhone()));
  93. String bloodPress = patientDto.getBloodPressureLevel();
  94. if (!bloodPress.equals("") && !bloodPress.equals("|")) {
  95. String[] bloodPressureLevel = bloodPress.split("[|]");
  96. if (bloodPressureLevel[0] != null) {
  97. patientDto.setBloodPressureLevelCon(bloodPressureLevel[0]);
  98. }
  99. if (bloodPressureLevel[1] != null) {
  100. patientDto.setBloodPressureLevelRel(bloodPressureLevel[1]);
  101. }
  102. }
  103. String strDisease = "";
  104. String strSymptom = LifeCenterFunction.getSymptom(patientDto);
  105. if (patientDto.getBasalDiseaseYn().equals("Y")) {
  106. strDisease = LifeCenterFunction.getDisease(patientDto);
  107. }
  108. // 히스토리 데이터
  109. PatientPHRHistoryDTO dto = new PatientPHRHistoryDTO();
  110. dto.setPatientIdx(patientIdx);
  111. // 체온
  112. dto.setPhrType("temperature");
  113. List<PatientPHRHistoryDTO> temperatureResult = phrService.selectPHRHistoryList(dto);
  114. // 혈압
  115. dto.setPhrType("bloodPressure");
  116. List<PatientPHRHistoryDTO> bloodPressureResult = phrService.selectPHRHistoryList(dto);
  117. // 맥박
  118. dto.setPhrType("pulseRate");
  119. List<PatientPHRHistoryDTO> pulseRateResult = phrService.selectPHRHistoryList(dto);
  120. // 산소포화도
  121. dto.setPhrType("oxygenSaturation");
  122. List<PatientPHRHistoryDTO> oxygenSaturationResult = phrService.selectPHRHistoryList(dto);
  123. // 혈당
  124. dto.setPhrType("bloodSugar");
  125. List<PatientPHRHistoryDTO> bloodSugarResult = phrService.selectPHRHistoryList(dto);
  126. // 증상
  127. PatientSymptomSimDTO dto2 = new PatientSymptomSimDTO();
  128. dto2.setPatientIdx(patientIdx);
  129. List<PatientSymptomSimDTO> symptomResult = phrService.selectSymptomList(dto2);
  130. // 메모
  131. PatientMemoDTO dto3 = new PatientMemoDTO();
  132. dto3.setPatientIdx(patientIdx);
  133. List<PatientMemoDTO> memoResult = clinicService.selectMemoList(dto3);
  134. // response
  135. List<PatientPHRHistoryDTO> bloodPressureUnionResult = getBloodPressureUnionResult(patientIdx, bloodPressureResult, pulseRateResult);
  136. ModelAndView mv = setMV("clinic/info");
  137. mv.addObject("patientIdx", patientIdx);
  138. mv.addObject("info", patientDto);
  139. mv.addObject("symptom", strSymptom);
  140. mv.addObject("disease", strDisease);
  141. mv.addObject("temperatureResult", temperatureResult);
  142. mv.addObject("bloodPressureResult", bloodPressureResult);
  143. mv.addObject("pulseRateResult", pulseRateResult);
  144. mv.addObject("bloodPressureUnionResult", bloodPressureUnionResult);
  145. mv.addObject("oxygenSaturationResult", oxygenSaturationResult);
  146. mv.addObject("bloodSugarResult", bloodSugarResult);
  147. mv.addObject("symptomResult", symptomResult);
  148. mv.addObject("memoResult", memoResult);
  149. mv.addObject("refererSearch", refererSearch);
  150. mv.addObject("refererPage", refererPage);
  151. return mv;
  152. }
  153. @RequestMapping("/api/state")
  154. public @ResponseBody String getStateAPI(HttpServletRequest request,
  155. @RequestParam(value = "page", required = true, defaultValue = "1") int page,
  156. @RequestParam(value = "size", required = true, defaultValue = "30") int pageSize,
  157. @RequestParam(value = "searchText", required = false, defaultValue = "") String searchText) {
  158. String centerCode = LifeCenterSessionController.getSession( request, "sesCenterCode" );
  159. PatientPHRLatestDTO dto = new PatientPHRLatestDTO();
  160. dto.setLimit((Integer.valueOf(page) - 1) * pageSize);
  161. dto.setLimitMax(pageSize);
  162. dto.setCenterCode(centerCode);
  163. dto.setSearchText(searchText);
  164. int total = clinicService.selectPHRLatestCount(dto);
  165. List<PatientPHRLatestDTO> result = new ArrayList<PatientPHRLatestDTO>();
  166. if (total > 0) {
  167. result = clinicService.selectPHRLatestList(dto);
  168. }
  169. JSONObject json = new JSONObject();
  170. json.put("count", total);
  171. json.put("items", result);
  172. return json.toString();
  173. }
  174. @RequestMapping("/api/phrDatas")
  175. public @ResponseBody List<PatientPHRHistoryDTO> getPhrDatasAPI(
  176. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx,
  177. @RequestParam(value = "phrType", required = true, defaultValue = "temperature") String phrType) {
  178. PatientPHRHistoryDTO dto = new PatientPHRHistoryDTO();
  179. dto.setPatientIdx(patientIdx);
  180. dto.setPhrType(phrType);
  181. List<PatientPHRHistoryDTO> result = phrService.selectPHRHistoryList(dto);
  182. boolean needPulseRate = phrType.equals("bloodPressure");
  183. if (needPulseRate) {
  184. PatientPHRHistoryDTO dto2 = new PatientPHRHistoryDTO();
  185. dto2.setPatientIdx(patientIdx);
  186. dto2.setPhrType("pulseRate");
  187. List<PatientPHRHistoryDTO> pulseRateResult = phrService.selectPHRHistoryList(dto2);
  188. List<PatientPHRHistoryDTO> bloodPressureUnionResult = getBloodPressureUnionResult(patientIdx, result, pulseRateResult);
  189. return bloodPressureUnionResult;
  190. }
  191. else {
  192. return result;
  193. }
  194. }
  195. @RequestMapping(value = "/api/phrData", method = RequestMethod.POST)
  196. public @ResponseBody String insertPhrDataAPI(@ModelAttribute("dto") final PatientPHRHistoryDTO dto) {
  197. try {
  198. phrService.insertPHR(dto);
  199. if (dto.getPhrValueExtra() != null) {
  200. PatientPHRHistoryDTO pulseRateDto = new PatientPHRHistoryDTO();
  201. pulseRateDto.setPatientIdx(dto.getPatientIdx());
  202. pulseRateDto.setPhrType("pulseRate");
  203. pulseRateDto.setPhrValue(dto.getPhrValueExtra());
  204. pulseRateDto.setRecordedByName(dto.getRecordedByName());
  205. if (dto.getRecordedById() != null) {
  206. pulseRateDto.setRecordedById(dto.getRecordedById());
  207. }
  208. phrService.insertPHR(pulseRateDto);
  209. }
  210. JSONObject json = new JSONObject();
  211. json.put("code", "00");
  212. json.put("message", "");
  213. return json.toString();
  214. } catch (Exception e) {
  215. JSONObject json = new JSONObject();
  216. json.put("code", "01");
  217. json.put("message", e.getLocalizedMessage());
  218. return json.toString();
  219. }
  220. }
  221. @RequestMapping("/api/symptomDatas")
  222. public @ResponseBody List<PatientSymptomSimDTO> getSymptomDatasAPI(
  223. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx) {
  224. PatientSymptomSimDTO dto = new PatientSymptomSimDTO();
  225. dto.setPatientIdx(patientIdx);
  226. return phrService.selectSymptomList(dto);
  227. }
  228. @RequestMapping(value = "/api/symptomData", method = RequestMethod.POST)
  229. public @ResponseBody String insertSymptomDataAPI(@ModelAttribute("dto") final PatientSymptomSimDTO dto) {
  230. try {
  231. phrService.insertSymptom(dto);
  232. JSONObject json = new JSONObject();
  233. json.put("code", "00");
  234. json.put("message", "");
  235. return json.toString();
  236. } catch (Exception e) {
  237. JSONObject json = new JSONObject();
  238. json.put("code", "01");
  239. json.put("message", e.getLocalizedMessage());
  240. return json.toString();
  241. }
  242. }
  243. @RequestMapping("/api/memoDatas")
  244. public @ResponseBody List<PatientMemoDTO> getMemoDatasAPI(
  245. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx) {
  246. PatientMemoDTO dto = new PatientMemoDTO();
  247. dto.setPatientIdx(patientIdx);
  248. return clinicService.selectMemoList(dto);
  249. }
  250. @RequestMapping(value = "/api/memoData", method = RequestMethod.POST)
  251. public @ResponseBody String insertMemoDataAPI(@ModelAttribute("dto") final PatientMemoDTO dto) {
  252. try {
  253. clinicService.insertMemo(dto);
  254. JSONObject json = new JSONObject();
  255. json.put("code", "00");
  256. json.put("message", "");
  257. return json.toString();
  258. } catch (Exception e) {
  259. JSONObject json = new JSONObject();
  260. json.put("code", "01");
  261. json.put("message", e.getLocalizedMessage());
  262. return json.toString();
  263. }
  264. }
  265. @RequestMapping(value = "/api/memoData", method = RequestMethod.DELETE)
  266. public @ResponseBody String deleteMemoDataAPI(@ModelAttribute("dto") final PatientMemoDTO dto) {
  267. try {
  268. clinicService.deleteMemo(dto);
  269. JSONObject json = new JSONObject();
  270. json.put("code", "00");
  271. json.put("message", "");
  272. return json.toString();
  273. } catch (Exception e) {
  274. JSONObject json = new JSONObject();
  275. json.put("code", "01");
  276. json.put("message", e.getLocalizedMessage());
  277. return json.toString();
  278. }
  279. }
  280. @RequestMapping(value = "/api/memoData", method = RequestMethod.PATCH)
  281. public @ResponseBody String updateMemoDataAPI(@ModelAttribute("dto") final PatientMemoDTO dto) {
  282. try {
  283. clinicService.updateMemo(dto);
  284. JSONObject json = new JSONObject();
  285. json.put("code", "00");
  286. json.put("message", "");
  287. return json.toString();
  288. } catch (Exception e) {
  289. JSONObject json = new JSONObject();
  290. json.put("code", "01");
  291. json.put("message", e.getLocalizedMessage());
  292. return json.toString();
  293. }
  294. }
  295. private List<PatientPHRHistoryDTO> getBloodPressureUnionResult(int patientIdx, List<PatientPHRHistoryDTO> bloodPressureResult, List<PatientPHRHistoryDTO>pulseRateResult) {
  296. // 혈압 맥박 정리
  297. int bloodPressureIndex = 0;
  298. int pulseRateIndex = 0;
  299. List<PatientPHRHistoryDTO> bloodPressureUnionResult = new ArrayList<PatientPHRHistoryDTO>();
  300. while (bloodPressureIndex < bloodPressureResult.size() || pulseRateIndex < pulseRateResult.size()) {
  301. PatientPHRHistoryDTO union = new PatientPHRHistoryDTO();
  302. union.setPatientIdx(patientIdx);
  303. union.setPhrType("bloodPressure");
  304. if (bloodPressureIndex == bloodPressureResult.size()) {
  305. PatientPHRHistoryDTO pr = pulseRateResult.get(pulseRateIndex);
  306. union.setCreateDate(pr.getCreateDate());
  307. union.setPhrValueExtra(pr.getPhrValue());
  308. union.setRecordedByName(pr.getRecordedByName());
  309. union.setRecordedById(pr.getRecordedById());
  310. bloodPressureUnionResult.add(union);
  311. pulseRateIndex += 1;
  312. continue;
  313. }
  314. else if (pulseRateIndex == pulseRateResult.size()) {
  315. PatientPHRHistoryDTO bp = bloodPressureResult.get(bloodPressureIndex);
  316. union.setCreateDate(bp.getCreateDate());
  317. union.setPhrValue(bp.getPhrValue());
  318. union.setPhrValue2(bp.getPhrValue2());
  319. union.setRecordedByName(bp.getRecordedByName());
  320. union.setRecordedById(bp.getRecordedById());
  321. bloodPressureUnionResult.add(union);
  322. bloodPressureIndex += 1;
  323. continue;
  324. }
  325. PatientPHRHistoryDTO bp = bloodPressureResult.get(bloodPressureIndex);
  326. PatientPHRHistoryDTO pr = pulseRateResult.get(pulseRateIndex);
  327. int dateDiffer = bp.getCreateDateFormatted().compareTo(pr.getCreateDateFormatted());
  328. if (dateDiffer == 0) {
  329. union.setCreateDate(bp.getCreateDate());
  330. union.setPhrValue(bp.getPhrValue());
  331. union.setPhrValue2(bp.getPhrValue2());
  332. union.setRecordedByName(bp.getRecordedByName());
  333. union.setRecordedById(bp.getRecordedById());
  334. union.setPhrValueExtra(pr.getPhrValue());
  335. bloodPressureIndex += 1;
  336. pulseRateIndex += 1;
  337. }
  338. else if (dateDiffer < 0) {
  339. union.setCreateDate(bp.getCreateDate());
  340. union.setPhrValue(bp.getPhrValue());
  341. union.setPhrValue2(bp.getPhrValue2());
  342. union.setRecordedByName(bp.getRecordedByName());
  343. union.setRecordedById(bp.getRecordedById());
  344. bloodPressureIndex += 1;
  345. }
  346. else if (dateDiffer > 0) {
  347. union.setCreateDate(pr.getCreateDate());
  348. union.setPhrValueExtra(pr.getPhrValue());
  349. union.setRecordedByName(pr.getRecordedByName());
  350. union.setRecordedById(pr.getRecordedById());
  351. pulseRateIndex += 1;
  352. }
  353. bloodPressureUnionResult.add(union);
  354. }
  355. return bloodPressureUnionResult;
  356. }
  357. @RequestMapping("/excel")
  358. public void getExcelFile(
  359. @RequestParam(value="phrType", required=true, defaultValue="temperature") String phrType,
  360. @RequestParam(value="patientIdx", required=true, defaultValue="") int patientIdx,
  361. HttpServletRequest request, HttpServletResponse response ) {
  362. PatientDTO patientDto = new PatientDTO();
  363. patientDto.setPatientIdx(patientIdx);
  364. patientDto = patientService.selectPatientOne(patientDto);
  365. this.createExcel(request, response, patientDto);
  366. }
  367. private void createExcel(HttpServletRequest request, HttpServletResponse response, PatientDTO patientDto) {
  368. Workbook workbook = new XSSFWorkbook();
  369. // 셀 스타일 및 폰트 설정
  370. CellStyle styleOfBoardFillFontBlackBold16 = workbook.createCellStyle();
  371. // 정렬
  372. styleOfBoardFillFontBlackBold16.setAlignment(CellStyle.ALIGN_CENTER); //가운데 정렬
  373. styleOfBoardFillFontBlackBold16.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //높이 가운데 정렬
  374. // 배경색
  375. styleOfBoardFillFontBlackBold16.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
  376. styleOfBoardFillFontBlackBold16.setFillPattern(CellStyle.SOLID_FOREGROUND);
  377. // 테두리 선 (우,좌,위,아래)
  378. styleOfBoardFillFontBlackBold16.setBorderRight(HSSFCellStyle.BORDER_THIN);
  379. styleOfBoardFillFontBlackBold16.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  380. styleOfBoardFillFontBlackBold16.setBorderTop(HSSFCellStyle.BORDER_THIN);
  381. styleOfBoardFillFontBlackBold16.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  382. // 폰트 설정
  383. Font fontOfGothicBlackBold16 = workbook.createFont();
  384. // fontOfGothicBlackBold16.setFontName("나눔고딕"); //글씨체
  385. fontOfGothicBlackBold16.setFontHeight((short)(10*20)); //사이즈
  386. fontOfGothicBlackBold16.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
  387. styleOfBoardFillFontBlackBold16.setFont(fontOfGothicBlackBold16);
  388. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "체온", "temperature");
  389. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "혈압", "bloodPressure");
  390. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "맥박", "pulseRate");
  391. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "산소포화도", "oxygenSaturation");
  392. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "혈당", "bloodSugar");
  393. this.createSymptomSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto);
  394. this.createMemoSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto);
  395. try {
  396. // File file = new File(".");
  397. // String rootPath = file.getAbsolutePath();
  398. // System.out.println("현재 프로젝트의 경로 : "+rootPath );
  399. // JBOSS에서 구동시 /home1/jboss/jboss-eap-7.3/domain/test/excel-temp 경로에 저장이됨
  400. String directoryName = "../excel-temp/";
  401. File directory = new File(directoryName);
  402. if (! directory.exists()) {
  403. directory.mkdir();
  404. }
  405. String timestamp = LifeCenterFunction.getNow("yyyy-MM-dd_HH-mm-ss");
  406. // 다운로드 파일 명: 호실_환자명(생년월일)_건강정보기록_다운로드일시.xlsx
  407. String downName = patientDto.getRoomNumber() + "_" + patientDto.getPatientName() + "(" + patientDto.getJumin() + ")_건강정보기록_" + timestamp + ".xlsx";
  408. String tempPath = directoryName + downName;
  409. File xlsFile = new File(tempPath);
  410. FileOutputStream fileOut = new FileOutputStream(xlsFile);
  411. workbook.write(fileOut);
  412. LifeCenterFileDownload.download(request, response, tempPath, downName);
  413. xlsFile.delete();
  414. } catch (FileNotFoundException e) {
  415. e.printStackTrace();
  416. } catch (IOException e) {
  417. e.printStackTrace();
  418. }
  419. }
  420. private void createPHRSheet(Workbook workbook, CellStyle styleOfBoardFillFontBlackBold16, PatientDTO patientDto, String phrTypeKorean, String phrType) {
  421. PatientPHRHistoryDTO patientPHRHistoryDto = new PatientPHRHistoryDTO();
  422. patientPHRHistoryDto.setPhrType(phrType);
  423. patientPHRHistoryDto.setPatientIdx(patientDto.getPatientIdx());
  424. int total = phrService.selectPHRHistoryCount(patientPHRHistoryDto);
  425. List<PatientPHRHistoryDTO> data = new ArrayList<PatientPHRHistoryDTO>();
  426. if (total > 0) {
  427. data = phrService.selectPHRHistoryList(patientPHRHistoryDto);
  428. }
  429. Sheet sheet1 = workbook.createSheet(phrTypeKorean);
  430. Row row = sheet1.createRow(0);
  431. Cell cell1 = row.createCell(0);
  432. Cell cell2 = row.createCell(1);
  433. Cell cell3 = row.createCell(2);
  434. Cell cell4 = row.createCell(3);
  435. Cell cell5 = row.createCell(4);
  436. Cell cell6 = row.createCell(5);
  437. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  438. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  439. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  440. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  441. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  442. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  443. sheet1.setColumnWidth( 0, 5000); // 환자명
  444. sheet1.setColumnWidth( 1, 5000); // 생년월일
  445. sheet1.setColumnWidth( 2, 5000); // 동, 호실
  446. sheet1.setColumnWidth( 3, 5000); // 기록일시
  447. sheet1.setColumnWidth( 4, 3000); // 값
  448. sheet1.setColumnWidth( 5, 4000); // 기록자
  449. cell1.setCellValue("환자명");
  450. cell2.setCellValue("생년월일");
  451. cell3.setCellValue("동,호실");
  452. cell4.setCellValue("기록일시");
  453. cell5.setCellValue(phrTypeKorean);
  454. cell6.setCellValue("기록자");
  455. // 동,호실
  456. String roomNumber = "";
  457. if (!patientDto.getWardNumber().equals("")) {
  458. roomNumber = patientDto.getWardNumber() + "동";
  459. }
  460. roomNumber += patientDto.getRoomNumber() + "호";
  461. int i = 1;
  462. for (PatientPHRHistoryDTO dto : data) {
  463. row = sheet1.createRow(i);
  464. cell1 = row.createCell(0);
  465. cell2 = row.createCell(1);
  466. cell3 = row.createCell(2);
  467. cell4 = row.createCell(3);
  468. cell5 = row.createCell(4);
  469. cell6 = row.createCell(5);
  470. // 일시
  471. String createDate = null;
  472. SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  473. SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  474. try {
  475. Date t = originalFormat.parse(dto.getCreateDate());
  476. createDate = targetFormat.format(t);
  477. } catch (Exception e) {
  478. createDate = dto.getCreateDate();
  479. }
  480. // 값
  481. String phrValue = "";
  482. String phrValue2 = "";
  483. if (phrType.equals("temperature")) {
  484. phrValue = String.format("%.1f", dto.getPhrValue());
  485. phrValue2 = String.format("%.1f", dto.getPhrValue2());
  486. } else {
  487. phrValue = String.format("%.0f", dto.getPhrValue());
  488. phrValue2 = String.format("%.0f", dto.getPhrValue2());
  489. }
  490. // 기록자
  491. String recordedByName = dto.getRecordedByName();
  492. cell1.setCellValue(patientDto.getPatientName());
  493. cell2.setCellValue(patientDto.getJumin());
  494. cell3.setCellValue(roomNumber);
  495. cell4.setCellValue(createDate);
  496. if (phrType.equals("bloodPressure")) {
  497. cell5.setCellValue(phrValue + "/" + phrValue2);
  498. } else {
  499. cell5.setCellValue(phrValue);
  500. }
  501. cell6.setCellValue(recordedByName);
  502. i++;
  503. }
  504. }
  505. private void createSymptomSheet(Workbook workbook, CellStyle styleOfBoardFillFontBlackBold16, PatientDTO patientDto) {
  506. PatientSymptomSimDTO patientSymptomSimDto = new PatientSymptomSimDTO();
  507. patientSymptomSimDto.setPatientIdx(patientDto.getPatientIdx());
  508. int total = phrService.selectSymptomCount(patientSymptomSimDto);
  509. List<PatientSymptomSimDTO> data = new ArrayList<PatientSymptomSimDTO>();
  510. if (total > 0) {
  511. data = phrService.selectSymptomList(patientSymptomSimDto);
  512. }
  513. Sheet sheet1 = workbook.createSheet("임상증상");
  514. Row row = sheet1.createRow(0);
  515. Cell cell1 = row.createCell(0);
  516. Cell cell2 = row.createCell(1);
  517. Cell cell3 = row.createCell(2);
  518. Cell cell4 = row.createCell(3);
  519. Cell cell5 = row.createCell(4);
  520. Cell cell6 = row.createCell(5);
  521. Cell cell7 = row.createCell(6);
  522. Cell cell8 = row.createCell(7);
  523. Cell cell9 = row.createCell(8);
  524. Cell cell10 = row.createCell(9);
  525. Cell cell11 = row.createCell(10);
  526. Cell cell12 = row.createCell(11);
  527. Cell cell13 = row.createCell(12);
  528. Cell cell14 = row.createCell(13);
  529. Cell cell15 = row.createCell(14);
  530. Cell cell16 = row.createCell(15);
  531. Cell cell17 = row.createCell(16);
  532. Cell cell18 = row.createCell(17);
  533. Cell cell19 = row.createCell(18);
  534. Cell cell20 = row.createCell(19);
  535. Cell cell21 = row.createCell(20);
  536. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  537. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  538. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  539. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  540. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  541. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  542. cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
  543. cell8.setCellStyle(styleOfBoardFillFontBlackBold16);
  544. cell9.setCellStyle(styleOfBoardFillFontBlackBold16);
  545. cell10.setCellStyle(styleOfBoardFillFontBlackBold16);
  546. cell11.setCellStyle(styleOfBoardFillFontBlackBold16);
  547. cell12.setCellStyle(styleOfBoardFillFontBlackBold16);
  548. cell13.setCellStyle(styleOfBoardFillFontBlackBold16);
  549. cell14.setCellStyle(styleOfBoardFillFontBlackBold16);
  550. cell15.setCellStyle(styleOfBoardFillFontBlackBold16);
  551. cell16.setCellStyle(styleOfBoardFillFontBlackBold16);
  552. cell17.setCellStyle(styleOfBoardFillFontBlackBold16);
  553. cell18.setCellStyle(styleOfBoardFillFontBlackBold16);
  554. cell19.setCellStyle(styleOfBoardFillFontBlackBold16);
  555. cell20.setCellStyle(styleOfBoardFillFontBlackBold16);
  556. cell21.setCellStyle(styleOfBoardFillFontBlackBold16);
  557. sheet1.setColumnWidth(0, 5000); // 환자명
  558. sheet1.setColumnWidth(1, 5000); // 생년월일
  559. sheet1.setColumnWidth(2, 5000); // 동호실
  560. sheet1.setColumnWidth(3, 5000); // 기록일시
  561. sheet1.setColumnWidth(4, 3000); // 기침
  562. sheet1.setColumnWidth(5, 3000); // 호흡곤란
  563. sheet1.setColumnWidth(6, 3000); // 오한
  564. sheet1.setColumnWidth(7, 3000); // 근육통
  565. sheet1.setColumnWidth(8, 3000); // 두통
  566. sheet1.setColumnWidth(9, 3000); // 인후통
  567. sheet1.setColumnWidth(10, 3000); // 후각/미각 손실
  568. sheet1.setColumnWidth(11, 3000); // 피로
  569. sheet1.setColumnWidth(12, 3000); // 식욕감소
  570. sheet1.setColumnWidth(13, 3000); // 가래
  571. sheet1.setColumnWidth(14, 3000); // 오심
  572. sheet1.setColumnWidth(15, 3000); // 구토
  573. sheet1.setColumnWidth(16, 3000); // 설사
  574. sheet1.setColumnWidth(17, 3000); // 어지러움
  575. sheet1.setColumnWidth(18, 3000); // 콧물/코막힘
  576. sheet1.setColumnWidth(19, 3000); // 기타증상
  577. sheet1.setColumnWidth(20, 5000); // 기록자
  578. cell1.setCellValue("환자명");
  579. cell2.setCellValue("생년월일");
  580. cell3.setCellValue("동,호실");
  581. cell4.setCellValue("기록일시");
  582. cell5.setCellValue("기침");
  583. cell6.setCellValue("호흡곤란");
  584. cell7.setCellValue("오한");
  585. cell8.setCellValue("근육통");
  586. cell9.setCellValue("두통");
  587. cell10.setCellValue("인후통");
  588. cell11.setCellValue("후각/미각 손실");
  589. cell12.setCellValue("피로");
  590. cell13.setCellValue("식욕감소");
  591. cell14.setCellValue("가래");
  592. cell15.setCellValue("오심");
  593. cell16.setCellValue("구토");
  594. cell17.setCellValue("설사");
  595. cell18.setCellValue("어지러움");
  596. cell19.setCellValue("콧물/코막힘");
  597. cell20.setCellValue("기타증상");
  598. cell21.setCellValue("기록자");
  599. // 동,호실
  600. String roomNumber = "";
  601. if (!patientDto.getWardNumber().equals("")) {
  602. roomNumber = patientDto.getWardNumber() + "동";
  603. }
  604. roomNumber += patientDto.getRoomNumber() + "호";
  605. int i = 1;
  606. for (int index = data.size() - 1; index >= 0; index--) {
  607. PatientSymptomSimDTO dto = data.get(index);
  608. row = sheet1.createRow(i);
  609. cell1 = row.createCell(0);
  610. cell2 = row.createCell(1);
  611. cell3 = row.createCell(2);
  612. cell4 = row.createCell(3);
  613. cell5 = row.createCell(4);
  614. cell6 = row.createCell(5);
  615. cell7 = row.createCell(6);
  616. cell8 = row.createCell(7);
  617. cell9 = row.createCell(8);
  618. cell10 = row.createCell(9);
  619. cell11 = row.createCell(10);
  620. cell12 = row.createCell(11);
  621. cell13 = row.createCell(12);
  622. cell14 = row.createCell(13);
  623. cell15 = row.createCell(14);
  624. cell16 = row.createCell(15);
  625. cell17 = row.createCell(16);
  626. cell18 = row.createCell(17);
  627. cell19 = row.createCell(18);
  628. cell20 = row.createCell(19);
  629. cell21 = row.createCell(20);
  630. String createDate = null;
  631. SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  632. SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  633. try {
  634. Date t = originalFormat.parse(dto.getCreateDate());
  635. createDate = targetFormat.format(t);
  636. } catch (Exception e) {
  637. createDate = dto.getCreateDate();
  638. }
  639. cell1.setCellValue(patientDto.getPatientName());
  640. cell2.setCellValue(patientDto.getJumin());
  641. cell3.setCellValue(roomNumber);
  642. cell4.setCellValue(createDate);
  643. cell5.setCellValue(dto.getCoughCheck().equals("Y") ? "V" : "-");
  644. cell6.setCellValue(dto.getDyspneaCheck().equals("Y") ? "V" : "-");
  645. cell7.setCellValue(dto.getColdFitCheck().equals("Y") ? "V" : "-");
  646. cell8.setCellValue(dto.getMusclePainCheck().equals("Y") ? "V" : "-");
  647. cell9.setCellValue(dto.getHeadacheCheck().equals("Y") ? "V" : "-");
  648. cell10.setCellValue(dto.getSoreThroatCheck().equals("Y") ? "V" : "-");
  649. cell11.setCellValue(dto.getSmellPalateCheck().equals("Y") ? "V" : "-");
  650. cell12.setCellValue(dto.getFatigueCheck().equals("Y") ? "V" : "-");
  651. cell13.setCellValue(dto.getAppetiteLossCheck().equals("Y") ? "V" : "-");
  652. cell14.setCellValue(dto.getSputumCheck().equals("Y") ? "V" : "-");
  653. cell15.setCellValue(dto.getOcinCheck().equals("Y") ? "V" : "-");
  654. cell16.setCellValue(dto.getVomitingCheck().equals("Y") ? "V" : "-");
  655. cell17.setCellValue(dto.getDiarrheaCheck().equals("Y") ? "V" : "-");
  656. cell18.setCellValue(dto.getDizzinessCheck().equals("Y") ? "V" : "-");
  657. cell19.setCellValue(dto.getNoseCheck().equals("Y") ? "V" : "-");
  658. cell20.setCellValue(dto.getEtcCheck().equals("Y") ? dto.getEtcContent() : "-");
  659. cell21.setCellValue(dto.getRecordedByName());
  660. i++;
  661. }
  662. }
  663. private void createMemoSheet(Workbook workbook, CellStyle styleOfBoardFillFontBlackBold16, PatientDTO patientDto) {
  664. PatientMemoDTO patientMemoDto = new PatientMemoDTO();
  665. patientMemoDto.setPatientIdx(patientDto.getPatientIdx());
  666. List<PatientMemoDTO> data = new ArrayList<PatientMemoDTO>();
  667. data = clinicService.selectMemoList(patientMemoDto);
  668. Sheet sheet1 = workbook.createSheet("의료진 메모");
  669. Row row = sheet1.createRow(0);
  670. Cell cell1 = row.createCell(0);
  671. Cell cell2 = row.createCell(1);
  672. Cell cell3 = row.createCell(2);
  673. Cell cell4 = row.createCell(3);
  674. Cell cell5 = row.createCell(4);
  675. Cell cell6 = row.createCell(5);
  676. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  677. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  678. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  679. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  680. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  681. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  682. sheet1.setColumnWidth(0, 5000); // 환자명
  683. sheet1.setColumnWidth(1, 5000); // 생년월일
  684. sheet1.setColumnWidth(2, 5000); // 동호실
  685. sheet1.setColumnWidth(3, 5000); // 기록일시
  686. sheet1.setColumnWidth(4, 20000); // 내용
  687. sheet1.setColumnWidth(5, 3000); // 기록자
  688. cell1.setCellValue("환자명");
  689. cell2.setCellValue("생년월일");
  690. cell3.setCellValue("동,호실");
  691. cell4.setCellValue("기록일시");
  692. cell5.setCellValue("내용");
  693. cell6.setCellValue("기록자");
  694. // 동,호실
  695. String roomNumber = "";
  696. if (!patientDto.getWardNumber().equals("")) {
  697. roomNumber = patientDto.getWardNumber() + "동";
  698. }
  699. roomNumber += patientDto.getRoomNumber() + "호";
  700. int i = 1;
  701. for (int index = data.size() - 1; index >= 0; index--) {
  702. PatientMemoDTO dto = data.get(index);
  703. row = sheet1.createRow(i);
  704. cell1 = row.createCell(0);
  705. cell2 = row.createCell(1);
  706. cell3 = row.createCell(2);
  707. cell4 = row.createCell(3);
  708. cell5 = row.createCell(4);
  709. cell6 = row.createCell(5);
  710. String createDate = null;
  711. SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  712. SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  713. try {
  714. Date t = originalFormat.parse(dto.getCreateDate());
  715. createDate = targetFormat.format(t);
  716. } catch (Exception e) {
  717. createDate = dto.getCreateDate();
  718. }
  719. cell1.setCellValue(patientDto.getPatientName());
  720. cell2.setCellValue(patientDto.getJumin());
  721. cell3.setCellValue(roomNumber);
  722. cell4.setCellValue(createDate);
  723. cell5.setCellValue(dto.getContents());
  724. cell6.setCellValue(dto.getRecordedByName());
  725. CellStyle cs = workbook.createCellStyle();
  726. cs.setWrapText(true);
  727. cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //높이 가운데 정렬
  728. cell5.setCellStyle(cs);
  729. i++;
  730. }
  731. }
  732. }