1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666 |
- package thyyxxk.webserver.service.zhuyuanyisheng;
- import cn.hutool.extra.spring.SpringUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- 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.apache.commons.collections4.ListUtils;
- import org.jetbrains.annotations.NotNull;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import thyyxxk.webserver.config.exception.BizException;
- import thyyxxk.webserver.config.exception.ExceptionEnum;
- import thyyxxk.webserver.constants.Capacity;
- import thyyxxk.webserver.constants.sidicts.ChargeStatus;
- import thyyxxk.webserver.dao.his.inpatient.XiangMuLuRuDao;
- import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao;
- import thyyxxk.webserver.entity.ResultVo;
- import thyyxxk.webserver.entity.RoleCode;
- import thyyxxk.webserver.entity.casefrontsheet.SheetOverview;
- import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
- import thyyxxk.webserver.entity.datamodify.YzActOrder;
- import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
- import thyyxxk.webserver.entity.dictionary.CodeName;
- import thyyxxk.webserver.entity.inpatient.patient.Overview;
- import thyyxxk.webserver.entity.inpatient.patient.Patient;
- import thyyxxk.webserver.entity.login.UserInfo;
- import thyyxxk.webserver.entity.zhuyuanyisheng.DoctorSOrderFee;
- import thyyxxk.webserver.entity.zhuyuanyisheng.ZyOrderZk;
- import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.*;
- import thyyxxk.webserver.service.PublicServer;
- import thyyxxk.webserver.service.casefrontsheet.CaseFrontSheetMainService;
- import thyyxxk.webserver.service.externalhttp.DrgWebServices;
- import thyyxxk.webserver.service.heliyongyao.RationalUseServer;
- import thyyxxk.webserver.service.redislike.RedisLikeService;
- import thyyxxk.webserver.utils.*;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 描述: 医嘱录入
- * </p>
- *
- * @author xc
- * @date 2022-01-04 16:59
- */
- @Service
- @Slf4j
- public class YiZhuLuRuServer {
- private final YiZhuLuRuDao dao;
- private final PublicServer publicServer;
- private final RedisLikeService redisLikeService;
- private final XiangMuLuRuDao xiangMuLuRuDao;
- private final RationalUseServer rationalUseServer;
- private final DrgWebServices drgWebServices;
- private final CaseFrontSheetMainService caseFrontSheetMainService;
- /**
- * 转科的医嘱编码
- */
- private final String ZK_CODE = "06286";
- private final String ONCE = "ONCE";
- private final int 出院带药限制天数 = 15;
- private final int 出院带药限制数量 = 4;
- private final List<String> groupList = Arrays.asList("71", "73");
- private final String ITEM = "00";
- private final String SMALL_PACKAGE = "01";
- private final String BIG_PACKAGE = "99";
- private YiZhuLuRuServer getThis() {
- return SpringUtil.getBean(this.getClass());
- }
- public YiZhuLuRuServer(YiZhuLuRuDao dao, PublicServer publicServer, RedisLikeService redisLikeService, XiangMuLuRuDao xiangMuLuRuDao, RationalUseServer rationalUseServer, DrgWebServices drgWebServices, CaseFrontSheetMainService caseFrontSheetMainService) {
- this.dao = dao;
- this.publicServer = publicServer;
- this.redisLikeService = redisLikeService;
- this.xiangMuLuRuDao = xiangMuLuRuDao;
- this.rationalUseServer = rationalUseServer;
- this.drgWebServices = drgWebServices;
- this.caseFrontSheetMainService = caseFrontSheetMainService;
- }
- public ResultVo<String> getOrderNo() {
- return ResultVoUtil.success(publicServer.getActOrderNo().stripTrailingZeros().toPlainString());
- }
- public ResultVo<List<Patient>> getMyPatient() {
- return ResultVoUtil.success(dao.getMyPatient(TokenUtil.getTokenUserId()));
- }
- /**
- * 获取医嘱的数据
- * 可以根据,医嘱时间区间,执行频率,医嘱名
- *
- * @param param 查询条件
- * @return 返回分页数据,同时做了树状图,这样会有一个问题,那就是开了套餐的数据查询不出来
- */
- public ResultVo<List<XinZhenYzActOrder>> huoQuYiZhuShuJu(YiZhuFeiYongChaXunTiaoJian param) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- qw.eq("a.inpatient_no", param.getPatNo()).eq("a.admiss_times", param.getTimes());
- qw.orderByAsc("a.order_time");
- List<XinZhenYzActOrder> yiZhuList = dao.selectOrderNo(qw);
- // 还有那些没有被匹配的子级医嘱
- Map<BigDecimal, XinZhenYzActOrder> wuFuJiYiZhu = yiZhuList.stream().collect(Collectors.toMap(XinZhenYzActOrder::getActOrderNo, a -> a, (k1, k2) -> k1));
- if (ListUtil.isBlank(yiZhuList)) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该患者还没有开医嘱。");
- }
- // 做成树状图
- Map<BigDecimal, XinZhenYzActOrder> map = new HashMap<>();
- List<XinZhenYzActOrder> tree = new ArrayList<>();
- for (XinZhenYzActOrder item : yiZhuList) {
- if (item.getParentNo() == null) {
- tree.add(item);
- wuFuJiYiZhu.remove(item.getActOrderNo());
- }
- map.put(item.getActOrderNo(), item);
- EntityStringTrim.beanAttributeValueTrim(item);
- if ("00".equals(item.getSerial())) {
- item.setGroupNoName("项目");
- item.setSerialName("项目");
- } else {
- if ("01".equals(item.getSerial())) {
- item.setSerialName("小包装");
- } else if ("99".equals(item.getSerial())) {
- item.setSerialName("大包装");
- }
- }
- }
- for (XinZhenYzActOrder item : yiZhuList) {
- XinZhenYzActOrder actOrder = map.get(item.getParentNo());
- if (actOrder != null) {
- wuFuJiYiZhu.remove(item.getActOrderNo());
- if (actOrder.getChildren() == null) {
- actOrder.setChildren(new ArrayList<>());
- actOrder.setOrderGroup("┌");
- }
- item.setOrderGroup("丨");
- actOrder.getChildren().add(item);
- }
- }
- if (!wuFuJiYiZhu.isEmpty()) {
- tree.addAll(wuFuJiYiZhu.values());
- }
- // 删除前后空格
- EntityStringTrim.beanAttributeValueTrimList(tree);
- List<XinZhenYzActOrder> list = new ArrayList<>();
- for (XinZhenYzActOrder zy : tree) {
- list.add(zy);
- if (ListUtil.notBlank(zy.getChildren())) {
- zy.getChildren().get(zy.getChildren().size() - 1).setOrderGroup("└");
- list.addAll(zy.getChildren());
- zy.setChildren(null);
- }
- }
- return ResultVoUtil.success(list);
- }
- /**
- * 获取搜索的项目信息,如药品和项目
- *
- * @param code 拼音首字母,中文,编码来进行搜索
- * @return 返回项目信息
- */
- @DS("his")
- public ResultVo<List<YiZhuMingChen>> huoQuXiangMu(String code, String groupNo) {
- code = StringUtil.isContainChinese(code);
- // 药品
- List<YiZhuMingChen> list = dao.yiZhuYaoPing(code, groupNo);
- // 项目
- list.addAll(dao.yiZhuXiangMu(code));
- // 模板
- list.addAll(dao.composeOrders(code, redisLikeService.getUserInfoByToken().getDeptCode()));
- EntityStringTrim.beanAttributeValueTrimList(list);
- return ResultVoUtil.success(list);
- }
- /**
- * 获取父医嘱
- *
- * @param patNo 住院号
- * @param times 次数
- * @return
- */
- public ResultVo<List<XinZhenYzActOrder>> getParentOrders(String patNo, Integer times) {
- return ResultVoUtil.success(dao.getParentOrders(patNo, times));
- }
- /**
- * 把有错误的子医嘱纠正回来,子医嘱要跟随父医嘱的频率 等
- *
- * @param list 患者的数据
- */
- public void correctSubOrders(List<XinZhenYzActOrder> list) {
- // 父医嘱
- Map<BigDecimal, XinZhenYzActOrder> parentOrder = new HashMap<>(list.size());
- list.forEach(item -> parentOrder.put(item.getActOrderNo(), item));
- list.forEach(item -> {
- if (item.getParentNo() != null && parentOrder.containsKey(item.getParentNo())) {
- XinZhenYzActOrder order = parentOrder.get(item.getParentNo());
- // 判断是否需要更新
- if (updateSubOrders(order, item)) {
- dao.updateSubOrderStatus(item.getActOrderNo(), order);
- }
- }
- });
- }
- private boolean updateSubOrders(XinZhenYzActOrder parent, XinZhenYzActOrder children) {
- if (!parent.getOrderTime().equals(children.getOrderTime())) {
- return true;
- }
- if (!parent.getStartTime().equals(children.getStartTime())) {
- return true;
- }
- if (parent.getEndTime() != null && !parent.getEndTime().equals(children.getEndTime())) {
- return true;
- }
- if (!"044".equals(children.getSupplyCode())) {
- return true;
- }
- if (!parent.getFrequCode().equals(children.getFrequCode())) {
- return true;
- }
- return !parent.getGroupNo().equals(children.getGroupNo());
- }
- /**
- * 确认医嘱 , 这个是最新的正确的
- *
- * @param param 数据
- * @return 返回提示
- */
- public ResultVo<Map<String, Object>> confirmOrders(@NotNull XinZhenYiZhu param) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- qw.eq("a.inpatient_no", param.getInpatientNo())
- .eq("a.admiss_times", param.getAdmissTimes())
- .eq("a.status_flag", "1")
- .eq("a.enter_oper", TokenUtil.getTokenUserId())
- // 排除出院带药的医嘱
- .ne("isnull(a.self_buy,'0')", "4")
- .orderByAsc("a.act_order_no");
- param.setList(dao.selectOrderNo(qw));
- List<XinZhenYzActOrder> yiZhuList = param.getList();
- if (ListUtil.isBlank(yiZhuList)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有需要确认的医嘱.");
- }
- correctSubOrders(param.getList());
- dischargeQCVerification(param);
- // 药品 code
- Set<String> yaoPingCode = new HashSet<>();
- // 项目的 code
- Set<String> xiangMuCode = new HashSet<>();
- for (XinZhenYzActOrder item : yiZhuList) {
- if (ITEM.equals(item.getSerial())) {
- xiangMuCode.add(item.getOrderCode());
- } else {
- yaoPingCode.add(item.getOrderCode().trim() + item.getSerial().trim() + item.getGroupNo().trim());
- }
- }
- String userCode = TokenUtil.getTokenUserId();
- // 获取医生开药品的权限
- Integer doctorLevel = dao.huoQuYiShenDengJi(userCode);
- XinZhenYiZhu patInfo = dao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes());
- Map<String, XinZhenYzActOrder> drug = getDrugInformation(yaoPingCode, patInfo.getZkWard());
- Map<String, List<XinZhenYzActOrder>> project = getProjectInformation(xiangMuCode);
- // 是否可以确认
- boolean isThereAnyErrorMessage = false;
- Map<String, Object> map = new HashMap<>();
- List<BigDecimal> confirmOrderInformation = new ArrayList<>();
- Date excludeOrders = null;
- BigDecimal orderNo = null;
- for (XinZhenYzActOrder item : yiZhuList) {
- if (ITEM.equals(item.getSerial())) {
- Integer paiChiYiZhu = dao.shiFouPaiChiYiZhu(item.getOrderCode());
- if (excludeOrders != null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "一次性不能确认多条全排斥医嘱。");
- }
- if (paiChiYiZhu != null && paiChiYiZhu.equals(1)) {
- excludeOrders = item.getStartTime();
- orderNo = item.getActOrderNo();
- }
- }
- confirmOrderInformation.add(item.getActOrderNo());
- Map<String, Object> errorMessageMap = checkData(item, drug, project, patInfo, doctorLevel);
- if (!errorMessageMap.isEmpty()) {
- if (!isThereAnyErrorMessage && errorMessageMap.containsKey("error")) {
- isThereAnyErrorMessage = true;
- }
- errorMessageMap.put("data", item);
- map.put(item.getId(), errorMessageMap);
- }
- }
- if (isThereAnyErrorMessage) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改错误的医嘱", map);
- }
- if (excludeOrders != null) {
- int count = dao.thereAreUnexecutedOrders(param.getInpatientNo(), param.getAdmissTimes(), orderNo);
- if (count > 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "有未确认和未执行的长期医嘱,无法确认全排斥医嘱,请先确认其他医嘱。");
- }
- dao.stopOrder(param.getInpatientNo(), param.getAdmissTimes(), excludeOrders, userCode, orderNo);
- }
- for (BigDecimal decimal : confirmOrderInformation) {
- dao.confirmOrders(decimal, userCode, new Date());
- }
- getThis().drgOrderUpdate(patInfo.getInpatientNo() + "_" + patInfo.getAdmissTimes() + "_" + patInfo.getLedgerSn());
- sendAMessageToTheNurse(param, userCode, patInfo, "新增医嘱");
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- /**
- * 出院医嘱质控校验
- *
- * @param param 患者信息
- */
- private void dischargeQCVerification(XinZhenYiZhu param) {
- if (dao.selectDischargeOrde(param, TokenUtil.getTokenUserId()) > 0) {
- SheetOverview overview = new SheetOverview();
- overview.setBah(param.getInpatientNo());
- overview.setTimes(param.getAdmissTimes());
- overview.setInOutFlag(1);
- ResultVo<Map<String, List<CodeName>>> result = caseFrontSheetMainService.sheetVerification(overview);
- if (!result.getCode().equals(ExceptionEnum.SUCCESS.getCode())) {
- throw new BizException(ExceptionEnum.LOGICAL_ERROR, result.getMessage());
- }
- if (!result.getData().get("force").isEmpty()) {
- throw new BizException(ExceptionEnum.LOGICAL_ERROR, "未通过病案首页质控,无法确认出院医嘱。");
- }
- }
- }
- /**
- * 在开医嘱时 drg 需要调用一下这个接口
- *
- * @param patientNo 患者id
- */
- @Async
- public void drgOrderUpdate(String patientNo) {
- try {
- JSONObject jsonDrg = new JSONObject();
- jsonDrg.put("visit_id", Collections.singletonList(patientNo));
- jsonDrg.put("scene_type", 1);
- JSONObject js = drgWebServices.etlClient(jsonDrg);
- log.info("调用drg医嘱确认接口:{}", js);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void sendAMessageToTheNurse(XinZhenYiZhu param, String inputCode, XinZhenYiZhu patInfo, String name) {
- List<String> content = new ArrayList<>();
- for (XinZhenYzActOrder item : param.getList()) {
- String sb = notificationStyle("医嘱名", "409eff", item.getOrderName()) +
- notificationStyle("医嘱时间", "409eff", DateUtil.formatDatetime(item.getStartTime())) +
- notificationStyle("床位", "409eff", patInfo.getBedNo()) +
- notificationStyle("患者姓名", "409eff", patInfo.getName()) +
- notificationStyle("频次", "409eff", item.getFrequCode());
- content.add(sb);
- }
- publicServer.faSongXiaoXi(patInfo, content, name, inputCode);
- }
- private String notificationStyle(String name, String color, String content) {
- return String.format("%s:<span style='color: #%s'>%s</span><br>", name, color, content);
- }
- /**
- * 录入单条医嘱 新的 下面的保存医嘱的都无效了
- *
- * @param param 参数
- * @return 错误信息和提示
- */
- public ResultVo<Map<String, Object>> enterOrders(XinZhenYiZhu param) {
- XinZhenYzActOrder oldOrderNo = dao.getActOrderNoOne(param.getActOrderNo());
- String userCode = TokenUtil.getTokenUserId();
- if (oldOrderNo != null) {
- if (!"1".equals(oldOrderNo.getStatusFlag().trim())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该医嘱不是录入状态无法保存.");
- }
- if (!oldOrderNo.getInpatientNo().trim().equals(param.getInpatientNo())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "两次医嘱录入时患者不一致。");
- }
- if (!oldOrderNo.getEnterOper().equals(userCode)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医嘱录入人不是您,无法修改。。");
- }
- }
- // 获取医生开药品的权限
- Integer doctorLevel = dao.huoQuYiShenDengJi(userCode);
- XinZhenYiZhu huanZheXinXi = dao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes());
- XinZhenYzActOrder data = param.getData();
- if (ITEM.equals(data.getSerial().trim())) {
- data.setGroupNo("00");
- }
- // 药品的 code
- Set<String> yaoPingCode = new HashSet<>();
- // 项目的 code
- Set<String> xiangMuCode = new HashSet<>();
- if (ITEM.equals(data.getSerial())) {
- xiangMuCode.add(data.getOrderCode());
- } else {
- yaoPingCode.add(data.getOrderCode().trim() + data.getSerial().trim() + data.getGroupNo().trim());
- }
- Map<String, XinZhenYzActOrder> drug = getDrugInformation(yaoPingCode, huanZheXinXi.getZkWard());
- Map<String, List<XinZhenYzActOrder>> project = getProjectInformation(xiangMuCode);
- Map<String, Object> errorMessageMap = checkData(data, drug, project, huanZheXinXi, doctorLevel);
- if (data.getParentNo() != null) {
- XinZhenYzActOrder parentOrder = dao.getActOrderNoOne(data.getParentNo().stripTrailingZeros().toPlainString());
- if (parentOrder != null) {
- data.setFrequCode(parentOrder.getFrequCode());
- }
- }
- // 删除抗菌药物信息
- dao.deleteAntimicrobialInformation(param.getActOrderNo());
- // 先删除转科在插入
- dao.deleteTransferOrder(param.getActOrderNo());
- if (errorMessageMap.isEmpty()) {
- if (ZK_CODE.equals(data.getOrderCode())) {
- ZyOrderZk transferData = new ZyOrderZk();
- transferData
- .setActOrderNo(param.getActOrderNo())
- .setNewDept(data.getZkDeptCode())
- .setNewWard(data.getZkWardCode())
- .setOldWard(huanZheXinXi.getDeptCode())
- .setOldDept(huanZheXinXi.getSmallDept());
- dao.insertDoctorSOrder(transferData);
- }
- // 判断是不是抗菌药物
- XinZhenYzActOrder kssItem = drug.get(data.getOrderCode().trim() + data.getSerial().trim() + data.getGroupNo().trim());
- if (kssItem != null && kssItem.getKjywFlag() != null && kssItem.getKjywFlag() == 1) {
- YzActRecordKss kss = new YzActRecordKss();
- kss.setActOrderNo(data.getActOrderNo());
- kss.setChargeCode(data.getOrderCode());
- kss.setYyfs(data.getYyfs());
- kss.setSsqk(data.getSsqk());
- kss.setYysj(data.getYysj());
- dao.insertAntimicrobialInformation(param.getActOrderNo(),
- kss, userCode, param.getInpatientNo(), param.getAdmissTimes());
- }
- }
- dao.deleteOrderNo(param.getActOrderNo(), param.getInpatientNo(), param.getAdmissTimes());
- dao.insertEntryOrder(huanZheXinXi, param.getData(), userCode);
- // 01724
- if (!errorMessageMap.isEmpty()) {
- Map<String, Object> map = new HashMap<>();
- errorMessageMap.put("data", data);
- map.put(param.getActOrderNo(), errorMessageMap);
- if (errorMessageMap.containsKey("error")) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的医嘱。", map);
- }
- }
- publicServer.orderRecord(new BigDecimal(param.getActOrderNo()), TokenUtil.getTokenUserId());
- log.info("医嘱录入日志:{}", JSON.toJSONString(param));
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "添加成功.");
- }
- /**
- * 把医嘱模板中的数据插入到 患者的医嘱表中
- *
- * @param param 参数
- * @return
- */
- public ResultVo<String> insertTemplateOrder(XinZhenYiZhu param) {
- if (StringUtil.isBlank(param.getInpatientNo())) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请先选择患者.");
- }
- Map<String, XinZhenYzActOrder> fatherAndSonDoctorSAdvice = new HashMap<>(param.getList().size());
- param.getList().forEach(item -> {
- fatherAndSonDoctorSAdvice.put(item.getId(), item);
- item.setActOrderNo(publicServer.getActOrderNo());
- publicServer.orderRecord(item.getActOrderNo(), TokenUtil.getTokenUserId());
- });
- XinZhenYiZhu huanZheXinXi = dao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes());
- // 把模板的数据插入到医嘱
- getThis().templateInsertToOrder(param, fatherAndSonDoctorSAdvice, huanZheXinXi);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "插入模板数据成功。");
- }
- @Transactional(rollbackFor = Exception.class)
- public void templateInsertToOrder(XinZhenYiZhu param, Map<String, XinZhenYzActOrder> fatherAndSonDoctorSAdvice, XinZhenYiZhu huanZheXinXi) {
- String userCode = TokenUtil.getTokenUserId();
- param.getList().forEach(item -> {
- String key = item.getParentNo() != null ? item.getParentNo().stripTrailingZeros().toPlainString() : "";
- if (StringUtil.notBlank(key)) {
- if (fatherAndSonDoctorSAdvice.containsKey(key)) {
- item.setParentNo(fatherAndSonDoctorSAdvice.get(key).getActOrderNo());
- }
- }
- dao.insertEntryOrder(huanZheXinXi, item, userCode);
- });
- }
- /**
- * 删除单条医嘱
- *
- * @param orderNo 医嘱号
- * @return 提示
- */
- public ResultVo<String> toDeleteAnOrder(String orderNo) {
- XinZhenYzActOrder oldData = dao.getActOrderNoOne(orderNo);
- String message = judgeWhetherItCanBeDeleted(oldData);
- if (StringUtil.notBlank(message)) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, message);
- }
- dao.toDeleteAnOrder(orderNo, oldData.getInpatientNo());
- dao.deleteGroup(orderNo);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- /**
- * 删除多条录入的医嘱
- *
- * @param param 参数
- * @return 返回提示
- */
- public ResultVo<Map<String, String>> deleteMultipleOrders(XinZhenYiZhu param) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- qw.eq("inpatient_no", param.getInpatientNo());
- qw.eq("admiss_times", param.getAdmissTimes());
- List<BigDecimal> list = new ArrayList<>();
- param.getList().forEach(item -> {
- list.add(item.getActOrderNo());
- });
- qw.in("act_order_no", list);
- List<XinZhenYzActOrder> deleteOrderList = dao.getOrdersToDelete(qw);
- if (ListUtil.isBlank(deleteOrderList)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到原医嘱可能已经被删除了");
- }
- Map<String, String> map = new HashMap<>();
- deleteOrderList.forEach(item -> {
- String error = judgeWhetherItCanBeDeleted(item);
- if (StringUtil.notBlank(error)) {
- map.put(item.getActOrderNo().stripTrailingZeros().toPlainString(), error);
- }
- });
- log.info("数据:{}", deleteOrderList);
- if (map.isEmpty()) {
- dao.deleteParentChildRelationship(param.getInpatientNo(), param.getAdmissTimes(), list);
- dao.deleteMultipleOrders(qw);
- return ResultVoUtil.fail(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "删除失败", map);
- }
- private String judgeWhetherItCanBeDeleted(XinZhenYzActOrder oldData) {
- StringBuilder str = new StringBuilder();
- if (oldData == null) {
- return "没有找到原医嘱可能已经被删除了";
- }
- if (!"1".equals(oldData.getStatusFlag())) {
- str.append("该医嘱不是录入状态,无法删除");
- }
- if (!oldData.getEnterOper().equals(TokenUtil.getTokenUserId())) {
- str.append("该医嘱录入人不是您,无法删除.");
- }
- return str.toString();
- }
- public ResultVo<Map<BigDecimal, String>> stopOrder(XinZhenYiZhu param) {
- if (ListUtil.isBlank(param.getList())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先选择数据");
- }
- Map<BigDecimal, String> map = new HashMap<>();
- param.getList().forEach(item -> {
- if (item.getEndTime() == null) {
- map.put(item.getActOrderNo(), "停止时间不能为空。");
- } else {
- // 因为前端用的是浏览器自带的 所以要删除 T
- if (DateUtil.shiJianDaXiao(item.getEndTime(), item.getStartTime(), "<")) {
- map.put(item.getActOrderNo(), "停止时间不能小于医嘱的开始时间。");
- }
- }
- });
- if (map.isEmpty()) {
- dao.setStopTime(param.getList(), TokenUtil.getTokenUserId(), param.getInpatientNo(), param.getAdmissTimes());
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- return ResultVoUtil.success(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的医嘱", map);
- }
- @Transactional(rollbackFor = Exception.class)
- public ResultVo<String> voidOrders(String orderNo, String reasonForCancellation) {
- XinZhenYzActOrder yz = dao.getActOrderNoOne(orderNo);
- if (yz == null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "原医嘱找不到了。");
- }
- if ("6".equals(yz.getStatusFlag())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医嘱已作废了。");
- }
- UserInfo userInfo = redisLikeService.getUserInfoByToken();
- if (!DateUtil.within24Hours(yz.getStartTime())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "只能对24小时内的医嘱进行作废处理");
- }
- List<String> list = dao.getTheDoctorSDepartment(userInfo.getDeptCode());
- list.add(userInfo.getDeptCode());
- if (publicServer.needRule(1)) {
- list.add(yz.getWardCode());
- }
- if (!list.contains(yz.getWardCode())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "非本科室开的医嘱不可作废");
- }
- if (dao.getADoctorSOrderWithADefiniteFee(yz.getInpatientNo(), yz.getAdmissTimes(), orderNo) > 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该医嘱已经执行,请对应的医技科室拒绝医嘱。");
- }
- if (dao.getDetailChargeFee(yz.getInstruction(), yz.getAdmissTimes(), orderNo) > 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该医嘱已经产生了医技费用,请对应的医技科室进行退费处理。");
- }
- // 患者最大的 detail_sn
- int maxDetailSn = publicServer.getMaxDetailSn(yz.getInpatientNo(), yz.getAdmissTimes());
- dao.cancelMedicalTechnologyAssuranceFee(TokenUtil.getTokenUserId(), orderNo, yz.getInpatientNo(), yz.getAdmissTimes());
- // 如果是药品的话就需要自动退费
- if (!yz.getSerial().equals(ITEM)) {
- // 获取父子医嘱同时退费
- List<String> parentNoList = dao.getParentChildOrders(orderNo);
- parentNoList.add(orderNo);
- List<ZyDetailCharge> feeList = dao.getExpenseData(yz.getInpatientNo(), yz.getAdmissTimes(), parentNoList);
- if (ListUtil.notBlank(feeList)) {
- List<ZyDetailCharge> refundArray = new ArrayList<>(feeList.size());
- for (ZyDetailCharge item : feeList) {
- // 取负数的费用
- item.setChargeFee(item.getChargeFee().negate());
- item.setChargeAmount(item.getChargeAmount().negate());
- item.setOpIdCode(userInfo.getCode());
- item.setOriDetailSn(item.getDetailSn());
- // 设置 流水号
- item.setDetailSn(maxDetailSn += 1);
- item.setOrderNo(new BigDecimal(0));
- refundArray.add(item);
- }
- List<List<ZyDetailCharge>> fenGe = ListUtils.partition(refundArray, 20);
- fenGe.forEach(xiangMuLuRuDao::xiangMuTuiFei);
- dao.updateItemFlag(yz.getInpatientNo(), yz.getAdmissTimes(), parentNoList);
- }
- }
- dao.updateVoidedOrders(orderNo, userInfo.getCode(), reasonForCancellation);
- dao.updateChildOrders(orderNo, userInfo.getCode(), reasonForCancellation);
- log.info("作废医嘱==》操作人:{},医嘱号:{}", userInfo.getCode(), orderNo);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "撤销成功。");
- }
- /**
- * 获取某一个费用的详细信息
- *
- * @param code 编码
- * @param serial 00-项目 01-小包装的药品 99-大包装
- * @return 返回该费用的一些详细信息,以及一些提示信息。
- */
- @DS("his")
- public ResultVo<Map<String, Object>> huoQuFeiYongXinXi(String code, String serial, String deptCode, String groupNo) {
- Map<String, Object> map = new HashMap<>();
- // 一些提示
- List<String> prompt = new ArrayList<>();
- // 加载项目信息
- if (ITEM.equals(serial.trim())) {
- List<XinZhenYzActOrder> xiangMu = dao.huoQuXiangMu(code);
- for (XinZhenYzActOrder item : xiangMu) {
- if (item.getDelFlag() == 1) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("该医嘱下的【%s】,已经被停用了,请联系物价科。", item.getOrderName()));
- } else if (StringUtil.isBlank(item.getNationalCode())) {
- prompt.add(String.format("该医嘱下面的【%s】,没有医保编码,请注意。", item.getOrderName()));
- } else {
- prompt.add(String.format("该医嘱下【%s】,医保码为:【%s】。", item.getOrderName(), item.getNationalCode()));
- }
- }
- if (ListUtil.isBlank(xiangMu)) {
- Integer paiChiYiZhu = dao.shiFouPaiChiYiZhu(code);
- if (paiChiYiZhu != null) {
- switch (paiChiYiZhu) {
- case 1:
- prompt.add("全排斥医嘱");
- break;
- case 2:
- prompt.add("单组排斥医嘱");
- break;
- case 3:
- prompt.add("多组斥医嘱");
- break;
- default:
- break;
- }
- }
- }
- } else {
- YaoPinXinXi yp = dao.huoQuYaoPin(code.trim() + serial.trim(), groupNo);
- if (StringUtil.notBlank(deptCode)) {
- if (dao.restrictedUseInTheDepartment(code.trim(), deptCode) > 0) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该药品禁止在患者所在的科室使用。");
- }
- }
- if (yp == null) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该医嘱下的药品,可能已经被停用了,请联系药剂科。");
- }
- yp.setDrugFlag(getDrugFlagByLargeCategories(yp.getCategoriesFlag()));
- if (yp.getVisibleFlagZy() == 1) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该药品禁止住院使用。");
- }
- Integer yiShenDengJi = dao.huoQuYiShenDengJi(TokenUtil.getTokenUserId());
- int yiShen = yiShenDengJi == null ? 0 : yiShenDengJi;
- if (yp.getYpLevel() > yiShen) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "您没有开此药品的权限。");
- }
- List<YaoPingJiLiang> yaoPingJiLiang = new ArrayList<>();
- if (StringUtil.notBlank(yp.getWeighUnit())) {
- yaoPingJiLiang.add(new YaoPingJiLiang(yp.getWeighUnit(), yp.getWeighUnitName(), yp.getWeight()));
- }
- if (StringUtil.notBlank(yp.getVolUnit())) {
- yaoPingJiLiang.add(new YaoPingJiLiang(yp.getVolUnit(), yp.getVolUnitName(), yp.getVolum()));
- }
- if (StringUtil.notBlank(yp.getPackUnit())) {
- yaoPingJiLiang.add(new YaoPingJiLiang(yp.getPackUnit(), yp.getPackUnitName(), yp.getPackSize()));
- }
- if (yp.getKjywFlag() == 1) {
- prompt.add("抗菌药物,需填写抗菌药物医嘱附注");
- }
- if (yp.getSelfFlagYb() == 1) {
- prompt.add("该药品医保自费药品,如符合条件请填写记账,不是请填写自费");
- }
- if (StringUtil.isBlank(yp.getNationalCode())) {
- prompt.add("该药品医保没有匹配医保码");
- } else {
- prompt.add(String.format("药品医保码为:【%s】", yp.getNationalCode()));
- }
- if (yp.getStockAmount() != null && BigUtils.bigXiaoYu(yp.getStockAmount(), 10)) {
- prompt.add(String.format("该药品剩余数量为:【%s】", yp.getStockAmount().stripTrailingZeros().toPlainString()));
- }
- if (yp.getPsFlag() == 1) {
- prompt.add("此药品为皮试药品");
- map.put("piShi", dao.piShiGeiYaoFangShi());
- }
- map.put("yaoPingJiLiang", yaoPingJiLiang);
- map.put("data", yp);
- }
- map.put("prompt", prompt);
- return ResultVoUtil.success(map);
- }
- private String getDrugFlagByLargeCategories(String val) {
- if (StringUtil.isBlank(val)) {
- return "z";
- }
- switch (val) {
- case "0":
- return "d";
- case "1":
- return "i";
- default:
- return "z";
- }
- }
- public ResultVo<List<GetDropdownBox>> getFrequency() {
- return ResultVoUtil.success(dao.selectFrequency());
- }
- /**
- * 获取频率
- *
- * @param code 五笔,拼音,中文,编码
- * @return 返回对应的数据
- */
- public ResultVo<List<GetDropdownBox>> huoQuZhuYuanPinLv(String code) {
- return ResultVoUtil.success(dao.huoQuZhuYuanPinLv("%" + code.toUpperCase() + "%"));
- }
- /**
- * 获取给药方式
- *
- * @param code 五笔,拼音,中文,编码
- * @return 返回对应的数据
- */
- public ResultVo<List<GetDropdownBox>> huoQuGeiYaoFangShi(String code) {
- return ResultVoUtil.success(dao.huoQuGeiYaoFangShi(StringUtil.isContainChinese(code)));
- }
- public ResultVo<List<GetDropdownBox>> getCostFreeDosing(String code) {
- return ResultVoUtil.success(dao.getCostFreeDosing(StringUtil.isContainChinese(code)));
- }
- /**
- * 获取执行科室
- *
- * @param code 五笔,拼音,中文,编码
- * @return 返回对应的数据
- */
- public ResultVo<List<GetDropdownBox>> huoQuZhiXinKeShi(String code) {
- return ResultVoUtil.success(dao.huoQuZhiXinKeShi(StringUtil.isContainChinese(code)));
- }
- /**
- * 这里是校验模板的数据
- *
- * @param param 模板数据
- * @return 返回提示信息
- */
- public ResultVo<Map<String, Object>> singleDataCheck(XinZhenYiZhu param) {
- // 获取医生开药品的权限
- Integer doctorLevel = dao.huoQuYiShenDengJi(TokenUtil.getTokenUserId());
- Set<String> yaoPingCode = new HashSet<>();
- Set<String> xiangMuCode = new HashSet<>();
- for (XinZhenYzActOrder item : param.getList()) {
- if (ITEM.equals(item.getSerial().trim())) {
- xiangMuCode.add(item.getOrderCode().trim());
- } else {
- yaoPingCode.add(item.getOrderCode().trim() + item.getSerial().trim() + item.getGroupNo().trim());
- }
- }
- Map<String, Object> errorMessage = checkData(param.getList().get(0), getDrugInformation(yaoPingCode, null), getProjectInformation(xiangMuCode), null, doctorLevel);
- errorMessage.put("data", param.getList().get(0));
- return ResultVoUtil.success(errorMessage);
- }
- public ResultVo<String> doesTheTemplateExist(String name) {
- if (dao.duplicateTemplateName(name, TokenUtil.getTokenUserId()) == 0) {
- return ResultVoUtil.success();
- }
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "模板名称重复");
- }
- /**
- * 保存模板数据
- *
- * @param param
- * @return
- */
- public ResultVo<String> saveTemplate(YzOrderPattern param) {
- // 如果名字重复了,那么就修改原来的模板
- YzOrderPattern yzOrderPattern = dao.yuanLaiDeMuBanBianMa(param.getPatternName(), TokenUtil.getTokenUserId());
- UserInfo userInfo = redisLikeService.getUserInfoByCode(TokenUtil.getTokenUserId());
- if (null == yzOrderPattern) {
- yzOrderPattern = new YzOrderPattern();
- }
- String patternCode = yzOrderPattern.getPatternCode();
- // 有原来的模板名称而且 还要是自己创建的才能删除,否则就只能创建新的模板了
- if (StringUtil.notBlank(patternCode) && userInfo.getCode().equals(yzOrderPattern.getInputId())) {
- // 更新的时候先删除模板 原来的模板
- dao.shanChuLaoMuBan(patternCode);
- param.setPatternCode(patternCode);
- } else {
- // 设置新的模板号
- param.setPatternCode(publicServer.getPatternCode());
- }
- String py = PingYinUtils.pyShouZiMuDaXie(param.getPatternName());
- String wb = PingYinUtils.getWBCode(param.getPatternName());
- param.setPyCode(py.length() > 9 ? py.substring(0, 9) : py);
- param.setDCode(wb.length() > 9 ? wb.substring(0, 9) : wb);
- param.setInputId(TokenUtil.getTokenUserId());
- param.setDeptCode(userInfo.getDeptCode());
- dao.chaRuMuBan(param);
- Map<String, XinZhenYzActOrder> map = param.getList().stream().collect(Collectors.toMap(XinZhenYzActOrder::getId, a -> a, (k1, k2) -> k1));
- for (XinZhenYzActOrder item : param.getList()) {
- // 设置模板号
- item.setActOrderNo(publicServer.getPatternOrderCode());
- if (item.getParentNo() != null && map.containsKey(item.getParentNo().stripTrailingZeros().toPlainString())) {
- item.setParentNo(map.get(item.getParentNo().stripTrailingZeros().toPlainString()).getActOrderNo());
- }
- }
- dao.chaRuMuBanShuJu(param.getList(), param.getPatternCode());
- return ResultVoUtil.success();
- }
- private void calculateDrugAmount(XinZhenYzActOrder item, XinZhenYzActOrder feiYongXinXi) {
- if (feiYongXinXi == null) {
- return;
- }
- if (StringUtil.notBlank(feiYongXinXi.getDrugWeightUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getDrugWeightUnit().trim())) {
- item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugWeight(), 2));
- } else if (StringUtil.notBlank(feiYongXinXi.getDrugVolUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getDrugVolUnit())) {
- item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugVolume(), 2));
- } else if (StringUtil.notBlank(feiYongXinXi.getPackUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getPackUnit())) {
- item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getPackSize(), 2));
- }
- }
- private Map<String, Object> checkData(XinZhenYzActOrder item,
- Map<String, XinZhenYzActOrder> drug,
- Map<String, List<XinZhenYzActOrder>> project,
- XinZhenYiZhu huanZheXinXi,
- Integer doctorLevel) {
- boolean strictVerification = huanZheXinXi != null;
- List<String> errorMessage = new ArrayList<>();
- List<String> warningMessage = new ArrayList<>();
- if (StringUtil.isBlank(item.getGroupNo())) {
- errorMessage.add("没有药房请重新开。");
- }
- if (ITEM.equals(item.getSerial())) {
- List<XinZhenYzActOrder> projectDetails = project.get(item.getOrderCode());
- // 如果这个项目下面没有费用明细,那么这就是一条口头医,口头医嘱每次只能开一个
- if (ListUtil.notBlank(projectDetails)) {
- for (XinZhenYzActOrder detailed : projectDetails) {
- if (detailed.getDelFlag() == 1) {
- errorMessage.add(String.format("项目:【%s】,已经被物价停用了", detailed.getOrderName()));
- }
- if (StringUtil.isBlank(detailed.getNationalCode())) {
- warningMessage.add(String.format("项目:【%s】,没有匹配医保码", detailed.getOrderName()));
- }
- }
- }
- item.setDrugOcc(item.getDrugQuan());
- } else {
- if (!groupList.contains(item.getGroupNo())) {
- errorMessage.add("药房错误,请重新选择药房。");
- }
- XinZhenYzActOrder detailsOfDrugs = drug.get(item.getOrderCode().trim() + item.getSerial().trim() + item.getGroupNo().trim());
- if (detailsOfDrugs != null) {
- if (detailsOfDrugs.getDelFlag() == 1) {
- errorMessage.add("药品已经被停用了,请联系药剂科");
- }
- if (detailsOfDrugs.getYpLevel() > doctorLevel) {
- errorMessage.add("您没有开此药品的权限");
- }
- if (StringUtil.isBlank(detailsOfDrugs.getNationalCode())) {
- warningMessage.add("该药品没有医保编码");
- }
- if (BigUtils.bigXiaoYu(detailsOfDrugs.getStockAmount(), 10)) {
- warningMessage.add(String.format("该药品剩余数量为:【%s】", detailsOfDrugs.getStockAmount().stripTrailingZeros().toPlainString()));
- }
- if (BigUtils.bigDaYu(item.getDrugQuan(), detailsOfDrugs.getStockAmount())) {
- errorMessage.add("药品领量大于药品的库存,当前库存量" + detailsOfDrugs.getStockAmount().stripTrailingZeros().toPlainString());
- }
- if (strictVerification) {
- if (detailsOfDrugs.getDeptRestrictions() > 0) {
- errorMessage.add("该药品禁止在患者所在的科室使用。");
- }
- if (detailsOfDrugs.getVisibleFlagZy() == 1) {
- errorMessage.add("该药品禁止住院患者使用。");
- }
- item.setKjywFlag(detailsOfDrugs.getKjywFlag());
- if (detailsOfDrugs.getKjywFlag() == 1) {
- if (item.getYyfs() == null) {
- errorMessage.add("请填写抗菌药物医嘱附注信息录入");
- } else if (item.getYyfs() == 1 || item.getYyfs() == 2) {
- if (item.getSsqk() == null) {
- errorMessage.add("当用药方式为 1 或 2 时,手术切口和用药时间不能为空");
- }
- }
- }
- }
- if (item.getSelfBuy() != null && "4".equals(item.getSelfBuy())) {
- // 如果是临时医嘱 开了就结束了.
- if ("ONCE".equals(item.getFrequCode())) {
- item.setEndTime(item.getStartTime());
- }
- if (dao.dischargeWithMedicationAdministration(item.getSupplyCode()) == 0) {
- errorMessage.add("出院带药给药方式不能包含费用。");
- }
- int day = 1;
- if (item.getStartTime() == null) {
- errorMessage.add("出院带药请输入开始时间。");
- }
- if (item.getEndTime() == null) {
- errorMessage.add("出院带药请输入结束时间。");
- } else {
- long cha = item.getEndTime().getTime() - item.getStartTime().getTime();
- long nd = 1000 * 24 * 60 * 60;
- day = (int) (cha / nd);
- if (day > 出院带药限制天数) {
- errorMessage.add("出院带药天数不得超过 15 天,计算方式结束时间减去开始时间。");
- }
- if (day == 0) {
- day = 1;
- }
- }
- BigDecimal total = getTotal(item, day);
- if (StringUtil.notBlank(detailsOfDrugs.getDrugWeightUnit()) && item.getDoseUnit().trim().equals(detailsOfDrugs.getDrugWeightUnit().trim())) {
- item.setDrugQuan(DecimalUtil.multiply(item.getDose(), total).divide(detailsOfDrugs.getDrugWeight(), 0, RoundingMode.UP));
- item.setDrugOcc(item.getDrugQuan());
- } else if (StringUtil.notBlank(detailsOfDrugs.getDrugVolUnit()) && item.getDoseUnit().trim().equals(detailsOfDrugs.getDrugVolUnit())) {
- item.setDrugQuan(DecimalUtil.multiply(item.getDose(), total).divide(detailsOfDrugs.getDrugVolume(), 0, RoundingMode.UP));
- item.setDrugOcc(item.getDrugQuan());
- } else if (StringUtil.notBlank(detailsOfDrugs.getPackUnit()) && item.getDoseUnit().trim().equals(detailsOfDrugs.getPackUnit())) {
- item.setDrugQuan(DecimalUtil.multiply(item.getDose(), total).divide(detailsOfDrugs.getPackSize(), 0, RoundingMode.UP));
- item.setDrugOcc(item.getDrugQuan());
- }
- if (item.getDrugQuan().equals(BigDecimal.ZERO)) {
- item.setDrugQuan(BigDecimal.ONE);
- item.setDrugOcc(BigDecimal.ONE);
- }
- } else {
- // 计算普通药品的领量 durg_quan durg_occ
- calculateDrugAmount(item, detailsOfDrugs);
- }
- }
- }
- if (StringUtil.isBlank(item.getOrderCode())) {
- errorMessage.add("项目编码不能为空");
- }
- if (StringUtil.isBlank(item.getOrderName())) {
- errorMessage.add("项目名称不能为空");
- }
- if (StringUtil.isBlank(item.getExecUnit())) {
- errorMessage.add("执行科室不能为空");
- } else if (item.getExecUnit().startsWith("8")) {
- errorMessage.add("执行科室不能选择为病区");
- }
- if (ZK_CODE.equals(item.getOrderCode())) {
- if (StringUtil.isBlank(item.getZkWardCode())) {
- errorMessage.add("转科病房不能为空");
- }
- if (StringUtil.isBlank(item.getZkDeptCode())) {
- errorMessage.add("转科科室不能为空");
- }
- }
- if (StringUtil.isBlank(item.getFrequCode())) {
- errorMessage.add("频次不能为空");
- }
- // 药品的校验
- if (!ITEM.equals(item.getSerial().trim())) {
- if (StringUtil.isBlank(item.getDrugSpecification())) {
- errorMessage.add("药品规格不能为空");
- }
- if (StringUtil.isBlank(item.getSupplyCode())) {
- errorMessage.add("给药方式不能为空");
- }
- if (item.getDose() == null || BigUtils.dengYu(item.getDose(), 0)) {
- errorMessage.add("一次计量不能为空");
- }
- if (StringUtil.isBlank(item.getDoseUnit())) {
- errorMessage.add("计量单位不能为空");
- }
- if (StringUtil.isBlank(item.getSerial())) {
- errorMessage.add("包装大小不能为空");
- }
- }
- if (strictVerification) {
- if (item.getParentNo() != null && item.getActOrderNo() != null) {
- if (BigUtils.bigXiaoYu(item.getActOrderNo(), item.getParentNo())) {
- errorMessage.add("子医嘱的医嘱号,小于父医嘱号,无法成组。【原因如果子医嘱的医嘱号小于父医嘱,会导致打印乱码】");
- }
- }
- // 获取患者的入院时间
- if (item.getOrderTime() == null) {
- errorMessage.add("医嘱时间不能为空");
- } else if (item.getStartTime() == null) {
- errorMessage.add("开始时间不能为空");
- } else if (huanZheXinXi.getAdmissDate() == null) {
- errorMessage.add("没有查询到患者的入院时间");
- } else if (DateUtil.shiJianDaXiao(item.getStartTime(), huanZheXinXi.getAdmissDate(), "<")) {
- errorMessage.add("开始时间不能在患者入院之前,患者入院时间" + DateUtil.formatDatetime(huanZheXinXi.getAdmissDate()));
- } else if (DateUtil.shiJianDaXiao(item.getStartTime(), item.getOrderTime(), "<")) {
- errorMessage.add("开始时间不能在开医嘱之前");
- }
- if (item.getEndTime() != null) {
- if (ONCE.equals(item.getFrequCode().trim())) {
- item.setEndTime(null);
- } else {
- if (DateUtil.shiJianDaXiao(item.getEndTime(), item.getStartTime(), "<")) {
- errorMessage.add("结束时间不能在开始时间之前");
- }
- }
- }
- }
- Map<String, Object> map = new HashMap<>(Capacity.TWO);
- if (ListUtil.notBlank(errorMessage)) {
- map.put("error", errorMessage);
- }
- if (ListUtil.notBlank(warningMessage)) {
- map.put("warning", warningMessage);
- }
- return map;
- }
- /**
- * 计算总量
- *
- * @param item 药品信息
- * @param day 天数
- * @return 返回总数
- */
- @NotNull
- private BigDecimal getTotal(XinZhenYzActOrder item, int day) {
- // 计算出院带药的领量
- Map<String, Short> numberOfTimesADay = dao.numberOfTimesADay(item.getFrequCode());
- int times = 0;
- for (Map.Entry<String, Short> entry : numberOfTimesADay.entrySet()) {
- if (entry.getValue() != null) {
- times += entry.getValue();
- }
- }
- // 最小天数一天
- return new BigDecimal((day <= 0 ? 1 : day) * times);
- }
- /***
- * 获取项目信息
- * @param xiangMuCode 项目编码
- * @return 返回数据
- */
- public Map<String, List<XinZhenYzActOrder>> getProjectInformation(Set<String> xiangMuCode) {
- if (!xiangMuCode.isEmpty()) {
- return dao.huoQuXiangMuXinXi(xiangMuCode).stream().collect(Collectors.groupingBy(item -> item.getOrderCode().trim()));
- }
- return new HashMap<>(0);
- }
- /**
- * 获取药品信息
- *
- * @param yaoPingCode 药品编码
- * @return 返回数据
- */
- public Map<String, XinZhenYzActOrder> getDrugInformation(Set<String> yaoPingCode, String dept) {
- if (!yaoPingCode.isEmpty()) {
- return dao.huoQuYaoPinXinXi(yaoPingCode, dept).stream().collect(Collectors.toMap(item -> item.getOrderCode().trim() + item.getSerial().trim() + item.getGroupNo(), a -> a, (k1, k2) -> k1));
- }
- return new HashMap<>(0);
- }
- /**
- * 获取医嘱录入的模板1
- *
- * @param code 模板编码
- * @param deptCode 科室编码
- * @param muBanLeiXing 项目类型
- * @param currentPage 当前页
- * @param total 总数
- * @return 返回模板
- */
- @DS("his")
- public ResultVo<IPage<YzOrderPattern>> huoQuYiZhuMuBan(String code, String deptCode, Integer muBanLeiXing, long currentPage, long total) {
- IPage<YzOrderPattern> page = new Page<>();
- if (total == 0) {
- page.setTotal(dao.huoQuMuBanTotal(StringUtil.isContainChinese(code), TokenUtil.getTokenUserId(), deptCode, muBanLeiXing));
- }
- page.setRecords(dao.huoQuMuBan(StringUtil.isContainChinese(code), TokenUtil.getTokenUserId(), deptCode, muBanLeiXing, currentPage));
- return ResultVoUtil.success(page);
- }
- /**
- * 获取 我的医嘱模板的最大医嘱码
- *
- * @return 最大排序码
- */
- public ResultVo<Integer> getDoctorSOrderTemplateMaxSortNo() {
- Integer sortCode = dao.getMyTemplateMaxSortNo(TokenUtil.getTokenUserId());
- return ResultVoUtil.success(sortCode == null ? 0 : sortCode);
- }
- private String getActOrderNo() {
- Random random = new Random();
- String a = String.valueOf(random.nextInt(5) + 1);
- String b = String.valueOf(random.nextInt(99999));
- return a + b;
- }
- /**
- * 获取模板数据
- *
- * @param code 模板的编码
- * @return 返回数据
- */
- @DS("his")
- public ResultVo<List<YzActOrder>> huoQuMuBanShuJu(String code) {
- List<YzActOrder> muBanShuJu = dao.huoQuMuBanShuJu(code);
- Map<BigDecimal, YzActOrder> map = new HashMap<>(muBanShuJu.size());
- List<YzActOrder> tree = new ArrayList<>();
- for (YzActOrder item : muBanShuJu) {
- item.setId(getActOrderNo());
- if (item.getParentNo() == null) {
- tree.add(item);
- }
- map.put(item.getActOrderNo(), item);
- }
- for (YzActOrder item : muBanShuJu) {
- YzActOrder yzActOrder = map.get(item.getParentNo());
- if (yzActOrder != null) {
- item.setParentNo(new BigDecimal(yzActOrder.getId()));
- item.setIsChildren(true);
- if (yzActOrder.getChildren() == null) {
- yzActOrder.setChildren(new ArrayList<>());
- }
- yzActOrder.getChildren().add(item);
- // 没有副医嘱的就返回到最上层
- } else if (!tree.contains(item)) {
- item.setParentNo(null);
- tree.add(item);
- }
- }
- return ResultVoUtil.success(tree);
- }
- /**
- * 删除医嘱模板
- *
- * @param patternCode 模板的编码
- * @return 提示
- */
- public ResultVo<String> deleteADoctorSOrderTemplate(String patternCode) {
- if (StringUtil.isBlank(patternCode)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "模板编号为空。");
- }
- YzOrderPattern yzOrderPattern = dao.huoQuMuBanXinXi(patternCode);
- EntityStringTrim.beanAttributeValueTrim(yzOrderPattern);
- if (yzOrderPattern == null) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到对应的模板信息。");
- }
- String userId = TokenUtil.getTokenUserId();
- List<Integer> role = publicServer.getRoleCode().getData();
- if (publicServer.needRule(role, RoleCode.PHYSICIAN_S_ORDER_TEMPLATEEDIT)) {
- return startDeletingTemplates(patternCode);
- }
- if (userId.equals(yzOrderPattern.getInputId())) {
- return startDeletingTemplates(patternCode);
- }
- // 主任可以删除本科室的任意模板
- if (publicServer.needRule(role, RoleCode.DIRECTOR) && dao.userDeptCode(userId).equals(yzOrderPattern.getDeptCode())) {
- return startDeletingTemplates(patternCode);
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限删除这个模板。");
- }
- /**
- * 删除父模板以及下面的子模板 数据
- *
- * @param patternCode 模板编码
- */
- private ResultVo<String> startDeletingTemplates(String patternCode) {
- dao.shanChuMuBan(patternCode);
- log.info("删除医嘱模板==> 操作人:{},模板编码:{}", TokenUtil.getTokenUserId(), patternCode);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "删除成功。");
- }
- /**
- * 收藏医嘱模板或者取消收藏
- * 如果以及收藏了就删除,没有就收藏
- *
- * @param patternCode 模板号
- * @return 提示
- */
- public ResultVo<String> collectDoctorSOrderTemplate(String patternCode) {
- String userId = TokenUtil.getTokenUserId();
- String saveTheDoctorSOrderNumber = dao.whetherToSaveTheDoctorSOrderTemplate(patternCode, userId);
- if (StringUtil.notBlank(saveTheDoctorSOrderNumber)) {
- dao.shanChuMuBan(saveTheDoctorSOrderNumber);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "已取消删除。");
- } else {
- YzOrderPattern yzOrderPattern = dao.huoQuMuBanXinXi(patternCode);
- EntityStringTrim.beanAttributeValueTrim(yzOrderPattern);
- dao.chaRuShouCang(publicServer.getPatternCode(), yzOrderPattern.getPatternName() + "(收藏)", yzOrderPattern.getPyCode(), yzOrderPattern.getDCode(), dao.userDeptCode(userId), userId, yzOrderPattern.getPatternCode());
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "收藏成功。");
- }
- }
- /**
- * 删除或修改模板
- *
- * @param patternCode 模板点吗
- * @param patternName 模板名称
- * @param sortNo 排序号
- * @param flag 标志 1-修改 2- 删除 3-收藏和取消收藏
- * @return 返回给前端提示
- */
- public ResultVo<String> muBanCaoZuo(String patternCode, String patternName, String deptCode, Integer sortNo, Integer flag) {
- if (StringUtil.isBlank(patternCode)) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "模板编码为空。");
- }
- YzOrderPattern yzOrderPattern = dao.huoQuMuBanXinXi(patternCode);
- if (yzOrderPattern == null) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到对应的模板信息。");
- }
- EntityStringTrim.beanAttributeValueTrim(yzOrderPattern);
- String inputId = TokenUtil.getTokenUserId();
- List<Integer> role = publicServer.getRoleCode().getData();
- // 管理员 和 医务部的无视 规则
- if (!role.contains(1) && !role.contains(38) && flag != 3) {
- // 只有模板在不等于 自己的时候触发
- if (!inputId.equals(yzOrderPattern.getInputId())) {
- if ("2".equals(yzOrderPattern.getInputType()) && !role.contains(11)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该模板为科室模板您没有权限修改或删除,请联系科主任进行修改。");
- } else if ("1".equals(yzOrderPattern.getInputType())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该模板为全院模板,无法删除或修改。");
- }
- }
- }
- if (flag == 1) {
- if (StringUtil.isBlank(patternName)) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "模板名称不能为空。");
- }
- if (patternName.trim().equals(yzOrderPattern.getPatternName().trim()) && sortNo.equals(yzOrderPattern.getSortNo())) {
- return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "数据没有变化,请勿点击。");
- }
- dao.genXingMuBan(patternName.trim(), PingYinUtils.pyShouZiMuDaXie(patternName), PingYinUtils.getWBCode(patternName), yzOrderPattern.getPatternCode(), sortNo);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "修改成功。");
- } else if (flag == 2) {
- // 删除父模板以及下面的子模板 数据
- dao.shanChuMuBan(yzOrderPattern.getPatternCode());
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "删除成功。");
- } else if (flag == 3) {
- // 收藏模板
- String collectCode = dao.chongFuShouCang(inputId, patternCode);
- if (collectCode == null) {
- dao.chaRuShouCang(publicServer.getPatternCode(), yzOrderPattern.getPatternName() + "(收藏)", yzOrderPattern.getPyCode(), yzOrderPattern.getDCode(), deptCode, inputId, yzOrderPattern.getPatternCode());
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "收藏成功。");
- } else {
- dao.shanChuMuBan(yzOrderPattern.getPatternCode());
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "已取消收藏。");
- }
- }
- return ResultVoUtil.success();
- }
- /**
- * 获取医嘱下面产生的费用
- *
- * @param patNo 住院号
- * @param times 住院次数
- * @return 返回
- */
- public ResultVo<Map<String, Object>> expensesForGettingADoctorSOrder(String patNo, Integer times) {
- List<DoctorSOrderFee> feeDate = dao.expensesForGettingADoctorSOrder(patNo, times);
- // 这些编码的医嘱都是有问题的
- List<String> problem = Arrays.asList("5", "6", "7", "9");
- Map<String, String> problemDoctorSOrder = new HashMap<>();
- Map<String, FeeSum> totalCost = new HashMap<>();
- Map<String, List<DoctorSOrderFee>> map = new HashMap<>(feeDate.size());
- for (DoctorSOrderFee fee : feeDate) {
- // 如果这个没有就代表没有产生费用
- if (fee.getOrderNoStr() == null) {
- continue;
- }
- String chargeStatusName = ChargeStatus.getValue(fee.getChargeStatus());
- String amount = fee.getChargeAmount().abs().stripTrailingZeros().toPlainString();
- String money = fee.getChargeFee().stripTrailingZeros().toPlainString();
- // 计算费用总和
- if (totalCost.containsKey(fee.getOrderNoStr())) {
- FeeSum sum = totalCost.get(fee.getOrderNoStr());
- sum.setSum(DecimalUtil.add(money, sum.getSum()));
- sum.setAmount(DecimalUtil.add(amount, sum.getAmount()));
- totalCost.replace(fee.getOrderNoStr(), sum);
- } else {
- FeeSum sum = new FeeSum();
- sum.setAmount(amount);
- sum.setSum(money);
- totalCost.put(fee.getOrderNoStr(), sum);
- }
- if (problem.contains(fee.getChargeStatus())) {
- problemDoctorSOrder.put(fee.getOrderNoStr(), chargeStatusName);
- }
- fee.setChargeStatusName(chargeStatusName);
- if (map.containsKey(fee.getOrderNoStr())) {
- map.get(fee.getOrderNoStr()).add(fee);
- } else {
- List<DoctorSOrderFee> list = new ArrayList<>();
- list.add(fee);
- map.put(fee.getOrderNoStr(), list);
- }
- }
- Map<String, Object> feeData = new HashMap<>(3);
- feeData.put("data", map);
- feeData.put("problem", problemDoctorSOrder);
- feeData.put("totalCost", totalCost);
- return ResultVoUtil.success(feeData);
- }
- /**
- * 设置患者三级医生
- *
- * @param param 参数
- * @return 返回值
- */
- public ResultVo<String> saveTheThirdLevelDoctor(Overview param) {
- log.info("设置三级医生:==> 操作人{},数据:{}", TokenUtil.getTokenUserId(), JSON.toJSONString(param));
- dao.updateTheThirdLevelDoctor(param);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- /**
- * 设置父子医嘱
- *
- * @param param 主医嘱 和 多个子医嘱
- * @return 返回数据
- */
- public ResultVo<String> associateOrders(XinZhenYiZhu param) {
- log.info("数据:{}", JSON.toJSONString(param));
- XinZhenYzActOrder order = dao.getActOrderNoOne(param.getActOrderNo());
- if (order.getParentNo() != null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "操作失败,父医嘱不能为子医嘱。");
- }
- param.getAssociatedGroup().forEach(item -> {
- dao.associateOrders(item, order);
- });
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "关联成功。");
- }
- /**
- * 批量检验医嘱是否正确
- *
- * @param list 医嘱数据
- * @param huanZheXinXi 患者信息
- * @param rationalUse 是否要用合理用药
- * @return
- */
- public Map<String, Object> batchVerification(List<XinZhenYzActOrder> list,
- XinZhenYiZhu huanZheXinXi,
- boolean rationalUse) {
- Map<String, Object> returnMap = new HashMap<>();
- // 药品 code
- Set<String> yaoPingCode = new HashSet<>();
- // 项目的 code
- Set<String> xiangMuCode = new HashSet<>();
- huanZheXinXi.setList(list);
- // 合理用药校验
- for (XinZhenYzActOrder item : list) {
- if (ITEM.equals(item.getSerial())) {
- xiangMuCode.add(item.getOrderCode());
- } else {
- yaoPingCode.add(item.getOrderCode().trim() + item.getSerial().trim() + item.getGroupNo().trim());
- }
- }
- String userCode = TokenUtil.getTokenUserId();
- // 获取医生开药品的权限
- Integer doctorLevel = dao.huoQuYiShenDengJi(userCode);
- Map<String, XinZhenYzActOrder> drug = getDrugInformation(yaoPingCode, huanZheXinXi.getZkWard());
- Map<String, List<XinZhenYzActOrder>> project = getProjectInformation(xiangMuCode);
- for (XinZhenYzActOrder item : list) {
- String key = item.getId();
- Map<String, Object> errorMessageMap = checkData(item, drug, project, huanZheXinXi, doctorLevel);
- if (!errorMessageMap.isEmpty()) {
- if (errorMessageMap.get("error") != null) {
- errorMessageMap.put("data", item);
- returnMap.put(item.getId(), errorMessageMap);
- }
- }
- }
- return returnMap;
- }
- /**
- * 确认出院带药医嘱
- *
- * @param patNo 住院号
- * @param times 住院次数
- * @return
- */
- public ResultVo<Map<String, Object>> confirmTheDoctorSOrderWithMedicine(String patNo, Integer times) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- qw.eq("a.inpatient_no", patNo)
- .eq("a.admiss_times", times)
- .eq("a.status_flag", "1")
- .eq("a.enter_oper", TokenUtil.getTokenUserId())
- .eq("isnull(a.self_buy,'0')", "4");
- XinZhenYiZhu patInfo = dao.queryPatientInfo(patNo, times);
- patInfo.setList(dao.selectOrderNo(qw));
- if (dao.obtainTheNumberOfDischargedDrugs(patNo, times) > 出院带药限制数量) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "出院带药医嘱不得超过 4 种,且不得超过 15 天。");
- }
- String userCode = TokenUtil.getTokenUserId();
- // 出院带药需要生成药单 key 是不同的药房。不同的药房就要
- Map<String, List<XinZhenYzActOrder>> takeTheMedicineList = new HashMap<>(Capacity.TWO);
- for (XinZhenYzActOrder item : patInfo.getList()) {
- XinZhenYzActOrder feiYongXinXi = dao.getDrugOne(item.getOrderCode() + item.getSerial(), item.getGroupNo());
- int day = 1;
- // 如果是临时医嘱 开了就结束了.
- if ("ONCE".equals(item.getFrequCode())) {
- item.setEndTime(item.getStartTime());
- }
- if (item.getStartTime() != null && item.getEndTime() != null) {
- long cha = item.getEndTime().getTime() - item.getStartTime().getTime();
- long nd = 1000 * 24 * 60 * 60;
- day = (int) (cha / nd);
- if (day == 0) {
- day = 1;
- }
- }
- // 计算出院带药的领量
- BigDecimal total = getTotal(item, day);
- if (StringUtil.notBlank(feiYongXinXi.getDrugWeightUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getDrugWeightUnit().trim())) {
- item.setDrugQuan(DecimalUtil.multiply(item.getDose(), total).divide(feiYongXinXi.getDrugWeight(), 0, RoundingMode.UP));
- item.setDrugOcc(item.getDrugQuan());
- } else if (StringUtil.notBlank(feiYongXinXi.getDrugVolUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getDrugVolUnit())) {
- item.setDrugQuan(DecimalUtil.multiply(item.getDose(), total).divide(feiYongXinXi.getDrugVolume(), 0, RoundingMode.UP));
- item.setDrugOcc(item.getDrugQuan());
- } else if (StringUtil.notBlank(feiYongXinXi.getPackUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getPackUnit())) {
- item.setDrugQuan(DecimalUtil.multiply(item.getDose(), total).divide(feiYongXinXi.getPackSize(), 0, RoundingMode.UP));
- item.setDrugOcc(item.getDrugQuan());
- }
- if (item.getDrugQuan().equals(BigDecimal.ZERO)) {
- item.setDrugQuan(BigDecimal.ONE);
- item.setDrugOcc(BigDecimal.ONE);
- }
- // 在这里更新出院带药领量
- dao.updateThePickup(item);
- // 费用标志为 4 的就是出院带药
- if ("4".equals(item.getSelfBuy())) {
- if (takeTheMedicineList.containsKey(item.getGroupNo())) {
- takeTheMedicineList.get(item.getGroupNo()).add(item);
- } else {
- List<XinZhenYzActOrder> temp = new ArrayList<>();
- temp.add(item);
- takeTheMedicineList.put(item.getGroupNo(), temp);
- }
- }
- }
- Map<String, Object> check = batchVerification(patInfo.getList(), patInfo, true);
- if (check.isEmpty()) {
- List<Integer> pageNoList = new ArrayList<>();
- for (int i = 0; i < takeTheMedicineList.size(); i++) {
- pageNoList.add(publicServer.getTheDrugListNo());
- }
- sendAMessageToTheNurse(patInfo, userCode, dao.queryPatientInfo(patNo, times), "出院带药");
- return getThis().getMapResultVo(patInfo, userCode, takeTheMedicineList, pageNoList);
- } else {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的医嘱。", check);
- }
- }
- @NotNull
- @Transactional(rollbackFor = Exception.class)
- public ResultVo<Map<String, Object>> getMapResultVo(XinZhenYiZhu patInfo, String userCode, Map<String, List<XinZhenYzActOrder>> takeTheMedicineList, List<Integer> pageNoList) {
- // 根据不同的药房,生成不同的单子.
- int index = 0;
- for (Map.Entry<String, List<XinZhenYzActOrder>> entry : takeTheMedicineList.entrySet()) {
- Integer pageNo = pageNoList.get(index);
- dao.summarySheetOfDrugs(pageNo, patInfo, userCode, entry.getKey());
- dao.insertDetailedMedicineList(pageNo, patInfo, userCode, entry.getKey(), entry.getValue());
- index++;
- }
- for (XinZhenYzActOrder order : patInfo.getList()) {
- // 出院带药 确认了直接停止医嘱
- dao.takeMedicineAfterDischargeStopOrder(order.getActOrderNo(), userCode, new Date());
- }
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- public ResultVo<String> copyTheDoctorSOrder(BigDecimal orderNo) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- qw.eq("a.act_order_no", orderNo);
- List<XinZhenYzActOrder> yiZhuList = dao.selectOrderNo(qw);
- if (ListUtil.isBlank(yiZhuList)) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "原医嘱已经不存在了。");
- }
- XinZhenYzActOrder fatherOrder = yiZhuList.get(0);
- QueryWrapper<?> childQw = new QueryWrapper<>();
- childQw.eq("a.parent_no", fatherOrder.getActOrderNo());
- List<XinZhenYzActOrder> childOrderList = dao.selectOrderNo(childQw);
- UserInfo us = redisLikeService.getUserInfoByToken();
- revertToTheDefaultState(fatherOrder, us, null);
- List<XinZhenYzActOrder> addOrderList = new ArrayList<>();
- addOrderList.add(fatherOrder);
- if (ListUtil.notBlank(childOrderList)) {
- childOrderList.forEach(item -> {
- revertToTheDefaultState(item, us, fatherOrder.getActOrderNo());
- addOrderList.add(item);
- });
- }
- XinZhenYiZhu patInfo = dao.queryPatientInfo(fatherOrder.getInpatientNo(), fatherOrder.getAdmissTimes());
- getThis().insertATemplate(addOrderList, patInfo);
- return ResultVoUtil.success();
- }
- @Transactional(rollbackFor = Exception.class)
- public void insertATemplate(List<XinZhenYzActOrder> list, XinZhenYiZhu patInfo) {
- String userCode = TokenUtil.getTokenUserId();
- list.forEach(item -> {
- dao.insertEntryOrder(patInfo, item, userCode);
- });
- }
- private void revertToTheDefaultState(XinZhenYzActOrder param, UserInfo us, BigDecimal parentNo) {
- param.setActOrderNo(publicServer.getActOrderNo());
- param.setStatusFlag("1");
- Date newDate = new Date();
- param.setOrderTime(newDate);
- param.setStartTime(newDate);
- param.setEndTime(null);
- param.setEnterOper(us.getCode());
- param.setSigner("");
- param.setModifier("");
- param.setParentNo(parentNo);
- }
- }
|