diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java index 3e393873..38cc522c 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java @@ -16,10 +16,12 @@ import java.util.Date; import java.sql.Timestamp; import com.openhis.common.enums.BindingType; import com.openhis.common.enums.EncounterStatus; +import com.openhis.document.domain.DocRecord; import com.openhis.document.domain.Emr; import com.openhis.document.domain.EmrDetail; import com.openhis.document.domain.EmrDict; import com.openhis.document.domain.EmrTemplate; +import com.openhis.document.service.IDocRecordService; import com.openhis.document.service.IEmrDetailService; import com.openhis.document.service.IEmrDictService; import com.openhis.document.service.IEmrService; @@ -54,6 +56,9 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi @Resource IEmrDictService emrDictService; + @Resource + IDocRecordService docRecordService; + @Resource private EncounterMapper encounterMapper; @@ -128,14 +133,33 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi /** * 获取病历详情 + * 同时检查门诊病历(emr表)和住院病历(doc_record表) * * @param encounterId 就诊id * @return 病历详情 */ @Override public R getEmrDetail(Long encounterId) { + // 先查询门诊病历(emr表) Emr emrDetail = emrService.getOne(new LambdaQueryWrapper().eq(Emr::getEncounterId, encounterId)); - return R.ok(emrDetail); + if (emrDetail != null) { + return R.ok(emrDetail); + } + + // 如果门诊病历为空,检查住院病历(doc_record表) + DocRecord docRecord = docRecordService.getOne( + new LambdaQueryWrapper() + .eq(DocRecord::getEncounterId, encounterId) + .orderByDesc(DocRecord::getCreateTime) + .last("LIMIT 1") + ); + if (docRecord != null) { + // 住院病历存在,也返回数据 + return R.ok(docRecord); + } + + // 都没有病历 + return R.ok(null); } /** diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/document/controller/DocDefinitionController.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/document/controller/DocDefinitionController.java index 57e6955a..da031b30 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/document/controller/DocDefinitionController.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/document/controller/DocDefinitionController.java @@ -106,7 +106,9 @@ public class DocDefinitionController { * @return */ @GetMapping("/treeList") - public R getTreeList(DocDefinitonParam docDefinitonParam) { + public R getTreeList(DocDefinitonParam docDefinitonParam, + @RequestParam(value = "useRanges", required = false) List useRanges) { + docDefinitonParam.setUseRanges(useRanges); return iDocDefinitionAppService.getTreeList(docDefinitonParam); } diff --git a/openhis-ui-vue3/src/views/inpatientDoctor/home/components/diagnosis/diagnosis.vue b/openhis-ui-vue3/src/views/inpatientDoctor/home/components/diagnosis/diagnosis.vue index 5b6e1c7d..1f0d10e5 100644 --- a/openhis-ui-vue3/src/views/inpatientDoctor/home/components/diagnosis/diagnosis.vue +++ b/openhis-ui-vue3/src/views/inpatientDoctor/home/components/diagnosis/diagnosis.vue @@ -189,6 +189,7 @@ import {patientInfo} from '../../store/patient.js'; import {ElMessage} from 'element-plus'; // const diagnosisList = ref([]); const allowAdd = ref(false); +const isSaving = ref(false); const tree = ref([]); const openDiagnosis = ref(false); const openAddDiagnosisDialog = ref(false); @@ -229,15 +230,42 @@ watch( { deep: true } ); +// 监听患者信息变化,自动获取病历详情和诊断列表 +watch( + () => props.patientInfo, + (newVal) => { + if (newVal?.encounterId) { + getDetail(newVal.encounterId); + getList(); + } + }, + { immediate: true, deep: true } +); + function getDetail(encounterId) { if (!encounterId) { console.warn('未提供有效的就诊ID,无法获取病历详情'); + allowAdd.value = false; return; } - getEmrDetail(encounterId).then((res) => { - allowAdd.value = res.data ? true : false; - }); + console.log('正在获取病历详情,encounterId:', encounterId); + + getEmrDetail(encounterId) + .then((res) => { + console.log('病历详情API返回:', res); + if (res.code === 200) { + allowAdd.value = res.data ? true : false; + console.log('设置 allowAdd =', allowAdd.value, ', 病历数据:', res.data); + } else { + allowAdd.value = false; + console.warn('获取病历详情失败:', res.msg); + } + }) + .catch((error) => { + console.error('获取病历详情异常:', error); + allowAdd.value = false; + }); } function getList() { @@ -245,7 +273,10 @@ function getList() { console.warn('患者就诊信息不完整,无法获取诊断数据'); return; } - + + // 初始化中医诊断列表 + const newList = []; + getEncounterDiagnosis(props.patientInfo.encounterId).then((res) => { if (res.code == 200) { const datas = (res.data || []).map((item) => { @@ -405,30 +436,57 @@ function getTree() { * 添加西医诊断 */ function handleAddDiagnosis() { - proxy.$refs.formRef.validate((valid) => { + console.log('点击新增诊断按钮,allowAdd:', allowAdd.value); + + // 检查表单ref是否存在 + if (!proxy.$refs.formRef) { + console.error('表单ref不存在'); + // 直接添加诊断,不经过表单验证 + addDiagnosisItem(); + return; + } + + proxy.$refs.formRef.validate((valid, fields) => { + console.log('表单验证结果:', valid, '错误字段:', fields); if (valid) { if (!allowAdd.value) { proxy.$modal.msgWarning('请先填写病历'); return; } - form.value.diagnosisList.push({ - showPopover: false, - name: undefined, - verificationStatusEnum: 4, - medTypeCode: undefined, // 不设默认值 - diagSrtNo: form.value.diagnosisList.length + 1, - iptDiseTypeCode: 2, - diagnosisDesc: '', - diagnosisDoctor: props.patientInfo.practitionerName || props.patientInfo.doctorName || props.patientInfo.physicianName || userStore.name, - diagnosisTime: new Date().toLocaleString('zh-CN') - }); - if (form.value.diagnosisList.length == 1) { - form.value.diagnosisList[0].maindiseFlag = 1; + addDiagnosisItem(); + } else { + console.warn('表单验证失败:', fields); + // 验证失败时也允许添加(因为是新增空行) + if (allowAdd.value) { + console.log('验证失败但允许添加,强制添加诊断'); + addDiagnosisItem(); } } }); } +/** + * 添加诊断项 + */ +function addDiagnosisItem() { + console.log('执行添加诊断,当前列表长度:', form.value.diagnosisList.length); + form.value.diagnosisList.push({ + showPopover: false, + name: undefined, + verificationStatusEnum: 4, + medTypeCode: undefined, + diagSrtNo: form.value.diagnosisList.length + 1, + iptDiseTypeCode: 2, + diagnosisDesc: '', + diagnosisDoctor: props.patientInfo.practitionerName || props.patientInfo.doctorName || props.patientInfo.physicianName || userStore.name, + diagnosisTime: new Date().toLocaleString('zh-CN') + }); + if (form.value.diagnosisList.length == 1) { + form.value.diagnosisList[0].maindiseFlag = 1; + } + console.log('添加完成,新列表长度:', form.value.diagnosisList.length); +} + // 添加中医诊断 function handleAddTcmDiagonsis() { openAddDiagnosisDialog.value = true; diff --git a/openhis-ui-vue3/src/views/inpatientDoctor/home/emr/index.vue b/openhis-ui-vue3/src/views/inpatientDoctor/home/emr/index.vue index 1f558900..4603ab01 100644 --- a/openhis-ui-vue3/src/views/inpatientDoctor/home/emr/index.vue +++ b/openhis-ui-vue3/src/views/inpatientDoctor/home/emr/index.vue @@ -560,12 +560,12 @@ const loadLatestMedicalRecord = async () => { loading.value = true; try { // 获取患者的历史病历记录 - // const res = await getRecordByEncounterIdList({ - // isPage: 0, - // encounterId: patientInfo.value.encounterId, - // patientId: patientInfo.value.patientId, - // definitionId: currentSelectTemplate.value.id, - // }); + const res = await getRecordByEncounterIdList({ + isPage: 0, + encounterId: patientInfo.value.encounterId, + patientId: patientInfo.value.patientId, + definitionId: currentSelectTemplate.value.id, + }); const historyRecords = res.data || []; if (historyRecords.length > 0) { @@ -623,7 +623,8 @@ const loadLatestMedicalRecord = async () => { loading.value = false; } } catch (error) { - ElMessage.error('加载最新病历数据失败=====>', error); + console.error('加载最新病历数据失败:', error); + ElMessage.error('加载最新病历数据失败'); // 出错时也清空选中状态 selectedHistoryRecordId.value = ''; // 出错时也要清空表单数据,避免显示之前患者的数据 diff --git a/openhis-ui-vue3/src/views/inpatientDoctor/home/index.vue b/openhis-ui-vue3/src/views/inpatientDoctor/home/index.vue index dd2cc589..200c29f9 100644 --- a/openhis-ui-vue3/src/views/inpatientDoctor/home/index.vue +++ b/openhis-ui-vue3/src/views/inpatientDoctor/home/index.vue @@ -153,6 +153,7 @@ const handleItemClick = (node) => { updateLocalPatientInfo(node); diagnosisRef.value?.getList(); + diagnosisRef.value?.getDetail(node?.encounterId); adviceRef.value?.getListInfo(); adviceRef.value?.getDiagnosisInfo(); }, 100); // 100ms 防抖延迟 @@ -189,6 +190,7 @@ watch(activeTabName, (newTab) => { provide('diagnosisInit', (value) => { currentPatientInfo.value = value; diagnosisRef.value.getList(); + diagnosisRef.value.getDetail(value?.encounterId); }); provide('getAdviceList', (value) => { adviceRef.value.getListInfo();