123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- 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.*;
- /**
- * <p>
- * 描述: 手术申请
- * </p>
- *
- * @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<List<ZdIcd9Cm3>> obtainSurgicalItems(String name, Integer type) {
- return ResultVoUtil.success(dao.obtainSurgicalItems(StringUtil.isContainChinese(name), type));
- }
- @DS("his")
- public ResultVo<List<CodeName>> getDoctorByOpCode(String opCode) {
- return ResultVoUtil.success(dao.getDoctorByOpCode(opCode));
- }
- @DS("his")
- public ResultVo<Boolean> 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<List<GetDropdownBox>> shouShuShenQingCeBianLan() {
- return ResultVoUtil.success(dao.shouShuShenQingCeBianLan());
- }
- public ResultVo<List<Map<String, String>>> huoQuShouShuMingCheng(String patNo, Integer times, String name) {
- return ResultVoUtil.success(dao.huoQuShouShuMing(patNo, times, StringUtil.isContainChinese(name)));
- }
- public ResultVo<IPage<OpRecord>> huoQuShouShu(ChaXunJianChaHeJianYan param) {
- IPage<OpRecord> page = new Page<>(param.getCurrentPage(), param.getPageSize(), param.getTotal() == 0);
- QueryWrapper<OpRecord> 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<OpRecord> 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<IPage<ShouShuFanHui>> fenLeiXiangQing(String code, String name, long total, long currentPage, long pageSize) {
- IPage<ShouShuFanHui> 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<List<GetDropdownBox>> huoQuShouShuBuWei(String name) {
- if (StringUtil.isBlank(name)) {
- return ResultVoUtil.success(dao.huoQuShouShuBuWei(name));
- }
- return ResultVoUtil.success(dao.huoQuShouShuBuWei(StringUtil.isContainChinese(name)));
- }
- public ResultVo<Map<String, String>> xinZengShouShuShenQing(XinZengShouShu param) {
- if (ListUtil.isBlank(param.getList())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先选择需要上传的数据。");
- }
- Map<String, String> 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<OpRecord> shenChengYiZhu = new ArrayList<>();
- List<String> 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("手术名称:<span style='color:#409eff'>【%s】</span><br>" +
- "手术时间:<span style='color:#409eff'>【%tF %<tT】</span><br>", 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<OpRecord> 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<String> 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<String> 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<String> removeSurgicalSite(String code) {
- dao.removeSurgicalSite(code);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- }
|