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 c44f32c24..2f6b9bcef 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,7 +29,6 @@ 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; @@ -42,7 +41,6 @@ import java.util.stream.Collectors; /** * 医生站-电子病历 应用实现类 */ -@Slf4j @Service public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppService { @@ -62,7 +60,13 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi IDocRecordService docRecordService; @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(); BeanUtils.copyProperties(patientEmrDto, emr); String contextStr = patientEmrDto.getContextJson().toString(); - Emr patientEmr = emrService.getOne(new LambdaQueryWrapper().eq(Emr::getEncounterId, emr.getEncounterId()).last("LIMIT 1")); + Emr patientEmr = emrService.getOne(new LambdaQueryWrapper().eq(Emr::getEncounterId, emr.getEncounterId()).orderByDesc(Emr::getCreateTime).last("LIMIT 1"), false); boolean saveSuccess; // 如果已经保存病历,再次保存走更新 if (patientEmr != null) { @@ -145,7 +149,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi return R.ok(null); } // 先查询门诊病历(emr表) - Emr emrDetail = emrService.getOne(new LambdaQueryWrapper().eq(Emr::getEncounterId, encounterId), false); + Emr emrDetail = emrService.getOne(new LambdaQueryWrapper().eq(Emr::getEncounterId, encounterId).orderByDesc(Emr::getCreateTime).last("LIMIT 1"), false); if (emrDetail != null) { return R.ok(emrDetail); } @@ -155,7 +159,8 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi new LambdaQueryWrapper() .eq(DocRecord::getEncounterId, encounterId) .orderByDesc(DocRecord::getCreateTime) - .last("LIMIT 1") + .last("LIMIT 1"), + false ); if (docRecord != null) { // 住院病历存在,也返回数据 @@ -227,29 +232,52 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi * @return 待写病历列表 */ @Override - public R getPendingEmrList(Long doctorId, Integer pageNo, Integer pageSize, String patientName) { - // 先查询总数 - Long total = doctorStationEmrAppMapper.getPendingEmrCount(doctorId, patientName); + public R getPendingEmrList(Long doctorId) { + // 由于Encounter实体中没有jzPractitionerUserId字段,我们需要通过关联查询来获取相关信息 + // 使用医生工作站的mapper来查询相关数据 + // 这里我们直接使用医生工作站的查询逻辑 - // 计算分页偏移量,再查询分页数据 - int offset = (pageNo - 1) * pageSize; - List> pageRows = doctorStationEmrAppMapper.getPendingEmrList(doctorId, patientName, pageSize, offset); + // 查询当前医生负责的、状态为"就诊中"但还没有写病历的患者 + // 需要通过EncounterParticipant表来关联医生信息 + List encounters = encounterMapper.selectList( + new LambdaQueryWrapper() + .eq(Encounter::getStatusEnum, EncounterStatus.IN_PROGRESS.getValue()) + ); - // 计算年龄列 - for (Map row : pageRows) { - Object birthDate = row.get("birthDate"); - if (birthDate instanceof Date) { - row.put("age", calculateAge((Date) birthDate)); - } else { - row.put("age", null); + // 过滤出由指定医生负责且还没有写病历的就诊记录 + 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); } - row.remove("birthDate"); } - Map result = new java.util.HashMap<>(); - result.put("rows", pageRows); - result.put("total", total != null ? total : 0L); - return R.ok(result); + return R.ok(pendingEmrs); } /** @@ -259,9 +287,14 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi * @return 待写病历数量 */ @Override - public R getPendingEmrCount(Long doctorId, String patientName) { - Long count = doctorStationEmrAppMapper.getPendingEmrCount(doctorId, patientName); - return R.ok(count != null ? count.intValue() : 0); + 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); } /** @@ -274,7 +307,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi public R checkNeedWriteEmr(Long encounterId) { // 检查该就诊记录是否已经有病历 Emr existingEmr = emrService.getOne( - new LambdaQueryWrapper().eq(Emr::getEncounterId, encounterId).last("LIMIT 1") + new LambdaQueryWrapper().eq(Emr::getEncounterId, encounterId).orderByDesc(Emr::getCreateTime).last("LIMIT 1"), false ); // 如果没有病历,则需要写病历 @@ -282,6 +315,24 @@ 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; + } /** * 根据出生日期计算年龄