toBundle(model) in to-bundle.ts returns the exact Bundle a cycle-log codec must emit, and stringify(bundle) returns its exact bytes. fromBundle(bundle) inverts it. The tests check fromBundle(JSON.parse(stringify(toBundle(m)))) equals normalize(m) on all twenty samples and on 300 random models that exercise every field, so the mapping is lossless for the model. Each sample's Bundle hash is pinned in golden.json.
Model semantics are in MODEL.md. This file covers the wire shape, the codes and the canonical form.
1. Bundle shape
Bundle type=collection, no id/identifier; optional timestamp (from exportedAt); meta only on a reduced card
entry[0] resource:0 Patient (always)
entry[1] resource:1 Device (only when the model has a source)
then Conditions, then all Procedures (sorted by date, kind, code, time),
then one Observation or MedicationStatement per dated fact, in the order of §3
- Export timestamp (
exportedAt) maps directly to FHIRBundle.timestamp(YYYY-MM-DDTHH:MM:SS±HH:MM, seconds always written,+00:00rather thanZ; inputFhirInstantaccepts bothZand omitted:00seconds). WhenexportedAtis omitted,Bundle.timestampis absent. There is no synthetictracking-windowObservation. - A reduced card (
reduced: true) is tagged"meta":{"tag":[{"system":"http://terminology.hl7.org/CodeSystem/v3-ObservationValue","code":"SUBSETTED","display":"subsetted"}]}on the Bundle. SUBSETTED is the R4 v3-ObservationValue code for "some information has been removed from the source object when the view this object contains was constructed" (checked in hl7.fhir.r4.core 4.0.1 and on tx.fhir.org, display "subsetted"); FHIR names it for exactly this use on Bundle.meta.tag. An unreduced card has nometa.fromBundleaccepts no othermeta. - The Patient is always
resource:0. Every fact (Observation, MedicationStatement, Procedure, Condition) has"subject":{"reference":"resource:0"}. - The source app is one Device at
resource:1:{"resourceType":"Device","deviceName":[{"name":…,"type":"user-friendly-name"}],"version":[{"value":…}]}(version only if stated). Every Observation then carries"device":{"reference":"resource:1"}. MedicationStatement, Procedure and Condition have no element that can reference a Device, so they do not. - Identity is optional and small. The model's
patientcarries at most a family name, up to three given names and a birth date.- With identity, the Patient is
{"resourceType":"Patient","name":[{"family":…,"given":[…]}],"birthDate":…}, with each part present only if the model has it, and noid. - Without identity, it is exactly
{"resourceType":"Patient","id":"0"}.
- With identity, the Patient is
- Why
id: "0"for the identity-free Patient.- A completely empty Patient fails
bdl-5("must be a resource unless there's a request or response"): R4 treats an element with no value or children as absent. idis the least assertive content. It is a logical id with no clinical meaning, unlikeactive: true(which asserts the record is in active use), a name or a gender.- Both
idandactivevalidate cleanly; the id was chosen because it asserts nothing. - The id
"0"matches the0offullUrlresource:0.resource:Nis not a RESTful URL, so R4 imposes no fullUrl/id consistency rule, and none is assumed. References always use the fullUrl. - A host that knows the person may replace the whole Patient.
- A completely empty Patient fails
- No
id,meta,text,identifier,performer,issuedornoteanywhere, except the Patient'sidand a reduced card's Bundle tag above. displayappears on the codes of the built-in fact types and vital-signscategory(§4.1), and on any non-built-in escape concept that carriescoding[0].display;CodeableConcept.textappears on any non-built-in escape concept that carriestextand on text-only{ text }concepts.
Resources by model field
| Model field | code | value | effective |
|---|---|---|---|
exportedAt | Bundle.timestamp (not a separate resource) | YYYY-MM-DDTHH:MM:SS±HH:MM (seconds always written) | – |
conditions | Condition: optional clinicalStatus (condition-clinical active / resolved), code = the condition (ConditionKind → SNOMED CT, or any FHIR CodeableConcept), subject, optional onsetDateTime (the onset date as given), asserter = the Patient | – | – |
bleeding | proposed menstrual-bleeding + display | valueBoolean | effectiveDateTime date, or date and time (below) |
bleeding flow states, in addition | proposed menstrual-flow + display | valueCodeableConcept proposed flow-* | date (the bleeding fact's time) |
volume | proposed menstrual-fluid-volume | valueQuantity integer mL | date |
pain | LOINC 72514-3 + display | valueQuantity integer {score} | date |
symptoms, one fact per symptom | proposed symptom + display | valueCodeableConcept (SymptomKind → SNOMED CT or proposed hot-flash, or any escape CodeableConcept including text-only { text }) | date |
bbt | proposed basal-body-temperature + display (distinct from LOINC 8310-5 Body temperature, which stays a vital-sign custom series) | valueQuantity Cel or [degF] (natural decimal, up to 2 decimal places); optional components reading-excluded (valueBoolean: true) and reading-exclusion-reason (valueCodeableConcept) | date |
skinTemp | proposed skin-temperature-deviation (kind deviation) or nightly-skin-temperature (kind absolute); no category | valueQuantity Cel or [degF] (natural decimal, up to 2 decimal places); optional components reading-excluded and reading-exclusion-reason | date (the wake day) |
mucus | proposed cervical-mucus | proposed mucus-* | date |
ovulationTest | proposed ovulation-test | SNOMED CT Negative / Positive / Indeterminate, proposed estrogen-surge | date |
progesteroneTest | proposed pdg-test | SNOMED CT Negative / Positive / Indeterminate | date |
pregnancyTest | LOINC 2106-3 | SNOMED CT Negative / Positive / Indeterminate | date |
sex | SNOMED CT 364316005 | SNOMED CT 63537005 / 2314005 / 70256003, proposed no-sexual-intercourse | date |
mood | proposed mood-valence | proposed valence-* (7) | date |
energy | proposed energy-level | proposed energy-* (4) | date |
sleep | LOINC 93832-4 | valueQuantity integer min | date (the wake day) |
pill | proposed contraceptive-pill-taken | valueBoolean (true = taken, false = explicitly missed) | date |
medications, one per (date, code) | MedicationStatement: status completed (taken) / not-taken; medicationCodeableConcept = the product (MedicationKind → SNOMED CT, or any escape CodeableConcept including RxNorm with display/text or text-only { text }); optional dosage[0].doseAndRate[0].doseQuantity (natural decimal UCUM quantity, up to 6 decimal places, when dose is recorded) | – | effectiveDateTime date |
intervals contraception | LOINC 8659-5 | LOINC answer from LL4578-2 | effectivePeriod start..end |
intervals pregnant | LOINC 82810-3 | LOINC LA15173-0 | effectivePeriod |
intervals breastfeeding | LOINC 63895-7 | LOINC LA29252-6 | effectivePeriod |
procedures | Procedure: status completed; code = SNOMED CT procedure (built-in ProcedureKind) or any FHIR CodeableConcept | – | performedDateTime = the model's date (FhirDateTime: YYYY, YYYY-MM, YYYY-MM-DD, or full timestamp with seconds written in FHIR) |
answers | the question's LOINC code (64700-8, 92656-8, 65930-0, 63889-0, 64701-6, 64702-4, 63888-2) | coded questions: valueCodeableConcept LOINC answer (LL1227-9, LL361-7, LL1228-7) or escape CodeableConcept; numeric: valueQuantity integer with the question's UCUM unit (/a, {#}/(3.mo), a) | date answered |
custom interval {code, value} | the given CodeableConcept | valueCodeableConcept the given CodeableConcept | effectivePeriod |
custom valueType: "boolean" | the series CodeableConcept | valueBoolean | date |
custom valueType: "coded", one fact per entry | the series CodeableConcept | valueCodeableConcept | date |
custom valueType: "quantity" | the series CodeableConcept | valueQuantity {value = natural decimal (≤ 6 decimal places), unit = code = the UCUM unit} | date |
custom valueType: "components", one fact per reading | the series CodeableConcept | no value; component [{code: the component CodeableConcept, valueBoolean / valueCodeableConcept / valueQuantity}], one per recorded component, in the components' canonical order | date |
Addressing. toBundle writes resource:N fullUrls and references, no meta.profile, and the identity-free Patient's id "0". fromBundle accepts exactly the addressing and order the project's profiles allow: entries in any order, any distinct fullUrls (urn:uuid, RESTful, resource:N), any Resource.id, subject / asserter / device references in any form that resolves within the Bundle to the Patient or the Device (an exact fullUrl, or Type/id against the referring entry's RESTful fullUrl base; as in R4 and the HL7 validator, a Type/id from a urn:uuid or resource:N entry and a version-specific _history reference do not resolve and are refused), meta.profile naming the resource's own profile (PROFILE_URL(profileNameOf(resource)), and cycle-log-bundle on the Bundle), and the SUBSETTED tag with or without its display. An identity-free Patient carries some id. It refuses anything else, and on content it is the exact inverse of toBundle.
Intervals of one state (the same kind, or the same code and value) that overlap or touch mean the same days in that state as their union; normalize merges them, so toBundle writes one interval and fromBundle accepts several.
Entries and times of day. Every entry in a series' { date, ... }[] array is its own fact, as above: one Observation, MedicationStatement or reading per entry; a bleeding entry is its bleeding fact and, for a flow state, its flow fact, both with the entry's date. A dated fact is precise to the day (YYYY-MM-DD) unless its DateTime (or FhirDateTime on a procedure) includes a time; then effectiveDateTime (or performedDateTime) is YYYY-MM-DDTHH:MM:SS±HH:MM: the local time with the offset as stored, seconds always written (:00 when the time has none), +00:00 rather than Z (input accepts Z and :00). Intervals and conditions have no time. fromBundle turns every fact into an entry of its series array (a flow fact joins the bleeding fact of the same date and time), normalizes Z to +00:00, drops :00 seconds, and writes each series in canonical order; repeats and disagreements are separate facts and stay separate entries, never merged (two identical Observations are two entries).
Escapes, displays and custom series
- Concepts (readable keywords & FHIR R4
CodeableConcept).- Built-in slots accept readable string keywords (
SymptomKind,MedicationKind,ConditionKind,Mucus,Sex,Mood,Energy,ProcedureKind,IntervalKind,ExcludeReason, codedAnswervalues) that expand on decode to canonical SNOMED CT, LOINC, orcycle-logcodings. - Escapes and
custom[]use genuine FHIR R4CodeableConceptobjects: either{"coding":[{"system":…,"code":…,"display"?:…}],"text"?:…}or text-only{"text":…}(requiring no synthetic code-system URI). - Any
CodeableConceptcan appear as symptoms, medications, conditions, and escape values of mucus, tests, sex, mood, energy, exclusion reasons and coded answers, as well as custom-series codes and values, custom interval concepts, and procedures.
- Built-in slots accept readable string keywords (
- Built-in vs. escape
displayandtext.- The six fixed displays appear only on
Observation.codeof the built-in bleeding, flow, symptom, pain and BBT facts, and on the vital-signscategory. - For any built-in concept (
BUILTIN_CONCEPTS),coding[0].displayis optional on model input and stripped in canonical form and in the emitted Bundle (apart from the six fixed displays above), andCodeableConcept.textis not allowed. - For any non-built-in escape concept — whether in SNOMED CT, LOINC, RxNorm, ICD-10-CM, ATC, NDC, or an app-defined system URI — both
coding[0].displayandCodeableConcept.text(≤ 128 chars each) are preserved verbatim and emitted on every occurrence of that(system, code)(and all occurrences in the model must agree on the samedisplayand the sametext). This enables offline human readability even for standard escape codes (as inoffline-displays). - Text-only concepts (
{"text":…}) emit{"text":…}directly as FHIRCodeableConcept(as intext-tags). fromBundlechecks displays and text by position, rejecting unexpected displays/text on built-in concepts or conflicting displays/text for one(system, code).
- The six fixed displays appear only on
- Custom series (
valueType).- Each declares its FHIR
Observation.value[x]viavalueType("boolean"→valueBoolean,"coded"→valueCodeableConcept,"quantity"→valueQuantitydecimal in UCUMunit,"components"→component[]with no top-level value) and has the shape of every built-in fact:statusfinal,effectiveDateTime(date, or date and time),subjectresource:0. - It may not use a built-in series code. Anything with a built-in code is carried by the built-in, whose coded values accept any
CodeableConcept. - Vital signs. A series whose code is one of the LOINC codes for which the HL7 validator applies an R4 vital-signs profile (the R4 ValueSet observation-vitalsignresult plus the related codes the validator maps,
R4_VITAL_SIGN_CODESinvocab.ts) is a vital sign: every fact carries"category":[{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/observation-category","code":"vital-signs","display":"Vital Signs"}]}]. Any other series has no category. - Components. A reading (
valueType: "components") is one Observation with no value of its own and acomponentper recorded value (each component declares its ownvalueType:"boolean","coded", or"quantity"). A component not recorded that day is absent from the list; a day with no recorded component has no Observation.fromBundlerebuilds the components from the codes and value types it finds; their order is the canonical concept order, because a Bundle carries none.
- Each declares its FHIR
- Quantity values. Custom quantity values are natural JSON decimals (up to 6 decimal places), printed in shortest form (
valueQuantity.value). Internally, the codec chooses the smallest exact scale (0..6) that keeps every value an integer. - Equivalence. Built-in pain and sleep (quantity), symptoms, mucus, tests, sex, mood and energy (coded), and the pill log (boolean) are produced by the same three renderers as custom series. For each, the facts are identical to the equivalent custom series apart from
Observation.code. A test checks this for six of them. Bleeding/flow, BBT, built-in intervals, and medications and procedures (MedicationStatement and Procedure resources) are special (EXPRESSIVENESS.md §1).
Quantities always carry value, unit, system (http://unitsofmeasure.org) and code, with unit equal to code. R4's body-temperature profile requires unit, and the same rule everywhere means one rule to implement.
Vital signs and the R4 vital-signs profiles
What the profiles in hl7.fhir.r4.core 4.0.1 require (StructureDefinitions vitalsigns, heartrate, resprate, oxygensat, bodyheight, headcircum, bodyweight, bmi, bp, bodytemp, vitalspanel), and what the card does about each:
| requirement | guaranteed by |
|---|---|
status, subject (the Patient), effective[x] precise to the day (vs-1) | every fact |
category vital-signs (slice VSCat, 1..1) | emitted on every fact of a series whose code is in R4_VITAL_SIGN_CODES |
code with the profile's own LOINC coding (e.g. 8867-4 for heartrate) | the series code, when it is the profile's own code |
| a value, or components (vs-2); each component has a value (vs-3) | a reading always has at least one recorded component, and only recorded components are written |
the profile's UCUM unit: heart rate and respiratory rate /min, oxygen saturation %, body height and head circumference cm or [in_i], body weight kg, g or [lb_av], BMI kg/m2 | validate (rule vital-sign-profile) requires it for those seven codes |
| a Quantity component's unit in ucum-vitals-common (required binding) | validate requires it for every quantity component of a vital-sign series |
bp: components 8480-6 and 8462-4, each a Quantity in mm[Hg] | validate requires 85354-9 to be a components series, and its 8480-6 / 8462-4 components to be quantities in mm[Hg] |
Not guaranteed:
- A blood-pressure reading with only one of its two components. The model carries it (a component can be not recorded), but bp requires both (component min 2, each slice 1..1); the validator reports two errors per such reading.
- The validator's related codes (for example 40443-4 "Heart rate --resting", 8889-8): the validator applies the matching profile, which also requires the profile's own coding (8867-4); the card writes one coding per concept, so such series do not conform to that profile. They carry the category and otherwise validate. Use the profile's own code where it says the same thing.
- 8480-6 or 8462-4 as series of their own, and the panel 85353-1 (which requires
hasMember): carried, not conformant to the profiles the validator applies. - A boolean or coded series under a vital-sign code: carried with the category; the code-specific profiles expect a Quantity.
The sample vitals-follow-up (heart rate 8867-4 in /min, weight 29463-7 in kg, blood pressure 85354-9 with both components in mm[Hg]) validates with 0 errors (§6.1). Basal body temperature uses the proposed code basal-body-temperature (separate from LOINC 8310-5 "Body temperature", which stays available as an R4 vital-sign custom series for fever / clinical temperatures — demonstrated in bbt-exclusions-and-fever).
Bleeding: the bleeding fact and the flow fact
| Model state | Facts emitted on the date |
|---|---|
| (omitted date) | none |
no-bleeding | menstrual-bleeding false |
flow-none | menstrual-bleeding false, then menstrual-flow flow-none |
bleeding | menstrual-bleeding true |
spotting / light / moderate / heavy | menstrual-bleeding true, then menstrual-flow flow-spotting / flow-light / flow-moderate / flow-heavy |
These are all the combinations for one bleeding entry. A bleeding fact is written whenever bleeding or explicit no-bleeding is recorded, and alongside every flow fact; flow-none pairs with false and spotting-or-more with true. So flow without a bleeding fact, true with flow-none, and false with spotting-or-more are excluded; fromBundle and the tests reject each one. A day may have any number of bleeding entries, timed or not, identical or disagreeing (MODEL.md §8), each its own bleeding fact and, for a flow state, its own flow fact. fromBundle recovers them as a multiset per day and time, with no pairing of individual facts needed: of f false facts, t true facts, n flow-none facts and the flow levels L, there are n × flow-none, (f − n) × no-bleeding, the levels L, and (t − |L|) × bleeding. This is exact because each state contributes a fixed set of facts; a Bundle with more flow-none facts than false facts, or more levels than true facts, at one day and time is refused.
Why these shapes
- Observation for every per-day fact and every state interval. These are things the person observed or reported.
- MedicationStatement for medications.
{"resourceType":"MedicationStatement","status":"completed"|"not-taken","medicationCodeableConcept":…,"subject":{"reference":"resource:0"},"effectiveDateTime":"YYYY-MM-DD"}(with a time when the medication series has one that day).- R4 requires
status,medication[x]andsubject(all 1..1); nothing else is required. completedmeans the person took it that day.not-takenis an explicitly recorded miss.- The product is any concept: a built-in SNOMED CT product, RxNorm, or another escape.
- Procedure for IUD and implant insertion or removal, emergency contraception and custom procedures.
{"resourceType":"Procedure","status":"completed","code":…,"subject":{"reference":"resource:0"},"performedDateTime":"YYYY-MM-DD"}.- R4 requires
statusandsubject.codeis 0..1 and is always emitted. - Emergency contraception is SNOMED CT 1372819003 "Administration of postcoital oral contraceptive". Its fully specified name carries the semantic tag (procedure). A known product (ulipristal 703737005, a levonorgestrel product) can additionally be logged as a medication escape.
- Contraceptive pill log.
- It is one boolean Observation per day, in the same pattern as menstrual bleeding: the proposed code
contraceptive-pill-takenwithvalueBoolean. Absence means not recorded. - It does not name the pill. The contraception interval (LOINC 8659-5 = combined or progestin-only pill) covering the day does.
- SNOMED CT 315604002 "Missed contraceptive pill (situation)" covers only the missed case, and nothing exists for "pill taken today". The CodeSystem definition records that
falseis equivalent to 315604002.
- It is one boolean Observation per day, in the same pattern as menstrual bleeding: the proposed code
- Contraception, pregnancy and breastfeeding as Observations with
effectivePeriod. The period is the calendar date range (start..end) during which the state held.- LOINC 8659-5, 82810-3 and 63895-7 are point-in-time codes, so the validator adds an information-level note.
- The alternative, one dated Observation per day, would multiply entries about 300-fold.
- BBT uses the proposed code
basal-body-temperature(separate from LOINC 8310-5 Body temperature, so fever readings recorded as vital signs never mix into fertility thermal-shift detection). Disturbed readings carryreading-excluded(valueBoolean: true) and an optionalreading-exclusion-reasoncomponent (fever,alcohol,poor-sleep,late-wake,travel,stress,medication,other, or any escape concept). - Condition for reported conditions.
- R4 requires only
subject, pluscodeby convention. clinicalStatusappears only when the person stated it.- There is no
verificationStatus: "confirmed" would claim more than a self-report can. - There is no
category:problem-list-itemandencounter-diagnosisare clinical-record categories, and con-3 only applies to problem-list items. asserter= the Patient marks the condition as patient-reported.
- R4 requires only
- Reduced cards carry the R4 SUBSETTED tag rather than a list of what was reduced: the model has one flag (MODEL.md §8).
- Wearable temperature uses proposed codes, not LOINC.
- LOINC 39106-0 "Temperature of Skin" is nominal scale (the validator warns on a quantity) and is not a sleep aggregate.
- Neither proposed code is in the set of LOINC codes the validator binds to R4 vital-signs profiles, so no
categoryis needed. - For a
deviationthe quantity is a difference expressed inCel(or[degF]), as the code's definition says.
- Measured volume uses a proposed code. SNOMED CT 364308001 "Quantity of menstrual blood loss" means blood; a cup collects menstrual fluid, whose blood fraction varies widely between people (1.6% to 81.7%, Fraser 1985).
- Screening answers use the questions' own LOINC codes and answer lists. An answer is dated on the day it was given, and the card has no computed summaries.
2. Canonical serialization (stringify)
- UTF-8 JSON with no insignificant whitespace and no trailing newline.
- Key order. Every object's keys follow this single global order, which is FHIR's element order for every object type that occurs (Bundle and its meta, entry, Patient, HumanName, Device and its deviceName and version, Observation and its component, MedicationStatement, Procedure, Condition, CodeableConcept, Coding, Quantity, Period, Reference) merged without conflict. Any other key is an error.
resourceType id meta tag name type timestamp entry fullUrl resource deviceName version status clinicalStatus category coding text value unit system code display medicationCodeableConcept subject reference effectiveDateTime effectivePeriod start end dosage doseAndRate doseQuantity performedDateTime onsetDateTime valueBoolean valueCodeableConcept valueQuantity device component asserter family given birthDate - Numbers use the ECMAScript shortest round-trip form (
JSON.stringify).- Pain, sleep, volume and numeric answers are integers.
- BBT and skin temperature are natural decimals with up to 2 decimal places (
36.5,37,98.66,-0.31), printed with no trailing zeros. - Medication doses and custom quantities are natural decimals with up to 6 decimal places, printed with no trailing zeros.
- The Rust WASM codec formats all decimals with exact integer arithmetic (zero floats).
- Strings use
JSON.stringifyescaping. Built-in strings are ASCII. Escape codes and labels may contain any Unicode except control characters and unpaired surrogates, so a codec must escape"as\"and\as\\and output everything else as UTF-8 unchanged. - Dates are
YYYY-MM-DD, directly from the model's calendar dates. A time of day follows asTHH:MM:SS(seconds always two digits,00when not recorded) and the offset exactly as stored (+00:00, neverZ).Bundle.timestampuses the same instant format whenexportedAtis present.
3. Entry order
The order is a pure function of the normalized model:
resource:0is the Patient.resource:1is the Device, if the model has a source.- Conditions, in canonical concept order (condition table index, then SNOMED CT ids ascending, then code-point order).
- Procedures (all procedures, unified), sorted by date (as a string:
2019<2019-05<2019-05-03<2020), then index inPROCEDURE, then code, then time. - Every other entry, sorted by (date, rank, sub-rank). Date is the fact's calendar date, or
startfor an interval. Within one series and date, the entries come in their canonical order (MODEL.md §8: without a time first, then by instant).
| rank | kind | sub-rank (within the same date and rank) |
|---|---|---|
| 1 | interval | position in the normalized intervals list, sorted by (start, index in INTERVAL_KIND, end) |
| 2 | screening answer | position in the normalized answers list (date, then index in QUESTIONS, then time) |
| 3 | menstrual-bleeding, each followed by its menstrual-flow fact | the entry's position on the date |
| 4 | (unused: flow facts follow their bleeding fact) | – |
| 5 | volume | – |
| 6 | pain | – |
| 7 | symptom | the entry's position on the date: plain dates in canonical concept order (below) with the symptom table |
| 8 | BBT | – |
| 9 | skin temperature | – |
| 10 | cervical mucus | – |
| 11 | ovulation test | – |
| 12 | progesterone (PdG) test | – |
| 13 | pregnancy test | – |
| 14 | sexual intercourse | – |
| 15 | mood | – |
| 16 | energy | – |
| 17 | sleep | – |
| 18 | pill log | – |
| 19 | MedicationStatement (taken or not-taken) | the entry's position on the date: plain dates in canonical medication order (built-in table index, then SNOMED CT ids ascending numerically, then other keys in code-point order) |
| 20 | custom series | 100,000 × (position of the series in the canonical custom list, which is sorted by code) + the entry's position on the date |
Concept order everywhere is: built-in table index (where a table exists), then coded concepts before text-only concepts (SNOMED CT ids ascending numerically, then other coded keys in Unicode code-point order, equal to UTF-8 byte order), then text-only { text } concepts in Unicode code-point order of their text. Custom intervals sort after built-in kinds that start the same date, by (code, value, end). Procedures sort by date string, then built-in kind index, then custom procedures by code, then time. Every per-day series not listed with a sub-rank above has, for its entries on one date, the entry's position on that date.
fullUrl is resource:<position>.
4. Fixed displays and things deliberately not done
The design started from the HL7 Period Tracking implementation guide; reconciling these codes and shapes with it is future work. The Bundles are validated against FHIR R4 core and the R4 vital-signs profiles (§6); the project's own profiles, generated from the model, plug into the same run (PROJECT_PROFILES, §6.1).
4.1 Fixed displays
displayon the fixedcodecodings. The built-in bleeding, flow, symptom and BBT facts (proposed codesmenstrual-bleeding"Menstrual bleeding",menstrual-flow"Patient-reported menstrual flow category",symptom"Symptom",basal-body-temperature"Basal body temperature"), pain (LOINC 72514-3 "Pain severity - 0-10 verbal numeric rating [Score] - Reported"), and the vital-signscategory("Vital Signs", emitted on R4 vital-sign custom series) carry these six display strings exactly. Value codings carry no display.- Quantity
unitis required by R4's body-temperature profile and emitted consistently on allQuantityvalues. id,text,meta(exceptSUBSETTEDon reduced cards), and Bundleidentifierare omitted.Bundle.timestampis written whenexportedAtis present.
4.2 Things deliberately not done
- No
meta.profile. Conformance is checked by validating against the profiles explicitly (§6). - A Device appears only when the model names a source app, and the Patient carries identity only if the model has it (§1).
- No
performer. The validator's best-practice warning is accepted.
5. Codes
5.1 Fact-type and flow codes (proposed)
menstrual-bleeding, menstrual-flow, symptom, flow-none, flow-spotting, flow-light, flow-moderate, flow-heavy, basal-body-temperature, reading-excluded, reading-exclusion-reason and the exclude-* reasons are concepts of this codec's CodeSystem (§5.3), with definitions there. Built-in symptoms 0–13 are the 14 SNOMED CT starter symptoms the design started from; pain (LOINC 72514-3), clinical body temperature / fever (LOINC 8310-5, observation-category#vital-signs in custom[]) and IUD insertion (SNOMED CT 65200003) are standard codes in the table below.
5.2 Standard codes, verified
Every code was looked up on 2026-12-03 with https://tx.fhir.org/r4/CodeSystem/$lookup?system=…&code=…:
- LOINC 2.83;
- SNOMED CT International Edition
http://snomed.info/sct/900000000000207008/version/20260701; - RxNorm 2026-11-24;
- ATC 2026;
- HL7 terminology (condition-clinical);
- UCUM.
The table covers every built-in code and every coding used by the first fourteen samples and the test fixtures, 162 codes in all (timestamped and bp-twice-daily use no other code; the tests check every sample). It also lists codes that were considered and not used: ATC G03AA/AC/AD and SNOMED 315604002.
All are active. bun verify-codes.ts repeats the lookups and rewrites codes-verified.json, which holds the full evidence: display, inactive flag, version, parents and answer lists. The tests fail if the mapping can emit a code that is neither in that file nor defined in the proposed CodeSystem.
| System | Code | Display returned | Status | Used for | Evidence |
|---|---|---|---|---|---|
| LOINC | 72514-3 | Pain severity - 0-10 verbal numeric rating [Score] - Reported | active | Observation.code (pain); sample power-tracker; sample copper-iud; sample pcos; sample perimenopause; sample combined-pill; sample wellness-diary; sample smart-cup-hmb | lookup |
| LOINC | 8310-5 | Body temperature | active | Observation.code (bbt); sample power-tracker; sample copper-iud; sample pcos; sample post-ablation | lookup |
| LOINC | 2106-3 | Choriogonadotropin [Presence] in Urine | active | Observation.code (pregnancyTest); sample power-tracker; sample pcos | lookup |
| SNOMED CT | 364316005 | Sexual intercourse observable | active | Observation.code (sex); sample power-tracker; sample copper-iud; sample pcos; sample combined-pill; sample own-vocabulary | lookup |
| LOINC | 93832-4 | Sleep duration | active | Observation.code (sleep); sample power-tracker; sample perimenopause; sample own-vocabulary; sample wellness-diary; sample wearable | lookup |
| LOINC | 8659-5 | Birth control method - Reported | active | Observation.code (contraception); sample power-tracker; sample copper-iud; sample combined-pill; sample near-empty; sample own-vocabulary | lookup |
| LOINC | 82810-3 | Pregnancy status | active | Observation.code (pregnancy); sample power-tracker | lookup |
| LOINC | 63895-7 | Breastfeeding status | active | Observation.code (breastfeeding); sample near-empty | lookup |
| SNOMED CT | 260385009 | Negative | active | ovulationTest value; progesteroneTest value; pregnancyTest value; sample power-tracker; sample pcos | lookup |
| SNOMED CT | 10828004 | Positive | active | ovulationTest value; progesteroneTest value; pregnancyTest value; sample power-tracker; sample copper-iud; sample pcos | lookup |
| SNOMED CT | 82334004 | Indeterminate | active | ovulationTest value; progesteroneTest value; pregnancyTest value; sample pcos | lookup |
| SNOMED CT | 63537005 | Protected sexual intercourse | active | sex value; sample power-tracker; sample pcos; sample combined-pill; sample own-vocabulary | lookup |
| SNOMED CT | 2314005 | Unprotected sexual intercourse | active | sex value; sample power-tracker; sample pcos; sample combined-pill | lookup |
| SNOMED CT | 70256003 | Sexual intercourse - finding | active | sex value; sample power-tracker; sample copper-iud | lookup |
| SNOMED CT | 431416001 | Menstrual cramp | active | symptom 0: Menstrual cramp; sample power-tracker; sample perimenopause; sample combined-pill; sample own-vocabulary; sample wearable | lookup |
| SNOMED CT | 161891005 | Backache | active | symptom 1: Backache | lookup |
| SNOMED CT | 25064002 | Headache | active | symptom 2: Headache; sample power-tracker; sample copper-iud; sample combined-pill; sample own-vocabulary | lookup |
| SNOMED CT | 37796009 | Migraine | active | symptom 3: Migraine; sample wellness-diary | lookup |
| SNOMED CT | 271681002 | Stomach ache | active | symptom 4: Stomach ache | lookup |
| SNOMED CT | 422587007 | Nausea | active | symptom 5: Nausea; sample power-tracker; sample combined-pill | lookup |
| SNOMED CT | 55222007 | Tenderness of breast | active | symptom 6: Breast tenderness; sample power-tracker; sample post-ablation | lookup |
| SNOMED CT | 43548008 | Mittelschmerz | active | symptom 7: Ovulation pain; sample power-tracker; sample post-ablation | lookup |
| SNOMED CT | 84229001 | Fatigue | active | symptom 8: Fatigue; sample power-tracker; sample copper-iud; sample pcos; sample smart-cup-hmb | lookup |
| SNOMED CT | 116289008 | Abdominal bloating | active | symptom 9: Abdominal bloating; sample power-tracker; sample copper-iud; sample own-vocabulary; sample post-ablation | lookup |
| SNOMED CT | 366979004 | Depressed mood | active | symptom 10: Depressed mood; sample copper-iud; sample pcos | lookup |
| SNOMED CT | 55929007 | Feeling irritable | active | symptom 11: Feeling irritable; sample power-tracker; sample copper-iud; sample post-ablation | lookup |
| SNOMED CT | 73595000 | Stress | active | symptom 12: Stress; sample power-tracker | lookup |
| SNOMED CT | 71315007 | Dyspareunia | active | symptom 13: Dyspareunia; sample copper-iud | lookup |
| SNOMED CT | 11381005 | Acne | active | symptom 14: Acne; sample power-tracker; sample pcos | lookup |
| SNOMED CT | 30473006 | Pain in pelvis | active | symptom 15: Pain in pelvis | lookup |
| SNOMED CT | 279039007 | Low back pain | active | symptom 16: Low back pain; sample power-tracker | lookup |
| SNOMED CT | 53430007 | Pain of breast | active | symptom 17: Pain of breast | lookup |
| SNOMED CT | 18963009 | Mood swings | active | symptom 18: Mood swings; sample power-tracker; sample perimenopause | lookup |
| SNOMED CT | 48694002 | Anxiety | active | symptom 19: Anxiety; sample perimenopause | lookup |
| SNOMED CT | 62315008 | Diarrhea | active | symptom 20: Diarrhea; sample power-tracker | lookup |
| SNOMED CT | 14760008 | Constipation | active | symptom 21: Constipation | lookup |
| SNOMED CT | 404640003 | Dizziness | active | symptom 22: Dizziness | lookup |
| SNOMED CT | 248132003 | Craving for food or drink | active | symptom 23: Craving for food or drink; sample power-tracker | lookup |
| SNOMED CT | 289532003 | Passing clots vaginally | active | symptom 24: Passing clots vaginally; sample copper-iud; sample perimenopause; sample smart-cup-hmb | lookup |
| SNOMED CT | 42984000 | Night sweats | active | symptom 26: Night sweats; sample perimenopause | lookup |
| SNOMED CT | 193462001 | Insomnia | active | symptom 27: Insomnia; sample perimenopause | lookup |
| SNOMED CT | 31908003 | Vaginal dryness | active | symptom 28: Vaginal dryness; sample perimenopause | lookup |
| SNOMED CT | 80313002 | Palpitations | active | symptom 29: Palpitations; sample perimenopause | lookup |
| SNOMED CT | 165232002 | Urinary incontinence | active | symptom 30: Urinary incontinence | lookup |
| SNOMED CT | 225038006 | Memory lapses | active | symptom 31: Memory lapses; sample perimenopause | lookup |
| SNOMED CT | 56317004 | Alopecia | active | symptom 32: Alopecia (hair loss) | lookup |
| SNOMED CT | 58436003 | Increased libido | active | symptom 33: Increased libido; sample power-tracker | lookup |
| SNOMED CT | 8357008 | Reduced libido | active | symptom 34: Reduced libido | lookup |
| SNOMED CT | 38268001 | Ibuprofen-containing product | active | medication 0: Ibuprofen-containing product; sample power-tracker; sample copper-iud | lookup |
| SNOMED CT | 11847009 | Naproxen-containing product | active | medication 1: Naproxen-containing product; sample pcos | lookup |
| SNOMED CT | 90332006 | Acetaminophen-containing product | active | medication 2: Acetaminophen-containing product; sample perimenopause | lookup |
| SNOMED CT | 34364009 | Mefenamic acid-containing product | active | medication 3: Mefenamic acid-containing product | lookup |
| SNOMED CT | 109006003 | Tranexamic acid-containing product | active | medication 4: Tranexamic acid-containing product; sample perimenopause; sample smart-cup-hmb | lookup |
| SNOMED CT | 30729008 | Iron-containing product | active | medication 5: Iron-containing product; sample perimenopause; sample smart-cup-hmb | lookup |
| SNOMED CT | 6247001 | Folic acid-containing product | active | medication 6: Folic acid-containing product; sample power-tracker | lookup |
| LOINC | LA137-2 | None | active | interval value: none; sample power-tracker | lookup |
| LOINC | LA27908-5 | Combined oral contraceptive pills | active | interval value: combined-pill; sample combined-pill | lookup |
| LOINC | LA27909-3 | Progestin only contraceptive pills | active | interval value: progestin-pill | lookup |
| LOINC | LA16581-3 | Contraceptive patch | active | interval value: patch | lookup |
| LOINC | LA27911-9 | Vaginal ring | active | interval value: ring | lookup |
| LOINC | LA27907-7 | Injectables | active | interval value: injection | lookup |
| LOINC | LA27901-0 | Implantable rod | active | interval value: implant | lookup |
| LOINC | LA27902-8 | IUD with Progestin | active | interval value: hormonal-iud | lookup |
| LOINC | LA27903-6 | IUD copper | active | interval value: copper-iud; sample copper-iud | lookup |
| LOINC | LA27904-4 | IUD unspecified | active | interval value: iud-unspecified | lookup |
| LOINC | LA27912-7 | Male condom | active | interval value: condom; sample copper-iud | lookup |
| LOINC | LA27918-4 | Fertility awareness-based methods | active | interval value: fertility-awareness; sample power-tracker | lookup |
| LOINC | LA27919-2 | Lactational amenorrhea method | active | interval value: lactational-amenorrhea; sample near-empty | lookup |
| LOINC | LA15173-0 | Pregnant | active | interval value: pregnant; sample power-tracker | lookup |
| LOINC | LA29252-6 | Currently breastfeeding | active | interval value: breastfeeding; sample near-empty | lookup |
| SNOMED CT | 65200003 | Insertion of intrauterine contraceptive device | active | procedure: iud-insertion; sample copper-iud | lookup |
| SNOMED CT | 1263416007 | Removal of intrauterine contraceptive device | active | procedure: iud-removal | lookup |
| SNOMED CT | 169553002 | Implantation of subcutaneous contraceptive | active | procedure: implant-insertion | lookup |
| SNOMED CT | 301807007 | Removal of subcutaneous contraceptive implant | active | procedure: implant-removal | lookup |
| SNOMED CT | 1372819003 | Administration of postcoital oral contraceptive | active | procedure: emergency-contraception; sample pcos | lookup |
| SNOMED CT | 236886002 | Hysterectomy | active | procedure: hysterectomy | lookup |
| SNOMED CT | 265060005 | Endometrial ablation | active | procedure: endometrial-ablation; sample post-ablation | lookup |
| SNOMED CT | 83152002 | Oophorectomy | active | procedure: oophorectomy | lookup |
| SNOMED CT | 76876009 | Excision of bilateral ovaries | active | procedure: bilateral-oophorectomy | lookup |
| SNOMED CT | 42010004 | Uterine myomectomy | active | procedure: myomectomy; sample smart-cup-hmb | lookup |
| SNOMED CT | 11401008 | Dilation and curettage of uterus | active | procedure: d-and-c | lookup |
| SNOMED CT | 236884004 | Excision of uterine polyp | active | procedure: polypectomy | lookup |
| SNOMED CT | 312138002 | Embolization of uterine artery | active | procedure: uterine-artery-embolization | lookup |
| SNOMED CT | 237055002 | Polycystic ovary syndrome | active | condition 0: Polycystic ovary syndrome; sample pcos | lookup |
| SNOMED CT | 95315005 | Uterine leiomyoma | active | condition 1: Uterine leiomyoma (fibroids); sample smart-cup-hmb | lookup |
| SNOMED CT | 784314006 | Uterine adenomyosis | active | condition 2: Uterine adenomyosis; sample post-ablation | lookup |
| SNOMED CT | 1237359009 | Endometrial polyp | active | condition 3: Endometrial polyp | lookup |
| SNOMED CT | 129103003 | Endometriosis | active | condition 4: Endometriosis | lookup |
| SNOMED CT | 128105004 | von Willebrand disorder | active | condition 5: von Willebrand disorder | lookup |
| SNOMED CT | 64779008 | Blood coagulation disorder | active | condition 6: Blood coagulation disorder | lookup |
| SNOMED CT | 87522002 | Iron deficiency anemia | active | condition 7: Iron deficiency anemia; sample smart-cup-hmb | lookup |
| SNOMED CT | 40930008 | Hypothyroidism | active | condition 8: Hypothyroidism | lookup |
| SNOMED CT | 34486009 | Hyperthyroidism | active | condition 9: Hyperthyroidism | lookup |
| SNOMED CT | 237662005 | Hyperprolactinemia | active | condition 10: Hyperprolactinemia | lookup |
| SNOMED CT | 237788002 | Premature ovarian insufficiency | active | condition 11: Premature ovarian insufficiency | lookup |
| SNOMED CT | 237120002 | Hypothalamic amenorrhea | active | condition 12: Hypothalamic amenorrhea | lookup |
| SNOMED CT | 161541000119104 | Perimenopausal state | active | condition 13: Perimenopausal state; sample perimenopause | lookup |
| SNOMED CT | 76498008 | Postmenopausal state | active | condition 14: Postmenopausal state | lookup |
| LOINC | 64700-8 | On average, during the last year, how many day were there in a typical menstrual cycle, that is, from the beginning of bleeding of one menstrual period to the beginning of bleeding of the next period [PhenX] | active | question: usual-cycle-length; sample pcos; sample calendar-only; sample smart-cup-hmb | lookup |
| LOINC | LA14649-0 | Less than 21 days | active | answer to usual-cycle-length: <21 | lookup |
| LOINC | LA14650-8 | 21-25 days | active | answer to usual-cycle-length: 21-25 | lookup |
| LOINC | LA14651-6 | 26-32 days | active | answer to usual-cycle-length: 26-32; sample calendar-only; sample smart-cup-hmb | lookup |
| LOINC | LA14652-4 | 33-35 days | active | answer to usual-cycle-length: 33-35 | lookup |
| LOINC | LA14653-2 | 36-90 days | active | answer to usual-cycle-length: 36-90; sample pcos | lookup |
| LOINC | LA14654-0 | More than 90 days | active | answer to usual-cycle-length: >90 | lookup |
| LOINC | LA14655-7 | Too variable to say | active | answer to usual-cycle-length: too-variable | lookup |
| LOINC | LA12688-0 | Don't know | active | answer to usual-cycle-length: dont-know | lookup |
| LOINC | 92656-8 | Number of menstrual periods per year | active | question: periods-per-year; sample pcos; sample calendar-only; sample smart-cup-hmb; sample post-ablation | lookup |
| UCUM | /a | /a | valid | unit of periods-per-year; sample pcos; sample calendar-only; sample smart-cup-hmb; sample post-ablation | lookup |
| LOINC | 65930-0 | Over the past 3 months, how many menstrual periods have you missed [EDDS] | active | question: missed-periods-3-months | lookup |
| UCUM | {#}/(3.mo) | {#}/(3.mo) | valid | unit of missed-periods-3-months | lookup |
| LOINC | 63889-0 | Have you had a menstrual period within the last year [PhenX] | active | question: period-in-last-year; sample post-ablation | lookup |
| LOINC | LA33-6 | Yes | active | answer to period-in-last-year: yes | lookup |
| LOINC | LA32-8 | No | active | answer to period-in-last-year: no; answer to periods-stopped: no; sample post-ablation | lookup |
| LOINC | 64701-6 | Have your menstrual periods stopped permanently [PhenX] | active | question: periods-stopped | lookup |
| LOINC | LA14656-5 | Yes, no menstrual periods | active | answer to periods-stopped: yes-no-periods | lookup |
| LOINC | LA14657-3 | Yes, but have periods now due to female hormones | active | answer to periods-stopped: yes-hormones | lookup |
| LOINC | LA12693-0 | Not sure | active | answer to periods-stopped: not-sure | lookup |
| LOINC | 64702-4 | How old were you when your periods stopped [PhenX] | active | question: age-periods-stopped | lookup |
| UCUM | a | a | valid | unit of age-periods-stopped; unit of age-at-menarche | lookup |
| LOINC | 63888-2 | Age at first menstrual period | active | question: age-at-menarche | lookup |
| condition-clinical | active | Active | active | Condition.clinicalStatus; sample pcos; sample perimenopause; sample smart-cup-hmb | lookup |
| condition-clinical | resolved | Resolved | active | Condition.clinicalStatus; sample post-ablation | lookup |
| UCUM | mL | mL | valid | volume unit; sample smart-cup-hmb | lookup |
| UCUM | {score} | {score} | valid | built-in Quantity unit; sample power-tracker; sample copper-iud; sample pcos; sample perimenopause; sample combined-pill; sample wellness-diary; sample smart-cup-hmb | lookup |
| UCUM | Cel | Cel | valid | built-in Quantity unit; sample power-tracker; sample copper-iud; sample own-vocabulary; sample wearable; sample post-ablation | lookup |
| UCUM | [degF] | [degF] | valid | built-in Quantity unit; sample pcos | lookup |
| UCUM | min | min | valid | built-in Quantity unit; sample power-tracker; sample perimenopause; sample own-vocabulary; sample wellness-diary; sample wearable | lookup |
| SNOMED CT | 34363003 | Pruritus of vagina | active | sample power-tracker | lookup |
| SNOMED CT | 399939002 | Hirsutism | active | sample pcos | lookup |
| SNOMED CT | 109081006 | Metformin-containing product | active | sample pcos | lookup |
| SNOMED CT | 57676002 | Pain of joint | active | sample perimenopause | lookup |
| LOINC | LA27913-5 | Diaphragm or cervical cap | active | sample own-vocabulary | lookup |
| SNOMED CT | 68962001 | Muscle pain | active | sample own-vocabulary | lookup |
| SNOMED CT | 255604002 | Mild | active | sample own-vocabulary; test fixture escape | lookup |
| RxNorm | 197805 | ibuprofen 400 MG Oral Tablet | active | sample own-vocabulary | lookup |
| SNOMED CT | 24484000 | Severe | active | sample own-vocabulary; test fixture escape | lookup |
| SNOMED CT | 6736007 | Moderate severity | active | sample own-vocabulary; test fixture escape | lookup |
| RxNorm | 849574 | naproxen sodium 220 MG Oral Tablet | active | sample own-vocabulary | lookup |
| SNOMED CT | 422400008 | Vomiting | active | sample own-vocabulary | lookup |
| RxNorm | 198741 | magnesium oxide 400 MG Oral Tablet | active | sample wellness-diary | lookup |
| LOINC | 41950-7 | Number of steps in 24 hour Measured | active | sample wellness-diary | lookup |
| UCUM | /d | /d | valid | sample wellness-diary | lookup |
| UCUM | mg | mg | valid | sample wellness-diary | lookup |
| UCUM | /min | /min | valid | sample wellness-diary | lookup |
| RxNorm | 313161 | sumatriptan 50 MG Oral Tablet | active | sample wellness-diary | lookup |
| RxNorm | 1368932 | riboflavin 400 MG Oral Tablet | active | sample wellness-diary | lookup |
| SNOMED CT | 143661000119109 | Non-menopausal hot flash | active | test fixture escape | lookup |
| SNOMED CT | 703737005 | Ulipristal-containing product | active | test fixture escape | lookup |
| ATC | G03AA | Progestogens and estrogens, fixed combinations | active | considered for pill coding (not used) | lookup |
| ATC | G03AC | Progestogens | active | considered for pill coding (not used) | lookup |
| ATC | G03AD | Emergency contraceptives | active | considered for pill coding (not used) | lookup |
| SNOMED CT | 315604002 | Missed contraceptive pill | active | considered for missed pill (not used) | lookup |
Notes on choices:
- LOINC answers as values.
- 8659-5's own answer list (LL353-4, "ART_4_Family planning") is too coarse: "Injectable/implantable hormone" and "Intrauterine device" do not separate copper from hormonal IUDs.
- The values therefore come from LL4578-2. That is the list LOINC attaches to the HL7 Family Planning (FPAR) questions 86649-1 and 86651-7, which are birth control method at intake and at exit.
- The alternative was the SNOMED CT "Uses … contraception" findings (448962006 copper IUD, 449038007 hormone-releasing IUD, 268458002 combined oral, 445375000 does not use contraception, and others). They are exact as well. The LOINC answers were chosen because a question/answer pair under one LOINC code is the pattern FPAR uses.
- Contraceptive pills are not medications. LOINC answer-list values (LA27908-5 and the others) are answers to the "birth control method" question. They appear only as values of the 8659-5 interval Observation, never as a medication code.
- The daily pill log is a separate boolean series (§1).
- Also considered for a pill medication code: the ATC classes G03AA "Progestogens and estrogens, fixed combinations", G03AC "Progestogens" and G03AD "Emergency contraceptives". All verified active on tx.fhir.org (
$lookup?system=http://www.whocc.no/atc&code=G03AA, ATC 2026), but they are class-level and say nothing about a specific pill. - SNOMED CT International has only ingredient-specific products, for example 779205005 "Ethinyl estradiol and levonorgestrel only product in oral dose form". An app that knows the product can still log it as a medication escape.
- Emergency contraception is a procedure-history Observation with SNOMED CT 1372819003 (§1). A known product (703737005 ulipristal, or a levonorgestrel product) may additionally be logged as a medication escape.
- Medication codes are SNOMED CT products only, from the built-in table or escapes. They are emitted as MedicationStatement
medicationCodeableConcept, with statuscompleted(taken) ornot-taken(§1). - Pregnancy test. 2106-3 "Choriogonadotropin [Presence] in Urine" describes exactly what a home test measures. The values are the SNOMED CT qualifiers Negative, Positive and Indeterminate, as used for presence tests.
- Sexual activity. 364316005 is an observable entity, used as Observation.code. Its findings are the values: 63537005 protected, 2314005 unprotected, and 70256003, their common parent, when protection is not recorded.
- Sleep. 93832-4 "Sleep duration" is unqualified (main sleep vs total). The model attributes it to the wake day.
5.3 Proposed codes (https://joshuamandel.com/shc2-poc/CodeSystem/cycle-log, CodeSystem-cycle-log.json)
The URL is the constant CYCLE_LOG_CS in vocab.ts. The CodeSystem is experimental: true with content: complete, and make-codesystem.ts writes it.
| Code | Use | Why no standard code fits (searched on tx.fhir.org: ValueSet/$expand?url=http://loinc.org/vs and …?url=http://snomed.info/sct?fhir_vs with filter=) |
|---|---|---|
menstrual-bleeding, menstrual-flow, symptom, flow-none, flow-spotting, flow-light, flow-moderate, flow-heavy | the bleeding fact (valueBoolean), the flow fact and its five values, and the code of a symptom fact (value: the symptom) | The design started from these fact types; they are defined here, with definitions, so the card depends on no other code system. Mapping them to LOINC or SNOMED CT is future work. |
basal-body-temperature | waking basal body temperature (bbt) | Keeps waking BBT distinct from LOINC 8310-5 "Body temperature" (fever / clinical vital signs), which stays available as an R4 vital-sign custom series without polluting thermal-shift baselines. |
reading-excluded, reading-exclusion-reason, exclude-fever, exclude-alcohol, exclude-poor-sleep, exclude-late-wake, exclude-travel, exclude-stress, exclude-medication, exclude-other | optional disturbance/exclusion components on bbt and skinTemp | No standard LOINC or SNOMED CT observation component codes distinguish a disturbed fertility-tracking temperature reading excluded from thermal-shift interpretation and its coded reason. |
cervical-mucus + mucus-dry/-sticky/-creamy/-watery/-egg-white | self-observed mucus | LOINC 10570-0 "Consistency of Cervical mucus" and 79333-1 "Viscosity … Qualitative" are laboratory specimen properties. Their answer list LL2446-4 (viscous, mildly viscous, slightly viscous, watery, liquified) cannot say "dry" or "egg white". SNOMED CT has vaginal-discharge findings (289553007 creamy, 289549005 watery) but no fertility-awareness mucus categories. Those would be close but wrong. |
ovulation-test (+ value estrogen-surge) | home LH test | LOINC has only quantitative lutropin in urine (15079-7 [Units/volume], 111244-0 [Measurement]). "Lutropin [Presence] in Urine" does not exist. The negative, positive and indeterminate values are SNOMED CT. Only the HealthKit estrogenSurge result ("high fertility" on combined monitors) needed a proposed value. |
pdg-test | home progesterone (PdG) test | LOINC has only quantitative pregnanediol (2833-2, 110593-1, 15091-2), with no presence test for pregnanediol glucuronide. |
no-sexual-intercourse | explicit "didn't have sex" | Searches found only 102956007 "Non-consummation of sexual intercourse" (a marital/diagnostic concept), 162171002 "Currently not sexually active" (a status, not a day) and the LOINC PhenX survey answer LA14635-9. None means "no intercourse on this day". |
mood-valence + 7 valence-* | daily mood | LOINC has instrument-specific mood items (MDQ, MFQ, CMS assessments). Nothing is a generic daily valence rating. HealthKit's 7-point valence is the model's source. |
energy-level + 4 energy-* | daily energy | LOINC 65515-9 (QIDS, past 7 days) and 69731-8 (PHQ, past 4 weeks) are instrument items with other time frames and answer lists. |
contraceptive-pill-taken | daily pill log, valueBoolean | SNOMED CT 315604002 "Missed contraceptive pill (situation)" covers only the missed case, and there is no concept for "pill taken". One boolean fact with one code mirrors the menstrual-bleeding fact (§1). |
menstrual-fluid-volume | measured volume | SNOMED CT 364308001 "Quantity of menstrual blood loss" is blood; collected menstrual fluid is 36% blood on average (Fraser 1985, PMID 3969232), about 50% in heavy losses (Fraser 2001, PMID 11704173). No LOINC concept for menstrual volume. |
skin-temperature-deviation, nightly-skin-temperature | wearable nightly temperature | LOINC 39106-0 "Temperature of Skin" is nominal (palpation), and the validator warns on a quantity. There is no LOINC or SNOMED CT quantity concept for a sleep-aggregated skin temperature or its deviation from a personal baseline. The LOINC body-temperature codes would bind R4 vital-signs profiles. |
hot-flash | symptom (built-in 25) | SNOMED CT International has only cause-specific concepts. 198436008 "Menopausal flushing" and 427368007 "Climacteric flushing" assert a menopausal cause. 143661000119109 "Non-menopausal hot flash" asserts the opposite, and 439407002 is drug-caused. The parent 238810007 "Flushing" is a skin sign without the heat sensation. A tracker does not know the cause. A producer that does can send 198436008 as an escape. |
6. Validation
6.1 HL7 FHIR validator
The HL7 IG Publisher jar contains org.hl7.fhir.validation.ValidationEngine. hl7-validate/Validate.java (about 40 lines, run with java -cp publisher.jar Validate.java) drives it, with the R4 core package from the local cache and terminology from https://tx.fhir.org. bun hl7-validate/run.ts validates every sample:
| pass | loaded | result, all sixteen samples |
|---|---|---|
| base | R4 core (with the R4 vital-signs profiles the validator applies by LOINC code), CodeSystem-cycle-log.json (as a receiver that knows it) | 0 errors (2026-12-03, all sixteen, including timestamped and bp-twice-daily with several entries a day, times and offsets) |
| project | only with PROJECT_PROFILES set: the project's own profiles, generated from the model, with meta.profile added from their profile-map.json | – (the hook for those profiles) |
Warnings, all expected:
dom-6: no narrative.- This is the only issue the validator raises on the Patient (both forms), the Device, the MedicationStatements, the Procedures and the Conditions, apart from one information note on the PCOS Condition (laterality).
- It raised no best-practice warning about a missing
performer,subjectorinformationSourceon those resource types.
- "all observations should have a performer". This applies to Observations only.
{score}: UCUM annotation advice. LOINC 72514-3 is a 0–10 score.- "A definition for CodeSystem … could not be found": the app code systems of samples (h) and (i).
Information-level notes:
- the validator applied R4 bodytemp to 8310-5, and heartrate, bp and bodyweight to the vital-sign series;
- point-in-time LOINC codes (8659-5, 82810-3, 63895-7) used with a period;
- LOINC 41950-7 (steps, a 24-hour collection) used with a single date.
Other runs:
- A limits-maximal random model (every built-in and context field populated, 32 custom series, 64 concepts per day, 255-character
urn:systems, 128-character codes and 128-character displays containing",\,|, non-ASCII and an emoji, quantities ±2³¹−1 at scale 6): 0 errors. - Negative controls produced the expected errors:
- an invented SNOMED CT code (unknown code);
- an invented LOINC answer;
Validity findings that shaped the model. Each was found by running the validator:
- The empty Patient
{"resourceType":"Patient"}failsbdl-5.- Without identity the Patient is
{"resourceType":"Patient","id":"0"}.{"resourceType":"Patient","active":true}also validates, but asserts more. - With identity it is name and/or birthDate (§1).
- Without identity the Patient is
- BBT without a subject fails R4 bodytemp, and R4
MedicationStatement.subjectandProcedure.subjectare 1..1. The Patient therefore always exists, and every fact references it asresource:0. - The validator applies R4 vital-signs profiles to about 90 LOINC codes, not just the 13 in the R4 ValueSet. For example, 40443-4 "Heart rate --resting" triggers the heart-rate profile. A custom series with any of these codes is therefore written as a vital sign, with the category and, for a code with its own profile, the profile's unit or components (§2); intervals may not use them (
R4_VITAL_SIGN_CODES, taken from the validator's ownBasePolicyAdvisorForFullValidation). - Code systems under example.org (and example.com) are an error: "Example URLs are not allowed in this context". The samples' fictitious app systems therefore use the reserved
.invalidTLD.- The proposed concepts are therefore at
https://joshuamandel.com/shc2-poc/CodeSystem/cycle-log, where the CodeSystem JSON is served. - Validated without
CodeSystem-cycle-log.jsonloaded (a receiver that has never seen it), the combined-pill sample gives 0 errors and 541 warnings "A definition for CodeSystem 'https://joshuamandel.com/shc2-poc/CodeSystem/cycle-log' could not be found, so the code cannot be validated". The near-empty sample gives 0 errors and 1 such warning. - With the CodeSystem loaded, all sixteen samples give 0 errors.
- The proposed concepts are therefore at
- A
Coding.displayon a SNOMED CT, LOINC or RxNorm concept that does not match an official display is a "Wrong Display Name" error. Built-in concepts therefore omit custom displays andtext(their displays are canonical); non-built-in escape concepts may carrycoding[0].display(which must be an official display for standard terminologies) and/or plain-textCodeableConcept.textfor offline readability (demonstrated inoffline-displays).
6.2 Offline structural checker
r4-structure.ts checks every Bundle against the R4 StructureDefinitions in specs/fhiredaction-studio/fhir/.cache/profiles-{resources,types}.json. It runs in the test suite, where all samples and 30 random models pass.
It establishes:
- every property is an R4 element of its resource or data type (choice types resolved);
- arrays versus single values match max cardinality;
- required elements are present;
- primitives match the R4 regexes;
- there are no empty objects, arrays or strings.
It does not establish anything about:
- invariants (it misses
bdl-5); - bindings or terminology;
- profiles, patterns or fixed values;
- references.
§6.1 covers those.