Compare commits
102 Commits
77b054a86c
...
bug/334
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c5353cf8b | ||
|
|
8a84b40ee5 | ||
| f6b39a4815 | |||
|
|
1b3d4e3dc0 | ||
|
|
cb46461ede | ||
| 3b0a359412 | |||
| 6fa26e895d | |||
| 8ab8691c17 | |||
|
|
35b8a7d10a | ||
| 22de02f132 | |||
| 11244aa48f | |||
| 0a5f26e9c0 | |||
| 4a8e9b5a22 | |||
| bfb2491842 | |||
|
|
b747f80507 | ||
| ced931a280 | |||
| b497eb853c | |||
| 7a2342ea2e | |||
|
|
09fdfa294a | ||
|
|
4ef9aa07d2 | ||
| 08085403b3 | |||
| 2d7dcb4aeb | |||
| ad29502488 | |||
| 5b0acede89 | |||
| ac1cd3afc8 | |||
|
|
8a863b4ecb | ||
|
|
882d63249c | ||
|
|
6315ca5658 | ||
|
|
9f802b67f0 | ||
| 6694ae52ba | |||
| 9491ceaa5d | |||
| db9a70a99d | |||
|
|
9105e687d6 | ||
| b1d6c6008e | |||
| 6b9f9a107e | |||
| 11a7f49162 | |||
| b4e5061b73 | |||
| f5a1ad7f3f | |||
| eeac88b1d1 | |||
| 1ab9b020c1 | |||
| 3055518d2b | |||
| 9f619ccdd4 | |||
| df78ff29bd | |||
| 4d13acacc2 | |||
| 67573c1d9d | |||
| b27d8a6703 | |||
| 6f3d4272e6 | |||
| 6e5315fdd6 | |||
| 544d7ee95c | |||
| 7f7f7d69f7 | |||
|
|
ae9a96822e | ||
| bbef0322a3 | |||
| a8a205aa48 | |||
| c052ea7c39 | |||
| 6accaa35c9 | |||
| 466e7296fa | |||
|
|
5678535d88 | ||
| b7993885bb | |||
| 3b8ef380ae | |||
|
|
2334a27467 | ||
|
|
92511c2777 | ||
| 64b02466b1 | |||
| 2ffbe73305 | |||
| 48d3941701 | |||
| 0ad1889029 | |||
| 7dc98dcf84 | |||
| 681fb695bd | |||
| 518d8385e6 | |||
|
|
7073ef0be0 | ||
| 2288162ad7 | |||
| 6f701d7fa6 | |||
| 34253f88b2 | |||
|
|
488c311788 | ||
|
|
b5527cc07f | ||
| 6d23d36a9c | |||
|
|
e2e5999276 | ||
|
|
112ec2e4a3 | ||
| 4b92be10b4 | |||
| 0b361df0a4 | |||
| 3a242074ff | |||
|
|
353f267488 | ||
|
|
2d705d2f81 | ||
| 184871e84f | |||
| ffcdaed087 | |||
| 91a0b48662 | |||
| c509a804ec | |||
| 1a7b6c0cd4 | |||
|
|
11cf88fd49 | ||
| 3f0fa3bbb3 | |||
| d7c15848f0 | |||
|
|
188b907907 | ||
| 71e3601d51 | |||
| f04c3d112c | |||
| 8739959be0 | |||
| 24bc049fa0 | |||
| b42cffdd8a | |||
| 927691a27b | |||
| 6c36ae5340 | |||
| 5473a21418 | |||
| b14c19a887 | |||
| 979dc0a34c | |||
| c2fa13de82 |
@@ -2,5 +2,5 @@
|
||||
"tools": {
|
||||
"approvalMode": "yolo"
|
||||
},
|
||||
"$version": 2
|
||||
"$version": 3
|
||||
}
|
||||
6
.qwen/settings.json.orig
Normal file
6
.qwen/settings.json.orig
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"tools": {
|
||||
"approvalMode": "yolo"
|
||||
},
|
||||
"$version": 2
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.core.framework.config;
|
||||
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
@@ -24,6 +28,14 @@ public class ApplicationConfig {
|
||||
*/
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
|
||||
return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
|
||||
return builder -> {
|
||||
// 设置默认时区
|
||||
builder.timeZone(TimeZone.getDefault());
|
||||
// 设置日期格式为 yyyy/M/d HH:mm:ss,支持多种格式反序列化
|
||||
builder.simpleDateFormat("yyyy/M/d HH:mm:ss");
|
||||
// 添加JavaTimeModule支持,用于LocalDateTime
|
||||
builder.modules(new JavaTimeModule());
|
||||
builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy/M/d HH:mm:ss")));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.openhis.web.appointmentmanage.appservice;
|
||||
|
||||
import com.core.common.core.domain.R;
|
||||
import com.openhis.appointmentmanage.domain.AppointmentConfig;
|
||||
|
||||
/**
|
||||
* 预约配置AppService接口
|
||||
*
|
||||
* @author openhis
|
||||
* @date 2026-03-23
|
||||
*/
|
||||
public interface IAppointmentConfigAppService {
|
||||
|
||||
/**
|
||||
* 获取当前机构的预约配置
|
||||
*
|
||||
* @return 预约配置
|
||||
*/
|
||||
R<?> getAppointmentConfig();
|
||||
|
||||
/**
|
||||
* 保存预约配置
|
||||
*
|
||||
* @param appointmentConfig 预约配置
|
||||
* @return 结果
|
||||
*/
|
||||
R<?> saveAppointmentConfig(AppointmentConfig appointmentConfig);
|
||||
}
|
||||
@@ -2,7 +2,9 @@ package com.openhis.web.appointmentmanage.appservice;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.openhis.appointmentmanage.dto.TicketQueryDTO;
|
||||
import com.openhis.web.appointmentmanage.dto.TicketDto;
|
||||
import com.openhis.appointmentmanage.dto.TicketQueryDTO;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -14,36 +16,52 @@ import java.util.Map;
|
||||
public interface ITicketAppService {
|
||||
|
||||
/**
|
||||
* 预约号源
|
||||
* 分页查询门诊号源列表(真分页)
|
||||
*
|
||||
* @param params 预约参数
|
||||
* @param query 查询参数
|
||||
* @return 结果
|
||||
*/
|
||||
R<?> bookTicket(Map<String, Object> params);
|
||||
R<?> listTicket(TicketQueryDTO query);
|
||||
|
||||
/**
|
||||
* 查询医生余号汇总(基于号源池,不受分页影响)
|
||||
*
|
||||
* @param query 查询参数
|
||||
* @return 结果
|
||||
*/
|
||||
R<?> listDoctorAvailability(TicketQueryDTO query);
|
||||
|
||||
/**
|
||||
* 预约号源
|
||||
*
|
||||
* @param dto 预约参数
|
||||
* @return 结果
|
||||
*/
|
||||
R<?> bookTicket(com.openhis.appointmentmanage.domain.AppointmentBookDTO dto);
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
R<?> cancelTicket(Long ticketId);
|
||||
R<?> cancelTicket(Long slotId);
|
||||
|
||||
/**
|
||||
* 取号
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
R<?> checkInTicket(Long ticketId);
|
||||
R<?> checkInTicket(Long slotId);
|
||||
|
||||
/**
|
||||
* 停诊
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
R<?> cancelConsultation(Long ticketId);
|
||||
R<?> cancelConsultation(Long slotId);
|
||||
|
||||
/**
|
||||
* 查询所有号源(用于测试)
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.openhis.web.appointmentmanage.appservice.impl;
|
||||
|
||||
import com.core.common.core.domain.R;
|
||||
import com.core.common.utils.SecurityUtils;
|
||||
import com.openhis.appointmentmanage.domain.AppointmentConfig;
|
||||
import com.openhis.appointmentmanage.service.IAppointmentConfigService;
|
||||
import com.openhis.web.appointmentmanage.appservice.IAppointmentConfigAppService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 预约配置AppService实现类
|
||||
*
|
||||
* @author openhis
|
||||
* @date 2026-03-23
|
||||
*/
|
||||
@Service
|
||||
public class AppointmentConfigAppServiceImpl implements IAppointmentConfigAppService {
|
||||
|
||||
@Resource
|
||||
private IAppointmentConfigService appointmentConfigService;
|
||||
|
||||
@Override
|
||||
public R<?> getAppointmentConfig() {
|
||||
// 获取当前登录用户的机构ID
|
||||
Integer tenantId = SecurityUtils.getLoginUser().getTenantId();
|
||||
if (tenantId == null) {
|
||||
return R.fail("获取机构信息失败");
|
||||
}
|
||||
|
||||
AppointmentConfig config = appointmentConfigService.getConfigByTenantId(tenantId);
|
||||
return R.ok(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> saveAppointmentConfig(AppointmentConfig appointmentConfig) {
|
||||
// 获取当前登录用户的机构ID
|
||||
Integer tenantId = SecurityUtils.getLoginUser().getTenantId();
|
||||
if (tenantId == null) {
|
||||
return R.fail("获取机构信息失败");
|
||||
}
|
||||
|
||||
// 查询是否已存在配置
|
||||
AppointmentConfig existingConfig = appointmentConfigService.getConfigByTenantId(tenantId);
|
||||
|
||||
if (existingConfig != null) {
|
||||
// 更新现有配置
|
||||
existingConfig.setCancelAppointmentType(appointmentConfig.getCancelAppointmentType());
|
||||
existingConfig.setCancelAppointmentCount(appointmentConfig.getCancelAppointmentCount());
|
||||
existingConfig.setValidFlag(appointmentConfig.getValidFlag());
|
||||
appointmentConfigService.saveOrUpdate(existingConfig);
|
||||
return R.ok(existingConfig);
|
||||
} else {
|
||||
// 新增配置
|
||||
appointmentConfig.setTenantId(tenantId);
|
||||
appointmentConfig.setValidFlag(1);
|
||||
appointmentConfigService.saveOrUpdateConfig(appointmentConfig);
|
||||
return R.ok(appointmentConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,7 +260,10 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
|
||||
|| doctorSchedule.getLimitNumber() != null
|
||||
|| doctorSchedule.getStopReason() != null
|
||||
|| doctorSchedule.getRegType() != null
|
||||
|| doctorSchedule.getRegisterFee() != null;
|
||||
|| doctorSchedule.getRegisterFee() != null
|
||||
|| doctorSchedule.getRegisterItem() != null
|
||||
|| doctorSchedule.getDiagnosisItem() != null
|
||||
|| doctorSchedule.getDiagnosisFee() != null;
|
||||
|
||||
if (needSyncPool) {
|
||||
schedulePoolService.lambdaUpdate()
|
||||
@@ -274,9 +277,9 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
|
||||
doctorSchedule.getLimitNumber())
|
||||
.set(doctorSchedule.getStopReason() != null, SchedulePool::getStopReason, doctorSchedule.getStopReason())
|
||||
.set(doctorSchedule.getRegType() != null, SchedulePool::getRegType, String.valueOf(doctorSchedule.getRegType()))
|
||||
.set(doctorSchedule.getRegisterFee() != null, SchedulePool::getFee, doctorSchedule.getRegisterFee() / 100.0)
|
||||
.set(doctorSchedule.getRegisterFee() != null, SchedulePool::getFee, Double.valueOf(doctorSchedule.getRegisterFee().toString()))
|
||||
.set(doctorSchedule.getRegisterFee() != null, SchedulePool::getInsurancePrice,
|
||||
doctorSchedule.getRegisterFee() / 100.0)
|
||||
Double.valueOf(doctorSchedule.getRegisterFee().toString()))
|
||||
.update();
|
||||
}
|
||||
|
||||
@@ -306,7 +309,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
|
||||
// 不设置available_num,因为它是数据库生成列
|
||||
// pool.setAvailableNum(0); // 初始为0,稍后更新
|
||||
pool.setRegType(schedule.getRegisterItem() != null ? schedule.getRegisterItem() : "普通");
|
||||
pool.setFee(schedule.getRegisterFee() != null ? schedule.getRegisterFee() / 100.0 : 0.0); // 假设数据库中以分为单位存储
|
||||
pool.setFee(schedule.getRegisterFee() != null ? Double.valueOf(schedule.getRegisterFee().toString()) : 0.0); // 直接使用原始价格
|
||||
pool.setInsurancePrice(pool.getFee()); // 医保价格暂时与原价相同
|
||||
// 暂时设置support_channel为空字符串,避免JSON类型问题
|
||||
pool.setSupportChannel("");
|
||||
@@ -359,7 +362,7 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
|
||||
// 不设置available_num,因为它是数据库生成列
|
||||
// pool.setAvailableNum(0); // 初始为0,稍后更新
|
||||
pool.setRegType(schedule.getRegisterItem() != null ? schedule.getRegisterItem() : "普通");
|
||||
pool.setFee(schedule.getRegisterFee() != null ? schedule.getRegisterFee() / 100.0 : 0.0); // 假设数据库中以分为单位存储
|
||||
pool.setFee(schedule.getRegisterFee() != null ? Double.valueOf(schedule.getRegisterFee().toString()) : 0.0); // 直接使用原始价格
|
||||
pool.setInsurancePrice(pool.getFee()); // 医保价格暂时与原价相同
|
||||
// 暂时设置support_channel为空字符串,避免JSON类型问题
|
||||
pool.setSupportChannel("");
|
||||
|
||||
@@ -4,28 +4,22 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.openhis.administration.domain.Patient;
|
||||
import com.openhis.administration.service.IPatientService;
|
||||
import com.openhis.appointmentmanage.domain.DoctorSchedule;
|
||||
import com.openhis.appointmentmanage.mapper.DoctorScheduleMapper;
|
||||
import com.openhis.appointmentmanage.service.IDoctorScheduleService;
|
||||
import com.openhis.clinical.domain.Order;
|
||||
import com.openhis.appointmentmanage.mapper.ScheduleSlotMapper;
|
||||
import com.openhis.clinical.domain.Ticket;
|
||||
import com.openhis.clinical.mapper.OrderMapper;
|
||||
import com.openhis.clinical.service.ITicketService;
|
||||
import com.openhis.web.appointmentmanage.appservice.IDoctorScheduleAppService;
|
||||
import com.openhis.web.appointmentmanage.appservice.ITicketAppService;
|
||||
import com.openhis.web.appointmentmanage.dto.TicketDto;
|
||||
import com.openhis.common.constant.CommonConstants.SlotStatus;
|
||||
import com.openhis.common.constant.CommonConstants.AppointmentOrderStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Locale;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 号源管理应用服务实现类
|
||||
*
|
||||
@@ -36,73 +30,41 @@ public class TicketAppServiceImpl implements ITicketAppService {
|
||||
|
||||
@Resource
|
||||
private ITicketService ticketService;
|
||||
|
||||
@Resource
|
||||
private ScheduleSlotMapper scheduleSlotMapper;
|
||||
@Resource
|
||||
private IPatientService patientService;
|
||||
@Resource
|
||||
private IDoctorScheduleAppService doctorScheduleAppService;
|
||||
@Resource
|
||||
private DoctorScheduleMapper doctorScheduleMapper;
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TicketAppServiceImpl.class);
|
||||
|
||||
/**
|
||||
* 预约号源
|
||||
* 预约号源 (重构版:精准锁定单一槽位)
|
||||
*
|
||||
* @param params 预约参数
|
||||
* @param dto 预约参数
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public R<?> bookTicket(Map<String, Object> params) {
|
||||
// 1. 获取 ticketId 和 slotId
|
||||
Long ticketId = null;
|
||||
Long slotId = null;
|
||||
if (params.get("ticketId") != null) {
|
||||
ticketId = Long.valueOf(params.get("ticketId").toString());
|
||||
public R<?> bookTicket(com.openhis.appointmentmanage.domain.AppointmentBookDTO dto) {
|
||||
Long slotId = dto.getSlotId();
|
||||
if (slotId == null) {
|
||||
return R.fail("参数校验失败:缺少排班槽位唯一标识");
|
||||
}
|
||||
if (params.get("slotId") != null) {
|
||||
slotId = Long.valueOf(params.get("slotId").toString());
|
||||
}
|
||||
// 2. 参数校验
|
||||
if (ticketId == null || slotId == null) {
|
||||
return R.fail("参数错误:ticketId 或 slotId 不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
// 3. 执行原有的预约逻辑
|
||||
int result = ticketService.bookTicket(params);
|
||||
int result = ticketService.bookTicket(dto);
|
||||
if (result > 0) {
|
||||
// 4. 预约成功后,更新排班表状态
|
||||
DoctorSchedule schedule = new DoctorSchedule();
|
||||
schedule.setId(slotId); // 对应 XML 中的 WHERE id = #{id}
|
||||
schedule.setIsStopped(true); // 设置为已预约
|
||||
schedule.setStopReason("booked"); // 设置停用原因
|
||||
|
||||
// 执行更新
|
||||
int updateCount = doctorScheduleMapper.updateDoctorSchedule(schedule);
|
||||
|
||||
if (updateCount > 0) {
|
||||
return R.ok("预约成功并已更新排班状态");
|
||||
} else {
|
||||
// 如果更新失败,可能需要根据业务逻辑决定是否回滚预约
|
||||
return R.ok("预约成功,但排班状态更新失败");
|
||||
}
|
||||
} else {
|
||||
return R.fail("预约失败");
|
||||
return R.ok("预约成功!号源已安全锁定。");
|
||||
}
|
||||
return R.fail("预约挂单核发失败");
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
log.error(e.getMessage());
|
||||
log.error("大厅挂号捕获系统异常", e);
|
||||
return R.fail("系统异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
* 取消预约 (重构版:精准释放单一槽位)
|
||||
*
|
||||
* @param slotId 医生排班ID
|
||||
* @param slotId 医生槽位排班ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@@ -111,18 +73,8 @@ public class TicketAppServiceImpl implements ITicketAppService {
|
||||
return R.fail("参数错误");
|
||||
}
|
||||
try {
|
||||
ticketService.cancelTicket(slotId);
|
||||
DoctorSchedule schedule = new DoctorSchedule();
|
||||
schedule.setId(slotId); // 对应 WHERE id = #{id}
|
||||
schedule.setIsStopped(false); // 设置为 false
|
||||
schedule.setStopReason(""); // 将原因清空 (设为空字符串)
|
||||
// 3. 调用自定义更新方法
|
||||
int updateCount = doctorScheduleMapper.updateDoctorSchedule(schedule);
|
||||
if (updateCount > 0) {
|
||||
return R.ok("取消成功");
|
||||
} else {
|
||||
return R.ok("取消成功");
|
||||
}
|
||||
int result = ticketService.cancelTicket(slotId);
|
||||
return R.ok(result > 0 ? "取消成功,号源已重新释放回市场" : "取消失败");
|
||||
} catch (Exception e) {
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
@@ -131,16 +83,16 @@ public class TicketAppServiceImpl implements ITicketAppService {
|
||||
/**
|
||||
* 取号
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public R<?> checkInTicket(Long ticketId) {
|
||||
if (ticketId == null) {
|
||||
public R<?> checkInTicket(Long slotId) {
|
||||
if (slotId == null) {
|
||||
return R.fail("参数错误");
|
||||
}
|
||||
try {
|
||||
int result = ticketService.checkInTicket(ticketId);
|
||||
int result = ticketService.checkInTicket(slotId);
|
||||
return R.ok(result > 0 ? "取号成功" : "取号失败");
|
||||
} catch (Exception e) {
|
||||
return R.fail(e.getMessage());
|
||||
@@ -150,16 +102,16 @@ public class TicketAppServiceImpl implements ITicketAppService {
|
||||
/**
|
||||
* 停诊
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public R<?> cancelConsultation(Long ticketId) {
|
||||
if (ticketId == null) {
|
||||
public R<?> cancelConsultation(Long slotId) {
|
||||
if (slotId == null) {
|
||||
return R.fail("参数错误");
|
||||
}
|
||||
try {
|
||||
int result = ticketService.cancelConsultation(ticketId);
|
||||
int result = ticketService.cancelConsultation(slotId);
|
||||
return R.ok(result > 0 ? "停诊成功" : "停诊失败");
|
||||
} catch (Exception e) {
|
||||
return R.fail(e.getMessage());
|
||||
@@ -167,92 +119,283 @@ public class TicketAppServiceImpl implements ITicketAppService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> listAllTickets() {
|
||||
// 1. 从 AppService 获取排班数据
|
||||
R<?> response = doctorScheduleAppService.getDoctorScheduleList();
|
||||
// 获取返回的 List 数据 (假设 R.ok 里的数据是 List<DoctorSchedule>)
|
||||
List<DoctorSchedule> scheduleList = (List<DoctorSchedule>) response.getData();
|
||||
public R<?> listTicket(com.openhis.appointmentmanage.dto.TicketQueryDTO query) {
|
||||
// 1. 防空指针处理
|
||||
if (query == null) {
|
||||
query = new com.openhis.appointmentmanage.dto.TicketQueryDTO();
|
||||
}
|
||||
normalizeQueryStatus(query);
|
||||
|
||||
// 2. 转换数据为 TicketDto
|
||||
List<TicketDto> tickets = new ArrayList<>();
|
||||
// 2. 构造 MyBatis 的分页对象 (传入前端给的当前页和每页条数)
|
||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.openhis.appointmentmanage.domain.TicketSlotDTO> pageParam = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(
|
||||
query.getPage(), query.getLimit());
|
||||
|
||||
if (scheduleList != null) {
|
||||
for (DoctorSchedule schedule : scheduleList) {
|
||||
// 3. 调用刚才写的底层动态 SQL 查询!
|
||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.openhis.appointmentmanage.domain.TicketSlotDTO> rawPage = scheduleSlotMapper
|
||||
.selectTicketSlotsPage(pageParam, query);
|
||||
|
||||
// 4. 将查出来的数据翻译为前端可以直接渲染的结构
|
||||
java.util.List<TicketDto> tickets = new java.util.ArrayList<>();
|
||||
if (rawPage.getRecords() != null) {
|
||||
for (com.openhis.appointmentmanage.domain.TicketSlotDTO raw : rawPage.getRecords()) {
|
||||
TicketDto dto = new TicketDto();
|
||||
|
||||
// 基础信息映射
|
||||
dto.setSlot_id(Long.valueOf(schedule.getId())); // Integer 转 Long
|
||||
dto.setBusNo(String.valueOf(schedule.getId())); // 生成一个业务编号
|
||||
dto.setDepartment(String.valueOf(schedule.getDeptId())); // 如果有科室名建议关联查询,这里暂填ID
|
||||
dto.setDoctor(schedule.getDoctor());
|
||||
// 基础字段映射
|
||||
dto.setSlot_id(raw.getSlotId());
|
||||
dto.setSeqNo(raw.getSeqNo());
|
||||
dto.setBusNo(String.valueOf(raw.getSlotId()));
|
||||
dto.setDoctor(raw.getDoctor());
|
||||
dto.setDepartment(raw.getDepartmentName()); // 注意:以前这里传成了ID,导致前端出Bug,现在修复成了真正的科室名
|
||||
dto.setFee(raw.getFee());
|
||||
dto.setPatientName(raw.getPatientName());
|
||||
dto.setPatientId(raw.getMedicalCard());
|
||||
dto.setPhone(raw.getPhone());
|
||||
dto.setIdCard(raw.getIdCard());
|
||||
dto.setDoctorId(raw.getDoctorId());
|
||||
dto.setDepartmentId(raw.getDepartmentId());
|
||||
dto.setRealPatientId(raw.getPatientId());
|
||||
|
||||
// 号源类型处理:根据挂号项目判断是普通号还是专家号
|
||||
String registerItem = schedule.getRegisterItem();
|
||||
if (registerItem != null && registerItem.contains("专家")) {
|
||||
// 性别处理:直接读取优先级最高的订单性别字段 (SQL 已处理优先级)
|
||||
if (raw.getPatientGender() != null) {
|
||||
String pg = raw.getPatientGender().trim();
|
||||
dto.setGender("1".equals(pg) ? "男" : ("2".equals(pg) ? "女" : "未知"));
|
||||
} else {
|
||||
dto.setGender("未知");
|
||||
}
|
||||
|
||||
if (raw.getRegType() != null && raw.getRegType() == 1) {
|
||||
dto.setTicketType("expert");
|
||||
} else {
|
||||
dto.setTicketType("general");
|
||||
}
|
||||
// 时间处理:格式化为日期+时间范围,如 "2025-12-01 08:00-12:00"
|
||||
String currentDate = LocalDate.now().toString(); // 或者从schedule中获取具体日期
|
||||
String timeRange = schedule.getStartTime() + "-" + schedule.getEndTime();
|
||||
dto.setDateTime(currentDate + " " + timeRange);
|
||||
LocalTime nowTime = LocalTime.now();
|
||||
LocalTime endTime = schedule.getEndTime();
|
||||
String stopReason1 = schedule.getStopReason();
|
||||
if ("cancelled".equals(stopReason1)||(endTime != null && nowTime.isAfter(endTime))) {
|
||||
dto.setStatus("已停诊");
|
||||
}else if (Boolean.TRUE.equals(schedule.getIsStopped())) {
|
||||
// 获取原因并处理可能的空值
|
||||
String stopReason = schedule.getStopReason();
|
||||
// 使用 .equals() 比较内容,并将常量放在前面防止空指针
|
||||
if ("booked".equals(stopReason)) {
|
||||
dto.setStatus("已预约");
|
||||
// --- 新增:获取患者信息 ---
|
||||
List<Order> Order = orderMapper.selectOrderBySlotId(Long.valueOf(schedule.getId()));
|
||||
Order latestOrder=Order.get(0);
|
||||
|
||||
if (latestOrder != null) {
|
||||
dto.setPatientName(latestOrder.getPatientName());
|
||||
dto.setPatientId(String.valueOf(latestOrder.getPatientId()));
|
||||
dto.setPhone(latestOrder.getPhone());
|
||||
if (raw.getScheduleDate() != null && raw.getExpectTime() != null) {
|
||||
dto.setDateTime(raw.getScheduleDate().toString() + " " + raw.getExpectTime().toString());
|
||||
try {
|
||||
String timeStr = raw.getAppointmentTime() != null ? raw.getAppointmentTime() : (raw.getScheduleDate().toString() + " " + raw.getExpectTime().toString());
|
||||
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(timeStr.length() > 10 ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd");
|
||||
java.util.Date date = sdf.parse(timeStr);
|
||||
dto.setAppointmentDate(date);
|
||||
dto.setAppointmentTime(date);
|
||||
} catch (Exception e) {
|
||||
dto.setAppointmentDate(new java.util.Date());
|
||||
}
|
||||
// -----------------------
|
||||
} else if ("checked".equals(stopReason)) {
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(raw.getIsStopped())) {
|
||||
dto.setStatus("已停诊");
|
||||
} else {
|
||||
Integer slotStatus = raw.getSlotStatus();
|
||||
if (slotStatus != null) {
|
||||
if (SlotStatus.CHECKED_IN.equals(slotStatus)) {
|
||||
dto.setStatus("已取号");
|
||||
} else if (SlotStatus.BOOKED.equals(slotStatus)) {
|
||||
if (AppointmentOrderStatus.CHECKED_IN.equals(raw.getOrderStatus())) {
|
||||
dto.setStatus("已取号");
|
||||
} else if (AppointmentOrderStatus.RETURNED.equals(raw.getOrderStatus())) {
|
||||
dto.setStatus("已退号");
|
||||
} else {
|
||||
// 兜底逻辑:如果 is_stopped 为 true 但没有匹配到原因
|
||||
dto.setStatus("不可预约");
|
||||
dto.setStatus("已预约");
|
||||
}
|
||||
} else if (SlotStatus.RETURNED.equals(slotStatus)) {
|
||||
dto.setStatus("已退号");
|
||||
} else if (SlotStatus.CANCELLED.equals(slotStatus)) {
|
||||
dto.setStatus("已停诊");
|
||||
} else if (SlotStatus.LOCKED.equals(slotStatus)) {
|
||||
dto.setStatus("已锁定");
|
||||
} else {
|
||||
dto.setStatus("未预约");
|
||||
}
|
||||
} else {
|
||||
// is_stopped 为 false 或 null 时
|
||||
dto.setStatus("未预约");
|
||||
}
|
||||
|
||||
// 费用处理 (挂号费 + 诊疗费)
|
||||
int totalFee = schedule.getRegisterFee() + schedule.getDiagnosisFee();
|
||||
dto.setFee(String.valueOf(totalFee));
|
||||
|
||||
// 日期处理:LocalDateTime 转 Date
|
||||
if (schedule.getCreateTime() != null) {
|
||||
// 1. 先转成 Instant
|
||||
Instant instant = schedule.getCreateTime().toInstant();
|
||||
// 2. 结合时区转成 ZonedDateTime
|
||||
ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
|
||||
// 3. 再转回 Date (如果 DTO 需要的是 Date)
|
||||
dto.setAppointmentDate(Date.from(zdt.toInstant()));
|
||||
}
|
||||
|
||||
tickets.add(dto);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 封装分页响应结构
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
// 5. 按照前端组件需要的【真分页】格式进行包装,并返回
|
||||
java.util.Map<String, Object> result = new java.util.HashMap<>();
|
||||
result.put("list", tickets);
|
||||
result.put("total", rawPage.getTotal()); // 这个 total 就是底层用 COUNT(*) 算出来的真实总条数!
|
||||
result.put("page", query.getPage());
|
||||
result.put("limit", query.getLimit());
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一状态入参,避免前端状态值大小写/中文/数字差异导致 SQL 条件失效后回全量数据
|
||||
*/
|
||||
private void normalizeQueryStatus(com.openhis.appointmentmanage.dto.TicketQueryDTO query) {
|
||||
String rawStatus = query.getStatus();
|
||||
if (rawStatus == null) {
|
||||
return;
|
||||
}
|
||||
String normalized = rawStatus.trim();
|
||||
if (normalized.isEmpty()) {
|
||||
query.setStatus(null);
|
||||
return;
|
||||
}
|
||||
String lower = normalized.toLowerCase(Locale.ROOT);
|
||||
switch (lower) {
|
||||
case "all":
|
||||
case "全部":
|
||||
query.setStatus("all");
|
||||
break;
|
||||
case "unbooked":
|
||||
case "0":
|
||||
case "未预约":
|
||||
query.setStatus("unbooked");
|
||||
break;
|
||||
case "booked":
|
||||
case "1":
|
||||
case "已预约":
|
||||
query.setStatus("booked");
|
||||
break;
|
||||
case "checked":
|
||||
case "checkin":
|
||||
case "checkedin":
|
||||
case "2":
|
||||
case "已取号":
|
||||
query.setStatus("checked");
|
||||
break;
|
||||
case "cancelled":
|
||||
case "canceled":
|
||||
case "3":
|
||||
case "已停诊":
|
||||
case "已取消":
|
||||
query.setStatus("cancelled");
|
||||
break;
|
||||
case "returned":
|
||||
case "4":
|
||||
case "5":
|
||||
case "已退号":
|
||||
query.setStatus("returned");
|
||||
break;
|
||||
default:
|
||||
// 设置为 impossible 值,配合 mapper 的 otherwise 分支直接返回空
|
||||
query.setStatus("__invalid__");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> listDoctorAvailability(com.openhis.appointmentmanage.dto.TicketQueryDTO query) {
|
||||
if (query == null) {
|
||||
query = new com.openhis.appointmentmanage.dto.TicketQueryDTO();
|
||||
}
|
||||
|
||||
java.util.List<com.openhis.appointmentmanage.domain.DoctorAvailabilityDTO> rawList = scheduleSlotMapper
|
||||
.selectDoctorAvailabilitySummary(query);
|
||||
java.util.List<java.util.Map<String, Object>> doctors = new java.util.ArrayList<>();
|
||||
if (rawList != null) {
|
||||
for (com.openhis.appointmentmanage.domain.DoctorAvailabilityDTO item : rawList) {
|
||||
java.util.Map<String, Object> row = new java.util.HashMap<>();
|
||||
String doctorName = item.getDoctorName();
|
||||
Long doctorId = item.getDoctorId();
|
||||
row.put("id", doctorId != null ? String.valueOf(doctorId) : doctorName);
|
||||
row.put("name", doctorName);
|
||||
row.put("available", item.getAvailable() == null ? 0 : item.getAvailable());
|
||||
row.put("type", item.getTicketType() == null ? "general" : item.getTicketType());
|
||||
doctors.add(row);
|
||||
}
|
||||
}
|
||||
return R.ok(doctors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> listAllTickets() {
|
||||
// 1. 调用最新的 Mapper,直接从数据库抽出我们半成品的 DTO(强类型!)
|
||||
List<com.openhis.appointmentmanage.domain.TicketSlotDTO> rawDtos = scheduleSlotMapper.selectAllTicketSlots();
|
||||
|
||||
// 这是真正要发给前端展示的包裹外卖盒
|
||||
List<TicketDto> tickets = new ArrayList<>();
|
||||
|
||||
if (rawDtos != null) {
|
||||
for (com.openhis.appointmentmanage.domain.TicketSlotDTO raw : rawDtos) {
|
||||
TicketDto dto = new TicketDto();
|
||||
|
||||
// --- 基础字段处理 ---
|
||||
// 注意:这里已经变成了极其舒服的 .getSlotId() 方法调用,告别魔鬼字符串!
|
||||
dto.setSlot_id(raw.getSlotId());
|
||||
dto.setSeqNo(raw.getSeqNo());
|
||||
dto.setBusNo(String.valueOf(raw.getSlotId())); // 暂时借用真实槽位ID做唯一流水号
|
||||
dto.setDoctor(raw.getDoctor());
|
||||
dto.setDepartment(raw.getDepartmentName());
|
||||
dto.setFee(raw.getFee());
|
||||
dto.setPatientName(raw.getPatientName());
|
||||
dto.setPatientId(raw.getMedicalCard());
|
||||
dto.setPhone(raw.getPhone());
|
||||
|
||||
// --- 号源类型处理 (普通/专家) ---
|
||||
// 改用底层 adm_doctor_schedule 传来的标准数字字典:0=普通,1=专家
|
||||
if (raw.getRegType() != null && raw.getRegType() == 1) {
|
||||
dto.setTicketType("expert");
|
||||
} else {
|
||||
dto.setTicketType("general");
|
||||
}
|
||||
|
||||
// --- 就诊时间严谨拼接 ---
|
||||
// 拼接出来给前端展示的,如 "2026-03-20 08:30"
|
||||
if (raw.getScheduleDate() != null && raw.getExpectTime() != null) {
|
||||
dto.setDateTime(raw.getScheduleDate().toString() + " " + raw.getExpectTime().toString());
|
||||
try {
|
||||
String timeStr = raw.getAppointmentTime() != null ? raw.getAppointmentTime() : (raw.getScheduleDate().toString() + " " + raw.getExpectTime().toString());
|
||||
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(timeStr.length() > 10 ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd");
|
||||
java.util.Date date = sdf.parse(timeStr);
|
||||
dto.setAppointmentDate(date);
|
||||
dto.setAppointmentTime(date);
|
||||
} catch (Exception e) {
|
||||
log.error("时间解析失败", e);
|
||||
dto.setAppointmentDate(new java.util.Date());
|
||||
}
|
||||
}
|
||||
|
||||
// --- 核心逻辑:精准状态分类 ---
|
||||
// 第一关:底层硬性停诊拦截
|
||||
if (Boolean.TRUE.equals(raw.getIsStopped())) {
|
||||
dto.setStatus("已停诊");
|
||||
} else {
|
||||
// 第二关:看独立的细分槽位状态 (0: 可用, 1: 已预约, 2: 已取消...)
|
||||
Integer slotStatus = raw.getSlotStatus();
|
||||
if (slotStatus != null) {
|
||||
if (SlotStatus.CHECKED_IN.equals(slotStatus)) {
|
||||
dto.setStatus("已取号");
|
||||
} else if (SlotStatus.BOOKED.equals(slotStatus)) {
|
||||
if (AppointmentOrderStatus.CHECKED_IN.equals(raw.getOrderStatus())) {
|
||||
dto.setStatus("已取号");
|
||||
} else if (AppointmentOrderStatus.RETURNED.equals(raw.getOrderStatus())) {
|
||||
dto.setStatus("已退号");
|
||||
} else {
|
||||
dto.setStatus("已预约");
|
||||
}
|
||||
} else if (SlotStatus.RETURNED.equals(slotStatus)) {
|
||||
dto.setStatus("已退号");
|
||||
} else if (SlotStatus.CANCELLED.equals(slotStatus)) {
|
||||
dto.setStatus("已停诊");
|
||||
} else if (SlotStatus.LOCKED.equals(slotStatus)) {
|
||||
dto.setStatus("已锁定");
|
||||
} else {
|
||||
dto.setStatus("未预约");
|
||||
}
|
||||
} else {
|
||||
dto.setStatus("未预约");
|
||||
}
|
||||
}
|
||||
|
||||
tickets.add(dto);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 封装分页响应结构并吐给前端
|
||||
java.util.Map<String, Object> result = new java.util.HashMap<>();
|
||||
result.put("list", tickets);
|
||||
result.put("total", tickets.size());
|
||||
result.put("page", 1);
|
||||
result.put("limit", 20);
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@@ -312,14 +455,11 @@ public class TicketAppServiceImpl implements ITicketAppService {
|
||||
if (patient != null) {
|
||||
Integer genderEnum = patient.getGenderEnum();
|
||||
if (genderEnum != null) {
|
||||
switch (genderEnum) {
|
||||
case 1:
|
||||
if (Integer.valueOf(1).equals(genderEnum)) {
|
||||
dto.setGender("男");
|
||||
break;
|
||||
case 2:
|
||||
} else if (Integer.valueOf(2).equals(genderEnum)) {
|
||||
dto.setGender("女");
|
||||
break;
|
||||
default:
|
||||
} else {
|
||||
dto.setGender("未知");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.openhis.web.appointmentmanage.controller;
|
||||
|
||||
import com.core.common.core.domain.R;
|
||||
import com.openhis.appointmentmanage.domain.AppointmentConfig;
|
||||
import com.openhis.web.appointmentmanage.appservice.IAppointmentConfigAppService;
|
||||
import com.openhis.web.appointmentmanage.appservice.IDeptAppService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@@ -16,6 +15,9 @@ public class DeptController {
|
||||
@Resource
|
||||
private IDeptAppService deptAppService;
|
||||
|
||||
@Resource
|
||||
private IAppointmentConfigAppService appointmentConfigAppService;
|
||||
|
||||
/*
|
||||
* 获取科室列表
|
||||
*
|
||||
@@ -38,4 +40,22 @@ public class DeptController {
|
||||
){
|
||||
return R.ok(deptAppService.searchDept(pageNo,pageSize,orgName,deptName));
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取预约配置
|
||||
*
|
||||
* */
|
||||
@GetMapping("/config")
|
||||
public R<?> getAppointmentConfig(){
|
||||
return appointmentConfigAppService.getAppointmentConfig();
|
||||
}
|
||||
|
||||
/*
|
||||
* 保存预约配置
|
||||
*
|
||||
* */
|
||||
@PostMapping("/config")
|
||||
public R<?> saveAppointmentConfig(@RequestBody AppointmentConfig appointmentConfig){
|
||||
return appointmentConfigAppService.saveAppointmentConfig(appointmentConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,12 @@ package com.openhis.web.appointmentmanage.controller;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.annotation.Anonymous;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.openhis.appointmentmanage.domain.AppointmentBookDTO;
|
||||
import com.openhis.appointmentmanage.dto.TicketQueryDTO;
|
||||
import com.openhis.web.appointmentmanage.appservice.ITicketAppService;
|
||||
import com.openhis.web.appointmentmanage.dto.TicketDto;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -19,11 +23,35 @@ import java.util.Map;
|
||||
@RequestMapping("/appointment/ticket")
|
||||
public class TicketController {
|
||||
|
||||
/**
|
||||
* 分页查询门诊号源列表 (带多条件过滤)
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @return 分页号源列表
|
||||
*/
|
||||
@Anonymous
|
||||
@PostMapping("/list")
|
||||
public R<?> listTicket(@RequestBody @Validated TicketQueryDTO query) {
|
||||
return ticketAppService.listTicket(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询医生余号汇总(基于号源池,不受分页影响)
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @return 医生余号列表
|
||||
*/
|
||||
@Anonymous
|
||||
@PostMapping("/doctorSummary")
|
||||
public R<?> listDoctorAvailability(@RequestBody @Validated TicketQueryDTO query) {
|
||||
return ticketAppService.listDoctorAvailability(query);
|
||||
}
|
||||
|
||||
@Resource
|
||||
private ITicketAppService ticketAppService;
|
||||
|
||||
/**
|
||||
* 查询所有号源(用于测试)
|
||||
* 查询所有号源
|
||||
*
|
||||
* @return 所有号源列表
|
||||
*/
|
||||
@@ -36,44 +64,44 @@ public class TicketController {
|
||||
/**
|
||||
* 预约号源
|
||||
*
|
||||
* @param params 预约参数
|
||||
* @param dto 预约参数
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/book")
|
||||
public R<?> bookTicket(@RequestBody Map<String, Object> params) {
|
||||
return ticketAppService.bookTicket(params);
|
||||
public R<?> bookTicket(@RequestBody @Validated AppointmentBookDTO dto) {
|
||||
return ticketAppService.bookTicket(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/cancel")
|
||||
public R<?> cancelTicket(@RequestParam Long ticketId) {
|
||||
return ticketAppService.cancelTicket(ticketId);
|
||||
public R<?> cancelTicket(@RequestParam Long slotId) {
|
||||
return ticketAppService.cancelTicket(slotId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取号
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/checkin")
|
||||
public R<?> checkInTicket(@RequestParam Long ticketId) {
|
||||
return ticketAppService.checkInTicket(ticketId);
|
||||
public R<?> checkInTicket(@RequestParam Long slotId) {
|
||||
return ticketAppService.checkInTicket(slotId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停诊
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/cancelConsultation")
|
||||
public R<?> cancelConsultation(@RequestParam Long ticketId) {
|
||||
return ticketAppService.cancelConsultation(ticketId);
|
||||
public R<?> cancelConsultation(@RequestParam Long slotId) {
|
||||
return ticketAppService.cancelConsultation(slotId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ public class TicketDto {
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long slot_id;
|
||||
|
||||
/**
|
||||
* 号源序号(对应 adm_schedule_slot.seq_no)
|
||||
*/
|
||||
private Integer seqNo;
|
||||
|
||||
/**
|
||||
* 号源编码
|
||||
*/
|
||||
@@ -49,7 +54,7 @@ public class TicketDto {
|
||||
private String dateTime;
|
||||
|
||||
/**
|
||||
* 状态 (unbooked:未预约, booked:已预约, checked:已取号, cancelled:已取消, locked:已锁定)
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
@@ -99,4 +104,15 @@ public class TicketDto {
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long doctorId;
|
||||
|
||||
/**
|
||||
* 真实患者ID(数据库主键,区别于 patientId 存的就诊卡号)
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long realPatientId;
|
||||
|
||||
/**
|
||||
* 身份证号
|
||||
*/
|
||||
private String idCard;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@ public class OutpatientChargeAppServiceImpl implements IOutpatientChargeAppServi
|
||||
= outpatientChargeAppMapper.selectEncounterPatientPrescription(encounterId,
|
||||
ChargeItemContext.ACTIVITY.getValue(), ChargeItemContext.MEDICATION.getValue(),
|
||||
ChargeItemContext.DEVICE.getValue(), ChargeItemContext.REGISTER.getValue(),
|
||||
ChargeItemContext.WESTERN_MEDICINE.getValue(), ChargeItemContext.CHINESE_PATENT_MEDICINE.getValue(),
|
||||
ChargeItemStatus.PLANNED.getValue(), ChargeItemStatus.BILLABLE.getValue(),
|
||||
ChargeItemStatus.BILLED.getValue(), ChargeItemStatus.REFUNDING.getValue(),
|
||||
ChargeItemStatus.REFUNDED.getValue(), ChargeItemStatus.PART_REFUND.getValue(),
|
||||
|
||||
@@ -73,10 +73,10 @@ public class OutpatientPricingAppServiceImpl implements IOutpatientPricingAppSer
|
||||
} else {
|
||||
adviceTypes = List.of(1, 2, 3);
|
||||
}
|
||||
// 门诊划价:不要强制 pricingFlag=1 参与过滤(wor_activity_definition.pricing_flag 可能为 0),
|
||||
// 否则会导致诊疗项目(adviceType=3)查询结果为空 records=[]
|
||||
String categoryCode = adviceBaseDto != null ? adviceBaseDto.getCategoryCode() : null;
|
||||
// 门诊划价:仅返回划价标记为“是”的项目
|
||||
return iDoctorStationAdviceAppService.getAdviceBaseInfo(adviceBaseDto, searchKey, locationId, null,
|
||||
organizationId, pageNo, pageSize, null, adviceTypes, null);
|
||||
organizationId, pageNo, pageSize, Whether.YES.getValue(), adviceTypes, null, categoryCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ import com.openhis.common.enums.ybenums.YbPayment;
|
||||
import com.openhis.common.utils.EnumUtils;
|
||||
import com.openhis.common.utils.HisPageUtils;
|
||||
import com.openhis.common.utils.HisQueryUtils;
|
||||
import com.openhis.appointmentmanage.mapper.SchedulePoolMapper;
|
||||
import com.openhis.appointmentmanage.mapper.ScheduleSlotMapper;
|
||||
import com.openhis.clinical.domain.Order;
|
||||
import com.openhis.clinical.service.IOrderService;
|
||||
import com.openhis.financial.domain.PaymentReconciliation;
|
||||
import com.openhis.financial.domain.RefundLog;
|
||||
import com.openhis.financial.service.IRefundLogService;
|
||||
@@ -48,6 +52,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -97,6 +102,15 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra
|
||||
@Resource
|
||||
IRefundLogService iRefundLogService;
|
||||
|
||||
@Resource
|
||||
IOrderService orderService;
|
||||
|
||||
@Resource
|
||||
ScheduleSlotMapper scheduleSlotMapper;
|
||||
|
||||
@Resource
|
||||
SchedulePoolMapper schedulePoolMapper;
|
||||
|
||||
/**
|
||||
* 门诊挂号 - 查询患者信息
|
||||
*
|
||||
@@ -291,6 +305,11 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra
|
||||
}
|
||||
}
|
||||
|
||||
// 如果本次门诊挂号来自预约签到,同步把预约订单与号源槽位状态改为已退号
|
||||
if (result != null && result.getCode() == 200) {
|
||||
syncAppointmentReturnStatus(byId, cancelRegPaymentDto.getReason());
|
||||
}
|
||||
|
||||
// 记录退号日志
|
||||
recordRefundLog(cancelRegPaymentDto, byId, result, paymentRecon);
|
||||
|
||||
@@ -399,6 +418,74 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra
|
||||
return R.ok("已取消挂号");
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步预约号源状态为已退号。
|
||||
* 说明:
|
||||
* 1) 门诊退号主流程不依赖该步骤成功与否,因此此方法内部异常仅记录日志,不向上抛出。
|
||||
* 2) 通过患者、科室、日期以及状态筛选最近一条预约订单,尽量避免误匹配。
|
||||
*/
|
||||
private void syncAppointmentReturnStatus(Encounter encounter, String reason) {
|
||||
if (encounter == null || encounter.getPatientId() == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<Order>()
|
||||
.eq(Order::getPatientId, encounter.getPatientId())
|
||||
.in(Order::getStatus, CommonConstants.AppointmentOrderStatus.BOOKED,
|
||||
CommonConstants.AppointmentOrderStatus.CHECKED_IN)
|
||||
.orderByDesc(Order::getUpdateTime)
|
||||
.orderByDesc(Order::getCreateTime)
|
||||
.last("LIMIT 1");
|
||||
|
||||
if (encounter.getOrganizationId() != null) {
|
||||
queryWrapper.eq(Order::getDepartmentId, encounter.getOrganizationId());
|
||||
}
|
||||
if (encounter.getTenantId() != null) {
|
||||
queryWrapper.eq(Order::getTenantId, encounter.getTenantId());
|
||||
}
|
||||
if (encounter.getCreateTime() != null) {
|
||||
LocalDate encounterDate = encounter.getCreateTime().toInstant()
|
||||
.atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
Date startOfDay = Date.from(encounterDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
Date nextDayStart = Date.from(encounterDate.plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
queryWrapper.ge(Order::getAppointmentDate, startOfDay)
|
||||
.lt(Order::getAppointmentDate, nextDayStart);
|
||||
}
|
||||
|
||||
Order appointmentOrder = orderService.getOne(queryWrapper, false);
|
||||
if (appointmentOrder == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
if (!CommonConstants.AppointmentOrderStatus.RETURNED.equals(appointmentOrder.getStatus())) {
|
||||
Order updateOrder = new Order();
|
||||
updateOrder.setId(appointmentOrder.getId());
|
||||
updateOrder.setStatus(CommonConstants.AppointmentOrderStatus.RETURNED);
|
||||
updateOrder.setCancelTime(now);
|
||||
updateOrder.setCancelReason(
|
||||
StringUtils.isNotEmpty(reason) ? reason : "门诊退号");
|
||||
updateOrder.setUpdateTime(now);
|
||||
orderService.updateById(updateOrder);
|
||||
}
|
||||
|
||||
Long slotId = appointmentOrder.getSlotId();
|
||||
if (slotId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int slotRows = scheduleSlotMapper.updateSlotStatus(slotId, CommonConstants.SlotStatus.RETURNED);
|
||||
if (slotRows > 0) {
|
||||
Long poolId = scheduleSlotMapper.selectPoolIdBySlotId(slotId);
|
||||
if (poolId != null) {
|
||||
schedulePoolMapper.refreshPoolStats(poolId);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("同步预约号源已退号状态失败, encounterId={}", encounter.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 补打挂号
|
||||
* 补打挂号不需要修改数据库,只需要返回成功即可,前端已有所有需要的数据用于打印
|
||||
|
||||
@@ -61,7 +61,12 @@ public class OutpatientPricingController {
|
||||
@RequestParam(value = "locationId", required = false) Long locationId,
|
||||
@RequestParam(value = "organizationId") Long organizationId,
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(value = "categoryCode", required = false) String categoryCode) {
|
||||
// 将 categoryCode 设置到 adviceBaseDto 中
|
||||
if (categoryCode != null && !categoryCode.isEmpty()) {
|
||||
adviceBaseDto.setCategoryCode(categoryCode);
|
||||
}
|
||||
return R.ok(iOutpatientPricingAppService.getAdviceBaseInfo(adviceBaseDto, searchKey, locationId, organizationId,
|
||||
pageNo, pageSize));
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ public interface OutpatientChargeAppMapper {
|
||||
* @param medication 药品
|
||||
* @param device 耗材
|
||||
* @param register 挂号费
|
||||
* @param westernMedicine 西药
|
||||
* @param chinesePatentMedicine 中成药
|
||||
* @param planned 收费状态:待收费
|
||||
* @param billable 收费状态:待结算
|
||||
* @param billed 收费状态:已结算
|
||||
@@ -53,7 +55,9 @@ public interface OutpatientChargeAppMapper {
|
||||
*/
|
||||
List<EncounterPatientPrescriptionDto> selectEncounterPatientPrescription(@Param("encounterId") Long encounterId,
|
||||
@Param("activity") Integer activity, @Param("medication") Integer medication, @Param("device") Integer device,
|
||||
@Param("register") Integer register, @Param("planned") Integer planned, @Param("billable") Integer billable,
|
||||
@Param("register") Integer register, @Param("westernMedicine") Integer westernMedicine,
|
||||
@Param("chinesePatentMedicine") Integer chinesePatentMedicine,
|
||||
@Param("planned") Integer planned, @Param("billable") Integer billable,
|
||||
@Param("billed") Integer billed, @Param("refunding") Integer refunding, @Param("refunded") Integer refunded,
|
||||
@Param("partRefund") Integer partRefund, @Param("worDeviceRequest") String worDeviceRequest);
|
||||
|
||||
|
||||
@@ -24,5 +24,5 @@ public interface ICheckMethodAppService{
|
||||
|
||||
R<?> searchCheckMethodList(Integer pageNo, Integer pageSize, String checkType, String name, String packageName);
|
||||
|
||||
R<?> exportCheckMethod(String checkType, String name, String packageName, HttpServletResponse response);
|
||||
void exportCheckMethod(String checkType, String name, String packageName, HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -16,5 +16,5 @@ public interface ICheckPartAppService {
|
||||
|
||||
R<?> searchCheckPartList(Integer pageNo, Integer pageSize, String checkType, String name, String packageName);
|
||||
|
||||
R<?> exportCheckPart(String checkType, String name, String packageName, HttpServletResponse response);
|
||||
void exportCheckPart(String checkType, String name, String packageName, HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class CheckMethodAppServiceImpl implements ICheckMethodAppService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> exportCheckMethod(String checkType, String name, String packageName, HttpServletResponse response) {
|
||||
public void exportCheckMethod(String checkType, String name, String packageName, HttpServletResponse response) {
|
||||
LambdaQueryWrapper<CheckMethod> wrapper = new LambdaQueryWrapper<>();
|
||||
if (checkType != null && ObjectUtil.isNotEmpty(checkType)) {
|
||||
wrapper.eq(CheckMethod::getCheckType, checkType);
|
||||
@@ -103,7 +103,13 @@ public class CheckMethodAppServiceImpl implements ICheckMethodAppService {
|
||||
List<CheckMethod> list = checkMethodService.list(wrapper);
|
||||
|
||||
if (list.isEmpty()) {
|
||||
return R.fail("导出Excel失败,无数据。");
|
||||
try {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":500,\"msg\":\"导出Excel失败,无数据。\"}");
|
||||
} catch (IOException e) {
|
||||
log.error("写入响应失败", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -123,9 +129,12 @@ public class CheckMethodAppServiceImpl implements ICheckMethodAppService {
|
||||
ExcelFillerUtil.makeExcelFile(response, list, headers, excelName, null);
|
||||
} catch (IOException | IllegalAccessException e) {
|
||||
log.error("导出Excel失败", e);
|
||||
return R.fail("导出Excel失败:" + e.getMessage());
|
||||
try {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":500,\"msg\":\"导出Excel失败:" + e.getMessage() + "\"}");
|
||||
} catch (IOException ex) {
|
||||
log.error("写入响应失败", ex);
|
||||
}
|
||||
}
|
||||
|
||||
return R.ok(null, "导出Excel成功");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 检查套餐AppService实现
|
||||
* 检查套餐 AppService 实现
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-11-26
|
||||
@@ -35,6 +35,32 @@ public class CheckPackageAppServiceImpl implements ICheckPackageAppService {
|
||||
private final ICheckPackageService checkPackageService;
|
||||
private final ICheckPackageDetailService checkPackageDetailService;
|
||||
|
||||
/**
|
||||
* 转换明细 DTO 列表为实体列表
|
||||
* @param detailDtos 明细 DTO 列表
|
||||
* @param packageId 套餐 ID
|
||||
* @param orderNumStart 起始序号
|
||||
* @return 明细实体列表
|
||||
*/
|
||||
private List<CheckPackageDetail> convertToDetails(List<CheckPackageDetailDto> detailDtos, Long packageId, int orderNumStart) {
|
||||
if (detailDtos == null || detailDtos.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<CheckPackageDetail> details = new ArrayList<>();
|
||||
int orderNum = orderNumStart;
|
||||
for (CheckPackageDetailDto detailDto : detailDtos) {
|
||||
CheckPackageDetail detail = new CheckPackageDetail();
|
||||
BeanUtils.copyProperties(detailDto, detail);
|
||||
detail.setPackageId(packageId);
|
||||
detail.setOrderNum(orderNum++);
|
||||
detail.setCreateTime(LocalDateTime.now());
|
||||
detail.setUpdateTime(LocalDateTime.now());
|
||||
details.add(detail);
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> getCheckPackageList() {
|
||||
try {
|
||||
@@ -61,7 +87,7 @@ public class CheckPackageAppServiceImpl implements ICheckPackageAppService {
|
||||
.orderByAsc(CheckPackageDetail::getOrderNum)
|
||||
);
|
||||
|
||||
// 转换为DTO
|
||||
// 转换为 DTO
|
||||
CheckPackageDto dto = new CheckPackageDto();
|
||||
BeanUtils.copyProperties(checkPackage, dto);
|
||||
|
||||
@@ -101,28 +127,21 @@ public class CheckPackageAppServiceImpl implements ICheckPackageAppService {
|
||||
|
||||
// 保存套餐明细
|
||||
if (checkPackageDto.getItems() != null && !checkPackageDto.getItems().isEmpty()) {
|
||||
List<CheckPackageDetail> details = new ArrayList<>();
|
||||
int orderNum = 1;
|
||||
for (CheckPackageDetailDto detailDto : checkPackageDto.getItems()) {
|
||||
CheckPackageDetail detail = new CheckPackageDetail();
|
||||
BeanUtils.copyProperties(detailDto, detail);
|
||||
detail.setPackageId(checkPackage.getId());
|
||||
detail.setOrderNum(orderNum++);
|
||||
detail.setCreateTime(LocalDateTime.now());
|
||||
detail.setUpdateTime(LocalDateTime.now());
|
||||
details.add(detail);
|
||||
List<CheckPackageDetail> details = convertToDetails(checkPackageDto.getItems(), checkPackage.getId(), 1);
|
||||
boolean detailSaveResult = checkPackageDetailService.saveBatch(details);
|
||||
if (!detailSaveResult) {
|
||||
throw new RuntimeException("保存套餐明细失败");
|
||||
}
|
||||
checkPackageDetailService.saveBatch(details);
|
||||
}
|
||||
|
||||
return R.ok(checkPackage.getId(), "保存成功");
|
||||
} catch (Exception e) {
|
||||
log.error("新增检查套餐失败", e);
|
||||
|
||||
// 捕获PostgreSQL唯一约束冲突异常
|
||||
// 捕获 PostgreSQL 唯一约束冲突异常
|
||||
String errorMessage = e.getMessage();
|
||||
if (errorMessage != null) {
|
||||
// PostgreSQL唯一约束错误通常包含 "duplicate key value" 或约束名称
|
||||
// PostgreSQL 唯一约束错误通常包含 "duplicate key value" 或约束名称
|
||||
if (errorMessage.contains("duplicate key value") ||
|
||||
errorMessage.contains("违反唯一约束") ||
|
||||
errorMessage.contains("unique constraint")) {
|
||||
@@ -135,7 +154,7 @@ public class CheckPackageAppServiceImpl implements ICheckPackageAppService {
|
||||
}
|
||||
}
|
||||
|
||||
return R.fail("新增检查套餐失败: " + errorMessage);
|
||||
return R.fail("新增检查套餐失败:" + errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,24 +189,14 @@ public class CheckPackageAppServiceImpl implements ICheckPackageAppService {
|
||||
|
||||
// 保存新的套餐明细
|
||||
if (checkPackageDto.getItems() != null && !checkPackageDto.getItems().isEmpty()) {
|
||||
List<CheckPackageDetail> details = new ArrayList<>();
|
||||
int orderNum = 1;
|
||||
for (CheckPackageDetailDto detailDto : checkPackageDto.getItems()) {
|
||||
CheckPackageDetail detail = new CheckPackageDetail();
|
||||
BeanUtils.copyProperties(detailDto, detail);
|
||||
detail.setPackageId(checkPackage.getId());
|
||||
detail.setOrderNum(orderNum++);
|
||||
detail.setCreateTime(LocalDateTime.now());
|
||||
detail.setUpdateTime(LocalDateTime.now());
|
||||
details.add(detail);
|
||||
}
|
||||
List<CheckPackageDetail> details = convertToDetails(checkPackageDto.getItems(), checkPackage.getId(), 1);
|
||||
checkPackageDetailService.saveBatch(details);
|
||||
}
|
||||
|
||||
return R.ok("更新成功");
|
||||
} catch (Exception e) {
|
||||
log.error("更新检查套餐失败", e);
|
||||
return R.fail("更新检查套餐失败: " + e.getMessage());
|
||||
return R.fail("更新检查套餐失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,11 +210,14 @@ public class CheckPackageAppServiceImpl implements ICheckPackageAppService {
|
||||
return R.fail("套餐不存在");
|
||||
}
|
||||
|
||||
// 删除套餐明细
|
||||
checkPackageDetailService.remove(
|
||||
// 删除套餐明细 - 先删除子表数据
|
||||
boolean removeDetailsResult = checkPackageDetailService.remove(
|
||||
new LambdaQueryWrapper<CheckPackageDetail>()
|
||||
.eq(CheckPackageDetail::getPackageId, id)
|
||||
);
|
||||
if (!removeDetailsResult) {
|
||||
log.warn("删除套餐明细失败,套餐 ID: {}", id);
|
||||
}
|
||||
|
||||
// 删除套餐主表
|
||||
boolean deleteResult = checkPackageService.removeById(id);
|
||||
@@ -213,11 +225,11 @@ public class CheckPackageAppServiceImpl implements ICheckPackageAppService {
|
||||
return R.fail("删除套餐失败");
|
||||
}
|
||||
|
||||
log.info("删除检查套餐成功,套餐 ID: {}", id);
|
||||
return R.ok("删除成功");
|
||||
} catch (Exception e) {
|
||||
log.error("删除检查套餐失败", e);
|
||||
return R.fail("删除检查套餐失败: " + e.getMessage());
|
||||
return R.fail("删除检查套餐失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class CheckPartAppServiceImpl implements ICheckPartAppService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> exportCheckPart(String checkType, String name, String packageName, HttpServletResponse response) {
|
||||
public void exportCheckPart(String checkType, String name, String packageName, HttpServletResponse response) {
|
||||
LambdaQueryWrapper<CheckPart> wrapper = new LambdaQueryWrapper<>();
|
||||
if (checkType != null && ObjectUtil.isNotEmpty(checkType)) {
|
||||
wrapper.eq(CheckPart::getCheckType, checkType);
|
||||
@@ -79,7 +79,13 @@ public class CheckPartAppServiceImpl implements ICheckPartAppService {
|
||||
List<CheckPart> list = checkPartService.list(wrapper);
|
||||
|
||||
if (list.isEmpty()) {
|
||||
return R.fail("导出Excel失败,无数据。");
|
||||
try {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":500,\"msg\":\"导出Excel失败,无数据。\"}");
|
||||
} catch (IOException e) {
|
||||
log.error("写入响应失败", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -102,8 +108,12 @@ public class CheckPartAppServiceImpl implements ICheckPartAppService {
|
||||
ExcelFillerUtil.makeExcelFile(response, list, headers, excelName, null);
|
||||
} catch (IOException | IllegalAccessException e) {
|
||||
log.error("导出Excel失败", e);
|
||||
return R.fail("导出Excel失败:" + e.getMessage());
|
||||
try {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":500,\"msg\":\"导出Excel失败:" + e.getMessage() + "\"}");
|
||||
} catch (IOException ex) {
|
||||
log.error("写入响应失败", ex);
|
||||
}
|
||||
}
|
||||
return R.ok(null, "导出Excel成功");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ public class CheckPackageDetailDto {
|
||||
@NotNull(message = "数量不能为空")
|
||||
private Integer quantity;
|
||||
|
||||
/** 单位 */
|
||||
private String unit;
|
||||
|
||||
/** 单价 */
|
||||
@NotNull(message = "单价不能为空")
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
@@ -343,11 +343,28 @@ public class SurgeryAppServiceImpl implements ISurgeryAppService {
|
||||
serviceRequest.setEncounterId(surgeryDto.getEncounterId()); // 就诊id
|
||||
serviceRequest.setAuthoredTime(curDate); // 请求签发时间
|
||||
serviceRequest.setOrgId(orgId); // 执行科室
|
||||
// 🔧 BugFix#318: 设置 contentJson,包含手术名称
|
||||
Map<String, String> serviceContentMap = new HashMap<>();
|
||||
String surgeryNameFromDto = surgeryDto.getSurgeryName();
|
||||
String surgeryCodeFromDto = surgeryDto.getSurgeryCode();
|
||||
log.info("【DEBUG】surgeryName from DTO: {}", surgeryNameFromDto);
|
||||
log.info("【DEBUG】surgeryCode from DTO: {}", surgeryCodeFromDto);
|
||||
serviceContentMap.put("surgeryName", surgeryNameFromDto != null ? surgeryNameFromDto : "");
|
||||
serviceContentMap.put("surgeryCode", surgeryCodeFromDto != null ? surgeryCodeFromDto : "");
|
||||
try {
|
||||
String contentJson = new ObjectMapper().writeValueAsString(serviceContentMap);
|
||||
log.info("【DEBUG】Setting contentJson: {}", contentJson);
|
||||
serviceRequest.setContentJson(contentJson);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("【DEBUG】设置手术医嘱 contentJson 失败", e);
|
||||
}
|
||||
serviceRequestService.save(serviceRequest);
|
||||
log.info("【DEBUG】Saved serviceRequest with ID: {}, contentJson: {}",
|
||||
serviceRequest.getId(), serviceRequest.getContentJson());
|
||||
|
||||
// 生成收费项目
|
||||
ChargeItem chargeItem = new ChargeItem();
|
||||
chargeItem.setStatusEnum(ChargeItemStatus.DRAFT.getValue()); // 收费状态
|
||||
chargeItem.setStatusEnum(ChargeItemStatus.PLANNED.getValue()); // 收费状态:待收费
|
||||
chargeItem.setBusNo("CI" + serviceRequest.getBusNo());
|
||||
chargeItem.setGenerateSourceEnum(GenerateSource.DOCTOR_PRESCRIPTION.getValue()); // 生成来源
|
||||
chargeItem.setPatientId(surgeryDto.getPatientId()); // 患者
|
||||
@@ -541,15 +558,33 @@ public class SurgeryAppServiceImpl implements ISurgeryAppService {
|
||||
// 收集所有需要查询的ID
|
||||
Set<Long> practitionerIds = new HashSet<>();
|
||||
Set<Long> orgIds = new HashSet<>();
|
||||
Set<Long> otherIds = new HashSet<>();
|
||||
Set<Long> userIds = new HashSet<>(); // 用于查询sys_user表
|
||||
|
||||
// 收集Practitioner IDs
|
||||
if (surgery.getMainSurgeonId() != null) practitionerIds.add(surgery.getMainSurgeonId());
|
||||
if (surgery.getAnesthetistId() != null) practitionerIds.add(surgery.getAnesthetistId());
|
||||
if (surgery.getAssistant1Id() != null) practitionerIds.add(surgery.getAssistant1Id());
|
||||
if (surgery.getAssistant2Id() != null) practitionerIds.add(surgery.getAssistant2Id());
|
||||
if (surgery.getScrubNurseId() != null) practitionerIds.add(surgery.getScrubNurseId());
|
||||
if (surgery.getApplyDoctorId() != null) practitionerIds.add(surgery.getApplyDoctorId());
|
||||
// 收集Practitioner IDs (医生相关)
|
||||
if (surgery.getMainSurgeonId() != null) {
|
||||
practitionerIds.add(surgery.getMainSurgeonId());
|
||||
userIds.add(surgery.getMainSurgeonId());
|
||||
}
|
||||
if (surgery.getAnesthetistId() != null) {
|
||||
practitionerIds.add(surgery.getAnesthetistId());
|
||||
userIds.add(surgery.getAnesthetistId());
|
||||
}
|
||||
if (surgery.getAssistant1Id() != null) {
|
||||
practitionerIds.add(surgery.getAssistant1Id());
|
||||
userIds.add(surgery.getAssistant1Id());
|
||||
}
|
||||
if (surgery.getAssistant2Id() != null) {
|
||||
practitionerIds.add(surgery.getAssistant2Id());
|
||||
userIds.add(surgery.getAssistant2Id());
|
||||
}
|
||||
if (surgery.getScrubNurseId() != null) {
|
||||
practitionerIds.add(surgery.getScrubNurseId());
|
||||
userIds.add(surgery.getScrubNurseId());
|
||||
}
|
||||
if (surgery.getApplyDoctorId() != null) {
|
||||
practitionerIds.add(surgery.getApplyDoctorId());
|
||||
userIds.add(surgery.getApplyDoctorId());
|
||||
}
|
||||
|
||||
// 收集Organization IDs
|
||||
if (surgery.getOrgId() != null) orgIds.add(surgery.getOrgId());
|
||||
@@ -558,69 +593,151 @@ public class SurgeryAppServiceImpl implements ISurgeryAppService {
|
||||
// 批量查询并缓存结果
|
||||
Map<Long, String> practitionerNameMap = new HashMap<>();
|
||||
Map<Long, String> orgNameMap = new HashMap<>();
|
||||
Map<Long, String> userNameMap = new HashMap<>(); // 从sys_user查询的名称
|
||||
|
||||
// 批量查询Practitioner
|
||||
if (!practitionerIds.isEmpty()) {
|
||||
try {
|
||||
List<com.openhis.administration.domain.Practitioner> practitioners = practitionerService.listByIds(practitionerIds);
|
||||
for (com.openhis.administration.domain.Practitioner p : practitioners) {
|
||||
if (p.getName() != null && !p.getName().isEmpty()) {
|
||||
practitionerNameMap.put(p.getId(), p.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询Practitioner名称失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 批量查询SysUser (作为备选) - 使用逐个查询
|
||||
if (!userIds.isEmpty()) {
|
||||
try {
|
||||
for (Long userId : userIds) {
|
||||
SysUser u = sysUserService.selectUserById(userId);
|
||||
if (u != null) {
|
||||
String userName = u.getNickName() != null && !u.getNickName().isEmpty()
|
||||
? u.getNickName()
|
||||
: u.getUserName();
|
||||
if (userName != null && !userName.isEmpty()) {
|
||||
userNameMap.put(u.getUserId(), userName);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询SysUser名称失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 批量查询Organization
|
||||
if (!orgIds.isEmpty()) {
|
||||
try {
|
||||
List<Organization> orgs = organizationService.listByIds(orgIds);
|
||||
for (Organization o : orgs) {
|
||||
if (o.getName() != null && !o.getName().isEmpty()) {
|
||||
orgNameMap.put(o.getId(), o.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询Organization名称失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 填充患者姓名
|
||||
if (surgery.getPatientId() != null && surgery.getPatientName() == null) {
|
||||
try {
|
||||
Patient patient = patientService.getById(surgery.getPatientId());
|
||||
if (patient != null) {
|
||||
surgery.setPatientName(patient.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询患者名称失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 使用缓存填充名称
|
||||
// 填充医生名称 - 优先使用practitioner,如果不存在则使用sys_user
|
||||
if (surgery.getMainSurgeonId() != null && surgery.getMainSurgeonName() == null) {
|
||||
surgery.setMainSurgeonName(practitionerNameMap.get(surgery.getMainSurgeonId()));
|
||||
String name = practitionerNameMap.get(surgery.getMainSurgeonId());
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = userNameMap.get(surgery.getMainSurgeonId());
|
||||
}
|
||||
if (name != null && !name.isEmpty()) {
|
||||
surgery.setMainSurgeonName(name);
|
||||
}
|
||||
}
|
||||
if (surgery.getAnesthetistId() != null && surgery.getAnesthetistName() == null) {
|
||||
surgery.setAnesthetistName(practitionerNameMap.get(surgery.getAnesthetistId()));
|
||||
String name = practitionerNameMap.get(surgery.getAnesthetistId());
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = userNameMap.get(surgery.getAnesthetistId());
|
||||
}
|
||||
if (name != null && !name.isEmpty()) {
|
||||
surgery.setAnesthetistName(name);
|
||||
}
|
||||
}
|
||||
if (surgery.getAssistant1Id() != null && surgery.getAssistant1Name() == null) {
|
||||
surgery.setAssistant1Name(practitionerNameMap.get(surgery.getAssistant1Id()));
|
||||
String name = practitionerNameMap.get(surgery.getAssistant1Id());
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = userNameMap.get(surgery.getAssistant1Id());
|
||||
}
|
||||
if (name != null && !name.isEmpty()) {
|
||||
surgery.setAssistant1Name(name);
|
||||
}
|
||||
}
|
||||
if (surgery.getAssistant2Id() != null && surgery.getAssistant2Name() == null) {
|
||||
surgery.setAssistant2Name(practitionerNameMap.get(surgery.getAssistant2Id()));
|
||||
String name = practitionerNameMap.get(surgery.getAssistant2Id());
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = userNameMap.get(surgery.getAssistant2Id());
|
||||
}
|
||||
if (name != null && !name.isEmpty()) {
|
||||
surgery.setAssistant2Name(name);
|
||||
}
|
||||
}
|
||||
if (surgery.getScrubNurseId() != null && surgery.getScrubNurseName() == null) {
|
||||
surgery.setScrubNurseName(practitionerNameMap.get(surgery.getScrubNurseId()));
|
||||
String name = practitionerNameMap.get(surgery.getScrubNurseId());
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = userNameMap.get(surgery.getScrubNurseId());
|
||||
}
|
||||
if (name != null && !name.isEmpty()) {
|
||||
surgery.setScrubNurseName(name);
|
||||
}
|
||||
}
|
||||
if (surgery.getApplyDoctorId() != null && surgery.getApplyDoctorName() == null) {
|
||||
surgery.setApplyDoctorName(practitionerNameMap.get(surgery.getApplyDoctorId()));
|
||||
String name = practitionerNameMap.get(surgery.getApplyDoctorId());
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = userNameMap.get(surgery.getApplyDoctorId());
|
||||
}
|
||||
if (name != null && !name.isEmpty()) {
|
||||
surgery.setApplyDoctorName(name);
|
||||
}
|
||||
}
|
||||
|
||||
// 填充手术室名称
|
||||
if (surgery.getOperatingRoomId() != null && surgery.getOperatingRoomName() == null) {
|
||||
try {
|
||||
OperatingRoom operatingRoom = operatingRoomService.getById(surgery.getOperatingRoomId());
|
||||
if (operatingRoom != null) {
|
||||
surgery.setOperatingRoomName(operatingRoom.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询手术室名称失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 使用缓存填充组织名称
|
||||
if (surgery.getOrgId() != null && surgery.getOrgName() == null) {
|
||||
surgery.setOrgName(orgNameMap.get(surgery.getOrgId()));
|
||||
String name = orgNameMap.get(surgery.getOrgId());
|
||||
if (name != null && !name.isEmpty()) {
|
||||
surgery.setOrgName(name);
|
||||
}
|
||||
}
|
||||
if (surgery.getApplyDeptId() != null && surgery.getApplyDeptName() == null) {
|
||||
surgery.setApplyDeptName(orgNameMap.get(surgery.getApplyDeptId()));
|
||||
String name = orgNameMap.get(surgery.getApplyDeptId());
|
||||
if (name != null && !name.isEmpty()) {
|
||||
surgery.setApplyDeptName(name);
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("填充手术名称字段完成 - patientName: {}, mainSurgeonName: {}, orgName: {}",
|
||||
surgery.getPatientName(), surgery.getMainSurgeonName(), surgery.getOrgName());
|
||||
log.debug("填充手术名称字段完成 - patientName: {}, mainSurgeonName: {}, applyDeptName: {}",
|
||||
surgery.getPatientName(), surgery.getMainSurgeonName(), surgery.getApplyDeptName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package com.openhis.web.clinicalmanage.appservice.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.core.common.core.domain.model.LoginUser;
|
||||
import com.core.common.utils.SecurityUtils;
|
||||
import com.openhis.administration.domain.Patient;
|
||||
import com.openhis.administration.service.IOrganizationService;
|
||||
import com.openhis.administration.service.IPatientService;
|
||||
import com.openhis.clinical.domain.Surgery;
|
||||
import com.openhis.clinical.service.ISurgeryService;
|
||||
import com.openhis.surgicalschedule.domain.OpSchedule;
|
||||
import com.openhis.surgicalschedule.service.IOpScheduleService;
|
||||
import com.openhis.web.clinicalmanage.appservice.ISurgicalScheduleAppService;
|
||||
@@ -29,6 +33,8 @@ import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.core.framework.datasource.DynamicDataSourceContextHolder.log;
|
||||
|
||||
/**
|
||||
* 手术安排业务层实现类
|
||||
*
|
||||
@@ -47,6 +53,15 @@ public class SurgicalScheduleAppServiceImpl implements ISurgicalScheduleAppServi
|
||||
@Resource
|
||||
private SurgicalScheduleAppMapper surgicalScheduleAppMapper;
|
||||
|
||||
@Resource
|
||||
private ISurgeryService surgeryService;
|
||||
|
||||
@Resource
|
||||
private com.openhis.administration.service.IOrganizationService organizationService;
|
||||
|
||||
@Resource
|
||||
private com.core.system.service.ISysUserService sysUserService;
|
||||
|
||||
|
||||
@Resource
|
||||
private RequestFormManageAppMapper requestFormManageAppMapper;
|
||||
@@ -94,14 +109,32 @@ public class SurgicalScheduleAppServiceImpl implements ISurgicalScheduleAppServi
|
||||
return R.fail("患者信息不存在");
|
||||
}
|
||||
}
|
||||
//校验该时段内手术间是否被占用
|
||||
LocalDateTime scheduleDate = opCreateScheduleDto.getEntryTime();//入室时间
|
||||
String roomCode = opCreateScheduleDto.getRoomCode();//手术室编号
|
||||
|
||||
// 校验是否重复手术安排(必须在校验手术间占用之前执行,确保能正确返回重复错误)
|
||||
// 同一患者 + 同一手术单号 + 同一手术名称 只能有一条有效安排记录
|
||||
if (opCreateScheduleDto.getPatientId() != null
|
||||
&& opCreateScheduleDto.getOperCode() != null && !opCreateScheduleDto.getOperCode().isEmpty()
|
||||
&& opCreateScheduleDto.getOperName() != null && !opCreateScheduleDto.getOperName().isEmpty()) {
|
||||
Boolean existsDuplicate = surgicalScheduleAppMapper.existsDuplicateSchedule(
|
||||
opCreateScheduleDto.getPatientId(),
|
||||
opCreateScheduleDto.getOperCode(),
|
||||
opCreateScheduleDto.getOperName()
|
||||
);
|
||||
if (existsDuplicate != null && existsDuplicate) {
|
||||
return R.fail("该患者此手术单号已存在手术安排,请勿重复提交");
|
||||
}
|
||||
}
|
||||
|
||||
// 校验该时段内手术间是否被占用
|
||||
LocalDateTime startTime = opCreateScheduleDto.getEntryTime();//入室时间
|
||||
LocalDateTime endTime = opCreateScheduleDto.getEndTime();//手术结束时间
|
||||
Boolean scheduleConflict = surgicalScheduleAppMapper.isScheduleConflict(scheduleDate, endTime, roomCode);
|
||||
if (scheduleConflict) {
|
||||
String roomCode = opCreateScheduleDto.getRoomCode();//手术室编号
|
||||
if (startTime != null && endTime != null && roomCode != null && !roomCode.isEmpty()) {
|
||||
Boolean scheduleConflict = surgicalScheduleAppMapper.isScheduleConflict(startTime, endTime, roomCode);
|
||||
if (scheduleConflict != null && scheduleConflict) {
|
||||
return R.fail("该时段内手术间被占用");
|
||||
}
|
||||
}
|
||||
|
||||
LoginUser loginUser = new LoginUser();
|
||||
//获取当前登录用户信息
|
||||
@@ -165,12 +198,34 @@ public class SurgicalScheduleAppServiceImpl implements ISurgicalScheduleAppServi
|
||||
|
||||
// 保存手术安排
|
||||
boolean saved = opScheduleService.save(opSchedule);
|
||||
//修改申请单状态为已排期
|
||||
|
||||
if (!saved) {
|
||||
return R.fail("新增手术安排失败");
|
||||
}
|
||||
|
||||
// Bug #247 修复:更新手术申请单状态为已排期 (1)
|
||||
if (opCreateScheduleDto.getApplyId() != null) {
|
||||
try {
|
||||
// 通过手术单号查找手术申请记录并更新状态
|
||||
LambdaQueryWrapper<com.openhis.clinical.domain.Surgery> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(com.openhis.clinical.domain.Surgery::getSurgeryNo, opSchedule.getOperCode())
|
||||
.eq(com.openhis.clinical.domain.Surgery::getDeleteFlag, "0");
|
||||
com.openhis.clinical.domain.Surgery surgery = surgeryService.getOne(queryWrapper);
|
||||
if (surgery != null) {
|
||||
surgery.setStatusEnum(1); // 1 = 已排期
|
||||
surgery.setUpdateTime(new Date());
|
||||
|
||||
// 填充缺失的申请科室和主刀医生名称
|
||||
fillSurgeryMissingNames(surgery);
|
||||
|
||||
surgeryService.updateById(surgery);
|
||||
log.info("更新手术申请单状态为已排期 - surgeryNo: {}, surgeryId: {}", opSchedule.getOperCode(), surgery.getId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新手术申请单状态失败 - operCode: {}", opSchedule.getOperCode(), e);
|
||||
// 状态更新失败不影响主流程,只记录日志
|
||||
}
|
||||
}
|
||||
|
||||
return R.ok("新增手术安排成功");
|
||||
}
|
||||
|
||||
@@ -316,7 +371,7 @@ public class SurgicalScheduleAppServiceImpl implements ISurgicalScheduleAppServi
|
||||
index, // 序号从1开始
|
||||
schedule.getOrgName() != null ? schedule.getOrgName() : "",
|
||||
schedule.getPatientName() != null ? schedule.getPatientName() : "",
|
||||
schedule.getVisitId() != null ? schedule.getVisitId().toString() : "",
|
||||
schedule.getIdentifierNo() != null ? schedule.getIdentifierNo() : "",
|
||||
schedule.getOperCode() != null ? schedule.getOperCode() : "",
|
||||
schedule.getOperName() != null ? schedule.getOperName() : "",
|
||||
schedule.getApplyDeptName() != null ? schedule.getApplyDeptName() : "",
|
||||
@@ -369,10 +424,84 @@ public class SurgicalScheduleAppServiceImpl implements ISurgicalScheduleAppServi
|
||||
/**
|
||||
* 格式化安排时间
|
||||
*/
|
||||
private String formatScheduleDate(LocalDate scheduleDate) {
|
||||
private String formatScheduleDate(LocalDateTime scheduleDate) {
|
||||
if (scheduleDate == null) return "";
|
||||
|
||||
// 格式化为 yyyy-MM-dd
|
||||
return scheduleDate.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
// 格式化为 yyyy-MM-dd HH:mm:ss
|
||||
return scheduleDate.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充手术申请中缺失的名称字段
|
||||
* 在创建手术安排时调用,确保关联的cli_surgery表中的名称字段有值
|
||||
*
|
||||
* @param surgery 手术申请对象
|
||||
*/
|
||||
private void fillSurgeryMissingNames(com.openhis.clinical.domain.Surgery surgery) {
|
||||
// 填充申请科室名称
|
||||
if ((surgery.getApplyDeptName() == null || surgery.getApplyDeptName().isEmpty())
|
||||
&& surgery.getApplyDeptId() != null) {
|
||||
try {
|
||||
com.openhis.administration.domain.Organization org = organizationService.getById(surgery.getApplyDeptId());
|
||||
if (org != null && org.getName() != null) {
|
||||
surgery.setApplyDeptName(org.getName());
|
||||
log.info("填充申请科室名称 - surgeryId: {}, deptId: {}, deptName: {}",
|
||||
surgery.getId(), surgery.getApplyDeptId(), org.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询申请科室名称失败 - deptId: {}, error: {}", surgery.getApplyDeptId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 填充主刀医生名称
|
||||
if ((surgery.getMainSurgeonName() == null || surgery.getMainSurgeonName().isEmpty())
|
||||
&& surgery.getMainSurgeonId() != null) {
|
||||
try {
|
||||
com.core.common.core.domain.entity.SysUser user = sysUserService.selectUserById(surgery.getMainSurgeonId());
|
||||
if (user != null) {
|
||||
String surgeonName = user.getNickName() != null && !user.getNickName().isEmpty()
|
||||
? user.getNickName()
|
||||
: user.getUserName();
|
||||
if (surgeonName != null) {
|
||||
surgery.setMainSurgeonName(surgeonName);
|
||||
log.info("填充主刀医生名称 - surgeryId: {}, surgeonId: {}, surgeonName: {}",
|
||||
surgery.getId(), surgery.getMainSurgeonId(), surgeonName);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询主刀医生名称失败 - surgeonId: {}, error: {}", surgery.getMainSurgeonId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 填充麻醉医生名称
|
||||
if ((surgery.getAnesthetistName() == null || surgery.getAnesthetistName().isEmpty())
|
||||
&& surgery.getAnesthetistId() != null) {
|
||||
try {
|
||||
com.core.common.core.domain.entity.SysUser user = sysUserService.selectUserById(surgery.getAnesthetistId());
|
||||
if (user != null) {
|
||||
String anesthetistName = user.getNickName() != null && !user.getNickName().isEmpty()
|
||||
? user.getNickName()
|
||||
: user.getUserName();
|
||||
if (anesthetistName != null) {
|
||||
surgery.setAnesthetistName(anesthetistName);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询麻醉医生名称失败 - anesthetistId: {}, error: {}", surgery.getAnesthetistId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 填充执行科室名称
|
||||
if ((surgery.getOrgName() == null || surgery.getOrgName().isEmpty())
|
||||
&& surgery.getOrgId() != null) {
|
||||
try {
|
||||
com.openhis.administration.domain.Organization org = organizationService.getById(surgery.getOrgId());
|
||||
if (org != null && org.getName() != null) {
|
||||
surgery.setOrgName(org.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询执行科室名称失败 - orgId: {}, error: {}", surgery.getOrgId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@ public class OpCreateScheduleDto {
|
||||
*/
|
||||
private Long visitId;
|
||||
|
||||
/**
|
||||
* 就诊卡号
|
||||
*/
|
||||
private String identifierNo;
|
||||
|
||||
/**
|
||||
* 手术编码
|
||||
*/
|
||||
@@ -45,9 +50,10 @@ public class OpCreateScheduleDto {
|
||||
private String postoperativeDiagnosis;
|
||||
|
||||
/**
|
||||
* 手术安排日期
|
||||
* 手术安排日期时间
|
||||
*/
|
||||
private LocalDate scheduleDate;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime scheduleDate;
|
||||
|
||||
/**
|
||||
* 手术台次序号
|
||||
@@ -82,11 +88,13 @@ public class OpCreateScheduleDto {
|
||||
/**
|
||||
* 入院时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime admissionTime;
|
||||
|
||||
/**
|
||||
* 入手术室时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime entryTime;
|
||||
|
||||
/**
|
||||
@@ -167,21 +175,25 @@ public class OpCreateScheduleDto {
|
||||
/**
|
||||
* 手术开始时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 手术结束时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 麻醉开始时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime anesStart;
|
||||
|
||||
/**
|
||||
* 麻醉结束时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime anesEnd;
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.openhis.surgicalschedule.domain.OpSchedule;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@@ -18,6 +19,20 @@ import java.time.LocalDate;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class OpScheduleDto extends OpSchedule {
|
||||
|
||||
/**
|
||||
* 手术安排日期开始(查询用)
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate scheduleDateStart;
|
||||
|
||||
/**
|
||||
* 手术安排日期结束(查询用)
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate scheduleDateEnd;
|
||||
|
||||
/**
|
||||
* 患者姓名
|
||||
*/
|
||||
@@ -28,6 +43,11 @@ public class OpScheduleDto extends OpSchedule {
|
||||
*/
|
||||
private Long encounterId;
|
||||
|
||||
/**
|
||||
* 就诊卡号
|
||||
*/
|
||||
private String patientCardNo;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
|
||||
@@ -45,6 +45,9 @@ public class SurgeryDto {
|
||||
/** 就诊流水号 */
|
||||
private String encounterNo;
|
||||
|
||||
/** 就诊卡号 */
|
||||
private String patientCardNo;
|
||||
|
||||
/** 申请医生ID */
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long applyDoctorId;
|
||||
|
||||
@@ -58,4 +58,14 @@ public interface SurgicalScheduleAppMapper {
|
||||
* @return 是否存在冲突的手术安排
|
||||
*/
|
||||
Boolean isScheduleConflict(LocalDateTime startTime, LocalDateTime endTime, String surgeryRoomId);
|
||||
|
||||
/**
|
||||
* 检查是否存在重复的手术安排
|
||||
*
|
||||
* @param patientId 患者ID
|
||||
* @param operCode 手术单号
|
||||
* @param operName 手术名称
|
||||
* @return 是否存在重复记录
|
||||
*/
|
||||
Boolean existsDuplicateSchedule(@Param("patientId") Long patientId, @Param("operCode") String operCode, @Param("operName") String operName);
|
||||
}
|
||||
|
||||
@@ -149,6 +149,14 @@ public interface IConsultationAppService {
|
||||
* @return 会诊意见列表
|
||||
*/
|
||||
List<ConsultationOpinionDto> getConsultationOpinions(String consultationId);
|
||||
|
||||
/**
|
||||
* 根据ID查询会诊申请详情
|
||||
*
|
||||
* @param id 会诊申请ID
|
||||
* @return 会诊申请详情
|
||||
*/
|
||||
ConsultationRequestDto getConsultationById(Long id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -186,6 +186,11 @@ public class ConsultationAppServiceImpl implements IConsultationAppService {
|
||||
wrapper.like(ConsultationRequest::getPatientName, dto.getPatientName());
|
||||
}
|
||||
|
||||
// 会诊ID查询(支持模糊匹配)
|
||||
if (StringUtils.hasText(dto.getConsultationId())) {
|
||||
wrapper.like(ConsultationRequest::getConsultationId, dto.getConsultationId());
|
||||
}
|
||||
|
||||
// 按创建时间倒序排列
|
||||
wrapper.orderByDesc(ConsultationRequest::getConsultationRequestDate);
|
||||
|
||||
@@ -240,6 +245,11 @@ public class ConsultationAppServiceImpl implements IConsultationAppService {
|
||||
wrapper.like(ConsultationRequest::getPatientName, dto.getPatientName());
|
||||
}
|
||||
|
||||
// 会诊ID查询(支持模糊匹配)
|
||||
if (StringUtils.hasText(dto.getConsultationId())) {
|
||||
wrapper.like(ConsultationRequest::getConsultationId, dto.getConsultationId());
|
||||
}
|
||||
|
||||
// 按创建时间倒序排列
|
||||
wrapper.orderByDesc(ConsultationRequest::getConsultationRequestDate);
|
||||
|
||||
@@ -435,7 +445,15 @@ public class ConsultationAppServiceImpl implements IConsultationAppService {
|
||||
}
|
||||
|
||||
// 判断是"取消提交"还是"作废"
|
||||
if ("取消提交".equals(cancelReason) && ConsultationStatusEnum.SUBMITTED.getCode().equals(entity.getConsultationStatus())) {
|
||||
if ("取消提交".equals(cancelReason)) {
|
||||
// 状态校验:禁止已确认 (20)、已签名 (30)、已完成 (40) 的会诊申请取消提交
|
||||
if (entity.getConsultationStatus() >= ConsultationStatusEnum.CONFIRMED.getCode()) {
|
||||
throw new IllegalArgumentException("当前状态不允许取消提交,只有已提交状态的会诊申请才能取消提交");
|
||||
}
|
||||
// 只有状态为 10(已提交) 才允许取消提交
|
||||
if (!ConsultationStatusEnum.SUBMITTED.getCode().equals(entity.getConsultationStatus())) {
|
||||
throw new IllegalArgumentException("只有已提交状态的会诊申请才能取消提交");
|
||||
}
|
||||
// 取消提交:将状态从"已提交"改回"新开"
|
||||
entity.setConsultationStatus(ConsultationStatusEnum.NEW.getCode());
|
||||
entity.setConfirmingPhysician(null);
|
||||
@@ -447,7 +465,13 @@ public class ConsultationAppServiceImpl implements IConsultationAppService {
|
||||
updateServiceRequestStatus(entity.getOrderId(), RequestStatus.DRAFT.getValue());
|
||||
|
||||
} else {
|
||||
// 作废:将状态改为"已取消"
|
||||
// 作废:状态校验 - 已确认(20)、已签名(30)、已完成(40) 状态禁止作废
|
||||
ConsultationStatusEnum currentStatus = ConsultationStatusEnum.getByCode(entity.getConsultationStatus());
|
||||
if (currentStatus != null && !currentStatus.canCancel()) {
|
||||
throw new IllegalArgumentException("当前状态【" + currentStatus.getDescription() + "】不允许作废,只有新开或已提交状态的会诊申请才能作废");
|
||||
}
|
||||
|
||||
// 将状态改为"已取消"
|
||||
entity.setConsultationStatus(CANCELLED.getCode());
|
||||
entity.setCancelReason(cancelReason);
|
||||
entity.setCancelNatureDate(new Date());
|
||||
@@ -717,38 +741,64 @@ public class ConsultationAppServiceImpl implements IConsultationAppService {
|
||||
|
||||
dto.setInvitedList(invitedDtoList);
|
||||
|
||||
// 🎯 如果会诊已完成或已签名,填充会诊记录信息(从已签名的医生中获取)
|
||||
|
||||
// 🎯 如果会诊已确认、已签名或已完成,填充会诊记录信息(从会诊确认表中获取)
|
||||
// 会诊状态:20=已确认,30=已签名,40=已完成
|
||||
if (entity.getConsultationStatus() != null &&
|
||||
(entity.getConsultationStatus() == ConsultationStatusEnum.SIGNED.getCode() ||
|
||||
entity.getConsultationStatus() == ConsultationStatusEnum.COMPLETED.getCode())) {
|
||||
entity.getConsultationStatus() >= ConsultationStatusEnum.CONFIRMED.getCode()) {
|
||||
|
||||
// 查询会诊确认记录
|
||||
LambdaQueryWrapper<ConsultationConfirmation> confirmWrapper = new LambdaQueryWrapper<>();
|
||||
confirmWrapper.eq(ConsultationConfirmation::getConsultationRequestId, entity.getId());
|
||||
ConsultationConfirmation confirmation = consultationConfirmationMapper.selectOne(confirmWrapper);
|
||||
|
||||
// 查询所有已确认和已签名的医生(invited_status >= 2)
|
||||
List<ConsultationInvited> confirmedAndSignedPhysicians = invitedList.stream()
|
||||
.filter(inv -> inv.getInvitedStatus() != null && inv.getInvitedStatus() >= 2)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 查询所有已签名的医生(invited_status >= 3)
|
||||
List<ConsultationInvited> signedPhysicians = invitedList.stream()
|
||||
.filter(inv -> inv.getInvitedStatus() != null && inv.getInvitedStatus() >= 3)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!signedPhysicians.isEmpty()) {
|
||||
// 1. 会诊邀请参加医师:拼接所有已签名医生的"科室-姓名"
|
||||
String invitedPhysiciansText = signedPhysicians.stream()
|
||||
if (confirmation != null) {
|
||||
// 1. 会诊确认参加医师:优先从确认表的confirming_physicians字段取值
|
||||
if (StringUtils.hasText(confirmation.getConfirmingPhysicians())) {
|
||||
dto.setInvitedPhysiciansText(confirmation.getConfirmingPhysicians());
|
||||
} else if (!confirmedAndSignedPhysicians.isEmpty()) {
|
||||
// 备用:从invitedList拼接
|
||||
String invitedPhysiciansText = confirmedAndSignedPhysicians.stream()
|
||||
.map(inv -> inv.getInvitedDepartmentName() + "-" + inv.getInvitedPhysicianName())
|
||||
.collect(Collectors.joining("、"));
|
||||
dto.setInvitedPhysiciansText(invitedPhysiciansText);
|
||||
}
|
||||
|
||||
// 2. 会诊意见:汇总所有已签名医生的意见
|
||||
String consultationOpinion = signedPhysicians.stream()
|
||||
// 2. 会诊意见:优先从确认表取值
|
||||
if (StringUtils.hasText(confirmation.getConsultationOpinion())) {
|
||||
dto.setConsultationOpinion(confirmation.getConsultationOpinion());
|
||||
} else if (!confirmedAndSignedPhysicians.isEmpty()) {
|
||||
// 备用:从invitedList汇总
|
||||
String consultationOpinion = confirmedAndSignedPhysicians.stream()
|
||||
.filter(inv -> StringUtils.hasText(inv.getConfirmOpinion()))
|
||||
.map(ConsultationInvited::getConfirmOpinion)
|
||||
.collect(Collectors.joining("\n"));
|
||||
dto.setConsultationOpinion(consultationOpinion);
|
||||
}
|
||||
|
||||
// 3. 所属医生、代表科室、签名医生、签名时间:使用第一个签名的医生
|
||||
ConsultationInvited firstSigned = signedPhysicians.get(0);
|
||||
dto.setAttendingPhysician(firstSigned.getInvitedPhysicianName());
|
||||
dto.setRepresentDepartment(firstSigned.getInvitedDepartmentName());
|
||||
dto.setSignPhysician(firstSigned.getInvitedPhysicianName());
|
||||
dto.setSignTime(firstSigned.getSignatureTime());
|
||||
// 3. 签名医生、签名时间:从确认表取值
|
||||
dto.setSignPhysician(confirmation.getSignature());
|
||||
dto.setSignTime(confirmation.getSignatureDate());
|
||||
}
|
||||
|
||||
log.info("填充会诊记录信息,已签名医生数:{}", signedPhysicians.size());
|
||||
// 4. 所属医生、代表科室:使用第一个确认的医生(向后兼容)
|
||||
if (!confirmedAndSignedPhysicians.isEmpty()) {
|
||||
ConsultationInvited firstConfirmed = confirmedAndSignedPhysicians.get(0);
|
||||
dto.setAttendingPhysician(firstConfirmed.getInvitedPhysicianName());
|
||||
dto.setRepresentDepartment(firstConfirmed.getInvitedDepartmentName());
|
||||
|
||||
log.info("填充会诊记录信息,已确认和已签名医生数:{},已签名医生数:{}",
|
||||
confirmedAndSignedPhysicians.size(), signedPhysicians.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1783,5 +1833,26 @@ public class ConsultationAppServiceImpl implements IConsultationAppService {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsultationRequestDto getConsultationById(Long id) {
|
||||
try {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("会诊申请ID不能为空");
|
||||
}
|
||||
|
||||
// 1. 查询会诊申请
|
||||
ConsultationRequest request = consultationRequestMapper.selectById(id);
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("会诊申请不存在,ID: " + id);
|
||||
}
|
||||
|
||||
// 2. 转换为DTO并返回
|
||||
return convertToDto(request);
|
||||
} catch (Exception e) {
|
||||
log.error("查询会诊申请详情失败", e);
|
||||
throw new RuntimeException("查询会诊申请详情失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -302,5 +302,21 @@ public class ConsultationController {
|
||||
return R.fail("获取会诊意见列表失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询会诊申请详情
|
||||
*/
|
||||
@ApiOperation("根据ID查询会诊申请详情")
|
||||
@GetMapping("/detail/{id}")
|
||||
public R<ConsultationRequestDto> getConsultationById(
|
||||
@ApiParam("会诊申请ID") @PathVariable Long id) {
|
||||
try {
|
||||
ConsultationRequestDto detail = consultationAppService.getConsultationById(id);
|
||||
return R.ok(detail);
|
||||
} catch (Exception e) {
|
||||
log.error("查询会诊申请详情失败", e);
|
||||
return R.fail("查询会诊申请详情失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,10 +76,12 @@ public enum ConsultationStatusEnum {
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否可以取消
|
||||
* 判断是否可以取消/作废
|
||||
* 只有新开(0)和已提交(10)状态可以作废
|
||||
* 已确认(20)、已签名(30)、已完成(40)状态禁止作废
|
||||
*/
|
||||
public boolean canCancel() {
|
||||
return this == NEW || this == SUBMITTED || this == CONFIRMED;
|
||||
return this == NEW || this == SUBMITTED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,6 @@ public class DiagTreatMAppServiceImpl implements IDiagTreatMAppService {
|
||||
private IOperationRecordService operationRecordService;
|
||||
@Resource
|
||||
private IServiceRequestService serviceRequestService;
|
||||
|
||||
/**
|
||||
* 诊疗目录初期查询
|
||||
*
|
||||
@@ -186,6 +185,14 @@ public class DiagTreatMAppServiceImpl implements IDiagTreatMAppService {
|
||||
public R<?> getDiseaseTreatmentPage(DiagnosisTreatmentSelParam DiagnosisTreatmentSelParam, String searchKey,
|
||||
Integer pageNo, Integer pageSize, HttpServletRequest request) {
|
||||
|
||||
// 如果没有指定状态,默认只查询启用状态(status_enum=2),避免显示未启用的项目导致保存失败
|
||||
if (DiagnosisTreatmentSelParam == null) {
|
||||
DiagnosisTreatmentSelParam = new DiagnosisTreatmentSelParam();
|
||||
}
|
||||
if (DiagnosisTreatmentSelParam.getStatusEnum() == null) {
|
||||
DiagnosisTreatmentSelParam.setStatusEnum(PublicationStatus.ACTIVE.getValue());
|
||||
}
|
||||
|
||||
// 临时保存ybType值并从参数对象中移除,避免HisQueryUtils构建yb_type条件
|
||||
String ybTypeValue = null;
|
||||
if (DiagnosisTreatmentSelParam != null && StringUtils.isNotEmpty(DiagnosisTreatmentSelParam.getYbType())) {
|
||||
@@ -232,9 +239,8 @@ public class DiagTreatMAppServiceImpl implements IDiagTreatMAppService {
|
||||
DiagnosisTreatmentSelParam.setPricingFlag(pricingFlagValue);
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
IPage<DiagnosisTreatmentDto> diseaseTreatmentPage
|
||||
= activityDefinitionManageMapper.getDiseaseTreatmentPage(new Page<DiagnosisTreatmentDto>(pageNo, pageSize), queryWrapper);
|
||||
= activityDefinitionManageMapper.getDiseaseTreatmentPage(new Page<>(pageNo, pageSize), queryWrapper);
|
||||
|
||||
diseaseTreatmentPage.getRecords().forEach(e -> {
|
||||
// 医保标记枚举类回显赋值
|
||||
@@ -439,24 +445,17 @@ public class DiagTreatMAppServiceImpl implements IDiagTreatMAppService {
|
||||
*/
|
||||
@Override
|
||||
public R<?> editDiseaseTreatmentStop(List<Long> ids) {
|
||||
|
||||
List<ActivityDefinition> ActivityDefinitionList = new CopyOnWriteArrayList<>();
|
||||
|
||||
// 取得更新值
|
||||
for (Long detail : ids) {
|
||||
ActivityDefinition ActivityDefinition = new ActivityDefinition();
|
||||
ActivityDefinition.setId(detail);
|
||||
ActivityDefinition.setStatusEnum(PublicationStatus.RETIRED.getValue());
|
||||
ActivityDefinitionList.add(ActivityDefinition);
|
||||
List<ActivityDefinition> actList = new CopyOnWriteArrayList<>();
|
||||
for (Long id : ids) {
|
||||
ActivityDefinition act = new ActivityDefinition();
|
||||
act.setId(id);
|
||||
act.setStatusEnum(PublicationStatus.RETIRED.getValue());
|
||||
actList.add(act);
|
||||
}
|
||||
// 插入操作记录
|
||||
operationRecordService.addIdsOperationRecord(DbOpType.STOP.getCode(),
|
||||
CommonConstants.TableName.WOR_ACTIVITY_DEFINITION, ids);
|
||||
// 更新诊疗信息
|
||||
return activityDefinitionService.updateBatchById(ActivityDefinitionList)
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"诊疗目录"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null));
|
||||
|
||||
activityDefinitionService.updateBatchById(actList);
|
||||
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"\u8bca\u7597\u76ee\u5f55"}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,24 +466,17 @@ public class DiagTreatMAppServiceImpl implements IDiagTreatMAppService {
|
||||
*/
|
||||
@Override
|
||||
public R<?> editDiseaseTreatmentStart(List<Long> ids) {
|
||||
|
||||
List<ActivityDefinition> ActivityDefinitionList = new CopyOnWriteArrayList<>();
|
||||
|
||||
// 取得更新值
|
||||
for (Long detail : ids) {
|
||||
ActivityDefinition ActivityDefinition = new ActivityDefinition();
|
||||
ActivityDefinition.setId(detail);
|
||||
ActivityDefinition.setStatusEnum(PublicationStatus.ACTIVE.getValue());
|
||||
ActivityDefinitionList.add(ActivityDefinition);
|
||||
List<ActivityDefinition> actList = new CopyOnWriteArrayList<>();
|
||||
for (Long id : ids) {
|
||||
ActivityDefinition act = new ActivityDefinition();
|
||||
act.setId(id);
|
||||
act.setStatusEnum(PublicationStatus.ACTIVE.getValue());
|
||||
actList.add(act);
|
||||
}
|
||||
// 插入操作记录
|
||||
operationRecordService.addIdsOperationRecord(DbOpType.START.getCode(),
|
||||
CommonConstants.TableName.WOR_ACTIVITY_DEFINITION, ids);
|
||||
// 更新诊疗信息
|
||||
return activityDefinitionService.updateBatchById(ActivityDefinitionList)
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"诊疗目录"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null));
|
||||
|
||||
activityDefinitionService.updateBatchById(actList);
|
||||
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"诊疗目录"}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.openhis.web.datadictionary.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentDto;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验项目定义管理 Mapper(操作 lab_activity_definition 表)
|
||||
*/
|
||||
@Repository
|
||||
public interface LabActivityDefinitionManageMapper {
|
||||
|
||||
/**
|
||||
* 检验项目分页查询
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param queryWrapper 查询条件
|
||||
* @return 分页结果
|
||||
*/
|
||||
IPage<DiagnosisTreatmentDto> getLabActivityDefinitionPage(
|
||||
@Param("page") Page<DiagnosisTreatmentDto> page,
|
||||
@Param(Constants.WRAPPER) QueryWrapper<DiagnosisTreatmentDto> queryWrapper);
|
||||
|
||||
/**
|
||||
* 检验项目详情
|
||||
*
|
||||
* @param id 项目ID
|
||||
* @param tenantId 租户ID
|
||||
* @return 详情
|
||||
*/
|
||||
DiagnosisTreatmentDto getLabActivityDefinitionOne(@Param("id") Long id, @Param("tenantId") Integer tenantId);
|
||||
|
||||
/**
|
||||
* 检验项目下拉列表(轻量级)
|
||||
*
|
||||
* @param statusEnum 状态
|
||||
* @param tenantId 租户ID
|
||||
* @param searchKey 搜索关键词(可选)
|
||||
* @return 列表
|
||||
*/
|
||||
List<DiagnosisTreatmentDto> getLabActivityDefinitionSimpleList(
|
||||
@Param("statusEnum") Integer statusEnum,
|
||||
@Param("tenantId") Integer tenantId,
|
||||
@Param("searchKey") String searchKey);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public interface IDoctorStationAdviceAppService {
|
||||
*/
|
||||
IPage<AdviceBaseDto> getAdviceBaseInfo(AdviceBaseDto adviceBaseDto, String searchKey, Long locationId,
|
||||
List<Long> adviceDefinitionIdParamList, Long organizationId, Integer pageNo, Integer pageSize,
|
||||
Integer pricingFlag, List<Integer> adviceTypes, String orderPricing);
|
||||
Integer pricingFlag, List<Integer> adviceTypes, String orderPricing, String categoryCode);
|
||||
|
||||
/**
|
||||
* 查询医嘱绑定信息
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.openhis.common.constant.PromptMsgConstant;
|
||||
import com.openhis.common.enums.*;
|
||||
import com.openhis.common.utils.EnumUtils;
|
||||
import com.openhis.common.utils.HisQueryUtils;
|
||||
import com.openhis.medication.domain.MedicationDispense;
|
||||
import com.openhis.medication.domain.MedicationRequest;
|
||||
import com.openhis.medication.service.IMedicationDispenseService;
|
||||
import com.openhis.medication.service.IMedicationRequestService;
|
||||
@@ -44,6 +45,8 @@ import com.openhis.workflow.service.IActivityDefinitionService;
|
||||
import com.openhis.workflow.service.IDeviceDispenseService;
|
||||
import com.openhis.workflow.service.IDeviceRequestService;
|
||||
import com.openhis.workflow.service.IServiceRequestService;
|
||||
import com.openhis.workflow.domain.InventoryItem;
|
||||
import com.openhis.workflow.service.IInventoryItemService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -111,6 +114,9 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
@Resource
|
||||
IEncounterService iEncounterService;
|
||||
|
||||
@Resource
|
||||
IInventoryItemService inventoryItemService;
|
||||
|
||||
// 缓存 key 前缀
|
||||
private static final String ADVICE_BASE_INFO_CACHE_PREFIX = "advice:base:info:";
|
||||
// 缓存过期时间(小时)
|
||||
@@ -135,7 +141,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
@Override
|
||||
public IPage<AdviceBaseDto> getAdviceBaseInfo(AdviceBaseDto adviceBaseDto, String searchKey, Long locationId,
|
||||
List<Long> adviceDefinitionIdParamList, Long organizationId, Integer pageNo, Integer pageSize,
|
||||
Integer pricingFlag, List<Integer> adviceTypes, String orderPricing) {
|
||||
Integer pricingFlag, List<Integer> adviceTypes, String orderPricing, String categoryCode) {
|
||||
|
||||
// 生成缓存键,处理可能的null值
|
||||
String safeSearchKey = searchKey != null ? searchKey : "";
|
||||
@@ -203,7 +209,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
new Page<>(pageNo, pageSize), PublicationStatus.ACTIVE.getValue(), organizationId,
|
||||
CommonConstants.TableName.MED_MEDICATION_DEFINITION, CommonConstants.TableName.ADM_DEVICE_DEFINITION,
|
||||
CommonConstants.TableName.WOR_ACTIVITY_DEFINITION, pricingFlag, adviceDefinitionIdParamList,
|
||||
adviceTypes, searchKey,
|
||||
adviceTypes, searchKey, categoryCode,
|
||||
queryWrapper);
|
||||
List<AdviceBaseDto> adviceBaseDtoList = adviceBaseInfo.getRecords();
|
||||
|
||||
@@ -564,13 +570,15 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
// 耗材(前端adviceType=4,后端ItemType.DEVICE=2)
|
||||
List<AdviceSaveDto> deviceList = adviceSaveList.stream()
|
||||
.filter(e -> ItemType.DEVICE.getValue().equals(e.getAdviceType())
|
||||
|| e.getAdviceType() == 4) // 🔧 BugFix: 前端耗材类型值为4
|
||||
|| e.getAdviceType() == 4) // 前端耗材类型值为4
|
||||
.collect(Collectors.toList());
|
||||
// 诊疗活动(包括普通诊疗:前端adviceType=3,会诊:前端adviceType=5)
|
||||
|
||||
// 诊疗活动(前端adviceType=3诊疗、adviceType=5会诊、adviceType=6手术)
|
||||
List<AdviceSaveDto> activityList = adviceSaveList.stream()
|
||||
.filter(e -> ItemType.ACTIVITY.getValue().equals(e.getAdviceType())
|
||||
|| e.getAdviceType() == 3 // 🔧 BugFix: 前端诊疗类型值为3
|
||||
|| e.getAdviceType() == 5) // 🔧 BugFix: 前端会诊类型值为5
|
||||
|| e.getAdviceType() == 3 // 前端诊疗类型值为3
|
||||
|| e.getAdviceType() == 5 // 前端会诊类型值为5
|
||||
|| ItemType.SURGERY.getValue().equals(e.getAdviceType())) // 🔧 BugFix#318: 手术类型值为6
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 🔍 Debug日志: 记录分类结果
|
||||
@@ -599,11 +607,12 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
iDeviceDispenseService.deleteDeviceDispense(adviceSaveDto.getRequestId());
|
||||
}
|
||||
|
||||
// 🔧 Bug Fix: 跳过耗材的库存校验(耗材的库存校验逻辑不同)
|
||||
// 🔧 Bug Fix: 跳过耗材、诊疗、手术的库存校验
|
||||
List<AdviceSaveDto> needCheckList = adviceSaveList.stream()
|
||||
.filter(e -> !DbOpType.DELETE.getCode().equals(e.getDbOpType())
|
||||
&& !ItemType.ACTIVITY.getValue().equals(e.getAdviceType())
|
||||
&& !ItemType.DEVICE.getValue().equals(e.getAdviceType())) // 排除耗材
|
||||
&& !ItemType.DEVICE.getValue().equals(e.getAdviceType())
|
||||
&& !ItemType.SURGERY.getValue().equals(e.getAdviceType())) // 🔧 BugFix#318: 排除手术类型
|
||||
.collect(Collectors.toList());
|
||||
// 校验库存
|
||||
String tipRes = adviceUtils.checkInventory(needCheckList);
|
||||
@@ -641,11 +650,13 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
.collect(Collectors.toList());
|
||||
// 就诊id
|
||||
Long encounterId = adviceSaveList.get(0).getEncounterId();
|
||||
iChargeItemService.update(new LambdaUpdateWrapper<ChargeItem>()
|
||||
.set(ChargeItem::getStatusEnum, ChargeItemStatus.PLANNED.getValue())
|
||||
.eq(ChargeItem::getEncounterId, encounterId)
|
||||
.eq(ChargeItem::getStatusEnum, ChargeItemStatus.DRAFT.getValue())
|
||||
.in(ChargeItem::getServiceId, requestIds));
|
||||
|
||||
// 使用安全的更新方法,避免并发冲突
|
||||
iChargeItemService.updateChargeStatusByConditionSafe(
|
||||
encounterId,
|
||||
ChargeItemStatus.DRAFT.getValue(),
|
||||
ChargeItemStatus.PLANNED.getValue(),
|
||||
requestIds);
|
||||
}
|
||||
|
||||
// 数据变更后清理相关缓存
|
||||
@@ -737,6 +748,28 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
|
||||
List<String> medRequestIdList = new ArrayList<>();
|
||||
for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) {
|
||||
// 🔧 Bug Fix: 确保accountId不为null,与handleBoundDevices保持一致
|
||||
if (adviceSaveDto.getAccountId() == null) {
|
||||
// 尝试从患者就诊中获取默认账户ID(自费账户)
|
||||
Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId());
|
||||
if (selfAccount != null) {
|
||||
adviceSaveDto.setAccountId(selfAccount.getId());
|
||||
} else {
|
||||
// 自动创建自费账户
|
||||
Account newAccount = new Account();
|
||||
newAccount.setPatientId(adviceSaveDto.getPatientId());
|
||||
newAccount.setEncounterId(adviceSaveDto.getEncounterId());
|
||||
newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO);
|
||||
newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode());
|
||||
newAccount.setBalanceAmount(BigDecimal.ZERO);
|
||||
newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue());
|
||||
newAccount.setEncounterFlag(Whether.YES.getValue());
|
||||
newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo());
|
||||
Long newAccountId = iAccountService.saveAccountByRegister(newAccount);
|
||||
adviceSaveDto.setAccountId(newAccountId);
|
||||
}
|
||||
}
|
||||
|
||||
boolean firstTimeSave = false;// 第一次保存
|
||||
medicationRequest = new MedicationRequest();
|
||||
medicationRequest.setId(adviceSaveDto.getRequestId()); // 主键id
|
||||
@@ -905,7 +938,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
deviceAdviceDto.setAdviceTableName(CommonConstants.TableName.ADM_DEVICE_DEFINITION);
|
||||
IPage<AdviceBaseDto> devicePage = getAdviceBaseInfo(deviceAdviceDto, null, null, null,
|
||||
adviceSaveDto.getFounderOrgId(), 1, 1, Whether.NO.getValue(),
|
||||
List.of(ItemType.DEVICE.getValue()), null);
|
||||
List.of(ItemType.DEVICE.getValue()), null, null);
|
||||
|
||||
if (devicePage == null || devicePage.getRecords().isEmpty()) {
|
||||
log.warn("无法找到耗材定价信息: deviceDefId={}", boundDevice.getDevActId());
|
||||
@@ -941,7 +974,29 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
deviceChargeItem.setServiceId(deviceRequest.getId());
|
||||
deviceChargeItem.setProductTable(CommonConstants.TableName.ADM_DEVICE_DEFINITION);
|
||||
deviceChargeItem.setProductId(boundDevice.getDevActId());
|
||||
deviceChargeItem.setAccountId(adviceSaveDto.getAccountId());
|
||||
// 🔧 Bug Fix #281: 如果accountId为null,从就诊中获取账户ID,如果没有则自动创建
|
||||
Long deviceAccountId = adviceSaveDto.getAccountId();
|
||||
if (deviceAccountId == null) {
|
||||
// 尝试从患者就诊中获取默认账户ID(自费账户)
|
||||
Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId());
|
||||
if (selfAccount != null) {
|
||||
deviceAccountId = selfAccount.getId();
|
||||
} else {
|
||||
// 自动创建自费账户
|
||||
Account newAccount = new Account();
|
||||
newAccount.setPatientId(adviceSaveDto.getPatientId());
|
||||
newAccount.setEncounterId(adviceSaveDto.getEncounterId());
|
||||
newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO);
|
||||
newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode());
|
||||
newAccount.setBalanceAmount(BigDecimal.ZERO);
|
||||
newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue());
|
||||
newAccount.setEncounterFlag(Whether.YES.getValue());
|
||||
// 🔧 Bug Fix: 设置账户名称,避免数据库NOT NULL约束错误
|
||||
newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo());
|
||||
deviceAccountId = iAccountService.saveAccountByRegister(newAccount);
|
||||
}
|
||||
}
|
||||
deviceChargeItem.setAccountId(deviceAccountId);
|
||||
deviceChargeItem.setConditionId(adviceSaveDto.getConditionId());
|
||||
deviceChargeItem.setEncounterDiagnosisId(adviceSaveDto.getEncounterDiagnosisId());
|
||||
deviceChargeItem.setDispenseId(dispenseId);
|
||||
@@ -1060,6 +1115,28 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
log.info("BugFix#219: ========== handDevice END ==========");
|
||||
|
||||
for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) {
|
||||
// 🔧 Bug Fix: 确保accountId不为null
|
||||
if (adviceSaveDto.getAccountId() == null) {
|
||||
// 尝试从患者就诊中获取默认账户ID(自费账户)
|
||||
Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId());
|
||||
if (selfAccount != null) {
|
||||
adviceSaveDto.setAccountId(selfAccount.getId());
|
||||
} else {
|
||||
// 自动创建自费账户
|
||||
Account newAccount = new Account();
|
||||
newAccount.setPatientId(adviceSaveDto.getPatientId());
|
||||
newAccount.setEncounterId(adviceSaveDto.getEncounterId());
|
||||
newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO);
|
||||
newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode());
|
||||
newAccount.setBalanceAmount(BigDecimal.ZERO);
|
||||
newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue());
|
||||
newAccount.setEncounterFlag(Whether.YES.getValue());
|
||||
newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo());
|
||||
Long newAccountId = iAccountService.saveAccountByRegister(newAccount);
|
||||
adviceSaveDto.setAccountId(newAccountId);
|
||||
}
|
||||
}
|
||||
|
||||
deviceRequest = new DeviceRequest();
|
||||
deviceRequest.setId(adviceSaveDto.getRequestId()); // 主键id
|
||||
deviceRequest.setStatusEnum(is_save ? RequestStatus.DRAFT.getValue() : RequestStatus.ACTIVE.getValue()); // 请求状态
|
||||
@@ -1124,6 +1201,47 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
chargeItem.setServiceId(deviceRequest.getId()); // 医疗服务ID
|
||||
chargeItem.setProductTable(adviceSaveDto.getAdviceTableName());// 产品所在表
|
||||
chargeItem.setProductId(adviceSaveDto.getAdviceDefinitionId());// 收费项id
|
||||
|
||||
// 🔧 Bug Fix: 如果 definitionId 或 definitionDetailId 为 null,从定价信息中获取
|
||||
if (chargeItem.getDefinitionId() == null || chargeItem.getDefDetailId() == null) {
|
||||
log.warn("耗材的 definitionId 或 definitionDetailId 为 null,尝试从定价信息中获取: deviceDefId={}",
|
||||
adviceSaveDto.getAdviceDefinitionId());
|
||||
// 查询耗材定价信息
|
||||
IPage<AdviceBaseDto> devicePage = doctorStationAdviceAppMapper.getAdviceBaseInfo(
|
||||
new Page<>(1, 1),
|
||||
PublicationStatus.ACTIVE.getValue(),
|
||||
orgId,
|
||||
CommonConstants.TableName.ADM_DEVICE_DEFINITION,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
Arrays.asList(adviceSaveDto.getAdviceDefinitionId()),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
if (devicePage != null && !devicePage.getRecords().isEmpty()) {
|
||||
AdviceBaseDto deviceBaseInfo = devicePage.getRecords().get(0);
|
||||
if (deviceBaseInfo.getPriceList() != null && !deviceBaseInfo.getPriceList().isEmpty()) {
|
||||
AdvicePriceDto devicePrice = deviceBaseInfo.getPriceList().get(0);
|
||||
if (chargeItem.getDefinitionId() == null) {
|
||||
chargeItem.setDefinitionId(devicePrice.getDefinitionId());
|
||||
log.info("从定价信息中获取 definitionId: {}", devicePrice.getDefinitionId());
|
||||
}
|
||||
if (chargeItem.getDefDetailId() == null) {
|
||||
chargeItem.setDefDetailId(devicePrice.getDefinitionDetailId());
|
||||
log.info("从定价信息中获取 definitionDetailId: {}", devicePrice.getDefinitionDetailId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 🔧 Bug Fix: 确保定义ID不为null
|
||||
if (chargeItem.getDefinitionId() == null) {
|
||||
log.error("无法获取耗材的 definitionId: deviceDefId={}", adviceSaveDto.getAdviceDefinitionId());
|
||||
throw new ServiceException("无法获取耗材的定价信息,请联系管理员");
|
||||
}
|
||||
|
||||
// 🔧 Bug Fix: 如果accountId为null,从就诊中获取账户ID,如果没有则自动创建
|
||||
Long accountId = adviceSaveDto.getAccountId();
|
||||
if (accountId == null) {
|
||||
@@ -1141,6 +1259,8 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
newAccount.setBalanceAmount(BigDecimal.ZERO);
|
||||
newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue());
|
||||
newAccount.setEncounterFlag(Whether.YES.getValue());
|
||||
// 🔧 Bug Fix: 设置账户名称,避免数据库NOT NULL约束错误
|
||||
newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo());
|
||||
accountId = iAccountService.saveAccountByRegister(newAccount);
|
||||
}
|
||||
}
|
||||
@@ -1222,6 +1342,28 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
}
|
||||
|
||||
for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) {
|
||||
// 🔧 Bug Fix: 确保accountId不为null
|
||||
if (adviceSaveDto.getAccountId() == null) {
|
||||
// 尝试从患者就诊中获取默认账户ID(自费账户)
|
||||
Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId());
|
||||
if (selfAccount != null) {
|
||||
adviceSaveDto.setAccountId(selfAccount.getId());
|
||||
} else {
|
||||
// 自动创建自费账户
|
||||
Account newAccount = new Account();
|
||||
newAccount.setPatientId(adviceSaveDto.getPatientId());
|
||||
newAccount.setEncounterId(adviceSaveDto.getEncounterId());
|
||||
newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO);
|
||||
newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode());
|
||||
newAccount.setBalanceAmount(BigDecimal.ZERO);
|
||||
newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue());
|
||||
newAccount.setEncounterFlag(Whether.YES.getValue());
|
||||
newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo());
|
||||
Long newAccountId = iAccountService.saveAccountByRegister(newAccount);
|
||||
adviceSaveDto.setAccountId(newAccountId);
|
||||
}
|
||||
}
|
||||
|
||||
// 🔧 Bug Fix #238: 诊疗项目执行科室非空校验
|
||||
if (adviceSaveDto.getAdviceType() != null && adviceSaveDto.getAdviceType() == 3) {
|
||||
Long effectiveOrgId = adviceSaveDto.getEffectiveOrgId();
|
||||
@@ -1333,26 +1475,26 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
|
||||
// 只有在签发时
|
||||
if (is_sign) {
|
||||
// 发送跨系统申请
|
||||
adviceSaveDto.setRequestId(serviceRequest.getId());
|
||||
try {
|
||||
// 查询诊疗定义
|
||||
ActivityDefinition activityDefinition
|
||||
= iActivityDefinitionService.getById(adviceSaveDto.getAdviceDefinitionId());
|
||||
if (activityDefinition != null) {
|
||||
// 检验 或 检查
|
||||
if (ActivityType.PROOF.getValue().equals(activityDefinition.getTypeEnum())
|
||||
|| ActivityType.TEST.getValue().equals(activityDefinition.getTypeEnum())) {
|
||||
doctorStationSendApplyUtil.sendCrossSystemApply(adviceSaveDto, organizationId, curDate);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!Whether.YES.getCode()
|
||||
.equals(TenantOptionUtil.getOptionContent(TenantOptionDict.LIS_PACS_ERROR_IGNORE))) {
|
||||
throw e;
|
||||
}
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
// 发送跨系统申请 - 已注释,项目未使用LIS/PACS系统
|
||||
// adviceSaveDto.setRequestId(serviceRequest.getId());
|
||||
// try {
|
||||
// // 查询诊疗定义
|
||||
// ActivityDefinition activityDefinition
|
||||
// = iActivityDefinitionService.getById(adviceSaveDto.getAdviceDefinitionId());
|
||||
// if (activityDefinition != null) {
|
||||
// // 检验 或 检查
|
||||
// if (ActivityType.PROOF.getValue().equals(activityDefinition.getTypeEnum())
|
||||
// || ActivityType.TEST.getValue().equals(activityDefinition.getTypeEnum())) {
|
||||
// doctorStationSendApplyUtil.sendCrossSystemApply(adviceSaveDto, organizationId, curDate);
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// if (!Whether.YES.getCode()
|
||||
// .equals(TenantOptionUtil.getOptionContent(TenantOptionDict.LIS_PACS_ERROR_IGNORE))) {
|
||||
// throw e;
|
||||
// }
|
||||
// log.error(e.getMessage(), e);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1417,15 +1559,60 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
iChargeItemService.updatePaymentStatus(chargeItemIdList, ChargeItemStatus.DRAFT.getValue());
|
||||
}
|
||||
|
||||
// 🔧 BugFix: 直接对所有requestId进行作废操作
|
||||
log.info("BugFix#219: signOffAdvice - 作废所有请求, requestIdList={}", requestIdList);
|
||||
// 🔧 新增:签退时回滚库存
|
||||
// 查询已发放的药品记录(用于回滚库存)
|
||||
List<MedicationDispense> dispensedList = iMedicationDispenseService.list(
|
||||
new LambdaQueryWrapper<MedicationDispense>()
|
||||
.in(MedicationDispense::getMedReqId, requestIdList)
|
||||
.eq(MedicationDispense::getStatusEnum, DispenseStatus.COMPLETED.getValue())
|
||||
);
|
||||
|
||||
// 尝试作废药品请求(只有存在的才会更新)
|
||||
iMedicationRequestService.updateCancelledStatusBatch(requestIdList, null, null);
|
||||
// 尝试作废耗材请求(只有存在的才会更新)
|
||||
iDeviceRequestService.updateCancelledStatusBatch(requestIdList);
|
||||
// 尝试作废诊疗请求(只有存在的才会更新)
|
||||
iServiceRequestService.updateCancelledStatusBatch(requestIdList);
|
||||
if (dispensedList != null && !dispensedList.isEmpty()) {
|
||||
// 需要回滚的库存列表
|
||||
List<InventoryItem> inventoryUpdateList = new ArrayList<>();
|
||||
|
||||
for (MedicationDispense dispense : dispensedList) {
|
||||
// 查询对应的库存记录(根据批号和药品ID)
|
||||
if (dispense.getMedicationId() != null && dispense.getLotNumber() != null) {
|
||||
InventoryItem inventoryItem = inventoryItemService.getOne(
|
||||
new LambdaQueryWrapper<InventoryItem>()
|
||||
.eq(InventoryItem::getItemId, dispense.getMedicationId())
|
||||
.eq(InventoryItem::getLotNumber, dispense.getLotNumber())
|
||||
);
|
||||
|
||||
if (inventoryItem != null) {
|
||||
// 计算回滚后的数量(加上已发放的数量)
|
||||
BigDecimal currentQuantity = inventoryItem.getQuantity() != null ? inventoryItem.getQuantity() : BigDecimal.ZERO;
|
||||
BigDecimal dispenseQuantity = dispense.getQuantity() != null ? dispense.getQuantity() : BigDecimal.ZERO;
|
||||
inventoryUpdateList.add(new InventoryItem()
|
||||
.setId(inventoryItem.getId())
|
||||
.setQuantity(currentQuantity.add(dispenseQuantity))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新发药记录状态为已退药
|
||||
dispense.setStatusEnum(DispenseStatus.RETURNED.getValue());
|
||||
}
|
||||
|
||||
// 批量更新库存(回滚数量)
|
||||
if (!inventoryUpdateList.isEmpty()) {
|
||||
inventoryItemService.updateBatchById(inventoryUpdateList);
|
||||
}
|
||||
|
||||
// 更新发药记录状态
|
||||
iMedicationDispenseService.updateBatchById(dispensedList);
|
||||
}
|
||||
|
||||
// 🔧 BugFix: 直接对所有requestId进行签退操作,将状态改为待签发
|
||||
log.info("BugFix: signOffAdvice - 签退所有请求,状态改为待签发, requestIdList={}", requestIdList);
|
||||
|
||||
// 尝试签退药品请求(只有存在的才会更新)
|
||||
iMedicationRequestService.updateDraftStatusBatch(requestIdList, null, null);
|
||||
// 尝试签退耗材请求(只有存在的才会更新)
|
||||
iDeviceRequestService.updateDraftStatusBatch(requestIdList);
|
||||
// 尝试签退诊疗请求(只有存在的才会更新)
|
||||
iServiceRequestService.updateDraftStatusBatch(requestIdList);
|
||||
|
||||
log.info("BugFix#219: signOffAdvice - 所有请求作废完成");
|
||||
|
||||
|
||||
@@ -10,8 +10,10 @@ import com.core.common.utils.AssignSeqUtil;
|
||||
import com.core.common.utils.MessageUtils;
|
||||
import com.core.common.utils.SecurityUtils;
|
||||
import com.core.common.utils.StringUtils;
|
||||
import com.openhis.administration.domain.Account;
|
||||
import com.openhis.administration.domain.ChargeItem;
|
||||
import com.openhis.administration.domain.EncounterDiagnosis;
|
||||
import com.openhis.administration.service.IAccountService;
|
||||
import com.openhis.administration.service.IChargeItemService;
|
||||
import com.openhis.administration.service.IEncounterDiagnosisService;
|
||||
import com.openhis.clinical.domain.Condition;
|
||||
@@ -80,6 +82,9 @@ public class DoctorStationChineseMedicalAppServiceImpl implements IDoctorStation
|
||||
@Resource
|
||||
AdviceUtils adviceUtils;
|
||||
|
||||
@Resource
|
||||
IAccountService iAccountService;
|
||||
|
||||
/**
|
||||
* 查询中医诊断数据
|
||||
*
|
||||
@@ -364,7 +369,7 @@ public class DoctorStationChineseMedicalAppServiceImpl implements IDoctorStation
|
||||
adviceBaseDto.setAdviceType(1); // 医嘱类型为药品
|
||||
adviceBaseDto.setCategoryCode(MedCategoryCode.CHINESE_HERBAL_MEDICINE.getValue());// 中草药
|
||||
return iDoctorStationAdviceAppService.getAdviceBaseInfo(adviceBaseDto, searchKey, locationId,
|
||||
adviceDefinitionIdParamList, organizationId, pageNo, pageSize, pricingFlag, List.of(1, 2, 3), null);
|
||||
adviceDefinitionIdParamList, organizationId, pageNo, pageSize, pricingFlag, List.of(1, 2, 3), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -475,6 +480,28 @@ public class DoctorStationChineseMedicalAppServiceImpl implements IDoctorStation
|
||||
// 医嘱签发编码
|
||||
String signCode = assignSeqUtil.getSeq(AssignSeqEnum.ADVICE_SIGN.getPrefix(), 10);
|
||||
for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) {
|
||||
// 🔧 Bug Fix: 确保accountId不为null
|
||||
if (adviceSaveDto.getAccountId() == null) {
|
||||
// 尝试从患者就诊中获取默认账户ID(自费账户)
|
||||
Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId());
|
||||
if (selfAccount != null) {
|
||||
adviceSaveDto.setAccountId(selfAccount.getId());
|
||||
} else {
|
||||
// 自动创建自费账户
|
||||
Account newAccount = new Account();
|
||||
newAccount.setPatientId(adviceSaveDto.getPatientId());
|
||||
newAccount.setEncounterId(adviceSaveDto.getEncounterId());
|
||||
newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO);
|
||||
newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode());
|
||||
newAccount.setBalanceAmount(BigDecimal.ZERO);
|
||||
newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue());
|
||||
newAccount.setEncounterFlag(Whether.YES.getValue());
|
||||
newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo());
|
||||
Long newAccountId = iAccountService.saveAccountByRegister(newAccount);
|
||||
adviceSaveDto.setAccountId(newAccountId);
|
||||
}
|
||||
}
|
||||
|
||||
// 中药付数
|
||||
BigDecimal chineseHerbsDoseQuantity = adviceSaveDto.getChineseHerbsDoseQuantity();
|
||||
medicationRequest = new MedicationRequest();
|
||||
@@ -586,7 +613,7 @@ public class DoctorStationChineseMedicalAppServiceImpl implements IDoctorStation
|
||||
|
||||
// 对应的诊疗医嘱信息
|
||||
AdviceBaseDto activityAdviceBaseDto = iDoctorStationAdviceAppService.getAdviceBaseInfo(adviceBaseDto, null,
|
||||
null, null, organizationId, 1, 1, Whether.NO.getValue(), List.of(3), null).getRecords().get(0);
|
||||
null, null, organizationId, 1, 1, Whether.NO.getValue(), List.of(3), null, null).getRecords().get(0);
|
||||
if (activityAdviceBaseDto != null) {
|
||||
// 费用定价
|
||||
AdvicePriceDto advicePriceDto = activityAdviceBaseDto.getPriceList().get(0);
|
||||
|
||||
@@ -273,12 +273,28 @@ public class DoctorStationDiagnosisAppServiceImpl implements IDoctorStationDiagn
|
||||
*/
|
||||
@Override
|
||||
public R<?> saveDoctorDiagnosisNew(SaveDiagnosisParam saveDiagnosisParam) {
|
||||
// 参数校验:确保诊断列表不为空
|
||||
if (saveDiagnosisParam == null) {
|
||||
return R.fail(MessageUtils.message(PromptMsgConstant.Common.M00009, new Object[] { "保存诊断参数" }));
|
||||
}
|
||||
|
||||
// 患者id
|
||||
Long patientId = saveDiagnosisParam.getPatientId();
|
||||
// 就诊ID
|
||||
Long encounterId = saveDiagnosisParam.getEncounterId();
|
||||
// 诊断定义集合
|
||||
List<SaveDiagnosisChildParam> diagnosisChildList = saveDiagnosisParam.getDiagnosisChildList();
|
||||
|
||||
// 校验患者ID和就诊ID
|
||||
if (patientId == null || encounterId == null) {
|
||||
return R.fail(MessageUtils.message(PromptMsgConstant.Common.M00009, new Object[] { "患者ID或就诊ID" }));
|
||||
}
|
||||
|
||||
// 校验诊断列表不为空
|
||||
if (diagnosisChildList == null || diagnosisChildList.isEmpty()) {
|
||||
return R.fail(MessageUtils.message(PromptMsgConstant.Common.M00009, new Object[] { "诊断列表" }));
|
||||
}
|
||||
|
||||
// 先删除再保存
|
||||
// iEncounterDiagnosisService.deleteEncounterDiagnosisInfos(encounterId);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.openhis.web.doctorstation.appservice.impl;
|
||||
|
||||
import com.core.common.core.domain.R;
|
||||
import com.core.common.core.redis.RedisCache;
|
||||
import com.core.common.enums.DelFlag;
|
||||
import com.core.common.utils.SecurityUtils;
|
||||
import com.openhis.common.enums.DbOpType;
|
||||
@@ -35,6 +36,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -76,6 +79,9 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
||||
@Autowired
|
||||
private IServiceRequestService serviceRequestService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
/**
|
||||
* 保存检验申请单信息
|
||||
* @param doctorStationLabApplyDto
|
||||
@@ -88,8 +94,39 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
||||
* 保存检验申请单信息逻辑
|
||||
* 保存检验申请单信息同时根据检验申请单检验项目数据保存检验申请单明细信息
|
||||
*/
|
||||
log.debug("保存检验申请单信息:{}", doctorStationLabApplyDto);
|
||||
log.debug("保存申请单明细信息:{}",doctorStationLabApplyDto.getLabApplyItemList());
|
||||
|
||||
// 申请单号为空或"待生成"时,由后端生成新单号
|
||||
String applyNo = doctorStationLabApplyDto.getApplyNo();
|
||||
boolean isNewApplyNo = false;
|
||||
if (applyNo == null || applyNo.trim().isEmpty() || "待生成".equals(applyNo) || "自动生成".equals(applyNo)) {
|
||||
applyNo = generateApplyNo();
|
||||
isNewApplyNo = true;
|
||||
}
|
||||
// 将生成的单号设置回 DTO
|
||||
doctorStationLabApplyDto.setApplyNo(applyNo);
|
||||
|
||||
try {
|
||||
// 执行保存逻辑
|
||||
doSaveInspectionLabApply(doctorStationLabApplyDto, applyNo);
|
||||
} catch (Exception e) {
|
||||
// 记录废号日志(申请单号已生成但保存失败)
|
||||
if (isNewApplyNo) {
|
||||
log.error("申请单号 {} 因保存失败成为废号,原因:{}", applyNo, e.getMessage());
|
||||
}
|
||||
throw e; // 重新抛出异常,让事务回滚
|
||||
}
|
||||
|
||||
// 返回生成的申请单号
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("applyNo", applyNo);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行保存检验申请单的实际逻辑
|
||||
*/
|
||||
private void doSaveInspectionLabApply(DoctorStationLabApplyDto doctorStationLabApplyDto, String applyNo) {
|
||||
|
||||
//获取当前登陆用户 ID
|
||||
String userId = String.valueOf(SecurityUtils.getLoginUser().getUserId());
|
||||
InspectionLabApply inspectionLabApply = new InspectionLabApply();
|
||||
@@ -102,22 +139,34 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
||||
inspectionLabApply.setOperatorId(userId);
|
||||
inspectionLabApply.setCreateTime(new Date());
|
||||
inspectionLabApply.setDeleteFlag(DelFlag.NO.getCode());
|
||||
// 申请日期使用服务器当前系统时间
|
||||
inspectionLabApply.setApplyTime(new Date());
|
||||
|
||||
log.debug("保存检验申请单信息:{}", inspectionLabApply);
|
||||
inspectionLabApplyService.saveOrUpdate(inspectionLabApply);
|
||||
|
||||
// 金额校验和重算:后端重新计算金额,防止前端篡改
|
||||
java.math.BigDecimal totalAmount = java.math.BigDecimal.ZERO;
|
||||
int index = 0;
|
||||
|
||||
//遍历 doctorStationLabApplyDto.getLabApplyItemList()
|
||||
int index = 0;
|
||||
for (DoctorStationLabApplyItemDto doctorStationLabApplyItemDto : doctorStationLabApplyDto.getLabApplyItemList()) {
|
||||
//将 dto 数据复制到 InspectionLabApplyItem 对象中
|
||||
InspectionLabApplyItem inspectionLabApplyItem = new InspectionLabApplyItem();
|
||||
BeanUtils.copyProperties(doctorStationLabApplyItemDto, inspectionLabApplyItem);
|
||||
|
||||
// 后端重新计算金额:金额 = 单价 × 数量
|
||||
java.math.BigDecimal itemPrice = doctorStationLabApplyItemDto.getItemPrice();
|
||||
java.math.BigDecimal itemQty = doctorStationLabApplyItemDto.getItemQty();
|
||||
if (itemPrice != null && itemQty != null) {
|
||||
java.math.BigDecimal calculatedAmount = itemPrice.multiply(itemQty).setScale(2, java.math.RoundingMode.HALF_UP);
|
||||
inspectionLabApplyItem.setItemAmount(calculatedAmount);
|
||||
totalAmount = totalAmount.add(calculatedAmount);
|
||||
}
|
||||
|
||||
//设置从表申请单明细的申请单号
|
||||
inspectionLabApplyItem.setApplyNo(doctorStationLabApplyDto.getApplyNo());
|
||||
//检验科代码,取值于检验申请单
|
||||
inspectionLabApplyItem.setPerformDeptCode(doctorStationLabApplyDto.getApplyDeptCode());
|
||||
//执行科室代码,取值于检验申请单明细(前端传递的字典值)
|
||||
inspectionLabApplyItem.setPerformDeptCode(doctorStationLabApplyItemDto.getPerformDeptCode());
|
||||
//同主表状态,可单独回写
|
||||
inspectionLabApplyItem.setItemStatus(doctorStationLabApplyDto.getApplyStatus());
|
||||
// 设置项目序号 (打印顺序),按照遍历序号进行排序
|
||||
@@ -125,7 +174,6 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
||||
index++;
|
||||
|
||||
inspectionLabApplyItem.setDeleteFlag(DelFlag.NO.getCode());
|
||||
log.debug("保存申请单明细信息:{}", inspectionLabApplyItem);
|
||||
inspectionLabApplyItemService.saveOrUpdate(inspectionLabApplyItem);
|
||||
|
||||
//创建条码对象
|
||||
@@ -141,8 +189,6 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
||||
barCode.setCreateTime(new Date());
|
||||
barCode.setDeleteFlag(DelFlag.NO.getCode());
|
||||
|
||||
|
||||
log.debug("插入条码数据前,barCode:{}",barCode);
|
||||
inspectionLabBarCodeService.saveOrUpdate(barCode);
|
||||
}
|
||||
|
||||
@@ -189,11 +235,14 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
||||
);
|
||||
if (organization != null) {
|
||||
positionId = organization.getId();
|
||||
} else {
|
||||
log.warn("未找到执行科室代码对应的科室:{}", performDeptCode);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有指定执行科室,使用当前医生所在的科室作为默认执行科室
|
||||
if (positionId == null) {
|
||||
positionId = SecurityUtils.getDeptId();
|
||||
}
|
||||
|
||||
// 4. 创建医嘱保存对象
|
||||
AdviceSaveDto adviceSaveDto = new AdviceSaveDto();
|
||||
// 设置医嘱操作类型
|
||||
@@ -270,23 +319,45 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
||||
adviceSaveParam.setAdviceSaveList(adviceSaveList);
|
||||
|
||||
// 调用门诊医嘱保存接口,创建关联的医嘱记录
|
||||
try {
|
||||
iDoctorStationAdviceAppService.saveAdvice(adviceSaveParam, "1"); // "1"表示保存操作
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("创建关联医嘱记录失败", e);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据申请单号查询检验申请单
|
||||
* 根据申请单号查询检验申请单(包含检验项目明细)
|
||||
*
|
||||
* @param applyNo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Object getInspectionApplyByApplyNo(String applyNo) {
|
||||
return doctorStationLabApplyMapper.getInspectionApplyByApplyNo(applyNo);
|
||||
// 查询主表数据
|
||||
DoctorStationLabApplyDto applyDto = (DoctorStationLabApplyDto) doctorStationLabApplyMapper.getInspectionApplyByApplyNo(applyNo);
|
||||
if (applyDto == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 查询检验项目明细
|
||||
List<InspectionLabApplyItem> itemList = inspectionLabApplyItemService.list(
|
||||
new QueryWrapper<InspectionLabApplyItem>()
|
||||
.eq("apply_no", applyNo)
|
||||
.eq("delete_flag", "0")
|
||||
.orderByAsc("item_seq")
|
||||
);
|
||||
|
||||
// 转换为 DTO 列表
|
||||
List<DoctorStationLabApplyItemDto> itemDtoList = new ArrayList<>();
|
||||
if (itemList != null && !itemList.isEmpty()) {
|
||||
for (InspectionLabApplyItem item : itemList) {
|
||||
DoctorStationLabApplyItemDto itemDto = new DoctorStationLabApplyItemDto();
|
||||
BeanUtils.copyProperties(item, itemDto);
|
||||
itemDtoList.add(itemDto);
|
||||
}
|
||||
// 从第一个明细项获取执行科室代码
|
||||
applyDto.setExecuteDepartment(itemList.get(0).getPerformDeptCode());
|
||||
}
|
||||
applyDto.setLabApplyItemList(itemDtoList);
|
||||
|
||||
return applyDto;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,11 +374,11 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
||||
|
||||
// 查询检验申请单列表
|
||||
log.debug("查询申请单数据前");
|
||||
List<InspectionLabApply> list = doctorStationLabApplyMapper.getInspectionApplyListPage(encounterId);
|
||||
List<DoctorStationLabApplyDto> list = doctorStationLabApplyMapper.getInspectionApplyListPage(encounterId);
|
||||
log.debug("查询申请单数据后");
|
||||
|
||||
// 使用 PageInfo 包装查询结果
|
||||
PageInfo<InspectionLabApply> pageInfo = new PageInfo<>(list);
|
||||
PageInfo<DoctorStationLabApplyDto> pageInfo = new PageInfo<>(list);
|
||||
|
||||
// 构建返回结果
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
@@ -514,4 +585,36 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成检验申请单号
|
||||
* 规则:LS + YYYYMMDD + 5位流水号(每日从1开始递增)
|
||||
* 支持并发安全:使用 Redis 原子递增保证唯一性
|
||||
* @return 申请单号
|
||||
*/
|
||||
private String generateApplyNo() {
|
||||
// 获取当前日期
|
||||
LocalDate today = LocalDate.now();
|
||||
String dateStr = today.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
|
||||
// 生成前缀:LS + 日期
|
||||
String prefix = "LS" + dateStr;
|
||||
|
||||
// Redis key 用于存储当天的流水号
|
||||
String redisKey = "lab_apply_no:" + dateStr;
|
||||
|
||||
// 使用 Redis 原子递增获取流水号(并发安全)
|
||||
long sequence = redisCache.incr(redisKey, 1);
|
||||
|
||||
// 设置 Redis key 过期时间(每天的 key 按日期独立,隔天不再使用,25小时确保跨午夜场景安全)
|
||||
redisCache.expire(redisKey, 25 * 60 * 60);
|
||||
|
||||
// 格式化流水号为5位,不足前补0
|
||||
String sequenceStr = String.format("%05d", sequence);
|
||||
|
||||
// 生成完整的申请单号
|
||||
String applyNo = prefix + sequenceStr;
|
||||
|
||||
return applyNo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.openhis.web.doctorstation.appservice.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -16,21 +17,23 @@ import com.openhis.common.constant.CommonConstants;
|
||||
import com.openhis.common.enums.*;
|
||||
import com.openhis.common.utils.EnumUtils;
|
||||
import com.openhis.common.utils.HisQueryUtils;
|
||||
import com.openhis.triageandqueuemanage.domain.TriageQueueItem;
|
||||
import com.openhis.triageandqueuemanage.service.TriageQueueItemService;
|
||||
import com.openhis.web.doctorstation.appservice.*;
|
||||
import com.openhis.web.doctorstation.dto.PatientInfoDto;
|
||||
import com.openhis.web.doctorstation.dto.PrescriptionInfoBaseDto;
|
||||
import com.openhis.web.doctorstation.dto.PrescriptionInfoDetailDto;
|
||||
import com.openhis.web.doctorstation.dto.ReceptionStatisticsDto;
|
||||
import com.openhis.web.doctorstation.mapper.DoctorStationMainAppMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -64,6 +67,9 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
|
||||
|
||||
@Resource
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Resource
|
||||
private TriageQueueItemService triageQueueItemService;
|
||||
/**
|
||||
* 查询就诊患者信息
|
||||
*
|
||||
@@ -124,14 +130,40 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public R<?> receiveEncounter(Long encounterId) {
|
||||
Integer tenantId = SecurityUtils.getLoginUser().getTenantId();
|
||||
String currentUsername = SecurityUtils.getUsername();
|
||||
|
||||
// 检查就诊记录是否存在
|
||||
Encounter encounter = encounterMapper.selectById(encounterId);
|
||||
if (encounter == null) {
|
||||
return R.fail("就诊记录不存在");
|
||||
}
|
||||
|
||||
// 检查患者状态,防止重复接诊
|
||||
Integer currentStatus = encounter.getStatusEnum();
|
||||
if (EncounterStatus.IN_PROGRESS.getValue().equals(currentStatus)) {
|
||||
return R.fail("已接诊,请勿重复点击,已为您刷新");
|
||||
}
|
||||
|
||||
int update = encounterMapper.update(null,
|
||||
new LambdaUpdateWrapper<Encounter>().eq(Encounter::getId, encounterId)
|
||||
.eq(Encounter::getStatusEnum, EncounterStatus.PLANNED.getValue()) // 只更新待诊状态的患者
|
||||
.set(Encounter::getReceptionTime, new Date())
|
||||
.set(Encounter::getStatusEnum, EncounterStatus.IN_PROGRESS.getValue())
|
||||
.set(Encounter::getSubjectStatusEnum, EncounterSubjectStatus.RECEIVING_CARE.getValue()));
|
||||
|
||||
// 如果更新失败,说明状态已被其他医生修改
|
||||
if (update <= 0) {
|
||||
// 重新查询当前状态
|
||||
encounter = encounterMapper.selectById(encounterId);
|
||||
if (EncounterStatus.IN_PROGRESS.getValue().equals(encounter.getStatusEnum())) {
|
||||
return R.fail("已接诊,请勿重复接诊");
|
||||
}
|
||||
return R.fail("接诊失败,请刷新后重试");
|
||||
}
|
||||
|
||||
// 先把之前的接诊记录更新为已完成
|
||||
iEncounterParticipantService.update(new LambdaUpdateWrapper<EncounterParticipant>()
|
||||
.eq(EncounterParticipant::getTypeCode, ParticipantType.ADMITTER.getCode())
|
||||
@@ -148,7 +180,28 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
|
||||
encounterParticipant.setCreateBy(currentUsername);
|
||||
encounterParticipant.setCreateTime(new Date());
|
||||
iEncounterParticipantService.save(encounterParticipant);
|
||||
return update > 0 ? R.ok() : R.fail();
|
||||
|
||||
// 更新 triage_queue_item 队列记录状态为 CALLING
|
||||
try {
|
||||
TriageQueueItem queueItem = triageQueueItemService.getOne(
|
||||
new LambdaQueryWrapper<TriageQueueItem>()
|
||||
.eq(TriageQueueItem::getTenantId, tenantId)
|
||||
.eq(TriageQueueItem::getEncounterId, encounterId)
|
||||
.eq(TriageQueueItem::getDeleteFlag, "0")
|
||||
);
|
||||
if (queueItem != null) {
|
||||
queueItem.setStatus("CALLING");
|
||||
queueItem.setUpdateTime(LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS));
|
||||
triageQueueItemService.updateById(queueItem);
|
||||
log.info("接诊时更新队列状态为CALLING,encounterId={}, queueItemId={}", encounterId, queueItem.getId());
|
||||
} else {
|
||||
log.warn("接诊时未找到队列记录,encounterId={}", encounterId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("接诊时更新队列状态失败,encounterId={}", encounterId, e);
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,11 +234,54 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
|
||||
return R.fail("就诊记录不存在");
|
||||
}
|
||||
|
||||
if (!EncounterStatus.IN_PROGRESS.getValue().equals(encounter.getStatusEnum())) {
|
||||
return R.fail("当前患者不在就诊中状态");
|
||||
// 检查患者状态,防止重复完诊
|
||||
Integer currentStatus = encounter.getStatusEnum();
|
||||
if (EncounterStatus.DISCHARGED.getValue().equals(currentStatus) ||
|
||||
EncounterStatus.COMPLETED.getValue().equals(currentStatus)) {
|
||||
// 患者已完成就诊,返回特定提示
|
||||
return R.fail("患者已完成就诊,已为您自动刷新患者列表");
|
||||
}
|
||||
|
||||
// 2. 更新状态、完成时间以及初复诊标识
|
||||
if (!EncounterStatus.IN_PROGRESS.getValue().equals(currentStatus)) {
|
||||
return R.fail("非就诊中患者不能完诊");
|
||||
}
|
||||
|
||||
// 2. 查找队列项
|
||||
Integer tenantId = SecurityUtils.getLoginUser().getTenantId();
|
||||
TriageQueueItem queueItem = triageQueueItemService.getOne(
|
||||
new LambdaQueryWrapper<TriageQueueItem>()
|
||||
.eq(TriageQueueItem::getTenantId, tenantId)
|
||||
.eq(TriageQueueItem::getEncounterId, encounterId)
|
||||
.eq(TriageQueueItem::getDeleteFlag, "0")
|
||||
);
|
||||
|
||||
// 如果队列项存在,检查状态并更新
|
||||
if (queueItem != null && "CALLING".equals(queueItem.getStatus())) {
|
||||
// 更新队列状态为已完成
|
||||
java.time.LocalDateTime nowLocal = java.time.LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS);
|
||||
queueItem.setStatus("COMPLETED");
|
||||
queueItem.setUpdateTime(nowLocal);
|
||||
triageQueueItemService.updateById(queueItem);
|
||||
|
||||
// 写入 div_log 审计日志
|
||||
try {
|
||||
Long userId = SecurityUtils.getLoginUser().getUserId();
|
||||
String divLogSql = "INSERT INTO hisdev.div_log "
|
||||
+ "(pool_id, slot_id, queue_no, op_user_id, action, create_time) "
|
||||
+ "VALUES (?, ?, ?, ?, 'COMPLETE', NOW()::timestamp(0))";
|
||||
|
||||
jdbcTemplate.update(divLogSql,
|
||||
queueItem.getOrganizationId(), // pool_id: 候选池ID(科室)
|
||||
queueItem.getPractitionerId(), // slot_id: 槽位ID(医生)
|
||||
queueItem.getQueueOrder(), // queue_no: 队列号
|
||||
userId); // op_user_id: 操作用户ID
|
||||
} catch (Exception e) {
|
||||
log.error("写入div_log审计日志失败", e);
|
||||
// 审计日志失败不影响主流程
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 更新状态、完成时间以及初复诊标识
|
||||
Date now = new Date();
|
||||
int update = encounterMapper.update(null,
|
||||
new LambdaUpdateWrapper<Encounter>()
|
||||
@@ -198,7 +294,7 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
|
||||
|
||||
if (update <= 0) return R.fail("完诊失败");
|
||||
|
||||
// 3. 审计日志
|
||||
// 4. 审计日志(sys_oper_log)
|
||||
try {
|
||||
String username = SecurityUtils.getUsernameSafe();
|
||||
String sql = "INSERT INTO sys_oper_log "
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package com.openhis.web.doctorstation.controller;
|
||||
|
||||
import com.core.common.annotation.RepeatSubmit;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.openhis.common.enums.AdviceOpType;
|
||||
import com.openhis.common.enums.Whether;
|
||||
@@ -51,7 +52,7 @@ public class DoctorStationAdviceController {
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
return R.ok(iDoctorStationAdviceAppService.getAdviceBaseInfo(adviceBaseDto, searchKey, locationId,
|
||||
adviceDefinitionIdParamList, organizationId, pageNo, pageSize, Whether.NO.getValue(), adviceTypes, null));
|
||||
adviceDefinitionIdParamList, organizationId, pageNo, pageSize, Whether.NO.getValue(), adviceTypes, null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,6 +86,7 @@ public class DoctorStationAdviceController {
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping(value = "/sign-advice")
|
||||
@RepeatSubmit(interval = 5000, message = "请勿重复签发医嘱,请稍候再试")
|
||||
public R<?> signAdvice(@RequestBody AdviceSaveParam adviceSaveParam) {
|
||||
return iDoctorStationAdviceAppService.saveAdvice(adviceSaveParam, AdviceOpType.SIGN_ADVICE.getCode());
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 门诊医生站-检验控制器
|
||||
|
||||
@@ -17,6 +17,10 @@ import java.util.List;
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DoctorStationLabApplyDto {
|
||||
/**
|
||||
* 申请单ID(数据库自增主键)
|
||||
*/
|
||||
private Long applicationId;
|
||||
/**
|
||||
* 申请单编号
|
||||
*/
|
||||
@@ -135,6 +139,10 @@ public class DoctorStationLabApplyDto {
|
||||
* 就诊id
|
||||
*/
|
||||
private Long encounterId;
|
||||
/**
|
||||
* 执行科室代码(从明细项获取)
|
||||
*/
|
||||
private String executeDepartment;
|
||||
/**
|
||||
* 检验项目数据列表
|
||||
*/
|
||||
|
||||
@@ -79,6 +79,11 @@ public class RequestBaseDto {
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long chargeItemId;
|
||||
|
||||
/**
|
||||
* 医嘱定义对应表名
|
||||
*/
|
||||
private String adviceTableName;
|
||||
|
||||
/**
|
||||
* 医嘱名称
|
||||
*/
|
||||
@@ -156,6 +161,11 @@ public class RequestBaseDto {
|
||||
private String doseUnitCode;
|
||||
private String doseUnitCode_dictText;
|
||||
|
||||
/**
|
||||
* 单价
|
||||
*/
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
/**
|
||||
* 总价
|
||||
*/
|
||||
@@ -210,4 +220,16 @@ public class RequestBaseDto {
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long basedOnId;
|
||||
|
||||
/**
|
||||
* 就诊id
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long encounterId;
|
||||
|
||||
/**
|
||||
* 患者id
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long patientId;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.openhis.web.doctorstation.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -73,12 +74,16 @@ public class SaveDiagnosisChildParam {
|
||||
|
||||
/**
|
||||
* 诊断时间
|
||||
* 添加 pattern 以支持前端传来的 "yyyy/M/d HH:mm:ss" 格式
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy/M/d HH:mm:ss", timezone = "GMT+8")
|
||||
private Date diagnosisTime;
|
||||
|
||||
/**
|
||||
* 发病时间
|
||||
* 同样添加 pattern 以防前端传来相同格式的发病时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy/M/d HH:mm:ss", timezone = "GMT+8")
|
||||
private Date onsetDate;
|
||||
|
||||
/** 患者疾病诊断类型代码 */
|
||||
|
||||
@@ -38,6 +38,7 @@ public interface DoctorStationAdviceAppMapper {
|
||||
@Param("adviceDefinitionIdParamList") List<Long> adviceDefinitionIdParamList,
|
||||
@Param("adviceTypes") List<Integer> adviceTypes,
|
||||
@Param("searchKey") String searchKey,
|
||||
@Param("categoryCode") String categoryCode,
|
||||
@Param(Constants.WRAPPER) QueryWrapper<AdviceBaseDto> queryWrapper);
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.openhis.web.doctorstation.mapper;
|
||||
|
||||
import com.openhis.lab.domain.InspectionLabApply;
|
||||
import com.openhis.web.doctorstation.dto.DoctorStationLabApplyDto;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -11,6 +11,11 @@ import java.util.List;
|
||||
*/
|
||||
@Repository
|
||||
public interface DoctorStationLabApplyMapper {
|
||||
/**
|
||||
* 根据申请单号查询检验申请单
|
||||
* @param applyNo 申请单号
|
||||
* @return 检验申请单DTO
|
||||
*/
|
||||
Object getInspectionApplyByApplyNo(String applyNo);
|
||||
|
||||
/**
|
||||
@@ -18,5 +23,5 @@ public interface DoctorStationLabApplyMapper {
|
||||
* @param encounterId 就诊 ID
|
||||
* @return 检验申请单列表
|
||||
*/
|
||||
List<InspectionLabApply> getInspectionApplyListPage(@Param("encounterId") Long encounterId);
|
||||
List<DoctorStationLabApplyDto> getInspectionApplyListPage(@Param("encounterId") Long encounterId);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.openhis.administration.domain.ChargeItem;
|
||||
import com.openhis.administration.domain.Account;
|
||||
import com.openhis.administration.service.IAccountService;
|
||||
import com.openhis.administration.service.IChargeItemService;
|
||||
import com.openhis.common.constant.CommonConstants;
|
||||
import com.openhis.common.enums.*;
|
||||
@@ -71,6 +73,9 @@ public class AdviceUtils {
|
||||
@Resource
|
||||
IDoctorStationAdviceAppService iDoctorStationAdviceAppService;
|
||||
|
||||
@Resource
|
||||
IAccountService iAccountService;
|
||||
|
||||
/**
|
||||
* 校验库存
|
||||
*
|
||||
@@ -110,6 +115,15 @@ public class AdviceUtils {
|
||||
matched = true;
|
||||
// 检查库存是否充足
|
||||
BigDecimal minUnitQuantity = saveDto.getMinUnitQuantity();
|
||||
// 🔧 Bug Fix: 对于耗材类型,如果没有设置minUnitQuantity,则使用quantity作为默认值
|
||||
if (minUnitQuantity == null) {
|
||||
if (CommonConstants.TableName.ADM_DEVICE_DEFINITION.equals(inventoryDto.getItemTable())) {
|
||||
// 耗材只有一个单位,minUnitQuantity等于quantity
|
||||
minUnitQuantity = saveDto.getQuantity();
|
||||
} else {
|
||||
return saveDto.getAdviceName() + "的小单位数量不能为空";
|
||||
}
|
||||
}
|
||||
BigDecimal chineseHerbsDoseQuantity = saveDto.getChineseHerbsDoseQuantity(); // 中药付数
|
||||
// 中草药医嘱的情况
|
||||
if (chineseHerbsDoseQuantity != null && chineseHerbsDoseQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
||||
@@ -305,6 +319,28 @@ public class AdviceUtils {
|
||||
*/
|
||||
public void handleActivityChild(String childrenJson, Long organizationId,
|
||||
ActivityChildrenJsonParams activityChildrenJsonParams) {
|
||||
// 🔧 Bug Fix: 确保accountId不为null
|
||||
if (activityChildrenJsonParams.getAccountId() == null) {
|
||||
// 尝试从患者就诊中获取默认账户ID(自费账户)
|
||||
Account selfAccount = iAccountService.getSelfAccount(activityChildrenJsonParams.getEncounterId());
|
||||
if (selfAccount != null) {
|
||||
activityChildrenJsonParams.setAccountId(selfAccount.getId());
|
||||
} else {
|
||||
// 自动创建自费账户
|
||||
Account newAccount = new Account();
|
||||
newAccount.setPatientId(activityChildrenJsonParams.getPatientId());
|
||||
newAccount.setEncounterId(activityChildrenJsonParams.getEncounterId());
|
||||
newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO);
|
||||
newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode());
|
||||
newAccount.setBalanceAmount(BigDecimal.ZERO);
|
||||
newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue());
|
||||
newAccount.setEncounterFlag(Whether.YES.getValue());
|
||||
newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo());
|
||||
Long newAccountId = iAccountService.saveAccountByRegister(newAccount);
|
||||
activityChildrenJsonParams.setAccountId(newAccountId);
|
||||
}
|
||||
}
|
||||
|
||||
// 治疗类型 (长期/临时)
|
||||
Integer therapyEnum = activityChildrenJsonParams.getTherapyEnum();
|
||||
// 当前登录账号的科室id
|
||||
@@ -337,7 +373,7 @@ public class AdviceUtils {
|
||||
// 对应的子项诊疗医嘱信息
|
||||
AdviceBaseDto activityAdviceBaseDto
|
||||
= iDoctorStationAdviceAppService.getAdviceBaseInfo(adviceBaseDto, null, null, null, organizationId, 1,
|
||||
1, Whether.NO.getValue(), List.of(1, 2, 3), null).getRecords().get(0);
|
||||
1, Whether.NO.getValue(), List.of(1, 2, 3), null, null).getRecords().get(0);
|
||||
if (activityAdviceBaseDto != null) {
|
||||
// 费用定价
|
||||
AdvicePriceDto advicePriceDto = activityAdviceBaseDto.getPriceList().get(0);
|
||||
|
||||
@@ -32,9 +32,11 @@ public class PrescriptionUtils {
|
||||
if (medicineList == null || medicineList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 1. 按诊断ID分组(不同诊断必须分开)
|
||||
// 1. 按诊断ID分组(不同诊断必须分开,null值归为一组)
|
||||
Map<Long, List<AdviceSaveDto>> diagnosisGroups =
|
||||
medicineList.stream().collect(Collectors.groupingBy(AdviceSaveDto::getConditionDefinitionId));
|
||||
medicineList.stream().collect(Collectors.groupingBy(dto ->
|
||||
dto.getConditionDefinitionId() != null ? dto.getConditionDefinitionId() : 0L
|
||||
));
|
||||
// 2. 处理每个诊断组
|
||||
diagnosisGroups.values().forEach(this::processDiagnosisGroup);
|
||||
}
|
||||
@@ -46,9 +48,11 @@ public class PrescriptionUtils {
|
||||
if (diagnosisGroup.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 1. 按药品性质分组
|
||||
// 1. 按药品性质分组(null值归为普通药品)
|
||||
Map<String, List<AdviceSaveDto>> pharmacologyGroups =
|
||||
diagnosisGroup.stream().collect(Collectors.groupingBy(AdviceSaveDto::getPharmacologyCategoryCode));
|
||||
diagnosisGroup.stream().collect(Collectors.groupingBy(dto ->
|
||||
dto.getPharmacologyCategoryCode() != null ? dto.getPharmacologyCategoryCode() : "0"
|
||||
));
|
||||
// 2. 处理每个药品性质组
|
||||
pharmacologyGroups.values().forEach(pharmaGroup -> {
|
||||
// 2.1 先处理有分组ID的药品(确保它们不会被拆分)
|
||||
|
||||
@@ -702,7 +702,7 @@ public class AdviceProcessAppServiceImpl implements IAdviceProcessAppService {
|
||||
= medUseExeList.stream().map(MedicationRequestUseExe::getMedicationId).collect(Collectors.toList());
|
||||
// 医嘱详细信息
|
||||
List<AdviceBaseDto> medicationInfos = doctorStationAdviceAppService.getAdviceBaseInfo(null, null, null,
|
||||
medicationDefinitionIdList, 0L, 1, 500, Whether.NO.getValue(), List.of(1), null).getRecords();
|
||||
medicationDefinitionIdList, 0L, 1, 500, Whether.NO.getValue(), List.of(1), null, null).getRecords();
|
||||
|
||||
// 当前时间
|
||||
Date curDate = new Date();
|
||||
@@ -979,7 +979,7 @@ public class AdviceProcessAppServiceImpl implements IAdviceProcessAppService {
|
||||
= actUseExeList.stream().map(ServiceRequestUseExe::getActivityId).collect(Collectors.toList());
|
||||
// 医嘱详细信息
|
||||
List<AdviceBaseDto> activityInfos = doctorStationAdviceAppService.getAdviceBaseInfo(null, null, null,
|
||||
activityDefinitionIdList, 0L, 1, 500, Whether.NO.getValue(), List.of(3), null).getRecords();
|
||||
activityDefinitionIdList, 0L, 1, 500, Whether.NO.getValue(), List.of(3), null, null).getRecords();
|
||||
|
||||
// 当前时间
|
||||
Date curDate = new Date();
|
||||
@@ -1146,7 +1146,7 @@ public class AdviceProcessAppServiceImpl implements IAdviceProcessAppService {
|
||||
|
||||
// 耗材医嘱详细信息
|
||||
List<AdviceBaseDto> deviceInfos = doctorStationAdviceAppService
|
||||
.getAdviceBaseInfo(null, null, null, deviceIds, 0L, 1, 500, Whether.NO.getValue(), List.of(2), null)
|
||||
.getAdviceBaseInfo(null, null, null, deviceIds, 0L, 1, 500, Whether.NO.getValue(), List.of(2), null, null)
|
||||
.getRecords();
|
||||
|
||||
DeviceRequest deviceRequest;
|
||||
|
||||
@@ -201,7 +201,7 @@ public class EncounterAutoRollAppServiceImpl implements IEncounterAutoRollAppSer
|
||||
.map(AutoRollNursingDto::getActivityDefinitionId).collect(Collectors.toList());
|
||||
// 诊疗医嘱信息
|
||||
List<AdviceBaseDto> activityInfos = doctorStationAdviceAppService.getAdviceBaseInfo(null, null, null,
|
||||
activityDefinitionIdList, 0L, 1, 500, Whether.NO.getValue(), List.of(3), orderPricing).getRecords();
|
||||
activityDefinitionIdList, 0L, 1, 500, Whether.NO.getValue(), List.of(3), orderPricing, null).getRecords();
|
||||
|
||||
// 计费
|
||||
ChargeItem chargeItem;
|
||||
@@ -295,7 +295,7 @@ public class EncounterAutoRollAppServiceImpl implements IEncounterAutoRollAppSer
|
||||
.map(AutoRollBasicServiceDto::getActivityDefinitionId).collect(Collectors.toList());
|
||||
// 诊疗医嘱信息
|
||||
List<AdviceBaseDto> activityInfos = doctorStationAdviceAppService.getAdviceBaseInfo(null, null, null,
|
||||
activityDefinitionIdList, 0L, 1, 500, Whether.NO.getValue(), List.of(3), orderPricing).getRecords();
|
||||
activityDefinitionIdList, 0L, 1, 500, Whether.NO.getValue(), List.of(3), orderPricing, null).getRecords();
|
||||
// 计费
|
||||
ChargeItem chargeItem;
|
||||
for (AutoRollBasicServiceDto autoRollBasicServiceDto : autoRollBasicService) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package com.openhis.web.inventorymanage.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.core.common.annotation.Excel;
|
||||
import com.core.common.annotation.ExcelExtra;
|
||||
@@ -248,7 +249,8 @@ public class ProductTransferDetailDto {
|
||||
private Date occurrenceTime;
|
||||
|
||||
/**
|
||||
* 单位列表
|
||||
* 单位列表(非数据库字段,业务逻辑填充)
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<UnitDto> unitList;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.openhis.web.lab.appservice;
|
||||
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentSelParam;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentUpDto;
|
||||
import com.core.common.core.domain.R;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验项目 AppService 接口(独立操作 lab_activity_definition 表)
|
||||
*/
|
||||
public interface ILabActivityDefinitionAppService {
|
||||
|
||||
/**
|
||||
* 分页查询检验项目列表
|
||||
*/
|
||||
R<?> getLabActivityDefinitionPage(DiagnosisTreatmentSelParam selParam, String searchKey,
|
||||
Integer pageNo, Integer pageSize, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 根据id查询检验项目详情
|
||||
*/
|
||||
R<?> getLabActivityDefinitionOne(Long id);
|
||||
|
||||
/**
|
||||
* 新增检验项目
|
||||
*/
|
||||
R<?> addLabActivityDefinition(DiagnosisTreatmentUpDto dto);
|
||||
|
||||
/**
|
||||
* 编辑检验项目
|
||||
*/
|
||||
R<?> editLabActivityDefinition(DiagnosisTreatmentUpDto dto);
|
||||
|
||||
/**
|
||||
* 停用检验项目
|
||||
*/
|
||||
R<?> stopLabActivityDefinition(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 启用检验项目
|
||||
*/
|
||||
R<?> startLabActivityDefinition(List<Long> ids);
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package com.openhis.web.lab.appservice.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.core.common.core.domain.model.LoginUser;
|
||||
import com.core.common.utils.*;
|
||||
import com.core.common.utils.bean.BeanUtils;
|
||||
import com.openhis.common.constant.PromptMsgConstant;
|
||||
import com.openhis.common.enums.ActivityType;
|
||||
import com.openhis.common.enums.PublicationStatus;
|
||||
import com.openhis.common.enums.Whether;
|
||||
import com.core.common.utils.ChineseConvertUtils;
|
||||
import com.openhis.common.utils.EnumUtils;
|
||||
import com.openhis.common.utils.HisQueryUtils;
|
||||
import com.openhis.common.enums.AssignSeqEnum;
|
||||
import com.openhis.lab.domain.LabActivityDefinition;
|
||||
import com.openhis.lab.service.ILabActivityDefinitionService;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentDto;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentSelParam;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentUpDto;
|
||||
import com.openhis.web.lab.appservice.ILabActivityDefinitionAppService;
|
||||
import com.openhis.web.datadictionary.mapper.LabActivityDefinitionManageMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* 检验项目 AppService 实现(独立操作 lab_activity_definition 表)
|
||||
*/
|
||||
@Service
|
||||
public class LabActivityDefinitionAppServiceImpl implements ILabActivityDefinitionAppService {
|
||||
|
||||
@Resource
|
||||
private ILabActivityDefinitionService labActivityDefinitionService;
|
||||
|
||||
@Resource
|
||||
private LabActivityDefinitionManageMapper labActivityDefinitionManageMapper;
|
||||
|
||||
@Resource
|
||||
private AssignSeqUtil assignSeqUtil;
|
||||
|
||||
@Override
|
||||
public R<?> getLabActivityDefinitionPage(DiagnosisTreatmentSelParam selParam, String searchKey,
|
||||
Integer pageNo, Integer pageSize, HttpServletRequest request) {
|
||||
if (selParam == null) {
|
||||
selParam = new DiagnosisTreatmentSelParam();
|
||||
}
|
||||
if (selParam.getStatusEnum() == null) {
|
||||
selParam.setStatusEnum(PublicationStatus.ACTIVE.getValue());
|
||||
}
|
||||
|
||||
// 临时移除需要手动拼别名条件的字段
|
||||
Long inspectionTypeIdValue = null;
|
||||
if (selParam.getInspectionTypeId() != null) {
|
||||
inspectionTypeIdValue = selParam.getInspectionTypeId();
|
||||
selParam.setInspectionTypeId(null);
|
||||
}
|
||||
Integer pricingFlagValue = null;
|
||||
if (selParam.getPricingFlag() != null) {
|
||||
pricingFlagValue = selParam.getPricingFlag();
|
||||
selParam.setPricingFlag(null);
|
||||
}
|
||||
|
||||
QueryWrapper<DiagnosisTreatmentDto> queryWrapper = HisQueryUtils.buildQueryWrapper(selParam,
|
||||
searchKey, new HashSet<>(Arrays.asList("T1.bus_no", "T1.name", "T1.py_str", "T1.wb_str")), request);
|
||||
|
||||
if (inspectionTypeIdValue != null) {
|
||||
queryWrapper.eq("T1.inspection_type_id", inspectionTypeIdValue);
|
||||
selParam.setInspectionTypeId(inspectionTypeIdValue);
|
||||
}
|
||||
if (pricingFlagValue != null) {
|
||||
queryWrapper.eq("T1.pricing_flag", pricingFlagValue);
|
||||
selParam.setPricingFlag(pricingFlagValue);
|
||||
}
|
||||
|
||||
IPage<DiagnosisTreatmentDto> page = labActivityDefinitionManageMapper
|
||||
.getLabActivityDefinitionPage(new Page<>(pageNo, pageSize), queryWrapper);
|
||||
|
||||
page.getRecords().forEach(e -> {
|
||||
e.setYbFlag_enumText(EnumUtils.getInfoByValue(Whether.class, e.getYbFlag()));
|
||||
e.setYbMatchFlag_enumText(EnumUtils.getInfoByValue(Whether.class, e.getYbMatchFlag()));
|
||||
e.setTypeEnum_enumText(EnumUtils.getInfoByValue(ActivityType.class, e.getTypeEnum()));
|
||||
e.setStatusEnum_enumText(EnumUtils.getInfoByValue(PublicationStatus.class, e.getStatusEnum()));
|
||||
e.setPricingFlag_enumText(EnumUtils.getInfoByValue(Whether.class, e.getPricingFlag()));
|
||||
});
|
||||
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> getLabActivityDefinitionOne(Long id) {
|
||||
Integer tenantId = SecurityUtils.getLoginUser().getTenantId();
|
||||
DiagnosisTreatmentDto dto = labActivityDefinitionManageMapper.getLabActivityDefinitionOne(id, tenantId);
|
||||
return R.ok(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> addLabActivityDefinition(DiagnosisTreatmentUpDto dto) {
|
||||
if (dto.getOrgId() == null) {
|
||||
dto.setOrgId(SecurityUtils.getLoginUser().getHospitalId());
|
||||
}
|
||||
|
||||
LabActivityDefinition lab = new LabActivityDefinition();
|
||||
BeanUtils.copyProperties(dto, lab);
|
||||
lab.setSortOrder(dto.getSortOrder())
|
||||
.setServiceRange(dto.getServiceRange())
|
||||
.setInspectionTypeId(dto.getInspectionTypeId())
|
||||
.setFeePackageId(dto.getFeePackageId())
|
||||
.setSubItemId(dto.getSubItemId());
|
||||
|
||||
if (StringUtils.isEmpty(lab.getBusNo())) {
|
||||
lab.setBusNo(assignSeqUtil.getSeq(AssignSeqEnum.ACTIVITY_DEFINITION_NUM.getPrefix(), 10));
|
||||
}
|
||||
lab.setPyStr(ChineseConvertUtils.toPinyinFirstLetter(lab.getName()));
|
||||
lab.setWbStr(ChineseConvertUtils.toWBFirstLetter(lab.getName()));
|
||||
lab.setStatusEnum(PublicationStatus.ACTIVE.getValue());
|
||||
|
||||
// 设置创建者和租户ID
|
||||
String createBy = "system";
|
||||
Integer tenantId = null;
|
||||
try {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser != null) {
|
||||
createBy = loginUser.getUsername();
|
||||
tenantId = loginUser.getTenantId();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 使用默认值
|
||||
}
|
||||
lab.setCreateBy(createBy);
|
||||
lab.setTenantId(tenantId != null ? tenantId : 1);
|
||||
if (lab.getCreateTime() == null) {
|
||||
lab.setCreateTime(new java.util.Date());
|
||||
}
|
||||
|
||||
return labActivityDefinitionService.addLabActivityDefinition(lab)
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"检验项目"}))
|
||||
: R.fail(null, "检验编码已存在:" + lab.getBusNo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> editLabActivityDefinition(DiagnosisTreatmentUpDto dto) {
|
||||
LabActivityDefinition lab = new LabActivityDefinition();
|
||||
BeanUtils.copyProperties(dto, lab);
|
||||
lab.setSortOrder(dto.getSortOrder())
|
||||
.setServiceRange(dto.getServiceRange())
|
||||
.setInspectionTypeId(dto.getInspectionTypeId())
|
||||
.setFeePackageId(dto.getFeePackageId())
|
||||
.setSubItemId(dto.getSubItemId())
|
||||
.setPricingFlag(dto.getPricingFlag());
|
||||
lab.setPyStr(ChineseConvertUtils.toPinyinFirstLetter(lab.getName()));
|
||||
lab.setWbStr(ChineseConvertUtils.toWBFirstLetter(lab.getName()));
|
||||
|
||||
return labActivityDefinitionService.updateById(lab)
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"检验项目"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> stopLabActivityDefinition(List<Long> ids) {
|
||||
List<LabActivityDefinition> labList = new CopyOnWriteArrayList<>();
|
||||
for (Long id : ids) {
|
||||
LabActivityDefinition lab = new LabActivityDefinition();
|
||||
lab.setId(id).setStatusEnum(PublicationStatus.RETIRED.getValue());
|
||||
labList.add(lab);
|
||||
}
|
||||
labActivityDefinitionService.updateBatchById(labList);
|
||||
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"检验项目"}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> startLabActivityDefinition(List<Long> ids) {
|
||||
List<LabActivityDefinition> labList = new CopyOnWriteArrayList<>();
|
||||
for (Long id : ids) {
|
||||
LabActivityDefinition lab = new LabActivityDefinition();
|
||||
lab.setId(id).setStatusEnum(PublicationStatus.ACTIVE.getValue());
|
||||
labList.add(lab);
|
||||
}
|
||||
labActivityDefinitionService.updateBatchById(labList);
|
||||
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"检验项目"}));
|
||||
}
|
||||
}
|
||||
@@ -146,6 +146,9 @@ public class InspectionPackageController extends BaseController {
|
||||
if (inspectionPackage.getIsDisabled() != null) {
|
||||
queryWrapper.eq("is_disabled", inspectionPackage.getIsDisabled());
|
||||
}
|
||||
if (inspectionPackage.getUserId() != null && !inspectionPackage.getUserId().isEmpty()) {
|
||||
queryWrapper.like("user_id", inspectionPackage.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
// 默认只查询未删除的记录
|
||||
|
||||
@@ -94,7 +94,6 @@ public class InspectionTypeController extends BaseController {
|
||||
|
||||
// 查询是否存在相同编码的记录
|
||||
List<InspectionType> existingRecords = inspectionTypeService.list(queryWrapper);
|
||||
log.debug("检查编码唯一性:code={}, 数据库中存在记录数={}", inspectionType.getCode(), existingRecords.size());
|
||||
|
||||
if (!existingRecords.isEmpty()) {
|
||||
return AjaxResult.error("检验类型编码已存在");
|
||||
@@ -119,8 +118,6 @@ public class InspectionTypeController extends BaseController {
|
||||
return toAjax(result);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("新增检验类型失败:code={}, 错误信息:{}", inspectionType.getCode(), e.getMessage(), e);
|
||||
|
||||
// 捕获唯一性约束冲突异常
|
||||
if (e.getMessage().contains("uk_inspection_type_code") ||
|
||||
e.getMessage().contains("duplicate key value") ||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.openhis.web.lab.controller;
|
||||
|
||||
import com.core.common.core.domain.R;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentSelParam;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentUpDto;
|
||||
import com.openhis.web.lab.appservice.ILabActivityDefinitionAppService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验项目维护 Controller(独立操作 lab_activity_definition 表)
|
||||
* 路径前缀:/lab/activity-definition
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/lab/activity-definition")
|
||||
@Slf4j
|
||||
public class LabActivityDefinitionController {
|
||||
|
||||
@Resource
|
||||
private ILabActivityDefinitionAppService labActivityDefinitionAppService;
|
||||
|
||||
/**
|
||||
* 分页查询检验项目列表
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R<?> getPage(DiagnosisTreatmentSelParam selParam,
|
||||
@RequestParam(value = "searchKey", defaultValue = "") String searchKey,
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest request) {
|
||||
return labActivityDefinitionAppService.getLabActivityDefinitionPage(selParam, searchKey, pageNo, pageSize, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询检验项目详情
|
||||
*/
|
||||
@GetMapping("/one")
|
||||
public R<?> getOne(@RequestParam Long id) {
|
||||
return labActivityDefinitionAppService.getLabActivityDefinitionOne(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增检验项目
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public R<?> add(@Validated @RequestBody DiagnosisTreatmentUpDto dto) {
|
||||
return labActivityDefinitionAppService.addLabActivityDefinition(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑检验项目
|
||||
*/
|
||||
@PutMapping("/edit")
|
||||
public R<?> edit(@RequestBody DiagnosisTreatmentUpDto dto) {
|
||||
return labActivityDefinitionAppService.editLabActivityDefinition(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用检验项目
|
||||
*/
|
||||
@PutMapping("/stop")
|
||||
public R<?> stop(@RequestBody List<Long> ids) {
|
||||
return labActivityDefinitionAppService.stopLabActivityDefinition(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用检验项目
|
||||
*/
|
||||
@PutMapping("/start")
|
||||
public R<?> start(@RequestBody List<Long> ids) {
|
||||
return labActivityDefinitionAppService.startLabActivityDefinition(ids);
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,8 @@ import com.openhis.web.paymentmanage.dto.CancelPaymentDto;
|
||||
import com.openhis.web.paymentmanage.dto.Clinic2207OrderResultDto;
|
||||
import com.openhis.web.paymentmanage.mapper.PaymentMapper;
|
||||
import com.openhis.web.personalization.dto.ActivityDeviceDto;
|
||||
import com.openhis.triageandqueuemanage.domain.TriageQueueItem;
|
||||
import com.openhis.triageandqueuemanage.service.TriageQueueItemService;
|
||||
import com.openhis.workflow.domain.ServiceRequest;
|
||||
import com.openhis.workflow.service.IDeviceDispenseService;
|
||||
import com.openhis.workflow.service.IDeviceRequestService;
|
||||
@@ -81,9 +83,11 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -149,6 +153,8 @@ public class PaymentRecServiceImpl implements IPaymentRecService {
|
||||
@Resource
|
||||
private OutpatientRegistrationAppMapper outpatientRegistrationAppMapper;
|
||||
@Resource
|
||||
private TriageQueueItemService triageQueueItemService;
|
||||
@Resource
|
||||
private IRegService iRegService;
|
||||
@Resource
|
||||
private IPatientService iPatientService;
|
||||
@@ -255,7 +261,9 @@ public class PaymentRecServiceImpl implements IPaymentRecService {
|
||||
|
||||
// 账户id,对应的账单列表
|
||||
Map<Long, List<ChargeItem>> chargeItemMapByAccountId
|
||||
= chargeItemList.stream().collect(Collectors.groupingBy(ChargeItem::getAccountId));
|
||||
= chargeItemList.stream()
|
||||
.filter(item -> item.getAccountId() != null)
|
||||
.collect(Collectors.groupingBy(ChargeItem::getAccountId));
|
||||
// 查询合同信息
|
||||
List<Contract> contractList = contractService.list();
|
||||
|
||||
@@ -1928,6 +1936,80 @@ public class PaymentRecServiceImpl implements IPaymentRecService {
|
||||
|
||||
// 就诊ID
|
||||
Long encounterId = iEncounterService.saveEncounterByRegister(encounter);
|
||||
|
||||
// 创建 triage_queue_item 队列记录
|
||||
try {
|
||||
Integer tenantId = encounter.getTenantId() != null ? encounter.getTenantId() : SecurityUtils.getLoginUser().getTenantId();
|
||||
LocalDate queueDate = LocalDate.now();
|
||||
|
||||
// 查询当前科室当天的最大排队序号
|
||||
Integer maxOrder = triageQueueItemService.list(
|
||||
new LambdaQueryWrapper<TriageQueueItem>()
|
||||
.eq(TriageQueueItem::getTenantId, tenantId)
|
||||
.eq(TriageQueueItem::getOrganizationId, encounter.getOrganizationId())
|
||||
.eq(TriageQueueItem::getQueueDate, queueDate)
|
||||
.eq(TriageQueueItem::getDeleteFlag, "0")
|
||||
.ne(TriageQueueItem::getStatus, "COMPLETED")
|
||||
).stream()
|
||||
.map(TriageQueueItem::getQueueOrder)
|
||||
.filter(Objects::nonNull)
|
||||
.max(Integer::compareTo)
|
||||
.orElse(0);
|
||||
|
||||
// 获取患者信息
|
||||
Patient patient = iPatientService.getById(encounter.getPatientId());
|
||||
String patientName = patient != null ? patient.getName() : null;
|
||||
|
||||
// 获取挂号医生信息
|
||||
String practitionerName = null;
|
||||
Long queuePractitionerId = null;
|
||||
if (encounterParticipantFormData.getPractitionerId() != null) {
|
||||
Practitioner practitioner = iPractitionerService.getById(encounterParticipantFormData.getPractitionerId());
|
||||
if (practitioner != null) {
|
||||
practitionerName = practitioner.getName();
|
||||
queuePractitionerId = practitioner.getId();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取科室信息
|
||||
Organization organization = iOrganizationService.getById(encounter.getOrganizationId());
|
||||
String organizationName = organization != null ? organization.getName() : null;
|
||||
|
||||
// 获取服务项目信息(挂号类型)
|
||||
String healthcareName = null;
|
||||
if (encounter.getServiceTypeId() != null) {
|
||||
HealthcareService healthcareService = healthcareServiceService.getById(encounter.getServiceTypeId());
|
||||
if (healthcareService != null) {
|
||||
healthcareName = healthcareService.getName();
|
||||
}
|
||||
}
|
||||
|
||||
// 创建队列项
|
||||
TriageQueueItem queueItem = new TriageQueueItem()
|
||||
.setTenantId(tenantId)
|
||||
.setQueueDate(queueDate)
|
||||
.setOrganizationId(encounter.getOrganizationId())
|
||||
.setOrganizationName(organizationName)
|
||||
.setEncounterId(encounterId)
|
||||
.setPatientId(encounter.getPatientId())
|
||||
.setPatientName(patientName)
|
||||
.setHealthcareName(healthcareName)
|
||||
.setPractitionerId(queuePractitionerId)
|
||||
.setPractitionerName(practitionerName)
|
||||
.setRoomNo(null)
|
||||
.setStatus("WAITING")
|
||||
.setQueueOrder(maxOrder + 1)
|
||||
.setDeleteFlag("0")
|
||||
.setCreateTime(LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS))
|
||||
.setUpdateTime(LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS));
|
||||
|
||||
triageQueueItemService.save(queueItem);
|
||||
logger.info("挂号时创建队列记录成功,encounterId={}, queueItemId={}", encounterId, queueItem.getId());
|
||||
} catch (Exception e) {
|
||||
logger.error("挂号时创建队列记录失败,encounterId={}", encounterId, e);
|
||||
// 队列记录创建失败不影响挂号流程
|
||||
}
|
||||
|
||||
// 保存就诊位置信息
|
||||
// 挂号时不选Location了
|
||||
// encounterLocationFormData.setEncounterId(encounterId);
|
||||
@@ -2095,7 +2177,7 @@ public class PaymentRecServiceImpl implements IPaymentRecService {
|
||||
adviceBaseDto.setAdviceDefinitionId(activityDeviceDto.getDevActId());
|
||||
// 对应的诊疗医嘱信息
|
||||
AdviceBaseDto activityAdviceBaseDto = iDoctorStationAdviceAppService.getAdviceBaseInfo(adviceBaseDto, null,
|
||||
null, null, organizationId, 1, 1, Whether.NO.getValue(), List.of(1, 2, 3), null).getRecords().get(0);
|
||||
null, null, organizationId, 1, 1, Whether.NO.getValue(), List.of(1, 2, 3), null, null).getRecords().get(0);
|
||||
// 价格信息
|
||||
if (activityAdviceBaseDto != null) {
|
||||
// 费用定价
|
||||
@@ -2251,7 +2333,9 @@ public class PaymentRecServiceImpl implements IPaymentRecService {
|
||||
= iChargeItemService.getChargeItemBaseInfoByIds(prePaymentDto.getChargeItemIds());
|
||||
|
||||
Map<String, List<ChargeItemBaseInfoDto>> chargeItemKVByContractNo
|
||||
= chargeItemBaseInfoByIds.stream().collect(Collectors.groupingBy(ChargeItemBaseInfoDto::getContractNo));
|
||||
= chargeItemBaseInfoByIds.stream()
|
||||
.filter(dto -> dto.getContractNo() != null && !dto.getContractNo().isEmpty())
|
||||
.collect(Collectors.groupingBy(ChargeItemBaseInfoDto::getContractNo));
|
||||
|
||||
List<InpatientPreSettleDto> yb2303OutputSetInfos = new ArrayList<>();
|
||||
Yb2303OutputSetInfo yb2303OutputSetInfo;
|
||||
@@ -2379,13 +2463,17 @@ public class PaymentRecServiceImpl implements IPaymentRecService {
|
||||
List<ChargeItemBaseInfoDto> chargeItemBaseInfoByIds
|
||||
= iChargeItemService.getChargeItemBaseInfoByIds(paymentDto.getChargeItemIds());
|
||||
Map<String, List<ChargeItemBaseInfoDto>> chargeItemKVByContractNo
|
||||
= chargeItemBaseInfoByIds.stream().collect(Collectors.groupingBy(ChargeItemBaseInfoDto::getContractNo));
|
||||
= chargeItemBaseInfoByIds.stream()
|
||||
.filter(dto -> dto.getContractNo() != null && !dto.getContractNo().isEmpty())
|
||||
.collect(Collectors.groupingBy(ChargeItemBaseInfoDto::getContractNo));
|
||||
|
||||
List<Account> accountList = iAccountService.getAccountListByEncounter(paymentDto.getEncounterId());
|
||||
if (accountList.isEmpty()) {
|
||||
throw new ServiceException("未查询到账户信息");
|
||||
}
|
||||
Map<Long, List<Account>> accountKVById = accountList.stream().collect(Collectors.groupingBy(Account::getId));
|
||||
Map<Long, List<Account>> accountKVById = accountList.stream()
|
||||
.filter(acc -> acc.getId() != null)
|
||||
.collect(Collectors.groupingBy(Account::getId));
|
||||
|
||||
com.openhis.financial.model.PaymentResult paymentResult;
|
||||
List<com.openhis.financial.model.PaymentResult> paymentResultList = new ArrayList<>();
|
||||
@@ -2395,7 +2483,9 @@ public class PaymentRecServiceImpl implements IPaymentRecService {
|
||||
|
||||
// <3>收费详情按照收费批次进行分组后结算
|
||||
Map<Long, List<PaymentRecDetail>> payTransNoMap
|
||||
= paymentRecDetails.stream().collect(Collectors.groupingBy(PaymentRecDetail::getAccountId));
|
||||
= paymentRecDetails.stream()
|
||||
.filter(detail -> detail.getAccountId() != null)
|
||||
.collect(Collectors.groupingBy(PaymentRecDetail::getAccountId));
|
||||
|
||||
for (Map.Entry<Long, List<PaymentRecDetail>> stringListEntry : payTransNoMap.entrySet()) {
|
||||
// paymentResult = new PaymentResult();
|
||||
|
||||
@@ -197,7 +197,7 @@ public class OrdersGroupPackageAppServiceImpl implements IOrdersGroupPackageAppS
|
||||
// 医嘱下拉详细信息
|
||||
List<AdviceBaseDto> personalRecords =
|
||||
iDoctorStationAdviceAppService.getAdviceBaseInfo(null, null, null, orderDefinitionIdParamList,
|
||||
organizationId, 1, 100, Whether.NO.getValue(), List.of(1, 2, 3), null).getRecords();
|
||||
organizationId, 1, 100, Whether.NO.getValue(), List.of(1, 2, 3), null, null).getRecords();
|
||||
// 创建AdviceBaseDto的映射,以adviceDefinitionId为key
|
||||
Map<Long, AdviceBaseDto> adviceMap = personalRecords.stream().collect(Collectors
|
||||
.toMap(AdviceBaseDto::getAdviceDefinitionId, advice -> advice, (existing, replacement) -> existing // 如果有重复key,保留第一个
|
||||
@@ -248,7 +248,7 @@ public class OrdersGroupPackageAppServiceImpl implements IOrdersGroupPackageAppS
|
||||
// 医嘱下拉详细信息
|
||||
List<AdviceBaseDto> personalRecords =
|
||||
iDoctorStationAdviceAppService.getAdviceBaseInfo(null, null, null, orderDefinitionIdParamList,
|
||||
organizationId, 1, 100, Whether.NO.getValue(), List.of(1, 2, 3), null).getRecords();
|
||||
organizationId, 1, 100, Whether.NO.getValue(), List.of(1, 2, 3), null, null).getRecords();
|
||||
// 创建AdviceBaseDto的映射,以adviceDefinitionId为key
|
||||
Map<Long, AdviceBaseDto> adviceMap = personalRecords.stream().collect(Collectors
|
||||
.toMap(AdviceBaseDto::getAdviceDefinitionId, advice -> advice, (existing, replacement) -> existing // 如果有重复key,保留第一个
|
||||
@@ -297,7 +297,7 @@ public class OrdersGroupPackageAppServiceImpl implements IOrdersGroupPackageAppS
|
||||
// 医嘱下拉详细信息
|
||||
List<AdviceBaseDto> personalRecords =
|
||||
iDoctorStationAdviceAppService.getAdviceBaseInfo(null, null, null, orderDefinitionIdParamList,
|
||||
organizationId, 1, 100, Whether.NO.getValue(), List.of(1, 2, 3), null).getRecords();
|
||||
organizationId, 1, 100, Whether.NO.getValue(), List.of(1, 2, 3), null, null).getRecords();
|
||||
// 创建AdviceBaseDto的映射,以adviceDefinitionId为key
|
||||
Map<Long, AdviceBaseDto> adviceMap = personalRecords.stream().collect(Collectors
|
||||
.toMap(AdviceBaseDto::getAdviceDefinitionId, advice -> advice, (existing, replacement) -> existing // 如果有重复key,保留第一个
|
||||
|
||||
@@ -394,7 +394,7 @@ public class MedicalDeviceDispenseAppServiceImpl implements IMedicalDeviceDispen
|
||||
}
|
||||
List<ChargeItem> chargeItemList = chargeItemService.listByIds(chargeItemIds);
|
||||
if (chargeItemList == null || chargeItemList.isEmpty()) {
|
||||
return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null));
|
||||
return R.fail("未查询到耗材收费项目信息");
|
||||
}
|
||||
|
||||
// 获取发申请id列表
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.core.common.exception.ServiceException;
|
||||
import com.core.common.utils.AssignSeqUtil;
|
||||
import com.core.common.utils.MessageUtils;
|
||||
import com.core.common.utils.SecurityUtils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.openhis.administration.domain.ChargeItem;
|
||||
import com.openhis.administration.service.IChargeItemService;
|
||||
import com.openhis.common.constant.CommonConstants;
|
||||
@@ -28,8 +29,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -132,6 +135,7 @@ public class RequestFormManageAppServiceImpl implements IRequestFormManageAppSer
|
||||
ChargeItem chargeItem;
|
||||
// 诊疗集合
|
||||
List<ActivitySaveDto> activityList = requestFormSaveDto.getActivityList();
|
||||
log.info("保存申请单,typeCode={}, activityListSize={}, encounterId={}", typeCode, activityList != null ? activityList.size() : 0, encounterId);
|
||||
// 诊疗执行科室配置
|
||||
List<ActivityOrganizationConfigDto> activityOrganizationConfig =
|
||||
requestFormManageAppMapper.getActivityOrganizationConfig(typeCode);
|
||||
@@ -211,6 +215,189 @@ public class RequestFormManageAppServiceImpl implements IRequestFormManageAppSer
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是手术申请单,需要额外生成手术医嘱
|
||||
log.info("【调试】判断手术医嘱生成条件: typeCode={}, PROCEDURE.code={}, typeCode类型={}, PROCEDURE.code类型={}",
|
||||
typeCode, ActivityDefCategory.PROCEDURE.getCode(),
|
||||
typeCode != null ? typeCode.getClass().getName() : "null",
|
||||
ActivityDefCategory.PROCEDURE.getCode().getClass().getName());
|
||||
boolean isProcedure = ActivityDefCategory.PROCEDURE.getCode().equals(typeCode);
|
||||
log.info("【调试】判断结果: isProcedure={}, typeCode字符串={}, PROCEDURE.code字符串={}",
|
||||
isProcedure,
|
||||
typeCode != null ? "'" + typeCode + "'" : "null",
|
||||
"'" + ActivityDefCategory.PROCEDURE.getCode() + "'");
|
||||
if (isProcedure) {
|
||||
log.info("开始生成手术医嘱,encounterId={}, patientId={}, typeCode={}, activityListSize={}",
|
||||
encounterId, patientId, typeCode, activityList != null ? activityList.size() : 0);
|
||||
try {
|
||||
// 从 descJson 中解析手术信息
|
||||
String descJson = requestFormSaveDto.getDescJson();
|
||||
Map<String, Object> descMap = null;
|
||||
if (descJson != null && !descJson.isEmpty()) {
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
descMap = objectMapper.readValue(descJson, Map.class);
|
||||
log.info("解析手术申请单 descJson 成功: {}", descMap);
|
||||
} catch (Exception e) {
|
||||
log.error("解析手术申请单 descJson 失败: {}", descJson, e);
|
||||
}
|
||||
} else {
|
||||
log.warn("手术申请单 descJson 为空");
|
||||
}
|
||||
|
||||
// 获取手术信息
|
||||
String surgeryName = descMap != null ? (String) descMap.get("surgeryName") : null;
|
||||
String surgeryCode = descMap != null ? (String) descMap.get("surgeryCode") : null;
|
||||
String surgeryFee = descMap != null ? (String) descMap.get("surgeryFee") : null;
|
||||
String anesthesiaFee = descMap != null ? (String) descMap.get("anesthesiaFee") : null;
|
||||
String plannedTime = descMap != null ? (String) descMap.get("plannedTime") : null;
|
||||
String surgeryIndication = descMap != null ? (String) descMap.get("surgeryIndication") : null;
|
||||
String preoperativeDiagnosis = descMap != null ? (String) descMap.get("preoperativeDiagnosis") : null;
|
||||
|
||||
// 🔧 BugFix#318: 从 activityList 获取手术项目名称
|
||||
String adviceDefinitionName = null;
|
||||
if (activityList != null && !activityList.isEmpty()) {
|
||||
adviceDefinitionName = activityList.get(0).getAdviceDefinitionName();
|
||||
log.info("从 activityList 获取手术项目名称: {}", adviceDefinitionName);
|
||||
}
|
||||
|
||||
log.info("手术信息: surgeryName={}, surgeryCode={}, surgeryFee={}, anesthesiaFee={}, adviceDefinitionName={}",
|
||||
surgeryName, surgeryCode, surgeryFee, anesthesiaFee, adviceDefinitionName);
|
||||
|
||||
// 生成手术医嘱
|
||||
ServiceRequest surgeryServiceRequest = new ServiceRequest();
|
||||
surgeryServiceRequest.setStatusEnum(RequestStatus.DRAFT.getValue());
|
||||
surgeryServiceRequest.setBusNo(String.format("%04d", (int) (Math.random() * 10000)));
|
||||
surgeryServiceRequest.setGenerateSourceEnum(GenerateSource.DOCTOR_PRESCRIPTION.getValue());
|
||||
surgeryServiceRequest.setPrescriptionNo(prescriptionNo);
|
||||
surgeryServiceRequest.setTherapyEnum(TherapyTimeType.TEMPORARY.getValue());
|
||||
surgeryServiceRequest.setQuantity(BigDecimal.valueOf(1));
|
||||
surgeryServiceRequest.setUnitCode("次");
|
||||
surgeryServiceRequest.setCategoryEnum(4); // 4-手术
|
||||
// 优先从 activityList 获取手术 ID
|
||||
if (activityList != null && !activityList.isEmpty()) {
|
||||
Long activityId = activityList.get(0).getAdviceDefinitionId();
|
||||
surgeryServiceRequest.setActivityId(activityId);
|
||||
log.info("从 activityList 获取手术ID: {}", activityId);
|
||||
} else {
|
||||
log.warn("activityList 为空,无法获取手术ID");
|
||||
}
|
||||
surgeryServiceRequest.setPatientId(patientId);
|
||||
surgeryServiceRequest.setRequesterId(practitionerId);
|
||||
surgeryServiceRequest.setEncounterId(encounterId);
|
||||
surgeryServiceRequest.setAuthoredTime(curDate);
|
||||
surgeryServiceRequest.setOrgId(orgId);
|
||||
|
||||
// 设置手术相关信息到 contentJson 字段
|
||||
Map<String, String> contentMap = new java.util.HashMap<>();
|
||||
// 🔧 BugFix#318: 优先使用 activityList 中的手术项目名称
|
||||
if (adviceDefinitionName != null && !adviceDefinitionName.isEmpty()) {
|
||||
contentMap.put("surgeryName", adviceDefinitionName);
|
||||
} else if (surgeryName != null && !surgeryName.isEmpty()) {
|
||||
contentMap.put("surgeryName", surgeryName);
|
||||
}
|
||||
if (surgeryCode != null && !surgeryCode.isEmpty()) {
|
||||
contentMap.put("surgeryCode", surgeryCode);
|
||||
}
|
||||
if (plannedTime != null && !plannedTime.isEmpty()) {
|
||||
contentMap.put("plannedTime", plannedTime);
|
||||
}
|
||||
if (surgeryIndication != null && !surgeryIndication.isEmpty()) {
|
||||
contentMap.put("surgeryIndication", surgeryIndication);
|
||||
}
|
||||
if (preoperativeDiagnosis != null && !preoperativeDiagnosis.isEmpty()) {
|
||||
contentMap.put("preoperativeDiagnosis", preoperativeDiagnosis);
|
||||
}
|
||||
if (!contentMap.isEmpty()) {
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
surgeryServiceRequest.setContentJson(objectMapper.writeValueAsString(contentMap));
|
||||
} catch (Exception e) {
|
||||
log.error("序列化手术信息失败", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
iServiceRequestService.save(surgeryServiceRequest);
|
||||
log.info("手术医嘱生成成功,serviceRequestId={}, prescriptionNo={}", surgeryServiceRequest.getId(), prescriptionNo);
|
||||
} catch (Exception e) {
|
||||
log.error("保存手术医嘱失败", e);
|
||||
throw new ServiceException("保存手术医嘱失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 生成手术收费项目
|
||||
try {
|
||||
ChargeItem surgeryChargeItem = new ChargeItem();
|
||||
surgeryChargeItem.setStatusEnum(ChargeItemStatus.DRAFT.getValue());
|
||||
surgeryChargeItem.setBusNo(AssignSeqEnum.CHARGE_ITEM_NO.getPrefix().concat(surgeryServiceRequest.getBusNo()));
|
||||
surgeryChargeItem.setGenerateSourceEnum(GenerateSource.DOCTOR_PRESCRIPTION.getValue());
|
||||
surgeryChargeItem.setPatientId(patientId);
|
||||
surgeryChargeItem.setContextEnum(6); // 6-手术
|
||||
surgeryChargeItem.setEncounterId(encounterId);
|
||||
surgeryChargeItem.setEntererId(practitionerId);
|
||||
surgeryChargeItem.setEnteredDate(curDate);
|
||||
surgeryChargeItem.setServiceTable(CommonConstants.TableName.WOR_SERVICE_REQUEST);
|
||||
surgeryChargeItem.setServiceId(surgeryServiceRequest.getId());
|
||||
surgeryChargeItem.setProductTable(CommonConstants.TableName.WOR_ACTIVITY_DEFINITION);
|
||||
// 优先从 activityList 获取 productId
|
||||
if (activityList != null && !activityList.isEmpty()) {
|
||||
surgeryChargeItem.setProductId(activityList.get(0).getAdviceDefinitionId());
|
||||
surgeryChargeItem.setAccountId(activityList.get(0).getAccountId());
|
||||
}
|
||||
surgeryChargeItem.setRequestingOrgId(orgId);
|
||||
surgeryChargeItem.setQuantityValue(BigDecimal.valueOf(1));
|
||||
surgeryChargeItem.setQuantityUnit("次");
|
||||
// 设置手术费用
|
||||
if (surgeryFee != null && !surgeryFee.isEmpty()) {
|
||||
try {
|
||||
surgeryChargeItem.setUnitPrice(new BigDecimal(surgeryFee));
|
||||
surgeryChargeItem.setTotalPrice(new BigDecimal(surgeryFee));
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("手术费用格式不正确:{}", surgeryFee);
|
||||
}
|
||||
}
|
||||
iChargeItemService.save(surgeryChargeItem);
|
||||
log.info("手术收费项目生成成功,chargeItemId={}", surgeryChargeItem.getId());
|
||||
} catch (Exception e) {
|
||||
log.error("生成手术收费项目失败", e);
|
||||
throw new ServiceException("生成手术收费项目失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 如果存在麻醉费用,生成麻醉收费项目
|
||||
if (anesthesiaFee != null && !anesthesiaFee.isEmpty()) {
|
||||
try {
|
||||
BigDecimal anesthesiaFeeAmount = new BigDecimal(anesthesiaFee);
|
||||
if (anesthesiaFeeAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
ChargeItem anesthesiaChargeItem = new ChargeItem();
|
||||
anesthesiaChargeItem.setStatusEnum(ChargeItemStatus.DRAFT.getValue());
|
||||
anesthesiaChargeItem.setBusNo(AssignSeqEnum.CHARGE_ITEM_NO.getPrefix().concat(surgeryServiceRequest.getBusNo()));
|
||||
anesthesiaChargeItem.setGenerateSourceEnum(GenerateSource.DOCTOR_PRESCRIPTION.getValue());
|
||||
anesthesiaChargeItem.setPatientId(patientId);
|
||||
anesthesiaChargeItem.setContextEnum(3); // 3-诊疗
|
||||
anesthesiaChargeItem.setEncounterId(encounterId);
|
||||
anesthesiaChargeItem.setEntererId(practitionerId);
|
||||
anesthesiaChargeItem.setEnteredDate(curDate);
|
||||
anesthesiaChargeItem.setServiceTable(CommonConstants.TableName.WOR_SERVICE_REQUEST);
|
||||
anesthesiaChargeItem.setServiceId(surgeryServiceRequest.getId());
|
||||
anesthesiaChargeItem.setProductTable(CommonConstants.TableName.WOR_ACTIVITY_DEFINITION);
|
||||
anesthesiaChargeItem.setRequestingOrgId(orgId);
|
||||
anesthesiaChargeItem.setQuantityValue(BigDecimal.valueOf(1));
|
||||
anesthesiaChargeItem.setQuantityUnit("次");
|
||||
anesthesiaChargeItem.setUnitPrice(anesthesiaFeeAmount);
|
||||
anesthesiaChargeItem.setTotalPrice(anesthesiaFeeAmount);
|
||||
iChargeItemService.save(anesthesiaChargeItem);
|
||||
log.info("麻醉收费项目生成成功");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("麻醉费用格式不正确:{}", anesthesiaFee);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("生成手术医嘱过程中发生异常", e);
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
log.info("不是手术申请单,跳过手术医嘱生成,typeCode={}", typeCode);
|
||||
}
|
||||
|
||||
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[] {"申请单"}));
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ public class SpecialAdviceAppServiceImpl implements ISpecialAdviceAppService {
|
||||
adviceBaseDto.setAdviceDefinitionId(definitionId); // 医嘱定义id
|
||||
// 对应的诊疗医嘱信息
|
||||
activityAdviceBaseDto = iDoctorStationAdviceAppService.getAdviceBaseInfo(adviceBaseDto, null, null,
|
||||
null, null, 1, 1, Whether.NO.getValue(), List.of(3), null).getRecords().get(0);
|
||||
null, null, 1, 1, Whether.NO.getValue(), List.of(3), null, null).getRecords().get(0);
|
||||
// 逻辑1---------------------直接新增
|
||||
longServiceRequest.setStatusEnum(RequestStatus.DRAFT.getValue());// 请求状态
|
||||
longServiceRequest.setOccurrenceStartTime(startTime); // 医嘱开始时间
|
||||
@@ -208,7 +208,7 @@ public class SpecialAdviceAppServiceImpl implements ISpecialAdviceAppService {
|
||||
adviceBaseDto.setAdviceDefinitionId(definitionId); // 医嘱定义id
|
||||
// 对应的诊疗医嘱信息
|
||||
activityAdviceBaseDto = iDoctorStationAdviceAppService
|
||||
.getAdviceBaseInfo(adviceBaseDto, null, null, null, null, 1, 1, Whether.NO.getValue(), List.of(3), null)
|
||||
.getAdviceBaseInfo(adviceBaseDto, null, null, null, null, 1, 1, Whether.NO.getValue(), List.of(3), null, null)
|
||||
.getRecords().get(0);
|
||||
|
||||
longServiceRequest.setStatusEnum(RequestStatus.DRAFT.getValue());// 请求状态
|
||||
@@ -348,7 +348,7 @@ public class SpecialAdviceAppServiceImpl implements ISpecialAdviceAppService {
|
||||
adviceBaseDto.setAdviceDefinitionId(transferOrganizationDefinitionId); // 医嘱定义id
|
||||
// 转科的医嘱信息
|
||||
AdviceBaseDto activityAdviceBaseDto = iDoctorStationAdviceAppService
|
||||
.getAdviceBaseInfo(adviceBaseDto, null, null, null, null, 1, 1, Whether.NO.getValue(), List.of(3), null)
|
||||
.getAdviceBaseInfo(adviceBaseDto, null, null, null, null, 1, 1, Whether.NO.getValue(), List.of(3), null, null)
|
||||
.getRecords().get(0);
|
||||
// 保存转科医嘱请求
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
@@ -430,7 +430,7 @@ public class SpecialAdviceAppServiceImpl implements ISpecialAdviceAppService {
|
||||
|
||||
// 出院的医嘱信息
|
||||
AdviceBaseDto activityAdviceBaseDto = iDoctorStationAdviceAppService.getAdviceBaseInfo(null, null, null,
|
||||
List.of(transferOrganizationDefinitionId), null, 1, 1, Whether.NO.getValue(), List.of(3), null).getRecords()
|
||||
List.of(transferOrganizationDefinitionId), null, 1, 1, Whether.NO.getValue(), List.of(3), null, null).getRecords()
|
||||
.get(0);
|
||||
// 保存出院医嘱请求
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
|
||||
@@ -72,6 +72,7 @@ public class RequestFormManageController {
|
||||
*/
|
||||
@PostMapping(value = "/save-surgery")
|
||||
public R<?> saveSurgeryRequestForm(@RequestBody RequestFormSaveDto requestFormSaveDto) {
|
||||
log.info("【Controller】保存手术申请单,typeCode={}", ActivityDefCategory.PROCEDURE.getCode());
|
||||
return iRequestFormManageAppService.saveRequestForm(requestFormSaveDto,
|
||||
ActivityDefCategory.PROCEDURE.getCode());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ import java.time.LocalDate;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RequestFormDto {
|
||||
/**
|
||||
* 手术单号
|
||||
*/
|
||||
private String surgeryNo;
|
||||
/**
|
||||
* 申请时间开始
|
||||
*/
|
||||
|
||||
@@ -77,4 +77,25 @@ public class RequestFormPageDto {
|
||||
* 申请时间
|
||||
*/
|
||||
private String applyTime;
|
||||
/**
|
||||
* 费用类别
|
||||
*/
|
||||
private String feeType;
|
||||
/**
|
||||
* 麻醉方式
|
||||
*/
|
||||
private Integer anesthesiaTypeEnum;
|
||||
/**
|
||||
* 切口等级
|
||||
*/
|
||||
private Integer incisionLevel;
|
||||
/**
|
||||
* 手术等级
|
||||
*/
|
||||
private Integer surgeryLevel;
|
||||
|
||||
/**
|
||||
* 就诊卡号
|
||||
*/
|
||||
private String identifierNo;
|
||||
}
|
||||
|
||||
@@ -93,16 +93,19 @@
|
||||
T7.med_type_code,
|
||||
T8.contract_name,
|
||||
CASE
|
||||
WHEN T1.context_enum = #{activity} AND T1.product_table = 'cli_surgery' THEN T9.surgery_name
|
||||
WHEN T1.context_enum = #{activity} THEN T2."name"
|
||||
WHEN T1.context_enum = #{medication} THEN T3."name"
|
||||
WHEN T1.context_enum = #{device} THEN T4."name"
|
||||
END AS item_name,
|
||||
CASE
|
||||
WHEN T1.context_enum = #{activity} AND T1.product_table = 'cli_surgery' THEN NULL
|
||||
WHEN T1.context_enum = #{activity} THEN T2.yb_no
|
||||
WHEN T1.context_enum = #{medication} THEN T3.yb_no
|
||||
WHEN T1.context_enum = #{device} THEN T4.yb_no
|
||||
END AS yb_no,
|
||||
CASE
|
||||
WHEN T1.context_enum = #{activity} AND T1.product_table = 'cli_surgery' THEN T9.id
|
||||
WHEN T1.context_enum = #{activity} THEN T2.id
|
||||
WHEN T1.context_enum = #{medication} THEN T3.id
|
||||
WHEN T1.context_enum = #{device} THEN T4.id
|
||||
@@ -120,6 +123,10 @@
|
||||
ON T1.context_enum = #{device}
|
||||
AND T1.product_id = T4.id
|
||||
AND T4.delete_flag = '0'
|
||||
LEFT JOIN cli_surgery AS T9
|
||||
ON T1.product_table = 'cli_surgery'
|
||||
AND T1.product_id = T9.id
|
||||
AND T9.delete_flag = '0'
|
||||
LEFT JOIN fin_payment_reconciliation AS T5
|
||||
ON T1.id::TEXT = ANY(string_to_array(T5.charge_item_ids, ','))
|
||||
AND T5.delete_flag = '0'
|
||||
@@ -186,16 +193,19 @@
|
||||
T7.med_type_code,
|
||||
T8.contract_name,
|
||||
CASE
|
||||
WHEN T1.context_enum = #{activity} AND T1.product_table = 'cli_surgery' THEN T9.surgery_name
|
||||
WHEN T1.context_enum = #{activity} THEN T2."name"
|
||||
WHEN T1.context_enum = #{medication} THEN T3."name"
|
||||
WHEN T1.context_enum = #{device} THEN T4."name"
|
||||
END AS item_name,
|
||||
CASE
|
||||
WHEN T1.context_enum = #{activity} AND T1.product_table = 'cli_surgery' THEN NULL
|
||||
WHEN T1.context_enum = #{activity} THEN T2.yb_no
|
||||
WHEN T1.context_enum = #{medication} THEN T3.yb_no
|
||||
WHEN T1.context_enum = #{device} THEN T4.yb_no
|
||||
END AS yb_no,
|
||||
CASE
|
||||
WHEN T1.context_enum = #{activity} AND T1.product_table = 'cli_surgery' THEN T9.id
|
||||
WHEN T1.context_enum = #{activity} THEN T2.id
|
||||
WHEN T1.context_enum = #{medication} THEN T3.id
|
||||
WHEN T1.context_enum = #{device} THEN T4.id
|
||||
@@ -214,6 +224,10 @@
|
||||
ON T1.context_enum = #{device}
|
||||
AND T1.product_id = T4.id
|
||||
AND T4.delete_flag = '0'
|
||||
LEFT JOIN cli_surgery AS T9
|
||||
ON T1.product_table = 'cli_surgery'
|
||||
AND T1.product_id = T9.id
|
||||
AND T9.delete_flag = '0'
|
||||
LEFT JOIN fin_payment_reconciliation AS T5
|
||||
ON T1.id::TEXT = ANY(string_to_array(T5.charge_item_ids, ','))
|
||||
AND T5.delete_flag = '0'
|
||||
|
||||
@@ -13,6 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="patientAge" column="patient_age" />
|
||||
<result property="encounterId" column="encounter_id" />
|
||||
<result property="encounterNo" column="encounter_no" />
|
||||
<result property="patientCardNo" column="patient_card_no" />
|
||||
<result property="applyDoctorId" column="apply_doctor_id" />
|
||||
<result property="applyDoctorName" column="apply_doctor_name" />
|
||||
<result property="applyDeptId" column="apply_dept_id" />
|
||||
@@ -79,6 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
EXTRACT(YEAR FROM AGE(p.birth_date)) as patient_age,
|
||||
s.encounter_id,
|
||||
e.bus_no as encounter_no,
|
||||
pi.identifier_no as patient_card_no,
|
||||
s.apply_doctor_id,
|
||||
COALESCE(s.apply_doctor_name, apply_doc.name) as apply_doctor_name,
|
||||
s.apply_dept_id,
|
||||
@@ -177,6 +179,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
FROM cli_surgery s
|
||||
LEFT JOIN adm_patient p ON s.patient_id = p.id
|
||||
LEFT JOIN adm_encounter e ON s.encounter_id = e.id
|
||||
LEFT JOIN (
|
||||
SELECT patient_id, identifier_no
|
||||
FROM (
|
||||
SELECT patient_id, identifier_no,
|
||||
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
|
||||
FROM adm_patient_identifier
|
||||
WHERE delete_flag = '0'
|
||||
AND identifier_no IS NOT NULL
|
||||
AND identifier_no != ''
|
||||
) t
|
||||
WHERE rn = 1
|
||||
) pi ON s.patient_id = pi.patient_id
|
||||
LEFT JOIN adm_operating_room r ON s.operating_room_id = r.id
|
||||
LEFT JOIN adm_organization ro ON r.organization_id = ro.id
|
||||
LEFT JOIN adm_organization o ON s.org_id = o.id
|
||||
@@ -248,6 +262,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
p.birth_date,
|
||||
<!-- 就诊编号 -->
|
||||
e.bus_no as encounter_no,
|
||||
<!-- 就诊卡号 -->
|
||||
pi.identifier_no as patient_card_no,
|
||||
<!-- 字典文本:使用CASE WHEN避免额外JOIN -->
|
||||
CASE s.surgery_type_enum
|
||||
WHEN 1 THEN '门诊手术'
|
||||
@@ -302,6 +318,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<!-- 只JOIN必要的表:患者和就诊 -->
|
||||
LEFT JOIN adm_patient p ON s.patient_id = p.id
|
||||
LEFT JOIN adm_encounter e ON s.encounter_id = e.id
|
||||
<!-- 关联患者标识表获取就诊卡号 -->
|
||||
LEFT JOIN (
|
||||
SELECT patient_id, identifier_no
|
||||
FROM (
|
||||
SELECT patient_id, identifier_no,
|
||||
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
|
||||
FROM adm_patient_identifier
|
||||
WHERE delete_flag = '0'
|
||||
AND identifier_no IS NOT NULL
|
||||
AND identifier_no != ''
|
||||
) t
|
||||
WHERE rn = 1
|
||||
) pi ON s.patient_id = pi.patient_id
|
||||
<where>
|
||||
s.delete_flag = '0'
|
||||
<if test="ew.sqlSegment != null and ew.sqlSegment != ''">
|
||||
|
||||
@@ -30,13 +30,26 @@
|
||||
cs.apply_dept_name,
|
||||
cs.org_id,
|
||||
o.name AS org_name,
|
||||
cs.main_surgeon_name AS surgeon_name
|
||||
cs.main_surgeon_name AS surgeon_name,
|
||||
COALESCE(pi.identifier_no, ap.bus_no, '') AS identifierNo
|
||||
FROM op_schedule os
|
||||
LEFT JOIN adm_patient ap ON os.patient_id = ap.id
|
||||
LEFT JOIN cli_surgery cs ON os.patient_id = cs.patient_id
|
||||
LEFT JOIN cli_surgery cs ON os.oper_code = cs.surgery_no AND cs.delete_flag = '0'
|
||||
LEFT JOIN adm_organization o ON cs.org_id = o.id
|
||||
LEFT JOIN sys_tenant st ON st.id = os.tenant_id
|
||||
LEFT JOIN sys_user su ON su.user_id = os.creator_id
|
||||
LEFT JOIN (
|
||||
SELECT patient_id, identifier_no
|
||||
FROM (
|
||||
SELECT patient_id, identifier_no,
|
||||
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
|
||||
FROM adm_patient_identifier
|
||||
WHERE delete_flag = '0'
|
||||
AND identifier_no IS NOT NULL
|
||||
AND identifier_no != ''
|
||||
) t
|
||||
WHERE rn = 1
|
||||
) pi ON os.patient_id = pi.patient_id
|
||||
<where>
|
||||
<if test="dto.tenantId != null">
|
||||
AND os.tenant_id = #{dto.tenantId}
|
||||
@@ -47,8 +60,14 @@
|
||||
<if test="dto.applyDeptId != null and dto.applyDeptId != ''">
|
||||
AND cs.apply_dept_id = #{dto.applyDeptId}
|
||||
</if>
|
||||
<if test="dto.scheduleDate != null">
|
||||
AND os.schedule_date = #{dto.scheduleDate}
|
||||
<if test="dto.scheduleDateStart != null">
|
||||
AND DATE(os.schedule_date) >= #{dto.scheduleDateStart}
|
||||
</if>
|
||||
<if test="dto.scheduleDateEnd != null">
|
||||
AND DATE(os.schedule_date) <= #{dto.scheduleDateEnd}
|
||||
</if>
|
||||
<if test="dto.operCode != null and dto.operCode != ''">
|
||||
AND os.oper_code LIKE CONCAT('%', #{dto.operCode}, '%')
|
||||
</if>
|
||||
AND os.delete_flag = '0'
|
||||
</where>
|
||||
@@ -69,12 +88,25 @@
|
||||
cs.main_surgeon_name AS surgeon_name,
|
||||
cs.apply_doctor_name AS apply_doctor_name,
|
||||
drf.create_time AS apply_time,
|
||||
os.surgery_nature AS surgeryType
|
||||
os.surgery_nature AS surgeryType,
|
||||
COALESCE(pi.identifier_no, ap.bus_no, '') AS identifierNo
|
||||
FROM op_schedule os
|
||||
LEFT JOIN adm_patient ap ON os.patient_id = ap.id
|
||||
LEFT JOIN cli_surgery cs ON os.patient_id = cs.patient_id
|
||||
LEFT JOIN cli_surgery cs ON os.oper_code = cs.surgery_no AND cs.delete_flag = '0'
|
||||
LEFT JOIN adm_organization o ON cs.org_id = o.id
|
||||
LEFT JOIN doc_request_form drf ON drf.prescription_no=cs.surgery_no
|
||||
LEFT JOIN (
|
||||
SELECT patient_id, identifier_no
|
||||
FROM (
|
||||
SELECT patient_id, identifier_no,
|
||||
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
|
||||
FROM adm_patient_identifier
|
||||
WHERE delete_flag = '0'
|
||||
AND identifier_no IS NOT NULL
|
||||
AND identifier_no != ''
|
||||
) t
|
||||
WHERE rn = 1
|
||||
) pi ON os.patient_id = pi.patient_id
|
||||
WHERE os.schedule_id = #{scheduleId}
|
||||
LIMIT 1
|
||||
</select>
|
||||
@@ -117,13 +149,26 @@
|
||||
cs.apply_dept_name,
|
||||
cs.org_id,
|
||||
o.name AS org_name,
|
||||
cs.main_surgeon_name AS surgeon_name
|
||||
cs.main_surgeon_name AS surgeon_name,
|
||||
COALESCE(pi.identifier_no, ap.bus_no, '') AS identifierNo
|
||||
FROM op_schedule os
|
||||
LEFT JOIN adm_patient ap ON os.patient_id = ap.id
|
||||
LEFT JOIN cli_surgery cs ON os.patient_id = cs.patient_id
|
||||
LEFT JOIN cli_surgery cs ON os.oper_code = cs.surgery_no AND cs.delete_flag = '0'
|
||||
LEFT JOIN adm_organization o ON cs.org_id = o.id
|
||||
LEFT JOIN sys_tenant st ON st.id = os.tenant_id
|
||||
LEFT JOIN sys_user su ON su.user_id = os.creator_id
|
||||
LEFT JOIN (
|
||||
SELECT patient_id, identifier_no
|
||||
FROM (
|
||||
SELECT patient_id, identifier_no,
|
||||
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
|
||||
FROM adm_patient_identifier
|
||||
WHERE delete_flag = '0'
|
||||
AND identifier_no IS NOT NULL
|
||||
AND identifier_no != ''
|
||||
) t
|
||||
WHERE rn = 1
|
||||
) pi ON os.patient_id = pi.patient_id
|
||||
<where>
|
||||
AND os.delete_flag = '0'
|
||||
<if test="dto.patientId != null"> AND os.patient_id = #{dto.patientId}</if>
|
||||
@@ -131,7 +176,8 @@
|
||||
<if test="dto.applyId != null"> AND os.apply_id = #{dto.applyId}</if>
|
||||
<if test="dto.operCode != null and dto.operCode != ''"> AND os.oper_code = #{dto.operCode}</if>
|
||||
<if test="dto.operName != null and dto.operName != ''"> AND os.oper_name LIKE CONCAT('%', #{dto.operName}, '%')</if>
|
||||
<if test="dto.scheduleDate != null"> AND os.schedule_date = #{dto.scheduleDate}</if>
|
||||
<if test="dto.scheduleDateStart != null"> AND DATE(os.schedule_date) >= #{dto.scheduleDateStart}</if>
|
||||
<if test="dto.scheduleDateEnd != null"> AND DATE(os.schedule_date) <= #{dto.scheduleDateEnd}</if>
|
||||
<if test="dto.orgId != null and dto.orgId != ''"> AND cs.org_id = #{dto.orgId}</if>
|
||||
<if test="dto.applyDeptId != null and dto.applyDeptId != ''"> AND cs.apply_dept_id = #{dto.applyDeptId}</if>
|
||||
<if test="dto.patientName != null and dto.patientName != ''"> AND ap.name LIKE CONCAT('%', #{dto.patientName}, '%')</if>
|
||||
@@ -140,8 +186,19 @@
|
||||
</select>
|
||||
<!-- 查询时间段内该手术室是否被占用-->
|
||||
<select id="isScheduleConflict" resultType="java.lang.Boolean">
|
||||
SELECT COUNT(*) > 0 FROM op_schedule WHERE room_code = #{surgeryRoomId}
|
||||
AND entry_time >= #{startTime}
|
||||
AND end_time < #{endTime}
|
||||
SELECT COUNT(*) > 0 FROM op_schedule
|
||||
WHERE room_code = #{surgeryRoomId}
|
||||
AND entry_time <= #{endTime}
|
||||
AND end_time >= #{startTime}
|
||||
AND delete_flag = '0'
|
||||
</select>
|
||||
|
||||
<!-- 检查是否存在重复的手术安排 -->
|
||||
<select id="existsDuplicateSchedule" resultType="java.lang.Boolean">
|
||||
SELECT COUNT(*) > 0 FROM op_schedule
|
||||
WHERE patient_id = #{patientId}
|
||||
AND oper_code = #{operCode}
|
||||
AND oper_name = #{operName}
|
||||
AND delete_flag = '0'
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
T1.id,
|
||||
T1.bus_no,
|
||||
T1.name,
|
||||
T1.permitted_unit_code,
|
||||
T2.price as retail_price
|
||||
FROM wor_activity_definition T1
|
||||
INNER JOIN adm_charge_item_definition T2
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.openhis.web.datadictionary.mapper.LabActivityDefinitionManageMapper">
|
||||
|
||||
<!-- 检验项目分页查询(操作 lab_activity_definition 表,无物理外键) -->
|
||||
<select id="getLabActivityDefinitionPage" parameterType="java.util.Map"
|
||||
resultType="com.openhis.web.datadictionary.dto.DiagnosisTreatmentDto">
|
||||
SELECT
|
||||
T1.id,
|
||||
T1.category_code,
|
||||
T1.bus_no,
|
||||
T1.name,
|
||||
T1.py_str,
|
||||
T1.wb_str,
|
||||
T1.type_enum,
|
||||
T1.permitted_unit_code,
|
||||
T1.org_id,
|
||||
T1.location_id,
|
||||
T1.yb_flag,
|
||||
T1.yb_no,
|
||||
T1.yb_match_flag,
|
||||
T1.status_enum,
|
||||
T1.body_site_code,
|
||||
T1.specimen_code,
|
||||
T1.description_text,
|
||||
T1.rule_id,
|
||||
T1.tenant_id,
|
||||
T1.chrgitm_lv,
|
||||
T1.children_json,
|
||||
T1.pricing_flag,
|
||||
T1.sort_order,
|
||||
T1.service_range,
|
||||
T1.inspection_type_id,
|
||||
T1.fee_package_id,
|
||||
T1.sub_item_id,
|
||||
T3.name AS test_type,
|
||||
T5.package_name,
|
||||
T6.name AS sub_item_name
|
||||
FROM lab_activity_definition T1
|
||||
/* 检验类型关联(逻辑关联,无外键) */
|
||||
LEFT JOIN inspection_type T3
|
||||
ON T1.inspection_type_id = T3.id
|
||||
AND T3.valid_flag = 1
|
||||
/* 费用套餐关联(逻辑关联,无外键) */
|
||||
LEFT JOIN inspection_basic_information T5
|
||||
ON T1.fee_package_id = T5.basic_information_id
|
||||
AND T5.del_flag = false
|
||||
/* 下级医技类型关联(逻辑关联,无外键) */
|
||||
LEFT JOIN inspection_type T6
|
||||
ON T1.sub_item_id = T6.id
|
||||
AND T6.valid_flag = 1
|
||||
<where>
|
||||
T1.delete_flag = '0'
|
||||
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
|
||||
<choose>
|
||||
<when test="ew.customSqlSegment.contains('tenant_id')">
|
||||
${ew.customSqlSegment.replaceFirst('tenant_id', 'T1.tenant_id').replaceFirst('status_enum', 'T1.status_enum').replaceFirst('WHERE', 'AND')}
|
||||
</when>
|
||||
<otherwise>
|
||||
${ew.customSqlSegment.replaceFirst('status_enum', 'T1.status_enum').replaceFirst('WHERE', 'AND')}
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY T1.id DESC
|
||||
</select>
|
||||
|
||||
<!-- 检验项目详情 -->
|
||||
<select id="getLabActivityDefinitionOne" resultType="com.openhis.web.datadictionary.dto.DiagnosisTreatmentDto">
|
||||
SELECT
|
||||
T1.id,
|
||||
T1.category_code,
|
||||
T1.bus_no,
|
||||
T1.name,
|
||||
T1.py_str,
|
||||
T1.wb_str,
|
||||
T1.type_enum,
|
||||
T1.permitted_unit_code,
|
||||
T1.org_id,
|
||||
T1.location_id,
|
||||
T1.yb_flag,
|
||||
T1.yb_no,
|
||||
T1.yb_match_flag,
|
||||
T1.status_enum,
|
||||
T1.body_site_code,
|
||||
T1.specimen_code,
|
||||
T1.description_text,
|
||||
T1.rule_id,
|
||||
T1.tenant_id,
|
||||
T1.chrgitm_lv,
|
||||
T1.children_json,
|
||||
T1.pricing_flag,
|
||||
T1.sort_order,
|
||||
T1.service_range,
|
||||
T1.inspection_type_id,
|
||||
T1.fee_package_id,
|
||||
T1.sub_item_id,
|
||||
T3.name AS test_type,
|
||||
T5.package_name,
|
||||
T6.name AS sub_item_name
|
||||
FROM lab_activity_definition T1
|
||||
LEFT JOIN inspection_type T3
|
||||
ON T1.inspection_type_id = T3.id
|
||||
AND T3.valid_flag = 1
|
||||
LEFT JOIN inspection_basic_information T5
|
||||
ON T1.fee_package_id = T5.basic_information_id
|
||||
AND T5.del_flag = false
|
||||
LEFT JOIN inspection_type T6
|
||||
ON T1.sub_item_id = T6.id
|
||||
AND T6.valid_flag = 1
|
||||
<where>
|
||||
T1.delete_flag = '0'
|
||||
<if test="id != null">
|
||||
AND T1.id = #{id}
|
||||
</if>
|
||||
<if test="tenantId != null">
|
||||
AND T1.tenant_id = #{tenantId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 检验项目下拉列表(轻量级) -->
|
||||
<select id="getLabActivityDefinitionSimpleList" resultType="com.openhis.web.datadictionary.dto.DiagnosisTreatmentDto">
|
||||
SELECT
|
||||
T1.id,
|
||||
T1.bus_no,
|
||||
T1.name,
|
||||
T1.permitted_unit_code
|
||||
FROM lab_activity_definition T1
|
||||
WHERE T1.delete_flag = '0'
|
||||
AND T1.status_enum = #{statusEnum}
|
||||
AND T1.tenant_id = #{tenantId}
|
||||
<if test="searchKey != null and searchKey != ''">
|
||||
AND (
|
||||
T1.name LIKE CONCAT('%', #{searchKey}, '%')
|
||||
OR T1.bus_no LIKE CONCAT('%', #{searchKey}, '%')
|
||||
OR T1.py_str LIKE CONCAT('%', #{searchKey}, '%')
|
||||
)
|
||||
</if>
|
||||
ORDER BY T1.id DESC
|
||||
<if test="searchKey != null and searchKey != ''">
|
||||
LIMIT 1500
|
||||
</if>
|
||||
<if test="searchKey == null or searchKey == ''">
|
||||
LIMIT 500
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -101,6 +101,9 @@
|
||||
<if test="pricingFlag == 1">
|
||||
AND 1 = 2
|
||||
</if>
|
||||
<if test="categoryCode != null and categoryCode != ''">
|
||||
AND t1.category_code = #{categoryCode}
|
||||
</if>
|
||||
<if test="searchKey != null and searchKey != ''">
|
||||
AND (t1.name ILIKE '%' || #{searchKey} || '%' OR t1.py_str ILIKE '%' || #{searchKey} || '%')
|
||||
</if>
|
||||
@@ -468,6 +471,7 @@
|
||||
T1.dose AS dose,
|
||||
T1.dose_unit_code AS dose_unit_code,
|
||||
T4.id AS charge_item_id,
|
||||
T4.unit_price AS unit_price,
|
||||
T4.total_price AS total_price,
|
||||
T4.status_enum AS charge_status,
|
||||
al.id AS position_id,
|
||||
@@ -477,7 +481,9 @@
|
||||
ccd.name AS condition_definition_name,
|
||||
T1.sort_number AS sort_number,
|
||||
T1.based_on_id AS based_on_id,
|
||||
T1.category_enum AS category_enum
|
||||
T1.category_enum AS category_enum,
|
||||
T1.encounter_id AS encounter_id,
|
||||
T1.patient_id AS patient_id
|
||||
FROM med_medication_request AS T1
|
||||
LEFT JOIN med_medication_definition AS T2 ON T2.ID = T1.medication_id
|
||||
AND T2.delete_flag = '0'
|
||||
@@ -520,6 +526,7 @@
|
||||
NULL AS dose,
|
||||
'' AS dose_unit_code,
|
||||
T3.id AS charge_item_id,
|
||||
T3.unit_price AS unit_price,
|
||||
T3.total_price AS total_price,
|
||||
T3.status_enum AS charge_status,
|
||||
al.id AS position_id,
|
||||
@@ -529,7 +536,9 @@
|
||||
'' AS condition_definition_name,
|
||||
99 AS sort_number,
|
||||
T1.based_on_id AS based_on_id,
|
||||
T1.category_enum AS category_enum
|
||||
T1.category_enum AS category_enum,
|
||||
T1.encounter_id AS encounter_id,
|
||||
T1.patient_id AS patient_id
|
||||
FROM wor_device_request AS T1
|
||||
LEFT JOIN adm_device_definition AS T2 ON T2.ID = T1.device_def_id
|
||||
AND T2.delete_flag = '0'
|
||||
@@ -547,7 +556,7 @@
|
||||
AND T1.refund_device_id IS NULL
|
||||
ORDER BY T1.status_enum)
|
||||
UNION ALL
|
||||
(SELECT 3 AS advice_type,
|
||||
(SELECT CASE WHEN T1.category_enum = 4 THEN 6 ELSE COALESCE(T1.category_enum, 3) END AS advice_type,
|
||||
T1.id AS request_id,
|
||||
T1.id || '-3' AS unique_key,
|
||||
'' AS prescription_no,
|
||||
@@ -558,7 +567,7 @@
|
||||
null AS skin_test_flag,
|
||||
null AS inject_flag,
|
||||
null AS group_id,
|
||||
COALESCE(T2.NAME, CASE WHEN T1.content_json IS NOT NULL AND T1.content_json != '' THEN T1.content_json::json->>'adviceName' ELSE NULL END) AS advice_name,
|
||||
COALESCE(T2.NAME, T1.content_json::jsonb->>'surgeryName', T1.content_json::jsonb->>'adviceName') AS advice_name,
|
||||
'' AS volume,
|
||||
'' AS lot_number,
|
||||
T1.quantity AS quantity,
|
||||
@@ -569,6 +578,7 @@
|
||||
NULL AS dose,
|
||||
'' AS dose_unit_code,
|
||||
T3.id AS charge_item_id,
|
||||
T3.unit_price AS unit_price,
|
||||
T3.total_price AS total_price,
|
||||
T3.status_enum AS charge_status,
|
||||
ao.id AS position_id,
|
||||
@@ -578,7 +588,9 @@
|
||||
'' AS condition_definition_name,
|
||||
99 AS sort_number,
|
||||
T1.based_on_id AS based_on_id,
|
||||
T1.category_enum AS category_enum
|
||||
T1.category_enum AS category_enum,
|
||||
T1.encounter_id AS encounter_id,
|
||||
T1.patient_id AS patient_id
|
||||
FROM wor_service_request AS T1
|
||||
LEFT JOIN wor_activity_definition AS T2
|
||||
ON T2.ID = T1.activity_id
|
||||
|
||||
@@ -4,29 +4,54 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.openhis.web.doctorstation.mapper.DoctorStationLabApplyMapper">
|
||||
|
||||
<!-- 根据申请单号查询检验申请单 -->
|
||||
<!-- 根据申请单号查询检验申请单(返回完整字段) -->
|
||||
<select id="getInspectionApplyByApplyNo" resultType="com.openhis.web.doctorstation.dto.DoctorStationLabApplyDto">
|
||||
SELECT apply_no AS applyNo
|
||||
SELECT
|
||||
id AS applicationId,
|
||||
apply_no AS applyNo,
|
||||
patient_id AS patientId,
|
||||
patient_name AS patientName,
|
||||
medicalrecord_number AS medicalrecordNumber,
|
||||
natureof_cost AS natureofCost,
|
||||
visit_no AS visitNo,
|
||||
apply_dept_code AS applyDeptCode,
|
||||
apply_department AS applyDepartment,
|
||||
apply_doc_code AS applyDocCode,
|
||||
apply_doc_name AS applyDocName,
|
||||
apply_time AS applyTime,
|
||||
clinic_diag AS clinicDiag,
|
||||
clinic_desc AS clinicDesc,
|
||||
contraindication AS contraindication,
|
||||
medical_history_summary AS medicalHistorySummary,
|
||||
purposeof_inspection AS purposeofInspection,
|
||||
physical_examination AS physicalExamination,
|
||||
inspection_item AS inspectionItem,
|
||||
specimen_type_code AS specimenTypeCode,
|
||||
specimen_name AS specimenName,
|
||||
priority_code AS priorityCode,
|
||||
apply_status AS applyStatus,
|
||||
apply_remark AS applyRemark,
|
||||
create_time AS createTime,
|
||||
operator_id AS operatorId,
|
||||
create_by AS createBy,
|
||||
tenant_id AS tenantId
|
||||
FROM lab_apply
|
||||
WHERE apply_no = #{applyNo}
|
||||
AND delete_flag = '0'
|
||||
</select>
|
||||
|
||||
<!-- 分页查询检验申请单列表(根据就诊ID查询,按申请时间降序)
|
||||
encounterId: 就诊ID作为查询条件查出患者id(patient_id)再以患者id对申请单进行查询
|
||||
对申请单表(lab_apply)、申请单明细表(lab_apply_item)和就诊表(adm_encounter)进行联合查询(申请单号,检验项目,申请医生,申请单优先级码,申请单状态,金额)-->
|
||||
直接查询申请单表,不关联明细表,避免重复记录-->
|
||||
<select id="getInspectionApplyListPage" resultType="com.openhis.web.doctorstation.dto.DoctorStationLabApplyDto">
|
||||
SELECT t1.apply_no AS applyNo,
|
||||
t1.inspection_item AS inspectionItem,
|
||||
SELECT t1.id AS applicationId,
|
||||
t1.apply_no AS applyNo,
|
||||
t1.inspection_item AS itemName,
|
||||
t1.apply_doc_name AS applyDocName,
|
||||
t1.priority_code AS priorityCode,
|
||||
t2.item_name AS itemName,
|
||||
t1.apply_status AS applyStatus,
|
||||
t2.item_amount AS itemAmount
|
||||
t1.apply_remark AS applyRemark
|
||||
FROM lab_apply AS t1
|
||||
INNER JOIN adm_encounter AS t3 ON t1.patient_id::bigint = t3.patient_id
|
||||
LEFT JOIN lab_apply_item AS t2
|
||||
ON t1.apply_no = t2.apply_no
|
||||
WHERE t1.delete_flag = '0'
|
||||
AND t3.id = #{encounterId}
|
||||
ORDER BY t1.apply_time DESC
|
||||
|
||||
@@ -203,6 +203,7 @@
|
||||
T1.dose AS dose,
|
||||
T1.dose_unit_code AS dose_unit_code,
|
||||
T4.id AS charge_item_id,
|
||||
T4.unit_price AS unit_price,
|
||||
T4.total_price AS total_price,
|
||||
T4.status_enum AS charge_status,
|
||||
al.id AS position_id,
|
||||
@@ -254,6 +255,7 @@
|
||||
NULL AS dose,
|
||||
'' AS dose_unit_code,
|
||||
T3.id AS charge_item_id,
|
||||
T3.unit_price AS unit_price,
|
||||
T3.total_price AS total_price,
|
||||
T3.status_enum AS charge_status,
|
||||
al.id AS position_id,
|
||||
@@ -281,7 +283,7 @@
|
||||
AND T1.refund_device_id IS NULL
|
||||
ORDER BY T1.status_enum)
|
||||
UNION ALL
|
||||
(SELECT 3 AS advice_type,
|
||||
(SELECT CASE WHEN T1.category_enum = 4 THEN 6 ELSE COALESCE(T1.category_enum, 3) END AS advice_type,
|
||||
T1.id AS request_id,
|
||||
T1.id || '-3' AS unique_key,
|
||||
T1.requester_id AS requester_id,
|
||||
@@ -291,7 +293,7 @@
|
||||
null AS skin_test_flag,
|
||||
null AS inject_flag,
|
||||
null AS group_id,
|
||||
T2.NAME AS advice_name,
|
||||
COALESCE(T2.NAME, T1.content_json::jsonb->>'surgeryName') AS advice_name,
|
||||
'' AS volume,
|
||||
'' AS lot_number,
|
||||
T1.quantity AS quantity,
|
||||
@@ -302,6 +304,7 @@
|
||||
NULL AS dose,
|
||||
'' AS dose_unit_code,
|
||||
T3.id AS charge_item_id,
|
||||
T3.unit_price AS unit_price,
|
||||
T3.total_price AS total_price,
|
||||
T3.status_enum AS charge_status,
|
||||
ao.id AS position_id,
|
||||
@@ -309,7 +312,7 @@
|
||||
null AS dispense_per_duration,
|
||||
1 AS part_percent,
|
||||
'' AS condition_definition_name,
|
||||
T1.therapy_enum AS therapyEnum,
|
||||
COALESCE(T1.therapy_enum, 2) AS therapyEnum,
|
||||
99 AS sort_number,
|
||||
T1.based_on_id AS based_on_id
|
||||
FROM wor_service_request AS T1
|
||||
|
||||
@@ -26,12 +26,13 @@
|
||||
<select id="getRequestFormDetail" resultType="com.openhis.web.regdoctorstation.dto.RequestFormDetailQueryDto">
|
||||
SELECT wsr.quantity,
|
||||
wsr.unit_code,
|
||||
wad.NAME AS advice_name,
|
||||
COALESCE(wad.NAME, wsr.content_json::jsonb->>'surgeryName') AS advice_name,
|
||||
aci.total_price
|
||||
FROM wor_service_request AS wsr
|
||||
LEFT JOIN wor_activity_definition AS wad ON wad.ID = wsr.activity_id
|
||||
AND wad.delete_flag = '0'
|
||||
LEFT JOIN adm_charge_item AS aci ON aci.service_id = wsr.ID
|
||||
AND aci.service_table = 'wor_service_request'
|
||||
AND aci.delete_flag = '0'
|
||||
WHERE wsr.delete_flag = '0'
|
||||
AND wsr.prescription_no = #{prescriptionNo}
|
||||
@@ -63,6 +64,11 @@
|
||||
<result column="apply_dept_name" property="applyDeptName"/>
|
||||
<result column="encounter_id" property="encounterId"/>
|
||||
<result column="surgery_type_enum" property="surgeryTypeEnum"/>
|
||||
<result column="fee_type" property="feeType"/>
|
||||
<result column="anesthesia_type_enum" property="anesthesiaTypeEnum"/>
|
||||
<result column="incision_level" property="incisionLevel"/>
|
||||
<result column="surgery_level" property="surgeryLevel"/>
|
||||
<result column="identifier_no" property="identifierNo"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 分页查询申请单 -->
|
||||
@@ -83,12 +89,33 @@
|
||||
cs.main_surgeon_name,
|
||||
cs.apply_dept_id,
|
||||
cs.apply_dept_name,
|
||||
cs.surgery_type_enum
|
||||
cs.surgery_type_enum,
|
||||
cs.anesthesia_type_enum,
|
||||
cs.incision_level,
|
||||
cs.surgery_level,
|
||||
fc.contract_name AS fee_type,
|
||||
COALESCE(pi.identifier_no, ap.bus_no, '') AS identifier_no
|
||||
FROM doc_request_form drf
|
||||
LEFT JOIN cli_surgery cs ON cs.surgery_no = drf.prescription_no
|
||||
LEFT JOIN adm_patient ap ON ap.id = cs.patient_id
|
||||
LEFT JOIN adm_encounter ae ON ae.id = cs.encounter_id
|
||||
LEFT JOIN adm_account aa ON aa.encounter_id = ae.id AND aa.delete_flag = '0'
|
||||
LEFT JOIN fin_contract fc ON fc.bus_no = aa.contract_no AND fc.delete_flag = '0'
|
||||
LEFT JOIN op_schedule os ON os.apply_id = drf.id AND os.delete_flag = '0'
|
||||
LEFT JOIN (
|
||||
SELECT patient_id, identifier_no
|
||||
FROM (
|
||||
SELECT patient_id, identifier_no,
|
||||
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
|
||||
FROM adm_patient_identifier
|
||||
WHERE delete_flag = '0' AND identifier_no IS NOT NULL AND identifier_no != ''
|
||||
) t
|
||||
WHERE rn = 1
|
||||
) pi ON ap.id = pi.patient_id
|
||||
<where>
|
||||
<if test="requestFormDto.surgeryNo != null and requestFormDto.surgeryNo != ''">
|
||||
AND drf.prescription_no LIKE CONCAT('%', #{requestFormDto.surgeryNo}, '%')
|
||||
</if>
|
||||
<if test="requestFormDto.applyTimeStart != null">
|
||||
AND drf.create_time >= #{requestFormDto.applyTimeStart}
|
||||
</if>
|
||||
@@ -102,6 +129,7 @@
|
||||
AND cs.apply_dept_id = #{requestFormDto.applyDeptId}
|
||||
</if>
|
||||
AND drf.delete_flag = '0'
|
||||
AND os.schedule_id IS NULL
|
||||
</where>
|
||||
ORDER BY drf.create_time DESC
|
||||
</select>
|
||||
|
||||
@@ -768,4 +768,36 @@ public class CommonConstants {
|
||||
Integer ACCOUNT_DEVICE_TYPE = 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* 号源槽位状态 (adm_schedule_slot.status)
|
||||
*/
|
||||
public interface SlotStatus {
|
||||
/** 可用 / 待预约 */
|
||||
Integer AVAILABLE = 0;
|
||||
/** 已预约 */
|
||||
Integer BOOKED = 1;
|
||||
/** 已取消 / 已停诊 */
|
||||
Integer CANCELLED = 2;
|
||||
/** 已锁定 */
|
||||
Integer LOCKED = 3;
|
||||
/** 已签到 / 已取号 */
|
||||
Integer CHECKED_IN = 4;
|
||||
/** 已退号 */
|
||||
Integer RETURNED = 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约订单状态 (order_main.status)
|
||||
*/
|
||||
public interface AppointmentOrderStatus {
|
||||
/** 已预约 (待就诊) */
|
||||
Integer BOOKED = 1;
|
||||
/** 已取号 (已就诊) */
|
||||
Integer CHECKED_IN = 2;
|
||||
/** 已取消 */
|
||||
Integer CANCELLED = 3;
|
||||
/** 已退号 */
|
||||
Integer RETURNED = 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,10 +31,20 @@ public enum ChargeItemContext implements HisEnumInterface {
|
||||
*/
|
||||
ACTIVITY(3, "3", "项目"),
|
||||
|
||||
/**
|
||||
* 西药
|
||||
*/
|
||||
WESTERN_MEDICINE(5, "5", "西药"),
|
||||
|
||||
/**
|
||||
* 中成药
|
||||
*/
|
||||
CHINESE_PATENT_MEDICINE(6, "6", "中成药"),
|
||||
|
||||
/**
|
||||
* 挂号
|
||||
*/
|
||||
REGISTER(4, "4", "挂号");
|
||||
REGISTER(7, "7", "挂号");
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
|
||||
@@ -86,7 +86,12 @@ public enum DispenseStatus implements HisEnumInterface {
|
||||
/**
|
||||
* 待退药
|
||||
*/
|
||||
PENDING_REFUND(16, "PRD", "待退药");
|
||||
PENDING_REFUND(16, "PRD", "待退药"),
|
||||
|
||||
/**
|
||||
* 已退药
|
||||
*/
|
||||
RETURNED(17, "RT", "已退药");
|
||||
|
||||
private Integer value;
|
||||
private String code;
|
||||
|
||||
@@ -23,14 +23,19 @@ public enum ItemType implements HisEnumInterface {
|
||||
MEDICINE(1, "1", "药品"),
|
||||
|
||||
/**
|
||||
* 耗材
|
||||
* 医疗活动
|
||||
*/
|
||||
ACTIVITY(3, "3", "医疗活动"),
|
||||
|
||||
/**
|
||||
* 耗材(前端使用值2)
|
||||
*/
|
||||
DEVICE(2, "2", "耗材"),
|
||||
|
||||
/**
|
||||
* 医疗活动
|
||||
* 手术(前端使用值6,避免与耗材冲突)
|
||||
*/
|
||||
ACTIVITY(3, "3", "医疗活动");
|
||||
SURGERY(6, "6", "手术");
|
||||
|
||||
@EnumValue
|
||||
private Integer value;
|
||||
|
||||
@@ -64,6 +64,26 @@ public interface IChargeItemService extends IService<ChargeItem> {
|
||||
*/
|
||||
void updatePaymentStatus(List<Long> chargeItemIdList, Integer value);
|
||||
|
||||
/**
|
||||
* 安全更新收费项目状态(按条件更新,避免并发冲突)
|
||||
*
|
||||
* @param encounterId 就诊ID
|
||||
* @param fromStatusEnum 原状态
|
||||
* @param toStatusEnum 目标状态
|
||||
* @param serviceIds 服务ID列表
|
||||
*/
|
||||
void updateChargeStatusByCondition(Long encounterId, Integer fromStatusEnum, Integer toStatusEnum, List<Long> serviceIds);
|
||||
|
||||
/**
|
||||
* 安全批量更新收费项目状态(逐个更新,避免并发冲突)
|
||||
*
|
||||
* @param encounterId 就诊ID
|
||||
* @param fromStatusEnum 原状态
|
||||
* @param toStatusEnum 目标状态
|
||||
* @param serviceIds 服务ID列表
|
||||
*/
|
||||
void updateChargeStatusByConditionSafe(Long encounterId, Integer fromStatusEnum, Integer toStatusEnum, List<Long> serviceIds);
|
||||
|
||||
/**
|
||||
* 根据表名和id删除费用项
|
||||
*
|
||||
|
||||
@@ -22,12 +22,14 @@ import com.openhis.administration.service.IChargeItemService;
|
||||
import com.openhis.common.enums.*;
|
||||
import com.openhis.common.utils.EnumUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -38,6 +40,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class ChargeItemServiceImpl extends ServiceImpl<ChargeItemMapper, ChargeItem> implements IChargeItemService {
|
||||
|
||||
@Autowired
|
||||
@@ -130,10 +133,93 @@ public class ChargeItemServiceImpl extends ServiceImpl<ChargeItemMapper, ChargeI
|
||||
*/
|
||||
@Override
|
||||
public void updatePaymentStatus(List<Long> chargeItemIdList, Integer value) {
|
||||
baseMapper.update(
|
||||
new ChargeItem().setStatusEnum(value).setPerformerId(SecurityUtils.getLoginUser().getPractitionerId()),
|
||||
new LambdaUpdateWrapper<ChargeItem>().in(ChargeItem::getId, chargeItemIdList).eq(ChargeItem::getDeleteFlag,
|
||||
DelFlag.NO.getCode()));
|
||||
if (chargeItemIdList == null || chargeItemIdList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 逐个更新,避免并发冲突
|
||||
for (Long chargeItemId : chargeItemIdList) {
|
||||
int retryCount = 0;
|
||||
final int maxRetries = 3;
|
||||
|
||||
while (retryCount < maxRetries) {
|
||||
try {
|
||||
// 先查询当前状态,确保更新操作的安全性
|
||||
ChargeItem currentChargeItem = baseMapper.selectById(chargeItemId);
|
||||
|
||||
if (currentChargeItem == null) {
|
||||
log.warn("收费项目不存在,ID: {}", chargeItemId);
|
||||
break; // 项目不存在,跳出重试循环
|
||||
}
|
||||
|
||||
// 检查当前状态是否已经是目标状态,避免不必要的更新
|
||||
if (currentChargeItem.getStatusEnum().equals(value)) {
|
||||
log.debug("收费项目已是目标状态,跳过更新,ID: {}, 状态: {}", chargeItemId, value);
|
||||
break; // 已是目标状态,跳出重试循环
|
||||
}
|
||||
|
||||
// 使用精确的条件更新,包括当前状态,防止并发更新冲突
|
||||
int updatedRows = baseMapper.update(
|
||||
new ChargeItem()
|
||||
.setStatusEnum(value)
|
||||
.setPerformerId(SecurityUtils.getLoginUser().getPractitionerId()),
|
||||
new LambdaUpdateWrapper<ChargeItem>()
|
||||
.eq(ChargeItem::getId, chargeItemId)
|
||||
.eq(ChargeItem::getStatusEnum, currentChargeItem.getStatusEnum()) // 使用当前状态作为条件
|
||||
.eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode()));
|
||||
|
||||
// 如果成功更新了行数,跳出重试循环
|
||||
if (updatedRows > 0) {
|
||||
log.debug("收费项目状态更新成功,ID: {}, 状态: {}", chargeItemId, value);
|
||||
break; // 成功更新,跳出重试循环
|
||||
} else {
|
||||
log.warn("收费项目更新失败,可能已被其他事务更改,ID: {}, 目标状态: {},重试次数: {}",
|
||||
chargeItemId, value, retryCount + 1);
|
||||
|
||||
// 增加重试计数
|
||||
retryCount++;
|
||||
|
||||
// 如果达到最大重试次数,检查最终状态
|
||||
if (retryCount >= maxRetries) {
|
||||
ChargeItem finalChargeItem = baseMapper.selectById(chargeItemId);
|
||||
if (finalChargeItem != null && finalChargeItem.getStatusEnum().equals(value)) {
|
||||
log.debug("收费项目最终已是目标状态,ID: {}", chargeItemId);
|
||||
break; // 最终状态符合预期,跳出重试循环
|
||||
} else {
|
||||
log.warn("收费项目状态更新失败,达到最大重试次数,ID: {}, 期望状态: {}, 当前状态: {}",
|
||||
chargeItemId, value, finalChargeItem != null ? finalChargeItem.getStatusEnum() : "NULL");
|
||||
break; // 达到最大重试次数,跳出重试循环
|
||||
}
|
||||
} else {
|
||||
// 短暂延迟后重试,避免过于频繁的重试
|
||||
try {
|
||||
Thread.sleep(10); // 10毫秒延迟
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
break; // 中断线程,跳出重试循环
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新收费项目状态失败,ID: {}, 状态: {},重试次数: {}", chargeItemId, value, retryCount + 1, e);
|
||||
|
||||
retryCount++;
|
||||
if (retryCount >= maxRetries) {
|
||||
log.error("更新收费项目状态失败,达到最大重试次数,ID: {}, 状态: {}", chargeItemId, value, e);
|
||||
// 不抛出异常,以避免整个事务回滚
|
||||
break; // 达到最大重试次数,跳出重试循环
|
||||
}
|
||||
|
||||
// 短暂延迟后重试
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
break; // 中断线程,跳出重试循环
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,4 +410,130 @@ public class ChargeItemServiceImpl extends ServiceImpl<ChargeItemMapper, ChargeI
|
||||
});
|
||||
return costDetails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateChargeStatusByCondition(Long encounterId, Integer fromStatusEnum, Integer toStatusEnum, List<Long> serviceIds) {
|
||||
if (serviceIds == null || serviceIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用逐个更新的方式,避免批量更新的并发问题
|
||||
for (Long serviceId : serviceIds) {
|
||||
try {
|
||||
int updatedRows = baseMapper.update(
|
||||
new ChargeItem().setStatusEnum(toStatusEnum),
|
||||
new LambdaUpdateWrapper<ChargeItem>()
|
||||
.eq(ChargeItem::getEncounterId, encounterId)
|
||||
.eq(ChargeItem::getStatusEnum, fromStatusEnum) // 确保原状态匹配
|
||||
.eq(ChargeItem::getServiceId, serviceId)
|
||||
.eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())
|
||||
);
|
||||
|
||||
// 如果没有更新任何行,可能是因为状态已经被其他事务更改
|
||||
if (updatedRows == 0) {
|
||||
log.warn("收费项目状态更新失败或无变化,encounterId: {}, serviceId: {}, 原状态: {}, 目标状态: {}",
|
||||
encounterId, serviceId, fromStatusEnum, toStatusEnum);
|
||||
|
||||
// 查询当前状态以供调试
|
||||
List<ChargeItem> currentChargeItems = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<ChargeItem>()
|
||||
.eq(ChargeItem::getEncounterId, encounterId)
|
||||
.eq(ChargeItem::getServiceId, serviceId)
|
||||
.eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())
|
||||
);
|
||||
|
||||
for (ChargeItem item : currentChargeItems) {
|
||||
log.info("收费项目当前状态,ID: {}, 状态: {}", item.getId(), item.getStatusEnum());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新收费项目状态失败,encounterId: {}, serviceId: {}, 原状态: {}, 目标状态: {}",
|
||||
encounterId, serviceId, fromStatusEnum, toStatusEnum, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateChargeStatusByConditionSafe(Long encounterId, Integer fromStatusEnum, Integer toStatusEnum, List<Long> serviceIds) {
|
||||
if (serviceIds == null || serviceIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用逐个更新的方式,避免批量更新的并发问题
|
||||
for (Long serviceId : serviceIds) {
|
||||
int retryCount = 0;
|
||||
final int maxRetries = 3;
|
||||
|
||||
while (retryCount < maxRetries) {
|
||||
try {
|
||||
// 先查询当前符合条件的收费项目
|
||||
List<ChargeItem> chargeItems = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<ChargeItem>()
|
||||
.eq(ChargeItem::getEncounterId, encounterId)
|
||||
.eq(ChargeItem::getStatusEnum, fromStatusEnum)
|
||||
.eq(ChargeItem::getServiceId, serviceId)
|
||||
.eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())
|
||||
);
|
||||
|
||||
if (chargeItems.isEmpty()) {
|
||||
log.debug("未找到符合条件的收费项目,encounterId: {}, serviceId: {}, 原状态: {}",
|
||||
encounterId, serviceId, fromStatusEnum);
|
||||
break; // 没有符合条件的项目,跳出重试循环
|
||||
}
|
||||
|
||||
// 对每个符合条件的收费项目进行更新
|
||||
for (ChargeItem chargeItem : chargeItems) {
|
||||
int updatedRows = baseMapper.update(
|
||||
new ChargeItem().setStatusEnum(toStatusEnum),
|
||||
new LambdaUpdateWrapper<ChargeItem>()
|
||||
.eq(ChargeItem::getId, chargeItem.getId())
|
||||
.eq(ChargeItem::getStatusEnum, fromStatusEnum) // 确保原状态匹配
|
||||
.eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())
|
||||
);
|
||||
|
||||
if (updatedRows > 0) {
|
||||
log.debug("收费项目状态更新成功,ID: {}, 从状态: {} 到状态: {}",
|
||||
chargeItem.getId(), fromStatusEnum, toStatusEnum);
|
||||
} else {
|
||||
log.warn("收费项目状态更新失败,ID: {}, 从状态: {} 到状态: {}",
|
||||
chargeItem.getId(), fromStatusEnum, toStatusEnum);
|
||||
|
||||
// 检查项目当前状态
|
||||
ChargeItem currentChargeItem = baseMapper.selectById(chargeItem.getId());
|
||||
if (currentChargeItem != null) {
|
||||
log.debug("收费项目当前状态,ID: {}, 状态: {}", currentChargeItem.getId(), currentChargeItem.getStatusEnum());
|
||||
|
||||
// 如果已经是目标状态,则认为更新成功
|
||||
if (currentChargeItem.getStatusEnum().equals(toStatusEnum)) {
|
||||
log.debug("收费项目已是目标状态,ID: {}", currentChargeItem.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 成功更新,跳出重试循环
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
retryCount++;
|
||||
log.warn("收费项目状态更新失败,encounterId: {}, serviceId: {}, 原状态: {}, 目标状态: {},重试次数: {}",
|
||||
encounterId, serviceId, fromStatusEnum, toStatusEnum, retryCount, e);
|
||||
|
||||
if (retryCount >= maxRetries) {
|
||||
log.error("收费项目状态更新失败,达到最大重试次数,encounterId: {}, serviceId: {}, 原状态: {}, 目标状态: {}",
|
||||
encounterId, serviceId, fromStatusEnum, toStatusEnum, e);
|
||||
// 不抛出异常,以避免影响整体流程
|
||||
} else {
|
||||
// 短暂延迟后重试
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
break; // 中断线程,跳出重试循环
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.openhis.appointmentmanage.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 预约挂号提交表单 (防篡改设计)
|
||||
*/
|
||||
@Data
|
||||
public class AppointmentBookDTO implements Serializable {
|
||||
|
||||
@NotNull(message = "号源槽位ID不能为空")
|
||||
private Long slotId;
|
||||
|
||||
// 兼容前端发来的旧字段,即使发了我们底层也不用,防报错接收
|
||||
private Long ticketId;
|
||||
|
||||
private Long patientId;
|
||||
|
||||
@NotBlank(message = "患者姓名不能为空")
|
||||
private String patientName;
|
||||
|
||||
@NotBlank(message = "就诊卡号不能为空")
|
||||
private String medicalCard;
|
||||
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
private String phone;
|
||||
|
||||
private Integer gender;
|
||||
|
||||
// 前端传的 tenant_id,我们为了兼容它带下划线的写法
|
||||
private Integer tenant_id;
|
||||
|
||||
// 前端还会强行发这俩危险字段,我们只管接收堵口子,到了后端全丢弃不用
|
||||
private BigDecimal fee;
|
||||
private String regType;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.openhis.appointmentmanage.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 预约配置Entity
|
||||
*
|
||||
* @date 2026-03-23
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "appointment_config")
|
||||
@Accessors(chain = true)
|
||||
public class AppointmentConfig {
|
||||
|
||||
/** 主键ID */
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/** 机构ID(关联 sys_tenant) */
|
||||
private Integer tenantId;
|
||||
|
||||
/** 取消预约时间类型:YEAR/MONTH/DAY */
|
||||
private String cancelAppointmentType;
|
||||
|
||||
/** 取消预约次数限制 */
|
||||
private Integer cancelAppointmentCount;
|
||||
|
||||
/** 有效标志:1=有效,0=无效 */
|
||||
private Integer validFlag;
|
||||
|
||||
/** 创建人 */
|
||||
private String createBy;
|
||||
|
||||
/** 创建时间 */
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/** 更新时间 */
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.openhis.appointmentmanage.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 医生余号汇总DTO(按号源池聚合)
|
||||
*/
|
||||
@Data
|
||||
public class DoctorAvailabilityDTO {
|
||||
private Long doctorId;
|
||||
private String doctorName;
|
||||
private Integer available;
|
||||
private String ticketType;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 号源池明细Entity
|
||||
*
|
||||
@@ -29,12 +31,15 @@ public class ScheduleSlot extends HisBaseEntity {
|
||||
/** 序号 */
|
||||
private Integer seqNo;
|
||||
|
||||
/** 序号状态: 0-可用,1-已预约,2-已取消,3-已过期等 */
|
||||
/** 序号状态: 0-可用,1-已预约,2-已取消/已停诊,3-已锁定,4-已签到,5-已退号 */
|
||||
private Integer status;
|
||||
|
||||
/** 预约订单ID */
|
||||
private Integer orderId;
|
||||
private Long orderId;
|
||||
|
||||
/** 预计叫号时间 */
|
||||
private LocalTime expectTime;
|
||||
|
||||
/** 签到时间 */
|
||||
private Date checkInTime;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.openhis.appointmentmanage.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
/**
|
||||
* 专门用于承接底层的号源池与具体槽位联查结果 (不对外暴露)
|
||||
*/
|
||||
@Data
|
||||
public class TicketSlotDTO {
|
||||
// 基础信息
|
||||
private Long slotId;
|
||||
private Integer seqNo;
|
||||
private Long scheduleId;
|
||||
private String doctor;
|
||||
private Long doctorId;
|
||||
private Long departmentId;
|
||||
private String departmentName;
|
||||
private String fee;
|
||||
private String patientName;
|
||||
private String medicalCard;
|
||||
private Long patientId;
|
||||
private String phone;
|
||||
private Integer orderStatus;
|
||||
private Long orderId;
|
||||
private String orderNo;
|
||||
private String patientGender;
|
||||
private Integer genderEnum;
|
||||
private String idCard;
|
||||
private String encounterId;
|
||||
private String appointmentTime;
|
||||
|
||||
// 底层逻辑判断专属字段
|
||||
private Integer slotStatus;
|
||||
private LocalTime expectTime;
|
||||
private LocalDate scheduleDate;
|
||||
private Integer regType;
|
||||
private Integer poolStatus;
|
||||
private String stopReason;
|
||||
private Boolean isStopped;
|
||||
|
||||
public Boolean getIsStopped() {
|
||||
return isStopped;
|
||||
}
|
||||
|
||||
public void setIsStopped(Boolean isStopped) {
|
||||
this.isStopped = isStopped;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.openhis.appointmentmanage.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 门诊预约挂号查询条件 DTO
|
||||
*/
|
||||
@Data
|
||||
public class TicketQueryDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// 看诊日期 (例如: 2026-03-25)
|
||||
private String date;
|
||||
|
||||
// 号源状态 (unbooked, booked, checked, cancelled, all)
|
||||
private String status;
|
||||
|
||||
// 号源类型 (general: 普通号, expert: 专家号)
|
||||
private String type;
|
||||
|
||||
// 科室名称 (例如: 内科)
|
||||
private String department;
|
||||
|
||||
// 医生ID
|
||||
private Long doctorId;
|
||||
|
||||
// 患者姓名 (模糊搜索)
|
||||
private String name;
|
||||
|
||||
// 就诊卡号 (模糊搜索)
|
||||
private String card;
|
||||
|
||||
// 手机号 (模糊搜索)
|
||||
private String phone;
|
||||
|
||||
// 当前页码 (默认第一页)
|
||||
private Integer page = 1;
|
||||
|
||||
// 每页显示条数 (默认查20条)
|
||||
private Integer limit = 20;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.openhis.appointmentmanage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.openhis.appointmentmanage.domain.AppointmentConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 预约配置Mapper接口
|
||||
*
|
||||
* @author openhis
|
||||
* @date 2026-03-23
|
||||
*/
|
||||
@Mapper
|
||||
public interface AppointmentConfigMapper extends BaseMapper<AppointmentConfig> {
|
||||
}
|
||||
@@ -2,8 +2,56 @@ package com.openhis.appointmentmanage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.openhis.appointmentmanage.domain.SchedulePool;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SchedulePoolMapper extends BaseMapper<SchedulePool> {
|
||||
|
||||
/**
|
||||
* 按号源池实时重算统计值,避免并发场景下计数漂移。
|
||||
*
|
||||
* 说明:available_num 在当前项目中可能为数据库生成列,因此这里仅维护
|
||||
* booked_num / locked_num,剩余号由数据库或查询逻辑计算。
|
||||
*/
|
||||
@Update("""
|
||||
UPDATE adm_schedule_pool p
|
||||
SET
|
||||
booked_num = COALESCE((
|
||||
SELECT COUNT(1)
|
||||
FROM adm_schedule_slot s
|
||||
WHERE s.pool_id = p.id
|
||||
AND s.delete_flag = '0'
|
||||
AND s.status = 1
|
||||
), 0),
|
||||
locked_num = COALESCE((
|
||||
SELECT COUNT(1)
|
||||
FROM adm_schedule_slot s
|
||||
WHERE s.pool_id = p.id
|
||||
AND s.delete_flag = '0'
|
||||
AND s.status = 3
|
||||
), 0),
|
||||
update_time = now()
|
||||
WHERE p.id = #{poolId}
|
||||
AND p.delete_flag = '0'
|
||||
""")
|
||||
int refreshPoolStats(@Param("poolId") Long poolId);
|
||||
|
||||
/**
|
||||
* 签到时更新号源池统计:锁定数-1,已预约数+1
|
||||
*
|
||||
* @param poolId 号源池ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Update("""
|
||||
UPDATE adm_schedule_pool
|
||||
SET locked_num = locked_num - 1,
|
||||
booked_num = booked_num + 1,
|
||||
update_time = NOW()
|
||||
WHERE id = #{poolId}
|
||||
AND locked_num > 0
|
||||
AND delete_flag = '0'
|
||||
""")
|
||||
int updatePoolStatsOnCheckIn(@Param("poolId") Integer poolId);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,64 @@
|
||||
package com.openhis.appointmentmanage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.openhis.appointmentmanage.domain.DoctorAvailabilityDTO;
|
||||
import com.openhis.appointmentmanage.domain.ScheduleSlot;
|
||||
import com.openhis.appointmentmanage.domain.TicketSlotDTO;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.openhis.appointmentmanage.dto.TicketQueryDTO;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Repository
|
||||
public interface ScheduleSlotMapper extends BaseMapper<ScheduleSlot> {
|
||||
//
|
||||
// 多表查询排班信息展示来预约挂号
|
||||
List<TicketSlotDTO> selectAllTicketSlots();
|
||||
|
||||
/**
|
||||
* 根据槽位ID精确查出完整的聚合信息
|
||||
*/
|
||||
TicketSlotDTO selectTicketSlotById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 原子抢占槽位:仅当当前状态=0(可用)时,更新为1(已预约)。
|
||||
*/
|
||||
int lockSlotForBooking(@Param("slotId") Long slotId);
|
||||
|
||||
/**
|
||||
* 按主键更新槽位状态。
|
||||
*/
|
||||
int updateSlotStatus(@Param("slotId") Long slotId, @Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 更新槽位状态并记录签到时间
|
||||
*
|
||||
* @param slotId 槽位ID
|
||||
* @param status 状态
|
||||
* @param checkInTime 签到时间
|
||||
* @return 结果
|
||||
*/
|
||||
int updateSlotStatusAndCheckInTime(@Param("slotId") Long slotId, @Param("status") Integer status, @Param("checkInTime") Date checkInTime);
|
||||
|
||||
/**
|
||||
* 根据槽位ID查询所属号源池ID。
|
||||
*/
|
||||
Long selectPoolIdBySlotId(@Param("slotId") Long slotId);
|
||||
|
||||
/**
|
||||
* 预约成功后,回填对应订单ID到号源槽位。
|
||||
*/
|
||||
int bindOrderToSlot(@Param("slotId") Long slotId, @Param("orderId") Long orderId);
|
||||
|
||||
/**
|
||||
* 带分页和动态条件过滤的真实查询接口
|
||||
*/
|
||||
Page<TicketSlotDTO> selectTicketSlotsPage(Page<TicketSlotDTO> page, @Param("query") TicketQueryDTO query);
|
||||
|
||||
/**
|
||||
* 按号源池聚合医生余号(不受分页影响)。
|
||||
*/
|
||||
List<DoctorAvailabilityDTO> selectDoctorAvailabilitySummary(@Param("query") TicketQueryDTO query);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.openhis.appointmentmanage.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.openhis.appointmentmanage.domain.AppointmentConfig;
|
||||
|
||||
/**
|
||||
* 预约配置Service接口
|
||||
*
|
||||
* @author openhis
|
||||
* @date 2026-03-23
|
||||
*/
|
||||
public interface IAppointmentConfigService extends IService<AppointmentConfig> {
|
||||
|
||||
/**
|
||||
* 根据机构ID获取预约配置
|
||||
*
|
||||
* @param tenantId 机构ID
|
||||
* @return 预约配置
|
||||
*/
|
||||
AppointmentConfig getConfigByTenantId(Integer tenantId);
|
||||
|
||||
/**
|
||||
* 保存或更新预约配置
|
||||
*
|
||||
* @param appointmentConfig 预约配置
|
||||
* @return 结果
|
||||
*/
|
||||
int saveOrUpdateConfig(AppointmentConfig appointmentConfig);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.openhis.appointmentmanage.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.openhis.appointmentmanage.domain.AppointmentConfig;
|
||||
import com.openhis.appointmentmanage.mapper.AppointmentConfigMapper;
|
||||
import com.openhis.appointmentmanage.service.IAppointmentConfigService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 预约配置Service实现类
|
||||
*
|
||||
* @author openhis
|
||||
* @date 2026-03-23
|
||||
*/
|
||||
@Service
|
||||
public class AppointmentConfigServiceImpl
|
||||
extends ServiceImpl<AppointmentConfigMapper, AppointmentConfig>
|
||||
implements IAppointmentConfigService {
|
||||
|
||||
@Override
|
||||
public AppointmentConfig getConfigByTenantId(Integer tenantId) {
|
||||
LambdaQueryWrapper<AppointmentConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AppointmentConfig::getTenantId, tenantId)
|
||||
.eq(AppointmentConfig::getValidFlag, 1);
|
||||
return this.getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveOrUpdateConfig(AppointmentConfig appointmentConfig) {
|
||||
if (appointmentConfig.getId() == null) {
|
||||
// 新增
|
||||
appointmentConfig.setCreateTime(LocalDateTime.now());
|
||||
appointmentConfig.setUpdateTime(LocalDateTime.now());
|
||||
return this.baseMapper.insert(appointmentConfig) > 0 ? 1 : 0;
|
||||
} else {
|
||||
// 更新
|
||||
appointmentConfig.setUpdateTime(LocalDateTime.now());
|
||||
return this.baseMapper.updateById(appointmentConfig) > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public class CheckPackageDetail {
|
||||
private String dose;
|
||||
|
||||
/** 途径 */
|
||||
@TableField("\"method\"")
|
||||
private String method;
|
||||
|
||||
/** 频次 */
|
||||
@@ -53,6 +54,10 @@ public class CheckPackageDetail {
|
||||
/** 数量 */
|
||||
private Integer quantity;
|
||||
|
||||
/** 单位 */
|
||||
@TableField("\"unit\"")
|
||||
private String unit;
|
||||
|
||||
/** 单价 */
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import lombok.experimental.Accessors;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Order extends HisBaseEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@TableId(type = IdType.AUTO)
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
|
||||
@@ -32,4 +32,14 @@ public interface OrderMapper extends BaseMapper<Order> {
|
||||
int updateOrderStatusById(Long id, Integer status);
|
||||
|
||||
int updateOrderCancelInfoById(Long id, Date cancelTime, String cancelReason);
|
||||
|
||||
/**
|
||||
* 更新订单支付状态
|
||||
*
|
||||
* @param orderId 订单ID
|
||||
* @param payStatus 支付状态:0-未支付,1-已支付
|
||||
* @param payTime 支付时间
|
||||
* @return 结果
|
||||
*/
|
||||
int updatePayStatus(@Param("orderId") Long orderId, @Param("payStatus") Integer payStatus, @Param("payTime") Date payTime);
|
||||
}
|
||||
|
||||
@@ -33,4 +33,14 @@ public interface IOrderService extends IService<Order> {
|
||||
Order createAppointmentOrder(Map<String, Object> params);
|
||||
|
||||
int cancelAppointmentOrder(Long orderId, String cancelReason);
|
||||
|
||||
/**
|
||||
* 统计患者在指定机构、指定起始时间后的取消预约次数
|
||||
*
|
||||
* @param patientId 患者ID
|
||||
* @param tenantId 机构ID
|
||||
* @param startTime 起始时间
|
||||
* @return 取消次数
|
||||
*/
|
||||
long countPatientCancellations(Long patientId, Integer tenantId, java.time.LocalDateTime startTime);
|
||||
}
|
||||
|
||||
@@ -74,10 +74,10 @@ public interface ITicketService extends IService<Ticket> {
|
||||
/**
|
||||
* 预约号源
|
||||
*
|
||||
* @param params 预约参数
|
||||
* @param dto 预约参数
|
||||
* @return 结果
|
||||
*/
|
||||
int bookTicket(Map<String, Object> params);
|
||||
int bookTicket(com.openhis.appointmentmanage.domain.AppointmentBookDTO dto);
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
@@ -85,7 +85,7 @@ public interface ITicketService extends IService<Ticket> {
|
||||
* @param ticketId 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
int cancelTicket(Long ticketId);
|
||||
int cancelTicket(Long slotId);
|
||||
|
||||
/**
|
||||
* 取号
|
||||
@@ -93,7 +93,7 @@ public interface ITicketService extends IService<Ticket> {
|
||||
* @param ticketId 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
int checkInTicket(Long ticketId);
|
||||
int checkInTicket(Long slotId);
|
||||
|
||||
/**
|
||||
* 停诊
|
||||
@@ -101,5 +101,5 @@ public interface ITicketService extends IService<Ticket> {
|
||||
* @param ticketId 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
int cancelConsultation(Long ticketId);
|
||||
int cancelConsultation(Long slotId);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.core.common.utils.AssignSeqUtil;
|
||||
import com.openhis.clinical.domain.Order;
|
||||
import com.openhis.clinical.domain.Ticket;
|
||||
import com.openhis.clinical.mapper.OrderMapper;
|
||||
import com.openhis.clinical.mapper.TicketMapper;
|
||||
import com.openhis.clinical.service.IOrderService;
|
||||
import com.openhis.common.constant.CommonConstants.AppointmentOrderStatus;
|
||||
import com.openhis.common.enums.AssignSeqEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -23,9 +22,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Resource
|
||||
private TicketMapper ticketMapper;
|
||||
|
||||
@Resource
|
||||
private AssignSeqUtil assignSeqUtil;
|
||||
|
||||
@@ -86,25 +82,21 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
|
||||
@Override
|
||||
public Order createAppointmentOrder(Map<String, Object> params) {
|
||||
Long slotId = params.get("slotId") != null ? Long.valueOf(params.get("slotId").toString()) : null;
|
||||
Long slotId = (Long) params.get("slotId");
|
||||
if (slotId == null) {
|
||||
throw new RuntimeException("号源ID不能为空");
|
||||
}
|
||||
|
||||
Ticket ticket = ticketMapper.selectTicketById(slotId);
|
||||
if (ticket == null) {
|
||||
throw new RuntimeException("号源不存在");
|
||||
}
|
||||
|
||||
Order order = new Order();
|
||||
order.setId(null); // 显式置空,确保触发数据库自增,避免 MP 预分配雪花 ID 的干扰
|
||||
String orderNo = assignSeqUtil.getSeq(AssignSeqEnum.ORDER_NUM.getPrefix(), 18);
|
||||
order.setOrderNo(orderNo);
|
||||
|
||||
Long patientId = params.get("patientId") != null ? Long.valueOf(params.get("patientId").toString()) : null;
|
||||
String patientName = params.get("patientName") != null ? params.get("patientName").toString() : null;
|
||||
String medicalCard = params.get("medicalCard") != null ? params.get("medicalCard").toString() : null;
|
||||
String phone = params.get("phone") != null ? params.get("phone").toString() : null;
|
||||
Integer gender = params.get("gender") != null ? Integer.valueOf(params.get("gender").toString()) : null;
|
||||
Long patientId = (Long) params.get("patientId");
|
||||
String patientName = (String) params.get("patientName");
|
||||
String medicalCard = (String) params.get("medicalCard");
|
||||
String phone = (String) params.get("phone");
|
||||
Integer gender = (Integer) params.get("gender");
|
||||
|
||||
order.setPatientId(patientId);
|
||||
order.setPatientName(patientName);
|
||||
@@ -113,28 +105,31 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
order.setGender(gender);
|
||||
|
||||
order.setSlotId(slotId);
|
||||
order.setDepartmentId(ticket.getDepartmentId());
|
||||
order.setDepartmentName(ticket.getDepartment());
|
||||
order.setDoctorId(ticket.getDoctorId());
|
||||
order.setDoctorName(ticket.getDoctor());
|
||||
order.setScheduleId((Long) params.get("scheduleId"));
|
||||
order.setDepartmentId((Long) params.get("departmentId"));
|
||||
order.setDepartmentName((String) params.get("departmentName"));
|
||||
order.setDoctorId((Long) params.get("doctorId"));
|
||||
order.setDoctorName((String) params.get("doctorName"));
|
||||
|
||||
String regType = params.get("regType") != null ? params.get("regType").toString() : "普通";
|
||||
order.setRegType(regType);
|
||||
String regType = (String) params.get("regType");
|
||||
order.setRegType(regType != null ? regType : "普通");
|
||||
|
||||
BigDecimal fee = params.get("fee") != null ? new BigDecimal(params.get("fee").toString()) : BigDecimal.ZERO;
|
||||
order.setFee(fee);
|
||||
BigDecimal fee = parseFee(params.get("fee"));
|
||||
order.setFee(fee != null ? fee : BigDecimal.ZERO);
|
||||
|
||||
Date appointmentDate = new Date();
|
||||
order.setAppointmentDate(appointmentDate);
|
||||
order.setAppointmentTime(new Date());
|
||||
|
||||
order.setStatus(1);
|
||||
// appointmentDate / appointmentTime 由调用方(TicketServiceImpl)在强类型上下文中
|
||||
// 提前合并为 java.util.Date,此处直接使用,不再重复做 LocalDate + LocalTime 类型转换。
|
||||
Date appointmentDateTime = params.get("appointmentDate") instanceof Date
|
||||
? (Date) params.get("appointmentDate")
|
||||
: new Date(); // 兜底:正常业务不应走到这里
|
||||
order.setAppointmentDate(appointmentDateTime);
|
||||
order.setAppointmentTime(appointmentDateTime);
|
||||
order.setStatus(AppointmentOrderStatus.BOOKED);
|
||||
order.setPayStatus(0);
|
||||
order.setVersion(0);
|
||||
|
||||
// 设置租户ID
|
||||
Integer tenantId = params.get("tenant_id") != null ? Integer.valueOf(params.get("tenant_id").toString()) : null;
|
||||
order.setTenantId(tenantId);
|
||||
order.setTenantId((Integer) params.get("tenant_id"));
|
||||
|
||||
order.setCreateTime(new Date());
|
||||
order.setUpdateTime(new Date());
|
||||
@@ -144,20 +139,56 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
return order;
|
||||
}
|
||||
|
||||
private BigDecimal parseFee(Object feeObj) {
|
||||
if (feeObj == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
if (feeObj instanceof BigDecimal) {
|
||||
return (BigDecimal) feeObj;
|
||||
}
|
||||
if (feeObj instanceof Number) {
|
||||
return BigDecimal.valueOf(((Number) feeObj).doubleValue());
|
||||
}
|
||||
if (feeObj instanceof String) {
|
||||
String feeStr = ((String) feeObj).trim();
|
||||
if (feeStr.isEmpty()) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
try {
|
||||
return new BigDecimal(feeStr);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new RuntimeException("挂号费格式错误: " + feeStr);
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("挂号费类型错误: " + feeObj.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cancelAppointmentOrder(Long orderId, String cancelReason) {
|
||||
Order order = orderMapper.selectOrderById(orderId);
|
||||
if (order == null) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
if (order.getStatus() == 3) {
|
||||
if (AppointmentOrderStatus.CANCELLED.equals(order.getStatus())) {
|
||||
throw new RuntimeException("订单已取消");
|
||||
}
|
||||
if (order.getStatus() == 2) {
|
||||
if (AppointmentOrderStatus.CHECKED_IN.equals(order.getStatus())) {
|
||||
throw new RuntimeException("订单已完成,无法取消");
|
||||
}
|
||||
|
||||
Date cancelTime = new Date();
|
||||
return orderMapper.updateOrderCancelInfoById(orderId, cancelTime, cancelReason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countPatientCancellations(Long patientId, Integer tenantId, java.time.LocalDateTime startTime) {
|
||||
if (patientId == null || tenantId == null || startTime == null) {
|
||||
return 0;
|
||||
}
|
||||
return this.count(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Order>()
|
||||
.eq(Order::getPatientId, patientId)
|
||||
.eq(Order::getTenantId, tenantId)
|
||||
.ge(Order::getCancelTime, startTime)
|
||||
.eq(Order::getStatus, AppointmentOrderStatus.CANCELLED));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,31 @@ package com.openhis.clinical.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.openhis.appointmentmanage.domain.AppointmentConfig;
|
||||
import com.openhis.appointmentmanage.service.IAppointmentConfigService;
|
||||
import com.openhis.appointmentmanage.domain.TicketSlotDTO;
|
||||
import com.openhis.appointmentmanage.domain.ScheduleSlot;
|
||||
import com.openhis.appointmentmanage.mapper.SchedulePoolMapper;
|
||||
import com.openhis.appointmentmanage.mapper.ScheduleSlotMapper;
|
||||
import com.openhis.clinical.domain.Order;
|
||||
import com.openhis.clinical.domain.Ticket;
|
||||
import com.openhis.clinical.mapper.TicketMapper;
|
||||
import com.openhis.clinical.service.IOrderService;
|
||||
import com.openhis.clinical.service.ITicketService;
|
||||
import com.openhis.common.constant.CommonConstants.AppointmentOrderStatus;
|
||||
import com.openhis.common.constant.CommonConstants.SlotStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -33,6 +47,18 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
|
||||
@Resource
|
||||
private IOrderService orderService;
|
||||
|
||||
@Resource
|
||||
private ScheduleSlotMapper scheduleSlotMapper;
|
||||
|
||||
@Resource
|
||||
private SchedulePoolMapper schedulePoolMapper;
|
||||
|
||||
@Resource
|
||||
private com.openhis.clinical.mapper.OrderMapper orderMapper;
|
||||
|
||||
@Resource
|
||||
private IAppointmentConfigService appointmentConfigService;
|
||||
|
||||
/**
|
||||
* 查询号源列表
|
||||
*
|
||||
@@ -114,154 +140,255 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
|
||||
/**
|
||||
* 预约号源
|
||||
*
|
||||
* @param params 预约参数
|
||||
* @param dto 预约参数
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int bookTicket(Map<String, Object> params) {
|
||||
Long ticketId = Long.valueOf(params.get("ticketId").toString());
|
||||
Long patientId = params.get("patientId") != null ? Long.valueOf(params.get("patientId").toString()) : null;
|
||||
String patientName = params.get("patientName") != null ? params.get("patientName").toString() : null;
|
||||
String medicalCard = params.get("medicalCard") != null ? params.get("medicalCard").toString() : null;
|
||||
String phone = params.get("phone") != null ? params.get("phone").toString() : null;
|
||||
public int bookTicket(com.openhis.appointmentmanage.domain.AppointmentBookDTO dto) {
|
||||
Long slotId = dto.getSlotId();
|
||||
|
||||
logger.debug("开始预约号源,ticketId: {}, patientId: {}, patientName: {}", ticketId, patientId, patientName);
|
||||
logger.debug("开始执行纯净打单路线,slotId: {}, patientName: {}", slotId, dto.getPatientName());
|
||||
|
||||
Ticket ticket = ticketMapper.selectTicketById(ticketId);
|
||||
if (ticket == null) {
|
||||
logger.error("号源不存在,ticketId: {}", ticketId);
|
||||
throw new RuntimeException("号源不存在");
|
||||
// 1. 检查患者取消预约次数限制(应在预约挂号时限制,而非取消预约时)
|
||||
Integer tenantId = dto.getTenant_id();
|
||||
Long patientId = dto.getPatientId();
|
||||
if (tenantId != null && patientId != null) {
|
||||
AppointmentConfig config = appointmentConfigService.getConfigByTenantId(tenantId);
|
||||
if (config != null && config.getCancelAppointmentCount() != null
|
||||
&& config.getCancelAppointmentCount() > 0) {
|
||||
// 计算当前周期的起始时间
|
||||
LocalDateTime startTime = calculatePeriodStartTime(config.getCancelAppointmentType());
|
||||
// 统计已取消次数
|
||||
long cancelledCount = orderService.countPatientCancellations(patientId, tenantId, startTime);
|
||||
if (cancelledCount >= config.getCancelAppointmentCount()) {
|
||||
String periodName = getPeriodName(config.getCancelAppointmentType());
|
||||
throw new RuntimeException("由于您在" + periodName + "内累计取消预约已达" + cancelledCount + "次,触发系统限制,暂时无法在线预约,请联系分诊台或咨询客服。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("查询到号源信息,id: {}, status: {}, deleteFlag: {}", ticket.getId(), ticket.getStatus(), ticket.getDeleteFlag());
|
||||
// 2. 直查物理大底座!
|
||||
TicketSlotDTO slot = scheduleSlotMapper.selectTicketSlotById(slotId);
|
||||
|
||||
// 详细调试:检查状态字符串的详细信息
|
||||
String status = ticket.getStatus();
|
||||
logger.debug("状态字符串详细信息: value='{}', length={}, isNull={}", status, status != null ? status.length() : "null", status == null);
|
||||
if (status != null) {
|
||||
StringBuilder charInfo = new StringBuilder();
|
||||
for (int i = 0; i < status.length(); i++) {
|
||||
charInfo.append(status.charAt(i)).append("(").append((int) status.charAt(i)).append(") ");
|
||||
if (slot == null) {
|
||||
logger.error("安全拦截:号源底库核对失败,slotId: {}", slotId);
|
||||
throw new RuntimeException("号源数据不存在");
|
||||
}
|
||||
logger.debug("状态字符串字符信息: {}", charInfo.toString());
|
||||
if (slot.getSlotStatus() != null && !SlotStatus.AVAILABLE.equals(slot.getSlotStatus())) {
|
||||
throw new RuntimeException("手慢了!该号源已刚刚被他人抢占");
|
||||
}
|
||||
if (Boolean.TRUE.equals(slot.getIsStopped())) {
|
||||
throw new RuntimeException("该排班医生已停诊");
|
||||
}
|
||||
|
||||
// 详细调试:检查每个状态比较的结果
|
||||
boolean isUnbooked = "unbooked".equals(status);
|
||||
boolean isLocked = "locked".equals(status);
|
||||
boolean isCancelled = "cancelled".equals(status);
|
||||
boolean isChecked = "checked".equals(status);
|
||||
boolean isBooked = "booked".equals(status);
|
||||
logger.debug("状态比较结果: unbooked={}, locked={}, cancelled={}, checked={}, booked={}",
|
||||
isUnbooked, isLocked, isCancelled, isChecked, isBooked);
|
||||
|
||||
if (!isUnbooked && !isLocked && !isCancelled && !isChecked && !isBooked) {
|
||||
logger.error("号源不可预约,id: {}, status: {}", ticket.getId(), ticket.getStatus());
|
||||
throw new RuntimeException("号源不可预约");
|
||||
// 原子抢占:避免并发下同一槽位被重复预约
|
||||
int lockRows = scheduleSlotMapper.lockSlotForBooking(slotId);
|
||||
if (lockRows <= 0) {
|
||||
throw new RuntimeException("手慢了!该号源已刚刚被他人抢占");
|
||||
}
|
||||
|
||||
params.put("slotId", ticketId);
|
||||
Order order = orderService.createAppointmentOrder(params);
|
||||
// 2. 将 DTO 安全降级转换为 Map 给最底层的建单工厂
|
||||
// 因为建单方法非常底层,通用性强,为了不影响它,我们在这里安全组装 Map
|
||||
|
||||
Ticket updateTicket = new Ticket();
|
||||
updateTicket.setId(ticketId);
|
||||
updateTicket.setStatus("booked");
|
||||
updateTicket.setPatientId(patientId);
|
||||
updateTicket.setPatientName(patientName);
|
||||
updateTicket.setMedicalCard(medicalCard);
|
||||
updateTicket.setPhone(phone);
|
||||
updateTicket.setAppointmentDate(new Date());
|
||||
updateTicket.setAppointmentTime(new Date());
|
||||
// 在持有强类型 DTO 的地方提前合并日期+时间,转为 java.util.Date 后再传入 Map,
|
||||
// 避免将 LocalDate/LocalTime 装箱为 Object 跨层传递时可能出现的类型映射失败(如 MyBatis 将
|
||||
// PostgreSQL date 类型映射为 java.sql.Date 导致 slot.getScheduleDate() 返回 null)。
|
||||
LocalDate scheduleDate = slot.getScheduleDate();
|
||||
LocalTime expectTime = slot.getExpectTime();
|
||||
Date appointmentDateTime;
|
||||
if (scheduleDate != null && expectTime != null) {
|
||||
LocalDateTime ldt = LocalDateTime.of(scheduleDate, expectTime);
|
||||
appointmentDateTime = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
|
||||
} else {
|
||||
// 理论上不应走到这里,若走到说明号源池数据异常
|
||||
appointmentDateTime = new Date();
|
||||
}
|
||||
|
||||
int result = ticketMapper.updateById(updateTicket);
|
||||
logger.debug("预约成功,更新号源状态为booked,result: {}", result);
|
||||
Map<String, Object> safeParams = new java.util.HashMap<>();
|
||||
safeParams.put("slotId", slotId);
|
||||
safeParams.put("scheduleId", slot.getScheduleId());
|
||||
// 直接传入已合并的 Date 对象,OrderServiceImpl 无需再做类型转换
|
||||
safeParams.put("appointmentDate", appointmentDateTime);
|
||||
safeParams.put("appointmentTime", appointmentDateTime);
|
||||
safeParams.put("patientId", dto.getPatientId());
|
||||
safeParams.put("patientName", dto.getPatientName());
|
||||
safeParams.put("medicalCard", dto.getMedicalCard());
|
||||
safeParams.put("phone", dto.getPhone());
|
||||
safeParams.put("gender", dto.getGender());
|
||||
safeParams.put("tenant_id", dto.getTenant_id());
|
||||
|
||||
return result;
|
||||
// 3. 【绝对防御】:强制覆盖!不管前端 DTO 传了什么鬼,全以底层数据库物理表为准!
|
||||
safeParams.put("departmentId", slot.getDepartmentId());
|
||||
safeParams.put("departmentName", slot.getDepartmentName());
|
||||
safeParams.put("doctorId", slot.getDoctorId());
|
||||
safeParams.put("doctorName", slot.getDoctor());
|
||||
safeParams.put("fee", toBigDecimal(slot.getFee()));
|
||||
safeParams.put("regType", slot.getRegType() != null && slot.getRegType() == 1 ? "专家" : "普通");
|
||||
|
||||
// 4. 收银台建单!
|
||||
Order order = orderService.createAppointmentOrder(safeParams);
|
||||
if (order == null || order.getId() == null) {
|
||||
throw new RuntimeException("预约订单创建失败");
|
||||
}
|
||||
|
||||
// 5. 回填订单ID到号源槽位,保证号源与订单一一关联
|
||||
int bindRows = scheduleSlotMapper.bindOrderToSlot(slotId, order.getId());
|
||||
if (bindRows <= 0) {
|
||||
throw new RuntimeException("预约成功但号源回填订单失败,请重试");
|
||||
}
|
||||
|
||||
refreshPoolStatsBySlotId(slotId);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int cancelTicket(Long ticketId) {
|
||||
Ticket ticket = ticketMapper.selectTicketById(ticketId);
|
||||
if (ticket == null) {
|
||||
throw new RuntimeException("号源不存在");
|
||||
public int cancelTicket(Long slotId) {
|
||||
TicketSlotDTO slot = scheduleSlotMapper.selectTicketSlotById(slotId);
|
||||
if (slot == null) {
|
||||
throw new RuntimeException("号源槽位不存在");
|
||||
}
|
||||
if (!"booked".equals(ticket.getStatus()) && !"locked".equals(ticket.getStatus())) {
|
||||
if (slot.getSlotStatus() == null || !SlotStatus.BOOKED.equals(slot.getSlotStatus())) {
|
||||
throw new RuntimeException("号源不可取消预约");
|
||||
}
|
||||
|
||||
List<Order> orders = orderService.selectOrderBySlotId(ticketId);
|
||||
for(Order order:orders){
|
||||
List<Order> orders = orderService.selectOrderBySlotId(slotId);
|
||||
if (orders == null || orders.isEmpty()) {
|
||||
throw new RuntimeException("当前号源没有可取消的预约订单");
|
||||
}
|
||||
|
||||
// 获取订单信息
|
||||
Order latestOrder = orders.get(0);
|
||||
|
||||
// 直接执行取消,不再检查取消限制
|
||||
// 根据需求,取消限制应在预约挂号时检查,而非取消预约时
|
||||
for (Order order : orders) {
|
||||
orderService.cancelAppointmentOrder(order.getId(), "患者取消预约");
|
||||
}
|
||||
|
||||
ticket.setStatus("unbooked");
|
||||
ticket.setPatientId(null);
|
||||
ticket.setPatientName(null);
|
||||
ticket.setMedicalCard(null);
|
||||
ticket.setPhone(null);
|
||||
ticket.setAppointmentDate(null);
|
||||
ticket.setAppointmentTime(null);
|
||||
return ticketMapper.updateTicket(ticket);
|
||||
int updated = scheduleSlotMapper.updateSlotStatus(slotId, SlotStatus.AVAILABLE);
|
||||
if (updated > 0) {
|
||||
refreshPoolStatsBySlotId(slotId);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取号
|
||||
* 取号(签到)
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int checkInTicket(Long ticketId) {
|
||||
// 获取号源信息
|
||||
Ticket ticket = ticketMapper.selectTicketById(ticketId);
|
||||
if (ticket == null) {
|
||||
throw new RuntimeException("号源不存在");
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int checkInTicket(Long slotId) {
|
||||
List<Order> orders = orderService.selectOrderBySlotId(slotId);
|
||||
if (orders == null || orders.isEmpty()) {
|
||||
throw new RuntimeException("当前号源没有可取号的预约订单");
|
||||
}
|
||||
if (!"booked".equals(ticket.getStatus()) && !"locked".equals(ticket.getStatus())) {
|
||||
throw new RuntimeException("号源不可取号");
|
||||
Order latestOrder = orders.get(0);
|
||||
|
||||
// 1. 更新订单状态为已取号,并更新支付状态和支付时间
|
||||
orderService.updateOrderStatusById(latestOrder.getId(), AppointmentOrderStatus.CHECKED_IN);
|
||||
// 更新支付状态为已支付,记录支付时间
|
||||
orderMapper.updatePayStatus(latestOrder.getId(), 1, new Date());
|
||||
|
||||
// 2. 查询号源槽位信息
|
||||
ScheduleSlot slot = scheduleSlotMapper.selectById(slotId);
|
||||
|
||||
// 3. 更新号源槽位状态为已签到,记录签到时间
|
||||
scheduleSlotMapper.updateSlotStatusAndCheckInTime(slotId, SlotStatus.CHECKED_IN, new Date());
|
||||
|
||||
// 4. 更新号源池统计:锁定数-1,已预约数+1
|
||||
if (slot != null && slot.getPoolId() != null) {
|
||||
schedulePoolMapper.updatePoolStatsOnCheckIn(slot.getPoolId());
|
||||
}
|
||||
// 更新号源状态为已取号
|
||||
ticket.setStatus("checked");
|
||||
return ticketMapper.updateTicket(ticket);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停诊
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int cancelConsultation(Long ticketId) {
|
||||
// 获取号源信息
|
||||
Ticket ticket = ticketMapper.selectTicketById(ticketId);
|
||||
if (ticket == null) {
|
||||
throw new RuntimeException("号源不存在");
|
||||
public int cancelConsultation(Long slotId) {
|
||||
TicketSlotDTO slot = scheduleSlotMapper.selectTicketSlotById(slotId);
|
||||
if (slot == null) {
|
||||
throw new RuntimeException("号源槽位不存在");
|
||||
}
|
||||
|
||||
// 检查是否存在相关订单,如果存在则取消
|
||||
List<Order> orders = orderService.selectOrderBySlotId(ticketId);
|
||||
for(Order order:orders){
|
||||
List<Order> orders = orderService.selectOrderBySlotId(slotId);
|
||||
for (Order order : orders) {
|
||||
orderService.cancelAppointmentOrder(order.getId(), "医生停诊");
|
||||
}
|
||||
|
||||
// 更新号源状态为已取消
|
||||
ticket.setStatus("cancelled");
|
||||
ticket.setPatientId(null);
|
||||
ticket.setPatientName(null);
|
||||
ticket.setMedicalCard(null);
|
||||
ticket.setPhone(null);
|
||||
ticket.setAppointmentDate(null);
|
||||
ticket.setAppointmentTime(null);
|
||||
return ticketMapper.updateTicket(ticket);
|
||||
int updated = scheduleSlotMapper.updateSlotStatus(slotId, SlotStatus.CANCELLED);
|
||||
if (updated > 0) {
|
||||
refreshPoolStatsBySlotId(slotId);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据槽位ID找到号源池并刷新 booked_num / locked_num 统计。
|
||||
*/
|
||||
private void refreshPoolStatsBySlotId(Long slotId) {
|
||||
Long poolId = scheduleSlotMapper.selectPoolIdBySlotId(slotId);
|
||||
if (poolId != null) {
|
||||
schedulePoolMapper.refreshPoolStats(poolId);
|
||||
}
|
||||
}
|
||||
|
||||
private BigDecimal toBigDecimal(String fee) {
|
||||
if (fee == null || fee.trim().isEmpty()) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
try {
|
||||
return new BigDecimal(fee.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new RuntimeException("挂号费格式错误: " + fee);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型获取周期名称
|
||||
*/
|
||||
private String getPeriodName(String type) {
|
||||
if ("YEAR".equalsIgnoreCase(type)) {
|
||||
return "年度";
|
||||
} else if ("MONTH".equalsIgnoreCase(type)) {
|
||||
return "月度";
|
||||
} else {
|
||||
return "当日";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据取消预约时间类型计算本周期的起始时间
|
||||
*
|
||||
* @param type YEAR/MONTH/DAY
|
||||
* @return 起始时间
|
||||
*/
|
||||
private LocalDateTime calculatePeriodStartTime(String type) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if ("YEAR".equalsIgnoreCase(type)) {
|
||||
return now.with(TemporalAdjusters.firstDayOfYear()).with(LocalTime.MIN);
|
||||
} else if ("MONTH".equalsIgnoreCase(type)) {
|
||||
return now.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
|
||||
} else {
|
||||
// 默认为 DAY
|
||||
return now.with(LocalTime.MIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.Date;
|
||||
* @date 2025-06-03
|
||||
*/
|
||||
@Data
|
||||
@TableName("doc_ital_signs")
|
||||
@TableName("doc_vital_signs")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class VitalSigns extends HisBaseEntity {
|
||||
|
||||
@@ -46,16 +46,24 @@ public class PaymentRecStaticServiceImpl extends ServiceImpl<PaymentRecStaticMap
|
||||
Map<String, List<ChargeItemDefInfo>> collect;
|
||||
List<PaymentRecStatic> paymentRecStatics = new ArrayList<>();
|
||||
if (paymentStatisticalMethod == PaymentStatisticalMethod.FIN_TYPE_CODE) {
|
||||
collect = chargeItemDefInfoList.stream().collect(Collectors.groupingBy(ChargeItemDefInfo::getTypeCode));
|
||||
collect = chargeItemDefInfoList.stream()
|
||||
.filter(info -> info.getTypeCode() != null)
|
||||
.collect(Collectors.groupingBy(ChargeItemDefInfo::getTypeCode));
|
||||
getPaymentRecStaticList(paymentId, paymentType, paymentStatisticalMethod, collect, paymentRecStatics);
|
||||
} else if (paymentStatisticalMethod == PaymentStatisticalMethod.MED_CHRGITM_TYPE) {
|
||||
collect = chargeItemDefInfoList.stream().collect(Collectors.groupingBy(ChargeItemDefInfo::getYbType));
|
||||
collect = chargeItemDefInfoList.stream()
|
||||
.filter(info -> info.getYbType() != null)
|
||||
.collect(Collectors.groupingBy(ChargeItemDefInfo::getYbType));
|
||||
getPaymentRecStaticList(paymentId, paymentType, paymentStatisticalMethod, collect, paymentRecStatics);
|
||||
} else {
|
||||
collect = chargeItemDefInfoList.stream().collect(Collectors.groupingBy(ChargeItemDefInfo::getTypeCode));
|
||||
collect = chargeItemDefInfoList.stream()
|
||||
.filter(info -> info.getTypeCode() != null)
|
||||
.collect(Collectors.groupingBy(ChargeItemDefInfo::getTypeCode));
|
||||
getPaymentRecStaticList(paymentId, paymentType, PaymentStatisticalMethod.FIN_TYPE_CODE, collect,
|
||||
paymentRecStatics);
|
||||
collect = chargeItemDefInfoList.stream().collect(Collectors.groupingBy(ChargeItemDefInfo::getYbType));
|
||||
collect = chargeItemDefInfoList.stream()
|
||||
.filter(info -> info.getYbType() != null)
|
||||
.collect(Collectors.groupingBy(ChargeItemDefInfo::getYbType));
|
||||
getPaymentRecStaticList(paymentId, paymentType, PaymentStatisticalMethod.MED_CHRGITM_TYPE, collect,
|
||||
paymentRecStatics);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user