fix(hospitalization): 优化住院登记表单的默认值设置逻辑 bug#178
- 引入watch监听诊断类别字典变化,动态设置默认值 - 移除硬编码的medTypeCode初始值'21',改为从字典动态获取 - 修复科室选择逻辑,支持当前医生科室不在住院科室列表时的显示 - 为诊断类别添加验证逻辑,确保主诊断的medTypeCode在字典选项中 - 解决已选科室不在过滤列表中时无法正确显示的问题 - 添加科室树形结构递归查找功能,支持临时添加医生科室到选项列表
This commit is contained in:
@@ -184,10 +184,11 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {watch} from 'vue';
|
||||
import {getDiagnosisDefinitionList, getInit, getOrgList, handleHospitalization, wardList,} from './api.js';
|
||||
|
||||
const submitForm = reactive({
|
||||
medTypeCode: '21',
|
||||
medTypeCode: '', // 从字典动态获取默认值
|
||||
});
|
||||
|
||||
const props = defineProps({
|
||||
@@ -217,6 +218,17 @@ let diagnosisYbNo = '';
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
const { med_type } = proxy.useDict('med_type');
|
||||
|
||||
// 监听诊断类别字典加载,默认选择第一项(仅当没有主诊断时)
|
||||
watch(
|
||||
med_type,
|
||||
(newVal) => {
|
||||
if (newVal && newVal.length > 0 && !submitForm.medTypeCode && !props.mainDiagnosis) {
|
||||
submitForm.medTypeCode = newVal[0].value;
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
const rules = reactive({
|
||||
diagnosisDefinitionId: [
|
||||
{
|
||||
@@ -277,10 +289,38 @@ function openDialog() {
|
||||
|
||||
console.log('筛选后的组织机构数据:', organization.value);
|
||||
|
||||
// 如果当前患者所属科室在筛选结果中,则默认选中
|
||||
// 默认选中当前医生所在科室(即使不在住院科室列表中)
|
||||
if (props.patientInfo?.orgId) {
|
||||
submitForm.inHospitalOrgId =
|
||||
organization.value.find((item) => item?.id === props.patientInfo.orgId)?.id || '';
|
||||
const doctorOrgId = props.patientInfo.orgId;
|
||||
const exists = organization.value.some((item) => item?.id === doctorOrgId);
|
||||
|
||||
if (exists) {
|
||||
// 如果医生科室在列表中,直接选中
|
||||
submitForm.inHospitalOrgId = doctorOrgId;
|
||||
} else {
|
||||
// 如果医生科室不在列表中(如门诊科室),临时添加到列表并选中
|
||||
// 从原始数据中找到医生科室信息
|
||||
const findOrgInTree = (nodes, orgId) => {
|
||||
for (const node of nodes) {
|
||||
if (node.id === orgId) return node;
|
||||
if (node.children) {
|
||||
const found = findOrgInTree(node.children, orgId);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const doctorOrg = findOrgInTree(res.data.records, doctorOrgId);
|
||||
if (doctorOrg) {
|
||||
organization.value.unshift(doctorOrg);
|
||||
submitForm.inHospitalOrgId = doctorOrgId;
|
||||
}
|
||||
}
|
||||
|
||||
// 触发科室选择事件,加载对应病区
|
||||
if (submitForm.inHospitalOrgId) {
|
||||
handleNodeClick({ id: submitForm.inHospitalOrgId });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
organization.value = [];
|
||||
@@ -310,9 +350,21 @@ function openDialog() {
|
||||
submitForm.diagnosisDefinitionId = props.mainDiagnosis.definitionId;
|
||||
diagnosisDefinitionId = props.mainDiagnosis.definitionId;
|
||||
diagnosisYbNo = props.mainDiagnosis.ybNo || '';
|
||||
submitForm.medTypeCode = props.mainDiagnosis.medTypeCode;
|
||||
submitForm.diagnosisDesc = props.mainDiagnosis.name || ''; // 设置诊断描述
|
||||
diagnosisDefinitionList.value = [props.mainDiagnosis];
|
||||
|
||||
// 诊断类别:优先使用主诊断的medTypeCode,但要验证是否在字典选项中
|
||||
const diagnosisMedTypeCode = props.mainDiagnosis.medTypeCode;
|
||||
const medTypeExists = med_type.value && med_type.value.some(item => item.value === diagnosisMedTypeCode);
|
||||
if (medTypeExists) {
|
||||
submitForm.medTypeCode = diagnosisMedTypeCode;
|
||||
} else if (med_type.value && med_type.value.length > 0) {
|
||||
// 如果主诊断的medTypeCode不在字典中,默认选择字典第一项
|
||||
submitForm.medTypeCode = med_type.value[0].value;
|
||||
}
|
||||
} else if (med_type.value && med_type.value.length > 0) {
|
||||
// 无主诊断时,默认选择字典第一项
|
||||
submitForm.medTypeCode = med_type.value[0].value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,6 +200,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import {watch} from 'vue';
|
||||
import {
|
||||
diagnosisInit,
|
||||
getPractitionerWard,
|
||||
@@ -219,6 +220,17 @@ const { in_way_code, admit_source_code, med_type } = proxy.useDict(
|
||||
'med_type'
|
||||
);
|
||||
|
||||
// 监听诊断类别字典加载,默认选择第一项
|
||||
watch(
|
||||
med_type,
|
||||
(newVal) => {
|
||||
if (newVal && newVal.length > 0 && !submitForm.medTypeCode) {
|
||||
submitForm.medTypeCode = newVal[0].value;
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const emits = defineEmits([]);
|
||||
const props = defineProps({
|
||||
patientInfo: {
|
||||
@@ -337,7 +349,7 @@ const submitForm = reactive({
|
||||
startTime: formatDateStr(new Date(), 'YYYY-MM-DD HH:mm:ss'), // 入院日期
|
||||
priorityEnum: props.inHospitalInfo.priorityEnum, // 患者病情(字典:PatAdmCondition)
|
||||
ambDiagnosisName: props.inHospitalInfo.ambDiagnosisName,
|
||||
medTypeCode: '21',
|
||||
medTypeCode: '', // 从字典动态获取默认值
|
||||
});
|
||||
// /* 科室 病区 */
|
||||
// watch(
|
||||
@@ -445,6 +457,23 @@ function getInitOptions() {
|
||||
|
||||
// 过滤出与病区关联过的科室
|
||||
organization.value = allOrgs.filter((org) => linkedOrgIds.has(org.id));
|
||||
|
||||
// Bug #178 Fix: 如果已选科室不在列表中,手动添加以确保正确显示
|
||||
const selectedOrgId = props.inHospitalInfo?.inHospitalOrgId;
|
||||
const selectedOrgName = props.inHospitalInfo?.inHospitalOrgName;
|
||||
if (selectedOrgId && selectedOrgName) {
|
||||
const exists = organization.value.some((org) => org.id === selectedOrgId);
|
||||
if (!exists) {
|
||||
// 将已选科室添加到列表中,确保el-tree-select能正确显示名称
|
||||
organization.value.unshift({
|
||||
id: selectedOrgId,
|
||||
name: selectedOrgName,
|
||||
typeEnum: 2,
|
||||
classEnum: '2',
|
||||
children: []
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// if (!props.noFile) {
|
||||
|
||||
Reference in New Issue
Block a user