Skip to content

FlixCoder/fhir-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Flix
Sep 16, 2023
c55191f · Sep 16, 2023

History

66 Commits
Sep 3, 2023
Sep 16, 2023
Sep 3, 2023
May 1, 2023
Sep 16, 2023
Sep 16, 2023
Sep 6, 2023
Mar 24, 2023
Sep 10, 2023
Sep 1, 2023
Mar 24, 2023
Mar 24, 2023

Repository files navigation

FHIR SDK

crates.io page docs.rs page license: MIT

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
    • GraphQL
  • FHIRpath implementation
  • Resource validation using FHIRpath and regular expressions

Not Planned

  • XML

Example

use fhir_sdk::r5::resources::Patient;
use fhir_sdk::client::*;
use fhir_sdk::TryStreamExt;

#[tokio::main]
async fn main() -> Result<(), Error> {
    // Set up the client using the local test server.
    let client = Client::new("http://localhost:8090/fhir/".parse().unwrap())?;

    // Create a Patient resource using a typed builder.
    let mut patient = Patient::builder().active(false).build();
    // Push it to the server.
    patient.create(&client).await?;
    // The id and versionId is updated automatically this way.
    assert!(patient.id.is_some());
    
    // Search for all patient with `active` = false, including pagination.
    let patients: Vec<Patient> = client
        .search(SearchParameters::empty().and(TokenSearch::Standard {
            name: "active",
            system: None,
            code: Some("false"),
            not: false,
        }))
        .try_collect()
        .await?;

    Ok(())
}

For more examples, see the tests.

Testing

Simply set up the FHIR test server using docker compose up -d in the workspace root and then run cargo xtask test.

Known Problems

  • Due to the big number of big types, the compile time and its memory usage is really high. The auto-generated builders also take a long time during the build time. The builders can be disabled by disabling the builders feature to save some resources.
  • The builder cannot use setter(strip_option), because it disables dynamic setting of optional fields.
  • Vec<Option<T>> is annoying, but sadly is required to allow [null, {...}, null] for extensions..

Lints

This projects uses a bunch of clippy lints for higher code quality and style.

Install cargo-lints using cargo install --git https://github.com/FlixCoder/cargo-lints. The lints are defined in lints.toml and can be checked by running cargo lints clippy --all-targets --workspace.

License

Licensed under the MIT license. All contributors agree to license under this license.