fix(signing): 统一性别归一逻辑,避免文书显示英文枚举
This commit is contained in:
@@ -10,6 +10,7 @@ import { mockFlags } from '@/utils/mock-flags'
|
|||||||
import { readLocalSigningTemplates } from '@/utils/mock-document-library'
|
import { readLocalSigningTemplates } from '@/utils/mock-document-library'
|
||||||
import { MOCK_STORAGE_KEYS, readMockState, writeMockState } from '@/utils/mock-storage'
|
import { MOCK_STORAGE_KEYS, readMockState, writeMockState } from '@/utils/mock-storage'
|
||||||
import { request } from '@/utils/request'
|
import { request } from '@/utils/request'
|
||||||
|
import { normalizeSexLabel } from '@/utils/signing-fields'
|
||||||
import {
|
import {
|
||||||
ALL_SIGNING_METHODS,
|
ALL_SIGNING_METHODS,
|
||||||
formatSigningMethod,
|
formatSigningMethod,
|
||||||
@@ -683,16 +684,11 @@ function formatApiDate(value: string | null | undefined) {
|
|||||||
return formatApiDateTime(value).slice(0, 10)
|
return formatApiDateTime(value).slice(0, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 与文书渲染同一条口径(utils/signing-fields 的 normalizeSexLabel),避免两处各认一套枚举 */
|
||||||
function normalizePatientSex(value: string): PatientSex {
|
function normalizePatientSex(value: string): PatientSex {
|
||||||
if (value === 'MALE' || value === '男') {
|
const label = normalizeSexLabel(value)
|
||||||
return '男'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value === 'FEMALE' || value === '女') {
|
return label === '男' || label === '女' ? label : '未知'
|
||||||
return '女'
|
|
||||||
}
|
|
||||||
|
|
||||||
return '未知'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeVisitType(value: string): VisitType {
|
function normalizeVisitType(value: string): VisitType {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
collectStructuredFieldIds,
|
collectStructuredFieldIds,
|
||||||
FIELD_ELEMENT_SELECTOR,
|
FIELD_ELEMENT_SELECTOR,
|
||||||
FIELD_TOKEN_OPEN,
|
FIELD_TOKEN_OPEN,
|
||||||
|
normalizeSexLabel,
|
||||||
PRIMARY_SIGNATURE_FIELD_ID,
|
PRIMARY_SIGNATURE_FIELD_ID,
|
||||||
readFieldFromElement,
|
readFieldFromElement,
|
||||||
resolveAnswersFromSystem,
|
resolveAnswersFromSystem,
|
||||||
@@ -775,6 +776,13 @@ export function buildSigningDocumentHtml(
|
|||||||
...(data.fieldAnswers ?? {}),
|
...(data.fieldAnswers ?? {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 性别在文书上必须落成中文:后端的填写结果里可能是 HIS 的英文枚举(MALE / FEMALE),
|
||||||
|
// 它会盖掉患者快照那一路的归一值,所以只在两路合并之后收口一次 ——
|
||||||
|
// 不这样做的话,工作台列表显示「男」、点开文书却是「MALE」。
|
||||||
|
if (typeof answers.sex === 'string') {
|
||||||
|
answers.sex = normalizeSexLabel(answers.sex)
|
||||||
|
}
|
||||||
|
|
||||||
if (data.signatureDataUrl && !answers.signature) {
|
if (data.signatureDataUrl && !answers.signature) {
|
||||||
answers.signature = data.signatureDataUrl
|
answers.signature = data.signatureDataUrl
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1057,11 +1057,31 @@ export interface SigningSystemSnapshot {
|
|||||||
signatureDataUrl?: string
|
signatureDataUrl?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 性别取值归一:HIS / 患者就诊快照可能给 `MALE` / `FEMALE` 这类英文枚举,
|
||||||
|
* 而文书上要印的是「男」/「女」——文书是要打印、要留档的,不能夹着原始枚举值。
|
||||||
|
*
|
||||||
|
* 认不出的取值原样返回,而不是抹成空:多一个没见过的枚举让它照抄原文,
|
||||||
|
* 也比把已有信息变成空白强(性别在文书上是核对项,不是纯展示项)。
|
||||||
|
*/
|
||||||
|
export function normalizeSexLabel(value: string): string {
|
||||||
|
switch (value.trim().toUpperCase()) {
|
||||||
|
case 'MALE':
|
||||||
|
case '男':
|
||||||
|
return '男'
|
||||||
|
case 'FEMALE':
|
||||||
|
case '女':
|
||||||
|
return '女'
|
||||||
|
default:
|
||||||
|
return value.trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 把患者/就诊快照映射成填写项初值,字段键即 SIGNING_FIELD_PRESETS 的 id。 */
|
/** 把患者/就诊快照映射成填写项初值,字段键即 SIGNING_FIELD_PRESETS 的 id。 */
|
||||||
export function resolveAnswersFromSystem(snapshot: SigningSystemSnapshot): SigningAnswers {
|
export function resolveAnswersFromSystem(snapshot: SigningSystemSnapshot): SigningAnswers {
|
||||||
return {
|
return {
|
||||||
patient: snapshot.patientName ?? '',
|
patient: snapshot.patientName ?? '',
|
||||||
sex: snapshot.sex ?? '',
|
sex: normalizeSexLabel(snapshot.sex ?? ''),
|
||||||
age: snapshot.age === undefined || snapshot.age === null ? '' : String(snapshot.age),
|
age: snapshot.age === undefined || snapshot.age === null ? '' : String(snapshot.age),
|
||||||
visit: snapshot.visitNo ?? '',
|
visit: snapshot.visitNo ?? '',
|
||||||
phone: snapshot.phone ?? '',
|
phone: snapshot.phone ?? '',
|
||||||
|
|||||||
Reference in New Issue
Block a user