diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/appointmentmanage/appservice/impl/DoctorScheduleAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/appointmentmanage/appservice/impl/DoctorScheduleAppServiceImpl.java index c5c8c1da..dbfcee09 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/appointmentmanage/appservice/impl/DoctorScheduleAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/appointmentmanage/appservice/impl/DoctorScheduleAppServiceImpl.java @@ -134,7 +134,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService { if (poolSaved) { // 创建号源槽 - List slots = createScheduleSlots(pool.getId().intValue(), newSchedule.getLimitNumber(), + List slots = createScheduleSlots(pool.getId(), newSchedule.getLimitNumber(), newSchedule.getStartTime(), newSchedule.getEndTime()); boolean slotsSaved = scheduleSlotService.saveBatch(slots); @@ -224,7 +224,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService { if (poolSaved) { // 创建号源槽 - List slots = createScheduleSlots(pool.getId().intValue(), newSchedule.getLimitNumber(), + List slots = createScheduleSlots(pool.getId(), newSchedule.getLimitNumber(), newSchedule.getStartTime(), newSchedule.getEndTime()); boolean slotsSaved = scheduleSlotService.saveBatch(slots); @@ -384,7 +384,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService { /** * 创建号源槽 */ - private List createScheduleSlots(Integer poolId, Integer limitNumber, LocalTime startTime, + private List createScheduleSlots(Long poolId, Integer limitNumber, LocalTime startTime, LocalTime endTime) { List slots = new ArrayList<>(); @@ -514,7 +514,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService { .in("pool_id", poolIds)); if (ObjectUtil.isNotEmpty(slots)) { - List slotIds = slots.stream().map(ScheduleSlot::getId) + List slotIds = slots.stream().map(ScheduleSlot::getId) .collect(java.util.stream.Collectors.toList()); // 3. 逻辑删除所有号源槽 scheduleSlotService.removeByIds(slotIds); diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/consultation/appservice/impl/ConsultationAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/consultation/appservice/impl/ConsultationAppServiceImpl.java index 6e5b6fa1..1fe860da 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/consultation/appservice/impl/ConsultationAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/consultation/appservice/impl/ConsultationAppServiceImpl.java @@ -581,8 +581,33 @@ public class ConsultationAppServiceImpl implements IConsultationAppService { .collect(Collectors.groupingBy(Practitioner::getOrgId)); // 构建树形结构 + // 过滤条件:科室分类只要包含"门诊(编码1)"或"住院(编码2)"其一,即可显示 List treeList = new ArrayList<>(); for (Organization dept : deptList) { + // 过滤科室:只显示包含门诊(1)或住院(2)分类的科室 + String classEnum = dept.getClassEnum(); + boolean needShow = false; + + if (classEnum != null && !classEnum.isEmpty()) { + // 拆分分类编码,检查是否包含 1 或 2 + String[] codes = classEnum.split(","); + for (String code : codes) { + code = code.trim(); + if ("1".equals(code) || "2".equals(code)) { + needShow = true; + break; + } + } + } else { + // 如果没有分类,默认显示 + needShow = true; + } + + if (!needShow) { + // 既不包含门诊也不包含住院,跳过 + continue; + } + DepartmentTreeDto treeDto = new DepartmentTreeDto(); treeDto.setId(dept.getId()); treeDto.setLabel(dept.getName()); @@ -599,11 +624,10 @@ public class ConsultationAppServiceImpl implements IConsultationAppService { }) .collect(Collectors.toList()); treeDto.setChildren(children); - } else { - treeDto.setChildren(new ArrayList<>()); + // 只添加有医生的科室 + treeList.add(treeDto); } - - treeList.add(treeDto); + // 没有医生的科室不添加到列表中 } @@ -1340,9 +1364,13 @@ public class ConsultationAppServiceImpl implements IConsultationAppService { throw new IllegalArgumentException("会诊申请不存在"); } - // 只有已提交状态才能确认 - if (request.getConsultationStatus() != ConsultationStatusEnum.SUBMITTED.getCode()) { - throw new IllegalArgumentException("只有已提交状态的会诊申请才能确认"); + // 会诊必须处于已提交或已确认状态才能确认 + // - 已提交(10):还没有医生确认 + // - 已确认(20):已有部分医生确认,允许其他医生继续确认(每个医生独立确认,类似已读) + // - 已签名(30)或已完成(40):不能再确认 + if (request.getConsultationStatus() != null && + request.getConsultationStatus() >= ConsultationStatusEnum.SIGNED.getCode()) { + throw new IllegalArgumentException("会诊已签名或完成,无法再确认"); } // 2. 获取当前登录医生信息 @@ -1360,26 +1388,20 @@ public class ConsultationAppServiceImpl implements IConsultationAppService { throw new IllegalArgumentException("您不在被邀请的医生列表中"); } + log.info("会诊确认检查:currentPhysicianId={}, invitedId={}, invitedStatus={}, CONFIRMED.code={}", + currentPhysicianId, invited.getId(), invited.getInvitedStatus(), ConsultationStatusEnum.CONFIRMED.getCode()); if (invited.getInvitedStatus() != null && invited.getInvitedStatus() >= ConsultationStatusEnum.CONFIRMED.getCode()) { throw new IllegalArgumentException("您已经确认过了,无需重复确认"); } // 4. 更新邀请记录(存储会诊意见) - // 格式:科室-会诊确认参加医师:意见内容 - // 兼容:若前端未填写“会诊确认参加医师”,则回退为当前医生姓名 - String confirmingPhysicianText = - StringUtils.hasText(dto.getConfirmingPhysician()) ? dto.getConfirmingPhysician().trim() : currentPhysicianName; - String formattedOpinion = String.format("%s-%s:%s", - currentDeptName, - confirmingPhysicianText, - dto.getConsultationOpinion()); - + // 直接存储用户输入的原始意见内容,不添加医师姓名前缀 invited.setInvitedStatus(ConsultationStatusEnum.CONFIRMED.getCode()); // 已确认 - invited.setConfirmOpinion(formattedOpinion); + invited.setConfirmOpinion(dto.getConsultationOpinion()); // 直接存储原始意见,不添加前缀 invited.setConfirmTime(new Date()); consultationInvitedMapper.updateById(invited); - - log.info("医生 {} 确认会诊,意见:{}", currentPhysicianName, formattedOpinion); + + log.info("医生 {} 确认会诊", currentPhysicianName); // 5. 更新会诊申请的确认计数 Integer confirmedCount = (request.getConfirmedCount() == null ? 0 : request.getConfirmedCount()) + 1; diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java index 9f086afa..b9e2b924 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java @@ -599,27 +599,40 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp } } - // 药品(前端adviceType=1) + // 药品(前端adviceType=1=西药, 2=中成药 → 都属于药品后端分类) List medicineList = adviceSaveList.stream() - .filter(e -> ItemType.MEDICINE.getValue().equals(e.getAdviceType()) - || e.getAdviceType() == 1).collect(Collectors.toList()); + .filter(e -> ItemType.MEDICINE.getValue().equals(e.getAdviceType()) + || e.getAdviceType() == 1 + || e.getAdviceType() == 2) // 前端中成药类型值为2 → 也属于药品分类 + .collect(Collectors.toList()); // 耗材(前端adviceType=4,后端ItemType.DEVICE=2) List deviceList = adviceSaveList.stream() - .filter(e -> ItemType.DEVICE.getValue().equals(e.getAdviceType()) + .filter(e -> ItemType.DEVICE.getValue().equals(e.getAdviceType()) || e.getAdviceType() == 4) // 前端耗材类型值为4 .collect(Collectors.toList()); - - // 诊疗活动(前端adviceType=3诊疗、adviceType=5会诊、adviceType=6手术) + + // 诊疗活动(前端adviceType=3诊疗、adviceType=5会诊、adviceType=6手术、adviceType=23检查 → 都属于诊疗后端分类) List activityList = adviceSaveList.stream() - .filter(e -> ItemType.ACTIVITY.getValue().equals(e.getAdviceType()) + .filter(e -> ItemType.ACTIVITY.getValue().equals(e.getAdviceType()) || e.getAdviceType() == 3 // 前端诊疗类型值为3 || e.getAdviceType() == 5 // 前端会诊类型值为5 - || ItemType.SURGERY.getValue().equals(e.getAdviceType())) // 🔧 BugFix#318: 手术类型值为6 + || e.getAdviceType() == 6 // 前端手术类型值为6 + || e.getAdviceType() == 23 // 前端检查类型值为23 + || ItemType.SURGERY.getValue().equals(e.getAdviceType())) // 后端手术类型值为6 .collect(Collectors.toList()); - // 🔍 Debug日志: 记录分类结果 - log.info("BugFix#219: 医嘱分类完成 - 药品:{}, 耗材:{}, 诊疗:{}", + // 🔍 Debug日志日志: 记录分类结果 + log.info("BugFix#219: 医嘱分类完成 - 药品:{}, 耗材:{}, 诊疗:{}", medicineList.size(), deviceList.size(), activityList.size()); + // 🔍 Debug日志: 打印所有医嘱的adviceType + for (AdviceSaveDto dto : adviceSaveList) { + log.info("BugFix#219: 医嘱详情 - adviceType:{}, requestId:{}, adviceName:{}, dbOpType:{}", + dto.getAdviceType(), dto.getRequestId(), + dto.getContentJson() != null && dto.getContentJson().contains("adviceName") + ? dto.getContentJson().substring(0, Math.min(100, dto.getContentJson().length())) + : "N/A", + dto.getDbOpType()); + } // 统计各类删除操作 long medDeleteCount = medicineList.stream().filter(e -> DbOpType.DELETE.getCode().equals(e.getDbOpType())).count(); @@ -679,19 +692,114 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp // 签发时,把草稿状态的账单更新为待收费 if (AdviceOpType.SIGN_ADVICE.getCode().equals(adviceOpType) && !adviceSaveList.isEmpty()) { - // 签发的医嘱id集合 + // 签发的医嘱id集合 - 收集所有需要签发的医嘱ID List requestIds = adviceSaveList.stream() .filter(e -> !DbOpType.DELETE.getCode().equals(e.getDbOpType()) && e.getRequestId() != null) .collect(Collectors.toList()).stream().map(AdviceSaveDto::getRequestId) .collect(Collectors.toList()); + + // 🔧 BugFix: 批量更新药品请求状态为已签发(ACTIVE=2) + if (!requestIds.isEmpty() && !medicineList.isEmpty()) { + List medicineIds = medicineList.stream() + .filter(e -> !DbOpType.DELETE.getCode().equals(e.getDbOpType()) && e.getRequestId() != null) + .map(AdviceSaveDto::getRequestId) + .collect(Collectors.toList()); + if (!medicineIds.isEmpty()) { + log.info("BugFix: 准备批量更新药品医嘱状态,medicineIds={}", medicineIds); + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.in("id", medicineIds); + updateWrapper.set("status_enum", RequestStatus.ACTIVE.getValue()); + boolean updateResult = iMedicationRequestService.update(null, updateWrapper); + log.info("BugFix: 批量更新药品医嘱状态为已签发,count={}, result={}", medicineIds.size(), updateResult); + + // 🔧 BugFix: 如果批量更新失败,尝试逐个更新 + if (!updateResult) { + log.warn("BugFix: 批量更新药品医嘱状态失败,尝试逐个更新"); + for (Long medicineId : medicineIds) { + try { + MedicationRequest updateReq = new MedicationRequest(); + updateReq.setId(medicineId); + updateReq.setStatusEnum(RequestStatus.ACTIVE.getValue()); + boolean singleResult = iMedicationRequestService.updateById(updateReq); + log.info("BugFix: 逐个更新药品医嘱状态,id={}, result={}", medicineId, singleResult); + } catch (Exception e) { + log.error("BugFix: 逐个更新药品医嘱状态失败,id={}", medicineId, e); + } + } + } + } + } + // 🔧 BugFix: 批量更新耗材请求状态为已签发(ACTIVE=2) + if (!requestIds.isEmpty() && !deviceList.isEmpty()) { + List deviceIds = deviceList.stream() + .filter(e -> !DbOpType.DELETE.getCode().equals(e.getDbOpType()) && e.getRequestId() != null) + .map(AdviceSaveDto::getRequestId) + .collect(Collectors.toList()); + if (!deviceIds.isEmpty()) { + log.info("BugFix: 准备批量更新耗材医嘱状态,deviceIds={}", deviceIds); + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.in("id", deviceIds); + updateWrapper.set("status_enum", RequestStatus.ACTIVE.getValue()); + boolean updateResult = iDeviceRequestService.update(null, updateWrapper); + log.info("BugFix: 批量更新耗材医嘱状态为已签发,count={}, result={}", deviceIds.size(), updateResult); + + // 🔧 BugFix: 如果批量更新失败,尝试逐个更新 + if (!updateResult) { + log.warn("BugFix: 批量更新耗材医嘱状态失败,尝试逐个更新"); + for (Long deviceId : deviceIds) { + try { + DeviceRequest updateReq = new DeviceRequest(); + updateReq.setId(deviceId); + updateReq.setStatusEnum(RequestStatus.ACTIVE.getValue()); + boolean singleResult = iDeviceRequestService.updateById(updateReq); + log.info("BugFix: 逐个更新耗材医嘱状态,id={}, result={}", deviceId, singleResult); + } catch (Exception e) { + log.error("BugFix: 逐个更新耗材医嘱状态失败,id={}", deviceId, e); + } + } + } + } + } + // 🔧 BugFix: 批量更新诊疗请求状态为已签发(ACTIVE=2) + if (!requestIds.isEmpty() && !activityList.isEmpty()) { + List activityIds = activityList.stream() + .filter(e -> !DbOpType.DELETE.getCode().equals(e.getDbOpType()) && e.getRequestId() != null) + .map(AdviceSaveDto::getRequestId) + .collect(Collectors.toList()); + if (!activityIds.isEmpty()) { + log.info("BugFix: 准备批量更新诊疗医嘱状态,activityIds={}", activityIds); + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.in("id", activityIds); + updateWrapper.set("status_enum", RequestStatus.ACTIVE.getValue()); + boolean updateResult = iServiceRequestService.update(null, updateWrapper); + log.info("BugFix: 批量更新诊疗医嘱状态为已签发,count={}, result={}", activityIds.size(), updateResult); + + // 🔧 BugFix: 如果批量更新失败,尝试逐个更新 + if (!updateResult) { + log.warn("BugFix: 批量更新诊疗医嘱状态失败,尝试逐个更新"); + for (Long activityId : activityIds) { + try { + ServiceRequest updateReq = new ServiceRequest(); + updateReq.setId(activityId); + updateReq.setStatusEnum(RequestStatus.ACTIVE.getValue()); + boolean singleResult = iServiceRequestService.updateById(updateReq); + log.info("BugFix: 逐个更新诊疗医嘱状态,id={}, result={}", activityId, singleResult); + } catch (Exception e) { + log.error("BugFix: 逐个更新诊疗医嘱状态失败,id={}", activityId, e); + } + } + } + } + } + // 就诊id Long encounterId = adviceSaveList.get(0).getEncounterId(); - - // 使用安全的更新方法,避免并发冲突 + + // 使用安全的更新方法,避免并发冲突 - 更新费用项状态 iChargeItemService.updateChargeStatusByConditionSafe( - encounterId, - ChargeItemStatus.DRAFT.getValue(), - ChargeItemStatus.PLANNED.getValue(), + encounterId, + ChargeItemStatus.DRAFT.getValue(), + ChargeItemStatus.PLANNED.getValue(), requestIds); } @@ -734,11 +842,14 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp // 声明费用项 ChargeItem chargeItem; // 新增 + 修改 + // 🔧 BugFix: 如果 requestId 不为空说明是已存在的医嘱,需要更新,即使 dbOpType 不匹配也应该包含进来 List insertOrUpdateList = medicineList.stream() .filter(e -> (DbOpType.INSERT.getCode().equals(e.getDbOpType()) - || DbOpType.UPDATE.getCode().equals(e.getDbOpType()))) + || DbOpType.UPDATE.getCode().equals(e.getDbOpType()) + || e.getRequestId() != null)) .collect(Collectors.toList()); // 删除 + // 🔧 BugFix: 如果 dbOpType 不匹配但 requestId 存在,仍然允许删除(增加健壮性) List deleteList = medicineList.stream() .filter(e -> DbOpType.DELETE.getCode().equals(e.getDbOpType())).collect(Collectors.toList()); // 校验删除的医嘱是否已经收费 @@ -1151,9 +1262,11 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp // 声明费用项 ChargeItem chargeItem; // 新增 + 修改 + // 🔧 BugFix: 如果 requestId 不为空说明是已存在的医嘱,需要更新,即使 dbOpType 不匹配也应该包含进来 List insertOrUpdateList = deviceList.stream() .filter(e -> (DbOpType.INSERT.getCode().equals(e.getDbOpType()) - || DbOpType.UPDATE.getCode().equals(e.getDbOpType()))) + || DbOpType.UPDATE.getCode().equals(e.getDbOpType()) + || e.getRequestId() != null)) .collect(Collectors.toList()); // 删除 List deleteList = deviceList.stream() @@ -1439,9 +1552,11 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp // 声明费用项 ChargeItem chargeItem; // 新增 + 修改 + // 🔧 BugFix: 如果 requestId 不为空说明是已存在的医嘱,需要更新,即使 dbOpType 不匹配也应该包含进来 List insertOrUpdateList = activityList.stream() .filter(e -> (DbOpType.INSERT.getCode().equals(e.getDbOpType()) - || DbOpType.UPDATE.getCode().equals(e.getDbOpType()))) + || DbOpType.UPDATE.getCode().equals(e.getDbOpType()) + || e.getRequestId() != null)) .collect(Collectors.toList()); // 删除 List deleteList = activityList.stream() diff --git a/openhis-server-new/openhis-common/src/main/java/com/openhis/common/constant/CommonConstants.java b/openhis-server-new/openhis-common/src/main/java/com/openhis/common/constant/CommonConstants.java index 1521d552..13e95eb8 100644 --- a/openhis-server-new/openhis-common/src/main/java/com/openhis/common/constant/CommonConstants.java +++ b/openhis-server-new/openhis-common/src/main/java/com/openhis/common/constant/CommonConstants.java @@ -778,10 +778,10 @@ public class CommonConstants { Integer BOOKED = 1; /** 已取消 / 已停诊 */ Integer CANCELLED = 2; - /** 已锁定 */ - Integer LOCKED = 3; /** 已签到 / 已取号 */ - Integer CHECKED_IN = 4; + Integer CHECKED_IN = 3; + /** 已锁定 */ + Integer LOCKED = 4; /** 已退号 */ Integer RETURNED = 5; } diff --git a/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/domain/ScheduleSlot.java b/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/domain/ScheduleSlot.java index e3185138..4ea15692 100644 --- a/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/domain/ScheduleSlot.java +++ b/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/domain/ScheduleSlot.java @@ -23,15 +23,15 @@ import java.util.Date; public class ScheduleSlot extends HisBaseEntity { /** 明细主键 */ @TableId(type = IdType.AUTO) - private Integer id; + private Long id; /** 号源池ID */ - private Integer poolId; + private Long poolId; /** 序号 */ private Integer seqNo; - /** 序号状态: 0-可用,1-已预约,2-已取消/已停诊,3-已锁定,4-已签到,5-已退号 */ + /** 序号状态: 0-可用,1-已预约,2-已取消/已停诊,3-已签到,4-已锁定,5-已退号 */ private Integer status; /** 预约订单ID */ diff --git a/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/mapper/SchedulePoolMapper.java b/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/mapper/SchedulePoolMapper.java index 52987380..ed01dd7b 100644 --- a/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/mapper/SchedulePoolMapper.java +++ b/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/mapper/SchedulePoolMapper.java @@ -53,5 +53,5 @@ public interface SchedulePoolMapper extends BaseMapper { AND locked_num > 0 AND delete_flag = '0' """) - int updatePoolStatsOnCheckIn(@Param("poolId") Integer poolId); + int updatePoolStatsOnCheckIn(@Param("poolId") Long poolId); } diff --git a/openhis-server-new/openhis-domain/src/main/resources/mapper/administration/ScheduleSlotMapper.xml b/openhis-server-new/openhis-domain/src/main/resources/mapper/administration/ScheduleSlotMapper.xml index f04b966e..6191bdce 100644 --- a/openhis-server-new/openhis-domain/src/main/resources/mapper/administration/ScheduleSlotMapper.xml +++ b/openhis-server-new/openhis-domain/src/main/resources/mapper/administration/ScheduleSlotMapper.xml @@ -10,8 +10,8 @@ WHEN LOWER(CONCAT('', s.status)) IN ('0', 'unbooked', 'available') THEN 0 WHEN LOWER(CONCAT('', s.status)) IN ('1', 'booked') THEN 1 WHEN LOWER(CONCAT('', s.status)) IN ('2', 'cancelled', 'canceled', 'stopped') THEN 2 - WHEN LOWER(CONCAT('', s.status)) IN ('3', 'locked') THEN 3 - WHEN LOWER(CONCAT('', s.status)) IN ('4', 'checked', 'checked_in', 'checkin') THEN 4 + WHEN LOWER(CONCAT('', s.status)) IN ('3', 'checked', 'checked_in', 'checkin') THEN 3 + WHEN LOWER(CONCAT('', s.status)) IN ('4', 'locked') THEN 4 WHEN LOWER(CONCAT('', s.status)) IN ('5', 'returned') THEN 5 ELSE NULL END @@ -32,8 +32,8 @@ WHEN LOWER(CONCAT('', p.status)) IN ('0', 'unbooked', 'available') THEN 0 WHEN LOWER(CONCAT('', p.status)) IN ('1', 'booked') THEN 1 WHEN LOWER(CONCAT('', p.status)) IN ('2', 'cancelled', 'canceled', 'stopped') THEN 2 - WHEN LOWER(CONCAT('', p.status)) IN ('3', 'locked') THEN 3 - WHEN LOWER(CONCAT('', p.status)) IN ('4', 'checked', 'checked_in', 'checkin') THEN 4 + WHEN LOWER(CONCAT('', p.status)) IN ('3', 'checked', 'checked_in', 'checkin') THEN 3 + WHEN LOWER(CONCAT('', p.status)) IN ('4', 'locked') THEN 4 WHEN LOWER(CONCAT('', p.status)) IN ('5', 'returned') THEN 5 ELSE NULL END @@ -86,7 +86,8 @@ ORDER BY p.schedule_date, p.doctor_id, - s.expect_time + s.expect_time, + s.seq_no ASC