Skip to content
Alpha: see what works today →
Menu

decisions/medications.md on GitHub, at the commit these pages were built from

Medications: each copy's own lifecycle, and how long it was taken

Status: draft, 2026-10-29, written with #292 (phase 1 of #287), which applies it; #299 adds a request's supply, its dosage's bounds and its dispensing window (rows "exposure start", "exposure end", "a supply"); #300 adds a pharmacy's dispense (rows "a dispense", "a dispense's prescription", "a dispense's lifecycle"). Acceptance waits on the departures: rows "exposure start", "exposure end", "no end", "a partial date" and "a supply". Depends on version-content.md (row "what rules read": rules read each member's own version and a small layer of derivations that defines exposure as CumulativeMedicationDuration does), clinical-terms-follow-fhir.md (a departure from FHIR is explained in its area's note, and this is the medications area's), one-meaning-per-term.md (the lifecycle classes, rule L1) and partial-dates-and-absent-reasons.md (the four date types a source date may take). The medication matching rules M15 and M16, which decide which copies are one entry, are ruled in medication-matching.md.

Question

"You have taken metformin for two years" is a question about how long a medication was taken, and a pod holds that medication as several copies, one per source and per course, joined into one entry. A rule that reads the entry reads one copy's dates and one copy's status: the entry shows its latest arrival's. The experiment on #288 (comment 3, cases c3c and c7b0) found both failures. A brand copy a second hospital first recorded in 2025, arriving after the generic the first hospital had recorded since 2022, gave the entry a 2025 start and shortened the exposure by three years (c3c). A course from 2019 to 2021 joined with a course started in 2026 lost the first course entirely (c7b0). And a copy with no end date borrowed the entry's status, so a stopped copy in an active entry read as still taken. The pod has no server of record to say which copy is right; each copy is what one source said, and a rule must read each.

What others do

Sources: CumulativeMedicationDuration 4.1.000 (https://github.com/cqframework/ecqm-content-qicore-2024/blob/07c68e5e76d96d167627469f0face771c702023f/input/cql/CumulativeMedicationDuration.cql) and 3.3.000 (https://github.com/cqframework/ecqm-content-qicore-2023/blob/da1a856e10a7ed96236009ee65840c64bc16b076/input/cql/CumulativeMedicationDuration.cql); FHIR R4 MedicationStatement (https://hl7.org/fhir/R4/medicationstatement-definitions.html#MedicationStatement.effective_x_) and MedicationRequest (https://hl7.org/fhir/R4/medicationrequest-definitions.html#MedicationRequest.authoredOn); OMOP CDM 5.4 (https://ohdsi.github.io/CommonDataModel/cdm54.html); the experiment (https://github.com/the-cascade-protocol/cascade-vocabulary/issues/288, comment 3).

Choice

thing prior art what we do borrowed or diverged Rules that cite it
a copy's own lifecycle FHIR's status on each resource; one-meaning-per-term.md's classes each medication record in an entry is classed by L1 from its own current version's status (cascade:currentVersionStatusLifecycle and its step), and the entry has the class of the member it takes its status from, or unknown where none gives one, so L1's table is written once; a rule reads the copy's class, never the entry's; rule L1 ours, as the lifecycle is (clinical-terms-follow-fhir.md, row "a departure")
exposure start CMD: start of boundsPeriod, else authoredOn, else start of dispenseRequest.validityPeriod, of the request's singleton from dosage; FHIR MedicationStatement.effective[x] the start of use (effective[x], C-CDA effectiveTime/low), else the start of the bounds of the version's one structured dosage (cascade:dosageBoundsPeriodStart), else the day the prescription was written (authoredOn), else the start of its dispensing window (cascade:dispenseValidityPeriodStart); a version with several dosages is read from these without any dosage's bounds; cascade:medicationExposureStart (queries/derivations/medication-exposure-periods.rq) borrowed from CMD's request start; diverged for a version with several dosages, where CQL's singleton from over more than one element is a run-time error and CMD gives no period: we read its start and its supply as for one dosage and leave out only the bounds, which belong to one dosage each; a statement's start is FHIR's, since CMD has no statement function No rule cites this row.
exposure end CMD: start plus days' supply times one plus refills, less one day, or the end of boundsPeriod; FHIR effective[x] the end of use (effective[x], C-CDA effectiveTime/high), else the start plus the supply (cascade:expectedSupplyDuration) times one plus the repeats (cascade:numberOfRepeatsAllowed, none stated read as 0), less one day, else the end of the one dosage's bounds (cascade:dosageBoundsPeriodEnd); a dispensing window's end is never an end; a dispense's days' supply is not read here (row "a dispense"); cascade:medicationExposureEnd (queries/derivations/medication-exposure-periods.rq) borrowed; diverged where a request states an end of use as well, which no FHIR request does, and for a version with several dosages, as in row "exposure start" No rule cites this row.
a supply CMD: convert expectedSupplyDuration to days, else quantity.value / (dose.value * dosesPerDay), and startDate + Quantity(totalDaysSupplied - 1, 'day'), where CQL ignores the decimal portion of a quantity of days; UCUM's units of time; FHIR Duration drt-1; Timing's UnitsOfTime the supply in one of the seven codes of Timing's UnitsOfTime, read in days (a week 7, a month 30.4375, a year 365.25, UCUM's mean Julian month and year), times one plus the repeats, rounded down to whole days, counted from the first day the start may be; a supply under a day ends on its start; a supply with a comparator, or with no UCUM unit, is not read; a supply from the quantity dispensed and the dose is not computed (queries/derivations/medication-exposure-periods.rq; ontologies/cascade.shapes.ttl, DurationQuantityShape) borrowed from CMD's arithmetic, its rounding and its end for a supply under a day among it; diverged in counting from the earliest start, so exposure is never overstated, and in leaving out the quantity's fallback, whose quantity term is not carried No rule cites this row.
no end CMD: null; OMOP: an imputed end with no end, cascade:medicationExposureOngoing true when the copy's own lifecycle is active, and neither an end nor the flag otherwise (queries/derivations/medication-exposure-periods.rq) diverged: CMD measures closed periods inside a measurement period, a pod asks about today, and an active status says the period has not closed, known through the current revision's cascade:observedAsOf No rule cites this row.
a partial date partial-dates-and-absent-reasons.md row "1. datatype"; CMD's date from a start given to the year or month is its last day, an end its first, and a time its day, so exposure is never overstated (queries/derivations/medication-exposure-periods.rq) borrowed from FHIR search's implied range (as row 3 of partial-dates-and-absent-reasons.md does; queries/matcher/same-code-and-period-read-as-ranges.rq), taking the range's inner edge; diverged from reading the day a source gave: CQL's date from keeps the source's precision, so a year stays a year No rule cites this row.
no period CMD: "else null"; CQL's interval needs its low at or before its high a copy with no start, or whose end so read falls before its start, has no exposure (queries/derivations/medication-exposure-periods.rq) borrowed No rule cites this row.
no collapse CMD's CumulativeDuration and RolloutIntervals; OMOP's eras the derivation writes each copy's period and never combines them: collapsing or rolling out over an entry's members is the rule's, #287 phase 3 borrowed from CMD's split between a period and a cumulative duration No rule cites this row.
the derived dates' type CMD's Interval<Date> xsd:date only, never the partial-date union, which is for dates a source wrote (ontologies/cascade.ttl) borrowed No rule cites this row.
a dispense FHIR R4 MedicationDispense, US Core 6.1.0's profile (Must Support: status, medication[x], authorizingPrescription, quantity, whenHandedOver, type, performer.actor, dosageInstruction); CMD's dispense period from Coalesce(whenHandedOver, whenPrepared) for its daysSupply a record of its own kind, cascade:MedicationDispense ("Medication dispense"), filed under records/medication-dispenses/ with a view of its own (queries/views/medication-dispenses.rq); its drug in the medication's own drug terms (cascade:drugName, rxNormCode, ndcCode, medicationCodeInOtherSystem, userSelectedCode), its status in cascade:workflowStatus, and cascade:dispensePreparedTime, cascade:dispenseHandedOverTime, cascade:dispenseQuantity and cascade:dispenseDaysSupply (<version>#dispense-days-supply, a UCUM unit of time); dated by the time it was handed over, else prepared (queries/derivations/records.rq); left out at source when entered in error borrowed: FHIR's split of a request from its supply (the maintainer's ruling on Q2, 2026-10-31, #300); type, performer beyond the record's attribution, and dosageInstruction are not carried yet No rule cites this row.
a dispense's prescription FHIR MedicationDispense.authorizingPrescription, a reference to a MedicationRequest cascade:authorizingPrescription, the prescription's medication record by its IRI, one per reference; the view names that record's medications entry; no matcher rule joins a dispense to anything, since kinds never join (tests/fixtures/kinds-never-join) and, under the M15/M16 ruling, records join only on periods with no gap, which monthly fills are not borrowed No rule cites this row.
a dispense's lifecycle FHIR R4 MedicationDispense.status (required binding, nine codes) each dispense in an entry is classed by its own current version's status (cascade:currentVersionStatusLifecycle), and the entry by the member it takes its status from, into cascade:MedicationDispenseLifecycle: completed; in progress (preparation, in-progress, on-hold); not completed (cancelled, declined, stopped); entered-in-error; unknown (unknown, absent, anything else); rule L2, queries/derivations/medication-dispense-lifecycles.rq. L1's table is never read for a dispense, so a completed fill is never a stopped medication and ends no course ours, as L1 is (clinical-terms-follow-fhir.md, row "a departure"): the classes group FHIR's codes; stopped, which FHIR says halted "before all of them occurred", is not completed, so a part-fill is never read as received

Why

Why intent is the rule's. (rows "exposure start", "exposure end") The derivation reads what the copy states. A rule filters cascade:medicationRequestIntent (a proposal or a plan is not an order) and status, as CMD's callers do with the list they hand it ("MedicationRequest status is not considered by this calculation").

Why the copy's own status. (row "a copy's own lifecycle") An entry takes its status from one member, the latest that states one (queries/derivations/status-sources.rq). That answers "is it still taken" for the entry, and nothing about the other copies: a copy completed in 2021 is stopped whatever a 2026 copy says. A rule that read the entry's class for every member would extend the 2021 course to today. Classing every record with the same L1 table, and giving the entry its status member's class, keeps one table and one meaning; a second table for records would drift.

Why CMD's definition. (rows "exposure start", "exposure end", "no period") CMD is what the CMS FHIR measures run, so a rule built on it counts exposure as a quality measure does, and a reviewer can check it against published logic. A request's start falls back from its one dosage's bounds to authoredOn and then to its dispensing window exactly as CMD's does, and with no end of use its end is CMD's supply end, else its bounds' end. A version with several dosages is a departure: CQL's singleton from over more than one element is a run-time error, so CMD gives such a request no period at all. A taper or a split dose states several dosages and was still written on a day and supplied for a time, so its start and supply end are read as for any request; only the dosages' bounds are left out, since each belongs to one dosage and none is the request's. Where CMD has no answer, a statement, FHIR's own definition of effective[x] is the period, the same element CMD would read if it had the function.

Why an ongoing flag and not an end. (row "no end") A rule asking "taken for two years" needs to know a period runs to today, and CMD's null would drop every current medication with no supply data, which is most of US Core's (version-content.md, row 4). Writing today as the end would make derived state change each day with nothing new in the pod. A flag on the copy says the period is open. It is known only through the current revision's cascade:observedAsOf, the last instant a source said the copy was active, so a rule closes the period at the earlier of that and the day it asks, never at the day it asks alone. The flag is never written false; absent means not known. It is written only for an active copy: a copy with no end that is stopped, paused or unknown is not known to have lasted past its start, so neither an end nor a flag is written, and a rule cannot overstate it.

Why the supply is read as it is. (row "a supply") CMD converts the supply to days and adds days to a date, so a supply in weeks, months or years is read in days by UCUM's own definitions of its units of time; FHIR's Duration must be a UCUM expression of time (drt-1), and the seven read are the codes of Timing's UnitsOfTime. A fraction of a day is dropped, as CQL drops it when it adds days to a date, since adding it would end the period on a day no supply reaches; a supply under a day so ends on its start, the one day it covers. The supply is counted from the first day the start may be: a prescription written in "April 2025" with 60 days' supply ran out by 30 May at the latest, and counting from 30 April would credit a month no supply covered. A comparator makes the supply a bound, which says nothing certain about its length in the direction that matters, and a supply with no UCUM unit cannot be converted, so neither is read. CMD's other supply, the quantity dispensed over the daily dose, needs dispenseRequest.quantity, which no term carries yet. A supply end is an inner bound, as a partial date's is: the supply covers the days to it, and an order may be renewed, or the medication taken from another supply, after it. With a supply end an active order is not flagged ongoing, so a rule asking how long it was taken never counts past it; a rule asking about absence reads the copy's lifecycle and its current revision's cascade:observedAsOf, never a supply-capped end.

Why the conservative bounds. (row "a partial date") A start written "2022" may be any day of 2022; reading it as 1 January would credit up to a year of exposure no source stated, and a rule asking "at least two years" would fire on a guess. Reading the start as the last day and the end as the first gives the shortest period the source allows: these are the dates the medication was certainly taken, the inner bounds, and a supply end is one too (row "a supply"). So a rule asking about absence ("no statin") must not read missing exposure triples, or an end before today, as "not taken": a course stated within one month or one year can have no exposure, and a supply runs out while the order stays active. It reads the copy's own lifecycle and its cascade:observedAsOf instead. A time is read as its day in its own zone, as CMD's date from does.

Why no collapse here. (row "no collapse") Two copies of one course overlap and two courses of one entry do not; whether to collapse, roll out or count each is the question a rule asks, with a gap it chooses, as OMOP's era does with 30 days. Collapsing in the derivation would decide it for every rule and lose the copies a rule may need to cite.

Why xsd:date. (row "the derived dates' type") The conservative bounds turn every partial date into a day, so a derived period is always to the day, and one type compares on every engine (partial-dates-and-absent-reasons.md, row "2. comparison and order").

Why a dispense is its own kind. (rows "a dispense", "a dispense's prescription", "a dispense's lifecycle") FHIR keeps the order (MedicationRequest), the person's account (MedicationStatement) and the pharmacy's supply (MedicationDispense) apart, and a dispense's statuses mean the supply, not the course: its completed is "The dispensed product has been picked up" (R4 CodeSystem medicationdispense-status). Read through L1, every filled prescription's fills would read as stopped and end the course (tests/fixtures/a-completed-dispense-neither-stops-nor-ends-its-prescription). A fill names its order, so it reaches its course by that reference, not by the matcher, which joins no records across a gap in their periods and none of two kinds.

Alternatives that lost

Still open

What would change our mind