FHIR SDK
This is a FHIR library in its early stages. The models are generated from the FHIR StructureDefinitions (see FHIR downloads). It aims to be:
- fully compliant
- as safe as possibe
- as easy to use as possible
- fully featured
Features
- Generated FHIR codes, types and resources
- Serialization and deserialization to and from JSON
- Optional builders for types and resources
- Implementation of base traits
- (Base)Resource for accessing common fields
- NamedResource for getting the resource type in const time
- DomainResource for accessing common fields
- IdentifiableResource for all resources with an identifier field
- Client implementation
- Create, Read, Update, Delete
- Search + Paging
- Batch operations / Transactions
- Operations
- Patch
- Authentication
- GraphQL
- FHIRpath implementation
- Resource validation using FHIRpath and regular expressions
Not Planned
- XML (fhirbolt implements it though)
Example
use Patient;
use ;
use ;
async
For more examples, see the tests or below.
Development & Testing
- Install cargo-nextest and cargo-make:
cargo install cargo-nextest cargo-make. - From the workspace root directory, you can run the following tasks:
- Format code:
cargo make format - Check formatting:
cargo make formatting - Run docker environment for all FHIR versions:
cargo make docker-ci-up - Run all tests via cargo test:
cargo make test-all - Run all tests via cargo nextest:
cargo make test - Stop docker environment for all FHIR versions:
cargo make docker-ci-down - Run docker env, run all tests, stop docker env:
cargo make ci-tests - Run clippy for all feature sets, failing on any warnings:
cargo make clippy - Do all checks that are done in CI:
cargo make ci - Run code generator:
cargo make generate
- Format code:
Known Problems
- The compile time and its memory usage are really high. This is due to the big serde derives being highly generic. It might be possible to shave some off by manually implementing Deserialize and Serialize, but that is complex.
Vec<Option<T>>is annoying, but sadly is required to allow[null, {...}, null]for using FHIR resources with extensions..- It is not supported to replace required fields by an extension.
More examples
Reading a resource from string/file
use Resource;
Re-Authentication via callback
use Patient;
use *;
use ;
/// Gets called whenever there is an UNAUTHORIZED response.
/// Retries the response with the new Authorization header.
async
/// Same as above, but with state.
async
Resource identifier access
use ;
async
Minimum supported Rust version
Currently, I am always using the latest Rust version and do not put in any effort to keep the MSRV. Please open an issue in case you need a different policy, I might consider changing the policy.
License
Licensed under the MIT license. All contributors agree to license under this license.