|  | @ -4,6 +4,7 @@ import com.yihu.ehr.profile.family.ResourceCells;
 | 
	
		
			
				|  |  | import com.yihu.ehr.profile.model.InspectionInfo;
 | 
	
		
			
				|  |  | import com.yihu.ehr.profile.util.NumberValidationUtils;
 | 
	
		
			
				|  |  | import com.yihu.ehr.profile.util.SimpleSolrQueryUtil;
 | 
	
		
			
				|  |  | import com.yihu.ehr.util.datetime.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.ehr.util.rest.Envelop;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.util.StringUtils;
 | 
	
	
		
			
				|  | @ -83,7 +84,7 @@ public class ProfileInspectionService extends ProfileBasicService {
 | 
	
		
			
				|  |  |                 String subQ = "{\"q\":\"rowkey:" + temp.get("rowkey") + "$" + table + "$*\"}";
 | 
	
		
			
				|  |  |                 Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
 | 
	
		
			
				|  |  |                 List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
 | 
	
		
			
				|  |  |                 for (int i = 0; i < subList.size(); i ++) {
 | 
	
		
			
				|  |  |                 for (int i = 0; i < subList.size(); i++) {
 | 
	
		
			
				|  |  |                     Map<String, Object> item = subList.get(i);
 | 
	
		
			
				|  |  |                     //检查名称
 | 
	
		
			
				|  |  |                     if (!StringUtils.isEmpty(item.get("EHR_002883"))) {
 | 
	
	
		
			
				|  | @ -169,7 +170,7 @@ public class ProfileInspectionService extends ProfileBasicService {
 | 
	
		
			
				|  |  |                     if (item.get("EHR_000387") != null) {
 | 
	
		
			
				|  |  |                         //结果值
 | 
	
		
			
				|  |  |                         String result = item.get("EHR_000387").toString();
 | 
	
		
			
				|  |  |                         if (item.get("EHR_000391") != null && item.get("EHR_000390")!= null) {
 | 
	
		
			
				|  |  |                         if (item.get("EHR_000391") != null && item.get("EHR_000390") != null) {
 | 
	
		
			
				|  |  |                             //下限
 | 
	
		
			
				|  |  |                             String low = item.get("EHR_000391").toString();
 | 
	
		
			
				|  |  |                             //上限
 | 
	
	
		
			
				|  | @ -234,7 +235,7 @@ public class ProfileInspectionService extends ProfileBasicService {
 | 
	
		
			
				|  |  |                             //结果值
 | 
	
		
			
				|  |  |                             if (item.get("EHR_000387") != null) {
 | 
	
		
			
				|  |  |                                 String result = item.get("EHR_000387").toString();
 | 
	
		
			
				|  |  |                                 if (item.get("EHR_000391") != null && item.get("EHR_000390")!= null) {
 | 
	
		
			
				|  |  |                                 if (item.get("EHR_000391") != null && item.get("EHR_000390") != null) {
 | 
	
		
			
				|  |  |                                     //上限
 | 
	
		
			
				|  |  |                                     String low = item.get("EHR_000391").toString();
 | 
	
		
			
				|  |  |                                     //下限
 | 
	
	
		
			
				|  | @ -314,7 +315,7 @@ public class ProfileInspectionService extends ProfileBasicService {
 | 
	
		
			
				|  |  |                                             unknownMap.put(itemName, 1);
 | 
	
		
			
				|  |  |                                         }
 | 
	
		
			
				|  |  |                                     }
 | 
	
		
			
				|  |  |                                 } else  {
 | 
	
		
			
				|  |  |                                 } else {
 | 
	
		
			
				|  |  |                                     if (result.equals("阳性")) {
 | 
	
		
			
				|  |  |                                         if (positiveMap.containsKey(itemName)) {
 | 
	
		
			
				|  |  |                                             positiveMap.put(itemName, positiveMap.get(itemName) + 1);
 | 
	
	
		
			
				|  | @ -394,8 +395,152 @@ public class ProfileInspectionService extends ProfileBasicService {
 | 
	
		
			
				|  |  |         @Override
 | 
	
		
			
				|  |  |         public int compare(Map.Entry<String, Integer> me1, Map.Entry<String, Integer> me2) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             return - me1.getValue().compareTo(me2.getValue());
 | 
	
		
			
				|  |  |             return -me1.getValue().compareTo(me2.getValue());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /* **************************************** 区域检验平台 ********************************************  */
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List areaInspectionRecords(String orgCode, String deptCode, String dataSet,String patientName, String startDate, String endDate) throws Exception {
 | 
	
		
			
				|  |  |         List<Map<String, Object>> resultList = new ArrayList<>();
 | 
	
		
			
				|  |  |         Map<String, String> nameMap = new HashMap<>();
 | 
	
		
			
				|  |  |         //检查名称
 | 
	
		
			
				|  |  |         nameMap.put("HDSD00_79", "EHR_002883");
 | 
	
		
			
				|  |  |         //检验项目
 | 
	
		
			
				|  |  |         nameMap.put("HDSD00_77", "EHR_000352");
 | 
	
		
			
				|  |  |         startDate = DateUtil.stringToUtc(startDate, DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
 | 
	
		
			
				|  |  |         endDate = DateUtil.stringToUtc(endDate, DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
 | 
	
		
			
				|  |  |         String filter = "";
 | 
	
		
			
				|  |  |         //机构编码
 | 
	
		
			
				|  |  |         if (!StringUtils.isEmpty(orgCode)) {
 | 
	
		
			
				|  |  |             filter += "org_code="+orgCode;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //科室编码
 | 
	
		
			
				|  |  |         if (!StringUtils.isEmpty(deptCode)) {
 | 
	
		
			
				|  |  |             filter += "dept_code="+deptCode;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //填报者姓名
 | 
	
		
			
				|  |  |         if (!StringUtils.isEmpty(patientName)) {
 | 
	
		
			
				|  |  |             filter += "EHR_000378="+patientName;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         StringBuilder query = new StringBuilder("{\"q\":\"");
 | 
	
		
			
				|  |  |         if (!StringUtils.isEmpty(dataSet)) {
 | 
	
		
			
				|  |  |             query.append("rowkey:*").append(dataSet).append("*");
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             query.append("(rowkey:*HDSD00_79* OR rowkey:*HDSD00_77*)");//默认搜索检查及检验
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         query.append(" AND  event_date: [").append(startDate)
 | 
	
		
			
				|  |  |                 .append(" TO ").append(endDate).append("]\"}");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String queryStr = SimpleSolrQueryUtil.getQuery(filter, null, query.toString());
 | 
	
		
			
				|  |  |         Envelop subEnvelop = resource.getSubData(queryStr, 1, 2000, null);
 | 
	
		
			
				|  |  |         List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
 | 
	
		
			
				|  |  |         subList.forEach(item -> {
 | 
	
		
			
				|  |  |             Map<String, Object> resultMap = new HashMap<>();
 | 
	
		
			
				|  |  |             if (item != null) {
 | 
	
		
			
				|  |  |                 String itemName = "";
 | 
	
		
			
				|  |  |                 if (!StringUtils.isEmpty(dataSet)) {
 | 
	
		
			
				|  |  |                      itemName = (String) item.get(nameMap.get(dataSet));
 | 
	
		
			
				|  |  |                      if (StringUtils.isEmpty(itemName)) {
 | 
	
		
			
				|  |  |                          itemName = "-";
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     itemName = getItemName(item,nameMap.values());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 resultMap.put("itemName", itemName);
 | 
	
		
			
				|  |  |                 resultMap.put("type", dataSet);
 | 
	
		
			
				|  |  |                 resultMap.put("examDate", item.get("EHR_000366"));
 | 
	
		
			
				|  |  |                 resultMap.put("patientName", item.get("EHR_000378"));
 | 
	
		
			
				|  |  |                 resultMap.put("patientAge", item.get("patient_age"));
 | 
	
		
			
				|  |  |                 resultMap.put("patientSex", item.get("patient_sex"));
 | 
	
		
			
				|  |  |                 resultMap.put("dept",item.get("EHR_000365"));
 | 
	
		
			
				|  |  |                 resultMap.put("examiner",item.get("EHR_000367"));
 | 
	
		
			
				|  |  |                 resultMap.put("profileId", item.get(ResourceCells.ROWKEY));
 | 
	
		
			
				|  |  |                 resultList.add(resultMap);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |         return resultList;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *  获取检验档案详情
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param profileId  rowkey
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Map<String, String> inspectionDetail(String profileId) throws Exception {
 | 
	
		
			
				|  |  |         Map<String, String> dataMap = new HashMap<>();
 | 
	
		
			
				|  |  |         String subQ = "{\"q\":\"rowkey:" + profileId + "\"}";
 | 
	
		
			
				|  |  |         Envelop subData = resource.getSubData(subQ, 1, 1, null);
 | 
	
		
			
				|  |  |         List<Map<String, Object>> subList = subData.getDetailModelList();
 | 
	
		
			
				|  |  |         if (subList.size() > 0) {
 | 
	
		
			
				|  |  |             Map<String, Object> temp = subList.get(0);
 | 
	
		
			
				|  |  |             //检验报告单号
 | 
	
		
			
				|  |  |             String reportNo = temp.get("EHR_000363").toString();
 | 
	
		
			
				|  |  |             subQ = "{\"q\":\"rowkey:" + profileId.split("\\$")[0] + "$HDSD00_75$*" + "\"}";
 | 
	
		
			
				|  |  |             subData = resource.getSubData(subQ, 1, 1000, null);
 | 
	
		
			
				|  |  |             List<Map<String, Object>> subItems = subData.getDetailModelList();
 | 
	
		
			
				|  |  |             subItems.forEach(item -> {
 | 
	
		
			
				|  |  |                 //子项所属的报告单号
 | 
	
		
			
				|  |  |                 if (reportNo.equals(item.get("EHR_006339"))) {
 | 
	
		
			
				|  |  |                     //结果值
 | 
	
		
			
				|  |  |                     if (item.get("EHR_000387") != null) {
 | 
	
		
			
				|  |  |                         //结果值
 | 
	
		
			
				|  |  |                         String result = item.get("EHR_000387").toString();
 | 
	
		
			
				|  |  |                         if (item.get("EHR_000391") != null && item.get("EHR_000390") != null) {
 | 
	
		
			
				|  |  |                             //下限
 | 
	
		
			
				|  |  |                             String low = item.get("EHR_000391").toString();
 | 
	
		
			
				|  |  |                             //上限
 | 
	
		
			
				|  |  |                             String high = item.get("EHR_000390").toString();
 | 
	
		
			
				|  |  |                             if (NumberValidationUtils.isRealNumber(result) && NumberValidationUtils.isRealNumber(low) && NumberValidationUtils.isRealNumber(high)) {
 | 
	
		
			
				|  |  |                                 Double _result = Double.parseDouble(result);
 | 
	
		
			
				|  |  |                                 Double _row = Double.parseDouble(low);
 | 
	
		
			
				|  |  |                                 Double _high = Double.parseDouble(high);
 | 
	
		
			
				|  |  |                                 if (_result < _row) {
 | 
	
		
			
				|  |  |                                     dataMap.put(item.get("EHR_000394").toString(), "偏低");
 | 
	
		
			
				|  |  |                                 } else if (_result > _high) {
 | 
	
		
			
				|  |  |                                     dataMap.put(item.get("EHR_000394").toString(), "偏高");
 | 
	
		
			
				|  |  |                                 } else {
 | 
	
		
			
				|  |  |                                     dataMap.put(item.get("EHR_000394").toString(), "正常");
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                             } else {
 | 
	
		
			
				|  |  |                                 dataMap.put(item.get("EHR_000394").toString(), item.get("EHR_000387").toString());
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             dataMap.put(item.get("EHR_000394").toString(), item.get("EHR_000387").toString());
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         dataMap.put(item.get("EHR_000394").toString(), "");
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return dataMap;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *  获取检验报告名称
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param itemMap   资源数据
 | 
	
		
			
				|  |  |      * @param nameList  名称集合
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getItemName(Map<String, Object> itemMap, Collection<String> nameList){
 | 
	
		
			
				|  |  |         String itemName ="-";
 | 
	
		
			
				|  |  |         for (String key : nameList) {
 | 
	
		
			
				|  |  |             if (itemMap.get(key)!=null) {
 | 
	
		
			
				|  |  |                 itemName = (String) itemMap.get(key);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return itemName;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |