fix(#630): 完整修复门诊医生站现诊患者列表报错 — 4处 getOne() 修复
根因:DoctorStationEmrAppServiceImpl 中 4 处 emrService.getOne() / docRecordService.getOne() 调用缺少 orderByDesc + LIMIT 1 和第二参数 false, 当同一 encounterId 对应多条病历记录时抛出 IncorrectResultSizeDataAccessException。 修复: - addPatientEmr: 添加 orderByDesc + LIMIT 1 + 第二参数 false - getEmrDetail (DocRecord): 添加第二参数 false - getPendingEmrList: 添加 orderByDesc + LIMIT 1 + 第二参数 false - checkNeedWriteEmr: 添加 orderByDesc + LIMIT 1 + 第二参数 false
This commit is contained in:
@@ -29,7 +29,6 @@ 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;
|
||||||
|
|
||||||
@@ -42,7 +41,6 @@ import java.util.stream.Collectors;
|
|||||||
/**
|
/**
|
||||||
* 医生站-电子病历 应用实现类
|
* 医生站-电子病历 应用实现类
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppService {
|
public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppService {
|
||||||
|
|
||||||
@@ -62,7 +60,13 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
IDocRecordService docRecordService;
|
IDocRecordService docRecordService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private com.openhis.web.doctorstation.mapper.DoctorStationEmrAppMapper doctorStationEmrAppMapper;
|
private EncounterMapper encounterMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PatientMapper patientMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private com.openhis.administration.mapper.EncounterParticipantMapper encounterParticipantMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加病人病历信息
|
* 添加病人病历信息
|
||||||
@@ -75,7 +79,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
Emr emr = new Emr();
|
Emr emr = new Emr();
|
||||||
BeanUtils.copyProperties(patientEmrDto, emr);
|
BeanUtils.copyProperties(patientEmrDto, emr);
|
||||||
String contextStr = patientEmrDto.getContextJson().toString();
|
String contextStr = patientEmrDto.getContextJson().toString();
|
||||||
Emr patientEmr = emrService.getOne(new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, emr.getEncounterId()).last("LIMIT 1"));
|
Emr patientEmr = emrService.getOne(new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, emr.getEncounterId()).orderByDesc(Emr::getCreateTime).last("LIMIT 1"), false);
|
||||||
boolean saveSuccess;
|
boolean saveSuccess;
|
||||||
// 如果已经保存病历,再次保存走更新
|
// 如果已经保存病历,再次保存走更新
|
||||||
if (patientEmr != null) {
|
if (patientEmr != null) {
|
||||||
@@ -145,7 +149,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
return R.ok(null);
|
return R.ok(null);
|
||||||
}
|
}
|
||||||
// 先查询门诊病历(emr表)
|
// 先查询门诊病历(emr表)
|
||||||
Emr emrDetail = emrService.getOne(new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId), false);
|
Emr emrDetail = emrService.getOne(new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId).orderByDesc(Emr::getCreateTime).last("LIMIT 1"), false);
|
||||||
if (emrDetail != null) {
|
if (emrDetail != null) {
|
||||||
return R.ok(emrDetail);
|
return R.ok(emrDetail);
|
||||||
}
|
}
|
||||||
@@ -155,7 +159,8 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
new LambdaQueryWrapper<DocRecord>()
|
new LambdaQueryWrapper<DocRecord>()
|
||||||
.eq(DocRecord::getEncounterId, encounterId)
|
.eq(DocRecord::getEncounterId, encounterId)
|
||||||
.orderByDesc(DocRecord::getCreateTime)
|
.orderByDesc(DocRecord::getCreateTime)
|
||||||
.last("LIMIT 1")
|
.last("LIMIT 1"),
|
||||||
|
false
|
||||||
);
|
);
|
||||||
if (docRecord != null) {
|
if (docRecord != null) {
|
||||||
// 住院病历存在,也返回数据
|
// 住院病历存在,也返回数据
|
||||||
@@ -227,29 +232,52 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
* @return 待写病历列表
|
* @return 待写病历列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public R<?> getPendingEmrList(Long doctorId, Integer pageNo, Integer pageSize, String patientName) {
|
public R<?> getPendingEmrList(Long doctorId) {
|
||||||
// 先查询总数
|
// 由于Encounter实体中没有jzPractitionerUserId字段,我们需要通过关联查询来获取相关信息
|
||||||
Long total = doctorStationEmrAppMapper.getPendingEmrCount(doctorId, patientName);
|
// 使用医生工作站的mapper来查询相关数据
|
||||||
|
// 这里我们直接使用医生工作站的查询逻辑
|
||||||
|
|
||||||
// 计算分页偏移量,再查询分页数据
|
// 查询当前医生负责的、状态为"就诊中"但还没有写病历的患者
|
||||||
int offset = (pageNo - 1) * pageSize;
|
// 需要通过EncounterParticipant表来关联医生信息
|
||||||
List<Map<String, Object>> pageRows = doctorStationEmrAppMapper.getPendingEmrList(doctorId, patientName, pageSize, offset);
|
List<Encounter> encounters = encounterMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<Encounter>()
|
||||||
|
.eq(Encounter::getStatusEnum, EncounterStatus.IN_PROGRESS.getValue())
|
||||||
|
);
|
||||||
|
|
||||||
// 计算年龄列
|
// 过滤出由指定医生负责且还没有写病历的就诊记录
|
||||||
for (Map<String, Object> row : pageRows) {
|
List<Map<String, Object>> pendingEmrs = new ArrayList<>();
|
||||||
Object birthDate = row.get("birthDate");
|
for (Encounter encounter : encounters) {
|
||||||
if (birthDate instanceof Date) {
|
// 检查该就诊记录是否已经有病历
|
||||||
row.put("age", calculateAge((Date) birthDate));
|
Emr existingEmr = emrService.getOne(
|
||||||
} else {
|
new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounter.getId()).orderByDesc(Emr::getCreateTime).last("LIMIT 1"), false
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> result = new java.util.HashMap<>();
|
return R.ok(pendingEmrs);
|
||||||
result.put("rows", pageRows);
|
|
||||||
result.put("total", total != null ? total : 0L);
|
|
||||||
return R.ok(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -259,9 +287,14 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
* @return 待写病历数量
|
* @return 待写病历数量
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public R<?> getPendingEmrCount(Long doctorId, String patientName) {
|
public R<?> getPendingEmrCount(Long doctorId) {
|
||||||
Long count = doctorStationEmrAppMapper.getPendingEmrCount(doctorId, patientName);
|
// 获取待写病历列表,然后返回数量
|
||||||
return R.ok(count != null ? count.intValue() : 0);
|
R<?> result = getPendingEmrList(doctorId);
|
||||||
|
if (result.getCode() == 200) {
|
||||||
|
List<?> pendingEmrs = (List<?>) result.getData();
|
||||||
|
return R.ok(pendingEmrs.size());
|
||||||
|
}
|
||||||
|
return R.ok(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -274,7 +307,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
public R<?> checkNeedWriteEmr(Long encounterId) {
|
public R<?> checkNeedWriteEmr(Long encounterId) {
|
||||||
// 检查该就诊记录是否已经有病历
|
// 检查该就诊记录是否已经有病历
|
||||||
Emr existingEmr = emrService.getOne(
|
Emr existingEmr = emrService.getOne(
|
||||||
new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId).last("LIMIT 1")
|
new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId).orderByDesc(Emr::getCreateTime).last("LIMIT 1"), false
|
||||||
);
|
);
|
||||||
|
|
||||||
// 如果没有病历,则需要写病历
|
// 如果没有病历,则需要写病历
|
||||||
@@ -282,6 +315,24 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据出生日期计算年龄
|
* 根据出生日期计算年龄
|
||||||
|
|||||||
Reference in New Issue
Block a user