#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct BodyStructure {
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 active: Option<super::primitives::Boolean>,
pub morphology: Option<super::codeable_concept::CodeableConcept>,
pub included_structure: Vec<BodyStructureIncludedStructure>,
pub excluded_structure: Vec<BodyStructureIncludedStructure>,
pub description: Option<super::primitives::Markdown>,
pub image: Vec<super::attachment::Attachment>,
pub patient: super::reference::Reference,
}
impl super::super::codec::Json for BodyStructure {
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("BodyStructure")),
);
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 let Some(item) = &self.active {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("active"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_active"), e);
}
}
if let Some(item) = &self.morphology {
object.insert(
std::string::String::from("morphology"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.included_structure.is_empty() {
let mut items = Vec::with_capacity(self.included_structure.len());
for item in &self.included_structure {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("includedStructure"),
super::super::codec::Value::Array(items),
);
}
if !self.excluded_structure.is_empty() {
let mut items = Vec::with_capacity(self.excluded_structure.len());
for item in &self.excluded_structure {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("excludedStructure"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
if !self.image.is_empty() {
let mut items = Vec::with_capacity(self.image.len());
for item in &self.image {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("image"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("patient"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.patient)?),
);
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_active: Option<&super::super::codec::Value> = None;
let mut raw_active_element: Option<&super::super::codec::Value> = None;
let mut raw_morphology: Option<&super::super::codec::Value> = None;
let mut raw_included_structure: Option<&super::super::codec::Value> = None;
let mut raw_excluded_structure: Option<&super::super::codec::Value> = None;
let mut raw_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
let mut raw_image: Option<&super::super::codec::Value> = None;
let mut raw_patient: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("BodyStructure") {
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);
}
"active" => {
raw_active = Some(value);
}
"_active" => {
raw_active_element = Some(value);
}
"morphology" => {
raw_morphology = Some(value);
}
"includedStructure" => {
raw_included_structure = Some(value);
}
"excludedStructure" => {
raw_excluded_structure = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"image" => {
raw_image = Some(value);
}
"patient" => {
raw_patient = 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 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_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 field_active = match (raw_active, raw_active_element) {
(None, None) => None,
(value, element) => Some(path.with("active", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_morphology = raw_morphology
.map(|value| {
path.with("morphology", |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_included_structure = Vec::new();
if let Some(raw) = raw_included_structure {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_included_structure.push(path.with_index(
"includedStructure",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_excluded_structure = Vec::new();
if let Some(raw) = raw_excluded_structure {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_excluded_structure.push(path.with_index(
"excludedStructure",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_image = Vec::new();
if let Some(raw) = raw_image {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_image.push(path.with_index("image", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_patient = path.with("patient", |path| {
let value = raw_patient
.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,
)
})?;
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,
active: field_active,
morphology: field_morphology,
included_structure: field_included_structure,
excluded_structure: field_excluded_structure,
description: field_description,
image: field_image,
patient: field_patient,
})
}
}
impl serde::Serialize for BodyStructure {
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.active {
super::super::codec::element_entry(&mut map, "_active", item)?;
}
if let Some(item) = &self.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
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.active {
super::super::codec::value_entry(&mut map, "active", item)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if !self.excluded_structure.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"excludedStructure",
&self.excluded_structure,
)?;
}
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 !self.image.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "image", &self.image)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if !self.included_structure.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"includedStructure",
&self.included_structure,
)?;
}
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 !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.morphology {
serde::ser::SerializeMap::serialize_entry(&mut map, "morphology", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "patient", &self.patient)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "BodyStructure")?;
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for BodyStructure {
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("BodyStructure");
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 BodyStructureIncludedStructure {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub structure: super::codeable_concept::CodeableConcept,
pub laterality: Option<super::codeable_concept::CodeableConcept>,
pub body_landmark_orientation: Vec<BodyStructureIncludedStructureBodyLandmarkOrientation>,
pub spatial_reference: Vec<super::reference::Reference>,
pub qualifier: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for BodyStructureIncludedStructure {
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("structure"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.structure,
)?),
);
if let Some(item) = &self.laterality {
object.insert(
std::string::String::from("laterality"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.body_landmark_orientation.is_empty() {
let mut items = Vec::with_capacity(self.body_landmark_orientation.len());
for item in &self.body_landmark_orientation {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("bodyLandmarkOrientation"),
super::super::codec::Value::Array(items),
);
}
if !self.spatial_reference.is_empty() {
let mut items = Vec::with_capacity(self.spatial_reference.len());
for item in &self.spatial_reference {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("spatialReference"),
super::super::codec::Value::Array(items),
);
}
if !self.qualifier.is_empty() {
let mut items = Vec::with_capacity(self.qualifier.len());
for item in &self.qualifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("qualifier"),
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_structure: Option<&super::super::codec::Value> = None;
let mut raw_laterality: Option<&super::super::codec::Value> = None;
let mut raw_body_landmark_orientation: Option<&super::super::codec::Value> = None;
let mut raw_spatial_reference: Option<&super::super::codec::Value> = None;
let mut raw_qualifier: 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);
}
"structure" => {
raw_structure = Some(value);
}
"laterality" => {
raw_laterality = Some(value);
}
"bodyLandmarkOrientation" => {
raw_body_landmark_orientation = Some(value);
}
"spatialReference" => {
raw_spatial_reference = Some(value);
}
"qualifier" => {
raw_qualifier = 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 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_structure = path.with("structure", |path| {
let value = raw_structure
.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_laterality = raw_laterality
.map(|value| {
path.with("laterality", |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_landmark_orientation = Vec::new();
if let Some(raw) = raw_body_landmark_orientation {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_body_landmark_orientation.push(path.with_index(
"bodyLandmarkOrientation",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_spatial_reference = Vec::new();
if let Some(raw) = raw_spatial_reference {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_spatial_reference.push(path.with_index(
"spatialReference",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_qualifier = Vec::new();
if let Some(raw) = raw_qualifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_qualifier.push(path.with_index("qualifier", 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,
structure: field_structure,
laterality: field_laterality,
body_landmark_orientation: field_body_landmark_orientation,
spatial_reference: field_spatial_reference,
qualifier: field_qualifier,
})
}
}
impl serde::Serialize for BodyStructureIncludedStructure {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.body_landmark_orientation.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"bodyLandmarkOrientation",
&self.body_landmark_orientation,
)?;
}
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 let Some(item) = &self.laterality {
serde::ser::SerializeMap::serialize_entry(&mut map, "laterality", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.qualifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "qualifier", &self.qualifier)?;
}
if !self.spatial_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"spatialReference",
&self.spatial_reference,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "structure", &self.structure)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for BodyStructureIncludedStructure {
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("BodyStructureIncludedStructure");
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 BodyStructureIncludedStructureBodyLandmarkOrientation {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub landmark_description: Vec<super::codeable_concept::CodeableConcept>,
pub clock_face_position: Vec<super::codeable_concept::CodeableConcept>,
pub distance_from_landmark:
Vec<BodyStructureIncludedStructureBodyLandmarkOrientationDistanceFromLandmark>,
pub surface_orientation: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for BodyStructureIncludedStructureBodyLandmarkOrientation {
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 !self.landmark_description.is_empty() {
let mut items = Vec::with_capacity(self.landmark_description.len());
for item in &self.landmark_description {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("landmarkDescription"),
super::super::codec::Value::Array(items),
);
}
if !self.clock_face_position.is_empty() {
let mut items = Vec::with_capacity(self.clock_face_position.len());
for item in &self.clock_face_position {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("clockFacePosition"),
super::super::codec::Value::Array(items),
);
}
if !self.distance_from_landmark.is_empty() {
let mut items = Vec::with_capacity(self.distance_from_landmark.len());
for item in &self.distance_from_landmark {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("distanceFromLandmark"),
super::super::codec::Value::Array(items),
);
}
if !self.surface_orientation.is_empty() {
let mut items = Vec::with_capacity(self.surface_orientation.len());
for item in &self.surface_orientation {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("surfaceOrientation"),
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_landmark_description: Option<&super::super::codec::Value> = None;
let mut raw_clock_face_position: Option<&super::super::codec::Value> = None;
let mut raw_distance_from_landmark: Option<&super::super::codec::Value> = None;
let mut raw_surface_orientation: 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);
}
"landmarkDescription" => {
raw_landmark_description = Some(value);
}
"clockFacePosition" => {
raw_clock_face_position = Some(value);
}
"distanceFromLandmark" => {
raw_distance_from_landmark = Some(value);
}
"surfaceOrientation" => {
raw_surface_orientation = 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 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_landmark_description = Vec::new();
if let Some(raw) = raw_landmark_description {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_landmark_description.push(path.with_index(
"landmarkDescription",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_clock_face_position = Vec::new();
if let Some(raw) = raw_clock_face_position {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_clock_face_position.push(path.with_index(
"clockFacePosition",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_distance_from_landmark = Vec::new();
if let Some(raw) = raw_distance_from_landmark {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_distance_from_landmark.push(path.with_index(
"distanceFromLandmark",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_surface_orientation = Vec::new();
if let Some(raw) = raw_surface_orientation {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_surface_orientation.push(path.with_index(
"surfaceOrientation",
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,
landmark_description: field_landmark_description,
clock_face_position: field_clock_face_position,
distance_from_landmark: field_distance_from_landmark,
surface_orientation: field_surface_orientation,
})
}
}
impl serde::Serialize for BodyStructureIncludedStructureBodyLandmarkOrientation {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.clock_face_position.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"clockFacePosition",
&self.clock_face_position,
)?;
}
if !self.distance_from_landmark.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"distanceFromLandmark",
&self.distance_from_landmark,
)?;
}
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.landmark_description.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"landmarkDescription",
&self.landmark_description,
)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.surface_orientation.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"surfaceOrientation",
&self.surface_orientation,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for BodyStructureIncludedStructureBodyLandmarkOrientation {
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(
"BodyStructureIncludedStructureBodyLandmarkOrientation",
);
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 BodyStructureIncludedStructureBodyLandmarkOrientationDistanceFromLandmark {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub device: Vec<super::codeable_reference::CodeableReference>,
pub value: Vec<super::quantity::Quantity>,
}
impl super::super::codec::Json
for BodyStructureIncludedStructureBodyLandmarkOrientationDistanceFromLandmark
{
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 !self.device.is_empty() {
let mut items = Vec::with_capacity(self.device.len());
for item in &self.device {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("device"),
super::super::codec::Value::Array(items),
);
}
if !self.value.is_empty() {
let mut items = Vec::with_capacity(self.value.len());
for item in &self.value {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("value"),
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_device: Option<&super::super::codec::Value> = None;
let mut raw_value: 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);
}
"device" => {
raw_device = Some(value);
}
"value" => {
raw_value = 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 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_device = Vec::new();
if let Some(raw) = raw_device {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_device.push(path.with_index("device", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_value = Vec::new();
if let Some(raw) = raw_value {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_value.push(path.with_index("value", 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,
device: field_device,
value: field_value,
})
}
}
impl serde::Serialize
for BodyStructureIncludedStructureBodyLandmarkOrientationDistanceFromLandmark
{
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.device.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "device", &self.device)?;
}
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 !self.value.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "value", &self.value)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de>
for BodyStructureIncludedStructureBodyLandmarkOrientationDistanceFromLandmark
{
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(
"BodyStructureIncludedStructureBodyLandmarkOrientationDistanceFromLandmark",
);
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)
}
}