import { formatDateOnly, formatDateTimeDisplay } from '@/utils/datetime-display' export type SampleReceptionSourceType = 'cell_storage' | 'research_donation' export const SAMPLE_TYPE_PERINATAL_HSC = '围产期造血干细胞' export const SAMPLE_TYPE_UC_MSC = '脐带间充质干细胞' export type ProductionReceptionFieldKey = | 'originalBloodWeightG' | 'hesVolumeMl' | 'bloodType' | 'infectiousFourTestResult' | 'enrichedBloodWeightG' | 'cryopreservationVolumeMl' | 'inoculationAmount' | 'cryopreservationTime' | 'storageTotalTubes' | 'availableCellCount1e7' | 'originalBloodVolumeMl' | 'nucleatedCellCount1e8' export type ProductionReceptionFieldDef = { key: ProductionReceptionFieldKey label: string kind: 'number' | 'text' | 'datetime' | 'date' | 'select' | 'integer' maxLength?: number selectOptions?: Array<{ label: string; value: string }> } const INFECTIOUS_OPTIONS = [ { label: '正常', value: 'zc' }, { label: '不正常', value: 'bzc' } ] const FIELD_DEFS: Record = { originalBloodWeightG: { key: 'originalBloodWeightG', label: '原血重量/g', kind: 'number' }, hesVolumeMl: { key: 'hesVolumeMl', label: 'HES用量/ml', kind: 'number' }, bloodType: { key: 'bloodType', label: '血型', kind: 'text' }, infectiousFourTestResult: { key: 'infectiousFourTestResult', label: '传染四项检测(检测卡)', kind: 'select', selectOptions: INFECTIOUS_OPTIONS }, enrichedBloodWeightG: { key: 'enrichedBloodWeightG', label: '富集后血量/g', kind: 'number' }, cryopreservationVolumeMl: { key: 'cryopreservationVolumeMl', label: '冻存液用量/ml', kind: 'number' }, inoculationAmount: { key: 'inoculationAmount', label: '接种量', kind: 'text', maxLength: 255 }, cryopreservationTime: { key: 'cryopreservationTime', label: '冻存时间', kind: 'date' }, storageTotalTubes: { key: 'storageTotalTubes', label: '储存总量(管)', kind: 'integer' }, availableCellCount1e7: { key: 'availableCellCount1e7', label: '可提供细胞数量/*10E7', kind: 'number' }, originalBloodVolumeMl: { key: 'originalBloodVolumeMl', label: '原血体积/ml', kind: 'number' }, nucleatedCellCount1e8: { key: 'nucleatedCellCount1e8', label: '有核细胞数/10E8', kind: 'number' } } const PROFILE_KEYS: Record = { 'cell_storage|围产期造血干细胞': [ 'originalBloodWeightG', 'hesVolumeMl', 'bloodType', 'infectiousFourTestResult', 'enrichedBloodWeightG', 'cryopreservationVolumeMl' ], 'cell_storage|脐带间充质干细胞': [ 'inoculationAmount', 'cryopreservationTime', 'storageTotalTubes', 'availableCellCount1e7' ], 'research_donation|脐带间充质干细胞': ['inoculationAmount', 'cryopreservationTime'], 'research_donation|围产期造血干细胞': ['originalBloodVolumeMl', 'nucleatedCellCount1e8'] } export function resolveProductionReceptionFields( sourceType: string, sampleTypeName: string ): ProductionReceptionFieldDef[] { const key = `${sourceType === 'research_donation' ? 'research_donation' : 'cell_storage'}|${String(sampleTypeName || '').trim()}` const keys = PROFILE_KEYS[key] || [] return keys.map((k) => FIELD_DEFS[k]) } export function infectiousFourTestLabel(value: string) { return INFECTIOUS_OPTIONS.find((o) => o.value === value)?.label || value || '—' } /** 生产接收「处理时间」仅展示日期 YYYY-MM-DD(兼容历史带时分秒数据) */ export function formatProcessTimeDate(value: string | null | undefined): string { return formatDateOnly(value) } export type ProductionReceptionRecord = { id?: string receptionId?: string handlerUserId?: string handlerName?: string processTime?: string originalBloodWeightG?: number hesVolumeMl?: number bloodType?: string infectiousFourTestResult?: string infectiousFourTestResultLabel?: string enrichedBloodWeightG?: number cryopreservationVolumeMl?: number inoculationAmount?: string cryopreservationTime?: string storageTotalTubes?: number availableCellCount1e7?: number originalBloodVolumeMl?: number nucleatedCellCount1e8?: number remark?: string } export type QcReceptionRecord = { receptionTime?: string handlerName?: string receiveTemperature?: string acceptConclusion?: string acceptConclusionLabel?: string labStorageCode?: string checkResults?: Array<{ itemName?: string; checked?: boolean }> remark?: string receiveAttachmentFiles?: Array> } export function formatProductionFieldValue( def: ProductionReceptionFieldDef, record: ProductionReceptionRecord | null | undefined ) { if (!record) return '—' const raw = record[def.key as keyof ProductionReceptionRecord] if (raw === null || raw === undefined || raw === '') return '—' if (def.key === 'infectiousFourTestResult') { return infectiousFourTestLabel(String(raw)) } if (def.kind === 'datetime') { return formatDateTimeDisplay(String(raw)) || '—' } if (def.kind === 'date') { return formatDateOnly(String(raw)) || '—' } return String(raw) }