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