From ae3525a88e255318c84b49fe1b2711e21a863f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 3 Sep 2026 02:08:10 +0200 Subject: [PATCH] refactor(fhir): skip an adherence observation with no expectation rather than write 0 `adherenceRatePercent` returns null exactly when nothing was expected, so callers render a placeholder instead of a misleading 0 or 100. The FHIR exporter coalesced that null to 0, which would put a clinical claim of zero adherence into an exported bundle. The guard above it means the branch cannot be reached today; skipping rather than coalescing keeps it unreachable if that guard ever moves. --- src/lib/fhir/resources/observation.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/fhir/resources/observation.ts b/src/lib/fhir/resources/observation.ts index 07176a653..45a8bc4a8 100644 --- a/src/lib/fhir/resources/observation.ts +++ b/src/lib/fhir/resources/observation.ts @@ -177,8 +177,13 @@ function adherenceObservations( for (const [name, comp] of Object.entries(data.compliance)) { if (comp.total <= 0) continue; // Integer percent — the one canonical rounding the app card + PDF use, so - // a clinician sees the same adherence figure on every surface. - const rate = adherenceRatePercent(comp.taken, comp.total) ?? 0; + // a clinician sees the same adherence figure on every surface. The helper + // returns null exactly when nothing was expected, and a `?? 0` here would + // put a clinical claim of 0 % adherence into an exported bundle in that + // case. The `total <= 0` guard above already means it cannot happen; skip + // rather than coalesce so it stays impossible if that guard ever moves. + const rate = adherenceRatePercent(comp.taken, comp.total); + if (rate === null) continue; observations.push({ resourceType: "Observation", id: nextId(),