|  | @@ -71,13 +71,15 @@ import store from "@/store";
 | 
	
		
			
				|  |  |  import {onBeforeRouteLeave} from "vue-router";
 | 
	
		
			
				|  |  |  import {getUuid} from "@/api/public-api";
 | 
	
		
			
				|  |  |  import {
 | 
	
		
			
				|  |  | -  getDrgIntelligentGrouping, getExtractDataElement,
 | 
	
		
			
				|  |  | +  deletePatientEmrByDocumentId,
 | 
	
		
			
				|  |  | +  getDrgIntelligentGrouping, insertEmrData,
 | 
	
		
			
				|  |  |    submitMedicalRecord
 | 
	
		
			
				|  |  |  } from "@/api/zhu-yuan-yi-sheng/emr-patient";
 | 
	
		
			
				|  |  |  import {useDocumentVisibility} from "@vueuse/core";
 | 
	
		
			
				|  |  |  import EmrAssistant from "@/components/zhu-yuan-yi-sheng/emr/EmrAssistant.vue";
 | 
	
		
			
				|  |  |  import XcDialogV2 from "@/components/xiao-chan/dialog/XcDialogV2.vue";
 | 
	
		
			
				|  |  |  import {getWardsApi} from "@/api/login";
 | 
	
		
			
				|  |  | +import {xcMessage} from "@/utils/xiaochan-element-plus";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  const props = defineProps({
 | 
	
		
			
				|  |  |    huanZheXinXi: {
 | 
	
	
		
			
				|  | @@ -106,7 +108,8 @@ let openAssistant = $ref({
 | 
	
		
			
				|  |  |    data: {},
 | 
	
		
			
				|  |  |    dialog: false
 | 
	
		
			
				|  |  |  })
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +// 患者数据
 | 
	
		
			
				|  |  | +let patientData = {}
 | 
	
		
			
				|  |  |  // 编辑器
 | 
	
		
			
				|  |  |  let editor = null
 | 
	
		
			
				|  |  |  // 侧边栏
 | 
	
	
		
			
				|  | @@ -117,8 +120,7 @@ const emrSnippetRef = ref(null)
 | 
	
		
			
				|  |  |  let loaded = $ref(false)
 | 
	
		
			
				|  |  |  // 是否 改变了数据
 | 
	
		
			
				|  |  |  let isEditorChange = $ref(false)
 | 
	
		
			
				|  |  | -// 患者数据
 | 
	
		
			
				|  |  | -let patientData = {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  // 是否开启审阅模式
 | 
	
		
			
				|  |  |  let reviewMode = $ref(false)
 | 
	
		
			
				|  |  |  // 跳转定位
 | 
	
	
		
			
				|  | @@ -154,25 +156,33 @@ const clickSaveData = async () => {
 | 
	
		
			
				|  |  |      inputErrorMessage: '长度为2 - 20 个,汉字',
 | 
	
		
			
				|  |  |      inputPattern: /^\S{2,20}$/,
 | 
	
		
			
				|  |  |      inputValue: templateName
 | 
	
		
			
				|  |  | -  }).then(({value}) => {
 | 
	
		
			
				|  |  | +  }).then(async ({value}) => {
 | 
	
		
			
				|  |  |      data.name = value
 | 
	
		
			
				|  |  | -    currentEmr.value.saveDocument(data, async () => {
 | 
	
		
			
				|  |  | +    // 检验是否必填项目
 | 
	
		
			
				|  |  | +    let validator = editor.getValidator();
 | 
	
		
			
				|  |  | +    let valid = validator.valid();
 | 
	
		
			
				|  |  | +    if (valid) {
 | 
	
		
			
				|  |  | +      BizException(ExceptionEnum.MESSAGE_ERROR, "有必填项不能为空,请仔细检查,红色输入框.")
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    let res = await insertEmrData(data)
 | 
	
		
			
				|  |  | +    currentEmr.value.saveDocument(data).then(emrRes => {
 | 
	
		
			
				|  |  | +      // 把提取到的数据放到 patientData 中.
 | 
	
		
			
				|  |  | +      Object.assign(patientData, res)
 | 
	
		
			
				|  |  |        isEditorChange = false
 | 
	
		
			
				|  |  |        emrSidebarRef.value.queryData()
 | 
	
		
			
				|  |  | -      // 跳转到空白页面
 | 
	
		
			
				|  |  | -      caseHistoryUrl = `/emr/runtime/#/editor`
 | 
	
		
			
				|  |  |        let temp = {
 | 
	
		
			
				|  |  |          documentId: data.emrDocumentId,
 | 
	
		
			
				|  |  |          categoryCode: data.emrCategoryCode,
 | 
	
		
			
				|  |  |          name: data.name,
 | 
	
		
			
				|  |  |          categoryId: data.categoryId
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  | -      await updateCaseHistoryUrl(temp)
 | 
	
		
			
				|  |  | -    }, (err) => {
 | 
	
		
			
				|  |  | -      documentId = err
 | 
	
		
			
				|  |  | -      isEditorChange = true
 | 
	
		
			
				|  |  | +      updateCaseHistoryUrl(temp)
 | 
	
		
			
				|  |  | +      xcMessage.success('保存成功')
 | 
	
		
			
				|  |  | +    }).catch(() => {
 | 
	
		
			
				|  |  | +      xcMessage.error('保存失败请重新保存')
 | 
	
		
			
				|  |  |      })
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    }).catch(() => {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    })
 | 
	
	
		
			
				|  | @@ -235,12 +245,22 @@ const clickDelete = () => {
 | 
	
		
			
				|  |  |    whetherThereIsAMedicalRecordId()
 | 
	
		
			
				|  |  |    ElMessageBox.alert('是否要删除该模板。', '提示', {
 | 
	
		
			
				|  |  |      type: 'warning'
 | 
	
		
			
				|  |  | -  }).then(() => {
 | 
	
		
			
				|  |  | -    currentEmr.value.deleteDocument(documentId, function () {
 | 
	
		
			
				|  |  | -      emrSidebarRef.value.queryData()
 | 
	
		
			
				|  |  | -      emptyEditor()
 | 
	
		
			
				|  |  | -    });
 | 
	
		
			
				|  |  | -  }).catch(() => {
 | 
	
		
			
				|  |  | +  }).then(async () => {
 | 
	
		
			
				|  |  | +    // 本院删除
 | 
	
		
			
				|  |  | +    let res = await deletePatientEmrByDocumentId(documentId)
 | 
	
		
			
				|  |  | +    // 电子病历删除
 | 
	
		
			
				|  |  | +    await currentEmr.value.deleteDocument(documentId)
 | 
	
		
			
				|  |  | +    if (res.length > 0) {
 | 
	
		
			
				|  |  | +      console.log('删除的数据', res)
 | 
	
		
			
				|  |  | +      for (let i = 0; i < res.length; i++) {
 | 
	
		
			
				|  |  | +        let item = res[i]
 | 
	
		
			
				|  |  | +        // 删除提取到的数据源
 | 
	
		
			
				|  |  | +        delete patientData[item]
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    isEditorChange = false
 | 
	
		
			
				|  |  | +    emrSidebarRef.value.queryData()
 | 
	
		
			
				|  |  | +    emptyEditor()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    })
 | 
	
		
			
				|  |  |  }
 | 
	
	
		
			
				|  | @@ -342,7 +362,6 @@ const monitorPageRefresh = (event) => {
 | 
	
		
			
				|  |  |  const clickSnippet = ({content, styles}) => {
 | 
	
		
			
				|  |  |    if (!readonlyPattern()) {
 | 
	
		
			
				|  |  |      currentEmr.value.callMethod('setCursor', 'AREA_END')
 | 
	
		
			
				|  |  | -    console.log(patientData)
 | 
	
		
			
				|  |  |      currentEmr.value.insertSnippet(content, styles, patientData)
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  }
 | 
	
	
		
			
				|  | @@ -378,14 +397,18 @@ const emrEvent = {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    'contentchange': (event) => {
 | 
	
		
			
				|  |  |      if (!readonlyPattern()) {
 | 
	
		
			
				|  |  | -      // 判断内容是否改变
 | 
	
		
			
				|  |  | -      isEditorChange = true
 | 
	
		
			
				|  |  | -      emrSidebarRef.value.changeTemplateType(2)
 | 
	
		
			
				|  |  | +      // 如果是空的编辑器就不触发了
 | 
	
		
			
				|  |  | +      if (!emrRef.value.src.includes('/emr/runtime/#/editor')) {
 | 
	
		
			
				|  |  | +        // 判断内容是否改变
 | 
	
		
			
				|  |  | +        isEditorChange = true
 | 
	
		
			
				|  |  | +        emrSidebarRef.value.changeTemplateType(2)
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +// 设置编辑器的模式
 | 
	
		
			
				|  |  |  const setEditorModeFun = () => {
 | 
	
		
			
				|  |  |    // 判断是不是编辑模式
 | 
	
		
			
				|  |  |    if (emrConfig.value.editor) {
 | 
	
	
		
			
				|  | @@ -478,17 +501,14 @@ const deleteDataElement = () => {
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -/**
 | 
	
		
			
				|  |  | - * 重新查询患者信息
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | +// 重新设置提取的数据, 这里是强制替换
 | 
	
		
			
				|  |  |  const reQueryPatientInformation = () => {
 | 
	
		
			
				|  |  |    // 如果是只读模式就不触发这个
 | 
	
		
			
				|  |  |    if (!readonlyPattern()) {
 | 
	
		
			
				|  |  | -    getExtractDataElement(props.huanZheXinXi.inpatientNo, props.huanZheXinXi.admissTimes).then((res) => {
 | 
	
		
			
				|  |  | -      // getExtractDataElement('005959', 23).then((res) => {
 | 
	
		
			
				|  |  | -      Object.assign(patientData, res)
 | 
	
		
			
				|  |  | -      editor.setValues(res)
 | 
	
		
			
				|  |  | -    })
 | 
	
		
			
				|  |  | +    // 如果没有文档 id 就说明是
 | 
	
		
			
				|  |  | +    if (documentId) {
 | 
	
		
			
				|  |  | +      editor.setValues(patientData)
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |