|  | @@ -43,9 +43,7 @@ public class EmrServer {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          List<EmrPatientData> data = new ArrayList<>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        Map<String, List<EmrPatientData>> map = dao.getPatientData(patNo, times).stream().collect(
 | 
	
		
			
				|  |  | -                Collectors.groupingBy(EmrPatientData::getEmrCategoryCode)
 | 
	
		
			
				|  |  | -        );
 | 
	
		
			
				|  |  | +        Map<String, List<EmrPatientData>> map = dao.getPatientData(patNo, times).stream().collect(Collectors.groupingBy(EmrPatientData::getEmrCategoryCode));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          for (Map.Entry<String, List<EmrPatientData>> key : map.entrySet()) {
 | 
	
		
			
				|  |  |              if (key.getValue().size() == 1) {
 | 
	
	
		
			
				|  | @@ -65,12 +63,52 @@ public class EmrServer {
 | 
	
		
			
				|  |  |                  data.add(item);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          return ResultVoUtil.success(data);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public ResultVo<Boolean> existCourseRecord(String patNo, Integer times) {
 | 
	
		
			
				|  |  | -        return ResultVoUtil.success(dao.isThereARecordOfTheCourseOfTheDisease(patNo, times) > 0);
 | 
	
		
			
				|  |  | +    class ExtractData extends Thread {
 | 
	
		
			
				|  |  | +        private final EmrPatientData param;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        public ExtractData(EmrPatientData param) {
 | 
	
		
			
				|  |  | +            this.param = param;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        @Override
 | 
	
		
			
				|  |  | +        public void run() {
 | 
	
		
			
				|  |  | +            log.info("开始提取数据:{}", JSON.toJSONString(param));
 | 
	
		
			
				|  |  | +            extractDataElement(param);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public void extractDataElement(EmrPatientData param) {
 | 
	
		
			
				|  |  | +        EmrDataExtract 需要提取的数据源 = dao.extractDataSource(param.getEmrCategoryCode());
 | 
	
		
			
				|  |  | +        if (需要提取的数据源 == null) {
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<String> strings = JSON.parseArray(需要提取的数据源.getDataExtract(), String.class);
 | 
	
		
			
				|  |  | +        JSONObject elementData = JSONObject.parseObject(param.getEmrDataElement());
 | 
	
		
			
				|  |  | +        Map<String, Object> extractedData = new HashMap<>(strings.size());
 | 
	
		
			
				|  |  | +        for (String el : strings) {
 | 
	
		
			
				|  |  | +            if (elementData.containsKey(el)) {
 | 
	
		
			
				|  |  | +                JSONObject item = (JSONObject) elementData.get(el);
 | 
	
		
			
				|  |  | +                Object value = item.get("value");
 | 
	
		
			
				|  |  | +                if (value != null) {
 | 
	
		
			
				|  |  | +                    extractedData.put(el, value);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        EmrDataElement emrDataElement = dao.obtainPatientSOriginalData(param.getPatNo(), param.getTimes());
 | 
	
		
			
				|  |  | +        if (emrDataElement == null) {
 | 
	
		
			
				|  |  | +            dao.insertDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(extractedData));
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            JSONObject jsonObject = JSONObject.parseObject(emrDataElement.getDataElement());
 | 
	
		
			
				|  |  | +            log.info("患者原来的数据:{}", jsonObject);
 | 
	
		
			
				|  |  | +            jsonObject.putAll(extractedData);
 | 
	
		
			
				|  |  | +            dao.updatePatientDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(jsonObject));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        log.info("提取到的数据:{}", JSON.toJSONString(extractedData));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -81,13 +119,14 @@ public class EmrServer {
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public ResultVo<String> insertEmrData(EmrPatientData param) {
 | 
	
		
			
				|  |  |          param.setCreateId(TokenUtil.getTokenUserId());
 | 
	
		
			
				|  |  | -        if (dao.whetherThereIsAMedicalRecord(param.getPatNo(), param.getTimes(), param.getEmrDocumentId()).equals(1)) {
 | 
	
		
			
				|  |  | +        boolean isUpdated = dao.whetherThereIsAMedicalRecord(param.getPatNo(), param.getTimes(), param.getEmrDocumentId()).equals(1);
 | 
	
		
			
				|  |  | +        if (isUpdated) {
 | 
	
		
			
				|  |  |              dao.updateCreatedTemplate(param);
 | 
	
		
			
				|  |  | -            return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "保存成功,已覆盖原数据。");
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              dao.emrInsertForTheFirstTime(param);
 | 
	
		
			
				|  |  | -            return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "保存到本院成功");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        new ExtractData(param).start();
 | 
	
		
			
				|  |  | +        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, isUpdated ? "保存成功,已覆盖原数据。" : "保存到本院成功");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -112,36 +151,6 @@ public class EmrServer {
 | 
	
		
			
				|  |  |          return ResultVoUtil.success(dao.queryWhetherThePatientHasASpecifiedMedicalRecord(param.getPatNo(), param.getTimes(), param.getEmrCategoryCode()) == 1);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public ResultVo<String> extractDataElement(EmrDataElement param) {
 | 
	
		
			
				|  |  | -        EmrDataExtract 需要提取的数据源 = dao.extractDataSource(param.getCategoryCode());
 | 
	
		
			
				|  |  | -        if (需要提取的数据源 == null) {
 | 
	
		
			
				|  |  | -            return ResultVoUtil.success();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        List<String> strings = JSON.parseArray(需要提取的数据源.getDataExtract(), String.class);
 | 
	
		
			
				|  |  | -        JSONObject elementData = JSONObject.parseObject(param.getDataElement());
 | 
	
		
			
				|  |  | -        Map<String, Object> extractedData = new HashMap<>(strings.size());
 | 
	
		
			
				|  |  | -        for (String el : strings) {
 | 
	
		
			
				|  |  | -            if (elementData.containsKey(el)) {
 | 
	
		
			
				|  |  | -                JSONObject item = (JSONObject) elementData.get(el);
 | 
	
		
			
				|  |  | -                Object value = item.get("value");
 | 
	
		
			
				|  |  | -                if (value != null) {
 | 
	
		
			
				|  |  | -                    extractedData.put(el, value);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        EmrDataElement emrDataElement = dao.obtainPatientSOriginalData(param.getPatNo(), param.getTimes());
 | 
	
		
			
				|  |  | -        if (emrDataElement == null) {
 | 
	
		
			
				|  |  | -            log.info("提取到的数据:{}", JSON.toJSONString(extractedData));
 | 
	
		
			
				|  |  | -            dao.insertDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(extractedData));
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            JSONObject jsonObject = JSONObject.parseObject(emrDataElement.getDataElement());
 | 
	
		
			
				|  |  | -            jsonObject.putAll(extractedData);
 | 
	
		
			
				|  |  | -            dao.updatePatientDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(jsonObject));
 | 
	
		
			
				|  |  | -            log.info("患者原来的数据:{}", jsonObject);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        return ResultVoUtil.success();
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @DS("his")
 | 
	
		
			
				|  |  |      public void hotSearchSorting(String userCode, String code, String tableName) {
 |