ClinicController.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. package com.lemon.lifecenter.controller;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletRequest;
  5. import org.json.JSONObject;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10. import org.springframework.web.bind.annotation.RequestParam;
  11. import org.springframework.web.bind.annotation.ResponseBody;
  12. import org.springframework.web.servlet.ModelAndView;
  13. import com.lemon.lifecenter.common.LifeCenterController;
  14. import com.lemon.lifecenter.common.LifeCenterSessionController;
  15. import com.lemon.lifecenter.dto.PatientMemoDTO;
  16. import com.lemon.lifecenter.dto.PatientPHRHistoryDTO;
  17. import com.lemon.lifecenter.dto.PatientPHRLatestDTO;
  18. import com.lemon.lifecenter.dto.PatientSymptomSimDTO;
  19. import com.lemon.lifecenter.service.ClinicService;
  20. import com.lemon.lifecenter.service.PHRService;
  21. import com.lemon.lifecenter.service.PatientService;
  22. @Controller
  23. @RequestMapping("/clinic")
  24. public class ClinicController extends LifeCenterController {
  25. @Autowired
  26. private ClinicService clinicService;
  27. @Autowired
  28. private PHRService phrService;
  29. @Autowired
  30. private PatientService patientService;
  31. final int pageSize = 30;
  32. @RequestMapping("/state")
  33. public ModelAndView clinicState(HttpServletRequest request,
  34. @RequestParam(value = "page", required = true, defaultValue = "1") int page,
  35. @RequestParam(value = "searchText", required = false, defaultValue = "") String searchText) {
  36. boolean makePhrData = false;
  37. boolean makeSymptomData = false;
  38. boolean makeMemoData = false;
  39. if (makePhrData) {
  40. for (int i = 0; i < 2000; i++) {
  41. java.util.Random random = new java.util.Random();
  42. random.setSeed(System.currentTimeMillis());
  43. int idx = random.nextInt(2344) + 1;
  44. while ((idx > 56 && idx < 68) || (idx > 69 && idx < 114) || (idx > 145 && idx < 170)
  45. || (idx > 385 && idx < 388)) {
  46. idx = random.nextInt(2344) + 1;
  47. }
  48. String[] typeArray = { "temperature", "oxygenSaturation", "pulseRate", "systolicBloodPressure",
  49. "diastolicBloodPressure", "bloodSugar" };
  50. int type = random.nextInt(5);
  51. int value = random.nextInt(100);
  52. PatientPHRHistoryDTO dto2 = new PatientPHRHistoryDTO();
  53. dto2.setPatientIdx(idx);
  54. dto2.setPhrType(typeArray[type]);
  55. dto2.setPhrValue(value);
  56. dto2.setRecordedByName("홍길동");
  57. phrService.insertPHR(dto2);
  58. System.err.println("idx : " + idx);
  59. }
  60. }
  61. if (makeSymptomData) {
  62. java.util.Random random = new java.util.Random();
  63. random.setSeed(System.currentTimeMillis());
  64. int idx = random.nextInt(2344) + 1;
  65. String[] typeArray = { "temperature", "oxygenSaturation", "pulseRate", "systolicBloodPressure",
  66. "diastolicBloodPressure", "bloodSugar" };
  67. int type = random.nextInt(5);
  68. int value = random.nextInt(100);
  69. PatientPHRHistoryDTO dto2 = new PatientPHRHistoryDTO();
  70. dto2.setPatientIdx(idx);
  71. dto2.setPhrType(typeArray[type]);
  72. dto2.setPhrValue(value);
  73. dto2.setRecordedByName("홍길동");
  74. phrService.insertPHR(dto2);
  75. }
  76. System.err.println("page : " + page);
  77. String centerCode = "0000";// LifeCenterSessionController.getSession( request, "sesCenterCode" );
  78. PatientPHRLatestDTO dto = new PatientPHRLatestDTO();
  79. dto.setLimit((Integer.valueOf(page) - 1) * pageSize);
  80. dto.setLimitMax(pageSize);
  81. dto.setCenterCode(centerCode);
  82. dto.setSearchText(searchText);
  83. int total = clinicService.selectPHRLatestCount(dto);
  84. List<PatientPHRLatestDTO> result = new ArrayList<PatientPHRLatestDTO>();
  85. if (total > 0) {
  86. result = clinicService.selectPHRLatestList(dto);
  87. }
  88. ModelAndView mv = setMV("clinic/state");
  89. mv.addObject("searchText", searchText);
  90. mv.addObject("total", total);
  91. mv.addObject("items", result);
  92. return mv;
  93. }
  94. @RequestMapping("/info")
  95. public ModelAndView patientInfo(
  96. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx,
  97. @RequestParam(value = "phrType", required = true, defaultValue = "temperature") String phrType) {
  98. String centerCode = "0000";// LifeCenterSessionController.getSession( request, "sesCenterCode" );
  99. PatientPHRHistoryDTO dto = new PatientPHRHistoryDTO();
  100. dto.setPhrType(phrType);
  101. dto.setPatientIdx(patientIdx);
  102. int total = phrService.selectPHRHistoryCount(dto);
  103. List<PatientPHRHistoryDTO> result = new ArrayList<PatientPHRHistoryDTO>();
  104. if (total > 0) {
  105. result = phrService.selectPHRHistoryList(dto);
  106. }
  107. ModelAndView mv = setMV("clinic/info");
  108. mv.addObject("patientIdx", patientIdx);
  109. mv.addObject("phrType", phrType);
  110. mv.addObject("phrTotal", total);
  111. mv.addObject("phrItems", result);
  112. return mv;
  113. }
  114. @RequestMapping("/api/state")
  115. public @ResponseBody List<PatientPHRLatestDTO> state(HttpServletRequest request,
  116. @RequestParam(value = "page", required = true, defaultValue = "1") int page,
  117. @RequestParam(value = "searchText", required = false, defaultValue = "") String searchText) {
  118. System.err.println("page : " + page);
  119. String centerCode = "0000";// LifeCenterSessionController.getSession( request, "sesCenterCode" );
  120. PatientPHRLatestDTO dto = new PatientPHRLatestDTO();
  121. dto.setLimit((Integer.valueOf(page) - 1) * pageSize);
  122. dto.setLimitMax(pageSize);
  123. dto.setCenterCode(centerCode);
  124. dto.setSearchText(searchText);
  125. int total = clinicService.selectPHRLatestCount(dto);
  126. List<PatientPHRLatestDTO> result = new ArrayList<PatientPHRLatestDTO>();
  127. if (total > 0) {
  128. result = clinicService.selectPHRLatestList(dto);
  129. }
  130. return result;
  131. }
  132. @RequestMapping("/api/phrDatas")
  133. public @ResponseBody List<PatientPHRHistoryDTO> phrDatas(
  134. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx,
  135. @RequestParam(value = "phrType", required = true, defaultValue = "temperature") String phrType) {
  136. PatientPHRHistoryDTO dto = new PatientPHRHistoryDTO();
  137. dto.setPatientIdx(patientIdx);
  138. dto.setPhrType(phrType);
  139. return phrService.selectPHRHistoryList(dto);
  140. }
  141. @RequestMapping(value = "/api/phrData", method = RequestMethod.POST)
  142. public @ResponseBody String insertPhrData(
  143. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx,
  144. @RequestParam(value = "phrType", required = true, defaultValue = "") String phrType,
  145. @RequestParam(value = "phrValue", required = true, defaultValue = "") float phrValue) {
  146. try {
  147. PatientPHRHistoryDTO dto = new PatientPHRHistoryDTO();
  148. dto.setPatientIdx(patientIdx);
  149. dto.setPhrType(phrType);
  150. dto.setPhrValue(phrValue);
  151. dto.setRecordedByName("홍길동");
  152. phrService.insertPHR(dto);
  153. JSONObject json = new JSONObject();
  154. json.put("code", "00");
  155. json.put("message", "");
  156. return json.toString();
  157. } catch (Exception e) {
  158. JSONObject json = new JSONObject();
  159. json.put("code", "01");
  160. json.put("message", e.getLocalizedMessage());
  161. return json.toString();
  162. }
  163. }
  164. @RequestMapping("/api/symptomDatas")
  165. public @ResponseBody List<PatientSymptomSimDTO> symptomDatas(
  166. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx) {
  167. PatientSymptomSimDTO dto = new PatientSymptomSimDTO();
  168. dto.setPatientIdx(patientIdx);
  169. return phrService.selectSymptomList(dto);
  170. }
  171. @RequestMapping(value = "/api/symptomData", method = RequestMethod.POST)
  172. public @ResponseBody String symptomData(
  173. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx,
  174. @RequestParam(value = "phrType", required = true, defaultValue = "") String phrType,
  175. @RequestParam(value = "phrValue", required = true, defaultValue = "") float phrValue) {
  176. try {
  177. PatientSymptomSimDTO dto = new PatientSymptomSimDTO();
  178. phrService.insertSymptom(dto);
  179. JSONObject json = new JSONObject();
  180. json.put("code", "00");
  181. json.put("message", "");
  182. return json.toString();
  183. } catch (Exception e) {
  184. JSONObject json = new JSONObject();
  185. json.put("code", "01");
  186. json.put("message", e.getLocalizedMessage());
  187. return json.toString();
  188. }
  189. }
  190. @RequestMapping("/api/memoDatas")
  191. public @ResponseBody List<PatientMemoDTO> memoDatas(
  192. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx) {
  193. PatientMemoDTO dto = new PatientMemoDTO();
  194. return clinicService.selectMemoList(dto);
  195. }
  196. @RequestMapping(value = "/api/memoData", method = RequestMethod.POST)
  197. public @ResponseBody String memoData(
  198. @RequestParam(value = "patientIdx", required = true, defaultValue = "") int patientIdx,
  199. @RequestParam(value = "phrType", required = true, defaultValue = "") String phrType,
  200. @RequestParam(value = "phrValue", required = true, defaultValue = "") float phrValue) {
  201. try {
  202. PatientMemoDTO dto = new PatientMemoDTO();
  203. clinicService.insertMemo(dto);
  204. JSONObject json = new JSONObject();
  205. json.put("code", "00");
  206. json.put("message", "");
  207. return json.toString();
  208. } catch (Exception e) {
  209. JSONObject json = new JSONObject();
  210. json.put("code", "01");
  211. json.put("message", e.getLocalizedMessage());
  212. return json.toString();
  213. }
  214. }
  215. }