太湖云医医案收集

This commit is contained in:
wuchunlei
2025-07-18 11:11:16 +08:00
parent 556596475d
commit fdf8fcc1bb
3 changed files with 153 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
package com.peanut.modules.common.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.common.entity.MedicalRecords;
import com.peanut.modules.common.entity.MedicalRecordsToLabel;
import com.peanut.modules.common.service.MedicalRecordsService;
import com.peanut.modules.common.service.MedicalRecordsToLabelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Slf4j
@RestController("commonMedicalRecords")
@RequestMapping("common/medicalRecords")
public class MedicalRecordsController {
private final ChatClient chatClient;
@Autowired
private MedicalRecordsService medicalRecordsService;
@Autowired
private MedicalRecordsToLabelService medicalRecordsToLabelService;
public MedicalRecordsController(ChatClient.Builder chatClientBuilder, ToolCallbackProvider tools) {
this.chatClient = chatClientBuilder.defaultToolCallbacks(tools).build();
}
//拆分医案段落
@RequestMapping(value = "/medicalRecordsSplit")
public R medicalRecordsSplit(@RequestBody Map<String,Object> parmas) {
MedicalRecords mr = new MedicalRecords();
String uuid = UUID.randomUUID().toString();
StringBuffer sb = new StringBuffer();
Date date = new Date();
chatClient.prompt()
.user("你是一名文档编辑给你一份资料必须按照1.一般信息,2.主诉,3.现病史,4.既往史,5.家族史,6.体格检查,7.诊断,8.治疗和后续治疗;" +
"这8方面进行拆分不要增删内容,个人信息必须脱敏处理结果必须是markdown格式;内容如下:"+
parmas.get("message").toString())
.stream()
.content()
.doOnNext(data -> {
sb.append(data);
})
.doFinally(data -> {
System.out.println(sb);
String res = sb.toString().replace("```markdown\n","").replace("```","");
String[] datas = res.split("\n\n");
mr.setUserId(ShiroUtils.getUId());
mr.setInformation(datas[0]);
mr.setChiefComplaint(datas[1]);
mr.setHistoryOfPresentIllness(datas[2]);
mr.setPastHistory(datas[3]);
mr.setPersonalAndFamilyHistory(datas[4]);
mr.setPhysicaExamination(datas[5]);
mr.setDiagnosis(datas[6]);
mr.setTreatmentPlan(datas[7]);
mr.setData(uuid+"->\n"+res);
medicalRecordsService.save(mr);
System.out.println(new Date().getTime()-date.getTime());
})
.subscribe();
return R.ok().put("data",uuid);
}
//查询正在拆分的医案
@RequestMapping(value = "/medicalRecordsQuerySplit")
public R medicalRecordsQuerySplit(@RequestBody Map<String,Object> parmas) {
List<MedicalRecords> list = medicalRecordsService.list(new LambdaQueryWrapper<MedicalRecords>()
.like(MedicalRecords::getData,parmas.get("queryFlag")));
return R.ok().put("medicalRecords",list.size()>0?list.get(0):null);
}
//暂存或者保存医案
@RequestMapping(value = "/saveMedicalRecords")
@Transactional
public R saveMedicalRecords(@RequestBody MedicalRecords medicalRecords) {
MedicalRecordsToLabel toLabel = new MedicalRecordsToLabel();
toLabel.setRecordId(medicalRecords.getId());
toLabel.setLabelId(medicalRecords.getLabelId());
medicalRecordsToLabelService.save(toLabel);
if (medicalRecords.getState()==1){
if ("儿科".equals(medicalRecords.getLabelTitle())){
if ((!medicalRecords.getPastHistory().contains("接种")&&
!medicalRecords.getPastHistory().contains("疫苗"))&&
(!medicalRecords.getPersonalAndFamilyHistory().contains("接种")&&
!medicalRecords.getPersonalAndFamilyHistory().contains("疫苗"))){
return R.error("请补充患者疫苗接种信息");
}
}
if ("妇科".equals(medicalRecords.getLabelTitle())){
if ((!medicalRecords.getPastHistory().contains("月经")&&
!medicalRecords.getPastHistory().contains("例假")&&
!medicalRecords.getPastHistory().contains("婚育"))&&
(!medicalRecords.getPersonalAndFamilyHistory().contains("月经")&&
!medicalRecords.getPersonalAndFamilyHistory().contains("例假")&&
!medicalRecords.getPersonalAndFamilyHistory().contains("婚育"))){
return R.error("请补充患者月经婚育信息");
}
}
}
medicalRecordsService.save(medicalRecords);
return R.ok().put("medicalRecords",medicalRecords);
}
}

View File

@@ -1,5 +1,6 @@
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;
@@ -48,5 +49,9 @@ public class MedicalRecords {
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private Integer labelId;
@TableField(exist = false)
private String labelTitle;
}