12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061 |
- package com.diagbot.facade;
- import com.alibaba.fastjson.JSONArray;
- import com.diagbot.biz.push.entity.Item;
- import com.diagbot.biz.push.entity.Lis;
- import com.diagbot.client.ChiefPresentSimilarityServiceClient;
- import com.diagbot.client.StandConvertServiceClient;
- import com.diagbot.dto.*;
- import com.diagbot.entity.DiseaseInfo;
- import com.diagbot.entity.DiseaseProperty;
- import com.diagbot.entity.node.LisRemind;
- import com.diagbot.entity.relationship.LisRemindMedicine;
- import com.diagbot.entity.relationship.LisRemindYiBaoDiseaseName;
- import com.diagbot.enums.RedisEnum;
- import com.diagbot.enums.StandConvertEnum;
- import com.diagbot.exception.CommonErrorCode;
- import com.diagbot.exception.CommonException;
- import com.diagbot.model.entity.PD;
- import com.diagbot.repository.*;
- import com.diagbot.util.ListUtil;
- import com.diagbot.util.NeoUtil;
- import com.diagbot.util.RedisUtil;
- import com.diagbot.util.StringUtil;
- import com.diagbot.vo.Drug;
- import com.diagbot.vo.*;
- import com.diagbot.vo.neoPushEntity.*;
- import com.google.common.collect.Lists;
- import com.google.common.collect.Maps;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.stereotype.Component;
- import java.math.BigDecimal;
- import java.text.DecimalFormat;
- import java.util.*;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- /**
- * @Description: 图谱facade
- * @author: Mark
- * @time: 2018/8/6 9:11
- */
- @Component
- public class NeoFacade {
- @Autowired
- MedicineRepository medicineRepository;
- @Autowired
- PacsNameRepository pacsNameRepository;
- @Autowired
- PacsSubNameRepository pacsSubNameRepository;
- @Autowired
- LisNameRepository lisNameRepository;
- @Autowired
- LisSetRepository lisSetRepository;
- @Autowired
- LisRemindRepository lisRemindRepository;
- @Autowired
- YiBaoDiseaseRepository yiBaodiseaseRepository;
- @Autowired
- YiBaoOperationNameRepository yiBaoOperationRepository;
- @Autowired
- MedicineCodeRepository medicineCodeRepository;
- @Autowired
- MedRegNameRepository medRegNameRepository;
- @Autowired
- PacsCriticalRepository pacsCriticalRepository;
- @Autowired
- YiBaoDiseaseRepository yiBaoDiseaseRepository;
- @Autowired
- CombiOperationRepository combiOperationRepository;
- @Autowired
- BaseNodeRepository nodeRepository;
- @Autowired
- ChiefPresentSimilarityServiceClient chiefPresentSimilarityServiceClient;
- @Autowired
- NeoFacade self;
- @Autowired
- StandConvertServiceClient standConvertServiceClient;
- @Autowired
- RedisUtil redisUtil;
- @Autowired
- @Qualifier("redisTemplateForSimilar")
- RedisTemplate redisTemplate;
- @Value("${StandConvert.rate}")
- String standConvertRate;
- @Autowired
- SymptomNameRepository symptomNameRepository;
- @Autowired
- TransfusionRemindRepository transfusionRemindRepository;
- @Autowired
- TransfusionSuggestRepository transfusionSuggestRepository;
- @Autowired
- PacsRemindRepository pacsRemindRepository;
- @Autowired
- PacsResultRepository pacsResultRepository;
- /**
- * 返回药品缓存信息
- *
- * @return
- */
- // @Cacheable(value = "cache", key = "'drugCache'")
- public Map<String, List<String>> getDrugCache() {
- Map<String, List<String>> res = new HashMap<>();
- String med_type;
- String med_name;
- String comma = "::";
- List<String> medClass = nodeRepository.getMedHuaXueClass();
- medClass.addAll(nodeRepository.getMedYaoLiClass());
- medClass.addAll(nodeRepository.getMedZhiLiaoClass());
- medClass.addAll(nodeRepository.getMedJiePouClass());
- for (String medcls : medClass) {
- String[] spres = medcls.split(comma);
- med_type = spres[1];
- med_name = spres[0];
- if (res.get(med_type) == null) {
- res.put(med_type, new ArrayList<>());
- }
- if (res.get(med_type).indexOf(med_name) == -1) {
- res.get(med_type).add(med_name);
- }
- }
- Map redisMap = res.entrySet().stream().collect(
- Collectors.toMap(k -> RedisEnum.drugType.getName() + k.getKey(),
- v -> v.getValue(), (v1, v2) -> (v2)));
- if (redisMap != null && redisMap.size() > 0) {
- redisTemplate.opsForValue().multiSet(redisMap);
- }
- return res;
- }
- public void diseasePropertyCache() {
- List<DiseaseProperty> diseaseProperty = nodeRepository.getDiseaseProperty();
- if (ListUtil.isNotEmpty(diseaseProperty)) {
- Map map = diseaseProperty.stream().collect(Collectors.toMap(
- k -> RedisEnum.diseaseType.getName() + k.getName(),
- v -> {
- Map<String, String> desc = new HashMap<>();
- desc.put("name", v.getName());
- desc.put("sex", v.getSex());
- desc.put("age", v.getAge());
- desc.put("fbl", v.getFbl());
- return desc;
- },
- (v1, v2) -> (v2)
- ));
- redisTemplate.opsForValue().multiSet(map);
- }
- }
- /**
- * 返回图谱中所有症状缓存信息
- *
- * @return
- */
- @Cacheable(value = "cache", key = "'symptomCache'")
- public List<String> getSymptomCache() {
- List<String> symptomClass = nodeRepository.getSymptomClass();
- return symptomClass;
- }
- /**
- * 返回图谱中所有疾病和性别信息
- *
- * @return
- */
- @Cacheable(value = "cache", key = "'disSexCache'")
- public Map<String, String> getDisSexCache() {
- Map<String, String> disSexClass = Maps.newHashMap();
- List<String> disSex = nodeRepository.getDisSexClass();
- if (ListUtil.isNotEmpty(disSex)) {
- disSex.parallelStream().forEach(x -> {
- String[] splits = x.split("&");
- disSexClass.put(splits[0], splits[1]);
- });
- }
- return disSexClass;
- }
- /**
- * 返回图谱中所有疾病和年龄信息
- *
- * @return
- */
- @Cacheable(value = "cache", key = "'disAgeCache'")
- public Map<String, String> getDisAgeCache() {
- Map<String, String> disAgeClass = Maps.newHashMap();
- List<String> ageClass = nodeRepository.getDisAgeClass();
- if (ListUtil.isNotEmpty(ageClass)) {
- ageClass.parallelStream().forEach(x -> {
- String[] splits = x.split("&");
- disAgeClass.put(splits[0], splits[1]);
- });
- }
- return disAgeClass;
- }
- /**
- * 返回图谱中所有疾病和发病率信息
- *
- * @return
- */
- @Cacheable(value = "cache", key = "'disdistributionCache'")
- public Map<String, Double> getDisdistributionCache() {
- DecimalFormat df = new DecimalFormat("0.######");
- Map<String, Double> disdistribution = new HashMap<>();
- List<String> disdistributionClass = nodeRepository.getDisdistributionClass();
- if (ListUtil.isNotEmpty(disdistributionClass)) {
- disdistributionClass.parallelStream().forEach(x -> {
- String[] splits = x.split("&");
- disdistribution.put(splits[0], Double.parseDouble(splits[1]));
- });
- }
- return disdistribution;
- }
- /**
- * 图谱反推的数据
- *
- * @param pushVO
- * @return
- */
- public NeoPushDTO getReversePush(NeoPushVO pushVO) {
- NeoPushDTO neoPushDTO = new NeoPushDTO();
- // 如果有诊断名称,则通过诊断反推
- if (null != pushVO.getDiagVo() && pushVO.getDiagVo().getDiags().size() > 0) {
- neoPushDTO = getDiagInfo(pushVO);
- }
- return neoPushDTO;
- }
- /**
- * 图谱正推的数据
- *
- * @param pushVO
- * @return
- */
- public List<String> getPush(NeoPushVO pushVO) {
- Double age = pushVO.getAgeNum();
- Integer sex = pushVO.getSex();
- List<String> presentDiags = Lists.newArrayList();
- PresentPushVo presentPushVo = pushVO.getPresentPushVo();
- if(presentPushVo != null){
- List<Diag> diags = presentPushVo.getDiags();
- if(ListUtil.isNotEmpty(diags)){
- presentDiags = diags.stream().map(x -> x.getName()).collect(Collectors.toList());
- }
- }
- List<PD> pds = pushVO.getChiefPushVo().getPds();
- PD pd = null;
- if(ListUtil.isNotEmpty(pds)){
- pd = pds.get(0);
- }
- List<String> pushDis = new ArrayList<>();
- List<String> allDis = Lists.newArrayList();
- //如果化验有特异性就直接推送疾病
- List<Lis> lises = null;
- LisPushVo lisPushVo = pushVO.getLisPushVo();
- if (lisPushVo != null) {
- lises = lisPushVo.getLises();
- }
- pushDis = pushDisBySpecialLis(age, sex, pd, lises,presentDiags);
- if(ListUtil.isNotEmpty(pushDis)){
- return pushDis;
- }
- // 症状、体征推送出的疾病
- pushDisBySymptomOrVital(pushVO, allDis);
- //化验推出的疾病
- pushDisByLis(allDis, lises);
- //辅检推出的疾病
- pushDisByPacs(pushVO, allDis);
- filterAndSort(pushDis, allDis, sex, age, pd);
- pushDis = addDiagFromPresent(pushDis,presentDiags);
- return pushDis;
- }
- /**
- * 化验特异性推送疾病
- * @param age
- * @param sex
- * @param
- * @param lises
- * @return
- */
- private List<String> pushDisBySpecialLis(Double age, Integer sex, PD pd, List<Lis> lises,List<String> presentDiags) {
- List<String> neoPushDTOS = new ArrayList<>();
- if (ListUtil.isNotEmpty(lises)) {
- List<String> lis_dis = lises.parallelStream()
- .map(x -> nodeRepository.getDisByLis_Special(x.getName(), x.getUniqueName() + x.getResult()))
- .flatMap(List::stream).collect(Collectors.toList());
- if (ListUtil.isNotEmpty(lis_dis)) {
- filterAndSort(neoPushDTOS, lis_dis, sex, age,pd);
- neoPushDTOS = addDiagFromPresent(neoPushDTOS,presentDiags);
- }
- }
- return neoPushDTOS;
- }
- /**
- * 把现病史中的诊断添加到推送诊断中
- * @param lis_dis
- * @param presentDiags
- */
- private List<String> addDiagFromPresent(List<String> lis_dis,List<String> presentDiags){
- List<String> lis_dis_new = Lists.newArrayList();
- if(ListUtil.isNotEmpty(lis_dis) && ListUtil.isNotEmpty(presentDiags)){
- if(lis_dis.size()>=10){
- for(int i =0; i< lis_dis.size(); i++){
- if(i == 10 - presentDiags.size()){
- for (String dis: presentDiags) {
- if(!lis_dis_new.contains(dis)){
- lis_dis_new.add(dis);
- }
- }
- lis_dis_new.add(lis_dis.get(i));
- }else {
- lis_dis_new.add(lis_dis.get(i));
- }
- }
- }else {
- lis_dis_new.addAll(lis_dis);
- lis_dis_new.addAll(presentDiags);
- }
- lis_dis_new = lis_dis_new.stream().distinct().collect(Collectors.toList());
- }else {
- lis_dis_new =lis_dis;
- }
- return lis_dis_new;
- }
- /**
- * 辅检推送疾病
- * @param pushVO
- * @param allDis
- */
- private void pushDisByPacs(NeoPushVO pushVO, List<String> allDis) {
- PacsPushVo pacsPushVo = pushVO.getPacsPushVo();
- if (pacsPushVo != null) {
- List<Item> pacs = pacsPushVo.getPacs();
- if (ListUtil.isNotEmpty(pacs)) {
- List<String> pacsNames = pacs.stream().map(x -> x.getUniqueName()).collect(Collectors.toList());
- List<String> allDis_byPacsResult = getDisByPacsResult(pacsNames);
- allDis.addAll(allDis_byPacsResult);
- }
- }
- }
- /**
- * 化验推送疾病
- * @param allDis
- * @param lises
- */
- private void pushDisByLis(List<String> allDis, List<Lis> lises) {
- if (ListUtil.isNotEmpty(lises)) {
- List<String> lis_dis = lises.parallelStream()
- .map(x -> nodeRepository.getDisByLis(x.getName(), x.getUniqueName() + x.getResult()))
- .flatMap(List::stream).collect(Collectors.toList());
- allDis.addAll(lis_dis);
- }
- }
- /**
- * 症状和体征推送疾病
- * @param pushVO
- * @param allDis
- */
- private void pushDisBySymptomOrVital(NeoPushVO pushVO, List<String> allDis) {
- ChiefPushVo chiefPushVo = pushVO.getChiefPushVo();
- PresentPushVo presentPushVo = pushVO.getPresentPushVo();
- List<String> symptoms = new ArrayList<>();
- List<String> symptom_chief = new ArrayList<>();
- List<String> symptom_present = new ArrayList<>();
- if (chiefPushVo != null) {
- if (ListUtil.isNotEmpty(chiefPushVo.getSymptoms())) {
- symptom_chief = chiefPushVo.getSymptoms().stream().map(x -> x.getName()).collect(Collectors.toList());
- }
- }
- if (presentPushVo != null) {
- if (ListUtil.isNotEmpty(presentPushVo.getSymptoms())) {
- symptom_present = presentPushVo.getSymptoms().stream().map(x -> x.getName()).collect(Collectors.toList());
- }
- }
- symptoms = Stream.of(symptom_chief, symptom_present).flatMap(Collection::stream).distinct().collect(Collectors.toList());
- //症状、体征推疾病
- List<String> allDis_bySymptom = getDisBySymptom(symptoms);
- allDis.addAll(allDis_bySymptom);
- }
- private void filterAndSort(List<String> dises, List<String> allDis, int gender_code, double age, PD pd) {
- //推送出的所有疾病进行性别和年龄的过滤
- List<Map<String, String>> diseases = null;
- Map<String, Double> dis_fbl = new HashMap<>();
- if (ListUtil.isNotEmpty(allDis)) {
- // diseases = redisUtil.get(allDis);
- diseases = redisUtil.geth(allDis);
- allDis = diseases.stream().filter(x -> NeoUtil.matchBasic(x, gender_code, age) && NeoUtil.matchPds(x.get("name"),pd))
- // allDis = diseases.stream().filter(x -> NeoUtil.matchBasic(x, gender_code, age))
- .map(x -> x.get("name")).collect(Collectors.toList());
- diseases.forEach(x -> dis_fbl.put(x.get("name"), Double.parseDouble(x.get("fbl"))));
- }
- Map<Long, List<String>> numberDiseasesMap = disCountSort(allDis);
- //根据发病率排序
- // Map<String, Double> disdistributionCache = self.getDisdistributionCache();
- Map<Long, Map<String, Double>> disPack = new LinkedHashMap<>();
- numberDiseasesMap.forEach((x, y) -> {
- Map<String, Double> collect = y.stream()
- .collect(Collectors.toMap(v -> v, v -> dis_fbl.get(v), (e1, e2) -> e2));
- disPack.put(x, collect);
- });
- disPack.forEach((x, y) -> {
- Map<String, Double> collect = y.entrySet().stream()
- .sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));
- disPack.put(x, collect);
- collect.forEach((k, n) -> {
- /*NeoPushDTO neoPushDTO = new NeoPushDTO();
- PushBaseDTO pushBaseDTO = new PushBaseDTO();
- pushBaseDTO.setName(k);
- neoPushDTO.setDisease(pushBaseDTO);
- neoPushDTOS.add(neoPushDTO);*/
- dises.add(k);
- });
- });
- }
- public List<String> getDisBySymptom(List<String> symptoms) {
- List<String> symptomCache = getSymptomCache();
- //取交集
- symptoms.retainAll(symptomCache);
- long start = System.currentTimeMillis();
- List<String> allDis_bySymptom = pushDisBySymptom(symptomNameRepository, symptoms);
- long end = System.currentTimeMillis();
- return allDis_bySymptom;
- }
- public List<String> getDisByPacsResult(List<String> pacsResult) {
- /*List<PacsResult> byNameIn = pacsResultRepository.findByNameIn(pacsResult);
- List<String> allDis = byNameIn.stream()
- .map(z -> z.getDisease().stream().filter(o -> NeoUtil.matchBasic(o,sex,age)).map(y -> y.getName()).collect(Collectors.toList())).flatMap(List::stream)
- .collect(Collectors.toList());*/
- List<String> allDis = pacsResultRepository.getDisByPacsResults(pacsResult);
- return allDis;
- }
- /**
- * 症状、体征、化验、辅检等其他推送疾病
- *
- * @param symptomNameRepository
- * @param symptoms
- * @return
- */
- public List<String> pushDisBySymptom(SymptomNameRepository symptomNameRepository, List<String> symptoms) {
- List<String> allDis = Lists.newArrayList();
- /*List<Symptom> byNameIn = symptomNameRepository.findByNameIn(symptoms);
- allDis = byNameIn.parallelStream()
- .map(z -> z.getDisease().stream().filter(o -> NeoUtil.matchBasic(o,sex,age)).map(y -> y.getName()).collect(Collectors.toList())).flatMap(List::stream)
- .collect(Collectors.toList());*/
- allDis = symptomNameRepository.getDisBySymptoms(symptoms);
- return allDis;
- }
- /**
- * 推送的疾病计数排序
- *
- * @param allDis
- * @return
- */
- public Map<Long, List<String>> disCountSort(List<String> allDis) {
- Map<String, Long> dis_count = allDis.stream().collect(
- Collectors.groupingBy(Function.identity(), Collectors.counting())
- );
- if (dis_count != null && dis_count.size() > 0) {
- dis_count = dis_count.entrySet().stream().sorted((o1, o2) -> o2.getValue().compareTo(o1.getValue()))
- .map(entry -> {
- Map<String, Long> result = new LinkedHashMap();
- result.put(entry.getKey(), entry.getValue());
- return result;
- }).reduce((map1, map2) -> {
- map2.entrySet().forEach(entry -> map1.put(entry.getKey(), entry.getValue()));
- return map1;
- }).get();
- }
- Map<Long, List<String>> number_diseases = new LinkedHashMap<>();
- dis_count.forEach((x, y) -> {
- if (number_diseases.containsKey(y)) {
- List<String> diseases = number_diseases.get(y);
- diseases.add(x);
- number_diseases.put(y, diseases);
- } else {
- List<String> diseases = Lists.newArrayList();
- diseases.add(x);
- number_diseases.put(y, diseases);
- }
- });
- return number_diseases;
- }
- /**
- * 反推信息
- * @param dis
- * @return
- */
- public NeoPushDTO reverseInfo(String dis){
- NeoPushDTO neoPushDTO = new NeoPushDTO();
- List<DiseaseInfo> diseaseInfo = nodeRepository.getDiseaseInfo(dis);
- if(ListUtil.isNotEmpty(diseaseInfo)){
- diseaseInfo.forEach(disIf ->{
- String tp = disIf.getTp();
- List<String> col = disIf.getCol();
- switch (tp){
- case "医保疾病名称相关症状":
- neoPushDTO.setSymptoms(col.stream().map(x ->NeoUtil.updatePushInfo(x)).collect(Collectors.toList()));
- break;
- case "医保疾病名称相关化验套餐名称":
- neoPushDTO.setLis(col.stream().map(x ->NeoUtil.updatePushInfo(x)).collect(Collectors.toList()));
- break;
- case "医保疾病名称相关辅助检查名称":
- neoPushDTO.setPacs(col.stream().map(x ->NeoUtil.updatePushInfo(x)).collect(Collectors.toList()));
- break;
- case "医保疾病名称相关体征":
- neoPushDTO.setVitals(col.stream().map(x ->NeoUtil.updatePushInfo(x)).collect(Collectors.toList()));
- break;
- default:
- break;
- }
- });
- }
- return neoPushDTO;
- }
- /**
- * 处理开单合理性图谱数据
- *
- * @param billNeoVO
- * @return
- */
- public List<BillNeoDTO> getBillNeo(BillNeoVO billNeoVO) {
- List<BillNeoDTO> billNeoDTOs = new ArrayList<>();
- try {
- billNeoDTOs.addAll(getDrugBill(billNeoVO.getDrugList()));
- billNeoDTOs.addAll(getPacsBill(billNeoVO.getPacsList()));
- billNeoDTOs.addAll(getLisDetailBill(billNeoVO.getLisDetailList()));
- billNeoDTOs.addAll(getLisBill(billNeoVO.getLisList()));
- billNeoDTOs.addAll(getOperationBill(billNeoVO.getOperationList()));
- billNeoDTOs.addAll(getCombiOpBill(billNeoVO.getCombiopList()));
- billNeoDTOs.addAll(getTransfusionBill(billNeoVO.getTransfusionList()));
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return billNeoDTOs;
- }
- /**
- * 处理高危项目图谱数据
- *
- * @param wordCrfDTO
- * @return
- */
- public List<HighRiskNeoDTO> getHighRiskNeo(WordCrfDTO wordCrfDTO) {
- List<HighRiskNeoDTO> highRiskNeoDTOS = new ArrayList<>();
- highRiskNeoDTOS.addAll(getHighRiskDrugList(wordCrfDTO.getDrugOrder()));
- highRiskNeoDTOS.addAll(getHighRiskOperationList(wordCrfDTO));
- return highRiskNeoDTOS;
- }
- /**
- * 获取危急值图谱数据
- */
- public List<CriticalNeoDTO> getCritialNeo(CriticalNeoVO criticalNeoVO) {
- List<CriticalNeoDTO> criticalNeoDTOs = new ArrayList<>();
- criticalNeoDTOs.addAll(getLisCritical(criticalNeoVO));
- criticalNeoDTOs.addAll(getPacsCritical(criticalNeoVO));
- return criticalNeoDTOs;
- }
- /**
- * 处理其它化验提醒
- */
- public List<OtherTipNeoDTO> getOtherRemind(List<Lis> lislist) {
- Map<String, List<LisRemind>> lrmap = new HashMap<>();
- List<OtherTipNeoDTO> otherTipNeoDTOS = new ArrayList<>();
- try {
- List<LisRemind> lisReminds = lisRemindRepository.findByNameContaining("");
- String lisname, result, unit;
- Double val;
- for (LisRemind lisRemind : lisReminds) {
- lisname = lisRemind.getLisname();
- if (null == lrmap.get(lisname)) {
- lrmap.put(lisname, new ArrayList<>());
- }
- lrmap.get(lisname).add(lisRemind);
- }
- for (Lis lis : lislist) {
- lisname = lis.getUniqueName();
- if (null != lrmap.get(lisname)) {
- List<LisRemind> lrlist = lrmap.get(lisname);
- result = lis.getOtherValue();
- if (StringUtil.isBlank(result)) {
- val = lis.getValue();
- unit = lis.getUnits();
- for (LisRemind lisRemind : lrlist) {
- if (lisRemind.getRange() == 0) { /*&& lisRemind.getUnit().equals(unit) &&*/
- if (null == lisRemind.getMinval() && val <= lisRemind.getMaxval()) {
- otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
- } else if (null == lisRemind.getMaxval() && val >= lisRemind.getMinval()) {
- otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
- } else if (null != lisRemind.getMinval() && null != lisRemind.getMaxval() &&
- val <= lisRemind.getMaxval() && val >= lisRemind.getMinval()) {
- otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
- }
- } else if (lisRemind.getRange() == 1) { /*&& lisRemind.getUnit().equals(unit) &&*/
- if (null != lisRemind.getMaxval() && val > lisRemind.getMaxval()) {
- otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
- } else if (null != lisRemind.getMinval() && val < lisRemind.getMinval()) {
- otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
- }
- }
- }
- } else {
- for (LisRemind lisRemind : lrlist) {
- if (result.equals(lisRemind.getResult())) {
- OtherTipNeoDTO otherTipNeoDTO = new OtherTipNeoDTO();
- BeanUtils.copyProperties(lis, otherTipNeoDTO);
- otherTipNeoDTO.setFactor(getReminds(lisRemind));
- otherTipNeoDTOS.add(otherTipNeoDTO);
- }
- }
- }
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return otherTipNeoDTOS;
- }
- public List<OtherTipNeoDTO> updateTipNeoDTO(List<OtherTipNeoDTO> otherTipNeoDTOS, Lis lis, LisRemind lisRemind) {
- OtherTipNeoDTO otherTipNeoDTO = new OtherTipNeoDTO();
- BeanUtils.copyProperties(lis, otherTipNeoDTO);
- otherTipNeoDTO.setFactor(getReminds(lisRemind));
- otherTipNeoDTOS.add(otherTipNeoDTO);
- return otherTipNeoDTOS;
- }
- public List<NodeNeoDTO> getReminds(LisRemind lisRemind) {
- List<NodeNeoDTO> nodeNeoDTOS = new ArrayList<>();
- NodeNeoDTO nodeNeoDTO;
- for (LisRemindYiBaoDiseaseName lisReminddisease : lisRemind.getLisReminddisease()) {
- if (NeoUtil.isExist(lisReminddisease)) {
- nodeNeoDTO = new NodeNeoDTO();
- nodeNeoDTO.setName(lisReminddisease.getYiBaoDiseaseName().getName());
- nodeNeoDTO.setTermtype(Constants.zhenduan);
- nodeNeoDTOS.add(nodeNeoDTO);
- }
- }
- for (LisRemindMedicine lisRemindmedicine : lisRemind.getLisRemindmedicines()) {
- if (NeoUtil.isExist(lisRemindmedicine)) {
- nodeNeoDTO = new NodeNeoDTO();
- nodeNeoDTO.setName(lisRemindmedicine.getMedicine().getName());
- nodeNeoDTO.setTermtype(Constants.yaoping);
- nodeNeoDTOS.add(nodeNeoDTO);
- }
- }
- return nodeNeoDTOS;
- }
- /**
- * 处理建议输血
- */
- public List<OtherTipTransfusionNeoDTO> getRecommendTransfs(WordCrfDTO wordCrfDTO) {
- TransfusionSuggestNode transfusionSuggestNode = new TransfusionSuggestNode();
- List<OtherTipTransfusionNeoDTO> otherTipTransfsNeoDTOS = transfusionSuggestNode.getTransfusionSuggest(wordCrfDTO, transfusionSuggestRepository);
- return otherTipTransfsNeoDTOS;
- }
- /**
- * 处理辅检提醒
- */
- public List<OtherTipPacsNeoDTO> getPacsReminds(WordCrfDTO wordCrfDTO) {
- PacsRemindNode pacsRemindNode = new PacsRemindNode();
- List<OtherTipPacsNeoDTO> otherTipPacsNeoDTOS = pacsRemindNode.getPacsReminds(wordCrfDTO, pacsRemindRepository);
- return otherTipPacsNeoDTOS;
- }
- /**
- * 处理处方开单合理性
- */
- public List<BillNeoDTO> getDrugBill(List<Map<String, String>> medsterm) {
- MedicineNode medicineNode = new MedicineNode();
- List<BillNeoDTO> billNeoDTOs = medicineNode.getMedicineBill(medsterm, medicineRepository, medRegNameRepository);
- return billNeoDTOs;
- }
- /**
- * 处理辅检开单合理性
- */
- public List<BillNeoDTO> getPacsBill(List<Map<String, String>> pacsterm) {
- PacsNameNode pacsNode = new PacsNameNode();
- List<BillNeoDTO> billNeoDTOs = pacsNode.getPacsBill(pacsterm, pacsNameRepository);
- PacsSubNameNode pacsSubNode = new PacsSubNameNode();
- billNeoDTOs.addAll(pacsSubNode.getSubPacsBill(pacsterm, pacsSubNameRepository));
- return billNeoDTOs;
- }
- /**
- * 处理化验套餐开单合理性
- */
- public List<BillNeoDTO> getLisBill(List<Map<String, String>> lissetterms) {
- LisSetNode lisSetNode = new LisSetNode();
- List<BillNeoDTO> billNeoDTOs = lisSetNode.getLisBill(lissetterms, lisSetRepository);
- return billNeoDTOs;
- }
- /**
- * 处理化验开单合理性
- */
- public List<BillNeoDTO> getLisDetailBill(List<Map<String, String>> listerm) {
- LisNameNode lisNode = new LisNameNode();
- List<BillNeoDTO> billNeoDTOs = lisNode.getLisDetailBill(listerm, lisNameRepository);
- return billNeoDTOs;
- }
- /**
- * 处理手术开单合理性
- */
- public List<BillNeoDTO> getOperationBill(List<Map<String, String>> opterms) {
- YiBaoOperationNameNode yiBaoOpNode = new YiBaoOperationNameNode();
- List<BillNeoDTO> billNeoDTOs = yiBaoOpNode.getOperationBill(opterms, yiBaoOperationRepository);
- return billNeoDTOs;
- }
- /**
- * 处理联合项目开单合理性
- */
- public List<BillNeoDTO> getCombiOpBill(List<Map<String, String>> combiterms) {
- CombiOperationNode combiNode = new CombiOperationNode();
- List<BillNeoDTO> billNeoDTOS = combiNode.getCombiOpBill(combiterms, combiOperationRepository);
- return billNeoDTOS;
- }
- /**
- * 处理输血开单合理性
- */
- public List<BillNeoDTO> getTransfusionBill(List<Map<String, String>> termlist) {
- TransfusionRemindNode transfusionRemindNode = new TransfusionRemindNode();
- List<BillNeoDTO> billNeoDTOS = transfusionRemindNode.getTransfusionBill(termlist, transfusionRemindRepository);
- return billNeoDTOS;
- }
- /**
- * 推送疾病信息
- *
- * @param neoPushVO
- * @return
- */
- public NeoPushDTO getDiagInfo(NeoPushVO neoPushVO) {
- NeoPushDTO pushDTO = new NeoPushDTO();
- // YiBaoDiseaseNode icdDiseaseNode = new YiBaoDiseaseNode();
- String term = neoPushVO.getDiagVo().getDiags().get(0).getName();
- /*List<YiBaoDiseaseName> yiBaoName = yiBaoDiseaseRepository.findByNameIs(term);
- YiBaoDiseaseName icdDisease = null;
- if (ListUtil.isNotEmpty(yiBaoName)) {
- icdDisease = yiBaoName.get(0);
- }
- if (icdDisease != null) {
- icdDisease = NeoUtil.extract_node(icdDisease);
- pushDTO = icdDiseaseNode.YiBaoDiseasetoDiseaseDTO(icdDisease, neoPushVO);
- }*/
- pushDTO = this.reverseInfo(term);
- return pushDTO;
- }
- /**
- * 获取化验危急值
- *
- * @param criticalNeoVO
- */
- public List<CriticalNeoDTO> getLisCritical(CriticalNeoVO criticalNeoVO) {
- LisNameNode lisNode = new LisNameNode();
- List<CriticalNeoDTO> criticalNeoDTOs = lisNode.getLisCritialList(criticalNeoVO, lisNameRepository);
- return criticalNeoDTOs;
- }
- /**
- * 获取辅检危急值
- *
- * @Param criticalNeoVO
- */
- public List<CriticalNeoDTO> getPacsCritical(CriticalNeoVO criticalNeoVO) {
- PacsCriticalNode pacsCriticalNode = new PacsCriticalNode();
- List<CriticalNeoDTO> criticalNeoDTOS = pacsCriticalNode.getPacsList(criticalNeoVO, pacsCriticalRepository);
- return criticalNeoDTOS;
- }
- /**
- * 处理高危药品数据
- *
- * @param drugs
- * @return
- */
- public List<HighRiskNeoDTO> getHighRiskDrugList(List<Drug> drugs) {
- MedRegNameNode medRegNameNode = new MedRegNameNode();
- List<HighRiskNeoDTO> highRiskNeoDTOS = medRegNameNode.getHighRiskDrug(drugs, medicineRepository, medicineCodeRepository);
- return highRiskNeoDTOS;
- }
- /**
- * 处理高危手术和操作数据
- *
- * @param wordCrfDTO
- * @return
- */
- public List<HighRiskNeoDTO> getHighRiskOperationList(WordCrfDTO wordCrfDTO) {
- YiBaoOperationNameNode yiBaoOperationNode = new YiBaoOperationNameNode();
- List<HighRiskNeoDTO> highRiskNeoDTOS = yiBaoOperationNode.getHighRiskOperation(wordCrfDTO, yiBaoOperationRepository);
- return highRiskNeoDTOS;
- }
- /**
- * 提取方法
- *
- * @param jsonArray
- * @param originName
- * @param map
- */
- public void putMap(JSONArray jsonArray, String originName, Map<String, String> map) {
- if (jsonArray.size() == 2) {
- double likeRate = jsonArray.getDoubleValue(1);
- // System.out.println(originName + " " + likeRate);
- if (likeRate > 0.9) {
- String standName = jsonArray.getString(0);
- map.put(originName, standName);
- } else {
- map.put(originName, originName);
- }
- }
- }
- /**
- * 标准词转换
- * 类型,疾病: disease,症状: symptom,手术和操作:operation,药品: drug,实验室检查:lis,辅助检查:pacs, 辅助检查:vital"
- *
- * @param standConvert
- * @return Map<String, Map < String, String>> -->Map<类型, Map<原始词, 标准词>>
- */
- public Map<String, Map<String, String>> standConvertCrf(StandConvert standConvert) {
- Map<String, Map<String, String>> map = new LinkedHashMap<>();
- List<StandConvertCrfVO> standConvertCrfVOList = new ArrayList<>();
- List<String> clinicalConList = getConvertList(standConvert.getClinicalList(), StandConvertEnum.symptom.toString(), standConvertCrfVOList);
- List<String> operationConList = getConvertList(standConvert.getOperationList(), StandConvertEnum.operation.toString(), standConvertCrfVOList);
- List<String> drugConList = getConvertList(standConvert.getDrugList(), StandConvertEnum.drug.toString(), standConvertCrfVOList);
- List<String> vitallConList = getConvertList(standConvert.getVitalList(), StandConvertEnum.vital.toString(), standConvertCrfVOList);
- List<String> diseaseConList = getConvertList(standConvert.getDiaglList(), StandConvertEnum.disease.toString(), standConvertCrfVOList);
- List<String> pacsConList = getConvertList(standConvert.getPacsList(), StandConvertEnum.pacs.toString(), standConvertCrfVOList);
- List<String> lisConList = getConvertList(standConvert.getLisList(), StandConvertEnum.lis.toString(), standConvertCrfVOList);
- List<String> transfusionConList = getConvertList(standConvert.getTransfusionList(), StandConvertEnum.transfusion.toString(), standConvertCrfVOList);
- StandConvertCrfBatchDTO standConvertCrfBatchDTO = new StandConvertCrfBatchDTO();
- if (!(ListUtil.isEmpty(clinicalConList) && ListUtil.isEmpty(operationConList) && ListUtil.isEmpty(drugConList)
- && ListUtil.isEmpty(vitallConList) && ListUtil.isEmpty(diseaseConList) && ListUtil.isEmpty(pacsConList)
- && ListUtil.isEmpty(lisConList) && ListUtil.isEmpty(transfusionConList))) {
- try {
- standConvertCrfBatchDTO = standConvertServiceClient.similarityBatch(standConvertCrfVOList);
- } catch (Exception e) {
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标准词转换【服务器】挂了!" + e.getMessage());
- }
- }
- Map<String, Map<String, StandConvertCrfDTO>> crfMap = standConvertCrfBatchDTO.getData();
- getConvertMap(crfMap, StandConvertEnum.symptom.toString(), clinicalConList, standConvert.getClinicalList(), map);
- getConvertMap(crfMap, StandConvertEnum.operation.toString(), operationConList, standConvert.getOperationList(), map);
- getConvertMap(crfMap, StandConvertEnum.drug.toString(), drugConList, standConvert.getDrugList(), map);
- getConvertMap(crfMap, StandConvertEnum.vital.toString(), vitallConList, standConvert.getVitalList(), map);
- getConvertMap(crfMap, StandConvertEnum.disease.toString(), diseaseConList, standConvert.getDiaglList(), map);
- getConvertMap(crfMap, StandConvertEnum.pacs.toString(), pacsConList, standConvert.getPacsList(), map);
- getConvertMap(crfMap, StandConvertEnum.lis.toString(), lisConList, standConvert.getLisList(), map);
- getConvertMap(crfMap, StandConvertEnum.transfusion.toString(), transfusionConList, standConvert.getTransfusionList(), map);
- return map;
- }
- /**
- * 入参数据处理
- *
- * @param wordList
- * @param type
- * @param standConvertCrfVOList
- */
- public List<String> getConvertList(List<String> wordList, String type, List<StandConvertCrfVO> standConvertCrfVOList) {
- List<String> convertList = new ArrayList<>();
- if (ListUtil.isEmpty(wordList)) {
- return null;
- }
- if (ListUtil.isNotEmpty(wordList)) {
- for (String s : wordList) {
- String value = redisUtil.getWithString(type + "Conv:" + s);
- if (StringUtil.isBlank(value)) {
- StandConvertCrfVO standConvertCrfVO = new StandConvertCrfVO();
- standConvertCrfVO.setWord_type(type);
- standConvertCrfVO.setWord(s);
- standConvertCrfVOList.add(standConvertCrfVO);
- if (!convertList.contains(s)) {
- convertList.add(s);
- }
- }
- }
- }
- return convertList;
- }
- /**
- * 获取标准词转换map结果,并更新redis
- *
- * @param crfDTO
- * @param type
- * @param convertList
- * @param map
- */
- public void getConvertMap(Map<String, Map<String, StandConvertCrfDTO>> crfDTO, String type, List<String> convertList,
- List<String> originList, Map<String, Map<String, String>> map) {
- Map<String, String> typeMap = new LinkedHashMap<>();
- if (ListUtil.isNotEmpty(convertList)) {
- Map<String, StandConvertCrfDTO> crfMap = crfDTO.get(type);
- for (String s : convertList) {
- String lastS = s;
- if (StringUtil.isBlank(s)) {
- continue;
- }
- if (crfMap != null) {
- StandConvertCrfDTO standConvertCrfDTO = crfMap.get(s);
- if (standConvertCrfDTO != null) {
- List<Map<String, String>> list = standConvertCrfDTO.getStandard_words();
- if (ListUtil.isEmpty(list)) {
- redisUtil.updateValue(type + "Conv:" + s, s);
- } else {
- String rateStr = standConvertCrfDTO.getStandard_words().get(0).get("rate");
- if (StringUtil.isBlank(rateStr)) {
- redisUtil.updateValue(type + "Conv:" + s, s);
- } else {
- BigDecimal rate = new BigDecimal(rateStr);
- int flag = rate.compareTo(new BigDecimal(standConvertRate));
- if (flag < 0) {
- redisUtil.updateValue(type + "Conv:" + s, s);
- } else {
- redisUtil.updateValue(type + "Conv:" + s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
- lastS = standConvertCrfDTO.getStandard_words().get(0).get("standard_word");
- }
- }
- }
- } else {
- redisUtil.updateValue(type + "Conv:" + s, s);
- }
- }
- typeMap.put(s, lastS);
- }
- }
- // 将所有的词放入typeMap中
- for (String s : originList) {
- if (!typeMap.containsKey(s)) {
- typeMap.put(s, s);
- }
- }
- map.put(type, typeMap);
- }
- }
|