#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Observation {
pub id: Option<std::string::String>,
pub meta: Option<super::meta::Meta>,
pub implicit_rules: Option<super::primitives::Uri>,
pub language: Option<super::primitives::Code>,
pub text: Option<super::narrative::Narrative>,
pub contained: Vec<super::resource::Resource>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Vec<super::identifier::Identifier>,
pub based_on: Vec<super::reference::Reference>,
pub triggered_by: Vec<ObservationTriggeredBy>,
pub part_of: Vec<super::reference::Reference>,
pub status: super::primitives::Code,
pub status_reason: Option<super::codeable_concept::CodeableConcept>,
pub category: Vec<super::codeable_concept::CodeableConcept>,
pub code: super::codeable_concept::CodeableConcept,
pub subject: Option<super::reference::Reference>,
pub focus: Vec<super::reference::Reference>,
pub organizer: Option<super::primitives::Boolean>,
pub encounter: Option<super::reference::Reference>,
pub effective: Option<ObservationEffective>,
pub issued: Option<super::primitives::Instant>,
pub performer: Vec<super::reference::Reference>,
pub value: Option<ObservationValue>,
pub data_absent_reason: Option<super::codeable_concept::CodeableConcept>,
pub interpretation: Vec<super::codeable_concept::CodeableConcept>,
pub context: Vec<super::codeable_reference::CodeableReference>,
pub note: Vec<super::annotation::Annotation>,
pub body_site: Option<super::codeable_concept::CodeableConcept>,
pub body_structure: Vec<super::codeable_reference::CodeableReference>,
pub method: Option<super::codeable_concept::CodeableConcept>,
pub specimen: Option<super::reference::Reference>,
pub device: Option<super::reference::Reference>,
pub supporting_device: Vec<super::codeable_reference::CodeableReference>,
pub reference_range: Vec<ObservationReferenceRange>,
pub has_member: Vec<super::reference::Reference>,
pub derived_from: Vec<super::reference::Reference>,
pub component: Vec<ObservationComponent>,
}
impl super::super::codec::Json for Observation {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
object.insert(
std::string::String::from("resourceType"),
super::super::codec::Value::String(std::string::String::from("Observation")),
);
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if !self.based_on.is_empty() {
let mut items = Vec::with_capacity(self.based_on.len());
for item in &self.based_on {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("basedOn"),
super::super::codec::Value::Array(items),
);
}
if !self.triggered_by.is_empty() {
let mut items = Vec::with_capacity(self.triggered_by.len());
for item in &self.triggered_by {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("triggeredBy"),
super::super::codec::Value::Array(items),
);
}
if !self.part_of.is_empty() {
let mut items = Vec::with_capacity(self.part_of.len());
for item in &self.part_of {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("partOf"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.status)? {
object.insert(std::string::String::from("status"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.status)? {
object.insert(std::string::String::from("_status"), e);
}
if let Some(item) = &self.status_reason {
object.insert(
std::string::String::from("statusReason"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.category.is_empty() {
let mut items = Vec::with_capacity(self.category.len());
for item in &self.category {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.code)?),
);
if let Some(item) = &self.subject {
object.insert(
std::string::String::from("subject"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.focus.is_empty() {
let mut items = Vec::with_capacity(self.focus.len());
for item in &self.focus {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("focus"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.organizer {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("organizer"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_organizer"), e);
}
}
if let Some(item) = &self.encounter {
object.insert(
std::string::String::from("encounter"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.effective {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("effective{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_effective{suffix}"), element);
}
}
if let Some(item) = &self.issued {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("issued"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_issued"), e);
}
}
if !self.performer.is_empty() {
let mut items = Vec::with_capacity(self.performer.len());
for item in &self.performer {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("performer"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.value {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("value{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_value{suffix}"), element);
}
}
if let Some(item) = &self.data_absent_reason {
object.insert(
std::string::String::from("dataAbsentReason"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.interpretation.is_empty() {
let mut items = Vec::with_capacity(self.interpretation.len());
for item in &self.interpretation {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("interpretation"),
super::super::codec::Value::Array(items),
);
}
if !self.context.is_empty() {
let mut items = Vec::with_capacity(self.context.len());
for item in &self.context {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("context"),
super::super::codec::Value::Array(items),
);
}
if !self.note.is_empty() {
let mut items = Vec::with_capacity(self.note.len());
for item in &self.note {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("note"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.body_site {
object.insert(
std::string::String::from("bodySite"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.body_structure.is_empty() {
let mut items = Vec::with_capacity(self.body_structure.len());
for item in &self.body_structure {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("bodyStructure"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.method {
object.insert(
std::string::String::from("method"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.specimen {
object.insert(
std::string::String::from("specimen"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.device {
object.insert(
std::string::String::from("device"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.supporting_device.is_empty() {
let mut items = Vec::with_capacity(self.supporting_device.len());
for item in &self.supporting_device {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("supportingDevice"),
super::super::codec::Value::Array(items),
);
}
if !self.reference_range.is_empty() {
let mut items = Vec::with_capacity(self.reference_range.len());
for item in &self.reference_range {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("referenceRange"),
super::super::codec::Value::Array(items),
);
}
if !self.has_member.is_empty() {
let mut items = Vec::with_capacity(self.has_member.len());
for item in &self.has_member {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("hasMember"),
super::super::codec::Value::Array(items),
);
}
if !self.derived_from.is_empty() {
let mut items = Vec::with_capacity(self.derived_from.len());
for item in &self.derived_from {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("derivedFrom"),
super::super::codec::Value::Array(items),
);
}
if !self.component.is_empty() {
let mut items = Vec::with_capacity(self.component.len());
for item in &self.component {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("component"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_meta: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_language_element: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_contained: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_based_on: Option<&super::super::codec::Value> = None;
let mut raw_triggered_by: Option<&super::super::codec::Value> = None;
let mut raw_part_of: Option<&super::super::codec::Value> = None;
let mut raw_status: Option<&super::super::codec::Value> = None;
let mut raw_status_element: Option<&super::super::codec::Value> = None;
let mut raw_status_reason: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_subject: Option<&super::super::codec::Value> = None;
let mut raw_focus: Option<&super::super::codec::Value> = None;
let mut raw_organizer: Option<&super::super::codec::Value> = None;
let mut raw_organizer_element: Option<&super::super::codec::Value> = None;
let mut raw_encounter: Option<&super::super::codec::Value> = None;
let mut raw_effective = super::super::codec::ChoiceSlot::default();
let mut raw_issued: Option<&super::super::codec::Value> = None;
let mut raw_issued_element: Option<&super::super::codec::Value> = None;
let mut raw_performer: Option<&super::super::codec::Value> = None;
let mut raw_value = super::super::codec::ChoiceSlot::default();
let mut raw_data_absent_reason: Option<&super::super::codec::Value> = None;
let mut raw_interpretation: Option<&super::super::codec::Value> = None;
let mut raw_context: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_body_site: Option<&super::super::codec::Value> = None;
let mut raw_body_structure: Option<&super::super::codec::Value> = None;
let mut raw_method: Option<&super::super::codec::Value> = None;
let mut raw_specimen: Option<&super::super::codec::Value> = None;
let mut raw_device: Option<&super::super::codec::Value> = None;
let mut raw_supporting_device: Option<&super::super::codec::Value> = None;
let mut raw_reference_range: Option<&super::super::codec::Value> = None;
let mut raw_has_member: Option<&super::super::codec::Value> = None;
let mut raw_derived_from: Option<&super::super::codec::Value> = None;
let mut raw_component: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("Observation") {
return Err(path.error(super::super::codec::DecodeErrorKind::ResourceType));
}
}
"id" => {
raw_id = Some(value);
}
"meta" => {
raw_meta = Some(value);
}
"implicitRules" => {
raw_implicit_rules = Some(value);
}
"_implicitRules" => {
raw_implicit_rules_element = Some(value);
}
"language" => {
raw_language = Some(value);
}
"_language" => {
raw_language_element = Some(value);
}
"text" => {
raw_text = Some(value);
}
"contained" => {
raw_contained = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"identifier" => {
raw_identifier = Some(value);
}
"basedOn" => {
raw_based_on = Some(value);
}
"triggeredBy" => {
raw_triggered_by = Some(value);
}
"partOf" => {
raw_part_of = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"statusReason" => {
raw_status_reason = Some(value);
}
"category" => {
raw_category = Some(value);
}
"code" => {
raw_code = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"focus" => {
raw_focus = Some(value);
}
"organizer" => {
raw_organizer = Some(value);
}
"_organizer" => {
raw_organizer_element = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"effectiveDateTime" => {
raw_effective.value("DateTime", value, path)?;
}
"_effectiveDateTime" => {
raw_effective.element("DateTime", value, path)?;
}
"effectivePeriod" => {
raw_effective.value("Period", value, path)?;
}
"_effectivePeriod" => {
raw_effective.element("Period", value, path)?;
}
"effectiveTiming" => {
raw_effective.value("Timing", value, path)?;
}
"_effectiveTiming" => {
raw_effective.element("Timing", value, path)?;
}
"effectiveInstant" => {
raw_effective.value("Instant", value, path)?;
}
"_effectiveInstant" => {
raw_effective.element("Instant", value, path)?;
}
"issued" => {
raw_issued = Some(value);
}
"_issued" => {
raw_issued_element = Some(value);
}
"performer" => {
raw_performer = Some(value);
}
"valueQuantity" => {
raw_value.value("Quantity", value, path)?;
}
"_valueQuantity" => {
raw_value.element("Quantity", value, path)?;
}
"valueCodeableConcept" => {
raw_value.value("CodeableConcept", value, path)?;
}
"_valueCodeableConcept" => {
raw_value.element("CodeableConcept", value, path)?;
}
"valueString" => {
raw_value.value("String", value, path)?;
}
"_valueString" => {
raw_value.element("String", value, path)?;
}
"valueBoolean" => {
raw_value.value("Boolean", value, path)?;
}
"_valueBoolean" => {
raw_value.element("Boolean", value, path)?;
}
"valueInteger" => {
raw_value.value("Integer", value, path)?;
}
"_valueInteger" => {
raw_value.element("Integer", value, path)?;
}
"valueRange" => {
raw_value.value("Range", value, path)?;
}
"_valueRange" => {
raw_value.element("Range", value, path)?;
}
"valueRatio" => {
raw_value.value("Ratio", value, path)?;
}
"_valueRatio" => {
raw_value.element("Ratio", value, path)?;
}
"valueSampledData" => {
raw_value.value("SampledData", value, path)?;
}
"_valueSampledData" => {
raw_value.element("SampledData", value, path)?;
}
"valueTime" => {
raw_value.value("Time", value, path)?;
}
"_valueTime" => {
raw_value.element("Time", value, path)?;
}
"valueDateTime" => {
raw_value.value("DateTime", value, path)?;
}
"_valueDateTime" => {
raw_value.element("DateTime", value, path)?;
}
"valuePeriod" => {
raw_value.value("Period", value, path)?;
}
"_valuePeriod" => {
raw_value.element("Period", value, path)?;
}
"valueAttachment" => {
raw_value.value("Attachment", value, path)?;
}
"_valueAttachment" => {
raw_value.element("Attachment", value, path)?;
}
"dataAbsentReason" => {
raw_data_absent_reason = Some(value);
}
"interpretation" => {
raw_interpretation = Some(value);
}
"context" => {
raw_context = Some(value);
}
"note" => {
raw_note = Some(value);
}
"bodySite" => {
raw_body_site = Some(value);
}
"bodyStructure" => {
raw_body_structure = Some(value);
}
"method" => {
raw_method = Some(value);
}
"specimen" => {
raw_specimen = Some(value);
}
"device" => {
raw_device = Some(value);
}
"supportingDevice" => {
raw_supporting_device = Some(value);
}
"referenceRange" => {
raw_reference_range = Some(value);
}
"hasMember" => {
raw_has_member = Some(value);
}
"derivedFrom" => {
raw_derived_from = Some(value);
}
"component" => {
raw_component = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_id(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in path
.with("contained", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in path
.with("extension", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in path
.with("modifierExtension", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in path
.with("identifier", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_based_on = Vec::new();
if let Some(raw) = raw_based_on {
for (index, value) in path
.with("basedOn", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_based_on.push(path.with_index("basedOn", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_triggered_by = Vec::new();
if let Some(raw) = raw_triggered_by {
for (index, value) in path
.with("triggeredBy", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_triggered_by.push(path.with_index("triggeredBy", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_part_of = Vec::new();
if let Some(raw) = raw_part_of {
for (index, value) in path
.with("partOf", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_part_of.push(path.with_index("partOf", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
let field_status_reason = raw_status_reason
.map(|value| {
path.with("statusReason", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_category = Vec::new();
if let Some(raw) = raw_category {
for (index, value) in path
.with("category", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_category.push(path.with_index("category", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_code = path.with("code", |path| {
let value = raw_code
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_subject = raw_subject
.map(|value| {
path.with("subject", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_focus = Vec::new();
if let Some(raw) = raw_focus {
for (index, value) in path
.with("focus", |path| super::super::codec::expect_array(raw, path))?
.iter()
.enumerate()
{
field_focus.push(path.with_index("focus", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_organizer = match (raw_organizer, raw_organizer_element) {
(None, None) => None,
(value, element) => Some(path.with("organizer", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_encounter = raw_encounter
.map(|value| {
path.with("encounter", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_effective = match raw_effective.suffix {
None => None,
Some(suffix) => Some(path.with("effective", |path| {
ObservationEffective::from_json_parts(
suffix,
raw_effective.value,
raw_effective.element,
path,
)
})?),
};
let field_issued = match (raw_issued, raw_issued_element) {
(None, None) => None,
(value, element) => Some(path.with("issued", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_performer = Vec::new();
if let Some(raw) = raw_performer {
for (index, value) in path
.with("performer", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_performer.push(path.with_index("performer", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_value = match raw_value.suffix {
None => None,
Some(suffix) => Some(path.with("value", |path| {
ObservationValue::from_json_parts(suffix, raw_value.value, raw_value.element, path)
})?),
};
let field_data_absent_reason = raw_data_absent_reason
.map(|value| {
path.with("dataAbsentReason", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_interpretation = Vec::new();
if let Some(raw) = raw_interpretation {
for (index, value) in path
.with("interpretation", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_interpretation.push(path.with_index("interpretation", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_context = Vec::new();
if let Some(raw) = raw_context {
for (index, value) in path
.with("context", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_context.push(path.with_index("context", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_note = Vec::new();
if let Some(raw) = raw_note {
for (index, value) in path
.with("note", |path| super::super::codec::expect_array(raw, path))?
.iter()
.enumerate()
{
field_note.push(path.with_index("note", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_body_site = raw_body_site
.map(|value| {
path.with("bodySite", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_body_structure = Vec::new();
if let Some(raw) = raw_body_structure {
for (index, value) in path
.with("bodyStructure", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_body_structure.push(path.with_index("bodyStructure", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_method = raw_method
.map(|value| {
path.with("method", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_specimen = raw_specimen
.map(|value| {
path.with("specimen", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_device = raw_device
.map(|value| {
path.with("device", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_supporting_device = Vec::new();
if let Some(raw) = raw_supporting_device {
for (index, value) in path
.with("supportingDevice", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_supporting_device.push(path.with_index(
"supportingDevice",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_reference_range = Vec::new();
if let Some(raw) = raw_reference_range {
for (index, value) in path
.with("referenceRange", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_reference_range.push(path.with_index("referenceRange", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_has_member = Vec::new();
if let Some(raw) = raw_has_member {
for (index, value) in path
.with("hasMember", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_has_member.push(path.with_index("hasMember", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_derived_from = Vec::new();
if let Some(raw) = raw_derived_from {
for (index, value) in path
.with("derivedFrom", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_derived_from.push(path.with_index("derivedFrom", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_component = Vec::new();
if let Some(raw) = raw_component {
for (index, value) in path
.with("component", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_component.push(path.with_index("component", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
meta: field_meta,
implicit_rules: field_implicit_rules,
language: field_language,
text: field_text,
contained: field_contained,
extension: field_extension,
modifier_extension: field_modifier_extension,
identifier: field_identifier,
based_on: field_based_on,
triggered_by: field_triggered_by,
part_of: field_part_of,
status: field_status,
status_reason: field_status_reason,
category: field_category,
code: field_code,
subject: field_subject,
focus: field_focus,
organizer: field_organizer,
encounter: field_encounter,
effective: field_effective,
issued: field_issued,
performer: field_performer,
value: field_value,
data_absent_reason: field_data_absent_reason,
interpretation: field_interpretation,
context: field_context,
note: field_note,
body_site: field_body_site,
body_structure: field_body_structure,
method: field_method,
specimen: field_specimen,
device: field_device,
supporting_device: field_supporting_device,
reference_range: field_reference_range,
has_member: field_has_member,
derived_from: field_derived_from,
component: field_component,
})
}
}
impl serde::Serialize for Observation {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.effective {
Some(ObservationEffective::DateTime(inner)) => {
super::super::codec::element_entry(&mut map, "_effectiveDateTime", inner)?;
}
Some(ObservationEffective::Instant(inner)) => {
super::super::codec::element_entry(&mut map, "_effectiveInstant", inner)?;
}
_ => {}
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.issued {
super::super::codec::element_entry(&mut map, "_issued", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(item) = &self.organizer {
super::super::codec::element_entry(&mut map, "_organizer", item)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
match &self.value {
Some(ObservationValue::Boolean(inner)) => {
super::super::codec::element_entry(&mut map, "_valueBoolean", inner)?;
}
Some(ObservationValue::DateTime(inner)) => {
super::super::codec::element_entry(&mut map, "_valueDateTime", inner)?;
}
Some(ObservationValue::Integer(inner)) => {
super::super::codec::element_entry(&mut map, "_valueInteger", inner)?;
}
Some(ObservationValue::String(inner)) => {
super::super::codec::element_entry(&mut map, "_valueString", inner)?;
}
Some(ObservationValue::Time(inner)) => {
super::super::codec::element_entry(&mut map, "_valueTime", inner)?;
}
_ => {}
}
if !self.based_on.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "basedOn", &self.based_on)?;
}
if let Some(item) = &self.body_site {
serde::ser::SerializeMap::serialize_entry(&mut map, "bodySite", item)?;
}
if !self.body_structure.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"bodyStructure",
&self.body_structure,
)?;
}
if !self.category.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
if !self.component.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "component", &self.component)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if !self.context.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "context", &self.context)?;
}
if let Some(item) = &self.data_absent_reason {
serde::ser::SerializeMap::serialize_entry(&mut map, "dataAbsentReason", item)?;
}
if !self.derived_from.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "derivedFrom", &self.derived_from)?;
}
if let Some(item) = &self.device {
serde::ser::SerializeMap::serialize_entry(&mut map, "device", item)?;
}
match &self.effective {
Some(ObservationEffective::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "effectiveDateTime", inner)?;
}
Some(ObservationEffective::Instant(inner)) => {
super::super::codec::value_entry(&mut map, "effectiveInstant", inner)?;
}
Some(ObservationEffective::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"effectivePeriod",
inner.as_ref(),
)?;
}
Some(ObservationEffective::Timing(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"effectiveTiming",
inner.as_ref(),
)?;
}
None => {}
}
if let Some(item) = &self.encounter {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if !self.focus.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "focus", &self.focus)?;
}
if !self.has_member.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "hasMember", &self.has_member)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if !self.interpretation.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"interpretation",
&self.interpretation,
)?;
}
if let Some(item) = &self.issued {
super::super::codec::value_entry(&mut map, "issued", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.meta {
serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
}
if let Some(item) = &self.method {
serde::ser::SerializeMap::serialize_entry(&mut map, "method", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
if let Some(item) = &self.organizer {
super::super::codec::value_entry(&mut map, "organizer", item)?;
}
if !self.part_of.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "partOf", &self.part_of)?;
}
if !self.performer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "performer", &self.performer)?;
}
if !self.reference_range.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"referenceRange",
&self.reference_range,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "Observation")?;
if let Some(item) = &self.specimen {
serde::ser::SerializeMap::serialize_entry(&mut map, "specimen", item)?;
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if let Some(item) = &self.status_reason {
serde::ser::SerializeMap::serialize_entry(&mut map, "statusReason", item)?;
}
if let Some(item) = &self.subject {
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", item)?;
}
if !self.supporting_device.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"supportingDevice",
&self.supporting_device,
)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if !self.triggered_by.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "triggeredBy", &self.triggered_by)?;
}
match &self.value {
Some(ObservationValue::Attachment(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueAttachment",
inner.as_ref(),
)?;
}
Some(ObservationValue::Boolean(inner)) => {
super::super::codec::value_entry(&mut map, "valueBoolean", inner)?;
}
Some(ObservationValue::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueCodeableConcept",
inner.as_ref(),
)?;
}
Some(ObservationValue::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "valueDateTime", inner)?;
}
Some(ObservationValue::Integer(inner)) => {
super::super::codec::value_entry(&mut map, "valueInteger", inner)?;
}
Some(ObservationValue::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valuePeriod", inner.as_ref())?;
}
Some(ObservationValue::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueQuantity",
inner.as_ref(),
)?;
}
Some(ObservationValue::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valueRange", inner.as_ref())?;
}
Some(ObservationValue::Ratio(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valueRatio", inner.as_ref())?;
}
Some(ObservationValue::SampledData(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueSampledData",
inner.as_ref(),
)?;
}
Some(ObservationValue::String(inner)) => {
super::super::codec::value_entry(&mut map, "valueString", inner)?;
}
Some(ObservationValue::Time(inner)) => {
super::super::codec::value_entry(&mut map, "valueTime", inner)?;
}
None => {}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Observation {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
let mut path = super::super::codec::Path::root("Observation");
let object =
super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ObservationComponent {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub code: super::codeable_concept::CodeableConcept,
pub value: Option<ObservationComponentValue>,
pub data_absent_reason: Option<super::codeable_concept::CodeableConcept>,
pub interpretation: Vec<super::codeable_concept::CodeableConcept>,
pub reference_range: Vec<ObservationReferenceRange>,
}
impl super::super::codec::Json for ObservationComponent {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.code)?),
);
if let Some(item) = &self.value {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("value{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_value{suffix}"), element);
}
}
if let Some(item) = &self.data_absent_reason {
object.insert(
std::string::String::from("dataAbsentReason"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.interpretation.is_empty() {
let mut items = Vec::with_capacity(self.interpretation.len());
for item in &self.interpretation {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("interpretation"),
super::super::codec::Value::Array(items),
);
}
if !self.reference_range.is_empty() {
let mut items = Vec::with_capacity(self.reference_range.len());
for item in &self.reference_range {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("referenceRange"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_value = super::super::codec::ChoiceSlot::default();
let mut raw_data_absent_reason: Option<&super::super::codec::Value> = None;
let mut raw_interpretation: Option<&super::super::codec::Value> = None;
let mut raw_reference_range: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"code" => {
raw_code = Some(value);
}
"valueQuantity" => {
raw_value.value("Quantity", value, path)?;
}
"_valueQuantity" => {
raw_value.element("Quantity", value, path)?;
}
"valueCodeableConcept" => {
raw_value.value("CodeableConcept", value, path)?;
}
"_valueCodeableConcept" => {
raw_value.element("CodeableConcept", value, path)?;
}
"valueString" => {
raw_value.value("String", value, path)?;
}
"_valueString" => {
raw_value.element("String", value, path)?;
}
"valueBoolean" => {
raw_value.value("Boolean", value, path)?;
}
"_valueBoolean" => {
raw_value.element("Boolean", value, path)?;
}
"valueInteger" => {
raw_value.value("Integer", value, path)?;
}
"_valueInteger" => {
raw_value.element("Integer", value, path)?;
}
"valueRange" => {
raw_value.value("Range", value, path)?;
}
"_valueRange" => {
raw_value.element("Range", value, path)?;
}
"valueRatio" => {
raw_value.value("Ratio", value, path)?;
}
"_valueRatio" => {
raw_value.element("Ratio", value, path)?;
}
"valueSampledData" => {
raw_value.value("SampledData", value, path)?;
}
"_valueSampledData" => {
raw_value.element("SampledData", value, path)?;
}
"valueTime" => {
raw_value.value("Time", value, path)?;
}
"_valueTime" => {
raw_value.element("Time", value, path)?;
}
"valueDateTime" => {
raw_value.value("DateTime", value, path)?;
}
"_valueDateTime" => {
raw_value.element("DateTime", value, path)?;
}
"valuePeriod" => {
raw_value.value("Period", value, path)?;
}
"_valuePeriod" => {
raw_value.element("Period", value, path)?;
}
"valueAttachment" => {
raw_value.value("Attachment", value, path)?;
}
"_valueAttachment" => {
raw_value.element("Attachment", value, path)?;
}
"dataAbsentReason" => {
raw_data_absent_reason = Some(value);
}
"interpretation" => {
raw_interpretation = Some(value);
}
"referenceRange" => {
raw_reference_range = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in path
.with("extension", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in path
.with("modifierExtension", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_code = path.with("code", |path| {
let value = raw_code
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_value = match raw_value.suffix {
None => None,
Some(suffix) => Some(path.with("value", |path| {
ObservationComponentValue::from_json_parts(
suffix,
raw_value.value,
raw_value.element,
path,
)
})?),
};
let field_data_absent_reason = raw_data_absent_reason
.map(|value| {
path.with("dataAbsentReason", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_interpretation = Vec::new();
if let Some(raw) = raw_interpretation {
for (index, value) in path
.with("interpretation", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_interpretation.push(path.with_index("interpretation", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_reference_range = Vec::new();
if let Some(raw) = raw_reference_range {
for (index, value) in path
.with("referenceRange", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_reference_range.push(path.with_index("referenceRange", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
code: field_code,
value: field_value,
data_absent_reason: field_data_absent_reason,
interpretation: field_interpretation,
reference_range: field_reference_range,
})
}
}
impl serde::Serialize for ObservationComponent {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.value {
Some(ObservationComponentValue::Boolean(inner)) => {
super::super::codec::element_entry(&mut map, "_valueBoolean", inner)?;
}
Some(ObservationComponentValue::DateTime(inner)) => {
super::super::codec::element_entry(&mut map, "_valueDateTime", inner)?;
}
Some(ObservationComponentValue::Integer(inner)) => {
super::super::codec::element_entry(&mut map, "_valueInteger", inner)?;
}
Some(ObservationComponentValue::String(inner)) => {
super::super::codec::element_entry(&mut map, "_valueString", inner)?;
}
Some(ObservationComponentValue::Time(inner)) => {
super::super::codec::element_entry(&mut map, "_valueTime", inner)?;
}
_ => {}
}
serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
if let Some(item) = &self.data_absent_reason {
serde::ser::SerializeMap::serialize_entry(&mut map, "dataAbsentReason", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.interpretation.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"interpretation",
&self.interpretation,
)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.reference_range.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"referenceRange",
&self.reference_range,
)?;
}
match &self.value {
Some(ObservationComponentValue::Attachment(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueAttachment",
inner.as_ref(),
)?;
}
Some(ObservationComponentValue::Boolean(inner)) => {
super::super::codec::value_entry(&mut map, "valueBoolean", inner)?;
}
Some(ObservationComponentValue::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueCodeableConcept",
inner.as_ref(),
)?;
}
Some(ObservationComponentValue::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "valueDateTime", inner)?;
}
Some(ObservationComponentValue::Integer(inner)) => {
super::super::codec::value_entry(&mut map, "valueInteger", inner)?;
}
Some(ObservationComponentValue::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valuePeriod", inner.as_ref())?;
}
Some(ObservationComponentValue::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueQuantity",
inner.as_ref(),
)?;
}
Some(ObservationComponentValue::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valueRange", inner.as_ref())?;
}
Some(ObservationComponentValue::Ratio(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valueRatio", inner.as_ref())?;
}
Some(ObservationComponentValue::SampledData(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueSampledData",
inner.as_ref(),
)?;
}
Some(ObservationComponentValue::String(inner)) => {
super::super::codec::value_entry(&mut map, "valueString", inner)?;
}
Some(ObservationComponentValue::Time(inner)) => {
super::super::codec::value_entry(&mut map, "valueTime", inner)?;
}
None => {}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ObservationComponent {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
let mut path = super::super::codec::Path::root("ObservationComponent");
let object =
super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ObservationComponentValue {
Quantity(Box<super::quantity::Quantity>),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
String(super::primitives::String),
Boolean(super::primitives::Boolean),
Integer(super::primitives::Integer),
Range(Box<super::range::Range>),
Ratio(Box<super::ratio::Ratio>),
SampledData(Box<super::sampled_data::SampledData>),
Time(super::primitives::Time),
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
Attachment(Box<super::attachment::Attachment>),
}
impl ObservationComponentValue {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::Quantity(inner) => Ok((
"Quantity",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::String(inner) => Ok((
"String",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Boolean(inner) => Ok((
"Boolean",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Integer(inner) => Ok((
"Integer",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Range(inner) => Ok((
"Range",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Ratio(inner) => Ok((
"Ratio",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::SampledData(inner) => Ok((
"SampledData",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Time(inner) => Ok((
"Time",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Attachment(inner) => Ok((
"Attachment",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Quantity" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Quantity(Box::new(inner)))
}
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(Box::new(inner)))
}
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Boolean" => Ok(Self::Boolean(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Integer" => Ok(Self::Integer(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Range" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Range(Box::new(inner)))
}
"Ratio" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Ratio(Box::new(inner)))
}
"SampledData" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::SampledData(Box::new(inner)))
}
"Time" => Ok(Self::Time(super::super::codec::Primitive::from_json_parts(
value, element, path,
)?)),
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
"Attachment" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Attachment(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ObservationEffective {
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
Timing(Box<super::timing::Timing>),
Instant(super::primitives::Instant),
}
impl ObservationEffective {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Timing(inner) => Ok((
"Timing",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Instant(inner) => Ok((
"Instant",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
"Timing" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Timing(Box::new(inner)))
}
"Instant" => Ok(Self::Instant(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ObservationReferenceRange {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub low: Option<super::quantity::Quantity>,
pub high: Option<super::quantity::Quantity>,
pub normal_value: Option<super::codeable_concept::CodeableConcept>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub applies_to: Vec<super::codeable_concept::CodeableConcept>,
pub age: Option<super::range::Range>,
pub text: Option<super::primitives::Markdown>,
}
impl super::super::codec::Json for ObservationReferenceRange {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.low {
object.insert(
std::string::String::from("low"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.high {
object.insert(
std::string::String::from("high"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.normal_value {
object.insert(
std::string::String::from("normalValue"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.r#type {
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.applies_to.is_empty() {
let mut items = Vec::with_capacity(self.applies_to.len());
for item in &self.applies_to {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("appliesTo"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.age {
object.insert(
std::string::String::from("age"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.text {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("text"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_text"), e);
}
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_low: Option<&super::super::codec::Value> = None;
let mut raw_high: Option<&super::super::codec::Value> = None;
let mut raw_normal_value: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_applies_to: Option<&super::super::codec::Value> = None;
let mut raw_age: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_text_element: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"low" => {
raw_low = Some(value);
}
"high" => {
raw_high = Some(value);
}
"normalValue" => {
raw_normal_value = Some(value);
}
"type" => {
raw_type = Some(value);
}
"appliesTo" => {
raw_applies_to = Some(value);
}
"age" => {
raw_age = Some(value);
}
"text" => {
raw_text = Some(value);
}
"_text" => {
raw_text_element = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in path
.with("extension", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in path
.with("modifierExtension", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_low = raw_low
.map(|value| {
path.with("low", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_high = raw_high
.map(|value| {
path.with("high", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_normal_value = raw_normal_value
.map(|value| {
path.with("normalValue", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_type = raw_type
.map(|value| {
path.with("type", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_applies_to = Vec::new();
if let Some(raw) = raw_applies_to {
for (index, value) in path
.with("appliesTo", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_applies_to.push(path.with_index("appliesTo", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_age = raw_age
.map(|value| {
path.with("age", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_text = match (raw_text, raw_text_element) {
(None, None) => None,
(value, element) => Some(path.with("text", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
low: field_low,
high: field_high,
normal_value: field_normal_value,
r#type: field_type,
applies_to: field_applies_to,
age: field_age,
text: field_text,
})
}
}
impl serde::Serialize for ObservationReferenceRange {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.text {
super::super::codec::element_entry(&mut map, "_text", item)?;
}
if let Some(item) = &self.age {
serde::ser::SerializeMap::serialize_entry(&mut map, "age", item)?;
}
if !self.applies_to.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "appliesTo", &self.applies_to)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.high {
serde::ser::SerializeMap::serialize_entry(&mut map, "high", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.low {
serde::ser::SerializeMap::serialize_entry(&mut map, "low", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.normal_value {
serde::ser::SerializeMap::serialize_entry(&mut map, "normalValue", item)?;
}
if let Some(item) = &self.text {
super::super::codec::value_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ObservationReferenceRange {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
let mut path = super::super::codec::Path::root("ObservationReferenceRange");
let object =
super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ObservationTriggeredBy {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub observation: super::reference::Reference,
pub r#type: super::primitives::Code,
pub reason: Option<super::primitives::String>,
}
impl super::super::codec::Json for ObservationTriggeredBy {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("observation"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.observation,
)?),
);
if let Some(v) = super::super::codec::Primitive::value_json(&self.r#type)? {
object.insert(std::string::String::from("type"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.r#type)? {
object.insert(std::string::String::from("_type"), e);
}
if let Some(item) = &self.reason {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("reason"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_reason"), e);
}
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_observation: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_type_element: Option<&super::super::codec::Value> = None;
let mut raw_reason: Option<&super::super::codec::Value> = None;
let mut raw_reason_element: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"observation" => {
raw_observation = Some(value);
}
"type" => {
raw_type = Some(value);
}
"_type" => {
raw_type_element = Some(value);
}
"reason" => {
raw_reason = Some(value);
}
"_reason" => {
raw_reason_element = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in path
.with("extension", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in path
.with("modifierExtension", |path| {
super::super::codec::expect_array(raw, path)
})?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_observation = path.with("observation", |path| {
let value = raw_observation
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_type = path.with("type", |path| {
super::super::codec::Primitive::from_json_parts(raw_type, raw_type_element, path)
})?;
let field_reason = match (raw_reason, raw_reason_element) {
(None, None) => None,
(value, element) => Some(path.with("reason", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
observation: field_observation,
r#type: field_type,
reason: field_reason,
})
}
}
impl serde::Serialize for ObservationTriggeredBy {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.reason {
super::super::codec::element_entry(&mut map, "_reason", item)?;
}
super::super::codec::element_entry(&mut map, "_type", &self.r#type)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "observation", &self.observation)?;
if let Some(item) = &self.reason {
super::super::codec::value_entry(&mut map, "reason", item)?;
}
super::super::codec::value_entry(&mut map, "type", &self.r#type)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ObservationTriggeredBy {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
let mut path = super::super::codec::Path::root("ObservationTriggeredBy");
let object =
super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ObservationValue {
Quantity(Box<super::quantity::Quantity>),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
String(super::primitives::String),
Boolean(super::primitives::Boolean),
Integer(super::primitives::Integer),
Range(Box<super::range::Range>),
Ratio(Box<super::ratio::Ratio>),
SampledData(Box<super::sampled_data::SampledData>),
Time(super::primitives::Time),
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
Attachment(Box<super::attachment::Attachment>),
}
impl ObservationValue {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::Quantity(inner) => Ok((
"Quantity",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::String(inner) => Ok((
"String",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Boolean(inner) => Ok((
"Boolean",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Integer(inner) => Ok((
"Integer",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Range(inner) => Ok((
"Range",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Ratio(inner) => Ok((
"Ratio",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::SampledData(inner) => Ok((
"SampledData",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Time(inner) => Ok((
"Time",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Attachment(inner) => Ok((
"Attachment",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Quantity" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Quantity(Box::new(inner)))
}
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(Box::new(inner)))
}
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Boolean" => Ok(Self::Boolean(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Integer" => Ok(Self::Integer(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Range" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Range(Box::new(inner)))
}
"Ratio" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Ratio(Box::new(inner)))
}
"SampledData" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::SampledData(Box::new(inner)))
}
"Time" => Ok(Self::Time(super::super::codec::Primitive::from_json_parts(
value, element, path,
)?)),
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
"Attachment" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Attachment(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}