View on GitHub


The official .NET API for HL7 FHIR

Download this project as a .zip file Download this project as a tar.gz file

Validating instance data

Invoking the validator

Resources, Bundles, even individual Elements and BundleEntries can be validated using the FhirValidator class from the Hl7.Model.Validation namespace:

var pat = new Patient() { /* set up data */ };

// Will throw a ValidationException when an error is encountered

// Alternatively, use the TryXXXX pattern
var errors = new List<ValidationResult>();
var success = FhirValidator.TryValidate(pat, errors)

if(!success) { /* handle errors */ }

Normally, the validator will validate only the elements within the instance passed to the Validate call, but will not validate the contents of those elements (so, it will validate Encounter’s members, but not those of the nested Hospitalization). To recursively validate an instance, including all its children, pass an extra recursive parameter to the validation calls:

var success = FhirValidator.TryValidate(pat, errors, recursive: true);

Supported validations

Currently, the FhirValidator will validate the following aspects of the FHIR datamodel:

Notable rules not yet validated: