Commit 8910c3d3 by luoqi

fix(plan): 批量 close-orphan 关闭掉出 pool 的 assigned 计划 — 补齐 2026-06 决策

runAllForHost 的 close-orphan 此前只关 status='active',assigned 不动;而 upsertPlan
注释 + closeStaleActivePlan 定向路径已是"缺口全消失即关、assigned 也关"(2026-06 决策)。
批量路径漏改 → 已认领的误召计划在算法修复后仍残留旧理由,客服按错信息跟进
(本次部署实测:李姝妤外院/余奕铭无意愿/祁小夏固定桥 排除已生效但 claimed 计划没退役)。

改:批量扫 status IN ('active','assigned'),不在本轮 hitsByPatient 的一并 supersede。
in-pool 的 assigned 不误关(其患者在 hitsByPatient 被跳过,理由已由 upsert 刷新+继承认领)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
parent 8094eea7
......@@ -226,17 +226,18 @@ export class PlanEngineService {
}
// 3. ⭐ 缺口1 修复:关闭"有 active plan 但本轮 0 命中"的患者的遗留 plan。
// 旧版只遍历 hitsByPatient(有命中的患者)→ 治完疗变 0 命中的患者,其 active plan 永远残留召回池。
// 现在:跑完 upsert(已产生本轮新 active)后,扫该 (host, tenant) 全部 status='active' plan,
// 旧版只遍历 hitsByPatient(有命中的患者)→ 治完疗变 0 命中的患者,其 plan 永远残留召回池。
// 现在:跑完 upsert(已产生本轮新 active)后,扫该 (host, tenant) 全部 active+assigned plan,
// 凡 patientId 不在本轮 hitsByPatient 的,supersede 关闭(退出召回池)。
// 纪律:
// - 按 tenant 限定(隔离闸)
// - 只关 status='active';assigned 不动(客服跟进中),终态不动
// - 必须在 upsert 循环之后扫:这样本轮 created/superseded 出的新 active(其患者在 hitsByPatient)
// 会被 hitsByPatient.has 命中而跳过,不会误关
// - 关 status IN ('active','assigned')(2026-06 决策:缺口全消失即关,assigned 也关 —
// 与 upsertPlan 注释 + closeStaleActivePlan 定向路径一致;此前批量路径漏改成只关 active,
// 致已认领的误召计划在修复后仍残留旧理由 → 客服按错信息跟进。终态不动)
// - in-pool 的 assigned 不会被误关:其患者在 hitsByPatient,会被 has 命中跳过(理由已由 upsert 刷新+继承认领)
// - 不创建后继版本(无信号是终结,非版本演进)
const activePlans = await this.prisma.followupPlan.findMany({
where: { hostId: scope.hostId, tenantId: scope.tenantId, status: 'active' },
where: { hostId: scope.hostId, tenantId: scope.tenantId, status: { in: ['active', 'assigned'] } },
select: { id: true, patientId: true },
});
const staleIds = activePlans
......
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