| 
					
				 | 
			
			
				@@ -493,29 +493,58 @@ public class YiZhuLuRuServer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (StringUtil.isBlank(param.getInpatientNo())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请先选择患者."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Map<String, XinZhenYzActOrder> fatherAndSonDoctorSAdvice = new HashMap<>(param.getList().size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<BigDecimal> list = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        param.getList().forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            fatherAndSonDoctorSAdvice.put(item.getId(), item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            item.setActOrderNo(publicServer.getActOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            list.add(item.getActOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         XinZhenYiZhu huanZheXinXi = dao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 把模板的数据插入到医嘱 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        getThis().templateInsertToOrder(param, fatherAndSonDoctorSAdvice, huanZheXinXi); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getThis().templateInsertToOrder(treemapTransformation(param.getList(), list), huanZheXinXi); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "插入模板数据成功。", list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public void templateInsertToOrder(XinZhenYiZhu param, Map<String, XinZhenYzActOrder> fatherAndSonDoctorSAdvice, XinZhenYiZhu huanZheXinXi) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String userCode = TokenUtil.getTokenUserId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        param.getList().forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            String key = item.getParentNo() != null ? item.getParentNo().stripTrailingZeros().toPlainString() : ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (StringUtil.notBlank(key)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (fatherAndSonDoctorSAdvice.containsKey(key)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    item.setParentNo(fatherAndSonDoctorSAdvice.get(key).getActOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private List<XinZhenYzActOrder> treemapTransformation(List<XinZhenYzActOrder> list, List<BigDecimal> returnList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<XinZhenYzActOrder> resList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<BigDecimal, XinZhenYzActOrder> map = new HashMap<>(list.size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (XinZhenYzActOrder item : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (item.getParentNo() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                resList.add(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            map.put(item.getActOrderNo(), item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        list.forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (item.getParentNo() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                XinZhenYzActOrder mapItem = map.get(item.getParentNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (mapItem != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (mapItem.getChildren() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        mapItem.setChildren(new ArrayList<>()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    mapItem.getChildren().add(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<XinZhenYzActOrder> data = new LinkedList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resList.forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            item.setActOrderNo(publicServer.getActOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            data.add(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            returnList.add(item.getActOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (ListUtil.notBlank(item.getChildren())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.getChildren().forEach(children -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    children.setActOrderNo(publicServer.getActOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    children.setParentNo(item.getActOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    returnList.add(children.getActOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                data.addAll(item.getChildren()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void templateInsertToOrder(List<XinZhenYzActOrder> list, XinZhenYiZhu huanZheXinXi) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String userCode = TokenUtil.getTokenUserId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        list.forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             dao.insertEntryOrder(huanZheXinXi, item, userCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1512,9 +1541,6 @@ public class YiZhuLuRuServer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .eq("isnull(a.self_buy,'0')", "4"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         XinZhenYiZhu patInfo = dao.queryPatientInfo(patNo, times); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         patInfo.setList(dao.selectOrderNo(qw)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        if (dao.obtainTheNumberOfDischargedDrugs(patNo, times) > 出院带药限制数量) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "出院带药医嘱不得超过 4 种,且不得超过 15 天。"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String userCode = TokenUtil.getTokenUserId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 出院带药需要生成药单 key 是不同的药房。不同的药房就要 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String, List<XinZhenYzActOrder>> takeTheMedicineList = new HashMap<>(Capacity.TWO); 
			 |