Browse Source

完善判断,不走接口进行判断了,而是走socket

xiaochan 9 months ago
parent
commit
ee6c7aa2a7

+ 44 - 39
src/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/EmrMain.vue

@@ -492,6 +492,7 @@ const emrEventProxy = new Proxy(emrEvent, {
 });
 
 const editJudgment = async () => {
+  emrStore.documentSocket.close();
   await sleep(100);
   // 没有病历 id 不锁柱
   if (stringIsBlank(getId())) {
@@ -515,47 +516,10 @@ const editJudgment = async () => {
     return;
   }
 
-  currentEditorUser.value = (await isThereADoctorEditing(getId())) as any;
-  if (currentEditorUser.value === null) {
-    emrStore.documentSocket.open(getId());
-  } else if (currentEditorUser.value.code != userInfo.code) {
-    ElMessageBox.confirm(
-      `编辑者:【${currentEditorUser.value.name}】,
-    科室:【${currentEditorUser.value.deptName}】<br />
-    正在编辑病历,请医生退出后,重新打开病历。
-    <br />
-    <span style="color: red">强制提出人员,会导致当前正在编辑的医生,退出当前病历在点击之前请确保没有医生正在编辑了。</span>
-    `,
-      "有人在编辑病历",
-      {
-        type: "warning",
-        confirmButtonText: "只读查看",
-        cancelButtonText: "强制踢出人员",
-        dangerouslyUseHTMLString: true,
-        distinguishCancelAndClose: true,
-      }
-    )
-      .then(() => {
-        setEditorModel("readonly");
-      })
-      .catch(async action => {
-        if (action === "cancel") {
-          try {
-            await emrStore.kicked.a.open(getId());
-            emrStore.documentSocket.open(getId());
-          } catch (e) {
-            setEditorModel("readonly");
-          }
-        } else {
-          setEditorModel("readonly");
-        }
-      });
-  } else {
-    emrStore.documentSocket.open(getId());
-  }
-  readonlyPattern();
+  emrStore.documentSocket.open(getId());
 };
 
+
 const setEditorModel = (val: EditorMode = "free") => {
   try {
     editor!.setEditorMode(val);
@@ -1651,6 +1615,47 @@ const initEdit = () => {
     setRevisionShowMode(userConfig.emr_review_mode);
     emrStore.mutation.installPlugins(res, emrStore);
     if (isDev) {
+      await sleep(1000);
+      loadDocument({
+        documentId: "929535792783624192",
+        categoryCode: "e2dc4540772011ef9e02e3b1f4cbc51a",
+        name: "检验粘贴单",
+        parent: "noFolder",
+        emrPatientData: {
+          id: 316772,
+          patNo: "0434450",
+          times: 1,
+          emrDocumentId: "929535792783624192",
+          emrCategoryCode: "e2dc4540772011ef9e02e3b1f4cbc51a",
+          delFlag: 0,
+          emrName: "检验粘贴单",
+          name: "检验粘贴单",
+          createId: "02896",
+          createName: "肖蟾",
+          createDate: "2024-11-20 11:09:42",
+          modifyId: "02896",
+          modifyDate: "2024-12-19 14:46:40",
+          children: null,
+          emrDataElement: null,
+          emrDataElementStr: "",
+          submit: 0,
+          submitId: null,
+          submitTime: null,
+          documentData: null,
+          fragment: null,
+          parent: "noFolder",
+          referPhysician: null,
+          consultPhysician: null,
+          deptDirector: null,
+          reviewDoctors: null,
+          reviewTime: null,
+          signType: null,
+          signComplete: null,
+          archivePath: null,
+          sort: null,
+          type: "category",
+        },
+      });
     }
   });
 };

+ 69 - 30
src/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/socket/useEmrSocket.ts

@@ -3,8 +3,6 @@ import { useWebSocket, UseWebSocketReturn } from "@vueuse/core";
 import { ElMessageBox, ElNotification } from "element-plus";
 import { EmrStore } from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-func/useEmrStore";
 import { EditType } from "@/utils/emr/edit";
-import { stringIsBlank } from "@/utils/blank-utils";
-import { xcMessage } from "@/utils/xiaochan-element-plus";
 import XEUtils from "xe-utils";
 
 const us = useUserStore().userInfo;
@@ -57,6 +55,17 @@ const socketMsg = {
   },
 };
 
