ferrobridge_validator/lib.rs
1// SPDX-FileCopyrightText: Cadasto B.V.
2// SPDX-License-Identifier: BUSL-1.1
3
4//! A FHIR R4 profile validator over FHIR packages read offline.
5//!
6//! [`set::PackageSet::load`] reads packages from `.tgz` files and unpacked
7//! directories, checks that every dependency their manifests name is present,
8//! and resolves `StructureDefinitions` by canonical into the generated
9//! `fhir_types::r4` model. [`validate::Validator`] walks an instance, the
10//! lexical document model of `fhir-types`, over the R4 element table and
11//! holds it to the snapshot of the profile it is validated against
12//! (<https://hl7.org/fhir/R4/validation.html>,
13//! <https://hl7.org/fhir/R4/profiling.html>). The result is a
14//! [`report::Report`] of typed [`issue::Issue`]s that converts into an R4
15//! `OperationOutcome`, and that names every constraint the validator met and
16//! did not evaluate.
17//!
18//! ```no_run
19//! use ferrobridge_validator::set::PackageSet;
20//! use ferrobridge_validator::validate::Validator;
21//! use fhir_types::codec::Value;
22//! use fhir_types::r4::operation_outcome::OperationOutcome;
23//!
24//! let set = PackageSet::load(["vendor/hl7.fhir.r4.core", "packages/my.profiles.tgz"])?;
25//! let validator = Validator::new(&set);
26//! let patient: Value = serde_json::from_str(r#"{"resourceType": "Patient", "active": true}"#)?;
27//! let report = validator.validate_against(&patient, "http://example.org/StructureDefinition/my-patient")?;
28//! let outcome = OperationOutcome::from(&report);
29//! assert!(!outcome.issue.is_empty());
30//! # Ok::<(), Box<dyn std::error::Error>>(())
31//! ```
32
33#![doc(test(attr(deny(warnings))))]
34
35pub mod canonical;
36pub mod issue;
37pub mod package;
38pub mod report;
39pub mod set;
40pub mod validate;