package thyyxxk.webserver.service.zhuyuanyisheng; import cn.hutool.extra.spring.SpringUtil; import com.alibaba.fastjson.JSON; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import thyyxxk.webserver.config.exception.ExceptionEnum; import thyyxxk.webserver.constants.GetDateFormat; import thyyxxk.webserver.dao.his.zhuyuanyisheng.ShouShuShenQingDao; import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao; import thyyxxk.webserver.entity.ResultVo; import thyyxxk.webserver.entity.datamodify.GetDropdownBox; import thyyxxk.webserver.entity.dictionary.CodeName; import thyyxxk.webserver.entity.zhuyuanyisheng.query.ChaXunJianChaHeJianYan; import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.OpRecord; import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.ShouShuFanHui; import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.XinZengShouShu; import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.ZdIcd9Cm3; import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYiZhu; import thyyxxk.webserver.service.PublicServer; import thyyxxk.webserver.utils.*; import java.util.*; /** *

* 描述: 手术申请 *

* * @author xc * @date 2022-02-22 15:45 */ @Service @Slf4j public class ShouShuShenQingService { private final ShouShuShenQingDao dao; private final PublicServer publicServer; private final YiZhuLuRuDao yiZhuLuRuDao; private ShouShuShenQingService getThis() { return SpringUtil.getBean(this.getClass()); } public ShouShuShenQingService(ShouShuShenQingDao dao, PublicServer publicServer, YiZhuLuRuDao yiZhuLuRuDao) { this.dao = dao; this.publicServer = publicServer; this.yiZhuLuRuDao = yiZhuLuRuDao; } /** * 获取手术的项目 在 * * @param name 搜索名称 * @param type 搜索类型 * @return */ @DS("his") public ResultVo> obtainSurgicalItems(String name, Integer type) { return ResultVoUtil.success(dao.obtainSurgicalItems(StringUtil.isContainChinese(name), type)); } @DS("his") public ResultVo> getDoctorByOpCode(String opCode) { return ResultVoUtil.success(dao.getDoctorByOpCode(opCode)); } @DS("his") public ResultVo preoperativeDiscussion(String patNo, Integer times, Integer count) { int currentPatientOpCount = dao.currentPatientOpCount(patNo, times); currentPatientOpCount += count; int currentEmrPreoperativelyDiscussCount = dao.currentEmrPreoperativelyDiscussCount(patNo, times); if (currentPatientOpCount > currentEmrPreoperativelyDiscussCount) { return ResultVoUtil.success(true); } return ResultVoUtil.success(false); } public ResultVo> shouShuShenQingCeBianLan() { return ResultVoUtil.success(dao.shouShuShenQingCeBianLan()); } public ResultVo>> huoQuShouShuMingCheng(String patNo, Integer times, String name) { return ResultVoUtil.success(dao.huoQuShouShuMing(patNo, times, StringUtil.isContainChinese(name))); } public ResultVo> huoQuShouShu(ChaXunJianChaHeJianYan param) { IPage page = new Page<>(param.getCurrentPage(), param.getPageSize(), param.getTotal() == 0); QueryWrapper qw = new QueryWrapper<>(); qw.select("op_name, op_datetime, status,record_id"); qw.eq("inpatient_no", param.getPatNo()); qw.eq("admiss_times", param.getTimes()); if (StringUtil.notBlank(param.getStartTime())) { qw.ge("req_date", param.getStartTime()); qw.le("req_date", param.getEndTime()); } if (StringUtil.notBlank(param.getOrderName())) { qw.eq("op_name", param.getOrderName()); } qw.ne("status", "d"); dao.selectPage(page, qw); return ResultVoUtil.success(page); } public ResultVo huoQuShouShuShenQingDaYing(String patNo, Integer times, Integer recordId) { OpRecord op = dao.daYingShouShu(patNo, times, recordId); if (op == null) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该手术可能已经被删除了。"); } try { EntityCopy.Copy(dao.daYingHuanZheXinXi(patNo, times), op); } catch (Exception e) { e.printStackTrace(); } op.setAge(Objects.requireNonNull(DateUtil.calculateAge(DateUtil.parse(op.getBirthDate(), GetDateFormat.DATE), null)).toString()); return ResultVoUtil.success(op); } public ResultVo> fenLeiXiangQing(String code, String name, long total, long currentPage, long pageSize) { IPage page = new Page<>(currentPage, pageSize, total == 0); page = dao.fenLeiXiangQing(page, code, StringUtil.isContainChinese(name)); return ResultVoUtil.success(page); } /** * 远程搜索手术部位 * * @param name 名字 * @return 返回 */ @DS("his") public ResultVo> huoQuShouShuBuWei(String name) { if (StringUtil.isBlank(name)) { return ResultVoUtil.success(dao.huoQuShouShuBuWei(name)); } return ResultVoUtil.success(dao.huoQuShouShuBuWei(StringUtil.isContainChinese(name))); } public ResultVo> xinZengShouShuShenQing(XinZengShouShu param) { if (ListUtil.isBlank(param.getList())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先选择需要上传的数据。"); } Map map = new HashMap<>(param.getList().size()); for (int i = 0; i < param.getList().size(); i++) { OpRecord item = param.getList().get(i); String error = applyForVerification(item); if (StringUtil.notBlank(error)) { if (StringUtil.isBlank(item.getOpName())) { item.setOpName("添加手术" + i); } map.put(item.getOpName(), error); } } if (!map.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的手术申请", map); } publicServer.huanZheJieSuan(param.getInpatientNo(), param.getAdmissTimes()); String userCode = TokenUtil.getTokenUserId(); Integer shenQingCiShu = dao.shouShuShenQingCiShu(param.getInpatientNo(), param.getAdmissTimes()); List shenChengYiZhu = new ArrayList<>(); List content = new ArrayList<>(); for (OpRecord item : param.getList()) { item.setRecordId(publicServer.huoQuShouShuHao()); item.setActOrderNo(publicServer.getActOrderNo()); item.setOpTimes(shenQingCiShu += 1); // 生成医嘱 shenChengYiZhu.add(item); content.add(String.format("手术名称:【%s】
" + "手术时间:【%tF %
", item.getOpName(), item.getOpDatetime())); } log.info("上传数据:{}", JSON.toJSONString(param)); XinZhenYiZhu huanZheXinXi = yiZhuLuRuDao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes()); // 生成手术 getThis().generativeSurgery(param, userCode, shenChengYiZhu, huanZheXinXi); publicServer.faSongXiaoXi(huanZheXinXi, content, "新增手术", TokenUtil.getTokenUserId()); return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION); } @Transactional(rollbackFor = Exception.class) public void generativeSurgery(XinZengShouShu param, String userCode, List shenChengYiZhu, XinZhenYiZhu huanZheXinXi) { dao.chaRuShouShuYiSheng(param.getList()); dao.chaRuShouShu(param.getList(), param.getInpatientNo(), param.getName(), param.getAdmissTimes(), huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), userCode, param.getBedNo(), param.getAdmissWard()); String yzCode = param.getGenerateRejectedOrders() ? "10399" : "06054"; // 插入医嘱 dao.chaRuYiZhu(shenChengYiZhu, huanZheXinXi, userCode, param.getExecDept(), yzCode); } public String applyForVerification(OpRecord param) { StringBuilder sb = new StringBuilder(); if (StringUtil.isBlank(param.getOpCode())) { sb.append("手术编码不能为空。"); } if (param.getOpDatetime() == null) { sb.append("手术时间不能为空。"); } else if (DateUtil.shiJianDaXiao(param.getOpDatetime(), param.getApplyDate(), "<")) { sb.append("手术时间不能小于申请时间。"); } if (StringUtil.isBlank(param.getDiagBeforeCode())) { sb.append("术前诊断不能为空。"); } if (StringUtil.isBlank(param.getPartCode())) { sb.append("手术部位不能为空。"); } if (StringUtil.isBlank(param.getDoctorZd())) { sb.append("主刀医生不能为空。"); } if (StringUtil.isBlank(param.getOpScale())) { sb.append("手术等级不能为空。"); } if (StringUtil.isBlank(param.getOrderName())) { sb.append("生成的医嘱名不能为空。"); } return sb.toString(); } public ResultVo shanChuShouShu(Integer recordId) { OpRecord op = dao.shouShuXinXi(recordId); if (op == null) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到该手术的信息。"); } if (!"1".equals(op.getStatus().trim())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "无法删除该手术。"); } dao.genXingShanChuBiaoZhi(recordId); log.info("删除手术==》操作人:{},申请单号:{}", TokenUtil.getTokenUserId(), recordId); return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION); } public ResultVo addASurgicalSite(String name) { if (dao.repeatPartName(name)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "手术部位名称重复"); } String maxCode = String.valueOf(dao.getTheMaximumSurgicalCode() + 1); String newCode = maxCode.length() > 1 ? maxCode : '0' + maxCode; dao.insertNewSurgicalSite(newCode, name, PingYinUtils.pyShouZiMuDaXie(name), PingYinUtils.getWBCode(name)); log.info("新增手术部位==>操作人:{}", TokenUtil.getTokenUserId()); return ResultVoUtil.success(newCode); } public ResultVo removeSurgicalSite(String code) { dao.removeSurgicalSite(code); return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION); } }