From fdf8fcc1bbff494c2b29f2ab2ade095923d8c3d2 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 18 Jul 2025 11:11:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=AA=E6=B9=96=E4=BA=91=E5=8C=BB=E5=8C=BB?= =?UTF-8?q?=E6=A1=88=E6=94=B6=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MedicalRecordsController.java | 115 ++++++++++++++++++ .../modules/common/entity/MedicalRecords.java | 5 + .../controller/MedicalRecordsController.java | 33 +++++ 3 files changed, 153 insertions(+) create mode 100644 src/main/java/com/peanut/modules/common/controller/MedicalRecordsController.java diff --git a/src/main/java/com/peanut/modules/common/controller/MedicalRecordsController.java b/src/main/java/com/peanut/modules/common/controller/MedicalRecordsController.java new file mode 100644 index 00000000..22a555d6 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/controller/MedicalRecordsController.java @@ -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 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 parmas) { + List list = medicalRecordsService.list(new LambdaQueryWrapper() + .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); + } + +} diff --git a/src/main/java/com/peanut/modules/common/entity/MedicalRecords.java b/src/main/java/com/peanut/modules/common/entity/MedicalRecords.java index 93a8abd4..6945f0e4 100644 --- a/src/main/java/com/peanut/modules/common/entity/MedicalRecords.java +++ b/src/main/java/com/peanut/modules/common/entity/MedicalRecords.java @@ -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; } diff --git a/src/main/java/com/peanut/modules/master/controller/MedicalRecordsController.java b/src/main/java/com/peanut/modules/master/controller/MedicalRecordsController.java index c0de72de..de6800a1 100644 --- a/src/main/java/com/peanut/modules/master/controller/MedicalRecordsController.java +++ b/src/main/java/com/peanut/modules/master/controller/MedicalRecordsController.java @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Slf4j @@ -30,6 +31,38 @@ public class MedicalRecordsController { @Autowired private MedicalRecordsToLabelService toLabelService; + + + @RequestMapping("/getMedicalRecordsList") + public R getMedicalRecordsList(@RequestBody Map params){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); + wrapper.rightJoin(MedicalRecordsToLabel.class,MedicalRecordsToLabel::getRecordId,MedicalRecords::getId); + wrapper.selectAll(MedicalRecords.class); + wrapper.eq(MedicalRecordsToLabel::getLabelId,params.get("labelId")); + wrapper.eq(MedicalRecords::getState,1); + wrapper.eq(StringUtils.isNotBlank(params.get("train").toString()),MedicalRecords::getTrain,params.get("train")); + wrapper.eq(StringUtils.isNotBlank(params.get("title").toString()),MedicalRecords::getTitle,params.get("title")); + Page page = medicalRecordsService.page(new Page<>( + Long.parseLong(params.get("current").toString()),Long.parseLong(params.get("limit").toString())),wrapper); + return R.ok().put("page",page); + } + + @RequestMapping("/addMedicalRecords") + public R addMedicalRecords(@RequestBody MedicalRecords medicalRecords){ + medicalRecords.setState(1); + medicalRecordsService.updateById(medicalRecords); + return R.ok(); + } + + @RequestMapping("/editMedicalRecords") + public R editMedicalRecords(@RequestBody MedicalRecords medicalRecords){ + medicalRecordsService.updateById(medicalRecords); + return R.ok(); + } + + + + @RequestMapping("/getMedicalRecordsLabelList") public R getMedicalRecordsLabelList(){ return R.ok().put("Medicals", medicalRecordsLabels(0));