|
|
@@ -1,7 +1,14 @@
|
|
|
package cn.tr.module.phototherapy.common.service.impl;
|
|
|
|
|
|
+import cn.tr.module.phototherapy.common.dto.PatientTherapyDetailDTO;
|
|
|
+import cn.tr.module.phototherapy.common.enums.IsCurrentBindEnum;
|
|
|
+import cn.tr.module.phototherapy.common.enums.TherapyStatusEnum;
|
|
|
+import cn.tr.module.phototherapy.common.po.BusTherapyPlanPO;
|
|
|
+import cn.tr.module.phototherapy.common.po.BusTherapyRecordPO;
|
|
|
+import cn.tr.module.phototherapy.common.repository.BusTherapyPlanRepository;
|
|
|
+import cn.tr.module.phototherapy.common.repository.BusTherapyRecordRepository;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
@@ -12,6 +19,9 @@ import cn.tr.module.phototherapy.common.repository.BusClinicRepository;
|
|
|
import cn.tr.module.phototherapy.common.po.BusClinicPO;
|
|
|
import cn.tr.module.phototherapy.common.dto.BusClinicDTO;
|
|
|
import cn.tr.module.phototherapy.common.dto.BusClinicQueryDTO;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import cn.tr.module.phototherapy.common.service.IBusClinicService;
|
|
|
import cn.tr.module.phototherapy.common.mapper.BusClinicMapper;
|
|
|
@@ -26,6 +36,11 @@ import cn.tr.core.exception.TRExcCode;
|
|
|
@Service
|
|
|
public class BusClinicServiceImpl extends ServiceImpl<BusClinicRepository, BusClinicPO> implements IBusClinicService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private BusTherapyPlanRepository therapyPlanRepository;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BusTherapyRecordRepository therapyRecordRepository;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -44,9 +59,9 @@ public class BusClinicServiceImpl extends ServiceImpl<BusClinicRepository, BusCl
|
|
|
.eq(ObjectUtil.isNotNull(query.getLastTreatmentTime()), BusClinicPO::getLastTreatmentTime, query.getLastTreatmentTime())
|
|
|
.eq(ObjectUtil.isNotNull(query.getTherapyPlanId()), BusClinicPO::getTherapyPlanId, query.getTherapyPlanId())
|
|
|
.like(ObjectUtil.isNotNull(query.getPatientName()), BusClinicPO::getPatientName, query.getPatientName())
|
|
|
- .eq(ObjectUtil.isNotNull(query.getPatentAge()), BusClinicPO::getPatentAge, query.getPatentAge())
|
|
|
+ .eq(ObjectUtil.isNotNull(query.getPatientAge()), BusClinicPO::getPatientAge, query.getPatientAge())
|
|
|
.eq(ObjectUtil.isNotNull(query.getPatientGender()), BusClinicPO::getPatientGender, query.getPatientGender())
|
|
|
- .like(ObjectUtil.isNotNull(query.getPatentPhone()), BusClinicPO::getPatentPhone, query.getPatentPhone())
|
|
|
+ .like(ObjectUtil.isNotNull(query.getPatientPhone()), BusClinicPO::getPatientPhone, query.getPatientPhone())
|
|
|
.like(ObjectUtil.isNotNull(query.getPatientAddress()), BusClinicPO::getPatientAddress, query.getPatientAddress())
|
|
|
.eq(ObjectUtil.isNotNull(query.getDeviceId()), BusClinicPO::getDeviceId, query.getDeviceId())
|
|
|
.eq(ObjectUtil.isNotNull(query.getTenantId()), BusClinicPO::getTenantId, query.getTenantId())
|
|
|
@@ -103,4 +118,122 @@ public class BusClinicServiceImpl extends ServiceImpl<BusClinicRepository, BusCl
|
|
|
}
|
|
|
return this.removeByIds(ids);
|
|
|
};
|
|
|
+
|
|
|
+ /***
|
|
|
+ * 根据临床表id获取患者治疗详情
|
|
|
+ * @param clinicId
|
|
|
+ * @date 2026-01-20
|
|
|
+ **/
|
|
|
+ @Override
|
|
|
+ public PatientTherapyDetailDTO getPatientTherapyDetailById(String clinicId) {
|
|
|
+ // 查询临床信息
|
|
|
+ BusClinicPO clinicPO = this.getById(clinicId);
|
|
|
+ if (ObjectUtil.isNull(clinicPO)) {
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "临床信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询治疗方案信息
|
|
|
+ BusTherapyPlanPO therapyPlanPO = therapyPlanRepository.selectById(clinicPO.getTherapyPlanId());
|
|
|
+
|
|
|
+ // 查询治疗记录信息
|
|
|
+ LambdaQueryWrapper<BusTherapyRecordPO> therapyRecordQuery = new LambdaQueryWrapper<>();
|
|
|
+ therapyRecordQuery.eq(BusTherapyRecordPO::getClinicId, clinicId)
|
|
|
+ .eq(BusTherapyRecordPO::getIsDelete, 0)
|
|
|
+ .orderByDesc(BusTherapyRecordPO::getTherapyStartTime);
|
|
|
+
|
|
|
+ List<BusTherapyRecordPO> therapyRecords = therapyRecordRepository.selectList(therapyRecordQuery);
|
|
|
+
|
|
|
+ // 组装患者治疗详情DTO
|
|
|
+ PatientTherapyDetailDTO detailDTO = new PatientTherapyDetailDTO();
|
|
|
+
|
|
|
+ // 设置患者信息(来自bus_clinic表)
|
|
|
+ detailDTO.setPatientName(clinicPO.getPatientName());
|
|
|
+ detailDTO.setPatientAge(clinicPO.getPatientAge());
|
|
|
+ detailDTO.setPatientGender(clinicPO.getPatientGender());
|
|
|
+ detailDTO.setPatientUniqueId(clinicPO.getPatientUniqueId());
|
|
|
+ detailDTO.setPatientPhone(clinicPO.getPatientPhone());
|
|
|
+ detailDTO.setPatientAddress(clinicPO.getPatientAddress());
|
|
|
+ detailDTO.setLastTreatmentTime(clinicPO.getLastTreatmentTime());
|
|
|
+ detailDTO.setGroupType(clinicPO.getGroupType());
|
|
|
+
|
|
|
+ // 统计治疗次数(按天求和)
|
|
|
+ Set<Date> therapyDays = new HashSet<>();
|
|
|
+ if (CollectionUtil.isNotEmpty(therapyRecords)) {
|
|
|
+ for (BusTherapyRecordPO record : therapyRecords) {
|
|
|
+ if (ObjectUtil.isNotNull(record.getTherapyStartTime())) {
|
|
|
+ therapyDays.add(record.getTherapyStartTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detailDTO.setTherapyCount(therapyDays.size());
|
|
|
+
|
|
|
+/* // 计算依从性(这里简化处理,实际需要根据治疗记录和计划计算)
|
|
|
+ detailDTO.setCompliance(0);*/
|
|
|
+
|
|
|
+ // 判断今日治疗状态
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LambdaQueryWrapper<BusTherapyRecordPO> todayTherapyQuery = new LambdaQueryWrapper<>();
|
|
|
+ todayTherapyQuery.eq(BusTherapyRecordPO::getClinicId, clinicId)
|
|
|
+ .ge(BusTherapyRecordPO::getTherapyStartTime, today.atStartOfDay())
|
|
|
+ .le(BusTherapyRecordPO::getTherapyStartTime, today.atTime(23, 59, 59))
|
|
|
+ .eq(BusTherapyRecordPO::getIsDelete, 0);
|
|
|
+
|
|
|
+ List<BusTherapyRecordPO> todayTherapyRecords = therapyRecordRepository.selectList(todayTherapyQuery);
|
|
|
+ if (CollectionUtil.isEmpty(todayTherapyRecords)) {
|
|
|
+ detailDTO.setTherapyStatus(TherapyStatusEnum.NOT_STARTED.getText()); // 状态为未进行
|
|
|
+ } else {
|
|
|
+ // 根据最新的治疗记录判断状态
|
|
|
+ BusTherapyRecordPO latestTherapyRecord = todayTherapyRecords.get(0);
|
|
|
+ if (ObjectUtil.isNotNull(latestTherapyRecord.getTherapyStatus())) {
|
|
|
+ TherapyStatusEnum statusEnum = TherapyStatusEnum.getByValue(latestTherapyRecord.getTherapyStatus());
|
|
|
+ if (ObjectUtil.isNotNull(statusEnum)) {
|
|
|
+ detailDTO.setTherapyStatus(statusEnum.getText()); // 不为空,获取当前状态
|
|
|
+ } else {
|
|
|
+ detailDTO.setTherapyStatus("未知");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ detailDTO.setTherapyStatus("未知");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置光疗方案信息
|
|
|
+ if (ObjectUtil.isNotNull(therapyPlanPO)) {
|
|
|
+ // 使用继承的createTime字段
|
|
|
+ if (ObjectUtil.isNotNull(therapyPlanPO.getCreateTime())) {
|
|
|
+ detailDTO.setStartTime(therapyPlanPO.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
|
|
|
+ }
|
|
|
+ detailDTO.setPhaseType(therapyPlanPO.getPhaseType());
|
|
|
+
|
|
|
+ // 组装治疗方案描述
|
|
|
+ String therapyPlan = "";
|
|
|
+ if (ObjectUtil.isNotNull(therapyPlanPO.getPhaseFreq())) {
|
|
|
+ therapyPlan += therapyPlanPO.getPhaseFreq();
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotNull(therapyPlanPO.getPhaseDurationMin())) {
|
|
|
+ therapyPlan += "; 每次" + therapyPlanPO.getPhaseDurationMin() + "min";
|
|
|
+ }
|
|
|
+ detailDTO.setTherapyPlan(therapyPlan);
|
|
|
+
|
|
|
+ detailDTO.setPlanDoctor(therapyPlanPO.getPlanDoctor());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置设备信息
|
|
|
+ detailDTO.setDeviceId(clinicPO.getDeviceId());
|
|
|
+
|
|
|
+ // 查询设备绑定信息
|
|
|
+ // 查询设备绑定信息 - 使用clinic表中的isCurrentBind字段判断是否为当前绑定
|
|
|
+ if (ObjectUtil.isNotNull(clinicPO.getDeviceId()) &&
|
|
|
+ ObjectUtil.isNotNull(clinicPO.getIsCurrentBind()) &&
|
|
|
+ clinicPO.getIsCurrentBind().equals(IsCurrentBindEnum.CURRENT_BIND.getValue()) &&
|
|
|
+ ObjectUtil.isNotNull(clinicPO.getBindStartTime())) {
|
|
|
+ // 如果是当前绑定,则显示绑定开始时间
|
|
|
+ detailDTO.setBindStartTime(clinicPO.getBindStartTime());
|
|
|
+ } else {
|
|
|
+ // 如果不是当前绑定,显示无设备
|
|
|
+ detailDTO.setDeviceId(null); // TODO设置为"无设备"等提示信息
|
|
|
+ }
|
|
|
+
|
|
|
+ return detailDTO;
|
|
|
+
|
|
|
+ }
|
|
|
}
|