fix: 解决数据回显问题

This commit is contained in:
王天骄
2026-06-17 15:43:02 +08:00
parent 4a1fb3bc56
commit 179dca9007
+67 -12
View File
@@ -1514,7 +1514,7 @@ function fillCaseFormFromImportedPdf(result: ImportCasePdfResult) {
caseForm.chief_complaint = getImportString(record, ['chief_complaint', 'chiefComplaint']) caseForm.chief_complaint = getImportString(record, ['chief_complaint', 'chiefComplaint'])
caseForm.description = getImportString(record, ['description', 'summary', 'content']) caseForm.description = getImportString(record, ['description', 'summary', 'content'])
caseForm.patient_age = getImportNumber(record, ['patient_age', 'patientAge']) ?? undefined caseForm.patient_age = getImportNumber(record, ['patient_age', 'patientAge']) ?? undefined
caseForm.patient_gender = normalizeImportGender(getImportString(record, ['patient_gender', 'patientGender'])) caseForm.patient_gender = normalizeImportGender(getImportFirst(record, ['patient_gender', 'patientGender']))
caseForm.tags = getImportStringList(record, ['tags', 'tag_list', 'tagList']).join(', ') caseForm.tags = getImportStringList(record, ['tags', 'tag_list', 'tagList']).join(', ')
caseForm.icd_codes = getImportStringList(record, ['icd_codes', 'icdCodes', 'icd_list', 'icdList']).join(', ') caseForm.icd_codes = getImportStringList(record, ['icd_codes', 'icdCodes', 'icd_list', 'icdList']).join(', ')
caseForm.estimated_minutes = getImportNumber(record, ['estimated_minutes', 'estimatedMinutes']) ?? undefined caseForm.estimated_minutes = getImportNumber(record, ['estimated_minutes', 'estimatedMinutes']) ?? undefined
@@ -1551,7 +1551,7 @@ function fillDetailForm(row: CaseListItem, fullData: unknown) {
detailForm.chief_complaint = getImportString(record, ['chief_complaint', 'chiefComplaint'], row.chiefComplaint) detailForm.chief_complaint = getImportString(record, ['chief_complaint', 'chiefComplaint'], row.chiefComplaint)
detailForm.description = getImportString(record, ['description', 'summary', 'content']) detailForm.description = getImportString(record, ['description', 'summary', 'content'])
detailForm.patient_age = getImportNumber(record, ['patient_age', 'patientAge']) ?? undefined detailForm.patient_age = getImportNumber(record, ['patient_age', 'patientAge']) ?? undefined
detailForm.patient_gender = normalizeImportGender(getImportString(record, ['patient_gender', 'patientGender'])) detailForm.patient_gender = normalizeImportGender(getImportFirst(record, ['patient_gender', 'patientGender']))
detailForm.tags = getImportStringList(record, ['tags', 'tag_list', 'tagList']).join(', ') detailForm.tags = getImportStringList(record, ['tags', 'tag_list', 'tagList']).join(', ')
detailForm.icd_codes = getImportStringList(record, ['icd_codes', 'icdCodes', 'icd_list', 'icdList']).join(', ') detailForm.icd_codes = getImportStringList(record, ['icd_codes', 'icdCodes', 'icd_list', 'icdList']).join(', ')
detailForm.estimated_minutes = getImportNumber(record, ['estimated_minutes', 'estimatedMinutes']) ?? row.estimatedMinutes ?? undefined detailForm.estimated_minutes = getImportNumber(record, ['estimated_minutes', 'estimatedMinutes']) ?? row.estimatedMinutes ?? undefined
@@ -1690,11 +1690,17 @@ function normalizeImportCaseType(value: string, fallback: DraftCaseType): DraftC
return value === 'teaching' ? 'teaching' : fallback return value === 'teaching' ? 'teaching' : fallback
} }
function normalizeImportGender(value: string) { function normalizeImportGender(value: unknown) {
if (value === '男') return 'male' if (value === undefined || value === null) {
if (value === '女') return 'female' return ''
if (value === '未知') return 'unknown' }
return ['male', 'female', 'unknown'].includes(value) ? value : ''
const normalized = String(value).trim().toLowerCase()
if (['male', 'm', 'man', '1', '男'].includes(normalized)) return 'male'
if (['female', 'f', 'woman', '2', '女'].includes(normalized)) return 'female'
if (['unknown', 'unknow', '0', '未知', '不详'].includes(normalized)) return 'unknown'
return ''
} }
function createDetailDisplay(row: CaseListItem | null, fullData: unknown) { function createDetailDisplay(row: CaseListItem | null, fullData: unknown) {
@@ -1725,16 +1731,65 @@ function createDetailDisplay(row: CaseListItem | null, fullData: unknown) {
} }
function getDetailRecord(value: unknown): Record<string, unknown> { function getDetailRecord(value: unknown): Record<string, unknown> {
if (!value || typeof value !== 'object' || Array.isArray(value)) { return findDetailRecord(value) || {}
return {} }
function findDetailRecord(value: unknown, depth = 0): Record<string, unknown> | null {
if (!value || typeof value !== 'object' || Array.isArray(value) || depth > 4) {
return null
} }
const record = value as Record<string, unknown> const record = value as Record<string, unknown>
if (record.data && typeof record.data === 'object' && !Array.isArray(record.data)) { if (hasCaseDetailFields(record)) {
return record.data as Record<string, unknown> return record
} }
return record const preferredKeys = [
'data',
'case',
'case_detail',
'caseDetail',
'case_info',
'caseInfo',
'detail',
'full',
'result',
'record',
'item'
]
for (const key of preferredKeys) {
const found = findDetailRecord(record[key], depth + 1)
if (found) {
return found
}
}
for (const child of Object.values(record)) {
const found = findDetailRecord(child, depth + 1)
if (found) {
return found
}
}
return null
}
function hasCaseDetailFields(record: Record<string, unknown>) {
return [
'title',
'case_title',
'caseTitle',
'case_type',
'caseType',
'chief_complaint',
'chiefComplaint',
'patient_age',
'patientAge',
'patient_gender',
'patientGender',
'publish_status',
'publishStatus'
].some(key => record[key] !== undefined && record[key] !== null)
} }
function getDetailString(record: Record<string, unknown>, keys: string[]) { function getDetailString(record: Record<string, unknown>, keys: string[]) {