ClinicController.java 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. package com.lemon.lifecenter.controller;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.security.GeneralSecurityException;
  10. import java.text.SimpleDateFormat;
  11. import java.util.ArrayList;
  12. import java.util.Calendar;
  13. import java.util.Date;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Set;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19. import com.lemon.lifecenter.common.LifeCenterController;
  20. import com.lemon.lifecenter.common.LifeCenterFileDownload;
  21. import com.lemon.lifecenter.common.LifeCenterFunction;
  22. import com.lemon.lifecenter.common.LifeCenterSessionController;
  23. import com.lemon.lifecenter.dto.ClinicConfigurationDTO;
  24. import com.lemon.lifecenter.dto.FileDownloadDTO;
  25. import com.lemon.lifecenter.dto.MentalDTO;
  26. import com.lemon.lifecenter.dto.PatientDTO;
  27. import com.lemon.lifecenter.dto.PatientMemoDTO;
  28. import com.lemon.lifecenter.dto.PatientPHRHistoryDTO;
  29. import com.lemon.lifecenter.dto.PatientPHRLatestDTO;
  30. import com.lemon.lifecenter.dto.PatientSymptomSimDTO;
  31. import com.lemon.lifecenter.service.ClinicService;
  32. import com.lemon.lifecenter.service.FileDownloadService;
  33. import com.lemon.lifecenter.service.MentalService;
  34. import com.lemon.lifecenter.service.PHRService;
  35. import com.lemon.lifecenter.service.PatientService;
  36. import org.apache.poi.hssf.usermodel.HSSFCellStyle;
  37. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  38. import org.apache.poi.openxml4j.opc.OPCPackage;
  39. import org.apache.poi.poifs.crypt.EncryptionInfo;
  40. import org.apache.poi.poifs.crypt.EncryptionMode;
  41. import org.apache.poi.poifs.crypt.Encryptor;
  42. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  43. import org.apache.poi.ss.usermodel.Cell;
  44. import org.apache.poi.ss.usermodel.CellStyle;
  45. import org.apache.poi.ss.usermodel.Font;
  46. import org.apache.poi.ss.usermodel.IndexedColors;
  47. import org.apache.poi.ss.usermodel.Row;
  48. import org.apache.poi.ss.usermodel.Sheet;
  49. import org.apache.poi.ss.usermodel.Workbook;
  50. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  51. import org.json.JSONObject;
  52. import org.slf4j.Logger;
  53. import org.slf4j.LoggerFactory;
  54. import org.springframework.beans.factory.annotation.Autowired;
  55. import org.springframework.stereotype.Controller;
  56. import org.springframework.web.bind.annotation.ModelAttribute;
  57. import org.springframework.web.bind.annotation.RequestMapping;
  58. import org.springframework.web.bind.annotation.RequestMethod;
  59. import org.springframework.web.bind.annotation.RequestParam;
  60. import org.springframework.web.bind.annotation.ResponseBody;
  61. import org.springframework.web.servlet.ModelAndView;
  62. @Controller
  63. @RequestMapping("/clinic")
  64. public class ClinicController extends LifeCenterController {
  65. @Autowired
  66. private ClinicService clinicService;
  67. @Autowired
  68. private PHRService phrService;
  69. @Autowired
  70. private PatientService patientService;
  71. @Autowired
  72. private FileDownloadService fileDownloadService;
  73. @Autowired
  74. private MentalService mentalService;
  75. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  76. private enum FilterType {
  77. newPatient(0x01),
  78. alarm(0x02),
  79. temperatureBlank(0x04),
  80. bloodPressureBlank(0x08),
  81. pulseRateBlank(0x10),
  82. oxygenSaturationBlank(0x20),
  83. bloodSugarBlank(0x40),
  84. symptomBlank(0x80),
  85. mentalBlank(0x100);
  86. private final int value;
  87. FilterType(int value) {
  88. this.value = value;
  89. }
  90. public int getValue() {
  91. return value;
  92. }
  93. }
  94. private String[] parseFilter(String filter) {
  95. ArrayList<String> arrayList = new ArrayList<String>();
  96. try {
  97. int filterValue = Integer.parseInt(filter);
  98. for (FilterType f: FilterType.values()) {
  99. if ((filterValue & f.getValue()) == f.getValue()) {
  100. arrayList.add(f.name());
  101. System.out.println( f.name() );
  102. }
  103. }
  104. }
  105. catch( Exception e) {
  106. // 에러시 필터가 없는 것으로 간주
  107. }
  108. return arrayList.toArray(new String[arrayList.size()]);
  109. }
  110. @RequestMapping("/state")
  111. public ModelAndView clinicState(HttpServletRequest request,
  112. @RequestParam(value = "page", required = true, defaultValue = "1") int page,
  113. @RequestParam(value = "size", required = true, defaultValue = "30") int pageSize,
  114. @RequestParam(value = "searchText", required = false, defaultValue = "") String searchText,
  115. @RequestParam(value = "filter", required = false, defaultValue = "") String filter) {
  116. String centerCode = LifeCenterSessionController.getSession( request, "sesCenterCode" );
  117. PatientPHRLatestDTO dto = new PatientPHRLatestDTO();
  118. dto.setLimit((Integer.valueOf(page) - 1) * pageSize);
  119. dto.setLimitMax(pageSize);
  120. dto.setCenterCode(centerCode);
  121. dto.setSearchText(searchText);
  122. if (!filter.equals("")) {
  123. String[] filterList = parseFilter(filter);
  124. System.out.println( "#######################");
  125. System.out.println( filterList );
  126. System.out.println("#######################");
  127. if (filterList.length > 0) {
  128. dto.setFilterList(filterList);
  129. }
  130. }
  131. if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < 12) {
  132. dto.setTimeCriterion("AM");
  133. } else {
  134. dto.setTimeCriterion("PM");
  135. }
  136. int total = clinicService.selectPHRLatestCount(dto);
  137. // 서버사이드 렌더링 안함
  138. // List<PatientPHRLatestDTO> result = new ArrayList<PatientPHRLatestDTO>();
  139. //
  140. // if (total > 0) {
  141. // result = clinicService.selectPHRLatestList(dto);
  142. // }
  143. // 알람 임계치 정보
  144. ClinicConfigurationDTO configDto = new ClinicConfigurationDTO();
  145. configDto.setCenterCode(Integer.parseInt(centerCode));
  146. configDto = clinicService.selectConfiguration(configDto);
  147. ModelAndView mv = setMV("clinic/state");
  148. mv.addObject("page", page);
  149. mv.addObject("searchText", searchText);
  150. mv.addObject("filter", filter);
  151. mv.addObject("total", total);
  152. mv.addObject("config", configDto);
  153. // mv.addObject("items", result);
  154. return mv;
  155. }
  156. @RequestMapping("/info")
  157. public ModelAndView patientInfo(HttpServletRequest request,
  158. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx,
  159. @RequestParam(value = "refererSearch", required = false, defaultValue = "") String refererSearch,
  160. @RequestParam(value = "refererPage", required = false, defaultValue = "") String refererPage,
  161. @RequestParam(value = "refererFilter", required = false, defaultValue = "") String refererFilter) {
  162. String centerCode = LifeCenterSessionController.getSession( request, "sesCenterCode" );
  163. // 환자정보
  164. PatientDTO patientDto = new PatientDTO();
  165. patientDto.setPatientIdx(patientIdx);
  166. patientDto = patientService.selectPatientOne(patientDto);
  167. String jumin = patientDto.getJumin();
  168. jumin = LifeCenterFunction.changeJuminToBirthday(jumin);
  169. patientDto.setJumin(jumin);
  170. patientDto.setPatientPhone(LifeCenterFunction.phone(patientDto.getPatientPhone()));
  171. patientDto.setGuardianPhone(LifeCenterFunction.phone(patientDto.getGuardianPhone()));
  172. String bloodPress = patientDto.getBloodPressureLevel();
  173. if (!bloodPress.equals("") && !bloodPress.equals("|")) {
  174. String[] bloodPressureLevel = bloodPress.split("[|]");
  175. if (bloodPressureLevel[0] != null) {
  176. patientDto.setBloodPressureLevelCon(bloodPressureLevel[0]);
  177. }
  178. if (bloodPressureLevel[1] != null) {
  179. patientDto.setBloodPressureLevelRel(bloodPressureLevel[1]);
  180. }
  181. }
  182. String strDisease = "";
  183. String strSymptom = LifeCenterFunction.getSymptom(patientDto);
  184. if (patientDto.getBasalDiseaseYn().equals("Y")) {
  185. strDisease = LifeCenterFunction.getDisease(patientDto);
  186. }
  187. // 히스토리 데이터
  188. PatientPHRHistoryDTO dto = new PatientPHRHistoryDTO();
  189. dto.setPatientIdx(patientIdx);
  190. // 체온
  191. dto.setPhrType("temperature");
  192. List<PatientPHRHistoryDTO> temperatureResult = phrService.selectPHRHistoryList(dto);
  193. // 혈압
  194. dto.setPhrType("bloodPressure");
  195. List<PatientPHRHistoryDTO> bloodPressureResult = phrService.selectPHRHistoryList(dto);
  196. // 맥박
  197. dto.setPhrType("pulseRate");
  198. List<PatientPHRHistoryDTO> pulseRateResult = phrService.selectPHRHistoryList(dto);
  199. // 산소포화도
  200. dto.setPhrType("oxygenSaturation");
  201. List<PatientPHRHistoryDTO> oxygenSaturationResult = phrService.selectPHRHistoryList(dto);
  202. // 혈당
  203. dto.setPhrType("bloodSugar");
  204. List<PatientPHRHistoryDTO> bloodSugarResult = phrService.selectPHRHistoryList(dto);
  205. // 증상
  206. PatientSymptomSimDTO dto2 = new PatientSymptomSimDTO();
  207. dto2.setPatientIdx(patientIdx);
  208. List<PatientSymptomSimDTO> symptomResult = phrService.selectSymptomList(dto2);
  209. // 메모
  210. PatientMemoDTO dto3 = new PatientMemoDTO();
  211. dto3.setPatientIdx(patientIdx);
  212. List<PatientMemoDTO> memoResult = clinicService.selectMemoList(dto3);
  213. // response
  214. List<PatientPHRHistoryDTO> bloodPressureUnionResult = getBloodPressureUnionResult(patientIdx, bloodPressureResult, pulseRateResult);
  215. // 알람 임계치 정보
  216. ClinicConfigurationDTO configDto = new ClinicConfigurationDTO();
  217. configDto.setCenterCode(Integer.parseInt(centerCode));
  218. configDto = clinicService.selectConfiguration(configDto);
  219. // 정신건강 자가진단 추가 21.06.17
  220. MentalDTO mDTO = new MentalDTO();
  221. mDTO.setPatientIdx(patientIdx);
  222. List<MentalDTO> mentalList = new ArrayList<MentalDTO>();
  223. int mentalTotal = mentalService.selectMentalHealthTotalCount(mDTO);
  224. if( mentalTotal > 0 ) {
  225. mentalList = mentalService.selectMentalHealthTotalList(mDTO);
  226. }
  227. ModelAndView mv = setMV("clinic/info");
  228. // 정신건강 항목 데이터
  229. List<MentalDTO> mentalCheckList = mentalService.selectMentalHealthCheckList(mDTO);
  230. mv.addObject("mentalCheckList", mentalCheckList);
  231. mv.addObject("patientIdx", patientIdx);
  232. mv.addObject("info", patientDto);
  233. mv.addObject("symptom", strSymptom);
  234. mv.addObject("disease", strDisease);
  235. mv.addObject("temperatureResult", temperatureResult);
  236. mv.addObject("bloodPressureResult", bloodPressureResult);
  237. mv.addObject("pulseRateResult", pulseRateResult);
  238. mv.addObject("bloodPressureUnionResult", bloodPressureUnionResult);
  239. mv.addObject("oxygenSaturationResult", oxygenSaturationResult);
  240. mv.addObject("bloodSugarResult", bloodSugarResult);
  241. mv.addObject("symptomResult", symptomResult);
  242. mv.addObject("memoResult", memoResult);
  243. mv.addObject("refererSearch", refererSearch);
  244. mv.addObject("refererPage", refererPage);
  245. mv.addObject("refererFilter", refererFilter);
  246. mv.addObject("config", configDto);
  247. mv.addObject("mentalTotal" , mentalTotal);
  248. mv.addObject("mentalList" , mentalList);
  249. return mv;
  250. }
  251. @RequestMapping("/config")
  252. public ModelAndView clinicState(HttpServletRequest request) {
  253. String centerCode = LifeCenterSessionController.getSession( request, "sesCenterCode" );
  254. ClinicConfigurationDTO dto = new ClinicConfigurationDTO();
  255. dto.setCenterCode(Integer.parseInt(centerCode));
  256. dto = clinicService.selectConfiguration(dto);
  257. ModelAndView mv = setMV("clinic/config");
  258. mv.addObject("config", dto);
  259. return mv;
  260. }
  261. @RequestMapping("/api/state")
  262. public @ResponseBody String getStateAPI(HttpServletRequest request,
  263. @RequestParam(value = "page", required = true, defaultValue = "1") int page,
  264. @RequestParam(value = "size", required = true, defaultValue = "30") int pageSize,
  265. @RequestParam(value = "searchText", required = false, defaultValue = "") String searchText,
  266. @RequestParam(value = "filter", required = false, defaultValue = "") String filter,
  267. @RequestParam(value = "sortType", required = false, defaultValue = "") String sortType) {
  268. String centerCode = LifeCenterSessionController.getSession( request, "sesCenterCode" );
  269. PatientPHRLatestDTO dto = new PatientPHRLatestDTO();
  270. dto.setLimit((Integer.valueOf(page) - 1) * pageSize);
  271. dto.setLimitMax(pageSize);
  272. dto.setCenterCode(centerCode);
  273. dto.setSearchText(searchText);
  274. if (!filter.equals("")) {
  275. String[] filterList = parseFilter(filter);
  276. if (filterList.length > 0) {
  277. dto.setFilterList(filterList);
  278. }
  279. }
  280. if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < 12) {
  281. dto.setTimeCriterion("AM");
  282. } else {
  283. dto.setTimeCriterion("PM");
  284. }
  285. dto.setSortType(sortType);
  286. int total = clinicService.selectPHRLatestCount(dto);
  287. List<PatientPHRLatestDTO> result = new ArrayList<PatientPHRLatestDTO>();
  288. if (total > 0) {
  289. result = clinicService.selectPHRLatestList(dto);
  290. }
  291. JSONObject json = new JSONObject();
  292. json.put("count", total);
  293. json.put("items", result);
  294. return json.toString();
  295. }
  296. @RequestMapping("/api/phrDatas")
  297. public @ResponseBody List<PatientPHRHistoryDTO> getPhrDatasAPI(
  298. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx,
  299. @RequestParam(value = "phrType", required = true, defaultValue = "temperature") String phrType) {
  300. PatientPHRHistoryDTO dto = new PatientPHRHistoryDTO();
  301. dto.setPatientIdx(patientIdx);
  302. dto.setPhrType(phrType);
  303. List<PatientPHRHistoryDTO> result = phrService.selectPHRHistoryList(dto);
  304. boolean needPulseRate = phrType.equals("bloodPressure");
  305. if (needPulseRate) {
  306. PatientPHRHistoryDTO dto2 = new PatientPHRHistoryDTO();
  307. dto2.setPatientIdx(patientIdx);
  308. dto2.setPhrType("pulseRate");
  309. List<PatientPHRHistoryDTO> pulseRateResult = phrService.selectPHRHistoryList(dto2);
  310. List<PatientPHRHistoryDTO> bloodPressureUnionResult = getBloodPressureUnionResult(patientIdx, result, pulseRateResult);
  311. return bloodPressureUnionResult;
  312. }
  313. else {
  314. return result;
  315. }
  316. }
  317. @RequestMapping(value = "/api/phrData", method = RequestMethod.POST)
  318. public @ResponseBody String insertPhrDataAPI(@ModelAttribute("dto") final PatientPHRHistoryDTO dto) {
  319. try {
  320. phrService.insertPHR(dto);
  321. if (dto.getPhrValueExtra() != null) {
  322. PatientPHRHistoryDTO pulseRateDto = new PatientPHRHistoryDTO();
  323. pulseRateDto.setPatientIdx(dto.getPatientIdx());
  324. pulseRateDto.setPhrType("pulseRate");
  325. pulseRateDto.setPhrValue(dto.getPhrValueExtra());
  326. pulseRateDto.setRecordedByName(dto.getRecordedByName());
  327. if (dto.getRecordedById() != null) {
  328. pulseRateDto.setRecordedById(dto.getRecordedById());
  329. }
  330. if (dto.getRecordedDate() != null) {
  331. pulseRateDto.setRecordedDate(dto.getRecordedDate());
  332. }
  333. phrService.insertPHR(pulseRateDto);
  334. }
  335. JSONObject json = new JSONObject();
  336. json.put("code", "00");
  337. json.put("message", "");
  338. return json.toString();
  339. } catch (Exception e) {
  340. JSONObject json = new JSONObject();
  341. json.put("code", "01");
  342. json.put("message", e.getLocalizedMessage());
  343. return json.toString();
  344. }
  345. }
  346. @RequestMapping("/api/symptomDatas")
  347. public @ResponseBody List<PatientSymptomSimDTO> getSymptomDatasAPI(
  348. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx) {
  349. PatientSymptomSimDTO dto = new PatientSymptomSimDTO();
  350. dto.setPatientIdx(patientIdx);
  351. return phrService.selectSymptomList(dto);
  352. }
  353. @RequestMapping(value = "/api/symptomData", method = RequestMethod.POST)
  354. public @ResponseBody String insertSymptomDataAPI(@ModelAttribute("dto") final PatientSymptomSimDTO dto) {
  355. try {
  356. phrService.insertSymptom(dto);
  357. JSONObject json = new JSONObject();
  358. json.put("code", "00");
  359. json.put("message", "");
  360. return json.toString();
  361. } catch (Exception e) {
  362. JSONObject json = new JSONObject();
  363. json.put("code", "01");
  364. json.put("message", e.getLocalizedMessage());
  365. return json.toString();
  366. }
  367. }
  368. @RequestMapping("/api/memoDatas")
  369. public @ResponseBody List<PatientMemoDTO> getMemoDatasAPI(
  370. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx) {
  371. PatientMemoDTO dto = new PatientMemoDTO();
  372. dto.setPatientIdx(patientIdx);
  373. return clinicService.selectMemoList(dto);
  374. }
  375. @RequestMapping(value = "/api/memoData", method = RequestMethod.POST)
  376. public @ResponseBody String insertMemoDataAPI(@ModelAttribute("dto") final PatientMemoDTO dto) {
  377. try {
  378. clinicService.insertMemo(dto);
  379. JSONObject json = new JSONObject();
  380. json.put("code", "00");
  381. json.put("message", "");
  382. return json.toString();
  383. } catch (Exception e) {
  384. JSONObject json = new JSONObject();
  385. json.put("code", "01");
  386. json.put("message", e.getLocalizedMessage());
  387. return json.toString();
  388. }
  389. }
  390. @RequestMapping(value = "/api/memoData", method = RequestMethod.DELETE)
  391. public @ResponseBody String deleteMemoDataAPI(@ModelAttribute("dto") final PatientMemoDTO dto) {
  392. try {
  393. clinicService.deleteMemo(dto);
  394. JSONObject json = new JSONObject();
  395. json.put("code", "00");
  396. json.put("message", "");
  397. return json.toString();
  398. } catch (Exception e) {
  399. JSONObject json = new JSONObject();
  400. json.put("code", "01");
  401. json.put("message", e.getLocalizedMessage());
  402. return json.toString();
  403. }
  404. }
  405. @RequestMapping(value = "/api/memoData", method = RequestMethod.PATCH)
  406. public @ResponseBody String updateMemoDataAPI(@ModelAttribute("dto") final PatientMemoDTO dto) {
  407. try {
  408. clinicService.updateMemo(dto);
  409. JSONObject json = new JSONObject();
  410. json.put("code", "00");
  411. json.put("message", "");
  412. return json.toString();
  413. } catch (Exception e) {
  414. JSONObject json = new JSONObject();
  415. json.put("code", "01");
  416. json.put("message", e.getLocalizedMessage());
  417. return json.toString();
  418. }
  419. }
  420. private List<PatientPHRHistoryDTO> getBloodPressureUnionResult(int patientIdx, List<PatientPHRHistoryDTO> bloodPressureResult, List<PatientPHRHistoryDTO>pulseRateResult) {
  421. // 혈압 맥박 정리
  422. int bloodPressureIndex = 0;
  423. int pulseRateIndex = 0;
  424. List<PatientPHRHistoryDTO> bloodPressureUnionResult = new ArrayList<PatientPHRHistoryDTO>();
  425. while (bloodPressureIndex < bloodPressureResult.size() || pulseRateIndex < pulseRateResult.size()) {
  426. PatientPHRHistoryDTO union = new PatientPHRHistoryDTO();
  427. union.setPatientIdx(patientIdx);
  428. union.setPhrType("bloodPressure");
  429. if (bloodPressureIndex == bloodPressureResult.size()) {
  430. PatientPHRHistoryDTO pr = pulseRateResult.get(pulseRateIndex);
  431. union.setCreateDate(pr.getCreateDate());
  432. union.setRecordedDate(pr.getRecordedDate());
  433. union.setPhrValueExtra(pr.getPhrValue());
  434. union.setIsExtraWarning(pr.getIsWarning());
  435. union.setRecordedByName(pr.getRecordedByName());
  436. union.setRecordedById(pr.getRecordedById());
  437. bloodPressureUnionResult.add(union);
  438. pulseRateIndex += 1;
  439. continue;
  440. }
  441. else if (pulseRateIndex == pulseRateResult.size()) {
  442. PatientPHRHistoryDTO bp = bloodPressureResult.get(bloodPressureIndex);
  443. union.setCreateDate(bp.getCreateDate());
  444. union.setRecordedDate(bp.getRecordedDate());
  445. union.setPhrValue(bp.getPhrValue());
  446. union.setPhrValue2(bp.getPhrValue2());
  447. union.setIsWarning(bp.getIsWarning());
  448. union.setRecordedByName(bp.getRecordedByName());
  449. union.setRecordedById(bp.getRecordedById());
  450. bloodPressureUnionResult.add(union);
  451. bloodPressureIndex += 1;
  452. continue;
  453. }
  454. PatientPHRHistoryDTO bp = bloodPressureResult.get(bloodPressureIndex);
  455. PatientPHRHistoryDTO pr = pulseRateResult.get(pulseRateIndex);
  456. SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  457. SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  458. String bpRecordedDateFormatted = bp.getRecordedDate();
  459. String prRecordedDateFormatted = pr.getRecordedDate();
  460. try {
  461. Date t = originalFormat.parse(bpRecordedDateFormatted);
  462. bpRecordedDateFormatted = targetFormat.format(t);
  463. Date t2 = originalFormat.parse(prRecordedDateFormatted);
  464. prRecordedDateFormatted = targetFormat.format(t2);
  465. }
  466. catch (Exception e) {
  467. }
  468. int dateDiffer = bpRecordedDateFormatted.compareTo(prRecordedDateFormatted);
  469. if (dateDiffer == 0) {
  470. union.setCreateDate(bp.getCreateDate());
  471. union.setRecordedDate(bp.getRecordedDate());
  472. union.setPhrValue(bp.getPhrValue());
  473. union.setPhrValue2(bp.getPhrValue2());
  474. union.setIsWarning(bp.getIsWarning());
  475. union.setRecordedByName(bp.getRecordedByName());
  476. union.setRecordedById(bp.getRecordedById());
  477. union.setPhrValueExtra(pr.getPhrValue());
  478. union.setIsExtraWarning(pr.getIsWarning());
  479. bloodPressureIndex += 1;
  480. pulseRateIndex += 1;
  481. }
  482. else if (dateDiffer < 0) {
  483. union.setCreateDate(bp.getCreateDate());
  484. union.setRecordedDate(bp.getRecordedDate());
  485. union.setPhrValue(bp.getPhrValue());
  486. union.setPhrValue2(bp.getPhrValue2());
  487. union.setIsWarning(bp.getIsWarning());
  488. union.setRecordedByName(bp.getRecordedByName());
  489. union.setRecordedById(bp.getRecordedById());
  490. bloodPressureIndex += 1;
  491. }
  492. else if (dateDiffer > 0) {
  493. union.setCreateDate(pr.getCreateDate());
  494. union.setRecordedDate(pr.getRecordedDate());
  495. union.setPhrValueExtra(pr.getPhrValue());
  496. union.setIsExtraWarning(pr.getIsWarning());
  497. union.setRecordedByName(pr.getRecordedByName());
  498. union.setRecordedById(pr.getRecordedById());
  499. pulseRateIndex += 1;
  500. }
  501. bloodPressureUnionResult.add(union);
  502. }
  503. return bloodPressureUnionResult;
  504. }
  505. @RequestMapping("/excel")
  506. public void getExcelFile(
  507. @RequestParam(value="phrType", required=true, defaultValue="temperature") String phrType,
  508. @RequestParam(value="patientIdx", required=true, defaultValue="") int patientIdx,
  509. @RequestParam(value="downMemo", required=true, defaultValue="") String downMemo,
  510. HttpServletRequest request, HttpServletResponse response ) {
  511. PatientDTO patientDto = new PatientDTO();
  512. patientDto.setPatientIdx(patientIdx);
  513. patientDto = patientService.selectPatientOne(patientDto);
  514. //excel 다운로드 로그 남기기
  515. String userId = LifeCenterSessionController.getSession(request, "sesId");
  516. FileDownloadDTO fileDTO = new FileDownloadDTO();
  517. fileDTO.setId( userId );
  518. fileDTO.setIp( LifeCenterFunction.getRemoteAddr( request ) );
  519. fileDTO.setUrl( request.getRequestURI().toString() );
  520. fileDTO.setMemo( downMemo );
  521. fileDTO.setEtc( "진료관리, " + patientDto.getPatientName() + ", " + patientDto.getJumin() + ", " + Integer.toString(patientDto.getCenterCode()) );
  522. fileDTO.setPatientIdx( patientIdx );
  523. fileDownloadService.insertExcelDownloadLog( fileDTO );
  524. this.createExcel(request, response, patientDto);
  525. }
  526. private void createExcel(HttpServletRequest request, HttpServletResponse response, PatientDTO patientDto) {
  527. Workbook workbook = new XSSFWorkbook();
  528. // 셀 스타일 및 폰트 설정
  529. CellStyle styleOfBoardFillFontBlackBold16 = workbook.createCellStyle();
  530. // 정렬
  531. styleOfBoardFillFontBlackBold16.setAlignment(CellStyle.ALIGN_CENTER); //가운데 정렬
  532. styleOfBoardFillFontBlackBold16.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //높이 가운데 정렬
  533. // 배경색
  534. styleOfBoardFillFontBlackBold16.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
  535. styleOfBoardFillFontBlackBold16.setFillPattern(CellStyle.SOLID_FOREGROUND);
  536. // 테두리 선 (우,좌,위,아래)
  537. styleOfBoardFillFontBlackBold16.setBorderRight(HSSFCellStyle.BORDER_THIN);
  538. styleOfBoardFillFontBlackBold16.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  539. styleOfBoardFillFontBlackBold16.setBorderTop(HSSFCellStyle.BORDER_THIN);
  540. styleOfBoardFillFontBlackBold16.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  541. // 폰트 설정
  542. Font fontOfGothicBlackBold16 = workbook.createFont();
  543. // fontOfGothicBlackBold16.setFontName("나눔고딕"); //글씨체
  544. fontOfGothicBlackBold16.setFontHeight((short)(10*20)); //사이즈
  545. fontOfGothicBlackBold16.setBoldweight(Font.BOLDWEIGHT_BOLD); //볼드 (굵게)
  546. styleOfBoardFillFontBlackBold16.setFont(fontOfGothicBlackBold16);
  547. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "체온", "temperature");
  548. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "혈압", "bloodPressure");
  549. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "맥박", "pulseRate");
  550. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "산소포화도", "oxygenSaturation");
  551. this.createMentalSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto);
  552. this.createPHRSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto, "혈당", "bloodSugar");
  553. this.createSymptomSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto);
  554. this.createMemoSheet(workbook, styleOfBoardFillFontBlackBold16, patientDto);
  555. try {
  556. // File file = new File(".");
  557. // String rootPath = file.getAbsolutePath();
  558. // System.out.println("현재 프로젝트의 경로 : "+rootPath );
  559. // JBOSS에서 구동시 /home1/jboss/jboss-eap-7.3/domain/test/excel-temp 경로에 저장이됨
  560. String directoryName = "../excel-temp/";
  561. File directory = new File(directoryName);
  562. if (! directory.exists()) {
  563. directory.mkdir();
  564. }
  565. String password = LifeCenterSessionController.getSession(request, "sesPhoneNumber");
  566. password = password.toLowerCase();
  567. if (!password.equals("null")) {
  568. password = password.replace("-", "");
  569. password = password.substring(3).trim();
  570. } else {
  571. password = "";
  572. }
  573. String timestamp = LifeCenterFunction.getNow("yyyy-MM-dd_HH-mm-ss");
  574. // 다운로드 파일 명: 호실_환자명(생년월일)_건강정보기록_다운로드일시.xlsx
  575. String downName = patientDto.getRoomNumber() + "_" + patientDto.getPatientName() + "(" + patientDto.getJumin() + ")_건강정보기록_" + timestamp + ".xlsx";
  576. String tempPath = directoryName + downName;
  577. File xlsFile = new File(tempPath);
  578. // FileOutputStream fileOut = new FileOutputStream(xlsFile);
  579. // workbook.write(fileOut);
  580. //
  581. // LifeCenterFileDownload.download(request, response, tempPath, downName);
  582. //
  583. // xlsFile.delete();
  584. ByteArrayOutputStream fileOut = new ByteArrayOutputStream();
  585. FileOutputStream fos = new FileOutputStream(tempPath);
  586. workbook.write(fileOut);
  587. InputStream filein = new ByteArrayInputStream(fileOut.toByteArray());
  588. OPCPackage opc = OPCPackage.open(filein);
  589. POIFSFileSystem fileSystem = new POIFSFileSystem();
  590. EncryptionInfo encryptionInfo = new EncryptionInfo(EncryptionMode.agile);
  591. Encryptor encryptor = encryptionInfo.getEncryptor();
  592. encryptor.confirmPassword(password);
  593. opc.save(encryptor.getDataStream(fileSystem));
  594. opc.flush();
  595. fileSystem.writeFilesystem(fos);
  596. fileOut.close();
  597. opc.close();
  598. filein.close();
  599. fileSystem.close();
  600. LifeCenterFileDownload.download(request, response, tempPath, downName);
  601. xlsFile.delete();
  602. } catch (FileNotFoundException e) {
  603. e.printStackTrace();
  604. } catch (IOException e) {
  605. e.printStackTrace();
  606. } catch (InvalidFormatException e) {
  607. e.printStackTrace();
  608. } catch (GeneralSecurityException e) {
  609. e.printStackTrace();
  610. }
  611. }
  612. private void createPHRSheet(Workbook workbook, CellStyle styleOfBoardFillFontBlackBold16, PatientDTO patientDto, String phrTypeKorean, String phrType) {
  613. PatientPHRHistoryDTO patientPHRHistoryDto = new PatientPHRHistoryDTO();
  614. patientPHRHistoryDto.setPhrType(phrType);
  615. patientPHRHistoryDto.setPatientIdx(patientDto.getPatientIdx());
  616. int total = phrService.selectPHRHistoryCount(patientPHRHistoryDto);
  617. List<PatientPHRHistoryDTO> data = new ArrayList<PatientPHRHistoryDTO>();
  618. if (total > 0) {
  619. data = phrService.selectPHRHistoryList(patientPHRHistoryDto);
  620. }
  621. Sheet sheet1 = workbook.createSheet(phrTypeKorean);
  622. Row row = sheet1.createRow(0);
  623. Cell cell1 = row.createCell(0);
  624. Cell cell2 = row.createCell(1);
  625. Cell cell3 = row.createCell(2);
  626. Cell cell4 = row.createCell(3);
  627. Cell cell5 = row.createCell(4);
  628. Cell cell6 = row.createCell(5);
  629. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  630. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  631. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  632. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  633. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  634. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  635. sheet1.setColumnWidth( 0, 5000); // 환자명
  636. sheet1.setColumnWidth( 1, 5000); // 생년월일
  637. sheet1.setColumnWidth( 2, 5000); // 동, 호실
  638. sheet1.setColumnWidth( 3, 5000); // 측정일시
  639. sheet1.setColumnWidth( 4, 3000); // 값
  640. sheet1.setColumnWidth( 5, 4000); // 기록자
  641. cell1.setCellValue("환자명");
  642. cell2.setCellValue("생년월일");
  643. cell3.setCellValue("동,호실");
  644. cell4.setCellValue("측정일시");
  645. cell5.setCellValue(phrTypeKorean);
  646. cell6.setCellValue("기록자");
  647. // 동,호실
  648. String roomNumber = "";
  649. if (!patientDto.getWardNumber().equals("")) {
  650. roomNumber = patientDto.getWardNumber() + "동";
  651. }
  652. roomNumber += patientDto.getRoomNumber() + "호";
  653. int i = 1;
  654. for (PatientPHRHistoryDTO dto : data) {
  655. row = sheet1.createRow(i);
  656. cell1 = row.createCell(0);
  657. cell2 = row.createCell(1);
  658. cell3 = row.createCell(2);
  659. cell4 = row.createCell(3);
  660. cell5 = row.createCell(4);
  661. cell6 = row.createCell(5);
  662. // 일시
  663. String recordedDate = null;
  664. SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  665. SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  666. try {
  667. Date t = originalFormat.parse(dto.getRecordedDate());
  668. recordedDate = targetFormat.format(t);
  669. } catch (Exception e) {
  670. recordedDate = dto.getRecordedDate();
  671. }
  672. // 값
  673. String phrValue = "";
  674. String phrValue2 = "";
  675. if (phrType.equals("temperature")) {
  676. phrValue = String.format("%.1f", dto.getPhrValue());
  677. phrValue2 = String.format("%.1f", dto.getPhrValue2());
  678. } else {
  679. phrValue = String.format("%.0f", dto.getPhrValue());
  680. phrValue2 = String.format("%.0f", dto.getPhrValue2());
  681. }
  682. // 기록자
  683. String recordedByName = dto.getRecordedByName();
  684. cell1.setCellValue(patientDto.getPatientName());
  685. cell2.setCellValue(patientDto.getJumin());
  686. cell3.setCellValue(roomNumber);
  687. cell4.setCellValue(recordedDate);
  688. if (phrType.equals("bloodPressure")) {
  689. cell5.setCellValue(phrValue + "/" + phrValue2);
  690. } else {
  691. cell5.setCellValue(phrValue);
  692. }
  693. cell6.setCellValue(recordedByName);
  694. i++;
  695. }
  696. }
  697. private void createSymptomSheet(Workbook workbook, CellStyle styleOfBoardFillFontBlackBold16, PatientDTO patientDto) {
  698. PatientSymptomSimDTO patientSymptomSimDto = new PatientSymptomSimDTO();
  699. patientSymptomSimDto.setPatientIdx(patientDto.getPatientIdx());
  700. int total = phrService.selectSymptomCount(patientSymptomSimDto);
  701. List<PatientSymptomSimDTO> data = new ArrayList<PatientSymptomSimDTO>();
  702. if (total > 0) {
  703. data = phrService.selectSymptomList(patientSymptomSimDto);
  704. }
  705. Sheet sheet1 = workbook.createSheet("임상증상");
  706. Row row = sheet1.createRow(0);
  707. Cell cell1 = row.createCell(0);
  708. Cell cell2 = row.createCell(1);
  709. Cell cell3 = row.createCell(2);
  710. Cell cell4 = row.createCell(3);
  711. Cell cell5 = row.createCell(4);
  712. Cell cell6 = row.createCell(5);
  713. Cell cell7 = row.createCell(6);
  714. Cell cell8 = row.createCell(7);
  715. Cell cell9 = row.createCell(8);
  716. Cell cell10 = row.createCell(9);
  717. Cell cell11 = row.createCell(10);
  718. Cell cell12 = row.createCell(11);
  719. Cell cell13 = row.createCell(12);
  720. Cell cell14 = row.createCell(13);
  721. Cell cell15 = row.createCell(14);
  722. Cell cell16 = row.createCell(15);
  723. Cell cell17 = row.createCell(16);
  724. Cell cell18 = row.createCell(17);
  725. Cell cell19 = row.createCell(18);
  726. Cell cell20 = row.createCell(19);
  727. Cell cell21 = row.createCell(20);
  728. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  729. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  730. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  731. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  732. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  733. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  734. cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
  735. cell8.setCellStyle(styleOfBoardFillFontBlackBold16);
  736. cell9.setCellStyle(styleOfBoardFillFontBlackBold16);
  737. cell10.setCellStyle(styleOfBoardFillFontBlackBold16);
  738. cell11.setCellStyle(styleOfBoardFillFontBlackBold16);
  739. cell12.setCellStyle(styleOfBoardFillFontBlackBold16);
  740. cell13.setCellStyle(styleOfBoardFillFontBlackBold16);
  741. cell14.setCellStyle(styleOfBoardFillFontBlackBold16);
  742. cell15.setCellStyle(styleOfBoardFillFontBlackBold16);
  743. cell16.setCellStyle(styleOfBoardFillFontBlackBold16);
  744. cell17.setCellStyle(styleOfBoardFillFontBlackBold16);
  745. cell18.setCellStyle(styleOfBoardFillFontBlackBold16);
  746. cell19.setCellStyle(styleOfBoardFillFontBlackBold16);
  747. cell20.setCellStyle(styleOfBoardFillFontBlackBold16);
  748. cell21.setCellStyle(styleOfBoardFillFontBlackBold16);
  749. sheet1.setColumnWidth(0, 5000); // 환자명
  750. sheet1.setColumnWidth(1, 5000); // 생년월일
  751. sheet1.setColumnWidth(2, 5000); // 동호실
  752. sheet1.setColumnWidth(3, 5000); // 측정일시
  753. sheet1.setColumnWidth(4, 3000); // 기침
  754. sheet1.setColumnWidth(5, 3000); // 호흡곤란
  755. sheet1.setColumnWidth(6, 3000); // 오한
  756. sheet1.setColumnWidth(7, 3000); // 근육통
  757. sheet1.setColumnWidth(8, 3000); // 두통
  758. sheet1.setColumnWidth(9, 3000); // 인후통
  759. sheet1.setColumnWidth(10, 3000); // 후각/미각 손실
  760. sheet1.setColumnWidth(11, 3000); // 피로
  761. sheet1.setColumnWidth(12, 3000); // 식욕감소
  762. sheet1.setColumnWidth(13, 3000); // 가래
  763. sheet1.setColumnWidth(14, 3000); // 오심
  764. sheet1.setColumnWidth(15, 3000); // 구토
  765. sheet1.setColumnWidth(16, 3000); // 설사
  766. sheet1.setColumnWidth(17, 3000); // 어지러움
  767. sheet1.setColumnWidth(18, 3000); // 콧물/코막힘
  768. sheet1.setColumnWidth(19, 3000); // 기타증상
  769. sheet1.setColumnWidth(20, 5000); // 기록자
  770. cell1.setCellValue("환자명");
  771. cell2.setCellValue("생년월일");
  772. cell3.setCellValue("동,호실");
  773. cell4.setCellValue("측정일시");
  774. cell5.setCellValue("기침");
  775. cell6.setCellValue("호흡곤란");
  776. cell7.setCellValue("오한");
  777. cell8.setCellValue("근육통");
  778. cell9.setCellValue("두통");
  779. cell10.setCellValue("인후통");
  780. cell11.setCellValue("후각/미각 손실");
  781. cell12.setCellValue("피로");
  782. cell13.setCellValue("식욕감소");
  783. cell14.setCellValue("가래");
  784. cell15.setCellValue("오심");
  785. cell16.setCellValue("구토");
  786. cell17.setCellValue("설사");
  787. cell18.setCellValue("어지러움");
  788. cell19.setCellValue("콧물/코막힘");
  789. cell20.setCellValue("기타증상");
  790. cell21.setCellValue("기록자");
  791. // 동,호실
  792. String roomNumber = "";
  793. if (!patientDto.getWardNumber().equals("")) {
  794. roomNumber = patientDto.getWardNumber() + "동";
  795. }
  796. roomNumber += patientDto.getRoomNumber() + "호";
  797. int i = 1;
  798. for (int index = data.size() - 1; index >= 0; index--) {
  799. PatientSymptomSimDTO dto = data.get(index);
  800. row = sheet1.createRow(i);
  801. cell1 = row.createCell(0);
  802. cell2 = row.createCell(1);
  803. cell3 = row.createCell(2);
  804. cell4 = row.createCell(3);
  805. cell5 = row.createCell(4);
  806. cell6 = row.createCell(5);
  807. cell7 = row.createCell(6);
  808. cell8 = row.createCell(7);
  809. cell9 = row.createCell(8);
  810. cell10 = row.createCell(9);
  811. cell11 = row.createCell(10);
  812. cell12 = row.createCell(11);
  813. cell13 = row.createCell(12);
  814. cell14 = row.createCell(13);
  815. cell15 = row.createCell(14);
  816. cell16 = row.createCell(15);
  817. cell17 = row.createCell(16);
  818. cell18 = row.createCell(17);
  819. cell19 = row.createCell(18);
  820. cell20 = row.createCell(19);
  821. cell21 = row.createCell(20);
  822. String recordedDate = null;
  823. SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  824. SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  825. try {
  826. Date t = originalFormat.parse(dto.getRecordedDate());
  827. recordedDate = targetFormat.format(t);
  828. } catch (Exception e) {
  829. recordedDate = dto.getRecordedDate();
  830. }
  831. cell1.setCellValue(patientDto.getPatientName());
  832. cell2.setCellValue(patientDto.getJumin());
  833. cell3.setCellValue(roomNumber);
  834. cell4.setCellValue(recordedDate);
  835. cell5.setCellValue(dto.getCoughCheck().equals("Y") ? "V" : "-");
  836. cell6.setCellValue(dto.getDyspneaCheck().equals("Y") ? "V" : "-");
  837. cell7.setCellValue(dto.getColdFitCheck().equals("Y") ? "V" : "-");
  838. cell8.setCellValue(dto.getMusclePainCheck().equals("Y") ? "V" : "-");
  839. cell9.setCellValue(dto.getHeadacheCheck().equals("Y") ? "V" : "-");
  840. cell10.setCellValue(dto.getSoreThroatCheck().equals("Y") ? "V" : "-");
  841. cell11.setCellValue(dto.getSmellPalateCheck().equals("Y") ? "V" : "-");
  842. cell12.setCellValue(dto.getFatigueCheck().equals("Y") ? "V" : "-");
  843. cell13.setCellValue(dto.getAppetiteLossCheck().equals("Y") ? "V" : "-");
  844. cell14.setCellValue(dto.getSputumCheck().equals("Y") ? "V" : "-");
  845. cell15.setCellValue(dto.getOcinCheck().equals("Y") ? "V" : "-");
  846. cell16.setCellValue(dto.getVomitingCheck().equals("Y") ? "V" : "-");
  847. cell17.setCellValue(dto.getDiarrheaCheck().equals("Y") ? "V" : "-");
  848. cell18.setCellValue(dto.getDizzinessCheck().equals("Y") ? "V" : "-");
  849. cell19.setCellValue(dto.getNoseCheck().equals("Y") ? "V" : "-");
  850. cell20.setCellValue(dto.getEtcCheck().equals("Y") ? dto.getEtcContent() : "-");
  851. cell21.setCellValue(dto.getRecordedByName());
  852. i++;
  853. }
  854. }
  855. private void createMemoSheet(Workbook workbook, CellStyle styleOfBoardFillFontBlackBold16, PatientDTO patientDto) {
  856. PatientMemoDTO patientMemoDto = new PatientMemoDTO();
  857. patientMemoDto.setPatientIdx(patientDto.getPatientIdx());
  858. List<PatientMemoDTO> data = new ArrayList<PatientMemoDTO>();
  859. data = clinicService.selectMemoList(patientMemoDto);
  860. Sheet sheet1 = workbook.createSheet("의료진 메모");
  861. Row row = sheet1.createRow(0);
  862. Cell cell1 = row.createCell(0);
  863. Cell cell2 = row.createCell(1);
  864. Cell cell3 = row.createCell(2);
  865. Cell cell4 = row.createCell(3);
  866. Cell cell5 = row.createCell(4);
  867. Cell cell6 = row.createCell(5);
  868. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  869. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  870. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  871. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  872. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  873. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  874. sheet1.setColumnWidth(0, 5000); // 환자명
  875. sheet1.setColumnWidth(1, 5000); // 생년월일
  876. sheet1.setColumnWidth(2, 5000); // 동호실
  877. sheet1.setColumnWidth(3, 5000); // 처리일시
  878. sheet1.setColumnWidth(4, 20000); // 내용
  879. sheet1.setColumnWidth(5, 3000); // 기록자
  880. cell1.setCellValue("환자명");
  881. cell2.setCellValue("생년월일");
  882. cell3.setCellValue("동,호실");
  883. cell4.setCellValue("처리일시");
  884. cell5.setCellValue("내용");
  885. cell6.setCellValue("기록자");
  886. // 동,호실
  887. String roomNumber = "";
  888. if (!patientDto.getWardNumber().equals("")) {
  889. roomNumber = patientDto.getWardNumber() + "동";
  890. }
  891. roomNumber += patientDto.getRoomNumber() + "호";
  892. int i = 1;
  893. for (int index = data.size() - 1; index >= 0; index--) {
  894. PatientMemoDTO dto = data.get(index);
  895. row = sheet1.createRow(i);
  896. cell1 = row.createCell(0);
  897. cell2 = row.createCell(1);
  898. cell3 = row.createCell(2);
  899. cell4 = row.createCell(3);
  900. cell5 = row.createCell(4);
  901. cell6 = row.createCell(5);
  902. String recordedDate = null;
  903. SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  904. SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  905. try {
  906. Date t = originalFormat.parse(dto.getRecordedDate());
  907. recordedDate = targetFormat.format(t);
  908. } catch (Exception e) {
  909. recordedDate = dto.getRecordedDate();
  910. }
  911. cell1.setCellValue(patientDto.getPatientName());
  912. cell2.setCellValue(patientDto.getJumin());
  913. cell3.setCellValue(roomNumber);
  914. cell4.setCellValue(recordedDate);
  915. cell5.setCellValue(dto.getContents());
  916. cell6.setCellValue(dto.getRecordedByName());
  917. CellStyle cs = workbook.createCellStyle();
  918. cs.setWrapText(true);
  919. cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //높이 가운데 정렬
  920. cell5.setCellStyle(cs);
  921. i++;
  922. }
  923. }
  924. private void createMentalSheet(Workbook workbook, CellStyle styleOfBoardFillFontBlackBold16, PatientDTO patientDto) {
  925. // 정신건강 자가진단 추가 21.06.17
  926. MentalDTO mDTO = new MentalDTO();
  927. mDTO.setPatientIdx(patientDto.getPatientIdx());
  928. List<MentalDTO> data = new ArrayList<MentalDTO>();
  929. int mentalTotal = mentalService.selectMentalHealthTotalCount(mDTO);
  930. if (mentalTotal > 0) {
  931. data = mentalService.selectMentalHealthTotalList(mDTO);
  932. }
  933. Sheet sheet1 = workbook.createSheet("정신건강");
  934. Row row = sheet1.createRow(0);
  935. Cell cell1 = row.createCell(0);
  936. Cell cell2 = row.createCell(1);
  937. Cell cell3 = row.createCell(2);
  938. Cell cell4 = row.createCell(3);
  939. Cell cell5 = row.createCell(4);
  940. Cell cell6 = row.createCell(5);
  941. Cell cell7 = row.createCell(6);
  942. Cell cell8 = row.createCell(7);
  943. cell1.setCellStyle(styleOfBoardFillFontBlackBold16);
  944. cell2.setCellStyle(styleOfBoardFillFontBlackBold16);
  945. cell3.setCellStyle(styleOfBoardFillFontBlackBold16);
  946. cell4.setCellStyle(styleOfBoardFillFontBlackBold16);
  947. cell5.setCellStyle(styleOfBoardFillFontBlackBold16);
  948. cell6.setCellStyle(styleOfBoardFillFontBlackBold16);
  949. cell7.setCellStyle(styleOfBoardFillFontBlackBold16);
  950. cell8.setCellStyle(styleOfBoardFillFontBlackBold16);
  951. sheet1.setColumnWidth(0, 5000); // 측정일시
  952. sheet1.setColumnWidth(1, 7000); // 외상후 스트레스 증상(총점)
  953. sheet1.setColumnWidth(2, 4000); // 우울(총점)
  954. sheet1.setColumnWidth(3, 5000); // 우울(9번 문항)
  955. sheet1.setColumnWidth(4, 3000); // VAS
  956. sheet1.setColumnWidth(5, 4000); // 상담연계동의
  957. sheet1.setColumnWidth(6, 4000); // 기록자
  958. sheet1.setColumnWidth(7, 5000); // 기록일
  959. cell1.setCellValue("측정일시");
  960. cell2.setCellValue("외상후 스트레스 증상(총점)");
  961. cell3.setCellValue("우울(총점)");
  962. cell4.setCellValue("우울(9번 문항)");
  963. cell5.setCellValue("VAS");
  964. cell6.setCellValue("상담연계동의");
  965. cell7.setCellValue("기록자");
  966. cell8.setCellValue("기록일");
  967. int i = 1;
  968. for (MentalDTO dto : data ) {
  969. row = sheet1.createRow(i);
  970. cell1 = row.createCell(0);
  971. cell2 = row.createCell(1);
  972. cell3 = row.createCell(2);
  973. cell4 = row.createCell(3);
  974. cell5 = row.createCell(4);
  975. cell6 = row.createCell(5);
  976. cell7 = row.createCell(6);
  977. cell8 = row.createCell(7);
  978. cell1.setCellValue( dto.getRecordedDate() );
  979. cell2.setCellValue( dto.getStressTotal() );
  980. cell3.setCellValue( dto.getDepressedTotal() );
  981. cell4.setCellValue( dto.getDepressedNine() );
  982. cell5.setCellValue( dto.getVasTotal() );
  983. cell6.setCellValue( dto.getAgreeYn().equals("Y") ? "동의" : "비동의" );
  984. cell7.setCellValue( dto.getCreatedBy() );
  985. cell8.setCellValue( dto.getCreateDate() );
  986. CellStyle cs = workbook.createCellStyle();
  987. cs.setWrapText(true);
  988. cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER); // 높이 가운데 정렬
  989. cell5.setCellStyle(cs);
  990. i++;
  991. }
  992. }
  993. @RequestMapping("/api/configuration")
  994. public @ResponseBody ClinicConfigurationDTO getConfigurationAPI(
  995. @RequestParam(value = "centerCode", required = true, defaultValue = "") int centerCode) {
  996. ClinicConfigurationDTO dto = new ClinicConfigurationDTO();
  997. dto.setCenterCode(centerCode);
  998. return clinicService.selectConfiguration(dto);
  999. }
  1000. @RequestMapping(value = "/api/configuration", method = RequestMethod.POST)
  1001. public @ResponseBody String insertConfigurationAPI(@ModelAttribute("dto") final ClinicConfigurationDTO dto) {
  1002. try {
  1003. clinicService.insertConfiguration(dto);
  1004. JSONObject json = new JSONObject();
  1005. json.put("code", "00");
  1006. json.put("message", "");
  1007. return json.toString();
  1008. } catch (Exception e) {
  1009. JSONObject json = new JSONObject();
  1010. json.put("code", "01");
  1011. json.put("message", e.getLocalizedMessage());
  1012. return json.toString();
  1013. }
  1014. }
  1015. @RequestMapping(value = "/api/configuration", method = RequestMethod.DELETE)
  1016. public @ResponseBody String deleteConfigurationAPI(@ModelAttribute("dto") final ClinicConfigurationDTO dto) {
  1017. try {
  1018. clinicService.deleteConfiguration(dto);
  1019. JSONObject json = new JSONObject();
  1020. json.put("code", "00");
  1021. json.put("message", "");
  1022. return json.toString();
  1023. } catch (Exception e) {
  1024. JSONObject json = new JSONObject();
  1025. json.put("code", "01");
  1026. json.put("message", e.getLocalizedMessage());
  1027. return json.toString();
  1028. }
  1029. }
  1030. @RequestMapping(value = "/api/configuration/display", method = RequestMethod.PATCH)
  1031. public @ResponseBody String updateDisplayConfigurationAPI(@ModelAttribute("dto") final ClinicConfigurationDTO dto) {
  1032. try {
  1033. clinicService.updateDisplayConfiguration(dto);
  1034. JSONObject json = new JSONObject();
  1035. json.put("code", "00");
  1036. json.put("message", "");
  1037. return json.toString();
  1038. } catch (Exception e) {
  1039. JSONObject json = new JSONObject();
  1040. json.put("code", "01");
  1041. json.put("message", e.getLocalizedMessage());
  1042. return json.toString();
  1043. }
  1044. }
  1045. @RequestMapping(value = "/api/configuration/threshold", method = RequestMethod.PATCH)
  1046. public @ResponseBody String updateThresholdConfigurationAPI(@ModelAttribute("dto") final ClinicConfigurationDTO dto) {
  1047. try {
  1048. clinicService.updateThresholdConfiguration(dto);
  1049. JSONObject json = new JSONObject();
  1050. json.put("code", "00");
  1051. json.put("message", "");
  1052. return json.toString();
  1053. } catch (Exception e) {
  1054. JSONObject json = new JSONObject();
  1055. json.put("code", "01");
  1056. json.put("message", e.getLocalizedMessage());
  1057. return json.toString();
  1058. }
  1059. }
  1060. @RequestMapping(value = "/api/mentalDetail", method = RequestMethod.POST)
  1061. public @ResponseBody String selectMentalRecord(
  1062. @RequestParam(value = "totalIdx", required = true ) int totalIdx,
  1063. HttpServletRequest request ) {
  1064. try {
  1065. MentalDTO dto = new MentalDTO();
  1066. dto.setTotalIdx(totalIdx);
  1067. JSONObject json = new JSONObject();
  1068. json.put("code", "00");
  1069. json.put("data", mentalService.selectMentalHealthRecord(dto) );
  1070. return json.toString();
  1071. } catch (Exception e) {
  1072. JSONObject json = new JSONObject();
  1073. json.put("code", "01");
  1074. json.put("message", e.getLocalizedMessage());
  1075. return json.toString();
  1076. }
  1077. }
  1078. @RequestMapping(value = "/api/mentalInsert", method = RequestMethod.POST)
  1079. public @ResponseBody String insertMentalData(@ModelAttribute("dto") MentalDTO dto, HttpServletRequest request ) {
  1080. try{
  1081. Set<String> keySet = request.getParameterMap().keySet();
  1082. String createdBy = LifeCenterSessionController.getSession(request, "sesName");
  1083. String recordId = LifeCenterSessionController.getSession(request, "sesId");
  1084. int patientIdx = dto.getPatientIdx();
  1085. List<MentalDTO> mentalList = mentalService.selectMentalHealthCheckList(dto);
  1086. HashMap<String, String> ml = new HashMap<String, String>();
  1087. for (MentalDTO d : mentalList) {
  1088. ml.put(d.getItemCode(), d.getEtcCode());
  1089. }
  1090. int stressTotal = 0;
  1091. int depressedTotal = 0;
  1092. int depressedNine = 0;
  1093. int vasTotal = 0;
  1094. String agreeYn = "";
  1095. String recordedDate = "";
  1096. // total 통계부터 insert 계산
  1097. for (String key : keySet) {
  1098. if (key.equals("recordedDate")) {
  1099. System.out.println( "request.getParameter(key) : " + request.getParameter(key) );
  1100. recordedDate = request.getParameter(key).equals("") ? LifeCenterFunction.getNow("yyyy-MM-dd HH:mm").toString(): request
  1101. .getParameter(key);
  1102. continue;
  1103. }
  1104. if (key.equals("patientIdx")) continue;
  1105. dto = new MentalDTO();
  1106. String itemCode = key.trim();
  1107. int itemScore = Integer.valueOf(request.getParameter(key));
  1108. if (itemCode.equals("agree")) {
  1109. agreeYn = itemScore == 1 ? "Y" : "N";
  1110. continue;
  1111. }
  1112. if (ml.get(key).equals("stress")) {
  1113. stressTotal += itemScore;
  1114. } else if (ml.get(key).equals("depressed")) {
  1115. // 우울-> 9번항목 itemCode는 A0016이다
  1116. if (key.equals("A0016")) {
  1117. depressedNine = itemScore;
  1118. }
  1119. // 우울 마지막항목 itemCode는 A0017이다 마지막항목은 총점제외
  1120. if (!itemCode.equals("A0017")) {
  1121. depressedTotal += itemScore;
  1122. }
  1123. } else if (ml.get(key).equals("vas")) {
  1124. vasTotal += itemScore;
  1125. }
  1126. }
  1127. dto.setPatientIdx(patientIdx);
  1128. dto.setCreatedBy(createdBy);
  1129. dto.setStressTotal(stressTotal);
  1130. dto.setDepressedTotal(depressedTotal);
  1131. dto.setDepressedNine(depressedNine);
  1132. dto.setVasTotal(vasTotal);
  1133. dto.setAgreeYn(agreeYn);
  1134. dto.setRecordId(recordId);
  1135. mentalService.insertMentalHealthTotal(dto);
  1136. int totalIdx = dto.getIdx();
  1137. // detail 상세점수
  1138. for (String key : keySet) {
  1139. if (key.equals("patientIdx"))
  1140. continue;
  1141. if (key.equals("agree"))
  1142. continue;
  1143. if (key.equals("recordedDate"))
  1144. continue;
  1145. dto = new MentalDTO();
  1146. int itemScore = Integer.valueOf(request.getParameter(key));
  1147. String itemCode = key.trim();
  1148. dto.setTotalIdx(totalIdx);
  1149. dto.setPatientIdx(patientIdx);
  1150. dto.setCreatedBy(createdBy);
  1151. dto.setItemCode(itemCode);
  1152. dto.setItemScore(itemScore);
  1153. mentalService.insertMentalHealthRecord(dto);
  1154. }
  1155. JSONObject json = new JSONObject();
  1156. json.put("createDate", LifeCenterFunction.getNow("yyyy-MM-dd HH:mm").toString() );
  1157. json.put("stressTotal", stressTotal);
  1158. json.put("depressedTotal", depressedTotal);
  1159. json.put("depressedNine", depressedNine);
  1160. json.put("vasTotal", vasTotal);
  1161. json.put("agreeYn", agreeYn);
  1162. json.put("createdBy", createdBy);
  1163. json.put("recordedDate", recordedDate);
  1164. json.put("totalIdx", totalIdx);
  1165. json.put("code", "00");
  1166. json.put("message", "");
  1167. return json.toString();
  1168. } catch (Exception e) {
  1169. JSONObject json = new JSONObject();
  1170. json.put("code", "01");
  1171. json.put("message", e.getLocalizedMessage());
  1172. return json.toString();
  1173. }
  1174. }
  1175. }