Giter Site home page Giter Site logo

fhir-rs's Introduction

FHIR for Rust!

This project has moved

The fhirproject organization is now maintaining this library: https://github.com/fhirproject/fhir-rs.

Deprecated Readme

A simple, fast, and safe interface for FHIR (Fast Healthcare Interoperability Resources) JSON data in Rust.

Here's how parsing works:

use fhir_rs::{fhir_parse, model};

if let Some(resource_list) = fhir_parse(&json_string) {
  match resource_list.resource() {
    model::ResourceList::ResourceListEnum::ResourcePatient(patient) => {
      println!("Patient: {:?}", patient);
    }
    _ => {}
  }
}

You can also create FHIR resources using the type-safe model builders for every FHIR type:

let patient = model::Patient::PatientBuilder::new()
  .name(vec![model::HumanName::HumanNameBuilder::new()
    .given(vec!["Bob"])
    .family("Builder")
    .build()])
  .gender(model::Patient::PatientGender::Male)
  .build();
let json = patient.to_json().to_string();

Built on top of Serde

fhir_rs provides a type-safe and efficient collection of wrappers over serde_json. This allows fhir_rs to be extremely fast, efficient, and safe.

Frequently Asked Questions

Why should I use fhir_rs instead of just using serde_json with FHIR data?

Well it's up to you, but type safety when working with such a huge and complex standard can save you lots of time debugging difficult problems. The initial setup cost of using fhir_rs will pay for itself quickly through faster iteration on the data types.

Why do you wrap serde_json values instead of just using normal structs?

The initial version of this library used normal Rust structs... and quickly ran into stack overflows and performance problems. Rust's structs are not sparsely allocated, they consume exactly as much space as the member types require. In most mature Rust model libraries that use structs, use of enum/union types avoid the memory allocations, however the FHIR standard was built this in mind, and in practice some of the value types are enormous bags of nullable data.

As a result, a sparse structure was necessary to avoid excessive memory allocations, and we decided to rely on the underlying serde_json values to avoid data copying.

Why was fhir_rs built?

I built fhir_rs so that I could prototype a healthcare server. The challenges I had in building out the FHIR spec as Rust data types made me want to share my work with others. Maybe it'll be useful, maybe not...

What features still need to be implemented?

If you'd like to help out, please take one of these and turn it into a Pull Request! All help is welcome.

  1. A better numeric interface for floats. At the moment floating point values are represented as f64, and although we internally use an arbitrary precision feature inside Serde, the values we expose to the user are still f64. As a result, you may experience a reduction in precision when actually retrieving values, and the number of places after the decimal point are not preserved. This is true of many FHIR implementations, but we will be resolving this ASAP.

  2. Full (optional) OAuth support for authentication for full SMART on FHIR (SoF) interop. We don't want these additional features to bloat the core, it'll always stay a small collection of model wrappers, but over time we'd like to see this library expand optional support for SoF communication.

  3. (Optional) API Call interface. After we add authentication support, I'd like to provide an async interface for interacting with SoF APIs. This way you get to interact with a code completion engine for your remote calls in addition to your local data processing.

fhir-rs's People

Contributors

ocrickard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fhir-rs's Issues

might be able to simplify a bit

interesting library!

in looking at models/Account.rs, I noticed this pattern repeated a lot

        if let Some(val) = self.value.get("_description") {
            return Some(Element {
                value: Cow::Borrowed(val),
            });
        }
        return None;

is it possible you think to make a Prism for that?

it'a a way to define a getter/setter pair for an object, or none, if it doesn't exist.

I literally don't know rust yet but it might be something like this:

let description_prism: ResourcePrism = ResourcePrism::from_str("_description")
let maybe_description: Option<Element> = view(description_prism, account)

not sure if there's a great rust crate for functional programming optics but even if you rolled it yourself it would allow you to delete a lot of code!

plus you could immutably update the resources with the same strategy

let account_with_new_description: Account = over(description_prism, always("my new description!"), account)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.