123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768 |
- package thyyxxk.webserver.service.zhuyuanyisheng.emr;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson.serializer.SerializerFeature;
- import com.baomidou.dynamic.datasource.annotation.DS;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.client.RestTemplate;
- import thyyxxk.webserver.config.exception.ExceptionEnum;
- import thyyxxk.webserver.constants.Capacity;
- import thyyxxk.webserver.constants.EmrType;
- import thyyxxk.webserver.dao.his.LoginDao;
- import thyyxxk.webserver.dao.his.zhuyuanyisheng.EmrPatientDao;
- import thyyxxk.webserver.entity.ResultVo;
- import thyyxxk.webserver.entity.datamodify.YzTemperature;
- import thyyxxk.webserver.entity.dictionary.CodeName;
- import thyyxxk.webserver.entity.drg.AuxiliaryFillingOfDiagnosis;
- import thyyxxk.webserver.entity.login.UserInfo;
- import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyPatientInfo;
- import thyyxxk.webserver.entity.zhuyuanyisheng.ZyZkList;
- import thyyxxk.webserver.entity.zhuyuanyisheng.emr.*;
- import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.YshYjReq;
- import thyyxxk.webserver.service.PublicServer;
- import thyyxxk.webserver.service.externalhttp.emr.EmrEditor;
- import thyyxxk.webserver.service.redislike.RedisLikeService;
- import thyyxxk.webserver.utils.*;
- import thyyxxk.webserver.websocket.WebSocketServer;
- import javax.websocket.Session;
- import java.util.*;
- import java.util.stream.Collectors;
- @Service
- @Slf4j
- @DS("his")
- public class EmrServer {
- private final EmrPatientDao dao;
- private final EmrEditor emr;
- private final PublicServer publicServer;
- private final LoginDao loginDao;
- private final RedisLikeService redisLikeService;
- public EmrServer(EmrPatientDao dao, EmrEditor emr, PublicServer publicServer, LoginDao loginDao, RedisLikeService redisLikeService) {
- this.dao = dao;
- this.emr = emr;
- this.publicServer = publicServer;
- this.loginDao = loginDao;
- this.redisLikeService = redisLikeService;
- }
- /**
- * 获取这个患者这个住院次数的全部电子病历
- *
- * @param patNo 住院号
- * @param times 住院次数
- * @return 数据
- */
- public ResultVo<List<EmrPatientData>> getPatientDataTree(String patNo, Integer times) {
- List<EmrPatientData> data = new ArrayList<>();
- Map<String, List<EmrPatientData>> map = dao.getPatientData(patNo, times).stream().collect(Collectors.groupingBy(EmrPatientData::getEmrCategoryCode));
- for (Map.Entry<String, List<EmrPatientData>> key : map.entrySet()) {
- if (key.getValue().size() == 1) {
- data.add(key.getValue().get(0));
- } else {
- EmrPatientData item = new EmrPatientData();
- List<EmrPatientData> children = new ArrayList<>();
- for (int i = 0, len = key.getValue().size(); i < len; i++) {
- EmrPatientData childNode = key.getValue().get(i);
- children.add(childNode);
- }
- item.setName(key.getValue().get(0).getEmrName());
- item.setChildren(new ArrayList<>()).getChildren().addAll(children);
- data.add(item);
- }
- }
- return ResultVoUtil.success(data);
- }
- public ResultVo<Map<String, List<JSONObject>>> getEmrTree(String type) {
- Map<String, List<JSONObject>> map = new HashMap<>(Capacity.TWO);
- if ("all".equals(type)) {
- map.put("all", wholeHospitalTemplate());
- map.put("dept", getDeptTemplate());
- } else if ("dept".equals(type)) {
- map.put("dept", getDeptTemplate());
- } else if ("hosp".equals(type)) {
- map.put("all", wholeHospitalTemplate());
- }
- return ResultVoUtil.success(map);
- }
- private List<JSONObject> getDeptTemplate() {
- UserInfo user = redisLikeService.getUserInfoByToken();
- JSONArray data = new JSONArray();
- if (ListUtil.notBlank(user.getPartTimeDept())) {
- user.getPartTimeDept().forEach(item -> {
- data.addAll(emr.getDeptList(item));
- });
- }
- data.addAll(emr.getDeptList(user.getDeptCode()));
- return emrToTree(data);
- }
- /**
- * 获取 整个医院模板
- */
- private List<JSONObject> wholeHospitalTemplate() {
- JSONArray data = emr.getEmrTree();
- return emrToTree(data);
- }
- /**
- * 电子病历转成树状图 二次封装
- *
- * @param data 模板数据
- * @return 返回
- */
- public List<JSONObject> emrToTree(JSONArray data) {
- List<JSONObject> tree = new ArrayList<>();
- if (data.isEmpty()) {
- return tree;
- }
- emrArrToTree(data, tree);
- return tree;
- }
- /**
- * 电子病历转成树状图
- *
- * @param data 电子病历
- * @param tree 树
- */
- private static void emrArrToTree(JSONArray data, List<JSONObject> tree) {
- Map<String, JSONObject> map = new HashMap<>(data.size());
- for (int i = 0; i < data.size(); i++) {
- JSONObject item = data.getJSONObject(i);
- if (item.get("parent") == null) {
- tree.add(item);
- }
- map.put(item.getString("_id"), item);
- }
- for (int i = 0; i < data.size(); i++) {
- JSONObject item = data.getJSONObject(i);
- if (map.containsKey(item.getString("parent"))) {
- JSONObject parentList = map.get(item.getString("parent"));
- if (parentList.get("children") == null) {
- parentList.put("children", new JSONArray());
- }
- parentList.getJSONArray("children").add(item);
- }
- }
- }
- /**
- * 获取电子病历的片段
- *
- * @return 树
- */
- public ResultVo<List<JSONObject>> getSnippetTree() {
- JSONArray data = emr.getSnippetTree();
- List<JSONObject> tree = new ArrayList<>();
- emrArrToTree(data, tree);
- return ResultVoUtil.success(tree);
- }
- /**
- * 提取患者数据元
- *
- * @param param 结构化文档
- */
- public Map<String, Object> extractDataElement(EmrPatientData param) {
- EmrDataExtract emrDataExtract = dao.extractDataSource(param.getEmrCategoryCode());
- if (emrDataExtract == null) {
- return new HashMap<>();
- }
- // 获取 需要提取的数据元
- List<String> strings = JSON.parseArray(emrDataExtract.getDataExtract(), String.class);
- // 获取前端传入的数据元
- JSONObject elementData = param.getEmrDataElement();
- // 提取到的数据
- Map<String, Object> extractedData = new HashMap<>(strings.size());
- for (String el : strings) {
- if (elementData.containsKey(el)) {
- JSONObject item = elementData.getJSONObject(el);
- Object value = item.get("value");
- if (value != null) {
- extractedData.put(el, value);
- }
- }
- }
- EmrDataElement emrDataElement = dao.obtainPatientSOriginalData(param.getPatNo(), param.getTimes());
- if (emrDataElement == null) {
- // 创建的病历可以解锁了
- dao.insertDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(extractedData));
- } else {
- JSONObject jsonObject = JSONObject.parseObject(emrDataElement.getDataElement());
- log.info("患者原来的数据:{}", jsonObject);
- jsonObject.putAll(extractedData);
- dao.updatePatientDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(jsonObject));
- }
- dao.unlockMedicalRecords(param);
- log.info("提取到的数据:{}", JSON.toJSONString(extractedData));
- return extractedData;
- }
- /**
- * 保存患者电子病历信息
- *
- * @param param 参数
- * @return 提示
- */
- public ResultVo<Map<String, Object>> insertEmrData(EmrPatientData param) {
- JSONObject saveJson = new JSONObject();
- saveJson.put("document", param.getDocumentData());
- try {
- emr.saveDocument(saveJson);
- } catch (Exception e) {
- e.printStackTrace();
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "病历保存错误,请重试!" + e.getMessage());
- }
- param.setCreateId(TokenUtil.getTokenUserId());
- boolean isUpdated = dao.whetherThereIsAMedicalRecord(param.getEmrDocumentId()).equals(1);
- Map<String, Object> extractedData = extractDataElement(param);
- if (isUpdated) {
- dao.updateCreatedTemplate(param);
- } else {
- dao.emrInsertForTheFirstTime(param);
- }
- return ResultVoUtil.success(extractedData);
- }
- /**
- * 根据患者的电子病历 id 来删除
- * 这里用的是逻辑删除
- *
- * @param documentId 电子病历id
- * @return 删除电子病历的同时需要删除, 提取到的数据源.
- */
- public ResultVo<List<String>> deletePatientEmrByDocumentId(String documentId) {
- try {
- emr.deleteEmr(documentId);
- } catch (Exception e) {
- e.printStackTrace();
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存病历失败,请重试!" + e.getMessage());
- }
- EmrPatientData patientData = dao.getCategoryCodeByDocumentId(documentId);
- EmrDataExtract emrDataExtract = dao.extractDataSource(patientData.getEmrCategoryCode());
- List<String> strings = new ArrayList<>();
- if (emrDataExtract != null) {
- // 获取 需要提取的数据元
- strings = JSON.parseArray(emrDataExtract.getDataExtract(), String.class);
- log.info("需要提取的数据:{}", strings);
- // 获取到已经提取的数据
- EmrDataElement emrDataElement = dao.obtainPatientSOriginalData(patientData.getPatNo(), patientData.getTimes());
- // 转 json
- JSONObject jsonObject = JSONObject.parseObject(emrDataElement.getDataElement());
- for (String string : strings) {
- // 删除提取到的数据
- jsonObject.remove(string);
- }
- // 更新患者数据元
- dao.updatePatientDataSource(patientData.getPatNo(), patientData.getTimes(), JSON.toJSONString(jsonObject));
- }
- // 删除病历
- dao.deletePatientEmrByDocumentId(documentId, TokenUtil.getTokenUserId());
- return ResultVoUtil.success(strings);
- }
- /**
- * 查询患者是否有指定的病历了
- *
- * @param param 住院号,住院次数,病历编码
- * @return 返回 Boolean
- */
- public ResultVo<Boolean> queryWhetherThePatientHasASpecifiedMedicalRecord(EmrPatientData param) {
- return ResultVoUtil.success(dao.queryWhetherThePatientHasASpecifiedMedicalRecord(param.getPatNo(), param.getTimes(), param.getEmrCategoryCode()) == 1);
- }
- /**
- * 医生诊断热缩
- *
- * @param userCode 医生编码
- * @param code 诊断 code
- * @param tableName 表名
- */
- public void hotSearchSorting(String userCode, String code, String tableName) {
- boolean insert = dao.queryWhetherThereIsHotSearch(userCode, code, tableName) == 0;
- if (insert) {
- dao.hotSearchSorting(userCode, code, tableName);
- } else {
- dao.updateHotSearch(userCode, code, tableName);
- }
- log.info("医生编码:{},搜索关键字:{},表名:{}", userCode, code, tableName);
- }
- /**
- * 根据文档 id 提交病历
- *
- * @param documentId 文档id
- * @return 返回数据
- */
- public ResultVo<String> submitMedicalRecord(String documentId) {
- String userCode = TokenUtil.getTokenUserId();
- String createdId = dao.getDocumentIdCreatedBy(documentId);
- log.info("提交病历==》 操作人:{},病历id:{},创建人:{}", userCode, documentId, createdId);
- if (userCode.equals(createdId)) {
- dao.updateSubmissionFlag(documentId);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "提交成功");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "创建人不一致无法修改。");
- }
- /**
- * 获取电子病历数据
- *
- * @param panNo 住院号
- * @param times 住院次数
- * @param etType 类型
- * @return 返回数据
- */
- public JSONArray getEmrData(String panNo, Integer times, EmrType etType) {
- // 查询这个病历的 唯一 id
- List<String> idList = dao.getDocumentIdByPatietn(panNo, times, etType.getName());
- JSONArray returnArray = new JSONArray();
- if (ListUtil.isBlank(idList)) {
- return returnArray;
- }
- Map<String, JSONObject> surgicalSequencing = new TreeMap<>();
- for (String s : idList) {
- JSONObject jsonObject = emr.getEditorJsonDataByDocumentId(s);
- if (etType.getCode() == EmrType.DIAGNOSIS.getCode()) {
- returnArray.addAll(extractDiagnosis(jsonObject));
- } else if (etType.getCode() == EmrType.OPERATION.getCode()) {
- String key = DateUtil.formatDatetime(jsonObject.getJSONObject("手术日期").getDate("value"));
- surgicalSequencing.put(key, jsonObject);
- }
- }
- if (!surgicalSequencing.isEmpty()) {
- for (Map.Entry<String, JSONObject> item : surgicalSequencing.entrySet()) {
- returnArray.add(item.getValue());
- }
- }
- return returnArray;
- }
- /**
- * 获取患者提取到的数据
- *
- * @param patNo 住院号
- * @param times 次数
- * @return 返回 json
- */
- public JSONObject getEmrPatientData(String patNo, Integer times) {
- String js = dao.getEmrPatientData(patNo, times);
- if (StringUtil.isBlank(js)) {
- return new JSONObject();
- }
- return JSON.parseObject(js);
- }
- /**
- * 获取患者的手术
- *
- * @param patNo 获取住院号
- * @param times 获取住院次数
- * @return 返回数据
- */
- public JSONArray getPatientSurgery(String patNo, Integer times) {
- List<String> idList = dao.getDocumentIdByPatietn(patNo, times, "a2a2866054fe11edb28ac955a5f5cad1");
- JSONArray returnArray = new JSONArray();
- if (ListUtil.isBlank(idList)) {
- return returnArray;
- }
- Map<String, JSONObject> surgicalSequencing = new TreeMap<>();
- for (String s : idList) {
- JSONObject jsonObject = emr.getEditorJsonDataByDocumentId(s);
- JSONObject surgeryDate = jsonObject.getJSONObject("手术日期");
- if (null == surgeryDate) {
- continue;
- }
- String key = DateUtil.formatDatetime(surgeryDate.getDate("value"));
- if (StringUtil.isBlank(key)) {
- continue;
- }
- surgicalSequencing.put(key, jsonObject);
- }
- if (!surgicalSequencing.isEmpty()) {
- for (Map.Entry<String, JSONObject> item : surgicalSequencing.entrySet()) {
- returnArray.add(item.getValue());
- }
- }
- return returnArray;
- }
- private JSONArray extractDiagnosis(JSONObject jsonObject) {
- JSONObject diagnosis = jsonObject.getJSONObject("入院诊断");
- if (diagnosis != null) {
- JSONArray diagnosisArr = diagnosis.getJSONArray("value");
- if (diagnosisArr != null) {
- return diagnosisArr;
- }
- }
- return new JSONArray();
- }
- public ResultVo<String> getDrgIntelligentGrouping(String patNo, Integer times) {
- // 获取诊断
- JSONArray diagnosis = getEmrData(patNo, times, EmrType.DIAGNOSIS);
- // 获取手术
- JSONArray operation = getEmrData(patNo, times, EmrType.OPERATION);
- int ledgerSn = publicServer.getLedgerSn(patNo, times);
- // 获取患者数据
- Map<String, String> mapData = dao.drgPatientInfo(patNo, times, ledgerSn);
- if (mapData == null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到患者信息。");
- }
- mapData.put("visit_id", patNo + "_" + times + "_" + ledgerSn);
- mapData.put("bah", patNo + "_" + times);
- for (int i = 0; i < diagnosis.size(); i++) {
- JSONObject item = diagnosis.getJSONObject(i);
- if (i == 0) {
- mapData.put("jbdm", item.getString("code"));
- mapData.put("zyzd", item.getString("name"));
- } else {
- mapData.put("jbdm" + i, item.getString("code"));
- }
- }
- int operationIndex = 1;
- for (int i = 0; i < operation.size(); i++) {
- JSONObject item = operation.getJSONObject(i);
- JSONArray list = item.getJSONObject("手术名称").getJSONArray("value");
- if (list == null) {
- continue;
- }
- for (int a = 0; a < list.size(); a++) {
- JSONObject valueList = list.getJSONObject(a);
- mapData.put("ssjczbm" + operationIndex, valueList.getString("code"));
- if (operationIndex == 1) {
- mapData.put("ssjczmc" + operationIndex, valueList.getString("name"));
- }
- operationIndex++;
- }
- }
- AuxiliaryFillingOfDiagnosis data = EntityCopy.Copy(mapData, AuxiliaryFillingOfDiagnosis.class);
- String url = "http://172.16.32.126:8080/drg_web/localHelp/drg_dagns/list.action";
- RestTemplate template = new RestTemplate();
- String toJsonStr = JSON.toJSONString(data, SerializerFeature.WriteNullStringAsEmpty);
- log.info("DRG数据:{}", toJsonStr);
- String res = template.postForObject(url, JSON.parseObject(toJsonStr), String.class);
- return ResultVoUtil.success("http://172.16.32.126:8080" + res);
- }
- /**
- * 获取患者最大的住院次数
- *
- * @param patNo 住院号
- * @return 返回最大次数
- */
- public ResultVo<Integer> getDischargeTimes(String patNo) {
- Integer times = dao.getMaxTimes(patNo);
- if (times == null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到患者信息。");
- }
- return ResultVoUtil.success(times);
- }
- public ResultVo<JSONObject> getExtractDataElement(String patNo, Integer times) {
- Map<String, String> map = dao.selectEmrDataElement(patNo, times);
- if (map == null) {
- return ResultVoUtil.success();
- } else {
- return ResultVoUtil.success(JSONObject.parseObject(map.get("data_element")));
- }
- }
- public ResultVo<List<CodeName>> getAllWards() {
- return ResultVoUtil.success(loginDao.getAllWards());
- }
- /**
- * 获取患者已经被删除的病历
- *
- * @param patNo 住院号
- * @return 返回
- */
- public ResultVo<List<EmrPatientData>> getDeleteMedicalRecord(String patNo) {
- Integer times = dao.getAdmissTimes(patNo);
- if (times == null) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "出院患者无法恢复病历,如果要恢复请先召回在院。");
- }
- return ResultVoUtil.success(dao.selectEmrDeteles(patNo, times, TokenUtil.getTokenUserId()));
- }
- public ResultVo<JSONObject> getInvalidByDocumentId(String id) {
- return ResultVoUtil.success(emr.getInvalidByDocumentIdApi(id));
- }
- /**
- * 恢复电子病历
- *
- * @param documentId 电子病历文档
- * @return 返回提示
- */
- public ResultVo<String> resumeMedicalRecords(String documentId) {
- EmrPatientData data = dao.selectemPatientDataOne(documentId);
- if (data.getDelFlag() == 0) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "病历已经被恢复了请勿重复点击");
- }
- Integer times = dao.getAdmissTimes(data.getPatNo());
- if (times == null) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "出院患者无法恢复病历,如果要恢复请先召回在院。");
- }
- JSONObject param = new JSONObject();
- param.put("_id", documentId);
- param.put("valid", 1);
- JSONObject json = emr.resumeMedicalRecords(documentId, param);
- log.info("恢复电子病历:{}", json);
- if (json.getInteger("ok") == 1) {
- dao.updateDeleteFlag(data.getId());
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "病历恢复成功。");
- } else {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "病历恢复失败,请重试!");
- }
- }
- /**
- * 查询出院患者的申请
- *
- * @param flag 1 只查询自己的 2 查询审核的
- * @return 提示
- */
- public ResultVo<List<DischargedEmrModifyApply>> getDisReqEmr(Integer flag) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- if (flag == 1) {
- qw.eq("req_id", TokenUtil.getTokenUserId());
- } else if (flag == 2) {
- qw.eq("req_status", 0);
- }
- qw.ge("edit_date", DateUtil.formatDatetime(new Date(), DateUtil.DATE));
- return ResultVoUtil.success(dao.getDisReqEmr(qw));
- }
- public ResultVo<List<DischargedEmrModifyApply>> downloadTheDischargeEdit(String start, String end) {
- log.info("导出出院编辑数据:开始:{},结束:{}", start, end);
- return ResultVoUtil.success(dao.selectDisReqEmyDownload(start, end));
- }
- /**
- * 申请出院患者修改
- *
- * @param param 参数
- * @return 提示
- */
- @Transactional(rollbackFor = Exception.class)
- public ResultVo<String> saveDisEmrReq(DischargedEmrModifyApply param) {
- param.setReqId(TokenUtil.getTokenUserId());
- log.info("申请出院患者修改病历:{}", JSON.toJSONString(param));
- int num = dao.deleteRequest(param.getPatNo());
- dao.insertApplicationEmrDis(param);
- if (num > 0) {
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "修改原申请成功。");
- } else {
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "申请成功。");
- }
- }
- /**
- * 删除申请
- *
- * @param patNo 住院号
- * @return 提示
- */
- public ResultVo<String> deleteDisEmrDis(String patNo) {
- dao.deleteRequest(patNo);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "操作成功。");
- }
- /**
- * 通过申请
- *
- * @param patNo 住院号
- * @return 提示
- */
- public ResultVo<String> adoptEmrDisReq(String patNo) {
- int num = dao.adoptEmrDisReq(patNo, null, 1);
- if (num > 0) {
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "操作失败,原申请可能已经被删除了。");
- }
- /**
- * 拒绝出院患者申请
- *
- * @param patNo 住院号
- * @param reviewNotes 审核信息
- * @return 提示
- */
- public ResultVo<String> refuseEmrDisReq(String patNo, String reviewNotes) {
- int num = dao.adoptEmrDisReq(patNo, reviewNotes, 2);
- if (num > 0) {
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "操作失败,原申请可能已经被删除了。");
- }
- /**
- * 查询出院患者是否已经通过了编辑
- *
- * @param patNo 住院号
- * @return Boolean
- */
- public ResultVo<Boolean> isDisReqEdit(String patNo) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- qw.eq("pat_no", patNo);
- qw.eq("req_status", 1);
- qw.ge("edit_date", DateUtil.formatDatetime(new Date(), DateUtil.DATE));
- List<DischargedEmrModifyApply> list = dao.getDisReqEmr(qw);
- if (ListUtil.isBlank(list)) {
- return ResultVoUtil.success(false);
- } else {
- return ResultVoUtil.success(true);
- }
- }
- public ResultVo<Object> getHistory(String documentId) {
- return ResultVoUtil.success(emr.getHistory(documentId));
- }
- public ResultVo<List<MedicalHistoryPrompts>> getEmrTips() {
- return ResultVoUtil.success(dao.selectEmrTips(TokenUtil.getTokenUserId()));
- }
- public ResultVo<String> addEmrTips(MedicalHistoryPrompts param) {
- log.info("数据:{}", JSON.toJSONString(param));
- UserInfo userInfo = redisLikeService.getUserInfoByToken();
- param.setDept(userInfo.getDeptCode());
- param.setCreatorId(userInfo.getCode());
- dao.insertEmrTips(param);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- public ResultVo<String> updateEmrTips(MedicalHistoryPrompts param) {
- if (param.getId() == null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "id 为空无法更新。");
- }
- dao.updateEmrTips(param);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- public ResultVo<String> deleteEmrTips(Integer id) {
- dao.delEmrTips(id);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
- }
- /**
- * 在病程记录中获取文本数据
- *
- * @param name 名称
- * @return 返回数据
- */
- public ResultVo<List<MedicalHistoryPrompts>> getEmrTipsData(String name, int typeCode) {
- QueryWrapper<?> qw = new QueryWrapper<>();
- UserInfo us = redisLikeService.getUserInfoByToken();
- if (typeCode == 1) {
- qw.eq("creator_id", us.getCode());
- } else if (typeCode == 2) {
- qw.eq("dept", us.getDeptCode());
- }
- qw.like("query_key", name)
- .eq("type_code", typeCode)
- .orderByDesc("count");
- return ResultVoUtil.success(dao.getEmrTipsData(qw));
- }
- public ResultVo<List<ZyPatientInfo>> getListOfDischargedPatients(String patNo) {
- List<ZyPatientInfo> list = dao.getListOfDischargedPatients(patNo);
- if (ListUtil.isBlank(list)) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有" + patNo + "的出院记录。");
- }
- return ResultVoUtil.success(list);
- }
- public ResultVo<JSONObject> getYzTemperature(String patNo, Integer times) {
- JSONObject js = new JSONObject();
- List<YzTemperature> list = dao.getYzTemperature(patNo, times);
- if (ListUtil.isBlank(list)) {
- return ResultVoUtil.success(js);
- }
- Map<Date, YzTemperature> map = new LinkedHashMap<>(list.size());
- for (YzTemperature item : list) {
- Date key = item.getTempDate();
- if (map.containsKey(key)) {
- YzTemperature yz = map.get(key);
- yz.setOtherInfo(nullToEmpty(yz.getOtherInfo()) + nullToEmpty(item.getOtherInfo()));
- } else {
- map.put(key, item);
- }
- }
- js.put("list", list);
- js.put("map", map);
- return ResultVoUtil.success(js);
- }
- public ResultVo<List<YshYjReq>> getExamine(String patNo, Integer times) {
- return ResultVoUtil.success(dao.getExamine(patNo, times));
- }
- private String nullToEmpty(String str) {
- if (StringUtil.isBlank(str)) {
- return "";
- }
- return str;
- }
- public ResultVo<ZyZkList> whetherItExistsInTheDepartment(String patNo, Integer times) {
- ZyZkList zk = dao.getMaxTransferDateByPatNo(patNo, times);
- if (zk != null) {
- zk.setTimeout(DateUtil.moreThanHours(zk.getOpTime(), 48));
- }
- return ResultVoUtil.success(zk);
- }
- public ResultVo<String> emrSocketUnlock(String sid) {
- List<Session> list = WebSocketServer.getEmrMap(sid);
- list.removeIf(item -> {
- if (EmrWebSocketServer.sessionParseUserCode(item).equals(TokenUtil.getTokenUserId())) {
- WebSocketServer.emrSendMessage(item, "{\"closeSoctek\":\"true\"}");
- return true;
- }
- return false;
- });
- return ResultVoUtil.success();
- }
- }
|