PatientController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. package org.example.controller;
  2. import org.example.entity.PageResult;
  3. import org.example.entity.Patient;
  4. import org.example.entity.PatientDiagnosis;
  5. import org.example.entity.PatientOrder;
  6. import org.example.entity.PatientCharge;
  7. import org.example.entity.PatientExam;
  8. import org.example.entity.PatientTest;
  9. import org.example.entity.PatientTestItem;
  10. import org.example.service.PatientService;
  11. import org.example.service.PatientDiagnosisService;
  12. import org.example.service.PatientOrderService;
  13. import org.example.service.PatientChargeService;
  14. import org.example.service.PatientExamService;
  15. import org.example.service.PatientTestService;
  16. import org.example.service.PatientTestItemService;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.format.annotation.DateTimeFormat;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.util.Date;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. /**
  25. * 患者控制器
  26. */
  27. @RestController
  28. @RequestMapping("/api/patient")
  29. public class PatientController {
  30. @Autowired
  31. private PatientService patientService;
  32. @Autowired
  33. private PatientDiagnosisService patientDiagnosisService;
  34. @Autowired
  35. private PatientOrderService patientOrderService;
  36. @Autowired
  37. private PatientChargeService patientChargeService;
  38. @Autowired
  39. private PatientExamService patientExamService;
  40. @Autowired
  41. private PatientTestService patientTestService;
  42. @Autowired
  43. private PatientTestItemService patientTestItemService;
  44. /**
  45. * 获取页面初始化数据(合并接口,减少请求次数,支持分页)
  46. */
  47. @GetMapping("/init-data")
  48. public Map<String, Object> initData(
  49. @RequestParam(required = false, defaultValue = "1") Integer page,
  50. @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
  51. Map<String, Object> result = new HashMap<>();
  52. result.put("code", 200);
  53. result.put("data", patientService.getInitData(page, pageSize));
  54. return result;
  55. }
  56. /**
  57. * 查询患者列表(支持分页)
  58. */
  59. @GetMapping("/list")
  60. public Map<String, Object> list(
  61. @RequestParam(required = false) String name,
  62. @RequestParam(required = false) String deptCode,
  63. @RequestParam(required = false) String wardCode,
  64. @RequestParam(required = false) String roomNo,
  65. @RequestParam(required = false) String bedNo,
  66. @RequestParam(required = false) String inpatientNo,
  67. @RequestParam(required = false) String nurseLevel,
  68. @RequestParam(required = false) String inpatientStatus,
  69. @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date admissionDateStart,
  70. @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date admissionDateEnd,
  71. @RequestParam(required = false, defaultValue = "1") Integer page,
  72. @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
  73. Map<String, Object> result = new HashMap<>();
  74. List<Patient> list = patientService.findList(name, deptCode, wardCode, roomNo, bedNo,
  75. inpatientNo, nurseLevel, inpatientStatus, admissionDateStart, admissionDateEnd);
  76. // 分页处理
  77. PageResult<Patient> pageResult = PageResult.of(list, page, pageSize);
  78. result.put("code", 200);
  79. result.put("data", pageResult);
  80. return result;
  81. }
  82. /**
  83. * 获取所属科室列表(用于下拉框)
  84. */
  85. @GetMapping("/dept-list")
  86. public Map<String, Object> deptList() {
  87. Map<String, Object> result = new HashMap<>();
  88. List<String> list = patientService.findAllDeptCode();
  89. result.put("code", 200);
  90. result.put("data", list);
  91. return result;
  92. }
  93. /**
  94. * 根据科室获取病区列表(用于联动下拉框)
  95. */
  96. @GetMapping("/ward-list")
  97. public Map<String, Object> wardList(@RequestParam(required = false) String deptCode) {
  98. Map<String, Object> result = new HashMap<>();
  99. List<String> list = patientService.findWardsByDept(deptCode);
  100. result.put("code", 200);
  101. result.put("data", list);
  102. return result;
  103. }
  104. /**
  105. * 根据病区获取房间号列表(用于联动下拉框)
  106. */
  107. @GetMapping("/room-list")
  108. public Map<String, Object> roomList(@RequestParam(required = false) String wardCode) {
  109. Map<String, Object> result = new HashMap<>();
  110. List<String> list = patientService.findRoomsByWard(wardCode);
  111. result.put("code", 200);
  112. result.put("data", list);
  113. return result;
  114. }
  115. /**
  116. * 根据房间号获取床位号列表(用于联动下拉框)
  117. */
  118. @GetMapping("/bed-list")
  119. public Map<String, Object> bedList(@RequestParam(required = false) String roomNo) {
  120. Map<String, Object> result = new HashMap<>();
  121. List<String> list = patientService.findBedsByRoom(roomNo);
  122. result.put("code", 200);
  123. result.put("data", list);
  124. return result;
  125. }
  126. /**
  127. * 获取在院状态列表(用于下拉框)
  128. */
  129. @GetMapping("/inpatient-status-list")
  130. public Map<String, Object> inpatientStatusList() {
  131. Map<String, Object> result = new HashMap<>();
  132. List<String> list = patientService.findAllInpatientStatus();
  133. result.put("code", 200);
  134. result.put("data", list);
  135. return result;
  136. }
  137. /**
  138. * 获取护理级别列表(用于下拉框)
  139. */
  140. @GetMapping("/nurse-level-list")
  141. public Map<String, Object> nurseLevelList() {
  142. Map<String, Object> result = new HashMap<>();
  143. List<String> list = patientService.findAllNurseLevel();
  144. result.put("code", 200);
  145. result.put("data", list);
  146. return result;
  147. }
  148. /**
  149. * 获取患者详情
  150. */
  151. @GetMapping("/detail/{id}")
  152. public Map<String, Object> detail(@PathVariable Long id) {
  153. Map<String, Object> result = new HashMap<>();
  154. Patient patient = patientService.findById(id);
  155. if (patient != null) {
  156. result.put("code", 200);
  157. result.put("data", patient);
  158. } else {
  159. result.put("code", 404);
  160. result.put("message", "患者不存在");
  161. }
  162. return result;
  163. }
  164. /**
  165. * 保存患者
  166. */
  167. @PostMapping("/save")
  168. public Map<String, Object> save(@RequestBody Patient patient) {
  169. Map<String, Object> result = new HashMap<>();
  170. try {
  171. patientService.save(patient);
  172. result.put("code", 200);
  173. result.put("message", "保存成功");
  174. } catch (Exception e) {
  175. result.put("code", 500);
  176. result.put("message", "保存失败:" + e.getMessage());
  177. }
  178. return result;
  179. }
  180. /**
  181. * 删除患者
  182. */
  183. @DeleteMapping("/delete/{id}")
  184. public Map<String, Object> delete(@PathVariable Long id) {
  185. Map<String, Object> result = new HashMap<>();
  186. try {
  187. patientService.deleteById(id);
  188. result.put("code", 200);
  189. result.put("message", "删除成功");
  190. } catch (Exception e) {
  191. result.put("code", 500);
  192. result.put("message", "删除失败:" + e.getMessage());
  193. }
  194. return result;
  195. }
  196. /**
  197. * 获取患者诊断信息列表(通过患者ID查询)
  198. */
  199. @GetMapping("/diagnosis/{patientId}")
  200. public Map<String, Object> getDiagnosisList(@PathVariable Long patientId) {
  201. Map<String, Object> result = new HashMap<>();
  202. try {
  203. List<PatientDiagnosis> list = patientDiagnosisService.findByPatientId(patientId);
  204. result.put("code", 200);
  205. result.put("data", list);
  206. } catch (Exception e) {
  207. result.put("code", 500);
  208. result.put("message", "获取诊断信息失败:" + e.getMessage());
  209. }
  210. return result;
  211. }
  212. /**
  213. * 获取患者诊断信息列表(通过身份证号查询)
  214. */
  215. @GetMapping("/diagnosis/idcard/{idCard}")
  216. public Map<String, Object> getDiagnosisListByIdCard(@PathVariable String idCard) {
  217. Map<String, Object> result = new HashMap<>();
  218. try {
  219. List<PatientDiagnosis> list = patientDiagnosisService.findByIdCard(idCard);
  220. result.put("code", 200);
  221. result.put("data", list);
  222. } catch (Exception e) {
  223. result.put("code", 500);
  224. result.put("message", "获取诊断信息失败:" + e.getMessage());
  225. }
  226. return result;
  227. }
  228. /**
  229. * 获取患者医嘱信息列表(通过患者ID查询)
  230. */
  231. @GetMapping("/orders/{patientId}")
  232. public Map<String, Object> getOrderList(@PathVariable Long patientId) {
  233. Map<String, Object> result = new HashMap<>();
  234. try {
  235. List<PatientOrder> list = patientOrderService.findByPatientId(patientId);
  236. result.put("code", 200);
  237. result.put("data", list);
  238. } catch (Exception e) {
  239. result.put("code", 500);
  240. result.put("message", "获取医嘱信息失败:" + e.getMessage());
  241. }
  242. return result;
  243. }
  244. /**
  245. * 获取患者费用信息列表(通过患者ID查询)
  246. */
  247. @GetMapping("/charges/{patientId}")
  248. public Map<String, Object> getChargeList(@PathVariable Long patientId) {
  249. Map<String, Object> result = new HashMap<>();
  250. try {
  251. List<PatientCharge> list = patientChargeService.findByPatientId(patientId);
  252. result.put("code", 200);
  253. result.put("data", list);
  254. } catch (Exception e) {
  255. result.put("code", 500);
  256. result.put("message", "获取费用信息失败:" + e.getMessage());
  257. }
  258. return result;
  259. }
  260. /**
  261. * 获取患者检查报告列表(通过患者ID查询)
  262. */
  263. @GetMapping("/exams/{patientId}")
  264. public Map<String, Object> getExamList(@PathVariable Long patientId) {
  265. Map<String, Object> result = new HashMap<>();
  266. try {
  267. List<PatientExam> list = patientExamService.findByPatientId(patientId);
  268. result.put("code", 200);
  269. result.put("data", list);
  270. } catch (Exception e) {
  271. result.put("code", 500);
  272. result.put("message", "获取检查报告失败:" + e.getMessage());
  273. }
  274. return result;
  275. }
  276. /**
  277. * 获取患者检验报告列表(通过患者表ID查询)
  278. */
  279. @GetMapping("/tests/{patientId}")
  280. public Map<String, Object> getTestList(@PathVariable Long patientId) {
  281. Map<String, Object> result = new HashMap<>();
  282. try {
  283. List<PatientTest> list = patientTestService.findByPatientTableId(patientId);
  284. result.put("code", 200);
  285. result.put("data", list);
  286. } catch (Exception e) {
  287. result.put("code", 500);
  288. result.put("message", "获取检验报告失败:" + e.getMessage());
  289. }
  290. return result;
  291. }
  292. /**
  293. * 获取检验报告项目明细列表(通过检验报告ID查询)
  294. */
  295. @GetMapping("/test-items/{testId}")
  296. public Map<String, Object> getTestItemList(@PathVariable Long testId) {
  297. Map<String, Object> result = new HashMap<>();
  298. try {
  299. List<PatientTestItem> list = patientTestItemService.findByTestId(testId);
  300. result.put("code", 200);
  301. result.put("data", list);
  302. } catch (Exception e) {
  303. result.put("code", 500);
  304. result.put("message", "获取检验项目明细失败:" + e.getMessage());
  305. }
  306. return result;
  307. }
  308. }