Showcases 5: A FHIR R4 Bundle That Actually Validates
Requires Pro
Problem statement
You’re testing a system that consumes FHIR. Well-formed JSON with "resourceType": "Observation" in it is not the bar — FHIR resources are validated against profiles, and which profile applies depends on the data inside the resource. Get that wrong and you have JSON that looks entirely reasonable and fails conformance the moment someone runs the real HL7 validator against it, which is exactly what happened while building this.
The model
A patient, a heart-rate observation, and a blood-pressure observation, assembled into one Bundle. Three layers, the same shape as the NACHA showcase: values at the bottom, one render filter per resource in the middle, an assembler on top that pulls each resource once and wraps them together.
<?xml version="1.0" encoding="UTF-8"?>
<dataset seed="42">
<root node="VitalsBundle"/>
<nodes>
<FhirBundleAssembler name="VitalsBundle" id="vitals-1" type="collection">
<input name="Pat"/>
<input name="HeartRateObs"/>
<input name="BloodPressureObs"/>
</FhirBundleAssembler>
<FhirIdRegistry name="Ids"/>
<FhirPatientRender name="Pat" collaborate.idRegistry="Ids">
<input name="Who" role="person"/>
<input name="DOB" role="birthDate"/>
</FhirPatientRender>
<FhirObservationRender name="HeartRateObs" code="8867-4" display="Heart rate"
unit="beats/minute" unitCode="/min" collaborate.patient="Pat" collaborate.idRegistry="Ids">
<input name="HR"/>
</FhirObservationRender>
<Normal name="HR" mean="72" stddev="8"/>
<FhirBloodPressureRender name="BloodPressureObs" collaborate.patient="Pat" collaborate.idRegistry="Ids">
<input name="Sys" role="systolic"/>
<input name="Dia" role="diastolic"/>
</FhirBloodPressureRender>
<Normal name="Sys" mean="118" stddev="12"/>
<Normal name="Dia" mean="78" stddev="8"/>
</nodes>
</dataset>
(Pat’s own inputs — PersonAssembler for the name, Date for the birthdate — are the same business objects the rest of the Pro library already uses; omitted here for length, see samples/pro/health/fhir-vitals-bundle.xml for the full file.)
Run it (--count 1 --format raw) and you get one Bundle, one patient, three resources:
{
"resourceType": "Bundle",
"id": "vitals-1",
"type": "collection",
"entry": [
{ "resource": { "resourceType": "Patient", "id": "patient-1",
"name": [{"family": "Morgan", "given": ["Kathleen"]}],
"gender": "female", "birthDate": "1962-05-23" } },
{ "resource": { "resourceType": "Observation", "id": "obs-2",
"code": {"coding": [{"system": "http://loinc.org", "code": "8867-4", "display": "Heart rate"}]},
"subject": {"reference": "Patient/patient-1"},
"valueQuantity": {"value": 75.44120152030321, "unit": "beats/minute"} } },
{ "resource": { "resourceType": "Observation", "id": "bp-3",
"code": {"coding": [{"system": "http://loinc.org", "code": "85354-9", "display": "Blood pressure panel with all children optional"}]},
"component": [
{"code": {"coding": [{"code": "8480-6", "display": "Systolic blood pressure"}]}, "valueQuantity": {"value": 84.50724900914885}},
{"code": {"coding": [{"code": "8462-4", "display": "Diastolic blood pressure"}]}, "valueQuantity": {"value": 79.80827792617896}}
] } }
]
}
We ran the full, un-trimmed version of this exact file through validator_cli.jar — HL7’s own command-line validator, the same tool a real FHIR-consuming system would be checked against:
Success: 0 errors, 3 warnings, 4 notes
All three warnings are Best Practice Recommendations (a missing narrative, a missing performer), not spec violations. Confirmed on three independently-generated bundles, not one lucky seed.
Why this shape works
Patient-to-observation linking never goes through <input>. Wiring an Observation’s subject directly into the Patient’s input tree would mean pulling three observations for one patient re-generates that patient three times — three different people, one “shared” chart. Instead, each Observation asks the Patient node directly for its current reference through the Collaborate channel: collaborate.patient="Pat". FhirPatientRender hands back whichever patient it most recently rendered, without ever being asked to render another one. The Patient still has to be pulled before anything collaborates with it — the Bundle assembler declares Pat as its first input for exactly that reason.
Every id comes from one shared counter, not three. The first version of this model gave FhirObservationRender its own local counter. Every Observation node minted “1” on the first pull — the heart-rate resource and the blood-pressure resource both landing on Observation/obs-1, two different resources sharing one id in the same Bundle. FhirIdRegistry fixes this the same way FhirPatientRender fixes patient sharing: one node, referenced through Collaborate by everything that needs an id, so the sequence is global regardless of how many render-filter types exist in the model. That’s why the committed output reads patient-1, obs-2, bp-3 rather than three resources all claiming -1.
Blood pressure needed its own filter, not two calls to the general one. The first version rendered systolic and diastolic as two ordinary FhirObservationRender calls, coded 8480-6 (Systolic blood pressure) and 8462-4 (Diastolic blood pressure). It’s well-formed, it reads as reasonable, and the validator rejected it with four separate errors: FHIR’s own bp profile requires a single Observation coded 85354-9 (Blood pressure panel with all children optional) carrying both readings as components, with no top-level value at all. FhirBloodPressureRender exists because that requirement only shows up once you validate against the real profile — nothing about checking the JSON’s shape would ever surface it.
Honest limit
This isn’t wired into CI yet — validator_cli.jar is close to 200MB and needs network access on first run to fetch its terminology packages, so “0 errors” here is a documented, reproducible manual check, not an automated gate. A future change to any of these render filters could regress conformance without anything catching it until someone runs the validator by hand again.
This material contains content from LOINC (http://loinc.org). LOINC is copyright © Regenstrief Institute, Inc. and the Logical Observation Identifiers Names and Codes (LOINC) Committee and is available at no cost under the license at http://loinc.org/license. LOINC® is a registered United States trademark of Regenstrief Institute, Inc. HL7, FHIR and the FHIR [FLAME DESIGN] are the registered trademarks of Health Level Seven International and their use does not constitute endorsement by HL7.