精准医疗基因、方剂
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.peanut.modules.common.entity.PrecisionMedicineGene;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface PrecisionMedicineGeneDao extends MPJBaseMapper<PrecisionMedicineGene> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.peanut.modules.common.entity.PrecisionMedicinePrescription;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface PrecisionMedicinePrescriptionDao extends MPJBaseMapper<PrecisionMedicinePrescription> {
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("precision_medicine_gene")
|
||||
public class PrecisionMedicineGene {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId
|
||||
private Integer id;
|
||||
|
||||
//基因名称
|
||||
private String name;
|
||||
|
||||
//基因中文名
|
||||
private String namecn;
|
||||
|
||||
//别名
|
||||
private String alias;
|
||||
|
||||
//描述
|
||||
private String description;
|
||||
|
||||
//关联药材名
|
||||
private String tcmName;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("precision_medicine_prescription")
|
||||
public class PrecisionMedicinePrescription {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId
|
||||
private Integer id;
|
||||
|
||||
//方剂名称
|
||||
private String name;
|
||||
|
||||
//别名
|
||||
private String alias;
|
||||
|
||||
//药物组成
|
||||
private String compose;
|
||||
|
||||
//功效
|
||||
private String effect;
|
||||
|
||||
//主治
|
||||
private String indications;
|
||||
|
||||
//来源
|
||||
private String source;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.peanut.modules.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.PrecisionMedicineGene;
|
||||
import java.util.Map;
|
||||
|
||||
public interface PrecisionMedicineGeneService extends IService<PrecisionMedicineGene> {
|
||||
|
||||
Map<String,Object> getGeneInfo(String geneIds);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.peanut.modules.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.PrecisionMedicinePrescription;
|
||||
|
||||
public interface PrecisionMedicinePrescriptionService extends IService<PrecisionMedicinePrescription> {
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.peanut.modules.master.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.PrecisionMedicineGene;
|
||||
import com.peanut.modules.common.entity.PrecisionMedicinePrescription;
|
||||
import com.peanut.modules.common.service.PrecisionMedicineGeneService;
|
||||
import com.peanut.modules.common.service.PrecisionMedicinePrescriptionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
//精准医疗基因、方剂
|
||||
@Slf4j
|
||||
@RestController("masterPrecisionMedicine")
|
||||
@RequestMapping("master/precisionMedicine")
|
||||
public class PrecisionMedicineController {
|
||||
|
||||
@Autowired
|
||||
private PrecisionMedicineGeneService geneService;
|
||||
@Autowired
|
||||
private PrecisionMedicinePrescriptionService prescriptionService;
|
||||
|
||||
//基因管理
|
||||
@RequestMapping("/getGeneListByPage")
|
||||
public R getGeneListByPage(@RequestBody Map<String,Object> params) {
|
||||
LambdaQueryWrapper<PrecisionMedicineGene> wrapper = new LambdaQueryWrapper();
|
||||
if (StringUtils.isNotEmpty(params.get("name").toString())) {
|
||||
wrapper.like(PrecisionMedicineGene::getName,params.get("name"));
|
||||
}
|
||||
wrapper.orderByDesc(PrecisionMedicineGene::getCreateTime);
|
||||
Page<PrecisionMedicineGene> page = geneService.page(new Page<>(
|
||||
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
||||
return R.ok().put("result", page);
|
||||
}
|
||||
|
||||
@RequestMapping("/getGeneById")
|
||||
public R getGeneById(@RequestBody Map<String,Object> params) {
|
||||
return R.ok().put("result", geneService.getById(params.get("id").toString()));
|
||||
}
|
||||
|
||||
@RequestMapping("/saveGene")
|
||||
public R saveMessage(@RequestBody PrecisionMedicineGene gene) {
|
||||
geneService.save(gene);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/updateGene")
|
||||
public R updateGene(@RequestBody PrecisionMedicineGene gene) {
|
||||
geneService.updateById(gene);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/delGene")
|
||||
public R delGene(@RequestBody Map<String,Object> params) {
|
||||
geneService.removeById(params.get("id").toString());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//方剂管理
|
||||
@RequestMapping("/getPrescriptionListByPage")
|
||||
public R getPrescriptionListByPage(@RequestBody Map<String,Object> params) {
|
||||
LambdaQueryWrapper<PrecisionMedicinePrescription> wrapper = new LambdaQueryWrapper();
|
||||
if (StringUtils.isNotEmpty(params.get("name").toString())) {
|
||||
wrapper.like(PrecisionMedicinePrescription::getName,params.get("name"));
|
||||
}
|
||||
wrapper.orderByDesc(PrecisionMedicinePrescription::getCreateTime);
|
||||
Page<PrecisionMedicinePrescription> page = prescriptionService.page(new Page<>(
|
||||
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
||||
return R.ok().put("result", page);
|
||||
}
|
||||
|
||||
@RequestMapping("/getPrescriptionById")
|
||||
public R getPrescriptionById(@RequestBody Map<String,Object> params) {
|
||||
return R.ok().put("result", prescriptionService.getById(params.get("id").toString()));
|
||||
}
|
||||
|
||||
@RequestMapping("/savePrescription")
|
||||
public R savePrescription(@RequestBody PrecisionMedicinePrescription prescription) {
|
||||
prescriptionService.save(prescription);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/updatePrescription")
|
||||
public R updatePrescription(@RequestBody PrecisionMedicinePrescription prescription) {
|
||||
prescriptionService.updateById(prescription);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/delPrescription")
|
||||
public R delPrescription(@RequestBody Map<String,Object> params) {
|
||||
prescriptionService.removeById(params.get("id").toString());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.peanut.modules.taihumed.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.PrecisionMedicineGene;
|
||||
import com.peanut.modules.common.service.PrecisionMedicineGeneService;
|
||||
import com.peanut.modules.common.service.PrecisionMedicinePrescriptionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController("taihumedPrecisionMedicine")
|
||||
@RequestMapping("taihumed/precisionMedicine")
|
||||
public class PrecisionMedicineController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private PrecisionMedicineGeneService geneService;
|
||||
@Autowired
|
||||
private PrecisionMedicinePrescriptionService prescriptionService;
|
||||
|
||||
|
||||
@RequestMapping("/getPrecisionMedicineGenes")
|
||||
public R getPrecisionMedicineGenes(@RequestBody Map<String,Object> params){
|
||||
List<PrecisionMedicineGene> genes = geneService.list(new LambdaQueryWrapper<PrecisionMedicineGene>()
|
||||
.and(t->t.like(PrecisionMedicineGene::getName,params.get("name"))
|
||||
.or().like(PrecisionMedicineGene::getAlias,params.get("name"))));
|
||||
return R.ok().put("genes",genes);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/getGenes")
|
||||
public void getPrescriptions(HttpServletResponse response){
|
||||
List<PrecisionMedicineGene> genes = geneService.list();
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
//创建一张表
|
||||
Sheet sheet = wb.createSheet("Student");
|
||||
//创建第一行,起始为0
|
||||
Row titleRow = sheet.createRow(0);
|
||||
titleRow.createCell(0).setCellValue("基因名称");
|
||||
titleRow.createCell(1).setCellValue("基因中文名");
|
||||
titleRow.createCell(2).setCellValue("描述");
|
||||
titleRow.createCell(3).setCellValue("关联药材名");
|
||||
titleRow.createCell(4).setCellValue("关联方剂");
|
||||
//序号,默认为1
|
||||
int cell = 1;
|
||||
//遍历
|
||||
for (PrecisionMedicineGene gene:genes){
|
||||
Map<String,Object> geneInfo = geneService.getGeneInfo(gene.getId().toString());
|
||||
List<Map<String,Object>> prescriptionList = (List<Map<String, Object>>) geneInfo.get("prescriptionList");
|
||||
String prescriptionStr = "";
|
||||
for (Map<String, Object> prescription:prescriptionList) {
|
||||
prescriptionStr+="匹配方剂:"+prescription.get("name")+",方剂组成:"+prescription.get("compose")+"出处:"+prescription.get("source")+";";
|
||||
}
|
||||
Row row = sheet.createRow(cell);
|
||||
row.createCell(0).setCellValue(gene.getName());
|
||||
row.createCell(1).setCellValue(gene.getNamecn());
|
||||
row.createCell(2).setCellValue(gene.getDescription());
|
||||
row.createCell(3).setCellValue(gene.getTcmName());
|
||||
row.createCell(4).setCellValue(prescriptionStr);
|
||||
//序号自增
|
||||
cell++;
|
||||
}
|
||||
String fileName = "基因药材方剂.xlsx";
|
||||
OutputStream outputStream =null;
|
||||
try {
|
||||
//文件名编码格式
|
||||
fileName = URLEncoder.encode(fileName,"UTF-8");
|
||||
//设置ContentType请求信息格式
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
//设置标头
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
||||
outputStream = response.getOutputStream();
|
||||
wb.write(outputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// return R.ok().put("genes",genes);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user