Profiles & validation
Validate with the FHIR Validator CLI
Run the official HL7 validator from the lab, read its output and target the right profile.
The HL7 FHIR Validator is the reference implementation. If it says a resource is valid, every connectathon will agree. The lab wraps it in ~/fhir-lab/validator/validate.
Run it#
cd ~/fhir-lab/validator
./validate my-patient.jsonThe wrapper runs validator_cli.jar in a Java 21 container. It defaults to FHIR R4 (4.0.1), loads AU Core 2.0.0 and uses tx.fhir.org as the terminology server. Downloaded packages are cached in ./cache, so only the first run is slow. Expect about 40 seconds of loading after that.
Name the profile you mean
The validator checks a resource against the profiles listed in its own meta.profile. Synthea labels everything as US Core, so ./validate on a Synthea file validates against US Core, even with AU Core loaded. To test AU Core, say so:
bash
./validate my-patient.json -profile http://hl7.org.au/fhir/core/StructureDefinition/au-core-patient
Read the output#
*FAILURE*: 2 errors, 1 warnings, 15 notes
Error @ Patient.extension[5] (line 64, col4): The extension
http://synthetichealth.github.io/synthea/disability-adjusted-life-years could not be found
so is not allowed here, validating against AU Core Implementation Guide v2.0.0| Part | Meaning |
|---|---|
Error / Warning / Information |
Only errors make it fail. Treat warnings as a to-do list |
Patient.extension[5] |
A FHIRPath location. Indexes start at 0 |
(line 64, col4) |
The position in your file |
validating against … |
The profile or IG the rule came from |
Handy options#
| Option | Use |
|---|---|
-profile <url> |
Validate against a specific profile |
-ig hl7.fhir.au.base#5.0.0 |
Load another package (repeat for more) |
-ig ./my-profiles/ |
Load local StructureDefinitions |
-tx n/a |
No terminology server (faster, but codes aren't checked) |
-output result.json |
Write an OperationOutcome you can process with jq |
-html-output report.html |
A report you can read in a browser |
-level errors |
Only show errors |
-best-practice ignore |
Hide best-practice warnings such as dom-6 (no narrative) |
Point it at a folder to validate every file in it:
./validate ../synthea/output/fhir/ -profile http://hl7.org.au/fhir/core/StructureDefinition/au-core-patient -level errors