Browse Source

合理用药功能开发完成

hurugang 2 năm trước cách đây
mục cha
commit
9d127435ae

+ 286 - 94
src/main/java/cn/hnthyy/thmz/controller/mz/MzChargeDetailController.java

@@ -86,6 +86,8 @@ public class MzChargeDetailController {
     private MzDepositFileService mzDepositFileService;
     @Autowired
     private MzVisitTableService mzVisitTableService;
+    @Autowired
+    private RationalUseService rationalUseService;
 
     /**
      * 查询费用列表
@@ -1560,86 +1562,93 @@ public class MzChargeDetailController {
     public Map<String, Object> savePrescription(@RequestBody MzPrescriptionVo mzPrescriptionVo, HttpServletRequest httpServletRequest) {
         Map<String, Object> resultMap = new HashMap<>();
         try {
-            User tokenUser = TokenUtil.getUser(httpServletRequest);
-            Clinic clinic = null;
-            List<String> deptCodes = userDeptRelationService.queryAllByUserIdCode(tokenUser.getUserIdCode());
-            Integer ghjzFlag = YesNoEnum.YES.code;
-            String deptCodeMghjz = null;
-            if (deptCodes != null && deptCodes.size() > 0) {
-                for (String deptCode : deptCodes) {
-                    ZdUnitCode zdUnitCode = zdUnitCodeService.queryByCode(deptCode);
-                    if (zdUnitCode != null && YesNoEnum.NO.code.equals(zdUnitCode.getGhjzFlag())) {
-                        ghjzFlag = YesNoEnum.NO.code;
-                        deptCodeMghjz = deptCode;
-                        break;
-                    }
-                }
-            }
-            //当前接诊医生所有可接诊科室含有免挂号接诊科室,且转诊id 和分诊流水号同时为空时,是免挂号接诊
-            if (YesNoEnum.NO.code.equals(ghjzFlag) && mzPrescriptionVo.getTurnToConsultationId() == null && StringUtils.isBlank(mzPrescriptionVo.getSerialNo())) {
-                //免挂号就诊
-                if (mzPrescriptionVo.getSerialNo().startsWith("clnicId_")) {
-                    Long clnicId = Long.valueOf(mzPrescriptionVo.getSerialNo().replace("clnicId_", ""));
-                    clinic = clinicService.queryById(clnicId);
-                }
-                mzPrescriptionVo.setVisitDeptCode(deptCodeMghjz);
-                mzPrescriptionVo.setSerialNo(null);
-            } else if (mzPrescriptionVo.getTurnToConsultationId() != null) {
-                //转诊接诊
-                TurnToConsultation turnToConsultation = turnToConsultationService.queryTurnToConsultationById(mzPrescriptionVo.getTurnToConsultationId());
-                if (turnToConsultation == null) {
-                    resultMap.put("code", -1);
-                    resultMap.put("message", "未查询到对应的会诊申请记录不存在");
-                    return resultMap;
-                }
-                if(StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())){
-                    mzPrescriptionVo.setVisitDeptCode(turnToConsultation.getTargetDeptNo());
-                }
-                mzPrescriptionVo.setSerialNo(null);
-            } else {
-                //正常就诊
-                if (StringUtils.isBlank(mzPrescriptionVo.getSerialNo())) {
-                    resultMap.put("code", -1);
-                    resultMap.put("message", "当前接诊患者的分诊流水号为空");
-                    return resultMap;
-                }
-                if (mzPrescriptionVo.getSerialNo().startsWith("clnicId_")) {
-                    Long clnicId = Long.valueOf(mzPrescriptionVo.getSerialNo().replace("clnicId_", ""));
-                    clinic = clinicService.queryById(clnicId);
-                    if (clinic == null) {
-                        resultMap.put("code", -1);
-                        resultMap.put("message", "未查询到历史就诊记录,clinicId=" + clnicId);
-                        return resultMap;
-                    }
-                    if(StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())){
-                        mzPrescriptionVo.setVisitDeptCode(clinic.getDeptCode());
-                    }
-                    mzPrescriptionVo.setSerialNo(null);
-                } else {
-                    MzfzPatientOrder mzfzPatientOrder = mzfzPatientOrderService.queryBySerialNo(mzPrescriptionVo.getSerialNo());
-                    if (mzfzPatientOrder == null) {
-                        resultMap.put("code", -1);
-                        resultMap.put("message", "当前接诊患者的分诊记录不存在");
-                        return resultMap;
-                    }
-                    if(StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())){
-                        mzPrescriptionVo.setVisitDeptCode(mzfzPatientOrder.getDeptCode());
-                    }
-                }
-            }
-            if (!deptCodes.contains(mzPrescriptionVo.getVisitDeptCode())) {
-                String requestDay=DateUtil.paseToString(DateUtil.getFirstSecond(),"yyyy-MM-dd");
-                List<String> ampms = mzZdWorkTimeService.getNotUsedWorkTimes(requestDay);
-                List<String> requestDepts=mzyRequestService.queryUnitCodeByRequestDayAndDoctor(requestDay,tokenUser.getUserIdCode(),ampms);
-                if(requestDepts!=null && requestDepts.size()>0){
-                    mzPrescriptionVo.setVisitDeptCode(requestDepts.get(0));
-                }else {
-                    //如果设置的医生接诊科室不在医生的科室列表中,说明是取的该患者上一次就诊医生所属科室,将当前医生的第一个科室替换成实际接诊科室
-                    mzPrescriptionVo.setVisitDeptCode(deptCodes.get(0));
-                }
+            //原方法开始
+//    User tokenUser = TokenUtil.getUser(httpServletRequest);
+//    Clinic clinic = null;
+//    List<String> deptCodes = userDeptRelationService.queryAllByUserIdCode(tokenUser.getUserIdCode());
+//    Integer ghjzFlag = YesNoEnum.YES.code;
+//    String deptCodeMghjz = null;
+//            if (deptCodes != null && deptCodes.size() > 0) {
+//                    for (String deptCode : deptCodes) {
+//                    ZdUnitCode zdUnitCode = zdUnitCodeService.queryByCode(deptCode);
+//                    if (zdUnitCode != null && YesNoEnum.NO.code.equals(zdUnitCode.getGhjzFlag())) {
+//                    ghjzFlag = YesNoEnum.NO.code;
+//                    deptCodeMghjz = deptCode;
+//                    break;
+//                    }
+//                    }
+//                    }
+//                    //当前接诊医生所有可接诊科室含有免挂号接诊科室,且转诊id 和分诊流水号同时为空时,是免挂号接诊
+//                    if (YesNoEnum.NO.code.equals(ghjzFlag) && mzPrescriptionVo.getTurnToConsultationId() == null && StringUtils.isBlank(mzPrescriptionVo.getSerialNo())) {
+//                    //免挂号就诊
+//                    if (mzPrescriptionVo.getSerialNo().startsWith("clnicId_")) {
+//                    Long clnicId = Long.valueOf(mzPrescriptionVo.getSerialNo().replace("clnicId_", ""));
+//                    clinic = clinicService.queryById(clnicId);
+//                    }
+//                    mzPrescriptionVo.setVisitDeptCode(deptCodeMghjz);
+//                    mzPrescriptionVo.setSerialNo(null);
+//                    } else if (mzPrescriptionVo.getTurnToConsultationId() != null) {
+//                    //转诊接诊
+//                    TurnToConsultation turnToConsultation = turnToConsultationService.queryTurnToConsultationById(mzPrescriptionVo.getTurnToConsultationId());
+//                    if (turnToConsultation == null) {
+//                    resultMap.put("code", -1);
+//                    resultMap.put("message", "未查询到对应的会诊申请记录不存在");
+//                    return resultMap;
+//                    }
+//                    if(StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())){
+//                    mzPrescriptionVo.setVisitDeptCode(turnToConsultation.getTargetDeptNo());
+//                    }
+//                    mzPrescriptionVo.setSerialNo(null);
+//                    } else {
+//                    //正常就诊
+//                    if (StringUtils.isBlank(mzPrescriptionVo.getSerialNo())) {
+//                    resultMap.put("code", -1);
+//                    resultMap.put("message", "当前接诊患者的分诊流水号为空");
+//                    return resultMap;
+//                    }
+//                    if (mzPrescriptionVo.getSerialNo().startsWith("clnicId_")) {
+//                    Long clnicId = Long.valueOf(mzPrescriptionVo.getSerialNo().replace("clnicId_", ""));
+//                    clinic = clinicService.queryById(clnicId);
+//                    if (clinic == null) {
+//                    resultMap.put("code", -1);
+//                    resultMap.put("message", "未查询到历史就诊记录,clinicId=" + clnicId);
+//                    return resultMap;
+//                    }
+//                    if(StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())){
+//                    mzPrescriptionVo.setVisitDeptCode(clinic.getDeptCode());
+//                    }
+//                    mzPrescriptionVo.setSerialNo(null);
+//                    } else {
+//                    MzfzPatientOrder mzfzPatientOrder = mzfzPatientOrderService.queryBySerialNo(mzPrescriptionVo.getSerialNo());
+//                    if (mzfzPatientOrder == null) {
+//                    resultMap.put("code", -1);
+//                    resultMap.put("message", "当前接诊患者的分诊记录不存在");
+//                    return resultMap;
+//                    }
+//                    if(StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())){
+//                    mzPrescriptionVo.setVisitDeptCode(mzfzPatientOrder.getDeptCode());
+//                    }
+//                    }
+//                    }
+//                    if (!deptCodes.contains(mzPrescriptionVo.getVisitDeptCode())) {
+//                    String requestDay=DateUtil.paseToString(DateUtil.getFirstSecond(),"yyyy-MM-dd");
+//                    List<String> ampms = mzZdWorkTimeService.getNotUsedWorkTimes(requestDay);
+//        List<String> requestDepts=mzyRequestService.queryUnitCodeByRequestDayAndDoctor(requestDay,tokenUser.getUserIdCode(),ampms);
+//        if(requestDepts!=null && requestDepts.size()>0){
+//        mzPrescriptionVo.setVisitDeptCode(requestDepts.get(0));
+//        }else {
+//        //如果设置的医生接诊科室不在医生的科室列表中,说明是取的该患者上一次就诊医生所属科室,将当前医生的第一个科室替换成实际接诊科室
+//        mzPrescriptionVo.setVisitDeptCode(deptCodes.get(0));
+//        }
+//        }
+//        mzPrescriptionVo.setDoctorCode(tokenUser.getUserIdCode());
+//        mzPrescriptionVo.setJzFlag(YesNoEnum.NO.code);
+            //原方法结束
+            CommonResult commonResult = new CommonResult(mzPrescriptionVo, httpServletRequest, resultMap).invoke();
+            if (commonResult.is()) {
+                return resultMap;
             }
-            mzPrescriptionVo.setDoctorCode(tokenUser.getUserIdCode());
-            mzPrescriptionVo.setJzFlag(YesNoEnum.NO.code);
+            Clinic clinic = commonResult.getClinic();
             Clinic insertClinic = mzChargeDetailService.savePrescription(mzPrescriptionVo, clinic);
             if (insertClinic != null && insertClinic.getId() != null) {
                 resultMap.put("code", 0);
@@ -2341,8 +2350,8 @@ public class MzChargeDetailController {
                 resultMap.put("message", "职工门诊统筹试算失败,用户Token不存在");
                 return resultMap;
             }
-            Clinic clinic= clinicService.queryByPatientIdAndTimesAndReceiptNo( mzPrescriptionVo.getPatientId(), mzPrescriptionVo.getTimes(),0);
-            PayInfo payInfo = tsmzService.directRegistration(tokenUser.getUserIdCode(), mzPrescriptionVo.getPatientId(), mzPrescriptionVo.getTimes(), mzPrescriptionVo.getReadCardResult(), mzPrescriptionVo.getGrzhzf(), mzPrescriptionVo.getReadCardType(),clinic==null?null:clinic.getExpContent());
+            Clinic clinic = clinicService.queryByPatientIdAndTimesAndReceiptNo(mzPrescriptionVo.getPatientId(), mzPrescriptionVo.getTimes(), 0);
+            PayInfo payInfo = tsmzService.directRegistration(tokenUser.getUserIdCode(), mzPrescriptionVo.getPatientId(), mzPrescriptionVo.getTimes(), mzPrescriptionVo.getReadCardResult(), mzPrescriptionVo.getGrzhzf(), mzPrescriptionVo.getReadCardType(), clinic == null ? null : clinic.getExpContent());
             if (payInfo == null) {
                 resultMap.put("code", -1);
                 resultMap.put("message", "职工门诊统筹试算失败,没有获取到结算信息");
@@ -2431,8 +2440,6 @@ public class MzChargeDetailController {
     }
 
 
-
-
     /**
      * 门诊统筹补录费用信息
      *
@@ -2441,7 +2448,7 @@ public class MzChargeDetailController {
      */
     @UserLoginToken
     @RequestMapping(value = "/mztcblInfo", method = {RequestMethod.GET})
-    public Map<String, Object> mztcblInfo(@RequestParam("patientId") String patientId,@RequestParam("times") Integer times,@RequestParam("receiptNo") Integer receiptNo) {
+    public Map<String, Object> mztcblInfo(@RequestParam("patientId") String patientId, @RequestParam("times") Integer times, @RequestParam("receiptNo") Integer receiptNo) {
         Map<String, Object> results = new HashMap<>();
         try {
             if (StringUtils.isBlank(patientId)) {
@@ -2449,21 +2456,21 @@ public class MzChargeDetailController {
                 results.put("message", "患者ID不能为空");
                 return results;
             }
-            if(times==null){
+            if (times == null) {
                 results.put("code", -1);
                 results.put("message", "患者就诊次数不能为空");
                 return results;
             }
-            if(receiptNo==null){
+            if (receiptNo == null) {
                 results.put("code", -1);
                 results.put("message", "患者缴费次数不能为空");
                 return results;
             }
             results.put("code", 0);
-            results.put("data", mzChargeDetailService.mztcblInfo(patientId,times,receiptNo));
+            results.put("data", mzChargeDetailService.mztcblInfo(patientId, times, receiptNo));
             results.put("message", "查询门诊统筹补录费用信息成功");
             return results;
-        }catch (MzException e) {
+        } catch (MzException e) {
             results.put("code", -1);
             results.put("message", e.getMessage());
             log.error("查询门诊统筹补录费用信息失败,错误信息{}", e);
@@ -2478,7 +2485,6 @@ public class MzChargeDetailController {
     }
 
 
-
     /**
      * 门诊统筹补录费用
      *
@@ -2487,7 +2493,7 @@ public class MzChargeDetailController {
      */
     @UserLoginToken
     @RequestMapping(value = "/chargeFeeForMztcbl", method = {RequestMethod.GET})
-    public Map<String, Object> chargeFeeForMztcbl(@RequestParam("patientId") String patientId,@RequestParam("times") Integer times,@RequestParam("receiptNo") Integer receiptNo, HttpServletRequest httpServletRequest) {
+    public Map<String, Object> chargeFeeForMztcbl(@RequestParam("patientId") String patientId, @RequestParam("times") Integer times, @RequestParam("receiptNo") Integer receiptNo, HttpServletRequest httpServletRequest) {
         Map<String, Object> results = new HashMap<>();
         try {
             if (StringUtils.isBlank(patientId)) {
@@ -2495,12 +2501,12 @@ public class MzChargeDetailController {
                 results.put("message", "患者ID不能为空");
                 return results;
             }
-            if(times==null){
+            if (times == null) {
                 results.put("code", -1);
                 results.put("message", "患者就诊次数不能为空");
                 return results;
             }
-            if(receiptNo==null){
+            if (receiptNo == null) {
                 results.put("code", -1);
                 results.put("message", "患者缴费次数不能为空");
                 return results;
@@ -2512,10 +2518,10 @@ public class MzChargeDetailController {
                 return results;
             }
             results.put("code", 0);
-            results.put("receiptNo", mzChargeDetailService.chargeFeeForMztcbl(patientId,times,receiptNo,tokenUser));
+            results.put("receiptNo", mzChargeDetailService.chargeFeeForMztcbl(patientId, times, receiptNo, tokenUser));
             results.put("message", "门诊统筹补录费用成功");
             return results;
-        }catch (MzException e) {
+        } catch (MzException e) {
             results.put("code", -1);
             results.put("message", e.getMessage());
             log.error("门诊统筹补录费用失败,错误信息{}", e);
@@ -2529,4 +2535,190 @@ public class MzChargeDetailController {
         }
     }
 
+
+    /**
+     * 合理用药分析
+     *
+     * @param mzPrescriptionVo
+     * @return
+     */
+    @UserLoginToken
+    @RequestMapping(value = "/rationalUseOfMedicine", method = {RequestMethod.POST})
+    public Map<String, Object> rationalUseOfMedicine(@RequestBody MzPrescriptionVo mzPrescriptionVo, HttpServletRequest httpServletRequest) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            CommonResult commonResult = new CommonResult(mzPrescriptionVo, httpServletRequest, resultMap).invoke();
+            if (commonResult.is()) {
+                return resultMap;
+            }
+            Map<String, Object> rationalUseMap = rationalUseService.rationalUseOfMedicine(mzPrescriptionVo);
+            if (rationalUseMap == null) {
+                rationalUseMap = new HashMap<>();
+                rationalUseMap.put("result_lv", 0);
+            }
+            resultMap.put("code", 0);
+            resultMap.put("data", rationalUseMap);
+            resultMap.put("message", "合理用药分析成功");
+            return resultMap;
+        } catch (MzException e) {
+            resultMap.put("code", -1);
+            resultMap.put("message", e.getMessage());
+            log.error("合理用药分析异常,错误信息{}", e.getMessage());
+            return resultMap;
+        } catch (Exception e) {
+            e.printStackTrace();
+            resultMap.put("code", -1);
+            resultMap.put("message", "合理用药分析失败,请联系管理员");
+            log.error("系统异常,错误信息{}", e);
+            return resultMap;
+        }
+    }
+
+
+    /**
+     * 获取药品审方状态
+     *
+     * @param params
+     * @return
+     */
+    @UserLoginToken
+    @RequestMapping(value = "/auditingInterface", method = {RequestMethod.POST})
+    public Map<String, Object> auditingInterface(@RequestBody Map<String, String> params) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            if (params == null || params.size() == 0) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "回查请求地址为空");
+                return resultMap;
+            }
+            String getResultUrl = params.get("getResultUrl");
+            if (getResultUrl == null || "null".equals(getResultUrl) || StringUtils.isBlank(getResultUrl)) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "回查请求地址为空");
+                return resultMap;
+            }
+            resultMap.put("code", 0);
+            resultMap.put("data", rationalUseService.auditingInterface(getResultUrl));
+            resultMap.put("message", "获取药品审方状态成功");
+            return resultMap;
+        } catch (Exception e) {
+            e.printStackTrace();
+            resultMap.put("code", -1);
+            resultMap.put("message", "获取药品审方状态失败,请联系管理员");
+            log.error("系统异常,错误信息{}", e);
+            return resultMap;
+        }
+    }
+
+
+    private class CommonResult {
+        private boolean myResult;
+        private MzPrescriptionVo mzPrescriptionVo;
+        private HttpServletRequest httpServletRequest;
+        private Map<String, Object> resultMap;
+        private Clinic clinic;
+
+        public CommonResult(MzPrescriptionVo mzPrescriptionVo, HttpServletRequest httpServletRequest, Map<String, Object> resultMap) {
+            this.mzPrescriptionVo = mzPrescriptionVo;
+            this.httpServletRequest = httpServletRequest;
+            this.resultMap = resultMap;
+        }
+
+        boolean is() {
+            return myResult;
+        }
+
+        public Clinic getClinic() {
+            return clinic;
+        }
+
+        public CommonResult invoke() throws MzException {
+            User tokenUser = TokenUtil.getUser(httpServletRequest);
+            clinic = null;
+            List<String> deptCodes = userDeptRelationService.queryAllByUserIdCode(tokenUser.getUserIdCode());
+            Integer ghjzFlag = YesNoEnum.YES.code;
+            String deptCodeMghjz = null;
+            if (deptCodes != null && deptCodes.size() > 0) {
+                for (String deptCode : deptCodes) {
+                    ZdUnitCode zdUnitCode = zdUnitCodeService.queryByCode(deptCode);
+                    if (zdUnitCode != null && YesNoEnum.NO.code.equals(zdUnitCode.getGhjzFlag())) {
+                        ghjzFlag = YesNoEnum.NO.code;
+                        deptCodeMghjz = deptCode;
+                        break;
+                    }
+                }
+            }
+            //当前接诊医生所有可接诊科室含有免挂号接诊科室,且转诊id 和分诊流水号同时为空时,是免挂号接诊
+            if (YesNoEnum.NO.code.equals(ghjzFlag) && mzPrescriptionVo.getTurnToConsultationId() == null && StringUtils.isBlank(mzPrescriptionVo.getSerialNo())) {
+                //免挂号就诊
+                if (mzPrescriptionVo.getSerialNo().startsWith("clnicId_")) {
+                    Long clnicId = Long.valueOf(mzPrescriptionVo.getSerialNo().replace("clnicId_", ""));
+                    clinic = clinicService.queryById(clnicId);
+                }
+                mzPrescriptionVo.setVisitDeptCode(deptCodeMghjz);
+                mzPrescriptionVo.setSerialNo(null);
+            } else if (mzPrescriptionVo.getTurnToConsultationId() != null) {
+                //转诊接诊
+                TurnToConsultation turnToConsultation = turnToConsultationService.queryTurnToConsultationById(mzPrescriptionVo.getTurnToConsultationId());
+                if (turnToConsultation == null) {
+                    resultMap.put("code", -1);
+                    resultMap.put("message", "未查询到对应的会诊申请记录不存在");
+                    myResult = true;
+                    return this;
+                }
+                if (StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())) {
+                    mzPrescriptionVo.setVisitDeptCode(turnToConsultation.getTargetDeptNo());
+                }
+                mzPrescriptionVo.setSerialNo(null);
+            } else {
+                //正常就诊
+                if (StringUtils.isBlank(mzPrescriptionVo.getSerialNo())) {
+                    resultMap.put("code", -1);
+                    resultMap.put("message", "当前接诊患者的分诊流水号为空");
+                    myResult = true;
+                    return this;
+                }
+                if (mzPrescriptionVo.getSerialNo().startsWith("clnicId_")) {
+                    Long clnicId = Long.valueOf(mzPrescriptionVo.getSerialNo().replace("clnicId_", ""));
+                    clinic = clinicService.queryById(clnicId);
+                    if (clinic == null) {
+                        resultMap.put("code", -1);
+                        resultMap.put("message", "未查询到历史就诊记录,clinicId=" + clnicId);
+                        myResult = true;
+                        return this;
+                    }
+                    if (StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())) {
+                        mzPrescriptionVo.setVisitDeptCode(clinic.getDeptCode());
+                    }
+                    mzPrescriptionVo.setSerialNo(null);
+                } else {
+                    MzfzPatientOrder mzfzPatientOrder = mzfzPatientOrderService.queryBySerialNo(mzPrescriptionVo.getSerialNo());
+                    if (mzfzPatientOrder == null) {
+                        resultMap.put("code", -1);
+                        resultMap.put("message", "当前接诊患者的分诊记录不存在");
+                        myResult = true;
+                        return this;
+                    }
+                    if (StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())) {
+                        mzPrescriptionVo.setVisitDeptCode(mzfzPatientOrder.getDeptCode());
+                    }
+                }
+            }
+            if (!deptCodes.contains(mzPrescriptionVo.getVisitDeptCode())) {
+                String requestDay = DateUtil.paseToString(DateUtil.getFirstSecond(), "yyyy-MM-dd");
+                List<String> ampms = mzZdWorkTimeService.getNotUsedWorkTimes(requestDay);
+                List<String> requestDepts = mzyRequestService.queryUnitCodeByRequestDayAndDoctor(requestDay, tokenUser.getUserIdCode(), ampms);
+                if (requestDepts != null && requestDepts.size() > 0) {
+                    mzPrescriptionVo.setVisitDeptCode(requestDepts.get(0));
+                } else {
+                    //如果设置的医生接诊科室不在医生的科室列表中,说明是取的该患者上一次就诊医生所属科室,将当前医生的第一个科室替换成实际接诊科室
+                    mzPrescriptionVo.setVisitDeptCode(deptCodes.get(0));
+                }
+            }
+            mzPrescriptionVo.setDoctorCode(tokenUser.getUserIdCode());
+            mzPrescriptionVo.setJzFlag(YesNoEnum.NO.code);
+            myResult = false;
+            return this;
+        }
+    }
 }

+ 22 - 0
src/main/java/cn/hnthyy/thmz/mapper/his/mz/MzChargeDetailMapper.java

@@ -1201,4 +1201,26 @@ public interface MzChargeDetailMapper {
      */
     @Select("select sum(( case when convert(decimal(18,2),unit_price)=0.00 then 0.01 else convert(decimal(18,2),unit_price) end )*quantity*drug_win) from  mz_charge_detail where patient_id =#{patientId} and times = #{times} and receipt_no=#{receiptNo} and pay_mark <> 2")
     BigDecimal selectSumAmount(@Param(value = "patientId") String patientId, @Param("times") Integer times, @Param("receiptNo") Integer receiptNo);
+
+
+
+    /**
+     * 根据患者id查询该患者当天的所有已缴费处方
+     *
+     * @param patientId
+     * @return
+     */
+    @Select("select rtrim(patient_id) patient_id,times,receipt_no,order_no,item_no,rtrim(charge_item_code) charge_item_code,rtrim(bill_item_code) bill_item_code,"+
+            "quantity,unit_price,rtrim(pay_mark) pay_mark,rtrim(serial) serial,rtrim(charge_item_type) charge_item_type,rtrim(country_flag) country_flag,rtrim(drug_flag) drug_flag,"+
+            "serial_no,rtrim(name) name,charge_date,confirm_time,rtrim(group_no) group_no,rtrim(confirm_id) confirm_id,drug_win,rtrim(input_id) input_id,input_date,"+
+            "rtrim(cashier_id) cashier_id,rtrim(windows_no) windows_no,rtrim(price_id) price_id,price_time,rtrim(exec_dept) exec_dept,rtrim(audit_code) audit_code,"+
+            "rtrim(gongnks_flag) gongnks_flag,rtrim(print_flag) print_flag,confirm_flag,rtrim(warn_dept) warn_dept,rtrim(jz_flag) jz_flag,group_order,rtrim(cash_id) cash_id,"+
+            "rtrim(doctor_code) doctor_code,rtrim(supply_code) supply_code,rtrim(frequency) frequency,drug_quan,rtrim(drug_unit) drug_unit,rtrim(doctor_flag) doctor_flag,inject_res,inject_times,"+
+            "rtrim(confirm_zs) confirm_zs,real_no,windows_no_yf,ybbx_flag,tc_no,tc_name,rtrim(detail_flag) detail_flag,gl_percent,rtrim(order_type) order_type,supply_no,instruction_code,"+
+            "instruction_text,order_days,rtrim(pay_self) pay_self,rtrim(try_flag) try_flag,rtrim(req_yj) req_yj,req_no,rtrim(group_type) group_type,order_bill,charge_bill_code,"+
+            "rtrim(self_flag) self_flag,rtrim(responce_type) responce_type,dec_amount,back_serial,input_time,cy_mtjs,cy_jsl,cy_zql,cy_fj,cy_ffcs,cy_fysm,supply_amount,rtrim(cy_jssm) cy_jssm,"+
+            "dept_no,gl_percent_ft,rtrim(yb_zf_flag) yb_zf_flag,orig_price,rtrim(try_result) try_result,rtrim(supply_exec) supply_exec,rtrim(cy_dj) cy_dj,rtrim(receive_flag) receive_flag,"+
+            "rtrim(chequ_type) chequ_type,rtrim(print_flag_yj) print_flag_yj,rtrim(confirm_flag_qx) confirm_flag_qx,group_id "+
+            " from  mz_charge_detail where patient_id=#{patientId} and pay_mark = 0 and confirm_flag<>4 and DateDiff(dd,charge_date,getDate()) =0 and group_no in('71','81','82') ")
+    List<MzChargeDetail> selectCurrentYpList(@Param("patientId") String patientId);
 }

+ 417 - 0
src/main/java/cn/hnthyy/thmz/service/impl/thmz/RationalUseServiceImpl.java

@@ -0,0 +1,417 @@
+package cn.hnthyy.thmz.service.impl.thmz;
+
+
+import cn.hnthyy.thmz.Utils.DateUtil;
+import cn.hnthyy.thmz.Utils.HttpUtil;
+import cn.hnthyy.thmz.Utils.JsonUtil;
+import cn.hnthyy.thmz.common.Constants;
+import cn.hnthyy.thmz.entity.MzException;
+import cn.hnthyy.thmz.entity.his.mz.Employee;
+import cn.hnthyy.thmz.entity.his.mz.MzChargeDetail;
+import cn.hnthyy.thmz.entity.his.mz.MzPatientMi;
+import cn.hnthyy.thmz.entity.his.mz.MzVisitTable;
+import cn.hnthyy.thmz.entity.his.yp.YpZdDict;
+import cn.hnthyy.thmz.entity.his.zd.ZdEmpTitle;
+import cn.hnthyy.thmz.enums.PayMarkEnum;
+import cn.hnthyy.thmz.enums.UnitTypeEnum;
+import cn.hnthyy.thmz.mapper.his.mz.MzChargeDetailMapper;
+import cn.hnthyy.thmz.mapper.his.mz.MzPatientMiMapper;
+import cn.hnthyy.thmz.mapper.thmz.ClinicMapper;
+import cn.hnthyy.thmz.service.his.mz.EmployeeService;
+import cn.hnthyy.thmz.service.his.mz.MzVisitTableService;
+import cn.hnthyy.thmz.service.his.yp.YpZdDictService;
+import cn.hnthyy.thmz.service.his.zd.ZdEmpTitleService;
+import cn.hnthyy.thmz.service.his.zd.ZdUnitCodeService;
+import cn.hnthyy.thmz.service.thmz.RationalUseService;
+import cn.hnthyy.thmz.vo.MzPrescriptionVo;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+
+import java.math.BigDecimal;
+import java.util.*;
+
+/**
+ * 合理用药
+ */
+@Service
+@Slf4j
+public class RationalUseServiceImpl implements RationalUseService {
+
+    @Value("${rationalUseOfMedicineUrl}")
+    private String rationalUseOfMedicineUrl;
+    @SuppressWarnings("all")
+    @Autowired
+    private ClinicMapper clinicMapper;
+    @Autowired
+    private EmployeeService employeeService;
+    @Autowired
+    private MzVisitTableService mzVisitTableService;
+    @Autowired
+    ZdUnitCodeService zdUnitCodeService;
+    @Autowired
+    private ZdEmpTitleService zdEmpTitleService;
+    @SuppressWarnings("all")
+    @Autowired
+    private MzChargeDetailMapper mzChargeDetailMapper;
+    @SuppressWarnings("all")
+    @Autowired
+    private MzPatientMiMapper mzPatientMiMapper;
+    @Autowired
+    private YpZdDictService ypZdDictService;
+
+    /**
+     * 提交药品分析
+     *
+     * @param mzPrescriptionVo
+     * @return
+     */
+    @Override
+    public Map<String, Object> rationalUseOfMedicine(MzPrescriptionVo mzPrescriptionVo) throws MzException {
+        // 医生信息
+        Map<String, String> doctorMap = doctorInfo(mzPrescriptionVo);
+        String baseXml = doctorMap.get("baseXml");
+        String doctXml = doctorMap.get("doct");
+        List<MzChargeDetail> mzChargeDetailList = mzPrescriptionVo.getMzChargeDetailList();
+        if (mzChargeDetailList == null || mzChargeDetailList.size() == 0) {
+            //非药品处方,无需判定
+            return null;
+        }
+        //Map<Integer,String> orderTypeMap = new HashMap<>();
+        Map<Integer, List<MzChargeDetail>> orderMap = new HashMap<>();
+        List<List<MzChargeDetail>> currentList = new ArrayList<>();
+        List<XunHuanJieDian> psLiust = new ArrayList<>();
+        for (MzChargeDetail mzChargeDetail : mzChargeDetailList) {
+            if (mzChargeDetail == null) {
+                continue;
+            }
+            if (Constants.YJ_GROUP_NO.equals(mzChargeDetail.getGroupNo())) {
+                continue;
+            }
+            List<MzChargeDetail> orderList = orderMap.get(mzChargeDetail.getOrderNo());
+            if (orderList == null) {
+                orderList = new ArrayList<>();
+                orderMap.put(mzChargeDetail.getOrderNo(), orderList);
+                currentList.add(orderList);
+            }
+            mzChargeDetail.setPayMark(PayMarkEnum.NO_CHARGE.code);
+            mzChargeDetail.setReceiptNo(1);
+            orderList.add(mzChargeDetail);
+            setTryResult(psLiust, mzChargeDetail);
+        }
+        if (orderMap.size() == 0) {
+            //无药品处方,无需判定
+            return null;
+        }
+        List<MzChargeDetail> hisDetails = mzChargeDetailMapper.selectCurrentYpList(mzPrescriptionVo.getPatientId());
+        List<List<MzChargeDetail>> hisList = new ArrayList<>();
+        Map<String, List<MzChargeDetail>> hisOrderMap = null;
+        if (hisDetails != null && hisDetails.size() > 0) {
+            hisOrderMap = new HashMap<>();
+            for (MzChargeDetail mzChargeDetail : hisDetails) {
+                if (mzChargeDetail == null) {
+                    continue;
+                }
+                if (Constants.YJ_GROUP_NO.equals(mzChargeDetail.getOrderNo())) {
+                    continue;
+                }
+                String key = mzChargeDetail.getTimes() + "_" + mzChargeDetail.getOrderNo();
+                List<MzChargeDetail> orderList = hisOrderMap.get(key);
+                if (orderList == null) {
+                    orderList = new ArrayList<>();
+                    hisOrderMap.put(key, orderList);
+                    hisList.add(orderList);
+                }
+                orderList.add(mzChargeDetail);
+                setTryResult(psLiust, mzChargeDetail);
+            }
+        }
+        String detailsXml = drugInfoFunc(currentList, hisList, mzPrescriptionVo.getPatientId(), psLiust, mzPrescriptionVo.getIcdCode(), mzPrescriptionVo.getIcdText(), doctXml);
+        String params = String.format("{\"BaseXml\": \"%s\", \"DetailsXml\" : \"%s\"}", baseXml, detailsXml);
+        log.info(params);
+        String data = HttpUtil.httpPost(rationalUseOfMedicineUrl, params, "application/json", 4000);
+        Map<String, Object> resultMap = (Map<String, Object>) JsonUtil.jsontoObject(data, Map.class);
+        log.info(data);
+        return resultMap;
+    }
+
+    private void setTryResult(List<XunHuanJieDian> psLiust, MzChargeDetail mzChargeDetail) {
+        if (StringUtils.isNotBlank(mzChargeDetail.getTryResult())) {
+            YpZdDict ypZdDict = ypZdDictService.queryYpZdDictByCodeAndSerial(mzChargeDetail.getChargeItemCode(), mzChargeDetail.getSerial());
+            XunHuanJieDian xunHuanJieDian = new XunHuanJieDian();
+            xunHuanJieDian.setCode(mzChargeDetail.getChargeItemCode());
+            xunHuanJieDian.setName(ypZdDict == null ? "" : ypZdDict.getName());
+            xunHuanJieDian.setResult(mzChargeDetail.getTryResult());
+            psLiust.add(xunHuanJieDian);
+        }
+    }
+
+    /**
+     * 获取药品审方状态
+     *
+     * @param url 审方地址
+     * @return 返回提示
+     */
+    @Override
+    public Map<String, Object> auditingInterface(String url) {
+        try {
+            String data = HttpUtil.sendHttpGet(url, "utf-8", 4000);
+            Map<String, Object> resultMap = (Map<String, Object>) JsonUtil.jsontoObject(data, Map.class);
+            log.info(data);
+            return resultMap;
+        } catch (Exception e) {
+            return new HashMap<>();
+        }
+
+    }
+
+
+    private Map<String, String> doctorInfo(MzPrescriptionVo mzPrescriptionVo) throws MzException {
+        Employee employee = employeeService.queryByUserCode(mzPrescriptionVo.getDoctorCode());
+        if (employee == null) {
+            throw new MzException("没有查询到开方医生信息!");
+        }
+        ZdEmpTitle zdEmpTitle = zdEmpTitleService.queryByCode(employee.getEmpTitCode());
+        String deptName = zdUnitCodeService.queryDeptNameByIdInCache(mzPrescriptionVo.getVisitDeptCode());
+        Map<String, String> map = new HashMap<>();
+        String baseXml = "<base_xml>" +
+                "<source>HIS</source>" +
+                "<hosp_code>H43010500370</hosp_code>" +
+                "<hosp_name>长沙泰和医院</hosp_name>" +
+                "<dept_code>" + nullToBlank(mzPrescriptionVo.getVisitDeptCode()) + "</dept_code>" +
+                "<dept_name>" + nullToBlank(deptName) + "</dept_name>" +
+                "<doct>" +
+                "<code>" + nullToBlank(mzPrescriptionVo.getDoctorCode()) + "</code>" +
+                "<name>" + nullToBlank(employee.getEmployeeName()) + "</name>" +
+                "<type>" + nullToBlank(employee.getEmpTitCode()) + "</type>" +
+                "<type_name>" + nullToBlank(zdEmpTitle == null ? "" : zdEmpTitle.getName()) + "</type_name>" +
+                "</doct>" +
+                "</base_xml>";
+        map.put("baseXml", baseXml);
+        String str = "<dept_code>" + nullToBlank(mzPrescriptionVo.getVisitDeptCode()) + "</dept_code>" +
+                "<dept_name>" + nullToBlank(deptName) + "</dept_name>" +
+                "<doct_code>" + nullToBlank(mzPrescriptionVo.getDoctorCode()) + "</doct_code>" +
+                "<doct_name>" + nullToBlank(employee.getEmployeeName()) + "</doct_name>";
+        map.put("doct", str);
+        return map;
+    }
+
+    private String nullToBlank(String str) {
+        if (StringUtils.isBlank(str)) {
+            return "";
+        }
+        return str.trim();
+    }
+
+    /**
+     * 构造药品参数
+     *
+     * @param currentList
+     * @param hisList
+     * @param patientId
+     * @param psLiust
+     * @param icdCode
+     * @param icdText
+     * @param doctXml
+     * @return
+     */
+    private String drugInfoFunc(List<List<MzChargeDetail>> currentList, List<List<MzChargeDetail>> hisList, String patientId, List<XunHuanJieDian> psLiust, String icdCode, String icdText, String doctXml) throws MzException {
+        int times = 0;
+        MzPatientMi mzPatientMi = mzPatientMiMapper.selectByPatientId(patientId);
+        if (mzPatientMi == null) {
+            throw new MzException("当前病人信息不存在,请先保存病人信息!");
+        }
+        MzVisitTable lastMzVisitTable = mzVisitTableService.queryLastMzVisitTableByPatientId(patientId);
+        if (lastMzVisitTable != null) {
+            times = lastMzVisitTable.getTimes();
+        }
+        if (mzPatientMi.getTimes() != null && mzPatientMi.getTimes() > times) {
+            times = mzPatientMi.getTimes();
+        }
+        String date = DateUtil.fomart(new Date(), "yyyy-MM-dd HH:mm:ss");
+        times++;
+        StringBuffer sbf = new StringBuffer();
+        sbf.append("<details_xml>")
+                .append("<hosp_code>H43010500370</hosp_code>")
+                .append("<his_time>").append(date).append("</his_time>")
+                .append("<hosp_flag>op</hosp_flag>")
+                // 中西药处方/医嘱类型标识
+                .append("<cf_type></cf_type>")
+                // 就诊类型
+                .append("<treat_type>").append("100").append("</treat_type>")
+                // 就诊号
+                .append("<treat_code>").append(patientId).append("_").append(times).append("_1").append("</treat_code>")
+                .append("<is_repeat>").append("1").append("</is_repeat>")
+                .append("<bed_no></bed_no>")
+                .append("<patient>")
+                .append("<pati_id>").append(patientId).append("</pati_id>")
+                .append("<name>").append(nullToBlank(mzPatientMi.getName())).append("</name>")
+                .append("<is_infant></is_infant>")
+                .append("<birth>").append(nullToBlank(mzPatientMi.getBirthDayStr())).append("</birth>")
+                .append("<sex>").append(nullToBlank(mzPatientMi.getGender())).append("</sex>")
+                .append("<weight></weight>")
+                .append("<height></height>")
+                .append("<id_card>").append(mzPatientMi.getSocialNo()).append("</id_card>")
+                .append("<medical_record></medical_record>")
+                .append("<card_type></card_type>")
+                .append("<card_code></card_code>")
+                .append("<pregnant_unit></pregnant_unit>")
+                .append("<pregnant></pregnant>");
+        //  过敏节点,可循环
+        sbf.append("<allergic_data>");
+        xunHuanJieDian(sbf, null, "allergic");
+        sbf.append("</allergic_data>");
+        // 皮试节点,可循环
+        sbf.append("<skintest_data>");
+        if (psLiust.size() == 0) {
+            XunHuanJieDian skinTest = new XunHuanJieDian();
+            skinTest.setCode("");
+            skinTest.setType("");
+            skinTest.setName("");
+            psLiust.add(skinTest);
+        }
+        for (XunHuanJieDian item : psLiust) {
+            sbf.append("<skintest>")
+                    .append("<name>").append(nullToBlank(item.getName())).append("</name>")
+                    .append("<code>").append(nullToBlank(item.getCode())).append("</code>")
+                    .append("<result>").append(nullToBlank(item.getResult())).append("</result>")
+                    .append("</skintest>");
+        }
+        sbf.append("</skintest_data>");
+        // 诊断
+        sbf.append("<diagnose_data>");
+        List<XunHuanJieDian> diagnosticData = new ArrayList<>();
+        List<String> arr = Arrays.asList(icdCode.split(","));
+        List<String> icdTextArr = Arrays.asList(icdText.split(","));
+        for (int i = 0; i < arr.size(); i++) {
+            String str = arr.get(i);
+            if (str == null || StringUtils.isBlank(str)) {
+                continue;
+            }
+            XunHuanJieDian xunHuanJieDian = new XunHuanJieDian();
+            xunHuanJieDian.setCode(str);
+            xunHuanJieDian.setType("0");
+            xunHuanJieDian.setName(icdTextArr.get(i));
+            diagnosticData.add(xunHuanJieDian);
+        }
+        // 诊断节点
+        xunHuanJieDian(sbf, diagnosticData, "diagnose");
+        sbf.append("</diagnose_data>").append("</patient>");
+        // 处方信息
+        sbf.append("<prescription_data>");
+        setYpDetail(currentList, patientId, doctXml, times, date, sbf);
+        if (hisList != null && hisList.size() > 0) {
+            setYpDetail(hisList, patientId, doctXml, times, date, sbf);
+        }
+        sbf.append("</prescription_data></details_xml>");
+        return sbf.toString();
+    }
+
+    private void setYpDetail(List<List<MzChargeDetail>> hisList, String patientId, String doctXml, int times, String date, StringBuffer sbf) {
+        for (List<MzChargeDetail> list : hisList) {
+            if (list == null || list.size() == 0) {
+                continue;
+            }
+            sbf.append("<prescription>").append("<id>").append(list.get(0).getOrderNo()).append("</id>").
+                    append("<reason>").append("</reason>")
+                    .append("<is_current>").append(PayMarkEnum.NO_CHARGE.code.equals(list.get(0).getPayMark()) ? "1" : "0").append("</is_current>")
+                    .append("<pres_type>").append("T").append("</pres_type>")
+                    .append("<pres_time>").append(date).append("</pres_time>").append("<medicine_data>");
+            for (MzChargeDetail mzChargeDetail : list) {
+                sbf.append("<medicine>")
+                        .append("<cf_id>").append(mzChargeDetail.getOrderNo()).append("</cf_id>")
+                        .append("<cf_type>");
+                if (Constants.ZY_GROUP_NO.equals(mzChargeDetail.getGroupNo()) || Constants.GRANULA_GROUP_NO.equals(mzChargeDetail.getGroupNo())) {
+                    //中药 颗粒剂中药
+                    sbf.append("3");
+                } else {
+                    //西药
+                    sbf.append("1");
+                }
+                YpZdDict ypZdDict = ypZdDictService.queryYpZdDictByCodeAndSerial(mzChargeDetail.getChargeItemCode(), mzChargeDetail.getSerial());
+                //BigDecimal drugWin= mzChargeDetail.getDrugWin()==null?BigDecimal.ONE:BigDecimal.valueOf(mzChargeDetail.getDrugWin());
+                BigDecimal quantity = mzChargeDetail.getQuantity() == null ? BigDecimal.ONE : BigDecimal.valueOf(mzChargeDetail.getQuantity());
+                sbf.append("</cf_type>")
+                        .append("<oeridid>").append(patientId).append("_").append(times).append("_").append(mzChargeDetail.getReceiptNo()).append("_").append(mzChargeDetail.getOrderNo()).append("</oeridid>")
+                        .append("<is_current>").append(PayMarkEnum.NO_CHARGE.code.equals(mzChargeDetail.getPayMark()) ? "1" : "0").append("</is_current>")
+                        .append("<pres_type>").append("T").append("</pres_type>")
+                        .append("<pres_time>").append(date).append("</pres_time>")
+                        .append("<name>").append(ypZdDict == null ? "" : ypZdDict.getName()).append("</name>")
+                        .append("<his_code>").append(nullToBlank(ypZdDict.getCode() + "_" + ypZdDict.getSerial())).append("</his_code>")
+                        .append("<insur_code>").append(nullToBlank(ypZdDict.getNationalCode())).append("</insur_code>")
+                        .append("<approval>").append(nullToBlank(ypZdDict.getPzwh())).append("</approval>")
+                        .append("<spec>").append(nullToBlank(ypZdDict.getSpecification())).append("</spec>")
+                        .append("<quantity>").append(nullToBlank(quantity + ypZdDict.getPackUnitDesc())).append("</quantity>")
+                        .append("<group>").append(mzChargeDetail.getGroupOrder()).append("</group>")
+                        .append("<reason>").append("</reason>")
+                        .append("<dose_unit>").append(StringUtils.isNotBlank(ypZdDict.getWeighUnit()) ? UnitTypeEnum.getUnitTypeByCode(mzChargeDetail.getDrugUnit()).name : "").append("</dose_unit>")
+                        .append("<dose>").append(mzChargeDetail.getDrugQuan()).append("</dose>")
+                        .append("<kyzl>").append("</kyzl>")
+                        .append("<zl_unit>").append("</zl_unit>")
+                        .append("<freq>").append("MZ").append(nullToBlank(mzChargeDetail.getFrequency())).append("</freq>")
+                        .append("<administer>").append("MZ").append(mzChargeDetail.getSupplyCode()).append("</administer>")
+                        .append("<begin_time></begin_time>")
+                        .append("<end_time></end_time>")
+                        .append("<days>").append("</days>")
+                        .append(doctXml)
+                        .append("<PREVENTIVE_TYPE>").append("0").append("</PREVENTIVE_TYPE>")
+                        .append("<money>").append(ypZdDict.getPackRetprice().multiply(quantity)).append("</money>")
+                        .append("</medicine>");
+            }
+            sbf.append("</medicine_data></prescription>");
+        }
+    }
+
+    private void xunHuanJieDian(StringBuffer sbf, List<XunHuanJieDian> jieDians, String name) {
+        if(jieDians == null){
+            jieDians=new ArrayList<>();
+        }
+        if (jieDians.size() == 0) {
+            XunHuanJieDian zhenDuan = new XunHuanJieDian();
+            zhenDuan.setCode("");
+            zhenDuan.setType("");
+            zhenDuan.setName("");
+            jieDians.add(zhenDuan);
+        }
+        for (XunHuanJieDian item : jieDians) {
+            sbf.append("<").append(name).append(">").
+                    append("<type>").append(nullToBlank(item.getType())).append("</type>")
+                    .append("<name>").append(nullToBlank(item.getName())).append("</name>")
+                    .append("<code>").append(nullToBlank(item.getCode())).append("</code>")
+                    .append("</").append(name).append(">");
+        }
+    }
+
+
+    @Data
+    private class XunHuanJieDian {
+        // 过敏节点,可循环
+        /**
+         * 过敏类型
+         */
+        private String type;
+        /**
+         * 过敏源名称
+         */
+        private String name;
+        /**
+         * 过敏源代码
+         */
+        private String code;
+
+        // 皮试
+        /**
+         * 皮试结果
+         */
+        private String result;
+    }
+}
+
+
+
+
+

+ 28 - 0
src/main/java/cn/hnthyy/thmz/service/thmz/RationalUseService.java

@@ -0,0 +1,28 @@
+package cn.hnthyy.thmz.service.thmz;
+
+
+import cn.hnthyy.thmz.entity.MzException;
+import cn.hnthyy.thmz.vo.MzPrescriptionVo;
+
+import java.util.Map;
+
+/**
+ * 合理用药
+ */
+public interface RationalUseService {
+    /**
+     * 提交药品分析
+     *
+     * @param mzPrescriptionVo
+     * @return
+     */
+    Map<String, Object> rationalUseOfMedicine(MzPrescriptionVo mzPrescriptionVo) throws MzException;
+
+    /**
+     * 获取药品审方状态
+     *
+     * @param url 审方地址
+     * @return 返回提示
+     */
+    Map<String, Object> auditingInterface(String url);
+}

+ 3 - 0
src/main/resources/application-dev.yml

@@ -159,3 +159,6 @@ webSocketPrescriptionHost: "ws://172.16.30.22:9000/"
 
 #websocket 药房发送信息接口地址
 webSocketServiceUrl: "http://172.16.30.22:9000/api/v1/sendMessage"
+
+#合理用药分析接口
+rationalUseOfMedicineUrl: "http://172.16.32.121:8016/Audit.ashx"

+ 4 - 1
src/main/resources/application-prod.yml

@@ -155,4 +155,7 @@ mzjsdHost: http://webhis.thyy.cn:8080
 webSocketPrescriptionHost: "ws://172.16.32.161:9000/"
 
 #websocket 药房发送信息接口地址
-webSocketServiceUrl: "http://172.16.32.161:9000/api/v1/sendMessage"
+webSocketServiceUrl: "http://172.16.32.161:9000/api/v1/sendMessage"
+
+#合理用药分析接口
+rationalUseOfMedicineUrl: "http://172.16.32.121:8016/Audit.ashx"

+ 125 - 0
src/main/resources/static/js/mz/clinic.js

@@ -22,6 +22,8 @@ var gropuIdAndOrderNoMap = null;
 var orderNoAndTableIdMap = null;
 //处方回调和修改的时候处方tab与处方号的关系
 var tableIdAndOrderNoMap = null;
+//合理用药查询审核结果url
+var getResultUrl=null;
 $(function () {
     initGenderSelect();
     iniAdmissStatus();
@@ -2214,6 +2216,7 @@ function clearWorkSpaceExcludeUser(source) {
         //prevCategoriesFlag = null;
         initGroupOrder();
         localStorage.removeItem("currentDeptNo");
+        getResultUrl=null;
     }
     $("#totalAmount").text(0);
 }
@@ -8608,6 +8611,127 @@ function getParamsForpPrescription(type) {
  * 保存处方
  */
 function savePrescription() {
+    var jsonData = getParamsForpPrescription(1);
+    $.ajax({
+        type: "POST",
+        url: '/thmz/rationalUseOfMedicine',
+        contentType: "application/json;charset=UTF-8",
+        dataType: "json",
+        data: JSON.stringify(jsonData),
+        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
+        success: function (res) {
+            if (res == '401' || res == 401) {
+                window.location.href = '/thmz/login/view'
+                return;
+            }
+            $("#messageButton").attr("disabled", false);
+            if (res.code == 0) {
+              var rationalUseMap= res.data;
+                var result_lv=rationalUseMap.result_lv;
+                if(result_lv==0|| result_lv=="0"){
+                    savePrescriptionForReadCard();
+                }else {
+                    var showUrl=rationalUseMap.ShowUrl;
+                    getResultUrl=rationalUseMap.getResultUrl;
+                    showHlyyModel(showUrl);
+                }
+            } else {
+                savePrescriptionForReadCard();
+            }
+        }
+    });
+}
+
+/**
+ * 合理用药结果查询
+ */
+function getResult() {
+    $.ajax({
+        type: "POST",
+        url: '/thmz/auditingInterface',
+        contentType: "application/json;charset=UTF-8",
+        dataType: "json",
+        data: JSON.stringify({"getResultUrl": getResultUrl}),
+        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
+        success: function (res) {
+            if (res == '401' || res == 401) {
+                window.location.href = '/thmz/login/view'
+                return;
+            }
+            $("#messageButton").attr("disabled", false);
+            $("#hlyyModal").modal("hide");
+            if (res.code == 0) {
+                var rationalUseMap= res.data;
+                if(rationalUseMap.length==0){
+                    savePrescriptionForReadCard();
+                }else {
+                    var resultcode=rationalUseMap.resultcode;
+                    var success=rationalUseMap.success;
+                    var sh_msg=rationalUseMap.sh_msg;
+                    if(resultcode==-1){
+                        //为处方不存在分析结果 直接忽略
+                        savePrescriptionForReadCard();
+                    }else if(resultcode==0){
+                        //2.success:药师审核完成标志,false未审核,true已审核/无需审核
+                        if(success==true || success=="true"){
+                            savePrescriptionForReadCard();
+                        }else {
+                            //提示消息
+                            $("#messageModal").modal();
+                            $("#messageContent").html("药师未审核,请点击右上方【继续保存】提交审核!");
+                            $("#messageButton").off("click").bind("click", function (t) {
+                                $("#messageModal").modal("hide");
+                                $("#hlyyModal").modal();
+                            });
+                            $("#cancelButton").off("click").bind("click", function (t) {
+                                $("#hlyyModal").modal();
+                            });;
+                        }
+
+                    }else if(resultcode==1){
+                      //提示消息
+                        $("#messageModal").modal();
+                        $("#messageContent").html(sh_msg);
+                        $("#messageButton").off("click").bind("click", function (t) {
+                            $("#messageModal").modal("hide");
+                        });
+                        $("#cancelButton").off("click");
+                    }
+                }
+            } else {
+                savePrescriptionForReadCard();
+            }
+        }
+    });
+}
+
+
+/**
+ * 合理用药结果弹窗
+ * @param showUrl
+ */
+function showHlyyModel(showUrl) {
+    const iframeEle = document.getElementById('hlyyDiv');
+    const loadingEle = document.getElementById('loading');
+    //设置ififrame透明
+    iframeEle.style.opacity = 0;
+    loadingEle.style.display = 'block';
+    $("#hlyyDiv").attr("src", showUrl);
+    iframeEle.addEventListener('load', function () {
+        // Hide the loading indicator
+        loadingEle.style.display = 'none';
+        // Bring the iframe back
+        iframeEle.style.opacity = 1;
+    });
+    $("#hlyyModal").modal();
+}
+
+
+
+/**
+ * 点击保存处方时提示是否读卡
+ */
+function savePrescriptionForReadCard() {
     if (!verifyInsuranceInfo()) {
         return;
     }
@@ -8637,6 +8761,7 @@ function savePrescription() {
 }
 
 
+
 /**
  * 最终保存处方方法
  * @param openModel 是否需要打开提示弹层 true 需要 false 不需要

+ 19 - 1
src/main/resources/templates/mz/clinic.html

@@ -3734,7 +3734,25 @@
 </div>
 <!--门诊统筹额外内容弹窗结尾-->
 
-
+<!--合理用药结果弹窗开始-->
+<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="hlyyModal">
+    <div class="modal-dialog modal-lg">
+        <div class="modal-content container" style="width: 800px;margin-left: 200px;height: 550px;">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
+                </button>
+                <h4 class="modal-title modal-title-thmz">合理用药分析结果</h4>
+            </div>
+            <div class="loading" id="loading" align="center" width="100%" height="550px" style="line-height: 450px;font-size: 50px;">合理用药分析结果正在加载,请稍等...</div>
+            <iframe id="hlyyDiv" align="center" width="100%" height="420px"  frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
+            <div class="modal-footer">
+            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
+            <button type="button" class="btn btn-primary" onclick="getResult()">继续提交</button>
+            </div>
+        </div>
+    </div>
+</div>
+<!--合理用药结果弹窗结尾-->
 
 
 <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>