|
@@ -1,12 +1,27 @@
|
|
|
package cn.tr.module.smart.common.service.impl;
|
|
package cn.tr.module.smart.common.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.tr.core.exception.TRExcCode;
|
|
import cn.tr.core.exception.TRExcCode;
|
|
|
import cn.tr.module.smart.app.controller.dto.WxDoctorClinicRoomDTO;
|
|
import cn.tr.module.smart.app.controller.dto.WxDoctorClinicRoomDTO;
|
|
|
import cn.tr.module.smart.app.controller.vo.WxDoctorClinicRoomVO;
|
|
import cn.tr.module.smart.app.controller.vo.WxDoctorClinicRoomVO;
|
|
|
|
|
+import cn.tr.module.smart.common.dto.BizDeptDTO;
|
|
|
|
|
+import cn.tr.module.smart.common.enums.UserTypeEnums;
|
|
|
|
|
+import cn.tr.module.smart.common.po.BizClinicRoomWxUserPO;
|
|
|
|
|
+import cn.tr.module.smart.common.po.BizPatientPO;
|
|
|
|
|
+import cn.tr.module.smart.common.repository.BizClinicRoomWxUserRepository;
|
|
|
|
|
+import cn.tr.module.smart.common.repository.BizPatientRepository;
|
|
|
|
|
+import cn.tr.module.smart.common.service.*;
|
|
|
|
|
+import cn.tr.module.smart.wx.controller.vo.BizPreSurgeryQuestionVO;
|
|
|
import cn.tr.module.smart.wx.controller.vo.BizWxAppletClinicVO;
|
|
import cn.tr.module.smart.wx.controller.vo.BizWxAppletClinicVO;
|
|
|
|
|
+import cn.tr.module.smart.wx.controller.vo.BizWxDeptQuestionVO;
|
|
|
|
|
+import cn.tr.module.smart.wx.dto.BizClinicAddOrEditDTO;
|
|
|
import cn.tr.module.smart.wx.dto.BizWxAppletClinicQueryDTO;
|
|
import cn.tr.module.smart.wx.dto.BizWxAppletClinicQueryDTO;
|
|
|
|
|
+import cn.tr.plugin.security.bo.UserLoginInfoBO;
|
|
|
|
|
+import cn.tr.plugin.security.context.LoginUserContextHolder;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -18,8 +33,8 @@ import cn.tr.module.smart.common.dto.BizClinicRoomDTO;
|
|
|
import cn.tr.module.smart.common.dto.BizClinicRoomQueryDTO;
|
|
import cn.tr.module.smart.common.dto.BizClinicRoomQueryDTO;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
-import cn.tr.module.smart.common.service.IBizClinicRoomService;
|
|
|
|
|
import cn.tr.module.smart.common.mapper.BizClinicRoomMapper;
|
|
import cn.tr.module.smart.common.mapper.BizClinicRoomMapper;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -33,12 +48,172 @@ public class BizClinicRoomServiceImpl implements IBizClinicRoomService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private BizClinicRoomRepository baseRepository;
|
|
private BizClinicRoomRepository baseRepository;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BizPatientRepository patientRepository;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IBizPatientService patientService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BizClinicRoomWxUserRepository clinicRoomWxUserRepository;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ @Lazy
|
|
|
|
|
+ private IBizClinicRoomWxUserService roomWxUserService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IBizQuestionService bizQuestionService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IBizDeptService bizDeptService;
|
|
|
@Override
|
|
@Override
|
|
|
public List<BizWxAppletClinicVO> stdSelectWxAppletClinicList(BizWxAppletClinicQueryDTO query) {
|
|
public List<BizWxAppletClinicVO> stdSelectWxAppletClinicList(BizWxAppletClinicQueryDTO query) {
|
|
|
return baseRepository.stdSelectWxAppletClinicList(query);
|
|
return baseRepository.stdSelectWxAppletClinicList(query);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public BizWxAppletClinicVO stdSelectWxAppletCareClinicByUserId(String currentUserId) {
|
|
|
|
|
+ return baseRepository.stdSelectWxAppletCareClinicByUserId(currentUserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增手术信息 对于手术时间,患者只精确到日,医生端精确到小时
|
|
|
|
|
+ * 1、一个住院号对应1个病人
|
|
|
|
|
+ * 2、一个病人对应多场手术信息
|
|
|
|
|
+ * 3、病人信息中记录最新的手术数据
|
|
|
|
|
+ * @param source
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Boolean stdAddWxApplet(BizClinicAddOrEditDTO source) {
|
|
|
|
|
+ String userId = LoginUserContextHolder.getUser().getUserId();
|
|
|
|
|
+ String patientCode = source.getPatientCode();
|
|
|
|
|
+ Date clinicStartTime = source.getClinicStartTime();
|
|
|
|
|
+ //1、先判断住院号这一天是否已经有患者添加过了
|
|
|
|
|
+ BizClinicRoomPO clinicRoom=baseRepository.stdWxAppletSelectByPatientCodeAndClinicStartTime(patientCode,clinicStartTime);
|
|
|
|
|
+ if (ObjectUtil.isNotNull(clinicRoom)) {
|
|
|
|
|
+ //手术已经存在,判断该手术是否已被患者端监护
|
|
|
|
|
+ BizClinicRoomWxUserPO clinicRoomWxUserPO = clinicRoomWxUserRepository.selectOne(new LambdaQueryWrapper<BizClinicRoomWxUserPO>()
|
|
|
|
|
+ .eq(BizClinicRoomWxUserPO::getClinicRoomId, clinicRoom.getId())
|
|
|
|
|
+ .eq(BizClinicRoomWxUserPO::getWxUserId, userId)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (ObjectUtil.isNotNull(clinicRoomWxUserPO)) {
|
|
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,String.format("住院号{%s}于{%s}已存在手术:{%s},请勿重复添加",patientCode, DateUtil.formatDate(clinicStartTime),clinicRoom.getClinicName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ //若未监护,则证明该手术是由医生端发起的,添加监护信息(手术信息以医生输入为主,如果医生没有输入,则按照病人输入的来)
|
|
|
|
|
+ roomWxUserService.stdWxAppletInsertBizClinicRoomWxUser(userId,clinicRoom.getId());
|
|
|
|
|
+ //更新监护信息
|
|
|
|
|
+ updateClinicInfoBaseOnDoctorByWxApplet(clinicRoom,source);
|
|
|
|
|
+ baseRepository.updateById(clinicRoom);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //手术不存在,则新增手术信息
|
|
|
|
|
+ //1、先判断是否已经添加过了患者信息
|
|
|
|
|
+ BizPatientPO patient = patientRepository.selectOne(new LambdaQueryWrapper<BizPatientPO>()
|
|
|
|
|
+ .eq(BizPatientPO::getPatientCode, patientCode)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if(ObjectUtil.isNull(patient)){
|
|
|
|
|
+ patient=patientService.insertBizPatientAndReturnObj(source);
|
|
|
|
|
+ }
|
|
|
|
|
+ clinicRoom = BizClinicRoomMapper.INSTANCE.convertPO(source);
|
|
|
|
|
+ clinicRoom.setPatientId(patient.getId());
|
|
|
|
|
+ clinicRoom.setFollowUpCount(0);
|
|
|
|
|
+ clinicRoom.setFollowUp(Boolean.FALSE);
|
|
|
|
|
+ this.baseRepository.insert(clinicRoom);
|
|
|
|
|
+ //更新患者绑定的最新手术id
|
|
|
|
|
+ patient.setCurrentClinicId(clinicRoom.getId());
|
|
|
|
|
+ patientRepository.updateById(patient);
|
|
|
|
|
+ //更新微信用户患者列表
|
|
|
|
|
+ roomWxUserService.stdWxAppletInsertBizClinicRoomWxUser(userId,clinicRoom.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ return Boolean.TRUE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 微信端编辑手术信息
|
|
|
|
|
+ * @param source
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Boolean stdEditWxApplet(BizClinicAddOrEditDTO source) {
|
|
|
|
|
+ String id = source.getId();
|
|
|
|
|
+ source.setPatientCode(null);
|
|
|
|
|
+ BizClinicRoomPO clinicRoomPO = baseRepository.selectById(id);
|
|
|
|
|
+ if(ObjectUtil.isNull(clinicRoomPO)){
|
|
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"手术信息不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ BizClinicRoomPO updateSource = BizClinicRoomMapper.INSTANCE.convertPO(source);
|
|
|
|
|
+ //医生已确认数据,则患者只能编辑一些基本信息、如病人名称、年龄、性别
|
|
|
|
|
+ if(StrUtil.equals(clinicRoomPO.getLastModifyUserType(), UserTypeEnums.APP_DOCTOR)){
|
|
|
|
|
+ updateSource.setClinicStartTime(null);
|
|
|
|
|
+ updateSource.setClinicName(null);
|
|
|
|
|
+ updateSource.setDeptName(null);
|
|
|
|
|
+ updateSource.setDeptId(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ return baseRepository.updateById(clinicRoomPO)!=0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public BizWxAppletClinicVO stdSelectWxAppletById(String id) {
|
|
|
|
|
+ return baseRepository.stdSelectWxAppletById(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Integer removeBizClinicByIds(Collection<String> ids) {
|
|
|
|
|
+ UserLoginInfoBO user = LoginUserContextHolder.getUser();
|
|
|
|
|
+ String userId = user.getUserId();
|
|
|
|
|
+ Integer deletedCount = roomWxUserService.stdWxAppletRemoveBizClinicRoomWxUserByUserIdAndIds(userId, ids);
|
|
|
|
|
+ if(deletedCount!=0){
|
|
|
|
|
+ //重新设置当前看护患者
|
|
|
|
|
+ BizWxAppletClinicQueryDTO clinicQuery = new BizWxAppletClinicQueryDTO();
|
|
|
|
|
+ clinicQuery.setUserId(userId);
|
|
|
|
|
+ clinicQuery.setTenantId(user.getTenantId());
|
|
|
|
|
+ List<BizWxAppletClinicVO> clinicList = stdSelectWxAppletClinicList(clinicQuery);
|
|
|
|
|
+ if(CollectionUtil.isNotEmpty(clinicList)){
|
|
|
|
|
+ clinicList= clinicList.stream()
|
|
|
|
|
+ .sorted(Comparator.comparing(BizWxAppletClinicVO::getClinicStartTime)).collect(Collectors.toList());
|
|
|
|
|
+ roomWxUserService.shiftWxAppletCurrent(userId,CollectionUtil.getFirst(clinicList).getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return deletedCount;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public BizPreSurgeryQuestionVO selectPreSurgeryQuestionnaire(String clinicId) {
|
|
|
|
|
+ //判断临床id是否为空
|
|
|
|
|
+ if(StrUtil.isBlank(clinicId)){
|
|
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"参数为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ BizClinicRoomPO clinic = baseRepository.selectById(clinicId);
|
|
|
|
|
+ if (ObjectUtil.isNull(clinic)){
|
|
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"手术信息不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ String deptId = clinic.getDeptId();
|
|
|
|
|
+ Date lastQuestionTime = clinic.getLastQuestionTime();
|
|
|
|
|
+
|
|
|
|
|
+ //判断科室id是否为空
|
|
|
|
|
+ if(StrUtil.isBlank(deptId)){
|
|
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"手术未关联科室");
|
|
|
|
|
+ }
|
|
|
|
|
+ BizDeptDTO bizDeptDTO = bizDeptService.selectBizDeptById(deptId);
|
|
|
|
|
+ if (ObjectUtil.isNull(bizDeptDTO)){
|
|
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"科室信息不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ String groupId = bizDeptDTO.getGroupId();
|
|
|
|
|
+ //通过获取到的groupId查询问卷调查问题表
|
|
|
|
|
+ List<BizWxDeptQuestionVO> questionVOList = bizQuestionService.selectBizQuestionByGroupId(groupId);
|
|
|
|
|
+
|
|
|
|
|
+ BizPreSurgeryQuestionVO result = new BizPreSurgeryQuestionVO();
|
|
|
|
|
+ result.setDataList(questionVOList);
|
|
|
|
|
+ result.setLastQuestionTime(lastQuestionTime);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 根据条件查询诊疗室
|
|
* 根据条件查询诊疗室
|
|
|
*
|
|
*
|
|
@@ -127,4 +302,28 @@ public class BizClinicRoomServiceImpl implements IBizClinicRoomService {
|
|
|
return baseRepository.selectByClinicRoomAndPatientList(source);
|
|
return baseRepository.selectByClinicRoomAndPatientList(source);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 微信小程序基于医生已填写的信息更新数据
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateClinicInfoBaseOnDoctorByWxApplet(BizClinicRoomPO baseInfo,BizClinicAddOrEditDTO source){
|
|
|
|
|
+ if(ObjectUtil.isNull(source)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjectUtil.isNull(baseInfo.getPatientAge())) {
|
|
|
|
|
+ baseInfo.setPatientAge(source.getPatientAge());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isBlank(baseInfo.getDeptId())) {
|
|
|
|
|
+ baseInfo.setDeptId(source.getDeptId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isBlank(baseInfo.getDeptName())) {
|
|
|
|
|
+ baseInfo.setDeptName(source.getDeptName());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isBlank(baseInfo.getClinicName())) {
|
|
|
|
|
+ baseInfo.setClinicName(source.getClinicName());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjectUtil.isNull(baseInfo.getClinicStartTime())) {
|
|
|
|
|
+ baseInfo.setClinicStartTime(source.getClinicStartTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|