+const setInfo = () => {
+  return JSON.stringify({
+    code: MessageType.USER_INFO,
+    data: {
+      deptName: us.deptName,
+      name: us.name,
+      code: us.code,
+    },
+  });
+};
+
 export function useEmrSocket(
   patInfo: string,
   store: EmrStore["store"],
@@ -75,16 +84,6 @@ export function useEmrSocket(
     },
   });
 
-  const setInfo = () => {
-    return JSON.stringify({
-      code: MessageType.USER_INFO,
-      data: {
-        deptName: us.deptName,
-        name: us.name,
-      },
-    });
-  };
-
   const { status, send } = useWebSocket(URL + "/emrEditor/" + sid, {
     autoReconnect: true,
     onError: (ws, event) => {
@@ -119,13 +118,10 @@ export function useEmrSocket(
    * 发送用户当前在看什么病历
    */
   function sendCurrentDocument() {
-    if (stringIsBlank(editor()?.documentData?._id)) {
-      return;
-    }
     sendMsg({
       code: MessageType.VIEW_DOCUMENT,
       data: {
-        id: editor().documentData._id,
+        id: editor()?.documentData?._id,
         name: us.name,
       },
     });
@@ -161,30 +157,74 @@ export function documentSocket(
     status: ref(),
   };
 
+  let documentId: string;
+
+  function open(id: string) {
+    documentId = id;
+    newSocket(URL + "/emrDocument/" + id);
+  }
+
+  function showKickingDialog(value) {
+    ElMessageBox.confirm(
+      `编辑者:【${value.name}】,
+    科室:【${value.deptName}】<br />
+    正在编辑病历,请医生退出后,重新打开病历。
+    <br />
+    <span style="color: red">强制提出人员,会导致当前正在编辑的医生,退出当前病历在点击之前请确保没有医生正在编辑了。</span>
+    `,
+      "有人在编辑病历",
+      {
+        type: "warning",
+        confirmButtonText: "只读查看",
+        cancelButtonText: "强制踢出人员",
+        dangerouslyUseHTMLString: true,
+        distinguishCancelAndClose: true,
+      }
+    )
+      .then(() => {
+        editor()?.setEditorMode?.("readonly");
+      })
+      .catch(async action => {
+        if (action === "cancel") {
+          try {
+            await kicked.a.open(documentId);
+            open(documentId);
+          } catch (e) {
+            editor()?.setEditorMode?.("readonly");
+          }
+        } else {
+          editor()?.setEditorMode?.("readonly");
+        }
+      });
+  }
+
   function newSocket(url: string) {
     socketFun.close();
-    socketFun = useWebSocket(url, {
+    const newSocketFun = useWebSocket(url, {
       autoReconnect: true,
       immediate: true,
+      heartbeat: {
+        pongTimeout: 1000,
+        message: setInfo(),
+        interval: 1000 * 60 * 3,
+      },
       onDisconnected(ws, event) {
         if (event.code > 3000) {
-          socketFun.close();
+          newSocketFun.close();
           editor().setEditorMode("readonly");
+
+          if (event.code === 3001) {
+            showKickingDialog(JSON.parse(event.reason));
+            return;
+          }
+
           ElMessageBox.alert(event.reason, "出错了", {
             type: "error",
           }).catch(XEUtils.noop);
         }
       },
       onConnected(ws) {
-        ws.send(
-          JSON.stringify({
-            code: MessageType.USER_INFO,
-            data: {
-              name: us.name,
-              code: us.code,
-            },
-          })
-        );
+        ws.send(setInfo());
         kicked.b.wsSend = value => {
           value["kicked"] = true;
           socketFun.send(JSON.stringify(value));
@@ -195,12 +235,11 @@ export function documentSocket(
         kicked.b.onMsg[value?.code]?.(value.data);
       },
     });
+    socketFun = newSocketFun;
   }
 
   return {
-    open: id => {
-      newSocket(URL + "/emrDocument/" + id);
-    },
+    open,
     status: () => socketFun.status.value,
     sendMsg(message: any) {
       socketFun.send(JSON.stringify(message));