EmrServer.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package thyyxxk.webserver.service.zhuyuanyisheng;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.stereotype.Service;
  4. import thyyxxk.webserver.config.exception.ExceptionEnum;
  5. import thyyxxk.webserver.dao.his.zhuyuanyisheng.EmrPatientDao;
  6. import thyyxxk.webserver.entity.ResultVo;
  7. import thyyxxk.webserver.entity.zhuyuanyisheng.EmrPatientData;
  8. import thyyxxk.webserver.utils.DateUtil;
  9. import thyyxxk.webserver.utils.ResultVoUtil;
  10. import thyyxxk.webserver.utils.TokenUtil;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import java.util.Map;
  14. import java.util.stream.Collectors;
  15. @Service
  16. @Slf4j
  17. public class EmrServer {
  18. private final EmrPatientDao dao;
  19. public EmrServer(EmrPatientDao dao) {
  20. this.dao = dao;
  21. }
  22. /**
  23. * 获取这个患者这个住院次数的全部电子病历
  24. *
  25. * @param patNo 住院号
  26. * @param times 住院次数
  27. * @return 数据
  28. */
  29. public ResultVo<List<EmrPatientData>> getPatientData(String patNo, Integer times) {
  30. List<EmrPatientData> data = new ArrayList<>();
  31. Map<String, List<EmrPatientData>> map = dao.getPatientData(patNo, times).stream().collect(
  32. Collectors.groupingBy(EmrPatientData::getEmrCategoryCode)
  33. );
  34. for (Map.Entry<String, List<EmrPatientData>> key : map.entrySet()) {
  35. if (key.getValue().size() == 1) {
  36. EmrPatientData parentNode = key.getValue().get(0);
  37. String name = parentNode.getName() + "/" + DateUtil.formatDatetime(parentNode.getModifyDate() != null ? parentNode.getModifyDate() : parentNode.getCreateDate());
  38. key.getValue().get(0).setName(name);
  39. data.add(key.getValue().get(0));
  40. } else {
  41. EmrPatientData item = new EmrPatientData();
  42. List<EmrPatientData> children = new ArrayList<>();
  43. for (int i = 0, len = key.getValue().size(); i < len; i++) {
  44. EmrPatientData childNode = key.getValue().get(i);
  45. String name = childNode.getName() + "/" + DateUtil.formatDatetime(childNode.getModifyDate() != null ? childNode.getModifyDate() : childNode.getCreateDate());
  46. childNode.setName(name);
  47. children.add(childNode);
  48. }
  49. item.setName(key.getValue().get(0).getEmrName());
  50. item.setChildren(new ArrayList<>()).getChildren().addAll(children);
  51. data.add(item);
  52. }
  53. }
  54. return ResultVoUtil.success(data);
  55. }
  56. /**
  57. * 保存患者电子病历信息
  58. *
  59. * @param param 参数
  60. * @return 提示
  61. */
  62. public ResultVo<String> insertEmrData(EmrPatientData param) {
  63. param.setCreateId(TokenUtil.getTokenUserId());
  64. if (dao.isThereARecordOfTheCourseOfTheDisease(param.getPatNo(), param.getTimes()) != null) {
  65. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "该患者已经存在病程记录了,请勿重新填写。");
  66. }
  67. try {
  68. dao.emrInsertForTheFirstTime(param);
  69. } catch (Exception e) {
  70. dao.updateCreatedTemplate(param);
  71. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "保存成功,已覆盖原数据。");
  72. }
  73. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "保存到本院成功");
  74. }
  75. /**
  76. * 根据患者的电子病历 id 来删除
  77. * 这里用的是逻辑删除
  78. *
  79. * @param documentId 电子病历id
  80. * @return 提示
  81. */
  82. public ResultVo<String> deletePatientEmrByDocumentId(String documentId) {
  83. dao.deletePatientEmrByDocumentId(documentId, TokenUtil.getTokenUserId());
  84. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "删除成功.");
  85. }
  86. }