use ::serde::Serialize;
use ::serde_json::Value;
use crate::r3::meta;
#[must_use]
pub fn to_summary_value<T: Serialize>(resource: &T, resource_type: &str) -> Value {
crate::summary::to_summary_value(meta::elements(), resource, resource_type)
}
pub fn prune_to_summary(value: &mut Value, resource_type: &str) {
crate::summary::prune_to_summary(meta::elements(), value, resource_type);
}
#[cfg(test)]
mod tests {
use super::*;
use crate::r3::resources::Patient;
#[test]
fn patient_summary_keeps_summary_drops_the_rest() {
let patient: Patient = ::serde_json::from_value(::serde_json::json!({
"resourceType": "Patient",
"id": "p1",
"gender": "male",
"birthDate": "1970-01-01",
"name": [{ "family": "Chalmers" }],
"photo": [{ "title": "portrait" }],
"maritalStatus": { "text": "married" },
"communication": [{ "language": { "text": "en" } }]
}))
.unwrap();
let s = to_summary_value(&patient, "Patient");
for k in ["resourceType", "id", "gender", "birthDate", "name"] {
assert!(s.get(k).is_some(), "expected {k} in summary");
}
for k in ["photo", "maritalStatus", "communication"] {
assert!(s.get(k).is_none(), "expected {k} absent from summary");
}
}
#[test]
fn choice_element_summary() {
let patient: Patient = ::serde_json::from_value(::serde_json::json!({
"resourceType": "Patient",
"deceasedBoolean": true,
"multipleBirthInteger": 2
}))
.unwrap();
let s = to_summary_value(&patient, "Patient");
assert!(s.get("deceasedBoolean").is_some());
assert!(s.get("multipleBirthInteger").is_none());
}
}