提交
This commit is contained in:
1 parent
0b50eff3d8
commit
ee364e24aa
323 files changed
+57731
-35766
No files matched your search
@@ -0,0 +1,65 @@
|
||||
export type SampleReceptionSourceType = 'cell_storage' | 'research_donation'
|
||||
|
||||
const SAMPLE_TYPE_PERINATAL_HSC = '围产期造血干细胞'
|
||||
const SAMPLE_TYPE_UC_MSC = '脐带间充质干细胞'
|
||||
|
||||
function normalizeSampleTypeName(name: string): string {
|
||||
return String(name || '').trim()
|
||||
}
|
||||
|
||||
function normalizeSourceType(source: string): SampleReceptionSourceType {
|
||||
return source === 'research_donation' ? 'research_donation' : 'cell_storage'
|
||||
}
|
||||
|
||||
function formatYm(d: Date): string {
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}${pad(d.getMonth() + 1)}`
|
||||
}
|
||||
|
||||
function formatYear(d: Date): string {
|
||||
return String(d.getFullYear())
|
||||
}
|
||||
|
||||
/** 从接收时间字符串解析参考日期;无效时回退为当前时刻 */
|
||||
export function parseLabStorageReferenceDate(receptionTime: string): Date {
|
||||
const s = String(receptionTime || '').trim()
|
||||
const dateStr = s.length >= 10 ? s.slice(0, 10) : ''
|
||||
if (!dateStr || dateStr[4] !== '-' || dateStr[7] !== '-') {
|
||||
return new Date()
|
||||
}
|
||||
const [y, m, d] = dateStr.split('-').map((v) => Number(v))
|
||||
if (!y || !m || !d) return new Date()
|
||||
return new Date(y, m - 1, d)
|
||||
}
|
||||
|
||||
/**
|
||||
* 按来源与样本类型预制实验室入库编码;不匹配规则时返回空字符串。
|
||||
*/
|
||||
export function buildPrefilledLabStorageCode(
|
||||
sourceType: string,
|
||||
sampleTypeName: string,
|
||||
referenceDate: Date = new Date()
|
||||
): string {
|
||||
const source = normalizeSourceType(sourceType)
|
||||
const typeName = normalizeSampleTypeName(sampleTypeName)
|
||||
|
||||
if (source === 'research_donation') {
|
||||
if (typeName === SAMPLE_TYPE_PERINATAL_HSC) {
|
||||
return `UBMC${formatYm(referenceDate)}`
|
||||
}
|
||||
if (typeName === SAMPLE_TYPE_UC_MSC) {
|
||||
return `UC${formatYear(referenceDate)}`
|
||||
}
|
||||
}
|
||||
|
||||
if (source === 'cell_storage') {
|
||||
if (typeName === SAMPLE_TYPE_UC_MSC) {
|
||||
return 'BC'
|
||||
}
|
||||
if (typeName === SAMPLE_TYPE_PERINATAL_HSC) {
|
||||
return 'B'
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
Reference in new issue
Block a user