#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ObservationDefinition {
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 category: Vec<super::codeable_concept::CodeableConcept>,
pub code: super::codeable_concept::CodeableConcept,
pub identifier: Vec<super::identifier::Identifier>,
pub permitted_data_type: Vec<super::primitives::Code>,
pub multiple_results_allowed: Option<super::primitives::Boolean>,
pub method: Option<super::codeable_concept::CodeableConcept>,
pub preferred_report_name: Option<super::primitives::String>,
pub quantitative_details: Option<ObservationDefinitionQuantitativeDetails>,
pub qualified_interval: Vec<ObservationDefinitionQualifiedInterval>,
pub valid_coded_value_set: Option<super::reference::Reference>,
pub normal_coded_value_set: Option<super::reference::Reference>,
pub abnormal_coded_value_set: Option<super::reference::Reference>,
pub critical_coded_value_set: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ObservationDefinition {
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("ObservationDefinition")),
);
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.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 !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.permitted_data_type.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.permitted_data_type)?;
object.insert(std::string::String::from("permittedDataType"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_permittedDataType"), elements);
}
}
if let Some(item) = &self.multiple_results_allowed {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("multipleResultsAllowed"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_multipleResultsAllowed"), e);
}
}
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.preferred_report_name {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("preferredReportName"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_preferredReportName"), e);
}
}
if let Some(item) = &self.quantitative_details {
object.insert(
std::string::String::from("quantitativeDetails"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.qualified_interval.is_empty() {
let mut items = Vec::with_capacity(self.qualified_interval.len());
for item in &self.qualified_interval {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("qualifiedInterval"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.valid_coded_value_set {
object.insert(
std::string::String::from("validCodedValueSet"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.normal_coded_value_set {
object.insert(
std::string::String::from("normalCodedValueSet"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.abnormal_coded_value_set {
object.insert(
std::string::String::from("abnormalCodedValueSet"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.critical_coded_value_set {
object.insert(
std::string::String::from("criticalCodedValueSet"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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_category: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_permitted_data_type: Option<&super::super::codec::Value> = None;
let mut raw_permitted_data_type_element: Option<&super::super::codec::Value> = None;
let mut raw_multiple_results_allowed: Option<&super::super::codec::Value> = None;
let mut raw_multiple_results_allowed_element: Option<&super::super::codec::Value> = None;
let mut raw_method: Option<&super::super::codec::Value> = None;
let mut raw_preferred_report_name: Option<&super::super::codec::Value> = None;
let mut raw_preferred_report_name_element: Option<&super::super::codec::Value> = None;
let mut raw_quantitative_details: Option<&super::super::codec::Value> = None;
let mut raw_qualified_interval: Option<&super::super::codec::Value> = None;
let mut raw_valid_coded_value_set: Option<&super::super::codec::Value> = None;
let mut raw_normal_coded_value_set: Option<&super::super::codec::Value> = None;
let mut raw_abnormal_coded_value_set: Option<&super::super::codec::Value> = None;
let mut raw_critical_coded_value_set: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("ObservationDefinition") {
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);
}
"category" => {
raw_category = Some(value);
}
"code" => {
raw_code = Some(value);
}
"identifier" => {
raw_identifier = Some(value);
}
"permittedDataType" => {
raw_permitted_data_type = Some(value);
}
"_permittedDataType" => {
raw_permitted_data_type_element = Some(value);
}
"multipleResultsAllowed" => {
raw_multiple_results_allowed = Some(value);
}
"_multipleResultsAllowed" => {
raw_multiple_results_allowed_element = Some(value);
}
"method" => {
raw_method = Some(value);
}
"preferredReportName" => {
raw_preferred_report_name = Some(value);
}
"_preferredReportName" => {
raw_preferred_report_name_element = Some(value);
}
"quantitativeDetails" => {
raw_quantitative_details = Some(value);
}
"qualifiedInterval" => {
raw_qualified_interval = Some(value);
}
"validCodedValueSet" => {
raw_valid_coded_value_set = Some(value);
}
"normalCodedValueSet" => {
raw_normal_coded_value_set = Some(value);
}
"abnormalCodedValueSet" => {
raw_abnormal_coded_value_set = Some(value);
}
"criticalCodedValueSet" => {
raw_critical_coded_value_set = 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::super::codec::expect_string(value, 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 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 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 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_category = Vec::new();
if let Some(raw) = raw_category {
for (index, value) in 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 mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in 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_permitted_data_type = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_permitted_data_type,
raw_permitted_data_type_element,
path,
)?
.into_iter()
.enumerate()
{
field_permitted_data_type.push(path.with_index(
"permittedDataType",
index,
|path| super::super::codec::Primitive::from_json_parts(value, element, path),
)?);
}
let field_multiple_results_allowed = match (
raw_multiple_results_allowed,
raw_multiple_results_allowed_element,
) {
(None, None) => None,
(value, element) => Some(path.with("multipleResultsAllowed", |path| {
super::super::codec::Primitive::from_json_parts(value, element, 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_preferred_report_name =
match (raw_preferred_report_name, raw_preferred_report_name_element) {
(None, None) => None,
(value, element) => Some(path.with("preferredReportName", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_quantitative_details = raw_quantitative_details
.map(|value| {
path.with("quantitativeDetails", |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_qualified_interval = Vec::new();
if let Some(raw) = raw_qualified_interval {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_qualified_interval.push(path.with_index(
"qualifiedInterval",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_valid_coded_value_set = raw_valid_coded_value_set
.map(|value| {
path.with("validCodedValueSet", |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_coded_value_set = raw_normal_coded_value_set
.map(|value| {
path.with("normalCodedValueSet", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_abnormal_coded_value_set = raw_abnormal_coded_value_set
.map(|value| {
path.with("abnormalCodedValueSet", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_critical_coded_value_set = raw_critical_coded_value_set
.map(|value| {
path.with("criticalCodedValueSet", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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,
category: field_category,
code: field_code,
identifier: field_identifier,
permitted_data_type: field_permitted_data_type,
multiple_results_allowed: field_multiple_results_allowed,
method: field_method,
preferred_report_name: field_preferred_report_name,
quantitative_details: field_quantitative_details,
qualified_interval: field_qualified_interval,
valid_coded_value_set: field_valid_coded_value_set,
normal_coded_value_set: field_normal_coded_value_set,
abnormal_coded_value_set: field_abnormal_coded_value_set,
critical_coded_value_set: field_critical_coded_value_set,
})
}
}
impl serde::Serialize for ObservationDefinition {
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.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(item) = &self.multiple_results_allowed {
super::super::codec::element_entry(&mut map, "_multipleResultsAllowed", item)?;
}
super::super::codec::element_list_entry(
&mut map,
"_permittedDataType",
&self.permitted_data_type,
)?;
if let Some(item) = &self.preferred_report_name {
super::super::codec::element_entry(&mut map, "_preferredReportName", item)?;
}
if let Some(item) = &self.abnormal_coded_value_set {
serde::ser::SerializeMap::serialize_entry(&mut map, "abnormalCodedValueSet", item)?;
}
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.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.critical_coded_value_set {
serde::ser::SerializeMap::serialize_entry(&mut map, "criticalCodedValueSet", 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.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 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 let Some(item) = &self.multiple_results_allowed {
super::super::codec::value_entry(&mut map, "multipleResultsAllowed", item)?;
}
if let Some(item) = &self.normal_coded_value_set {
serde::ser::SerializeMap::serialize_entry(&mut map, "normalCodedValueSet", item)?;
}
super::super::codec::value_list_entry(
&mut map,
"permittedDataType",
&self.permitted_data_type,
)?;
if let Some(item) = &self.preferred_report_name {
super::super::codec::value_entry(&mut map, "preferredReportName", item)?;
}
if !self.qualified_interval.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"qualifiedInterval",
&self.qualified_interval,
)?;
}
if let Some(item) = &self.quantitative_details {
serde::ser::SerializeMap::serialize_entry(&mut map, "quantitativeDetails", item)?;
}
serde::ser::SerializeMap::serialize_entry(
&mut map,
"resourceType",
"ObservationDefinition",
)?;
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.valid_coded_value_set {
serde::ser::SerializeMap::serialize_entry(&mut map, "validCodedValueSet", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ObservationDefinition {
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("ObservationDefinition");
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 ObservationDefinitionQualifiedInterval {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub category: Option<super::primitives::Code>,
pub range: Option<super::range::Range>,
pub context: Option<super::codeable_concept::CodeableConcept>,
pub applies_to: Vec<super::codeable_concept::CodeableConcept>,
pub gender: Option<super::primitives::Code>,
pub age: Option<super::range::Range>,
pub gestational_age: Option<super::range::Range>,
pub condition: Option<super::primitives::String>,
}
impl super::super::codec::Json for ObservationDefinitionQualifiedInterval {
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.category {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("category"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_category"), e);
}
}
if let Some(item) = &self.range {
object.insert(
std::string::String::from("range"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.context {
object.insert(
std::string::String::from("context"),
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.gender {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("gender"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_gender"), e);
}
}
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.gestational_age {
object.insert(
std::string::String::from("gestationalAge"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.condition {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("condition"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_condition"), 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_category: Option<&super::super::codec::Value> = None;
let mut raw_category_element: Option<&super::super::codec::Value> = None;
let mut raw_range: Option<&super::super::codec::Value> = None;
let mut raw_context: Option<&super::super::codec::Value> = None;
let mut raw_applies_to: Option<&super::super::codec::Value> = None;
let mut raw_gender: Option<&super::super::codec::Value> = None;
let mut raw_gender_element: Option<&super::super::codec::Value> = None;
let mut raw_age: Option<&super::super::codec::Value> = None;
let mut raw_gestational_age: Option<&super::super::codec::Value> = None;
let mut raw_condition: Option<&super::super::codec::Value> = None;
let mut raw_condition_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);
}
"category" => {
raw_category = Some(value);
}
"_category" => {
raw_category_element = Some(value);
}
"range" => {
raw_range = Some(value);
}
"context" => {
raw_context = Some(value);
}
"appliesTo" => {
raw_applies_to = Some(value);
}
"gender" => {
raw_gender = Some(value);
}
"_gender" => {
raw_gender_element = Some(value);
}
"age" => {
raw_age = Some(value);
}
"gestationalAge" => {
raw_gestational_age = Some(value);
}
"condition" => {
raw_condition = Some(value);
}
"_condition" => {
raw_condition_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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in 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 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_category = match (raw_category, raw_category_element) {
(None, None) => None,
(value, element) => Some(path.with("category", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_range = raw_range
.map(|value| {
path.with("range", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_context = raw_context
.map(|value| {
path.with("context", |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 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_gender = match (raw_gender, raw_gender_element) {
(None, None) => None,
(value, element) => Some(path.with("gender", |path| {
super::super::codec::Primitive::from_json_parts(value, element, 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_gestational_age = raw_gestational_age
.map(|value| {
path.with("gestationalAge", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_condition = match (raw_condition, raw_condition_element) {
(None, None) => None,
(value, element) => Some(path.with("condition", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
category: field_category,
range: field_range,
context: field_context,
applies_to: field_applies_to,
gender: field_gender,
age: field_age,
gestational_age: field_gestational_age,
condition: field_condition,
})
}
}
impl serde::Serialize for ObservationDefinitionQualifiedInterval {
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.category {
super::super::codec::element_entry(&mut map, "_category", item)?;
}
if let Some(item) = &self.condition {
super::super::codec::element_entry(&mut map, "_condition", item)?;
}
if let Some(item) = &self.gender {
super::super::codec::element_entry(&mut map, "_gender", 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 let Some(item) = &self.category {
super::super::codec::value_entry(&mut map, "category", item)?;
}
if let Some(item) = &self.condition {
super::super::codec::value_entry(&mut map, "condition", item)?;
}
if let Some(item) = &self.context {
serde::ser::SerializeMap::serialize_entry(&mut map, "context", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.gender {
super::super::codec::value_entry(&mut map, "gender", item)?;
}
if let Some(item) = &self.gestational_age {
serde::ser::SerializeMap::serialize_entry(&mut map, "gestationalAge", item)?;
}
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,
)?;
}
if let Some(item) = &self.range {
serde::ser::SerializeMap::serialize_entry(&mut map, "range", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ObservationDefinitionQualifiedInterval {
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("ObservationDefinitionQualifiedInterval");
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 ObservationDefinitionQuantitativeDetails {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub customary_unit: Option<super::codeable_concept::CodeableConcept>,
pub unit: Option<super::codeable_concept::CodeableConcept>,
pub conversion_factor: Option<super::primitives::Decimal>,
pub decimal_precision: Option<super::primitives::Integer>,
}
impl super::super::codec::Json for ObservationDefinitionQuantitativeDetails {
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.customary_unit {
object.insert(
std::string::String::from("customaryUnit"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.unit {
object.insert(
std::string::String::from("unit"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.conversion_factor {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("conversionFactor"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_conversionFactor"), e);
}
}
if let Some(item) = &self.decimal_precision {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("decimalPrecision"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_decimalPrecision"), 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_customary_unit: Option<&super::super::codec::Value> = None;
let mut raw_unit: Option<&super::super::codec::Value> = None;
let mut raw_conversion_factor: Option<&super::super::codec::Value> = None;
let mut raw_conversion_factor_element: Option<&super::super::codec::Value> = None;
let mut raw_decimal_precision: Option<&super::super::codec::Value> = None;
let mut raw_decimal_precision_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);
}
"customaryUnit" => {
raw_customary_unit = Some(value);
}
"unit" => {
raw_unit = Some(value);
}
"conversionFactor" => {
raw_conversion_factor = Some(value);
}
"_conversionFactor" => {
raw_conversion_factor_element = Some(value);
}
"decimalPrecision" => {
raw_decimal_precision = Some(value);
}
"_decimalPrecision" => {
raw_decimal_precision_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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in 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 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_customary_unit = raw_customary_unit
.map(|value| {
path.with("customaryUnit", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_unit = raw_unit
.map(|value| {
path.with("unit", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_conversion_factor = match (raw_conversion_factor, raw_conversion_factor_element) {
(None, None) => None,
(value, element) => Some(path.with("conversionFactor", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_decimal_precision = match (raw_decimal_precision, raw_decimal_precision_element) {
(None, None) => None,
(value, element) => Some(path.with("decimalPrecision", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
customary_unit: field_customary_unit,
unit: field_unit,
conversion_factor: field_conversion_factor,
decimal_precision: field_decimal_precision,
})
}
}
impl serde::Serialize for ObservationDefinitionQuantitativeDetails {
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.conversion_factor {
super::super::codec::element_entry(&mut map, "_conversionFactor", item)?;
}
if let Some(item) = &self.decimal_precision {
super::super::codec::element_entry(&mut map, "_decimalPrecision", item)?;
}
if let Some(item) = &self.conversion_factor {
super::super::codec::value_entry(&mut map, "conversionFactor", item)?;
}
if let Some(item) = &self.customary_unit {
serde::ser::SerializeMap::serialize_entry(&mut map, "customaryUnit", item)?;
}
if let Some(item) = &self.decimal_precision {
super::super::codec::value_entry(&mut map, "decimalPrecision", 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.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.unit {
serde::ser::SerializeMap::serialize_entry(&mut map, "unit", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ObservationDefinitionQuantitativeDetails {
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("ObservationDefinitionQuantitativeDetails");
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)
}
}