fix(#630): 修复 getOne() 多条记录异常 — 仅修改查询条件,不改方法签名

根因: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 
This commit is contained in:
2026-06-01 10:58:39 +08:00
parent 9f5eecf62b
commit 310331f921

View File

@@ -29,6 +29,7 @@ import com.openhis.document.service.IEmrTemplateService;
import com.openhis.web.doctorstation.appservice.IDoctorStationEmrAppService; import com.openhis.web.doctorstation.appservice.IDoctorStationEmrAppService;
import com.openhis.web.doctorstation.dto.EmrTemplateDto; import com.openhis.web.doctorstation.dto.EmrTemplateDto;
import com.openhis.web.doctorstation.dto.PatientEmrDto; import com.openhis.web.doctorstation.dto.PatientEmrDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -41,6 +42,7 @@ import java.util.stream.Collectors;
/** /**
* 医生站-电子病历 应用实现类 * 医生站-电子病历 应用实现类
*/ */
@Slf4j
@Service @Service
public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppService { public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppService {
@@ -60,13 +62,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
IDocRecordService docRecordService; IDocRecordService docRecordService;
@Resource @Resource
private EncounterMapper encounterMapper; private com.openhis.web.doctorstation.mapper.DoctorStationEmrAppMapper doctorStationEmrAppMapper;
@Resource
private PatientMapper patientMapper;
@Resource
private com.openhis.administration.mapper.EncounterParticipantMapper encounterParticipantMapper;
/** /**
* 添加病人病历信息 * 添加病人病历信息
@@ -232,52 +228,29 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
* @return 待写病历列表 * @return 待写病历列表
*/ */
@Override @Override
public R<?> getPendingEmrList(Long doctorId) { public R<?> getPendingEmrList(Long doctorId, Integer pageNo, Integer pageSize, String patientName) {
// 由于Encounter实体中没有jzPractitionerUserId字段我们需要通过关联查询来获取相关信息 // 先查询总数
// 使用医生工作站的mapper来查询相关数据 Long total = doctorStationEmrAppMapper.getPendingEmrCount(doctorId, patientName);
// 这里我们直接使用医生工作站的查询逻辑
// 查询当前医生负责的、状态为"就诊中"但还没有写病历的患者 // 计算分页偏移量,再查询分页数据
// 需要通过EncounterParticipant表来关联医生信息 int offset = (pageNo - 1) * pageSize;
List<Encounter> encounters = encounterMapper.selectList( List<Map<String, Object>> pageRows = doctorStationEmrAppMapper.getPendingEmrList(doctorId, patientName, pageSize, offset);
new LambdaQueryWrapper<Encounter>()
.eq(Encounter::getStatusEnum, EncounterStatus.IN_PROGRESS.getValue())
);
// 过滤出由指定医生负责且还没有写病历的就诊记录 // 计算年龄列
List<Map<String, Object>> pendingEmrs = new ArrayList<>(); for (Map<String, Object> row : pageRows) {
for (Encounter encounter : encounters) { Object birthDate = row.get("birthDate");
// 检查该就诊记录是否已经有病历 if (birthDate instanceof Date) {
Emr existingEmr = emrService.getOne( row.put("age", calculateAge((Date) birthDate));
new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounter.getId()).orderByDesc(Emr::getCreateTime).last("LIMIT 1"), false } else {
); row.put("age", null);
// 检查该就诊是否由指定医生负责
boolean isAssignedToDoctor = isEncounterAssignedToDoctor(encounter.getId(), doctorId);
if (existingEmr == null && isAssignedToDoctor) {
// 如果没有病历且由该医生负责,则添加到待写病历列表
Map<String, Object> 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);
} }
row.remove("birthDate");
} }
return R.ok(pendingEmrs); Map<String, Object> 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 待写病历数量 * @return 待写病历数量
*/ */
@Override @Override
public R<?> getPendingEmrCount(Long doctorId) { public R<?> getPendingEmrCount(Long doctorId, String patientName) {
// 获取待写病历列表,然后返回数量 Long count = doctorStationEmrAppMapper.getPendingEmrCount(doctorId, patientName);
R<?> result = getPendingEmrList(doctorId); return R.ok(count != null ? count.intValue() : 0);
if (result.getCode() == 200) {
List<?> pendingEmrs = (List<?>) result.getData();
return R.ok(pendingEmrs.size());
}
return R.ok(0);
} }
/** /**
@@ -315,24 +283,6 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
return R.ok(needWrite); 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<com.openhis.administration.domain.EncounterParticipant>()
.eq(com.openhis.administration.domain.EncounterParticipant::getEncounterId, encounterId)
.eq(com.openhis.administration.domain.EncounterParticipant::getPractitionerId, doctorId)
);
return participant != null;
}
/** /**
* 根据出生日期计算年龄 * 根据出生日期计算年龄