EmrControlRuleSever.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package thyyxxk.webserver.service.zhuyuanyisheng.emr;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.dynamic.datasource.annotation.DS;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.metadata.IPage;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.jetbrains.annotations.NotNull;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import thyyxxk.webserver.config.auth.PassToken;
  12. import thyyxxk.webserver.config.exception.BizException;
  13. import thyyxxk.webserver.config.exception.ExceptionEnum;
  14. import thyyxxk.webserver.dao.his.zhuyuanyisheng.emr.EmrControlDao;
  15. import thyyxxk.webserver.entity.ResultVo;
  16. import thyyxxk.webserver.entity.zhuyuanyisheng.emr.EmrLimitUnlock;
  17. import thyyxxk.webserver.entity.zhuyuanyisheng.emrcontrolrule.*;
  18. import thyyxxk.webserver.utils.*;
  19. import javax.servlet.http.HttpServletResponse;
  20. import java.util.*;
  21. /**
  22. * @author Administrator
  23. */
  24. @Service
  25. @Slf4j
  26. public class EmrControlRuleSever {
  27. private final EmrControlDao dao;
  28. public EmrControlRuleSever(EmrControlDao dao) {
  29. this.dao = dao;
  30. }
  31. public ResultVo<List<Map<String, Object>>> getAvailableObjects() {
  32. return ResultVoUtil.success(dao.getAvailableObjects());
  33. }
  34. public List<EmrRule> getRuleList() {
  35. List<EmrRule> list = dao.selectRules();
  36. if (ListUtil.isBlank(list)) {
  37. return new ArrayList<>();
  38. }
  39. list.forEach(item -> {
  40. item.setMedicalRecordCode(dao.selectEmrCodeByRuleId(item.getId()));
  41. });
  42. return list;
  43. }
  44. public ResultVo<String> switchQualityControl(String id, Integer offOn) {
  45. int num = dao.switchQualityControl(id, offOn);
  46. if (num > 0) {
  47. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  48. }
  49. return ResultVoUtil.success();
  50. }
  51. public ResultVo<String> deleteRuleById(String id) {
  52. dao.deleteRuleById(id);
  53. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  54. }
  55. /**
  56. * 修改入院质控时间
  57. *
  58. * @param date 时间
  59. * @return 提示
  60. */
  61. public ResultVo<String> modifyTheAdmissionQualityControlTime(String date) {
  62. dao.setTheTime(date);
  63. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  64. }
  65. public ResultVo<String> getAdmissDate() {
  66. return ResultVoUtil.success(dao.getAdmissDate());
  67. }
  68. /**
  69. * 创建病历的限制
  70. *
  71. * @param code 病历编码
  72. * @param patNo 住院号
  73. * @param times 住院次数
  74. * @param doctorLevel 医生等级
  75. * @param id 病历id
  76. * @return 返回提示
  77. */
  78. public ResultVo<EmrRuleVerify> createRestrictions(String code, String patNo, Integer times, Integer doctorLevel, String id) {
  79. log.info("病历编码:{},住院号:{},住院次数:{}", code, patNo, times);
  80. EmrRuleVerify ruleVerify = new EmrRuleVerify();
  81. // 获取质控的list
  82. List<EmrRule> ruleList = dao.selectRuleByEmrCode(code);
  83. // 如果质控的list为空就可以创建
  84. if (ListUtil.isBlank(ruleList)) {
  85. ruleVerify.setFlag(false);
  86. return ResultVoUtil.success(ruleVerify);
  87. }
  88. for (EmrRule item : ruleList) {
  89. String sql = item.getSql().replace("${PATNO}", "'" + patNo + "'")
  90. .replace("${TIMES}", "'" + times + "'");
  91. Map<String, Object> executeSql = dao.executeSql(sql);
  92. if (executeSql == null) {
  93. continue;
  94. }
  95. boolean whetherToTimeOut = false;
  96. if (doctorLevel == 1) {
  97. whetherToTimeOut = DateUtil.moreThanHours((Date) executeSql.get("date"), item.getPrescription());
  98. ruleVerify.setFlag(whetherToTimeOut);
  99. }
  100. if (doctorLevel > 1) {
  101. whetherToTimeOut = DateUtil.moreThanHours((Date) executeSql.get("date"), item.getSuperiorDoctorTime());
  102. }
  103. ruleVerify.setFlag(whetherToTimeOut);
  104. ruleVerify.setMessage(item.getPromptStatement());
  105. break;
  106. }
  107. log.info("ruleList:{}", JSON.toJSONString(ruleList));
  108. return ResultVoUtil.success(ruleVerify);
  109. }
  110. @Transactional(rollbackFor = Exception.class)
  111. public ResultVo<String> requestToUnlockMedicalRecords(EmrLimitUnlock param) {
  112. param.setApplicant(TokenUtil.getInstance().getTokenUserId());
  113. param.setApplicationTime(new Date());
  114. log.info("数据:{}", JSON.toJSONString(param));
  115. // 把原来地申请取消
  116. int count = dao.updateUnlockOld(param);
  117. String str = "申请成功,等待医务部审核。";
  118. if (count > 0) {
  119. str = "原申请已顶替,申请成功,等待医务部审核。";
  120. }
  121. int insert = dao.applicationUnlock(param);
  122. if (insert == 0) {
  123. throw new BizException(ExceptionEnum.ERROR_MESSAGE, "申请错误。");
  124. }
  125. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, str);
  126. }
  127. public ResultVo<IPage<EmrLimitUnlock>> getApplicationData(SelectUnlockParam param) {
  128. IPage<EmrLimitUnlock> iPage = new Page<>(param.getCurrentPage(), param.getPageSize(), param.getTotal() == 0);
  129. QueryWrapper<EmrLimitUnlock> qw = getEmrLimitUnlockQueryWrapper(param);
  130. iPage.setTotal(param.getTotal());
  131. return ResultVoUtil.success(dao.selectUnlock(iPage, qw));
  132. }
  133. @NotNull
  134. private static QueryWrapper<EmrLimitUnlock> getEmrLimitUnlockQueryWrapper(SelectUnlockParam param) {
  135. QueryWrapper<EmrLimitUnlock> qw = new QueryWrapper<>();
  136. if (ListUtil.notBlank(param.getDateRange())) {
  137. qw.ge("application_time", param.getDateRange().get(0));
  138. qw.lt("application_time", param.getDateRange().get(1));
  139. }
  140. if (param.getFlag() > -1) {
  141. qw.eq("state", param.getFlag());
  142. }
  143. return qw;
  144. }
  145. public void exportExcelUnlock(HttpServletResponse response, SelectUnlockParam param) {
  146. IPage<EmrLimitUnlock> iPage = new Page<>(param.getCurrentPage(), -1, false);
  147. QueryWrapper<EmrLimitUnlock> qw = getEmrLimitUnlockQueryWrapper(param);
  148. iPage = dao.selectUnlock(iPage, qw);
  149. if (ListUtil.isBlank(iPage.getRecords())) {
  150. return;
  151. }
  152. String[] title = {"住院号", "住院次数", "申请人", "申请时间", "申请权限", "申请编辑时间", "申请备注", "状态", "审核人", "审核时间", "审核备注"};
  153. String[][] content = new String[iPage.getRecords().size()][];
  154. for (int i = 0; i < iPage.getRecords().size(); i++) {
  155. content[i] = new String[title.length];
  156. EmrLimitUnlock index = iPage.getRecords().get(i);
  157. content[i][0] = index.getPatNo();
  158. content[i][1] = String.valueOf(index.getTimes());
  159. content[i][2] = index.getApplicantName();
  160. content[i][3] = DateUtil.formatDatetime(index.getApplicationTime());
  161. content[i][4] = index.getUnlockJson();
  162. content[i][5] = DateUtil.formatDatetime(index.getEffectiveTime());
  163. content[i][6] = index.getRequestRemarks();
  164. content[i][7] = index.getStateName();
  165. content[i][8] = index.getApproveName();
  166. content[i][9] = DateUtil.formatDatetime(index.getReviewTime());
  167. content[i][10] = index.getReviewNotes();
  168. }
  169. ExcelUtil.exportExcel(response, title, content);
  170. log.info("数据:{}", JSON.toJSONString(iPage));
  171. }
  172. public ResultVo<String> reviewMedicalRecordsToUnlock(EmrLimitUnlock param) {
  173. EmrLimitUnlock emrLimitUnlock = dao.selectUnlockById(param.getId());
  174. if (emrLimitUnlock.getState().equals(3)) {
  175. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该数据已经被申请人删除了,无法审核。");
  176. }
  177. if (emrLimitUnlock.getState().equals(param.getState())) {
  178. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请勿重复操作。");
  179. }
  180. param.setApprove(TokenUtil.getInstance().getTokenUserId());
  181. dao.updateUnlockByIdNew(param);
  182. log.info("电子病历质控审核:{}", JSON.toJSONString(param));
  183. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  184. }
  185. public ResultVo<EmrLimitUnlock> getMyUnlockByPatNo(String patNo, Integer times) {
  186. return ResultVoUtil.success(dao.selectMyUnlockReqByPatNo(patNo, times, TokenUtil.getInstance().getTokenUserId()));
  187. }
  188. }