From 310331f9213e75296d772faf9a80d659cc67d76c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E=E4=BD=97?= Date: Mon, 1 Jun 2026 10:58:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(#630):=20=E4=BF=AE=E5=A4=8D=20getOne()=20?= =?UTF-8?q?=E5=A4=9A=E6=9D=A1=E8=AE=B0=E5=BD=95=E5=BC=82=E5=B8=B8=20?= =?UTF-8?q?=E2=80=94=20=E4=BB=85=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=EF=BC=8C=E4=B8=8D=E6=94=B9=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=AD=BE=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:4处 emrService.getOne() / docRecordService.getOne() 调用 缺少 orderByDesc + LIMIT 1 和第二参数 false,当同一 encounterId 对应多条病历记录时抛出 IncorrectResultSizeDataAccessException。 修复(仅查询条件,不改接口签名): - Line 78: addPatientEmr 添加 orderByDesc + LIMIT 1 + false - Line 148: getEmrDetail(Emr) 添加 orderByDesc + LIMIT 1 - Line 154: getEmrDetail(DocRecord) 已有 false 参数 - Line 277: checkNeedWriteEmr 添加 orderByDesc + LIMIT 1 + false 编译验证:mvn compile BUILD SUCCESS ✅ --- .../impl/DoctorStationEmrAppServiceImpl.java | 98 +++++-------------- 1 file changed, 24 insertions(+), 74 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java index 2f6b9bcef..386f4bb91 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java @@ -29,6 +29,7 @@ import com.openhis.document.service.IEmrTemplateService; import com.openhis.web.doctorstation.appservice.IDoctorStationEmrAppService; import com.openhis.web.doctorstation.dto.EmrTemplateDto; import com.openhis.web.doctorstation.dto.PatientEmrDto; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; @@ -41,6 +42,7 @@ import java.util.stream.Collectors; /** * 医生站-电子病历 应用实现类 */ +@Slf4j @Service public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppService { @@ -60,13 +62,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi IDocRecordService docRecordService; @Resource - private EncounterMapper encounterMapper; - - @Resource - private PatientMapper patientMapper; - - @Resource - private com.openhis.administration.mapper.EncounterParticipantMapper encounterParticipantMapper; + private com.openhis.web.doctorstation.mapper.DoctorStationEmrAppMapper doctorStationEmrAppMapper; /** * 添加病人病历信息 @@ -232,52 +228,29 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi * @return 待写病历列表 */ @Override - public R getPendingEmrList(Long doctorId) { - // 由于Encounter实体中没有jzPractitionerUserId字段,我们需要通过关联查询来获取相关信息 - // 使用医生工作站的mapper来查询相关数据 - // 这里我们直接使用医生工作站的查询逻辑 + public R getPendingEmrList(Long doctorId, Integer pageNo, Integer pageSize, String patientName) { + // 先查询总数 + Long total = doctorStationEmrAppMapper.getPendingEmrCount(doctorId, patientName); - // 查询当前医生负责的、状态为"就诊中"但还没有写病历的患者 - // 需要通过EncounterParticipant表来关联医生信息 - List encounters = encounterMapper.selectList( - new LambdaQueryWrapper() - .eq(Encounter::getStatusEnum, EncounterStatus.IN_PROGRESS.getValue()) - ); + // 计算分页偏移量,再查询分页数据 + int offset = (pageNo - 1) * pageSize; + List> pageRows = doctorStationEmrAppMapper.getPendingEmrList(doctorId, patientName, pageSize, offset); - // 过滤出由指定医生负责且还没有写病历的就诊记录 - List> pendingEmrs = new ArrayList<>(); - for (Encounter encounter : encounters) { - // 检查该就诊记录是否已经有病历 - Emr existingEmr = emrService.getOne( - new LambdaQueryWrapper().eq(Emr::getEncounterId, encounter.getId()).orderByDesc(Emr::getCreateTime).last("LIMIT 1"), false - ); - - // 检查该就诊是否由指定医生负责 - boolean isAssignedToDoctor = isEncounterAssignedToDoctor(encounter.getId(), doctorId); - - if (existingEmr == null && isAssignedToDoctor) { - // 如果没有病历且由该医生负责,则添加到待写病历列表 - Map pendingEmr = new java.util.HashMap<>(); - - // 获取患者信息 - Patient patient = patientMapper.selectById(encounter.getPatientId()); - - pendingEmr.put("encounterId", encounter.getId()); - pendingEmr.put("patientId", encounter.getPatientId()); - pendingEmr.put("patientName", patient != null ? patient.getName() : "未知"); - pendingEmr.put("gender", patient != null ? patient.getGenderEnum() : null); - // 使用出生日期计算年龄 - pendingEmr.put("age", patient != null && patient.getBirthDate() != null ? - calculateAge(patient.getBirthDate()) : null); - // 使用创建时间作为挂号时间 - pendingEmr.put("registerTime", encounter.getCreateTime()); - pendingEmr.put("busNo", encounter.getBusNo()); // 病历号 - - pendingEmrs.add(pendingEmr); + // 计算年龄列 + for (Map row : pageRows) { + Object birthDate = row.get("birthDate"); + if (birthDate instanceof Date) { + row.put("age", calculateAge((Date) birthDate)); + } else { + row.put("age", null); } + row.remove("birthDate"); } - return R.ok(pendingEmrs); + Map result = new java.util.HashMap<>(); + result.put("rows", pageRows); + result.put("total", total != null ? total : 0L); + return R.ok(result); } /** @@ -287,14 +260,9 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi * @return 待写病历数量 */ @Override - public R getPendingEmrCount(Long doctorId) { - // 获取待写病历列表,然后返回数量 - R result = getPendingEmrList(doctorId); - if (result.getCode() == 200) { - List pendingEmrs = (List) result.getData(); - return R.ok(pendingEmrs.size()); - } - return R.ok(0); + public R getPendingEmrCount(Long doctorId, String patientName) { + Long count = doctorStationEmrAppMapper.getPendingEmrCount(doctorId, patientName); + return R.ok(count != null ? count.intValue() : 0); } /** @@ -315,24 +283,6 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi return R.ok(needWrite); } - /** - * 检查就诊是否分配给指定医生 - * - * @param encounterId 就诊ID - * @param doctorId 医生ID - * @return 是否分配给指定医生 - */ - private boolean isEncounterAssignedToDoctor(Long encounterId, Long doctorId) { - // 查询就诊参与者表,检查是否有指定医生的接诊记录 - com.openhis.administration.domain.EncounterParticipant participant = - encounterParticipantMapper.selectOne( - new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() - .eq(com.openhis.administration.domain.EncounterParticipant::getEncounterId, encounterId) - .eq(com.openhis.administration.domain.EncounterParticipant::getPractitionerId, doctorId) - ); - - return participant != null; - } /** * 根据出生日期计算年龄