| 
					
				 | 
			
			
				@@ -138,6 +138,7 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @SuppressWarnings("all") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private MzZdYpYshMapper mzZdYpYshMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public int countMzChargeDetail(MzChargeDetailPageDto mzChargeDetailPageDto) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         mzChargeDetailPageDto.setTableName("mz_charge_detail"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -756,6 +757,16 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public int savePrescription(MzPrescriptionVo mzPrescriptionVo, Clinic dbClinic) throws MzException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String realIcdText = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (mzPrescriptionVo.getIcdText() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            realIcdText = mzPrescriptionVo.getIcdText().replaceAll(",", ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isBlank(realIcdText)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                realIcdText = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (realIcdText == null && (mzPrescriptionVo.getMzBlRecord().getTentativeDiagnosis() == null || StringUtils.isBlank(mzPrescriptionVo.getMzBlRecord().getTentativeDiagnosis()))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new MzException("诊断和初步诊断不能同时为空!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         setFullMzPrescriptionVo(mzPrescriptionVo, true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (dbClinic != null && dbClinic.getId() != null && StringUtils.isNotBlank(dbClinic.getPatientId()) && dbClinic.getTimes() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             List<MzChargeDetail> dbMzChargeDetailList = mzChargeDetailMapper.selectNotPayMzChargeDetailByPatientId(mzPrescriptionVo.getPatientId(), dbClinic.getTimes()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -833,8 +844,8 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         clinic.setDoctorCode(mzPrescriptionVo.getDoctorCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         clinic.setOpId(mzPrescriptionVo.getDoctorCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         clinic.setOpDay(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        clinic.setIcdCode(mzPrescriptionVo.getIcdCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        clinic.setIcdText(mzPrescriptionVo.getIcdText()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        clinic.setIcdCode(realIcdText != null?mzPrescriptionVo.getIcdCode():null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        clinic.setIcdText(realIcdText != null?mzPrescriptionVo.getIcdText():mzPrescriptionVo.getMzBlRecord().getTentativeDiagnosis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         clinic.setClinicStatus(ClinicStatusEnum.HAD_CLINIC.code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         clinicMapper.insertClinic(clinic); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return 1; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -960,16 +971,16 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         int itemNo = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (mzPrescriptionVo.getMzChargeDetailList() != null && mzPrescriptionVo.getMzChargeDetailList().size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //处方类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Map<Integer,String> orderNoMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<Integer, String> orderNoMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //精一药品编码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Set<String> mjSet=null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Set<String> mjSet = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //精二药品编码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Set<String> jeSet=null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if(needPatient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                List<MzZdYpYsh> mjList = mzZdYpYshMapper.selectMjyByCommonParams(null, null, null,null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                List<MzZdYpYsh> jeList = mzZdYpYshMapper.selectJeByCommonParams(null, null, null,null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                mjSet=mjList.stream().map(m->m.getCode()).collect(Collectors.toSet()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                jeSet=jeList.stream().map(m->m.getCode()).collect(Collectors.toSet()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Set<String> jeSet = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (needPatient) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<MzZdYpYsh> mjList = mzZdYpYshMapper.selectMjyByCommonParams(null, null, null, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<MzZdYpYsh> jeList = mzZdYpYshMapper.selectJeByCommonParams(null, null, null, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                mjSet = mjList.stream().map(m -> m.getCode()).collect(Collectors.toSet()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                jeSet = jeList.stream().map(m -> m.getCode()).collect(Collectors.toSet()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (MzChargeDetail mzChargeDetail : mzPrescriptionVo.getMzChargeDetailList()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (StringUtils.isBlank(mzChargeDetail.getChargeItemCode())) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -996,20 +1007,20 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                if (StringUtils.isBlank(mzChargeDetail.getSupplyExec())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                    throw new MzException("保存处方失败,第" + itemNo + "行药品给药方式执行科室不能为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if(needPatient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (needPatient) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     //设置处方类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     String jzFlag = orderNoMap.get(mzChargeDetail.getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if(jzFlag==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        if(mjSet.contains(mzChargeDetail.getChargeItemCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            jzFlag="2"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        }else if(jeSet.contains(mzChargeDetail.getChargeItemCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            jzFlag="3"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        }else if(Constants.EMERGENCY_WARD_CODE.equals(mzPrescriptionVo.getVisitDeptCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            jzFlag="1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            jzFlag="0"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (jzFlag == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (mjSet.contains(mzChargeDetail.getChargeItemCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            jzFlag = "2"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } else if (jeSet.contains(mzChargeDetail.getChargeItemCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            jzFlag = "3"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } else if (Constants.EMERGENCY_WARD_CODE.equals(mzPrescriptionVo.getVisitDeptCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            jzFlag = "1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            jzFlag = "0"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        orderNoMap.put(mzChargeDetail.getOrderNo(),jzFlag); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        orderNoMap.put(mzChargeDetail.getOrderNo(), jzFlag); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     mzChargeDetail.setJzFlag(jzFlag); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1333,7 +1344,7 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //四舍五入 和套餐 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //List<String> otherList = Arrays.asList(Constants.XYF, Constants.ZCYF, Constants.CYF, Constants.SSWRF, Constants.TC); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<String> otherList = Arrays.asList(Constants.SSWRF, Constants.TC); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        int orderNo=0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int orderNo = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String, Object> resultMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (MzChargeDetail md : mzChargeDetails) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             BigDecimal unitPrice = md.getUnitPrice() == null ? BigDecimal.ZERO : md.getUnitPrice().setScale(2, BigDecimal.ROUND_HALF_UP); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1341,21 +1352,21 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 unitPrice = BigDecimal.valueOf(0.01D); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 md.setUnitPrice(unitPrice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if(otherList.contains(md.getBillItemCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (otherList.contains(md.getBillItemCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             BigDecimal tempAmount = unitPrice.multiply(BigDecimal.valueOf(md.getQuantity() == null ? 1D : md.getQuantity())).multiply(BigDecimal.valueOf(md.getDrugWin() == null ? 1D : md.getDrugWin())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             amount = amount.add(tempAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             String key = md.getOrderNo().toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            BigDecimal orderAmount=(BigDecimal)resultMap.get(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if(orderAmount==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                orderAmount=BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal orderAmount = (BigDecimal) resultMap.get(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (orderAmount == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                orderAmount = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if(md.getOrderNo()>orderNo){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                orderNo=md.getOrderNo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (md.getOrderNo() > orderNo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                orderNo = md.getOrderNo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orderAmount=orderAmount.add(tempAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            resultMap.put(key,orderAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            orderAmount = orderAmount.add(tempAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            resultMap.put(key, orderAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //            if (xyList.contains(md.getBillItemCode()) || Constants.YC_GROUP_NO.equals(md.getGroupNo())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                xyAmount = xyAmount.add(tempAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //            } else if (zyList.contains(md.getBillItemCode())) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1366,8 +1377,8 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             notDiscountAmount = notDiscountAmount.add((md.getOrigPrice() == null ? BigDecimal.ZERO : md.getOrigPrice()).multiply(BigDecimal.valueOf(md.getQuantity() == null ? 1D : md.getQuantity())).multiply(BigDecimal.valueOf(md.getDrugWin() == null ? 1D : md.getDrugWin()))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<BigDecimal> amountList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for(int i=1;i<=orderNo;i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            amountList.add((BigDecimal)resultMap.get(String.valueOf(i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 1; i <= orderNo; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            amountList.add((BigDecimal) resultMap.get(String.valueOf(i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             resultMap.remove(String.valueOf(i)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         discountAmount = notDiscountAmount.subtract(amount).setScale(1, BigDecimal.ROUND_HALF_UP); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1414,24 +1425,24 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return mzPrescriptionVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<MzChargeDetail> mzChargeDetailList = mzChargeDetailMapper.selectMzChargeDetailByPatientId(patientId, times, null, payMark); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<MzChargeDetail> removeList =null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<MzChargeDetail> removeList = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (MzChargeDetail mzChargeDetail : mzChargeDetailList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (PayMarkEnum.CHARGED.code.equals(payMark)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //对于已经收费的药品记录查询,只需要查询医生开立的药品,给要方式等记录需要过滤 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if(removeList==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (removeList == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     removeList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (YesNoEnum.YES.code != (mzChargeDetail.getGroupId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     removeList.add(mzChargeDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if("2".equals(mzChargeDetail.getJzFlag())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ("2".equals(mzChargeDetail.getJzFlag())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 mzChargeDetail.setGroupNo("111"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }else if("3".equals(mzChargeDetail.getJzFlag())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else if ("3".equals(mzChargeDetail.getJzFlag())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 mzChargeDetail.setGroupNo("131"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (PayMarkEnum.CHARGED.code.equals(payMark) && removeList!=null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (PayMarkEnum.CHARGED.code.equals(payMark) && removeList != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //对于已经收费的药品记录查询,只需要查询医生开立的药品,给要方式等记录需要过滤 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             mzChargeDetailList.removeAll(removeList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 |