Commit 9a042f45 by luoqi

test(gap): 对拍差分支持 --subset=N —— 让生产真实数据上的零差异证据变得便宜

生产 113 万患者全量差分要几小时,还会跟 2 小时批次抢 RDS;收窄到几十万后
几分钟就能在**生产真实数据**上拿到证据。抽样偏向"有 active 诊断/建议信号"的患者,
否则大多数抽中的人两版都返回空,验了个寂寞。

️ 收窄降低的是**覆盖**不是可信度:差异一旦出现仍是真差异;但「子集零差异」
   ≠「全量零差异」,所以报告行里带上患者域,逼自己写清跑的是多少人。

本地 3000 位子集实测:11/11 零差异。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
parent 6d3ba7a1
...@@ -313,8 +313,34 @@ async function bootstrap(): Promise<number> { ...@@ -313,8 +313,34 @@ async function bootstrap(): Promise<number> {
if (!entries.length) throw new Error(`--sub=${args.sub} 不是已知子场景`); if (!entries.length) throw new Error(`--sub=${args.sub} 不是已知子场景`);
for (const t of tenants) { for (const t of tenants) {
const scope: ScenarioScope = { hostId: host.id, tenantId: t.tenantId, now }; // --subset=N:把对拍收窄到 N 位患者。生产 113 万患者全量差分要几小时,还会跟
out(`▶ host=${args.host} tenant=${t.tenantId} 子场景=${entries.length} 个`); // 2 小时批次抢 RDS;收窄后几分钟就能在**生产真实数据**上拿到零差异证据。
// ⚠️ 收窄降低的是**覆盖**不是可信度:差异一旦出现仍然是真差异。
// 但"子集零差异"≠"全量零差异" —— 报告时必须写清跑的是多少患者。
let subsetIds: string[] | undefined;
if (args.subset > 0) {
const rows = await prisma.$queryRaw<{ id: string }[]>(Prisma.sql`
SELECT p.id FROM patients p
WHERE p.host_id = ${host.id}::uuid AND p.tenant_id = ${t.tenantId} AND p.active = true
AND EXISTS (
SELECT 1 FROM patient_facts f
WHERE f.patient_id = p.id AND f.status = 'active'
AND f.type IN ('diagnosis_record','recommendation_record')
)
ORDER BY p.id LIMIT ${args.subset}`);
subsetIds = rows.map((r) => r.id);
out(` 收窄到 ${subsetIds.length} 位**有 active 诊断/建议信号**的患者(--subset)`);
}
const scope: ScenarioScope = {
hostId: host.id,
tenantId: t.tenantId,
now,
...(subsetIds ? { patientIds: subsetIds } : {}),
};
out(
`▶ host=${args.host} tenant=${t.tenantId} 子场景=${entries.length} 个 ` +
`患者域=${args.subset > 0 ? `${args.subset} 位子集` : '全量'}`,
);
for (const [subKey, cfg] of entries) { for (const [subKey, cfg] of entries) {
const rule = lookupDxTreatment(cfg.primaryCode); const rule = lookupDxTreatment(cfg.primaryCode);
......
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