|
@@ -1,27 +1,23 @@
|
|
|
package com.lantone.qc.kernel.util;
|
|
|
|
|
|
-
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.common.collect.Sets;
|
|
|
import com.lantone.qc.nlp.participle.cfg.Configuration;
|
|
|
import com.lantone.qc.nlp.participle.cfg.DefaultConfig;
|
|
|
import com.lantone.qc.pub.util.FastJsonUtils;
|
|
|
-import com.lantone.qc.pub.util.FileUtil;
|
|
|
+import com.lantone.qc.pub.util.StringUtil;
|
|
|
import com.lantone.qc.trans.comsis.ModuleMappingUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.ApplicationArguments;
|
|
|
import org.springframework.boot.ApplicationRunner;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.util.ResourceUtils;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.FileNotFoundException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
@@ -37,43 +33,51 @@ import java.util.Set;
|
|
|
* @Author : 楼辉荣
|
|
|
* @Date: 2020-03-11 11:42
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Component
|
|
|
public class CacheUtil implements ApplicationRunner {
|
|
|
- Logger logger = LoggerFactory.getLogger(DefaultConfig.class);
|
|
|
+ private Configuration configuration = new DefaultConfig();
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
-
|
|
|
@Value("${qc.hospital_id}")
|
|
|
- private String hospitalId;
|
|
|
+ private String hospitalIds;
|
|
|
|
|
|
public void run(ApplicationArguments var1) {
|
|
|
- try {
|
|
|
- this.loadModuleMappingInfo();//加载页面模板映射信息
|
|
|
- this.putConceptDiagPropertyMap();//疾病相关信息放入缓存 包括疾病是否是慢病、传染病、常见症状、同义词
|
|
|
- this.putHospitalDiagMap();//医院疾病信息
|
|
|
- this.putHospitalDiagHuaZMap();//医院华卓映射
|
|
|
- this.putLantoneDiagHuaZMap();//朗通华卓映射
|
|
|
- this.putClinicBodyPartMap();//症状需要部位描述词典放入redis缓存
|
|
|
- this.putHospitalDoctorInfoMap();//症状需要部位描述词典放入redis缓存
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("缓存文件读取错误。。。");
|
|
|
+ if (StringUtil.isBlank(hospitalIds)) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ for (String i : hospitalIds.split(",")) {
|
|
|
+ if (StringUtil.isBlank(i)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ redisUtil.getHospitalCache().put(i, Maps.newHashMap());
|
|
|
+ this.loadModuleMappingInfo(i);//加载页面模板映射信息
|
|
|
+ this.putConceptDiagPropertyMap(i);//疾病相关信息放入缓存 包括疾病是否是慢病、传染病、常见症状、同义词
|
|
|
+ this.putHospitalDiagMap(i);//医院疾病信息
|
|
|
+ this.putHospitalDiagHuaZMap(i);//医院华卓映射
|
|
|
+ this.putLantoneDiagHuaZMap(i);//朗通华卓映射
|
|
|
+ this.putClinicBodyPartMap(i);//症状需要部位描述词典放入redis缓存
|
|
|
+ this.putHospitalDoctorInfoMap(i);//症状需要部位描述词典放入redis缓存
|
|
|
+ }
|
|
|
+ log.info("缓存加载完成!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 加载页面模板映射信息
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
*/
|
|
|
- private void loadModuleMappingInfo() {
|
|
|
+ private void loadModuleMappingInfo(String hospitalId) {
|
|
|
List<String> xmlDataTypeHospitalIds = Lists.newArrayList("1", "3");
|
|
|
try {
|
|
|
InputStream stream = getClass().getClassLoader().getResourceAsStream("cache/" + hospitalId + "/module_mapping.json");
|
|
|
- File targetFile = new File("module_mapping.json");
|
|
|
+ File targetFile = new File("cache/" + hospitalId + "/module_mapping.json");
|
|
|
FileUtils.copyInputStreamToFile(stream, targetFile);
|
|
|
String mappingMsg = FileUtils.readFileToString(targetFile);
|
|
|
-// logger.error("模板数据:"+mappingMsg);
|
|
|
+ // logger.error("模板数据:"+mappingMsg);
|
|
|
|
|
|
-// String path = ResourceUtils.getURL("classpath:").getPath() + "cache/" + hospitalId + "/module_mapping.json";
|
|
|
-// String mappingMsg = FileUtil.fileRead(path);
|
|
|
+ // String path = ResourceUtils.getURL("classpath:").getPath() + "cache/" + hospitalId + "/module_mapping.json";
|
|
|
+ // String mappingMsg = FileUtil.fileRead(path);
|
|
|
if (xmlDataTypeHospitalIds.contains(hospitalId)) {
|
|
|
Map<String, Long> mapKeysModuleInfoIdMap = (Map) FastJsonUtils.getJsonToMap(mappingMsg);
|
|
|
Map<Set<String>, String> xmlDataTypeModuleInfo = Maps.newHashMap();
|
|
@@ -88,131 +92,160 @@ public class CacheUtil implements ApplicationRunner {
|
|
|
});
|
|
|
xmlDataTypeModuleInfo.put(Sets.newLinkedHashSet(list), entry.getValue() + "");
|
|
|
}
|
|
|
-// mapKeysModuleInfoIdMap.keySet().forEach(mapKeys -> {
|
|
|
-// xmlDataTypeModuleInfo.put(Sets.newLinkedHashSet(Arrays.asList(mapKeys.split(","))), mapKeysModuleInfoIdMap.get(mapKeys) + "");
|
|
|
-// });
|
|
|
- ModuleMappingUtil.xmlDataTypeModuleInfo = xmlDataTypeModuleInfo;
|
|
|
+ // mapKeysModuleInfoIdMap.keySet().forEach(mapKeys -> {
|
|
|
+ // xmlDataTypeModuleInfo.put(Sets.newLinkedHashSet(Arrays.asList(mapKeys.split(","))), mapKeysModuleInfoIdMap.get(mapKeys) + "");
|
|
|
+ // });
|
|
|
+ ModuleMappingUtil.xmlDataTypeModuleInfo.put(hospitalId, xmlDataTypeModuleInfo);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 疾病相关信息放入缓存
|
|
|
* 包括疾病是否是慢病、传染病、常见症状、同义词
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
*/
|
|
|
- public void putConceptDiagPropertyMap() throws Exception {
|
|
|
- Configuration configuration = new DefaultConfig();
|
|
|
- List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/concept_diag_properties.dict");
|
|
|
-
|
|
|
- Map<String, Map<String, Object>> diagMap = new HashMap<>();
|
|
|
- for (String line : lines) {
|
|
|
- String[] line_arr = line.split("\\|", -1);
|
|
|
- if (line_arr.length == 5) {
|
|
|
- List<String> synonymsList = new ArrayList<>();
|
|
|
- List<String> symptomsList = new ArrayList<>();
|
|
|
- if (StringUtils.isNotEmpty(line_arr[3])) {
|
|
|
- line_arr[3] = line_arr[3].trim();
|
|
|
- synonymsList = java.util.Arrays.asList(line_arr[3].split(","));
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(line_arr[4])) {
|
|
|
- line_arr[4] = line_arr[4].trim();
|
|
|
- symptomsList = java.util.Arrays.asList(line_arr[4].split(","));
|
|
|
+ public void putConceptDiagPropertyMap(String hospitalId) {
|
|
|
+ try {
|
|
|
+ List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/concept_diag_properties.dict");
|
|
|
+
|
|
|
+ Map<String, Map<String, Object>> diagMap = new HashMap<>();
|
|
|
+ for (String line : lines) {
|
|
|
+ String[] line_arr = line.split("\\|", -1);
|
|
|
+ if (line_arr.length == 5) {
|
|
|
+ List<String> synonymsList = new ArrayList<>();
|
|
|
+ List<String> symptomsList = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotEmpty(line_arr[3])) {
|
|
|
+ line_arr[3] = line_arr[3].trim();
|
|
|
+ synonymsList = java.util.Arrays.asList(line_arr[3].split(","));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(line_arr[4])) {
|
|
|
+ line_arr[4] = line_arr[4].trim();
|
|
|
+ symptomsList = java.util.Arrays.asList(line_arr[4].split(","));
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("infectious", line_arr[2].trim());
|
|
|
+ map.put("chronic", line_arr[1].trim());
|
|
|
+ map.put("synonyms", synonymsList);
|
|
|
+ map.put("symptoms", symptomsList);
|
|
|
+ diagMap.put(line_arr[0], map);
|
|
|
}
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("infectious", line_arr[2].trim());
|
|
|
- map.put("chronic", line_arr[1].trim());
|
|
|
- map.put("synonyms", synonymsList);
|
|
|
- map.put("symptoms", symptomsList);
|
|
|
- diagMap.put(line_arr[0], map);
|
|
|
}
|
|
|
+ redisUtil.setValByHospitalId(hospitalId, KernelConstants.CONCEPT_DIAG_PROPERTY_MAP, diagMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
- redisUtil.setJsonStringValue(KernelConstants.CONCEPT_DIAG_PROPERTY_MAP, diagMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 医院医生信息
|
|
|
*
|
|
|
- * @throws Exception
|
|
|
+ * @param hospitalId
|
|
|
*/
|
|
|
- public void putHospitalDoctorInfoMap() throws Exception {
|
|
|
- Configuration configuration = new DefaultConfig();
|
|
|
- List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_doctor_info.dict");
|
|
|
-
|
|
|
- Map<String, Map<String, Object>> hospitalDoctorMap = new HashMap<>();
|
|
|
- for (String line : lines) {
|
|
|
- String[] line_arr = line.split("\\|", -1);
|
|
|
- if (line_arr.length == 4) {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("doctorName", line_arr[0]);
|
|
|
- map.put("deptName", line_arr[1]);
|
|
|
- map.put("professor", line_arr[2]);
|
|
|
- map.put("occup", line_arr[3]);
|
|
|
- hospitalDoctorMap.put(line_arr[0], map);
|
|
|
+ public void putHospitalDoctorInfoMap(String hospitalId) {
|
|
|
+ try {
|
|
|
+ List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_doctor_info.dict");
|
|
|
+
|
|
|
+ Map<String, Map<String, Object>> hospitalDoctorMap = new HashMap<>();
|
|
|
+ for (String line : lines) {
|
|
|
+ String[] line_arr = line.split("\\|", -1);
|
|
|
+ if (line_arr.length == 4) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("doctorName", line_arr[0]);
|
|
|
+ map.put("deptName", line_arr[1]);
|
|
|
+ map.put("professor", line_arr[2]);
|
|
|
+ map.put("occup", line_arr[3]);
|
|
|
+ hospitalDoctorMap.put(line_arr[0], map);
|
|
|
+ }
|
|
|
}
|
|
|
+ redisUtil.setValByHospitalId(hospitalId, KernelConstants.HOSPITAL_DOCTOR_MAP, hospitalDoctorMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
- redisUtil.setJsonStringValue(KernelConstants.HOSPITAL_DOCTOR_MAP, hospitalDoctorMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 医院疾病信息放入redis缓存
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
*/
|
|
|
- public void putHospitalDiagMap() throws Exception {
|
|
|
- Configuration configuration = new DefaultConfig();
|
|
|
- List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
|
|
|
- Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
|
|
|
- for (String line : lines) {
|
|
|
- Map<String, String> detail = new HashMap<>();
|
|
|
- detail.put("name", line.trim());
|
|
|
- detail.put("icd10", "A001");
|
|
|
- hospitalDiagMap.put(line, detail);
|
|
|
+ public void putHospitalDiagMap(String hospitalId) {
|
|
|
+ try {
|
|
|
+ List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
|
|
|
+ Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
|
|
|
+ for (String line : lines) {
|
|
|
+ Map<String, String> detail = new HashMap<>();
|
|
|
+ detail.put("name", line.trim());
|
|
|
+ detail.put("icd10", "A001");
|
|
|
+ hospitalDiagMap.put(line, detail);
|
|
|
+ }
|
|
|
+ redisUtil.setValByHospitalId(hospitalId, KernelConstants.HOSPITAL_DIAG_MAP, hospitalDiagMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
- redisUtil.setJsonStringValue(KernelConstants.HOSPITAL_DIAG_MAP, hospitalDiagMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 医院和华卓映射疾病信息放入redis缓存
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
*/
|
|
|
- public void putHospitalDiagHuaZMap() throws Exception {
|
|
|
- Configuration configuration = new DefaultConfig();
|
|
|
- List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
|
|
|
- Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
|
|
|
- for (String line : lines) {
|
|
|
- Map<String, String> detail = new HashMap<>();
|
|
|
- detail.put("name", line.trim());
|
|
|
- detail.put("icd10", "A001");
|
|
|
- hospitalDiagMap.put(line, detail);
|
|
|
+ public void putHospitalDiagHuaZMap(String hospitalId) {
|
|
|
+ try {
|
|
|
+ List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
|
|
|
+ Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
|
|
|
+ for (String line : lines) {
|
|
|
+ Map<String, String> detail = new HashMap<>();
|
|
|
+ detail.put("name", line.trim());
|
|
|
+ detail.put("icd10", "A001");
|
|
|
+ hospitalDiagMap.put(line, detail);
|
|
|
+ }
|
|
|
+ redisUtil.setValByHospitalId(hospitalId, KernelConstants.HOSPITAL_DIAG_HUAZ_MAP, hospitalDiagMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
- redisUtil.setJsonStringValue(KernelConstants.HOSPITAL_DIAG_HUAZ_MAP, hospitalDiagMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 医院和华卓映射疾病信息放入redis缓存
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
*/
|
|
|
- public void putLantoneDiagHuaZMap() throws Exception {
|
|
|
- Configuration configuration = new DefaultConfig();
|
|
|
- List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
|
|
|
- Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
|
|
|
- for (String line : lines) {
|
|
|
- Map<String, String> detail = new HashMap<>();
|
|
|
- detail.put("name", line.trim());
|
|
|
- detail.put("icd10", "A001");
|
|
|
- hospitalDiagMap.put(line, detail);
|
|
|
+ public void putLantoneDiagHuaZMap(String hospitalId) {
|
|
|
+ try {
|
|
|
+ List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
|
|
|
+ Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
|
|
|
+ for (String line : lines) {
|
|
|
+ Map<String, String> detail = new HashMap<>();
|
|
|
+ detail.put("name", line.trim());
|
|
|
+ detail.put("icd10", "A001");
|
|
|
+ hospitalDiagMap.put(line, detail);
|
|
|
+ }
|
|
|
+ redisUtil.setValByHospitalId(hospitalId, KernelConstants.LANTONE_DIAG_HUAZ_MAP, hospitalDiagMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
- redisUtil.setJsonStringValue(KernelConstants.LANTONE_DIAG_HUAZ_MAP, hospitalDiagMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 症状需要部位描述词典放入redis缓存
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
*/
|
|
|
- public void putClinicBodyPartMap() throws Exception {
|
|
|
- Configuration configuration = new DefaultConfig();
|
|
|
- List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/concept_clinic_bodypart_properties.dict");
|
|
|
- List<String> clinicBodyPartList = new ArrayList<>();
|
|
|
- for (String line : lines) {
|
|
|
- clinicBodyPartList.add(line);
|
|
|
+ public void putClinicBodyPartMap(String hospitalId) {
|
|
|
+ try {
|
|
|
+ List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/concept_clinic_bodypart_properties.dict");
|
|
|
+ List<String> clinicBodyPartList = new ArrayList<>();
|
|
|
+ for (String line : lines) {
|
|
|
+ clinicBodyPartList.add(line);
|
|
|
+ }
|
|
|
+ redisUtil.setValByHospitalId(hospitalId, KernelConstants.CONCEPT_CLINIC_BODYPART_PROPERTIES_LIST, clinicBodyPartList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
- redisUtil.setJsonStringValue(KernelConstants.CONCEPT_CLINIC_BODYPART_PROPERTIES_LIST, clinicBodyPartList);
|
|
|
}
|
|
|
+
|
|
|
}
|