use fhir::r5::resources::{Bundle, Resource};
fn main() {
let bundle_json = serde_json::json!({
"resourceType": "Bundle",
"type": "searchset",
"total": 2,
"entry": [
{ "resource": { "resourceType": "Patient", "id": "pat-1", "active": true } },
{ "resource": { "resourceType": "Observation", "id": "obs-1",
"status": "final",
"code": { "text": "Body temperature" } } }
]
});
let bundle: Bundle = serde_json::from_value(bundle_json).expect("parse Bundle");
println!("Bundle type: {}", bundle.r#type.0);
for entry in bundle.entry.into_iter().flatten() {
let Some(value) = entry.resource else { continue };
match serde_json::from_value(value).expect("parse entry resource") {
Resource::Patient(patient) => {
println!(
"- Patient {} (active: {:?})",
patient.id.as_ref().map_or("?", |id| &id.0),
patient.active.map(|b| b.0),
);
}
Resource::Observation(observation) => {
println!(
"- Observation {} (status: {})",
observation.id.as_ref().map_or("?", |id| &id.0),
observation.status.0,
);
}
other => println!("- some other resource: {other:?}"),
}
}
}