精准医疗基因、方剂

This commit is contained in:
wuchunlei
2025-06-04 17:09:45 +08:00
parent 8dfd150e2c
commit 6852c64984
10 changed files with 426 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.PrecisionMedicineGeneDao;
import com.peanut.modules.common.dao.PrecisionMedicinePrescriptionDao;
import com.peanut.modules.common.entity.PrecisionMedicineGene;
import com.peanut.modules.common.entity.PrecisionMedicinePrescription;
import com.peanut.modules.common.service.PrecisionMedicineGeneService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service("commonPrecisionMedicineGeneService")
public class PrecisionMedicineGeneServiceImpl extends ServiceImpl<PrecisionMedicineGeneDao, PrecisionMedicineGene> implements PrecisionMedicineGeneService {
@Autowired
private PrecisionMedicinePrescriptionDao prescriptionDao;
@Override
public Map<String,Object> getGeneInfo(String geneIds) {
Map<String,Object> res = new HashMap<>();
String[] ids = geneIds.split(",");
Set<String> tcmNames = new HashSet<>();
//查出基因匹配的所有中药
List<PrecisionMedicineGene> geneList = new ArrayList<>();
for (String id : ids) {
PrecisionMedicineGene gene = this.getById(id);
geneList.add(gene);
if (StringUtils.isNotEmpty(gene.getTcmName())){
String[] names = gene.getTcmName().split("");
for (String str:names){
tcmNames.add(str);
}
}
}
res.put("geneList",geneList);
Map<String, Map<String,Object>> countPrescriptions = new HashMap<>();
for (String tcmName : tcmNames){
//方剂列表
List<PrecisionMedicinePrescription> prescriptions = prescriptionDao.selectList(new LambdaQueryWrapper<PrecisionMedicinePrescription>()
.like(PrecisionMedicinePrescription::getCompose,tcmName));
for (PrecisionMedicinePrescription prescription:prescriptions){
if (countPrescriptions.containsKey(prescription.getId()+"")){
Map<String,Object> map = countPrescriptions.get(prescription.getId()+"");
map.put("num",Integer.parseInt(map.get("num")+"")+1);
map.put("tcmName",map.get("tcmName")+","+tcmName);
}else {
Map<String,Object> map = new HashMap<>();
map.put("num",1);
map.put("tcmName",tcmName);
map.put("name",prescription.getName());
map.put("compose",prescription.getCompose());
map.put("total",prescription.getCompose().split("").length);
map.put("source",prescription.getSource());
countPrescriptions.put(prescription.getId()+"",map);
}
}
}
//计算占比,并加入排序集合
List<Map<String,Object>> list = new ArrayList<>();
for (Map<String, Object> m : countPrescriptions.values()){
m.put("percent",Double.parseDouble(m.get("num").toString())/Double.parseDouble(m.get("total").toString()));
list.add(m);
}
//排序
list = list.stream().sorted((map1,map2)->{
int x = Integer.compare(Integer.parseInt(map2.get("num").toString()),Integer.parseInt(map1.get("num").toString()));
if (x!=0){
return x;
}else {
return Double.compare(Double.parseDouble(map2.get("percent").toString()),Double.parseDouble(map1.get("percent").toString()));
}
}).collect(Collectors.toList());
//将匹配最高的加入结果集合
List<Map<String,Object>> prescriptionList = new ArrayList<>();
for (Map<String,Object> map:list){
if (prescriptionList.size() > 0){
if (Integer.parseInt(prescriptionList.get(0).get("num").toString())==Integer.parseInt(map.get("num").toString())){
if (prescriptionList.size()<3){
prescriptionList.add(map);
}
}
}else {
prescriptionList.add(map);
}
}
res.put("prescriptionList",prescriptionList);
return res;
}
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.PrecisionMedicinePrescriptionDao;
import com.peanut.modules.common.entity.PrecisionMedicinePrescription;
import com.peanut.modules.common.service.PrecisionMedicinePrescriptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("commonPrecisionMedicinePrescriptionService")
public class PrecisionMedicinePrescriptionServiceImpl extends ServiceImpl<PrecisionMedicinePrescriptionDao, PrecisionMedicinePrescription> implements PrecisionMedicinePrescriptionService {
}