123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470 |
- package thyyxxk.webserver.service.zhuyuanyisheng;
- import cn.hutool.core.util.StrUtil;
- 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.ibatis.session.ExecutorType;
- import org.apache.ibatis.session.SqlSession;
- import org.apache.ibatis.session.SqlSessionFactory;
- import org.jetbrains.annotations.NotNull;
- import org.springframework.stereotype.Service;
- import thyyxxk.webserver.config.exception.BizException;
- import thyyxxk.webserver.config.exception.ExceptionEnum;
- import thyyxxk.webserver.constants.sidicts.ChargeStatus;
- 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.SelectV2;
- 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.OneClickOrder;
- import thyyxxk.webserver.entity.zhuyuanyisheng.ZyOrderZk;
- import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.*;
- import thyyxxk.webserver.service.PublicServer;
- import thyyxxk.webserver.service.inpatient.casefrontsheet.CaseFrontSheetMainService;
- import thyyxxk.webserver.service.externalhttp.DrgWebServices;
- import thyyxxk.webserver.service.redislike.RedisLikeService;
- import thyyxxk.webserver.service.zhuyuanyisheng.yizhuverify.Repel;
- import thyyxxk.webserver.service.zhuyuanyisheng.yizhuverify.YiZhuCheckData;
- import thyyxxk.webserver.utils.*;
- import java.math.BigDecimal;
- 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 DrgWebServices drgWebServices;
- private final CaseFrontSheetMainService caseFrontSheetMainService;
- private final SqlSessionFactory sqlSessionFactory;
- /**
- * 转科的医嘱编码
- */
- private final String ZK_CODE = "06286";
- private final String ITEM = "00";
- private final String 出院带药 = "007";
- public YiZhuLuRuServer(YiZhuLuRuDao dao, PublicServer publicServer, RedisLikeService redisLikeService, DrgWebServices drgWebServices, CaseFrontSheetMainService caseFrontSheetMainService, SqlSessionFactory sqlSessionFactory) {
- this.dao = dao;
- this.publicServer = publicServer;
- this.redisLikeService = redisLikeService;
- this.drgWebServices = drgWebServices;
- this.caseFrontSheetMainService = caseFrontSheetMainService;
- this.sqlSessionFactory = sqlSessionFactory;
- }
- public ResultVo<String> getOrderNo() {
- return ResultVoUtil.success(publicServer.getActOrderNo().stripTrailingZeros().toPlainString());
- }
- public ResultVo<List<Patient>> getMyPatient() {
- return ResultVoUtil.success(dao.getMyPatient(TokenUtil.getInstance().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())
- .orderByAsc("a.act_order_no");
- List<XinZhenYzActOrder> yiZhuList = dao.selectOrderNo(qw);
- if (ListUtil.isBlank(yiZhuList)) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该患者还没有开医嘱。");
- }
- List<XinZhenYzActOrder> list = getOrderList(yiZhuList);
- return ResultVoUtil.success(list);
- }
- /**
- * 设置医嘱号的数状图
- *
- * @param yiZhuList 医嘱数据
- * @return s
- */
- @NotNull
- public static List<XinZhenYzActOrder> getOrderList(List<XinZhenYzActOrder> yiZhuList) {
- // 还有那些没有被匹配的子级医嘱
- Map<BigDecimal, XinZhenYzActOrder> wuFuJiYiZhu = yiZhuList.stream().collect(Collectors.toMap(XinZhenYzActOrder::getActOrderNo, a -> a, (k1, k2) -> k1));
- // 做成树状图
- Map<BigDecimal, XinZhenYzActOrder> map = new HashMap<>(yiZhuList.size());
- 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());
- }
- 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 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 返回父医嘱
- */
- @Deprecated
- 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 (!parent.getFrequCode().equals(children.getFrequCode())) {
- return true;
- }
- return !parent.getGroupNo().equals(children.getGroupNo());
- }
- /**
- * xc确认医嘱 , 这个是最新的正确的
- *
- * @param param 数据
- * @return 返回提示
- */
- public ResultVo<Map<String, Object>> confirmOrders(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.getInstance().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());
- String userCode = TokenUtil.getInstance().getTokenUserId();
- XinZhenYiZhu patInfo = dao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes());
- // 是否可以确认
- List<BigDecimal> confirmOrderInformation = new ArrayList<>();
- List<XinZhenYzActOrder> confirmYzList = new ArrayList<>();
- YiZhuCheckData checkData = new YiZhuCheckData(dao);
- checkData.init(yiZhuList, patInfo).judgeExclusion();
- Map<String, Object> checkMap = checkData.startCheck((item) -> {
- confirmYzList.add(item);
- confirmOrderInformation.add(item.getActOrderNo());
- });
- if (checkData.multipleExclusions()) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "一次性不能确认多条全排斥医嘱。");
- }
- if (checkData.getFailed()) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改错误的医嘱", checkMap);
- }
- Repel repel = checkData.getRepel();
- if (repel != null && repel.getCount() > 0) {
- // 把全排斥医嘱变成临时防止给药方式错误
- dao.modifyTheFrequency(repel.getOrderNo());
- dao.stopOrder(param.getInpatientNo(), param.getAdmissTimes(), repel.getDate(), userCode, repel.getOrderNo());
- }
- SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
- YiZhuLuRuDao mapper = sqlSession.getMapper(YiZhuLuRuDao.class);
- Date now = new Date();
- try {
- ListUtil.partitionAndFunc(confirmYzList, 50, (list) -> {
- for (XinZhenYzActOrder item : list) {
- if (StringUtil.notBlank(item.getSuperiorDoctor())) {
- mapper.confirmOrdersSuperiorDoctor(item.getActOrderNo(), item.getSuperiorDoctor(), now);
- } else {
- mapper.confirmOrders(item.getActOrderNo(), userCode, now);
- }
- }
- sqlSession.commit();
- });
- } finally {
- sqlSession.close();
- }
- drgOrderUpdate(patInfo.getInpatientNo() + "_" + patInfo.getAdmissTimes() + "_" + patInfo.getLedgerSn());
- sendAMessageToTheNurse(param, userCode, patInfo, "新增医嘱");
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- /**
- * 出院医嘱质控校验
- * 暂时废弃
- *
- * @param param 患者信息
- */
- @Deprecated
- private void dischargeQCVerification(XinZhenYiZhu param) {
- if (param.getInpatientNo().contains("$")) {
- return;
- }
- if (dao.selectDischargeOrde(param, TokenUtil.getInstance().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
- */
- public void drgOrderUpdate(String patientNo) {
- try {
- JSONObject jsonDrg = new JSONObject();
- jsonDrg.put("visit_id", Collections.singletonList(patientNo));
- jsonDrg.put("scene_type", 1);
- drgWebServices.etlClient(jsonDrg);
- } catch (Exception ignored) {
- }
- }
- 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.getInstance().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, "医嘱录入人不是您,无法修改。");
- }
- }
- XinZhenYiZhu huanZheXinXi = dao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes());
- XinZhenYzActOrder data = param.getData();
- if (ITEM.equals(data.getSerial().trim())) {
- data.setGroupNo("00");
- }
- YiZhuCheckData checkData = new YiZhuCheckData(dao);
- Map<String, Object> errorMessageMap = checkData.init(data, huanZheXinXi)
- .startCheck(null);
- if (checkData.getFailed()) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的医嘱。", errorMessageMap);
- }
- // 如果是 子医嘱 的话就拿到父医嘱的频率
- if (data.getParentNo() != null) {
- String frequCode = dao.selectParentNo(data.getParentNo().stripTrailingZeros().toPlainString());
- if (StringUtil.notBlank(frequCode)) {
- data.setFrequCode(frequCode);
- }
- }
- if (checkData.getPassTheAudit()) {
- 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.getZkWard());
- // 先删除转科在插入
- dao.deleteTransferOrder(param.getActOrderNo());
- dao.insertDoctorSOrder(transferData);
- }
- // 判断是不是抗菌药物
- XinZhenYzActOrder kssItem = checkData.getDrugData(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.deleteAntimicrobialInformation(param.getActOrderNo());
- dao.insertAntimicrobialInformation(param.getActOrderNo(),
- kss, userCode, param.getInpatientNo(), param.getAdmissTimes());
- }
- }
- dao.deleteOrderNo(param.getActOrderNo());
- dao.insertEntryOrder(huanZheXinXi, param.getData(), userCode);
- // 更新授权医生
- if (StringUtil.notBlank(param.getData().getSuperiorDoctor())) {
- dao.updateAuthorizedDoctor(param.getData().getActOrderNo(), param.getData().getSuperiorDoctor());
- }
- // 项目不触发
- if (param.getData().getParentNo() == null && !param.getData().getSerial().equals("00")) {
- String selectSupplyCode = dao.selectSupplyCode(param.getData().getSupplyCode().trim());
- if (StringUtil.isBlank(selectSupplyCode)) {
- selectSupplyCode = "044";
- }
- // 子医嘱跟随父医嘱
- dao.howOftenTheSubPhysicianOrderIsModified(param.getData(), selectSupplyCode);
- }
- QueryWrapper<?> qw = getQueryWrapper(param, data);
- Map<String, Object> successMap = new HashMap<>();
- successMap.put("code", 200);
- successMap.put("data", getOrderList(dao.selectOrderNo(qw)));
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "添加成功。", successMap);
- }
- @NotNull
- private static QueryWrapper<?> getQueryWrapper(XinZhenYiZhu param, XinZhenYzActOrder data) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- qw.eq("a.inpatient_no", param.getInpatientNo());
- qw.eq("a.admiss_times", param.getAdmissTimes());
- qw.eq("a.status_flag", "1");
- // 不是子节点,就需要查询 子节点
- if (data.getParentNo() == null) {
- qw.and(wrapper -> wrapper.eq("a.act_order_no", param.getActOrderNo())
- .or()
- .eq("a.parent_no", param.getActOrderNo())
- );
- } else {
- // 如果是子节点就返回自己
- qw.eq("a.act_order_no", data.getActOrderNo());
- }
- qw.orderByAsc("a.act_order_no");
- return qw;
- }
- /**
- * 把医嘱模板中的数据插入到 患者的医嘱表中
- *
- * @param param 参数
- * @return 返回插入的医嘱
- */
- public ResultVo<JSONObject> insertTemplateOrder(XinZhenYiZhu param) {
- if (StringUtil.isBlank(param.getInpatientNo())) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请先选择患者.");
- }
- XinZhenYiZhu patInfo = dao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes());
- if (patInfo == null) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请先选择患者.");
- }
- List<BigDecimal> returnOrderList = new ArrayList<>();
- List<XinZhenYzActOrder> list = param.getList();
- List<XinZhenYzActOrder> resList = new ArrayList<>();
- Map<BigDecimal, XinZhenYzActOrder> map = new HashMap<>(list.size());
- String userCode = TokenUtil.getInstance().getTokenUserId();
- Queue<BigDecimal> queue = new LinkedList<>();
- for (XinZhenYzActOrder item : list) {
- if (item.getParentNo() == null) {
- resList.add(item);
- }
- map.put(item.getActOrderNo(), item);
- queue.offer(publicServer.getActOrderNo());
- }
- list.forEach(item -> {
- if (item.getParentNo() != null) {
- XinZhenYzActOrder mapItem = map.get(item.getParentNo());
- if (mapItem != null) {
- if (mapItem.getChildren() == null) {
- mapItem.setChildren(new ArrayList<>());
- }
- mapItem.getChildren().add(item);
- }
- }
- });
- templateInsertToOrder(resList, patInfo, userCode, returnOrderList, queue);
- JSONObject js = getNewOrderData(returnOrderList);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "插入模板数据成功。", js);
- }
- /**
- * 把模板数据插入到医嘱中
- *
- * @param resList 医嘱数据
- * @param patInfo 患者信息
- * @param userCode 用户编码
- * @param returnOrderList 返回的医嘱号
- */
- public void templateInsertToOrder(List<XinZhenYzActOrder> resList,
- XinZhenYiZhu patInfo,
- String userCode,
- List<BigDecimal> returnOrderList,
- Queue<BigDecimal> queue) {
- CacheOnce<XinZhenYzActOrder> drug = new CacheOnce<>();
- SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
- YiZhuLuRuDao mapper = sqlSession.getMapper(YiZhuLuRuDao.class);
- resList.forEach(item -> {
- setTempInfo(drug, item, patInfo);
- item.setActOrderNo(queue.poll());
- returnOrderList.add(item.getActOrderNo());
- mapper.insertEntryOrder(patInfo, item, userCode);
- if (ListUtil.notBlank(item.getChildren())) {
- item.getChildren().forEach(children -> {
- setTempInfo(drug, children, patInfo);
- children.setActOrderNo(queue.poll());
- returnOrderList.add(children.getActOrderNo());
- children.setParentNo(item.getActOrderNo());
- mapper.insertEntryOrder(patInfo, children, userCode);
- });
- }
- });
- sqlSession.commit();
- sqlSession.close();
- }
- private void setTempInfo(CacheOnce<XinZhenYzActOrder> drug, XinZhenYzActOrder data, XinZhenYiZhu patInfo) {
- XinZhenYzActOrder feiYongXinXi = drug.get(
- data.getOrderCode().trim() + data.getSerial().trim() + data.getGroupNo().trim(),
- (temp) -> dao.drugDataOne(temp, patInfo.getZkWard())
- );
- YiZhuCheckData.calculateDrugAmount(data, feiYongXinXi);
- }
- /**
- * 删除单条医嘱
- *
- * @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<>();
- 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);
- }
- });
- 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()) || "2".equals(oldData.getStatusFlag()))) {
- str.append("该医嘱不是录入或确认状态,无法删除");
- }
- if (!oldData.getEnterOper().equals(TokenUtil.getInstance().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 {
- if (DateUtil.shiJianDaXiao(item.getEndTime(), item.getStartTime(), "<")) {
- map.put(item.getActOrderNo(), "停止时间不能小于医嘱的开始时间。");
- }
- }
- });
- if (map.isEmpty()) {
- dao.setStopTime(param.getList(), TokenUtil.getInstance().getTokenUserId(), param.getInpatientNo(), param.getAdmissTimes());
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "存在医嘱时间为空的医嘱请检查。", map);
- }
- private Integer a = 0;
- /**
- * 获取某一个费用的详细信息
- *
- * @param code 编码
- * @param serial 00-项目 01-小包装的药品 99-大包装
- * @param deptCode 科室编码
- * @param groupNo 药房编码
- * @param seniorDoctor 授权医生
- * @param flag 医嘱状态标志
- * @return 返回该费用的一些详细信息,以及一些提示信息。
- */
- @DS("his")
- public ResultVo<Map<String, Object>> huoQuFeiYongXinXi(String code, String serial,
- String deptCode,
- String groupNo,
- String seniorDoctor,
- String flag) {
- Map<String, Object> map = new HashMap<>();
- // 一些提示
- List<String> prompt = new ArrayList<>();
- boolean permissionPrompt = false;
- // 加载项目信息
- 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)) {
- if (flag.equals("1")) {
- 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 {
- String key = code.trim() + serial.trim();
- YaoPinXinXi yp = dao.huoQuYaoPin(key);
- // 新开的医嘱才需要判断这个
- if (flag.equals("1")) {
- if (yp == null) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该医嘱下的药品,可能已经被停用了,请联系药剂科。");
- }
- yp.setDrugFlag(getDrugFlagByLargeCategories(yp.getCategoriesFlag()));
- YaoPinXinXi disable = dao.huoQuJinYongXinXi(key, groupNo);
- if (disable != null && disable.getVisibleFlagZy() == 1) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该药品禁止住院使用。");
- }
- if (StringUtil.notBlank(deptCode)) {
- if (dao.restrictedUseInTheDepartment(code.trim(), deptCode) > 0) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该药品禁止在患者所在的科室使用。");
- }
- }
- Integer yiShenDengJi = dao.huoQuYiShenDengJi(TokenUtil.getInstance().getTokenUserId());
- int yiShen = yiShenDengJi == null ? 0 : yiShenDengJi;
- int superior = 0;
- if (StringUtil.notBlank(seniorDoctor) && !"null".equals(seniorDoctor)) {
- Integer superiorRank = dao.huoQuYiShenDengJi(seniorDoctor);
- superior = superiorRank == null ? 0 : superiorRank;
- }
- if (yp.getYpLevel() > yiShen && yp.getYpLevel() > superior) {
- permissionPrompt = true;
- }
- 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 (disable != null && disable.getStockAmount() != null && BigUtils.bigXiaoYu(disable.getStockAmount(), 10)) {
- prompt.add(String.format("该药品剩余数量为:【%s】", disable.getStockAmount().stripTrailingZeros().toPlainString()));
- }
- if (yp.getPsFlag() == 1) {
- prompt.add("此药品为皮试药品");
- }
- }
- 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()));
- }
- map.put("yaoPingJiLiang", yaoPingJiLiang);
- map.put("data", yp);
- }
- map.put("prompt", prompt);
- map.put("permissionPrompt", permissionPrompt);
- 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";
- }
- }
- /**
- * 获取医嘱频率
- *
- * @return 返回频率
- */
- public ResultVo<List<GetDropdownBox>> getFrequency() {
- return ResultVoUtil.success(dao.selectFrequency());
- }
- /**
- * @return 给药方式
- */
- public ResultVo<List<SelectV2>> getSupplyType() {
- return ResultVoUtil.success(dao.selectSupplyType());
- }
- /**
- * 获取执行科室
- *
- * @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) {
- param.getList().get(0).setActOrderNo(new BigDecimal(param.getList().get(0).getId()));
- YiZhuCheckData checkData = new YiZhuCheckData(dao);
- checkData.init(param.getList(), null);
- Map<String, Object> errorMessage = checkData.startCheck(null);
- Map<String, Object> returnMap = new HashMap<>();
- returnMap.put("data", param.getList().get(0));
- returnMap.put("message", errorMessage.get(param.getList().get(0).getId()));
- return ResultVoUtil.success(returnMap);
- }
- public ResultVo<String> doesTheTemplateExist(String name) {
- if (dao.duplicateTemplateName(name, TokenUtil.getInstance().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.getInstance().getTokenUserId());
- UserInfo userInfo = redisLikeService.getUserInfoByCode(TokenUtil.getInstance().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.getInstance().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();
- }
- /***
- * 获取项目信息
- * @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);
- }
- /**
- * 获取医嘱录入的模板
- *
- * @param code 模板编码
- * @param deptCode 科室编码
- * @param muBanLeiXing 项目类型
- * @param currentPage 当前页
- * @param total 总数
- * @return 返回模板
- */
- 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.getInstance().getTokenUserId(), deptCode, muBanLeiXing));
- }
- page.setRecords(dao.huoQuMuBan(StringUtil.isContainChinese(code), TokenUtil.getInstance().getTokenUserId(), deptCode, muBanLeiXing, currentPage));
- return ResultVoUtil.success(page);
- }
- /**
- * 获取 我的医嘱模板的最大医嘱码
- *
- * @return 最大排序码
- */
- public ResultVo<Integer> getDoctorSOrderTemplateMaxSortNo() {
- Integer sortCode = dao.getMyTemplateMaxSortNo(TokenUtil.getInstance().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 返回数据
- */
- 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.getInstance().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);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "删除成功。");
- }
- /**
- * 收藏医嘱模板或者取消收藏
- * 如果以及收藏了就删除,没有就收藏
- *
- * @param patternCode 模板号
- * @return 提示
- */
- public ResultVo<String> collectDoctorSOrderTemplate(String patternCode) {
- String userId = TokenUtil.getInstance().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.getInstance().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 返回
- */
- @Deprecated
- 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) {
- dao.updateTheThirdLevelDoctor(param);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- /**
- * 设置父子医嘱
- *
- * @param param 主医嘱 和 多个子医嘱
- * @return 返回数据
- */
- public ResultVo<List<XinZhenYzActOrder>> associateOrders(XinZhenYiZhu param) {
- XinZhenYzActOrder order = dao.getActOrderNoOne(param.getActOrderNo());
- if (order.getParentNo() != null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "操作失败,父医嘱不能为子医嘱。");
- }
- Set<BigDecimal> orderList = new HashSet<>();
- orderList.add(order.getActOrderNo());
- param.getAssociatedGroup().forEach(item -> {
- dao.associateOrders(item, order);
- orderList.add(item);
- });
- QueryWrapper<?> qw = new QueryWrapper<>();
- qw.in("a.act_order_no", orderList);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "关联成功。", dao.selectOrderNo(qw));
- }
- /**
- * 确认 出院带药医嘱
- *
- * @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.getInstance().getTokenUserId())
- .eq("isnull(a.supply_code,'0')", 出院带药);
- XinZhenYiZhu patInfo = dao.queryPatientInfo(patNo, times);
- patInfo.setList(dao.selectOrderNo(qw));
- if (ListUtil.isBlank(patInfo.getList())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到医嘱。");
- }
- String userCode = TokenUtil.getInstance().getTokenUserId();
- // 出院带药需要生成药单 key 是不同的药房。不同的药房就要
- YiZhuCheckData checkData = new YiZhuCheckData(dao);
- checkData.init(patInfo.getList(), patInfo);
- Map<String, Object> map = checkData.startCheck(null);
- if (checkData.getPassTheAudit()) {
- sendAMessageToTheNurse(patInfo, userCode, patInfo, "出院带药");
- Date now = new Date();
- ListUtil.batchList(patInfo.getList(), YiZhuLuRuDao.class, (mapper, item) -> {
- // 出院带药 确认了直接停止医嘱
- mapper.takeMedicineAfterDischargeStopOrder(item.getActOrderNo(), userCode, now);
- });
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- } else {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的医嘱。", map);
- }
- }
- public void insertATemplate(List<XinZhenYzActOrder> list, XinZhenYiZhu patInfo) {
- String userCode = TokenUtil.getInstance().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);
- }
- public ResultVo<JSONObject> copyOrder(CopyOrder copyOrder) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- qw.eq("a.act_order_no", copyOrder.getActOrderNo());
- List<XinZhenYzActOrder> yiZhuList = dao.selectOrderNo(qw);
- if (ListUtil.isBlank(yiZhuList)) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "原医嘱已经不存在了。");
- }
- // 个人信息
- UserInfo us = redisLikeService.getUserInfoByToken();
- // 存放生成的医嘱容器
- List<BigDecimal> orderList = new ArrayList<>();
- // 原来的医嘱
- XinZhenYzActOrder fatherOrder = yiZhuList.get(0);
- // 设置默认值
- revertToTheDefaultState(fatherOrder, us, null);
- fatherOrder.setExecUnit(copyOrder.getDeptCode());
- fatherOrder.setFrequCode(copyOrder.getFrequCode());
- orderList.add(fatherOrder.getActOrderNo());
- // 查询子医嘱
- QueryWrapper<?> childQw = new QueryWrapper<>();
- // 根据父医嘱的住院号和住院次数查询医嘱,设置默认值会重新生成 actOrderNo ,所以需要使用 CopyOrder 中的 actOrderNo
- childQw.eq("a.parent_no", copyOrder.getActOrderNo());
- childQw.eq("a.inpatient_no", fatherOrder.getInpatientNo());
- childQw.eq("a.admiss_times", fatherOrder.getAdmissTimes());
- // 保存的子医嘱
- List<XinZhenYzActOrder> childOrderList = dao.selectOrderNo(childQw);
- // 存放医嘱容器
- List<XinZhenYzActOrder> addOrderList = new ArrayList<>();
- // 存放父医嘱
- addOrderList.add(fatherOrder);
- // 设置子医嘱默认值
- if (ListUtil.notBlank(childOrderList)) {
- childOrderList.forEach(item -> {
- item.setExecUnit(copyOrder.getDeptCode());
- item.setFrequCode(copyOrder.getFrequCode());
- revertToTheDefaultState(item, us, fatherOrder.getActOrderNo());
- orderList.add(item.getActOrderNo());
- addOrderList.add(item);
- });
- }
- // 获取患者信息
- XinZhenYiZhu patInfo = dao.queryPatientInfo(copyOrder.getInpatientNo(), copyOrder.getAdmissTimes());
- insertATemplate(addOrderList, patInfo);
- JSONObject js = getNewOrderData(orderList);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "复制成功。", js);
- }
- @NotNull
- private JSONObject getNewOrderData(List<BigDecimal> orderList) {
- QueryWrapper<?> newList = new QueryWrapper<>();
- newList.in("a.act_order_no", orderList);
- newList.orderByAsc("a.act_order_no");
- List<XinZhenYzActOrder> newOrderList = getOrderList(dao.selectOrderNo(newList));
- JSONObject js = new JSONObject();
- js.put("list", orderList);
- js.put("data", newOrderList);
- return js;
- }
- public ResultVo<List<ZyDetailCharge>> queryFeeByOrderNo(BigDecimal actOrderNo) {
- XinZhenYzActOrder yz = dao.getActOrderNoOne(actOrderNo.stripTrailingZeros().toPlainString());
- if (yz == null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该医嘱未产生费用。");
- }
- List<ZyDetailCharge> feeList = dao.selectOrderFee(yz);
- return ResultVoUtil.success(feeList);
- }
- public ResultVo<String> oneClickStopOrder(OneClickOrder param) {
- param.setOrderNo(publicServer.getActOrderNo());
- param.setNowDate(new Date());
- param.setUserCode(TokenUtil.getInstance().getTokenUserId());
- return executeOneClickStopOrder(param);
- }
- public ResultVo<String> executeOneClickStopOrder(OneClickOrder param) {
- // 10507 固定医嘱号
- int count = dao.oneClickStopOrder(param, param.getUserCode());
- if (count > 0) {
- // 生成医嘱
- XinZhenYiZhu patInfo = dao.queryPatientInfo(param.getPatNo(), param.getTimes());
- dao.insertOneClickStopOrder(param, patInfo);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "操作成功,正在执行的长期医嘱停止到了【" + param.getDateStr() + "】");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有需要停止的长期医嘱操作失败。");
- }
- /**
- * 上级医生登录
- *
- * @return 信息
- */
- public ResultVo<UserInfo> doctorAuthorizationLogin(UserInfo userInfo) {
- UserInfo u = dao.doctorAuthorizationLogin(userInfo);
- Integer drugLeven = dao.selectYpLevel(userInfo.getDrugCode());
- if (u == null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到指定的医生。");
- }
- if (drugLeven > (u.getDoctorLevel() + 1)) {
- return ResultVoUtil.success(ExceptionEnum.LOGICAL_ERROR, StrUtil.format("该医生等级不足,药品等级【{}】,医生等级:【{}】", drugLeven, u.getDoctorLevel()));
- }
- u.setPassword("");
- return ResultVoUtil.success(u);
- }
- public ResultVo<String> updateOrderInstruction(BigDecimal orderNo, String str) {
- dao.updateOrderInstruction(orderNo, str);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "更新成功。");
- }
- public ResultVo<JSONObject> copyTableOrder(XinZhenYiZhu param) {
- if (StringUtil.isBlank(param.getInpatientNo())) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请先选择患者.");
- }
- XinZhenYiZhu patInfo = dao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes());
- if (patInfo == null) {
- return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请先选择患者.");
- }
- List<XinZhenYzActOrder> list = param.getList();
- Queue<BigDecimal> queue = new LinkedList<>();
- // 保存 老 新 医嘱
- Map<BigDecimal, BigDecimal> map = new HashMap<>();
- for (XinZhenYzActOrder item : list) {
- BigDecimal orderNo = publicServer.getActOrderNo();
- queue.offer(orderNo);
- map.put(item.getActOrderNo(), orderNo);
- }
- List<BigDecimal> returnOrderList = new LinkedList<>();
- String userCode = TokenUtil.getInstance().getTokenUserId();
- ListUtil.batchList(list, YiZhuLuRuDao.class, (mapper, item) -> {
- item.setActOrderNo(queue.poll());
- if (item.getParentNo() != null) {
- item.setParentNo(map.get(item.getParentNo()));
- }
- returnOrderList.add(item.getActOrderNo());
- mapper.insertEntryOrder(patInfo, item, userCode);
- });
- JSONObject js = getNewOrderData(returnOrderList);
- return ResultVoUtil.success(js);
- }
- }
|