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 b51a74e0f..eca1143e1 100755 --- a/openhis-ui-vue3/src/views/inpatientDoctor/home/components/diagnosis/diagnosis.vue +++ b/openhis-ui-vue3/src/views/inpatientDoctor/home/components/diagnosis/diagnosis.vue @@ -360,6 +360,7 @@ import { getTcmSyndrome, isFoodDiseasesNew, saveDiagnosis, + saveTcmDiagnosis, deleteTcmDiagnosis, } from '../api'; @@ -759,13 +760,19 @@ function handleMaindise(value, index) { * 诊断体系变化处理 */ function handleDiagnosisSystemChange(row, value) { - // 当切换到西医时,清空中医证候 + // 切换诊断体系时,清空诊断名称及相关字段,避免中西医数据混淆 + row.name = ''; + row.ybNo = ''; + row.definitionId = ''; + row.showPopover = false; + if (value === '西医') { row.tcmSyndromeCode = ''; row.tcmSyndromeName = ''; } - // 当切换到中医时,根据诊断名称加载中医证候选项 if (value === '中医') { + row.tcmSyndromeCode = ''; + row.tcmSyndromeName = ''; loadTcmSyndromeOptions(row.definitionId || ''); } } @@ -811,41 +818,70 @@ function handleTcmSyndromeChange(row, value) { */ function continueSave() { - // 设置保存标志,避免触发watch监听器 isSaving.value = true; - // 步骤1:深拷贝并按 diagSrtNo 排序 const sortedList = [...form.value.diagnosisList].sort((a, b) => { const aNo = typeof a.diagSrtNo === 'number' ? a.diagSrtNo : 9999; const bNo = typeof b.diagSrtNo === 'number' ? b.diagSrtNo : 9999; return aNo - bNo; }); - // 步骤2:重新分配连续的序号(从1开始) sortedList.forEach((item, index) => { - item.diagSrtNo = index + 1; // 这里是关键!把"诊断排序"改成新顺序 + item.diagSrtNo = index + 1; }); - // 步骤3:提交排序后的数据 - saveDiagnosis({ - patientId: props.patientInfo.patientId, - encounterId: props.patientInfo.encounterId, - diagnosisChildList: sortedList, - }).then((res) => { - if (res.code === 200) { + const westernList = sortedList.filter(item => item.diagnosisSystem !== '中医'); + const tcmList = sortedList.filter(item => item.diagnosisSystem === '中医'); + + const savePromises = []; + + if (westernList.length > 0) { + savePromises.push( + saveDiagnosis({ + patientId: props.patientInfo.patientId, + encounterId: props.patientInfo.encounterId, + diagnosisChildList: westernList, + }) + ); + } + + if (tcmList.length > 0) { + const syndromeGroupNo = String(Date.now()); + const tcmSaveList = tcmList.map((item) => ({ + definitionId: item.definitionId || '', + ybNo: item.ybNo, + syndromeGroupNo: item.syndromeGroupNo || syndromeGroupNo, + verificationStatusEnum: item.verificationStatusEnum || 4, + medTypeCode: item.medTypeCode || undefined, + tcmSyndromeCode: item.tcmSyndromeCode || '', + tcmSyndromeName: item.tcmSyndromeName || '', + })); + savePromises.push( + saveTcmDiagnosis({ + patientId: props.patientInfo.patientId, + encounterId: props.patientInfo.encounterId, + diagnosisChildList: tcmSaveList, + }) + ); + } + + Promise.all(savePromises).then((results) => { + const allSuccess = results.every(res => res.code === 200 || res.code == 200); + if (allSuccess) { emits('diagnosisSave', false); proxy.$modal.msgSuccess('诊断已保存'); - - // 保存成功后从服务器重新加载数据,确保前后端数据一致 getList(); - - // 食源性疾病逻辑 isFoodDiseasesNew({ encounterId: props.patientInfo.encounterId }).then((res2) => { if (res2.code === 20 && res2.data) { window.open(res2.data, '_blank'); } }); + } else { + proxy.$modal.msgWarning('部分诊断保存失败'); + getList(); } + }).catch(() => { + proxy.$modal.msgError('诊断保存失败,请重试'); }).finally(() => { setTimeout(() => { isSaving.value = false; @@ -853,7 +889,6 @@ function continueSave() { }); } function handleSaveDiagnosis() { - // 防止重复点击保存 if (isSaving.value) { return; } @@ -887,41 +922,71 @@ function handleSaveDiagnosis() { return; } - // 设置保存标志,避免触发watch监听器 isSaving.value = true; - // 步骤1:深拷贝并按 diagSrtNo 排序 const sortedList = [...form.value.diagnosisList].sort((a, b) => { const aNo = typeof a.diagSrtNo === 'number' ? a.diagSrtNo : 9999; const bNo = typeof b.diagSrtNo === 'number' ? b.diagSrtNo : 9999; return aNo - bNo; }); - // 步骤2:重新分配连续的序号(从1开始) sortedList.forEach((item, index) => { - item.diagSrtNo = index + 1; // 这里是关键!把”诊断排序”改成新顺序 + item.diagSrtNo = index + 1; }); - // 步骤3:提交排序后的数据 - saveDiagnosis({ - patientId: props.patientInfo.patientId, - encounterId: props.patientInfo.encounterId, - diagnosisChildList: sortedList, - }).then((res) => { - if (res.code === 200) { + // 分离西医和中医诊断,分别调用对应接口保存 + const westernList = sortedList.filter(item => item.diagnosisSystem !== '中医'); + const tcmList = sortedList.filter(item => item.diagnosisSystem === '中医'); + + const savePromises = []; + + if (westernList.length > 0) { + savePromises.push( + saveDiagnosis({ + patientId: props.patientInfo.patientId, + encounterId: props.patientInfo.encounterId, + diagnosisChildList: westernList, + }) + ); + } + + if (tcmList.length > 0) { + const syndromeGroupNo = String(Date.now()); + const tcmSaveList = tcmList.map((item) => ({ + definitionId: item.definitionId || '', + ybNo: item.ybNo, + syndromeGroupNo: item.syndromeGroupNo || syndromeGroupNo, + verificationStatusEnum: item.verificationStatusEnum || 4, + medTypeCode: item.medTypeCode || undefined, + tcmSyndromeCode: item.tcmSyndromeCode || '', + tcmSyndromeName: item.tcmSyndromeName || '', + })); + savePromises.push( + saveTcmDiagnosis({ + patientId: props.patientInfo.patientId, + encounterId: props.patientInfo.encounterId, + diagnosisChildList: tcmSaveList, + }) + ); + } + + Promise.all(savePromises).then((results) => { + const allSuccess = results.every(res => res.code === 200 || res.code == 200); + if (allSuccess) { emits('diagnosisSave', false); proxy.$modal.msgSuccess('诊断已保存'); - - // 保存成功后从服务器重新加载数据,确保前后端数据一致 getList(); - - // 食源性疾病逻辑 isFoodDiseasesNew({ encounterId: props.patientInfo.encounterId }).then((res2) => { if (res2.code === 20 && res2.data) { window.open(res2.data, '_blank'); } }); + } else { + proxy.$modal.msgWarning('部分诊断保存失败'); + getList(); } + }).catch(() => { + proxy.$modal.msgError('诊断保存失败,请重试'); }).finally(() => { setTimeout(() => { isSaving.value = false;