feat(diagnosis): 完善诊断模块功能并优化病历数据获取

- 添加isSaving状态控制保存过程
- 监听患者信息变化自动获取病历详情和诊断列表
- 增强getDetail方法添加错误处理和日志输出
- 重构handleAddDiagnosis方法分离验证逻辑到独立函数
- 优化病历详情获取接口同时查询门诊和住院病历数据
- 添加文档定义树形列表按使用范围筛选功能
- 修复历史病历数据加载错误处理机制
This commit is contained in:
2026-03-12 23:21:34 +08:00
parent bc12cc1b08
commit 6af7720470
5 changed files with 114 additions and 27 deletions

View File

@@ -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;

View File

@@ -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 = '';
// 出错时也要清空表单数据,避免显示之前患者的数据

View File

@@ -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();