76 门诊预约挂号
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.openhis.clinical.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.openhis.clinical.domain.Order;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IOrderService extends IService<Order> {
|
||||
|
||||
List<Order> selectOrderList(Order order);
|
||||
|
||||
Page<Order> selectOrderPage(Page<Order> page, Order order);
|
||||
|
||||
Order selectOrderById(Long id);
|
||||
|
||||
int insertOrder(Order order);
|
||||
|
||||
int updateOrder(Order order);
|
||||
|
||||
int deleteOrderByIds(Long[] ids);
|
||||
|
||||
int deleteOrderById(Long id);
|
||||
|
||||
int countOrders(Map<String, Object> params);
|
||||
|
||||
Order selectOrderBySlotId(Long slotId);
|
||||
|
||||
int updateOrderStatusById(Long id, Integer status);
|
||||
|
||||
int updateOrderCancelInfoById(Long id, java.util.Date cancelTime, String cancelReason);
|
||||
|
||||
Order createAppointmentOrder(Map<String, Object> params);
|
||||
|
||||
int cancelAppointmentOrder(Long orderId, String cancelReason);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.openhis.clinical.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.openhis.clinical.domain.Ticket;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 号源管理Service接口
|
||||
*
|
||||
* @author system
|
||||
*/
|
||||
public interface ITicketService extends IService<Ticket> {
|
||||
|
||||
/**
|
||||
* 查询号源列表
|
||||
*
|
||||
* @param ticket 号源信息
|
||||
* @return 号源集合
|
||||
*/
|
||||
List<Ticket> selectTicketList(Ticket ticket);
|
||||
|
||||
/**
|
||||
* 分页查询号源列表
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param ticket 号源信息
|
||||
* @return 号源集合
|
||||
*/
|
||||
Page<Ticket> selectTicketPage(Page<Ticket> page, Ticket ticket);
|
||||
|
||||
/**
|
||||
* 查询号源信息
|
||||
*
|
||||
* @param id 号源ID
|
||||
* @return 号源信息
|
||||
*/
|
||||
Ticket selectTicketById(Long id);
|
||||
|
||||
/**
|
||||
* 新增号源
|
||||
*
|
||||
* @param ticket 号源信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertTicket(Ticket ticket);
|
||||
|
||||
/**
|
||||
* 修改号源
|
||||
*
|
||||
* @param ticket 号源信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateTicket(Ticket ticket);
|
||||
|
||||
/**
|
||||
* 批量删除号源
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteTicketByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除号源信息
|
||||
*
|
||||
* @param id 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteTicketById(Long id);
|
||||
|
||||
/**
|
||||
* 预约号源
|
||||
*
|
||||
* @param params 预约参数
|
||||
* @return 结果
|
||||
*/
|
||||
int bookTicket(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
int cancelTicket(Long ticketId);
|
||||
|
||||
/**
|
||||
* 取号
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
int checkInTicket(Long ticketId);
|
||||
|
||||
/**
|
||||
* 停诊
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
int cancelConsultation(Long ticketId);
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.openhis.clinical.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.core.common.utils.AssignSeqUtil;
|
||||
import com.core.common.utils.SecurityUtils;
|
||||
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.enums.AssignSeqEnum;
|
||||
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;
|
||||
|
||||
@Service
|
||||
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
|
||||
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Resource
|
||||
private TicketMapper ticketMapper;
|
||||
|
||||
@Resource
|
||||
private AssignSeqUtil assignSeqUtil;
|
||||
|
||||
@Override
|
||||
public List<Order> selectOrderList(Order order) {
|
||||
return orderMapper.selectOrderList(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Order> selectOrderPage(Page<Order> page, Order order) {
|
||||
return orderMapper.selectOrderPage(page, order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order selectOrderById(Long id) {
|
||||
return orderMapper.selectOrderById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertOrder(Order order) {
|
||||
return orderMapper.insertOrder(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOrder(Order order) {
|
||||
return orderMapper.updateOrder(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteOrderByIds(Long[] ids) {
|
||||
return orderMapper.deleteOrderByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteOrderById(Long id) {
|
||||
return orderMapper.deleteOrderById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countOrders(Map<String, Object> params) {
|
||||
return orderMapper.countOrders(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order selectOrderBySlotId(Long slotId) {
|
||||
return orderMapper.selectOrderBySlotId(slotId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOrderStatusById(Long id, Integer status) {
|
||||
return orderMapper.updateOrderStatusById(id, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOrderCancelInfoById(Long id, Date cancelTime, String cancelReason) {
|
||||
return orderMapper.updateOrderCancelInfoById(id, cancelTime, cancelReason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order createAppointmentOrder(Map<String, Object> params) {
|
||||
Long slotId = params.get("slotId") != null ? Long.valueOf(params.get("slotId").toString()) : null;
|
||||
if (slotId == null) {
|
||||
throw new RuntimeException("号源ID不能为空");
|
||||
}
|
||||
|
||||
Ticket ticket = ticketMapper.selectTicketById(slotId);
|
||||
if (ticket == null) {
|
||||
throw new RuntimeException("号源不存在");
|
||||
}
|
||||
|
||||
Order order = new Order();
|
||||
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;
|
||||
|
||||
order.setPatientId(patientId);
|
||||
order.setPatientName(patientName);
|
||||
order.setMedicalCard(medicalCard);
|
||||
order.setPhone(phone);
|
||||
order.setGender(gender);
|
||||
|
||||
order.setSlotId(slotId);
|
||||
order.setDepartmentId(ticket.getDepartmentId());
|
||||
order.setDepartmentName(ticket.getDepartment());
|
||||
order.setDoctorId(ticket.getDoctorId());
|
||||
order.setDoctorName(ticket.getDoctor());
|
||||
|
||||
String regType = params.get("regType") != null ? params.get("regType").toString() : "普通";
|
||||
order.setRegType(regType);
|
||||
|
||||
BigDecimal fee = params.get("fee") != null ? new BigDecimal(params.get("fee").toString()) : BigDecimal.ZERO;
|
||||
order.setFee(fee);
|
||||
|
||||
Date appointmentDate = new Date();
|
||||
order.setAppointmentDate(appointmentDate);
|
||||
order.setAppointmentTime(new Date());
|
||||
|
||||
order.setStatus(1);
|
||||
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.setCreateTime(new Date());
|
||||
order.setUpdateTime(new Date());
|
||||
|
||||
orderMapper.insertOrder(order);
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cancelAppointmentOrder(Long orderId, String cancelReason) {
|
||||
Order order = orderMapper.selectOrderById(orderId);
|
||||
if (order == null) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
if (order.getStatus() == 3) {
|
||||
throw new RuntimeException("订单已取消");
|
||||
}
|
||||
if (order.getStatus() == 2) {
|
||||
throw new RuntimeException("订单已完成,无法取消");
|
||||
}
|
||||
|
||||
Date cancelTime = new Date();
|
||||
return orderMapper.updateOrderCancelInfoById(orderId, cancelTime, cancelReason);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
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.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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 号源管理Service业务层处理
|
||||
*
|
||||
* @author system
|
||||
*/
|
||||
@Service
|
||||
public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> implements ITicketService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TicketServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
private TicketMapper ticketMapper;
|
||||
|
||||
@Resource
|
||||
private IOrderService orderService;
|
||||
|
||||
/**
|
||||
* 查询号源列表
|
||||
*
|
||||
* @param ticket 号源信息
|
||||
* @return 号源集合
|
||||
*/
|
||||
@Override
|
||||
public List<Ticket> selectTicketList(Ticket ticket) {
|
||||
return ticketMapper.selectTicketList(ticket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询号源列表
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param ticket 号源信息
|
||||
* @return 号源集合
|
||||
*/
|
||||
@Override
|
||||
public Page<Ticket> selectTicketPage(Page<Ticket> page, Ticket ticket) {
|
||||
return ticketMapper.selectTicketPage(page, ticket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询号源信息
|
||||
*
|
||||
* @param id 号源ID
|
||||
* @return 号源信息
|
||||
*/
|
||||
@Override
|
||||
public Ticket selectTicketById(Long id) {
|
||||
return ticketMapper.selectTicketById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增号源
|
||||
*
|
||||
* @param ticket 号源信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertTicket(Ticket ticket) {
|
||||
return ticketMapper.insertTicket(ticket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改号源
|
||||
*
|
||||
* @param ticket 号源信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateTicket(Ticket ticket) {
|
||||
return ticketMapper.updateTicket(ticket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除号源
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteTicketByIds(Long[] ids) {
|
||||
return ticketMapper.deleteTicketByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除号源信息
|
||||
*
|
||||
* @param id 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteTicketById(Long id) {
|
||||
return ticketMapper.deleteTicketById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约号源
|
||||
*
|
||||
* @param params 预约参数
|
||||
* @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;
|
||||
|
||||
logger.debug("开始预约号源,ticketId: {}, patientId: {}, patientName: {}", ticketId, patientId, patientName);
|
||||
|
||||
Ticket ticket = ticketMapper.selectTicketById(ticketId);
|
||||
if (ticket == null) {
|
||||
logger.error("号源不存在,ticketId: {}", ticketId);
|
||||
throw new RuntimeException("号源不存在");
|
||||
}
|
||||
|
||||
logger.debug("查询到号源信息,id: {}, status: {}, deleteFlag: {}", ticket.getId(), ticket.getStatus(), ticket.getDeleteFlag());
|
||||
|
||||
// 详细调试:检查状态字符串的详细信息
|
||||
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(") ");
|
||||
}
|
||||
logger.debug("状态字符串字符信息: {}", charInfo.toString());
|
||||
}
|
||||
|
||||
// 详细调试:检查每个状态比较的结果
|
||||
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("号源不可预约");
|
||||
}
|
||||
|
||||
params.put("slotId", ticketId);
|
||||
Order order = orderService.createAppointmentOrder(params);
|
||||
|
||||
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());
|
||||
|
||||
int result = ticketMapper.updateById(updateTicket);
|
||||
logger.debug("预约成功,更新号源状态为booked,result: {}", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int cancelTicket(Long ticketId) {
|
||||
Ticket ticket = ticketMapper.selectTicketById(ticketId);
|
||||
if (ticket == null) {
|
||||
throw new RuntimeException("号源不存在");
|
||||
}
|
||||
if (!"booked".equals(ticket.getStatus()) && !"locked".equals(ticket.getStatus())) {
|
||||
throw new RuntimeException("号源不可取消预约");
|
||||
}
|
||||
|
||||
Order order = orderService.selectOrderBySlotId(ticketId);
|
||||
if (order != null) {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取号
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int checkInTicket(Long ticketId) {
|
||||
// 获取号源信息
|
||||
Ticket ticket = ticketMapper.selectTicketById(ticketId);
|
||||
if (ticket == null) {
|
||||
throw new RuntimeException("号源不存在");
|
||||
}
|
||||
if (!"booked".equals(ticket.getStatus()) && !"locked".equals(ticket.getStatus())) {
|
||||
throw new RuntimeException("号源不可取号");
|
||||
}
|
||||
// 更新号源状态为已取号
|
||||
ticket.setStatus("checked");
|
||||
return ticketMapper.updateTicket(ticket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停诊
|
||||
*
|
||||
* @param ticketId 号源ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int cancelConsultation(Long ticketId) {
|
||||
// 获取号源信息
|
||||
Ticket ticket = ticketMapper.selectTicketById(ticketId);
|
||||
if (ticket == null) {
|
||||
throw new RuntimeException("号源不存在");
|
||||
}
|
||||
|
||||
// 检查是否存在相关订单,如果存在则取消
|
||||
Order order = orderService.selectOrderBySlotId(ticketId);
|
||||
if (order != null) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user