diff --git a/Cargo.lock b/Cargo.lock index 6c2a6e14..7f94cb8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,12 +145,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - [[package]] name = "encoding_rs" version = "0.8.32" @@ -222,7 +216,6 @@ name = "fhir-sdk" version = "0.4.0" dependencies = [ "async-trait", - "dotenvy", "eyre", "fhir-model 0.4.0", "futures", diff --git a/README.md b/README.md index 50380b04..880c39bf 100644 --- a/README.md +++ b/README.md @@ -13,21 +13,20 @@ This is a [FHIR](https://www.hl7.org/fhir/) library in its early stages. The mod ## Features -- [x] Generation of FHIR codes, types and resources +- [x] Generated FHIR codes, types and resources - [x] Serialization and deserialization to and from JSON -- [x] Linked code-fields to respective enums -- [x] Builders for types and resources -- [x] Allow to convert code enums to Coding and CodeableConcept +- [x] Optional builders for types and resources - [x] Implementation of base traits - - [x] (Base)Resource - - [x] NamedResource - - [x] DomainResource - - [x] IdentifiableResource + - [x] (Base)Resource for accessing common fields + - [x] NamedResource for getting the resource type in const time + - [x] DomainResource for accessing common fields + - [x] IdentifiableResource for all resources with an identifier field - [x] REST client implementation - [x] Create, Read, Update, Delete - [x] Search - [x] Paging - [ ] Batch operations / Transactions + - [ ] Operations - [ ] Patch - [ ] FHIRpath implementation - [ ] Resource validation using FHIRpath and regular expressions @@ -37,6 +36,32 @@ This is a [FHIR](https://www.hl7.org/fhir/) library in its early stages. The mod - XML +## Example + +```rust +use fhir_sdk::r5::resources::Patient; +use fhir_sdk::client::*; + +#[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()); + + Ok(()) +} +``` + +## Testing + +Simply set up the FHIR test server using `docker compose up -d` and run `cargo test --workspace` in the workspace root. + ## 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. diff --git a/crates/fhir-sdk/Cargo.toml b/crates/fhir-sdk/Cargo.toml index f9ba8130..68321780 100644 --- a/crates/fhir-sdk/Cargo.toml +++ b/crates/fhir-sdk/Cargo.toml @@ -29,6 +29,5 @@ thiserror = {version = "1.0.40", optional = true} tokio-retry = {version = "0.3.0", optional = true} [dev-dependencies] -dotenvy = "0.15.7" eyre = "0.6.8" tokio = {version = "1.27.0", features = ["full"]} diff --git a/crates/fhir-sdk/tests/client.rs b/crates/fhir-sdk/tests/client.rs index 28d634b9..342d61e0 100644 --- a/crates/fhir-sdk/tests/client.rs +++ b/crates/fhir-sdk/tests/client.rs @@ -12,8 +12,8 @@ use fhir_sdk::{ use futures::TryStreamExt; fn client() -> Result { - dotenvy::dotenv()?; - let base_url = env::var("BASE_URL").expect("BASE_URL missing").parse()?; + let base_url = + env::var("FHIR_SERVER").unwrap_or("http://localhost:8090/fhir/".to_owned()).parse()?; Ok(Client::new(base_url)?) } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..6e2050c0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.7' + +services: + fhir: + image: hapiproject/hapi:latest + ports: + - "8090:8080" + volumes: + - fhir-data:/data/hapi + environment: + hapi.fhir.fhir_version: "R5" + hapi.fhir.tester.home.fhir_version: "R5" + hapi.fhir.subscription.resthook_enabled: "true" + hapi.fhir.subscription.email.from: "test@test.test" + hapi.fhir.subscription.email.host: "test.test" + +volumes: + fhir-data: