|  | @@ -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;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |