Commit b8d7cfb0 by luoqi

refactor(cleanup): persona age-bracket/contraindication 复用 ageYearsAt(审计 G3)

两个 feature 各自的私有 ageYears 副本 → 改用 potential-treatment.feature 已导出的
ageYearsAt(urgency-level 已在用),顺手用其 null 语义合并"无出生日期"与"脏数据"判断。

service tsc 通过。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
parent ea537a02
......@@ -5,6 +5,7 @@ import type {
FeatureExtractorContext,
PersonaFeatureDraft,
} from './feature.interface';
import { ageYearsAt } from './potential-treatment.feature';
/**
* age_bracket 年龄段(A.1.1)— 规则层,snapshot 时间语义(当下从 birthDate 算)
......@@ -38,19 +39,11 @@ export class AgeBracketFeatureExtractor implements FeatureExtractor {
{ min: 55, code: 'senior', zh: '老年' }, // ≥55
];
/** 周岁:年差,生日未到则减 1 */
private static ageYears(birth: Date, now: Date): number {
let age = now.getFullYear() - birth.getFullYear();
const m = now.getMonth() - birth.getMonth();
if (m < 0 || (m === 0 && now.getDate() < birth.getDate())) age--;
return age;
}
extract(ctx: FeatureExtractorContext): PersonaFeatureDraft | null {
const birth = ctx.patient.birthDate;
if (!birth) return null; // 无出生日期 → 不打标签
const age = AgeBracketFeatureExtractor.ageYears(birth, ctx.now);
if (age < 0 || age > 120) return null; // 脏数据
const age = ageYearsAt(birth, ctx.now);
if (age === null || age < 0 || age > 120) return null; // 脏数据
// 取最后一个 min ≤ age 的档(BRACKETS 升序)
let bracket = AgeBracketFeatureExtractor.BRACKETS[0]!;
......
......@@ -5,6 +5,7 @@ import type {
FeatureExtractorContext,
PersonaFeatureDraft,
} from './feature.interface';
import { ageYearsAt } from './potential-treatment.feature';
/**
* contraindication 禁忌标签(D.2.4)— 规则层,snapshot · 多标签
......@@ -26,18 +27,11 @@ export class ContraindicationFeatureExtractor implements FeatureExtractor {
readonly key = PersonaFeatureKey.CONTRAINDICATION;
private static readonly IMPLANT_MIN_AGE = 19; // ≤18 禁忌 → 满 19 解除
private static ageYears(birth: Date, now: Date): number {
let age = now.getFullYear() - birth.getFullYear();
const m = now.getMonth() - birth.getMonth();
if (m < 0 || (m === 0 && now.getDate() < birth.getDate())) age--;
return age;
}
extract(ctx: FeatureExtractorContext): PersonaFeatureDraft | null {
const birth = ctx.patient.birthDate;
if (!birth) return null;
const age = ContraindicationFeatureExtractor.ageYears(birth, ctx.now);
if (age < 0 || age > 120) return null;
const age = ageYearsAt(birth, ctx.now);
if (age === null || age < 0 || age > 120) return null;
const types: Array<{ code: string; zh: string; reason: string; validUntil: string | null }> = [];
// 种植年龄禁忌:≤18 岁
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment