80 门诊医生站检查申请单开单界面,排班的回显问题

This commit is contained in:
HuangXinQuan
2026-02-27 14:25:17 +08:00
parent 87c7981ad9
commit fcd2d03424
6 changed files with 323 additions and 120 deletions

View File

@@ -1,9 +1,10 @@
package com.openhis.web.appointmentmanage.appservice.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.core.common.core.domain.R;
import com.core.common.utils.SecurityUtils;
import com.openhis.appointmentmanage.domain.DoctorSchedule;
import com.openhis.appointmentmanage.domain.DoctorScheduleWithDateDto;
import com.openhis.appointmentmanage.domain.SchedulePool;
import com.openhis.appointmentmanage.domain.ScheduleSlot;
import com.openhis.appointmentmanage.mapper.DoctorScheduleMapper;
@@ -16,13 +17,9 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
@Service
@@ -39,10 +36,6 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
@Resource
private DoctorScheduleMapper doctorScheduleMapper;
// 转换 LocalDateTime 为 Date 的通用方法
Date now = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
Date tomorrow = Date.from(LocalDateTime.now().plusDays(1).atZone(ZoneId.systemDefault()).toInstant());
@Override
public R<?> getDoctorScheduleList() {
List<DoctorSchedule> list = doctorScheduleService.list();
@@ -52,89 +45,46 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
@Override
public R<?> getDoctorScheduleListByDeptId(Long deptId) {
List<DoctorSchedule> list = doctorScheduleService.list(
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<DoctorSchedule>()
.eq("dept_id", deptId)
);
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<DoctorSchedule>()
.eq("dept_id", deptId));
return R.ok(list);
}
@Override
public R<?> getDoctorScheduleListByDeptIdAndDateRange(Long deptId, String startDate, String endDate) {
// 暂时返回所有科室的排班数据,直到我们确定日期范围过滤逻辑
List<DoctorSchedule> list = doctorScheduleService.list(
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<DoctorSchedule>()
.eq("dept_id", deptId)
);
// 联表查询 adm_doctor_schedule LEFT JOIN adm_schedule_pool
// 通过 schedule_date 获取具体出诊日期,解决按星期匹配导致日期错位的问题
List<DoctorScheduleWithDateDto> list = doctorScheduleMapper.selectScheduleWithDateByDeptAndRange(
deptId, startDate, endDate);
return R.ok(list);
}
@Transactional
@Transactional(readOnly = true)
@Override
public R<?> getTodayDoctorScheduleList() {
// 获取今天的日期
LocalDate today = LocalDate.now();
DayOfWeek dayOfWeek = today.getDayOfWeek();
// 将 Java 的 DayOfWeek 转换为字符串表示
String weekdayStr = convertDayOfWeekToString(dayOfWeek);
// 查询今天排班的医生
LambdaQueryWrapper<DoctorSchedule> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DoctorSchedule::getWeekday, weekdayStr) // 根据星期几查询
.eq(DoctorSchedule::getIsStopped, false); // 只查询未停止的排班
List<DoctorSchedule> list = doctorScheduleService.list(queryWrapper);
// 联表查询 adm_schedule_pool按今日具体日期查询排班替代原来按星期匹配的方式
String todayStr = LocalDate.now().toString(); // yyyy-MM-dd
List<DoctorScheduleWithDateDto> list = doctorScheduleMapper.selectTodaySchedule(todayStr);
return R.ok(list);
}
@Transactional
@Transactional(readOnly = true)
@Override
public R<?> getTodayMySchedule() {
// 获取今天的日期
LocalDate today = LocalDate.now();
DayOfWeek dayOfWeek = today.getDayOfWeek();
// 联表查询 adm_schedule_pool按今日具体日期 + 医生ID 查询个人排班
String todayStr = LocalDate.now().toString(); // yyyy-MM-dd
// 将 Java 的 DayOfWeek 转换为字符串表示
String weekdayStr = convertDayOfWeekToString(dayOfWeek);
// 从 SecurityUtils 获取当前登录医生ID
Long currentDoctorId = SecurityUtils.getLoginUser().getPractitionerId();
// 获取当前登录医生的ID需要从SecurityUtils获取
// 如果没有SecurityUtils可以从参数传入或使用其他方式获取
// Long currentDoctorId = SecurityUtils.getLoginUser().getPractitionerId();
// 查询当前医生今天的排班
LambdaQueryWrapper<DoctorSchedule> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DoctorSchedule::getWeekday, weekdayStr) // 根据星期几查询
// .eq(DoctorSchedule::getDoctorId, currentDoctorId) // 只查询当前医生的排班
.eq(DoctorSchedule::getIsStopped, false); // 只查询未停止的排班
List<DoctorSchedule> list = doctorScheduleService.list(queryWrapper);
return R.ok(list);
}
/**
* 将 DayOfWeek 转换为字符串表示
* @param dayOfWeek DayOfWeek枚举
* @return 对应的字符串表示
*/
private String convertDayOfWeekToString(DayOfWeek dayOfWeek) {
switch (dayOfWeek) {
case MONDAY:
return "1"; // 或者 "星期一" 或 "Monday",取决于数据库中的实际存储格式
case TUESDAY:
return "2";
case WEDNESDAY:
return "3";
case THURSDAY:
return "4";
case FRIDAY:
return "5";
case SATURDAY:
return "6";
case SUNDAY:
return "7";
default:
return "1"; // 默认为星期一
if (currentDoctorId != null) {
List<DoctorScheduleWithDateDto> list = doctorScheduleMapper.selectTodayMySchedule(todayStr,
currentDoctorId);
return R.ok(list);
}
// 如果未绑定医生,则返回空列表
return R.ok(Collections.emptyList());
}
@Override
@@ -157,10 +107,12 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
newSchedule.setEndTime(doctorSchedule.getEndTime());
newSchedule.setLimitNumber(doctorSchedule.getLimitNumber());
// call_sign_record 字段不能为null设置默认值为空字符串
newSchedule.setCallSignRecord(doctorSchedule.getCallSignRecord() != null ? doctorSchedule.getCallSignRecord() : "");
newSchedule.setCallSignRecord(
doctorSchedule.getCallSignRecord() != null ? doctorSchedule.getCallSignRecord() : "");
newSchedule.setRegisterItem(doctorSchedule.getRegisterItem() != null ? doctorSchedule.getRegisterItem() : "");
newSchedule.setRegisterFee(doctorSchedule.getRegisterFee() != null ? doctorSchedule.getRegisterFee() : 0);
newSchedule.setDiagnosisItem(doctorSchedule.getDiagnosisItem() != null ? doctorSchedule.getDiagnosisItem() : "");
newSchedule
.setDiagnosisItem(doctorSchedule.getDiagnosisItem() != null ? doctorSchedule.getDiagnosisItem() : "");
newSchedule.setDiagnosisFee(doctorSchedule.getDiagnosisFee() != null ? doctorSchedule.getDiagnosisFee() : 0);
newSchedule.setIsOnline(doctorSchedule.getIsOnline() != null ? doctorSchedule.getIsOnline() : true);
newSchedule.setIsStopped(doctorSchedule.getIsStopped() != null ? doctorSchedule.getIsStopped() : false);
@@ -180,7 +132,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
if (poolSaved) {
// 创建号源槽
List<ScheduleSlot> slots = createScheduleSlots(pool.getId().intValue(), newSchedule.getLimitNumber(),
newSchedule.getStartTime(), newSchedule.getEndTime());
newSchedule.getStartTime(), newSchedule.getEndTime());
boolean slotsSaved = scheduleSlotService.saveBatch(slots);
if (slotsSaved) {
@@ -192,8 +144,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
} else {
throw new RuntimeException("创建号源槽失败");
}
}
else {
} else {
throw new RuntimeException("创建号源池失败");
}
} else {
@@ -221,10 +172,12 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
newSchedule.setEndTime(doctorSchedule.getEndTime());
newSchedule.setLimitNumber(doctorSchedule.getLimitNumber());
// call_sign_record 字段不能为null设置默认值为空字符串
newSchedule.setCallSignRecord(doctorSchedule.getCallSignRecord() != null ? doctorSchedule.getCallSignRecord() : "");
newSchedule.setCallSignRecord(
doctorSchedule.getCallSignRecord() != null ? doctorSchedule.getCallSignRecord() : "");
newSchedule.setRegisterItem(doctorSchedule.getRegisterItem() != null ? doctorSchedule.getRegisterItem() : "");
newSchedule.setRegisterFee(doctorSchedule.getRegisterFee() != null ? doctorSchedule.getRegisterFee() : 0);
newSchedule.setDiagnosisItem(doctorSchedule.getDiagnosisItem() != null ? doctorSchedule.getDiagnosisItem() : "");
newSchedule
.setDiagnosisItem(doctorSchedule.getDiagnosisItem() != null ? doctorSchedule.getDiagnosisItem() : "");
newSchedule.setDiagnosisFee(doctorSchedule.getDiagnosisFee() != null ? doctorSchedule.getDiagnosisFee() : 0);
newSchedule.setIsOnline(doctorSchedule.getIsOnline() != null ? doctorSchedule.getIsOnline() : true);
newSchedule.setIsStopped(doctorSchedule.getIsStopped() != null ? doctorSchedule.getIsStopped() : false);
@@ -244,7 +197,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
if (poolSaved) {
// 创建号源槽
List<ScheduleSlot> slots = createScheduleSlots(pool.getId().intValue(), newSchedule.getLimitNumber(),
newSchedule.getStartTime(), newSchedule.getEndTime());
newSchedule.getStartTime(), newSchedule.getEndTime());
boolean slotsSaved = scheduleSlotService.saveBatch(slots);
if (slotsSaved) {
@@ -252,8 +205,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
} else {
throw new RuntimeException("创建号源槽失败");
}
}
else {
} else {
throw new RuntimeException("创建号源池失败");
}
} else {
@@ -323,7 +275,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
pool.setDoctorName(schedule.getDoctor());
pool.setDeptId(schedule.getDeptId());
pool.setClinicRoom(schedule.getClinic());
// 使用传入的具体日期
if (scheduledDateStr != null && !scheduledDateStr.isEmpty()) {
try {
@@ -337,7 +289,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
// 如果没有提供具体日期,使用原来的计算方式
pool.setScheduleDate(calculateScheduleDate(schedule.getWeekday()));
}
pool.setShift(schedule.getTimePeriod());
pool.setStartTime(schedule.getStartTime());
pool.setEndTime(schedule.getEndTime());
@@ -367,7 +319,8 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
/**
* 创建号源槽
*/
private List<ScheduleSlot> createScheduleSlots(Integer poolId, Integer limitNumber, LocalTime startTime, LocalTime endTime) {
private List<ScheduleSlot> createScheduleSlots(Integer poolId, Integer limitNumber, LocalTime startTime,
LocalTime endTime) {
List<ScheduleSlot> slots = new ArrayList<>();
// 计算时间间隔
@@ -377,7 +330,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
for (int i = 1; i <= limitNumber; i++) {
ScheduleSlot slot = new ScheduleSlot();
slot.setPoolId(poolId);
slot.setSeqNo(i); // 序号
slot.setSeqNo(i); // 序号
slot.setStatus(0); // 0表示可用
// 计算预计叫号时间,均匀分布在开始时间和结束时间之间
LocalTime expectTime = startTime.plusMinutes(interval * (i - 1));
@@ -411,14 +364,22 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
*/
private int getDayOfWeekNumber(String weekday) {
switch (weekday) {
case "周一": return 1;
case "周二": return 2;
case "": return 3;
case "周四": return 4;
case "": return 5;
case "周六": return 6;
case "": return 7;
default: return 1; // 默认周一
case "周一":
return 1;
case "":
return 2;
case "":
return 3;
case "":
return 4;
case "周五":
return 5;
case "周六":
return 6;
case "周日":
return 7;
default:
return 1; // 默认周一
}
}
@@ -432,8 +393,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
// 1. 根据排班ID找到关联的号源池
List<SchedulePool> pools = schedulePoolService.list(
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<SchedulePool>()
.eq("schedule_id", doctorScheduleId)
);
.eq("schedule_id", doctorScheduleId));
if (ObjectUtil.isNotEmpty(pools)) {
List<Long> poolIds = pools.stream().map(SchedulePool::getId).collect(java.util.stream.Collectors.toList());
@@ -441,11 +401,11 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
// 2. 根据号源池ID找到所有关联的号源槽
List<ScheduleSlot> slots = scheduleSlotService.list(
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<ScheduleSlot>()
.in("pool_id", poolIds)
);
.in("pool_id", poolIds));
if (ObjectUtil.isNotEmpty(slots)) {
List<Integer> slotIds = slots.stream().map(ScheduleSlot::getId).collect(java.util.stream.Collectors.toList());
List<Integer> slotIds = slots.stream().map(ScheduleSlot::getId)
.collect(java.util.stream.Collectors.toList());
// 3. 逻辑删除所有号源槽
scheduleSlotService.removeByIds(slotIds);
}

View File

@@ -73,5 +73,103 @@
</set>
WHERE id = #{id}
</update>
</mapper>
<!-- 联表查询根据科室ID和日期范围查询排班信息含具体出诊日期 -->
<select id="selectScheduleWithDateByDeptAndRange"
resultType="com.openhis.appointmentmanage.domain.DoctorScheduleWithDateDto">
SELECT
ds.id,
ds.weekday,
ds.time_period AS time_period,
ds.doctor AS doctor_name,
ds.clinic AS clinic,
sp.clinic_room AS clinic_room,
org.name AS dept_name,
ds.start_time AS start_time,
ds.end_time AS end_time,
ds.limit_number AS limit_number,
ds.call_sign_record AS call_sign_record,
ds.register_item AS register_item,
ds.register_fee AS register_fee,
ds.diagnosis_item AS diagnosis_item,
ds.diagnosis_fee AS diagnosis_fee,
ds.is_online AS is_online,
ds.is_stopped AS is_stopped,
ds.stop_reason AS stop_reason,
ds.dept_id AS dept_id,
sp.doctor_id AS doctor_id,
sp.schedule_date AS schedule_date
FROM adm_doctor_schedule ds
LEFT JOIN adm_schedule_pool sp ON sp.schedule_id = ds.id
LEFT JOIN adm_organization org ON ds.dept_id = org.id
WHERE ds.dept_id = #{deptId}
AND sp.schedule_date BETWEEN #{startDate}::date AND #{endDate}::date
ORDER BY sp.schedule_date, ds.time_period
</select>
<!-- 联表查询:获取今日所有排班 -->
<select id="selectTodaySchedule"
resultType="com.openhis.appointmentmanage.domain.DoctorScheduleWithDateDto">
SELECT
ds.id,
ds.weekday,
ds.time_period AS time_period,
ds.doctor AS doctor_name,
ds.clinic AS clinic,
sp.clinic_room AS clinic_room,
org.name AS dept_name,
ds.start_time AS start_time,
ds.end_time AS end_time,
ds.limit_number AS limit_number,
ds.register_item AS register_item,
ds.register_fee AS register_fee,
ds.diagnosis_item AS diagnosis_item,
ds.diagnosis_fee AS diagnosis_fee,
ds.is_online AS is_online,
ds.is_stopped AS is_stopped,
ds.stop_reason AS stop_reason,
ds.dept_id AS dept_id,
sp.doctor_id AS doctor_id,
sp.schedule_date AS schedule_date
FROM adm_doctor_schedule ds
INNER JOIN adm_schedule_pool sp ON sp.schedule_id = ds.id
LEFT JOIN adm_organization org ON ds.dept_id = org.id
WHERE sp.schedule_date = #{today}::date
AND (ds.is_stopped = false OR ds.is_stopped IS NULL)
ORDER BY ds.time_period
</select>
<!-- 联表查询:获取指定医生今日排班 -->
<select id="selectTodayMySchedule"
resultType="com.openhis.appointmentmanage.domain.DoctorScheduleWithDateDto">
SELECT
ds.id,
ds.weekday,
ds.time_period AS time_period,
ds.doctor AS doctor_name,
ds.clinic AS clinic,
sp.clinic_room AS clinic_room,
org.name AS dept_name,
ds.start_time AS start_time,
ds.end_time AS end_time,
ds.limit_number AS limit_number,
ds.register_item AS register_item,
ds.register_fee AS register_fee,
ds.diagnosis_item AS diagnosis_item,
ds.diagnosis_fee AS diagnosis_fee,
ds.is_online AS is_online,
ds.is_stopped AS is_stopped,
ds.stop_reason AS stop_reason,
ds.dept_id AS dept_id,
sp.doctor_id AS doctor_id,
sp.schedule_date AS schedule_date
FROM adm_doctor_schedule ds
INNER JOIN adm_schedule_pool sp ON sp.schedule_id = ds.id
LEFT JOIN adm_organization org ON ds.dept_id = org.id
WHERE sp.schedule_date = #{today}::date
AND sp.doctor_id = #{doctorId}
AND (ds.is_stopped = false OR ds.is_stopped IS NULL)
ORDER BY ds.time_period
</select>
</mapper>