HospitalSvc.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. package com.dbs.consentServer.controller;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.Optional;
  6. import javax.validation.Valid;
  7. import com.dbs.consentServer.DTO.User;
  8. import com.dbs.consentServer.DTO.hospitalDTO.PatientInfoDTO;
  9. import com.dbs.consentServer.DTO.hospitalDTO.PatientListDTO;
  10. import com.dbs.consentServer.VO.hospitalVO.ConsentFormCategoryVO;
  11. import com.dbs.consentServer.VO.hospitalVO.GetDoctorVO;
  12. import com.dbs.consentServer.VO.hospitalVO.GetPatientInfoVO;
  13. import com.dbs.consentServer.VO.hospitalVO.GetPatientVO;
  14. import com.dbs.consentServer.VO.hospitalVO.GetUserDeptVO;
  15. import com.dbs.consentServer.VO.hospitalVO.GetWardDeptVO;
  16. import com.dbs.consentServer.service.HospitalService;
  17. import com.dbs.consentServer.util.CommonUtils;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.http.HttpStatus;
  22. import org.springframework.http.ResponseEntity;
  23. import org.springframework.web.bind.annotation.GetMapping;
  24. import org.springframework.web.bind.annotation.PutMapping;
  25. import org.springframework.web.bind.annotation.RequestMapping;
  26. import org.springframework.web.bind.annotation.RequestMethod;
  27. import org.springframework.web.bind.annotation.RequestParam;
  28. import org.springframework.web.bind.annotation.RestController;
  29. import org.springframework.web.server.ResponseStatusException;
  30. import io.swagger.annotations.Api;
  31. @Api(tags = {"2. HospitalService "})
  32. @RestController
  33. @RequestMapping("/hospitalSvc")
  34. public class HospitalSvc {
  35. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  36. @Autowired
  37. private HospitalService hospitalService;
  38. /**
  39. * 기본정보 조회
  40. * @param instCd
  41. * @return
  42. */
  43. @RequestMapping(path="/GetBaseData", method=RequestMethod.POST)
  44. public ArrayList<HashMap<String, String>> GetBaseData(final String instCd) {
  45. final ArrayList<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();
  46. final HashMap<String, String> map = new HashMap<String, String>();
  47. String baseData = hospitalService.hospitalMapper.getBaseData(instCd);
  48. if (baseData == null) {
  49. baseData = "";
  50. }
  51. if (baseData.equals("")) {
  52. map.put("code", "01");
  53. } else {
  54. map.put("code", "00");
  55. map.put("data", baseData);
  56. }
  57. result.add(map);
  58. return result;
  59. }
  60. @GetMapping("GetBaseData")
  61. public ResponseEntity<String> GetBaseData(@RequestParam final Map<String, String> reqQeury){
  62. HttpStatus status = HttpStatus.OK;
  63. String body = "";
  64. final String instCd = Optional.ofNullable(reqQeury.get("instCd")).orElse("");
  65. if(instCd.equals("")){
  66. status = HttpStatus.BAD_REQUEST;
  67. body = "instCd MUST not be null";
  68. }
  69. else{
  70. // 람다 안에서 접근하려면 해당 타입의 array 로 접근하여야 한다. 더럽넹...
  71. // String[] bodyTemp = { null };
  72. HttpStatus[] statusTemp = { HttpStatus.OK };
  73. body = Optional.ofNullable(hospitalService.hospitalMapper.getBaseData(instCd))
  74. .filter(o -> !o.equals(""))
  75. .orElseGet(() -> {
  76. statusTemp[0] = HttpStatus.NO_CONTENT;
  77. // 204 일때 어딘가에서 body 를 짤라먹는뎅...
  78. return "no basecode found";
  79. });
  80. status = statusTemp[0];
  81. }
  82. return new ResponseEntity<String>(body, status);
  83. }
  84. /**
  85. * 기본 탭 설정(입원, 외래 등)
  86. * @param userId 사용자 아이디
  87. * @param status 상태 (입원 : I)
  88. * @param instCd
  89. */
  90. @RequestMapping(path="updateUserSetUp", method=RequestMethod.POST)
  91. public ArrayList<HashMap<String, Object>> updateUserSetup(final String userId, final String status, final String instCd) {
  92. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  93. final HashMap<String, Object> map = new HashMap<String, Object>();
  94. final HashMap<String, String> params = new HashMap<String, String>();
  95. params.put("instCd", instCd);
  96. params.put("status", status);
  97. params.put("userId", userId);
  98. final int rts = hospitalService.updateUserSetUp(params);
  99. if (rts == 0) {
  100. map.put("code", "01");
  101. } else {
  102. map.put("code", "00");
  103. map.put("data", rts);
  104. }
  105. result.add(map);
  106. return result;
  107. }
  108. /**
  109. *
  110. * @param userSet
  111. * @return
  112. */
  113. @PutMapping("updateUserSetUp")
  114. public ResponseEntity<?> updateUserSetUp(@Valid User.UserSet userSet){
  115. HttpStatus[] status = { HttpStatus.OK };
  116. int updated = Optional.ofNullable(hospitalService.updateUserSetUp(userSet))
  117. .filter(o -> o >= 0)
  118. .orElseGet(() -> {
  119. status[0] = HttpStatus.NO_CONTENT;
  120. return 0;
  121. });
  122. return new ResponseEntity<Integer>(updated, status[0]);
  123. }
  124. /**
  125. * 로그인 프로세스
  126. * @param userId 사용자 ID
  127. * @param userPw 사용자 PW
  128. * @param dutInstCd 기관코드
  129. * @param certSucc 인증여부(문자열로 내려옴, true면 공인인증서 로그인을 통해 들어온것)
  130. * @return
  131. */
  132. @RequestMapping(path="/doLogin", method=RequestMethod.POST)
  133. public ArrayList<HashMap<String, Object>> doLogin(final String userId, final String userPw, final String dutInstCd, final String certSucc) {
  134. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  135. final HashMap<String, Object> map = new HashMap<String, Object>();
  136. String encryptPw = hospitalService.hospitalMapper.doLogin(userId);
  137. if (encryptPw == null) {
  138. encryptPw = "";
  139. }
  140. if (certSucc.equals("false")) {
  141. if (!encryptPw.equals(userPw)) {
  142. map.put("code", "02");
  143. return result;
  144. }
  145. }
  146. final String sysCd = "HIS031";
  147. final HashMap<String, String> params = new HashMap<String, String>();
  148. params.put("userId", userId);
  149. params.put("sysCd", sysCd);
  150. final ArrayList<GetUserDeptVO> userDeptList = hospitalService.hospitalMapper.getUserDeptList(params);
  151. map.put("code", "00");
  152. map.put("data", userDeptList);
  153. result.add(map);
  154. return result;
  155. }
  156. /**
  157. * 병동 리스트
  158. * @param instCd
  159. * @return
  160. */
  161. @RequestMapping(path="/getWardList", method=RequestMethod.POST)
  162. public ArrayList<HashMap<String, Object>> getWardList(final String instCd) {
  163. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  164. final HashMap<String, Object> map = new HashMap<String, Object>();
  165. final ArrayList<GetWardDeptVO> wardList = hospitalService.getWardList(instCd);
  166. if (wardList.size() == 0) {
  167. map.put("code", "01");
  168. } else {
  169. map.put("code", "00");
  170. map.put("data", wardList);
  171. }
  172. result.add(map);
  173. return result;
  174. }
  175. /**
  176. * 병동 리스트 조회
  177. *
  178. * @param reqQeury
  179. * @return
  180. * 검색된 병동 목록을 반환, instCd 가 null 일경우 BAD_REQUEST 반환
  181. * 병동 목록이 없을 경우 NO_CONTENT 반환
  182. */
  183. @GetMapping("getWardList")
  184. public ArrayList<GetWardDeptVO> getWardList(@RequestParam final Map<String, String> reqQeury) {
  185. final String instCd = Optional.ofNullable(reqQeury.get("instCd")).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "instCd is null"));
  186. return Optional.ofNullable(
  187. hospitalService.getWardList(instCd)).filter(o -> !o.isEmpty())
  188. .orElseThrow(() -> new ResponseStatusException(HttpStatus.NO_CONTENT, "no ward list found"));
  189. }
  190. /**
  191. * 진료과 리스트
  192. * @param instCd
  193. * @param ordType
  194. * @return
  195. */
  196. @RequestMapping(path="getDeptList", method=RequestMethod.POST)
  197. public ArrayList<HashMap<String, Object>> getDeptList(final String instCd, final String ordType) {
  198. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  199. final HashMap<String, Object> map = new HashMap<>();
  200. final HashMap<String, String> params = new HashMap<String, String>();
  201. params.put("instCd", instCd);
  202. params.put("ordType", ordType);
  203. final ArrayList<GetWardDeptVO> deptList = hospitalService.getDeptList(params);
  204. if (deptList.size() == 0) {
  205. map.put("code", "01");
  206. } else {
  207. map.put("code", "00");
  208. map.put("data", deptList);
  209. }
  210. result.add(map);
  211. return result;
  212. }
  213. @GetMapping("getDeptList")
  214. public ArrayList<GetWardDeptVO> getDeptList(@RequestParam final Map<String, String> reqQeury) {
  215. final HashMap<String, String> params = new HashMap<>();
  216. params.put("instCd", Optional.ofNullable(reqQeury.get("instCd")).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "instCd is null")));
  217. params.put("ordType", Optional.ofNullable(reqQeury.get("ordType")).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "ordType is null")));
  218. return Optional.ofNullable(hospitalService.getDeptList(params)).filter(o -> !o.isEmpty())
  219. .orElseThrow(() -> new ResponseStatusException(HttpStatus.NO_CONTENT, "item not found"));
  220. }
  221. /**
  222. * 진료과에 따른 진료의 리스트
  223. * @param instCd
  224. * @param ordDeptCd
  225. * @param srchDd
  226. * @return
  227. */
  228. @RequestMapping(path="getDoctorList", method=RequestMethod.POST)
  229. public ArrayList<HashMap<String, Object>> getDoctorList(final String instCd, final String ordDeptCd, final String srchDd) {
  230. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  231. final HashMap<String, Object> map = new HashMap<String, Object>();
  232. final HashMap<String, String> params = new HashMap<String, String>();
  233. params.put("instCd", instCd);
  234. params.put("ordDeptCd", ordDeptCd);
  235. params.put("srchDd", srchDd);
  236. final ArrayList<GetDoctorVO> doctorList = hospitalService.getDoctorList(params);
  237. if (doctorList.size() == 0) {
  238. map.put("code", "01");
  239. } else {
  240. map.put("code", "00");
  241. map.put("data", doctorList);
  242. }
  243. result.add(map);
  244. return result;
  245. }
  246. @GetMapping("getDoctorList")
  247. public ArrayList<GetDoctorVO> getDoctorList(@RequestParam final Map<String, String> reqQeury) {
  248. final HashMap<String, String> params = new HashMap<String, String>();
  249. params.put("instCd", Optional.ofNullable(reqQeury.get("instCd")).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "instCd is null")));
  250. params.put("ordDeptCd", Optional.ofNullable(reqQeury.get("ordDeptCd")).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "ordDeptCd is null")));
  251. params.put("srchDd", Optional.ofNullable(reqQeury.get("srchDd")).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "srchDd is null")));
  252. return Optional.ofNullable(hospitalService.getDoctorList(params)).filter(o -> !o.isEmpty())
  253. .orElseThrow(() -> new ResponseStatusException(HttpStatus.NO_CONTENT , "no doctor list found"));
  254. }
  255. /**
  256. * 환자 리스트 조회
  257. * @param patientListDTO
  258. * @return
  259. */
  260. @RequestMapping(path="getPatientList", method=RequestMethod.POST)
  261. public ArrayList<HashMap<String, Object>> getPatientList(final PatientListDTO patientListDTO) {
  262. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  263. final HashMap<String, Object> map = new HashMap<String, Object>();
  264. ArrayList<GetPatientVO> patientList = new ArrayList<>();
  265. if (patientListDTO == null) {
  266. map.put("code", "01");
  267. map.put("data", patientList);
  268. result.add(map);
  269. return result;
  270. }
  271. String selectFlag = patientListDTO.getSelectFlag();
  272. final String patientState = patientListDTO.getPatientState();
  273. String myPatient = patientListDTO.getMyPatient();
  274. logger.debug("patientState -- > " + patientListDTO.getPatientState());
  275. if (selectFlag.equals("SR")) {
  276. if (patientState.equals("A")) {
  277. selectFlag = "I";
  278. } else if (patientState.equals("0")) {
  279. selectFlag = "O";
  280. } else if (patientState.equals("1")) {
  281. selectFlag = "1";
  282. }
  283. patientListDTO.setPatientState("");
  284. }
  285. if (myPatient.equals("")) {
  286. myPatient = "N";
  287. }
  288. patientListDTO.setMyPatient(myPatient);
  289. patientList = hospitalService.getPatientList(patientListDTO);
  290. if (patientList.size() == 0) {
  291. map.put("code", "02");
  292. } else {
  293. map.put("code", "00");
  294. }
  295. map.put("data", patientList);
  296. result.add(map);
  297. return result;
  298. }
  299. /**
  300. * 환자상세 정보 조회
  301. * @param patientInfoDTO
  302. * @return
  303. */
  304. @RequestMapping(path="getPatientInfo", method=RequestMethod.POST)
  305. public ArrayList<HashMap<String, Object>> getPatientInfo(final PatientInfoDTO patientInfoDTO) {
  306. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  307. final HashMap<String, Object> map = new HashMap<String, Object>();
  308. ArrayList<GetPatientInfoVO> patientInfo = new ArrayList<GetPatientInfoVO>();
  309. if (patientInfoDTO == null) {
  310. map.put("code", "01");
  311. map.put("data", patientInfo);
  312. result.add(map);
  313. return result;
  314. }
  315. final String opRsrvNo = patientInfoDTO.getOpRsrvNo() == null ? "" : patientInfoDTO.getOpRsrvNo();
  316. patientInfoDTO.setOpRsrvNo(opRsrvNo);
  317. patientInfo = hospitalService.getPatientInfo(patientInfoDTO);
  318. if (patientInfo.size() == 0) {
  319. map.put("code", "02");
  320. } else {
  321. map.put("code", "00");
  322. }
  323. map.put("data", patientInfo);
  324. result.add(map);
  325. return result;
  326. }
  327. /**
  328. * 사용자 즐겨찾기 추가
  329. * 리턴이 0이면 실패 1이면 성공
  330. * @param userId 사용자 아이디
  331. * @param formCd 서식 코드
  332. * @param instCd 기관 코드
  333. */
  334. @RequestMapping(path="setUserFormSetList", method=RequestMethod.POST)
  335. public ArrayList<HashMap<String, Object>> setUserFormSetList(final String userId, final String formCd, final String instCd) {
  336. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  337. final HashMap<String, Object> map = new HashMap<String, Object>();
  338. final HashMap<String, String> params = new HashMap<String, String>();
  339. params.put("userId", userId);
  340. params.put("formCd", formCd);
  341. params.put("instCd", instCd);
  342. logger.debug("params -- > " + params);
  343. final int rCount = hospitalService.setUserFormSet(params);
  344. logger.debug("result -- > " + result);
  345. if (rCount == 0) {
  346. map.put("code", "01");
  347. } else {
  348. map.put("code", "00");
  349. map.put("data", rCount);
  350. }
  351. result.add(map);
  352. return result;
  353. }
  354. /**
  355. * 즐겨찾기 삭제
  356. * 리턴이 0이면 실패 1이면 성공
  357. * @param idx
  358. * @param userId
  359. * @param formCd
  360. * @param instCd
  361. * @return
  362. */
  363. @RequestMapping(path="delUserFormSet", method=RequestMethod.POST)
  364. public ArrayList<HashMap<String, Object>> delUserFormSet(final String idx, final String userId, final String formCd, final String instCd) {
  365. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  366. final HashMap<String, Object> map = new HashMap<String, Object>();
  367. final HashMap<Object, Object> params = new HashMap<Object, Object>();
  368. logger.debug("idx -- > " + idx);
  369. logger.debug("idx getClass-- > " + idx.getClass());
  370. final boolean intChk = CommonUtils.isNumeric(idx);
  371. if (intChk != true) {
  372. map.put("code", "01");
  373. result.add(map);
  374. return result;
  375. }
  376. params.put("idx", Integer.parseInt(idx));
  377. params.put("userId", userId);
  378. params.put("formCd", formCd);
  379. params.put("instCd", instCd);
  380. final int rCount = hospitalService.delUserFormSet(params);
  381. if (rCount == 0) {
  382. map.put("code", "02");
  383. } else {
  384. map.put("code", "00");
  385. map.put("data", rCount);
  386. }
  387. result.add(map);
  388. return result;
  389. }
  390. @RequestMapping(path="getConsentFormCategory", method=RequestMethod.POST)
  391. public ArrayList<HashMap<String, Object>> getConsentFormCategory() {
  392. final ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
  393. final HashMap<String, Object> map = new HashMap<String, Object>();
  394. ArrayList<ConsentFormCategoryVO> categoryList = new ArrayList<ConsentFormCategoryVO>();
  395. categoryList = hospitalService.getConsentFormCategory();
  396. if (categoryList.size() == 0) {
  397. map.put("code", "01");
  398. } else {
  399. map.put("code", "00");
  400. map.put("data", categoryList);
  401. }
  402. result.add(map);
  403. return result;
  404. }
  405. }