#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SubstanceSpecification {
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: Option<super::identifier::Identifier>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub status: Option<super::codeable_concept::CodeableConcept>,
pub domain: Option<super::codeable_concept::CodeableConcept>,
pub description: Option<super::primitives::String>,
pub source: Vec<super::reference::Reference>,
pub comment: Option<super::primitives::String>,
pub moiety: Vec<SubstanceSpecificationMoiety>,
pub property: Vec<SubstanceSpecificationProperty>,
pub reference_information: Option<super::reference::Reference>,
pub structure: Option<SubstanceSpecificationStructure>,
pub code: Vec<SubstanceSpecificationCode>,
pub name: Vec<SubstanceSpecificationName>,
pub molecular_weight: Vec<SubstanceSpecificationStructureIsotopeMolecularWeight>,
pub relationship: Vec<SubstanceSpecificationRelationship>,
pub nucleic_acid: Option<super::reference::Reference>,
pub polymer: Option<super::reference::Reference>,
pub protein: Option<super::reference::Reference>,
pub source_material: Option<super::reference::Reference>,
}
impl super::super::codec::Json for SubstanceSpecification {
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("SubstanceSpecification")),
);
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 let Some(item) = &self.identifier {
object.insert(
std::string::String::from("identifier"),
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 let Some(item) = &self.status {
object.insert(
std::string::String::from("status"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.domain {
object.insert(
std::string::String::from("domain"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.source.is_empty() {
let mut items = Vec::with_capacity(self.source.len());
for item in &self.source {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("source"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.comment {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("comment"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_comment"), e);
}
}
if !self.moiety.is_empty() {
let mut items = Vec::with_capacity(self.moiety.len());
for item in &self.moiety {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("moiety"),
super::super::codec::Value::Array(items),
);
}
if !self.property.is_empty() {
let mut items = Vec::with_capacity(self.property.len());
for item in &self.property {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("property"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.reference_information {
object.insert(
std::string::String::from("referenceInformation"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.structure {
object.insert(
std::string::String::from("structure"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.code.is_empty() {
let mut items = Vec::with_capacity(self.code.len());
for item in &self.code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Array(items),
);
}
if !self.name.is_empty() {
let mut items = Vec::with_capacity(self.name.len());
for item in &self.name {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("name"),
super::super::codec::Value::Array(items),
);
}
if !self.molecular_weight.is_empty() {
let mut items = Vec::with_capacity(self.molecular_weight.len());
for item in &self.molecular_weight {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("molecularWeight"),
super::super::codec::Value::Array(items),
);
}
if !self.relationship.is_empty() {
let mut items = Vec::with_capacity(self.relationship.len());
for item in &self.relationship {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("relationship"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.nucleic_acid {
object.insert(
std::string::String::from("nucleicAcid"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.polymer {
object.insert(
std::string::String::from("polymer"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.protein {
object.insert(
std::string::String::from("protein"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.source_material {
object.insert(
std::string::String::from("sourceMaterial"),
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_identifier: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_status: Option<&super::super::codec::Value> = None;
let mut raw_domain: 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_source: Option<&super::super::codec::Value> = None;
let mut raw_comment: Option<&super::super::codec::Value> = None;
let mut raw_comment_element: Option<&super::super::codec::Value> = None;
let mut raw_moiety: Option<&super::super::codec::Value> = None;
let mut raw_property: Option<&super::super::codec::Value> = None;
let mut raw_reference_information: Option<&super::super::codec::Value> = None;
let mut raw_structure: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_name: Option<&super::super::codec::Value> = None;
let mut raw_molecular_weight: Option<&super::super::codec::Value> = None;
let mut raw_relationship: Option<&super::super::codec::Value> = None;
let mut raw_nucleic_acid: Option<&super::super::codec::Value> = None;
let mut raw_polymer: Option<&super::super::codec::Value> = None;
let mut raw_protein: Option<&super::super::codec::Value> = None;
let mut raw_source_material: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("SubstanceSpecification") {
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);
}
"type" => {
raw_type = Some(value);
}
"status" => {
raw_status = Some(value);
}
"domain" => {
raw_domain = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"source" => {
raw_source = Some(value);
}
"comment" => {
raw_comment = Some(value);
}
"_comment" => {
raw_comment_element = Some(value);
}
"moiety" => {
raw_moiety = Some(value);
}
"property" => {
raw_property = Some(value);
}
"referenceInformation" => {
raw_reference_information = Some(value);
}
"structure" => {
raw_structure = Some(value);
}
"code" => {
raw_code = Some(value);
}
"name" => {
raw_name = Some(value);
}
"molecularWeight" => {
raw_molecular_weight = Some(value);
}
"relationship" => {
raw_relationship = Some(value);
}
"nucleicAcid" => {
raw_nucleic_acid = Some(value);
}
"polymer" => {
raw_polymer = Some(value);
}
"protein" => {
raw_protein = Some(value);
}
"sourceMaterial" => {
raw_source_material = 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 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 field_identifier = raw_identifier
.map(|value| {
path.with("identifier", |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 field_status = raw_status
.map(|value| {
path.with("status", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_domain = raw_domain
.map(|value| {
path.with("domain", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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_source = Vec::new();
if let Some(raw) = raw_source {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_source.push(path.with_index("source", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_comment = match (raw_comment, raw_comment_element) {
(None, None) => None,
(value, element) => Some(path.with("comment", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_moiety = Vec::new();
if let Some(raw) = raw_moiety {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_moiety.push(path.with_index("moiety", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_property = Vec::new();
if let Some(raw) = raw_property {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_property.push(path.with_index("property", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_reference_information = raw_reference_information
.map(|value| {
path.with("referenceInformation", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_structure = raw_structure
.map(|value| {
path.with("structure", |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_code = Vec::new();
if let Some(raw) = raw_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_code.push(path.with_index("code", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_name = Vec::new();
if let Some(raw) = raw_name {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_name.push(path.with_index("name", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_molecular_weight = Vec::new();
if let Some(raw) = raw_molecular_weight {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_molecular_weight.push(path.with_index("molecularWeight", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_relationship = Vec::new();
if let Some(raw) = raw_relationship {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_relationship.push(path.with_index("relationship", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_nucleic_acid = raw_nucleic_acid
.map(|value| {
path.with("nucleicAcid", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_polymer = raw_polymer
.map(|value| {
path.with("polymer", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_protein = raw_protein
.map(|value| {
path.with("protein", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_source_material = raw_source_material
.map(|value| {
path.with("sourceMaterial", |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,
identifier: field_identifier,
r#type: field_type,
status: field_status,
domain: field_domain,
description: field_description,
source: field_source,
comment: field_comment,
moiety: field_moiety,
property: field_property,
reference_information: field_reference_information,
structure: field_structure,
code: field_code,
name: field_name,
molecular_weight: field_molecular_weight,
relationship: field_relationship,
nucleic_acid: field_nucleic_acid,
polymer: field_polymer,
protein: field_protein,
source_material: field_source_material,
})
}
}
impl serde::Serialize for SubstanceSpecification {
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.comment {
super::super::codec::element_entry(&mut map, "_comment", 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 !self.code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
}
if let Some(item) = &self.comment {
super::super::codec::value_entry(&mut map, "comment", 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 let Some(item) = &self.domain {
serde::ser::SerializeMap::serialize_entry(&mut map, "domain", 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 let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
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 !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.moiety.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "moiety", &self.moiety)?;
}
if !self.molecular_weight.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"molecularWeight",
&self.molecular_weight,
)?;
}
if !self.name.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "name", &self.name)?;
}
if let Some(item) = &self.nucleic_acid {
serde::ser::SerializeMap::serialize_entry(&mut map, "nucleicAcid", item)?;
}
if let Some(item) = &self.polymer {
serde::ser::SerializeMap::serialize_entry(&mut map, "polymer", item)?;
}
if !self.property.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "property", &self.property)?;
}
if let Some(item) = &self.protein {
serde::ser::SerializeMap::serialize_entry(&mut map, "protein", item)?;
}
if let Some(item) = &self.reference_information {
serde::ser::SerializeMap::serialize_entry(&mut map, "referenceInformation", item)?;
}
if !self.relationship.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"relationship",
&self.relationship,
)?;
}
serde::ser::SerializeMap::serialize_entry(
&mut map,
"resourceType",
"SubstanceSpecification",
)?;
if !self.source.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "source", &self.source)?;
}
if let Some(item) = &self.source_material {
serde::ser::SerializeMap::serialize_entry(&mut map, "sourceMaterial", item)?;
}
if let Some(item) = &self.status {
serde::ser::SerializeMap::serialize_entry(&mut map, "status", item)?;
}
if let Some(item) = &self.structure {
serde::ser::SerializeMap::serialize_entry(&mut map, "structure", item)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_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 SubstanceSpecification {
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("SubstanceSpecification");
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 SubstanceSpecificationCode {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub status: Option<super::codeable_concept::CodeableConcept>,
pub status_date: Option<super::primitives::DateTime>,
pub comment: Option<super::primitives::String>,
pub source: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for SubstanceSpecificationCode {
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.code {
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.status {
object.insert(
std::string::String::from("status"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.status_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("statusDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_statusDate"), e);
}
}
if let Some(item) = &self.comment {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("comment"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_comment"), e);
}
}
if !self.source.is_empty() {
let mut items = Vec::with_capacity(self.source.len());
for item in &self.source {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("source"),
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_status: Option<&super::super::codec::Value> = None;
let mut raw_status_date: Option<&super::super::codec::Value> = None;
let mut raw_status_date_element: Option<&super::super::codec::Value> = None;
let mut raw_comment: Option<&super::super::codec::Value> = None;
let mut raw_comment_element: Option<&super::super::codec::Value> = None;
let mut raw_source: 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);
}
"status" => {
raw_status = Some(value);
}
"statusDate" => {
raw_status_date = Some(value);
}
"_statusDate" => {
raw_status_date_element = Some(value);
}
"comment" => {
raw_comment = Some(value);
}
"_comment" => {
raw_comment_element = Some(value);
}
"source" => {
raw_source = 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_code = raw_code
.map(|value| {
path.with("code", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_status = raw_status
.map(|value| {
path.with("status", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_status_date = match (raw_status_date, raw_status_date_element) {
(None, None) => None,
(value, element) => Some(path.with("statusDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_comment = match (raw_comment, raw_comment_element) {
(None, None) => None,
(value, element) => Some(path.with("comment", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_source = Vec::new();
if let Some(raw) = raw_source {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_source.push(path.with_index("source", 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,
status: field_status,
status_date: field_status_date,
comment: field_comment,
source: field_source,
})
}
}
impl serde::Serialize for SubstanceSpecificationCode {
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.comment {
super::super::codec::element_entry(&mut map, "_comment", item)?;
}
if let Some(item) = &self.status_date {
super::super::codec::element_entry(&mut map, "_statusDate", item)?;
}
if let Some(item) = &self.code {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", item)?;
}
if let Some(item) = &self.comment {
super::super::codec::value_entry(&mut map, "comment", 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 !self.source.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "source", &self.source)?;
}
if let Some(item) = &self.status {
serde::ser::SerializeMap::serialize_entry(&mut map, "status", item)?;
}
if let Some(item) = &self.status_date {
super::super::codec::value_entry(&mut map, "statusDate", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceSpecificationCode {
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("SubstanceSpecificationCode");
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 SubstanceSpecificationMoiety {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub role: Option<super::codeable_concept::CodeableConcept>,
pub identifier: Option<super::identifier::Identifier>,
pub name: Option<super::primitives::String>,
pub stereochemistry: Option<super::codeable_concept::CodeableConcept>,
pub optical_activity: Option<super::codeable_concept::CodeableConcept>,
pub molecular_formula: Option<super::primitives::String>,
pub amount: Option<SubstanceSpecificationMoietyAmount>,
}
impl super::super::codec::Json for SubstanceSpecificationMoiety {
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.role {
object.insert(
std::string::String::from("role"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.identifier {
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.name {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_name"), e);
}
}
if let Some(item) = &self.stereochemistry {
object.insert(
std::string::String::from("stereochemistry"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.optical_activity {
object.insert(
std::string::String::from("opticalActivity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.molecular_formula {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("molecularFormula"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_molecularFormula"), e);
}
}
if let Some(item) = &self.amount {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("amount{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_amount{suffix}"), element);
}
}
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_role: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: Option<&super::super::codec::Value> = None;
let mut raw_stereochemistry: Option<&super::super::codec::Value> = None;
let mut raw_optical_activity: Option<&super::super::codec::Value> = None;
let mut raw_molecular_formula: Option<&super::super::codec::Value> = None;
let mut raw_molecular_formula_element: Option<&super::super::codec::Value> = None;
let mut raw_amount = super::super::codec::ChoiceSlot::default();
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);
}
"role" => {
raw_role = Some(value);
}
"identifier" => {
raw_identifier = Some(value);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"stereochemistry" => {
raw_stereochemistry = Some(value);
}
"opticalActivity" => {
raw_optical_activity = Some(value);
}
"molecularFormula" => {
raw_molecular_formula = Some(value);
}
"_molecularFormula" => {
raw_molecular_formula_element = Some(value);
}
"amountQuantity" => {
raw_amount.value("Quantity", value, path)?;
}
"_amountQuantity" => {
raw_amount.element("Quantity", value, path)?;
}
"amountString" => {
raw_amount.value("String", value, path)?;
}
"_amountString" => {
raw_amount.element("String", value, path)?;
}
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_role = raw_role
.map(|value| {
path.with("role", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_identifier = raw_identifier
.map(|value| {
path.with("identifier", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_name = match (raw_name, raw_name_element) {
(None, None) => None,
(value, element) => Some(path.with("name", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_stereochemistry = raw_stereochemistry
.map(|value| {
path.with("stereochemistry", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_optical_activity = raw_optical_activity
.map(|value| {
path.with("opticalActivity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_molecular_formula = match (raw_molecular_formula, raw_molecular_formula_element) {
(None, None) => None,
(value, element) => Some(path.with("molecularFormula", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_amount = match raw_amount.suffix {
None => None,
Some(suffix) => Some(path.with("amount", |path| {
SubstanceSpecificationMoietyAmount::from_json_parts(
suffix,
raw_amount.value,
raw_amount.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
role: field_role,
identifier: field_identifier,
name: field_name,
stereochemistry: field_stereochemistry,
optical_activity: field_optical_activity,
molecular_formula: field_molecular_formula,
amount: field_amount,
})
}
}
impl serde::Serialize for SubstanceSpecificationMoiety {
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(SubstanceSpecificationMoietyAmount::String(inner)) = &self.amount {
super::super::codec::element_entry(&mut map, "_amountString", inner)?;
}
if let Some(item) = &self.molecular_formula {
super::super::codec::element_entry(&mut map, "_molecularFormula", item)?;
}
if let Some(item) = &self.name {
super::super::codec::element_entry(&mut map, "_name", item)?;
}
match &self.amount {
Some(SubstanceSpecificationMoietyAmount::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"amountQuantity",
inner.as_ref(),
)?;
}
Some(SubstanceSpecificationMoietyAmount::String(inner)) => {
super::super::codec::value_entry(&mut map, "amountString", inner)?;
}
None => {}
}
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.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.molecular_formula {
super::super::codec::value_entry(&mut map, "molecularFormula", item)?;
}
if let Some(item) = &self.name {
super::super::codec::value_entry(&mut map, "name", item)?;
}
if let Some(item) = &self.optical_activity {
serde::ser::SerializeMap::serialize_entry(&mut map, "opticalActivity", item)?;
}
if let Some(item) = &self.role {
serde::ser::SerializeMap::serialize_entry(&mut map, "role", item)?;
}
if let Some(item) = &self.stereochemistry {
serde::ser::SerializeMap::serialize_entry(&mut map, "stereochemistry", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceSpecificationMoiety {
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("SubstanceSpecificationMoiety");
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 SubstanceSpecificationMoietyAmount {
Quantity(Box<super::quantity::Quantity>),
String(super::primitives::String),
}
impl SubstanceSpecificationMoietyAmount {
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::String(inner) => Ok((
"String",
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 {
"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)))
}
"String" => Ok(Self::String(
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 SubstanceSpecificationName {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub name: super::primitives::String,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub status: Option<super::codeable_concept::CodeableConcept>,
pub preferred: Option<super::primitives::Boolean>,
pub language: Vec<super::codeable_concept::CodeableConcept>,
pub domain: Vec<super::codeable_concept::CodeableConcept>,
pub jurisdiction: Vec<super::codeable_concept::CodeableConcept>,
pub synonym: Vec<SubstanceSpecificationName>,
pub translation: Vec<SubstanceSpecificationName>,
pub official: Vec<SubstanceSpecificationNameOfficial>,
pub source: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for SubstanceSpecificationName {
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(v) = super::super::codec::Primitive::value_json(&self.name)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.name)? {
object.insert(std::string::String::from("_name"), e);
}
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 let Some(item) = &self.status {
object.insert(
std::string::String::from("status"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.preferred {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("preferred"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_preferred"), e);
}
}
if !self.language.is_empty() {
let mut items = Vec::with_capacity(self.language.len());
for item in &self.language {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("language"),
super::super::codec::Value::Array(items),
);
}
if !self.domain.is_empty() {
let mut items = Vec::with_capacity(self.domain.len());
for item in &self.domain {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("domain"),
super::super::codec::Value::Array(items),
);
}
if !self.jurisdiction.is_empty() {
let mut items = Vec::with_capacity(self.jurisdiction.len());
for item in &self.jurisdiction {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("jurisdiction"),
super::super::codec::Value::Array(items),
);
}
if !self.synonym.is_empty() {
let mut items = Vec::with_capacity(self.synonym.len());
for item in &self.synonym {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("synonym"),
super::super::codec::Value::Array(items),
);
}
if !self.translation.is_empty() {
let mut items = Vec::with_capacity(self.translation.len());
for item in &self.translation {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("translation"),
super::super::codec::Value::Array(items),
);
}
if !self.official.is_empty() {
let mut items = Vec::with_capacity(self.official.len());
for item in &self.official {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("official"),
super::super::codec::Value::Array(items),
);
}
if !self.source.is_empty() {
let mut items = Vec::with_capacity(self.source.len());
for item in &self.source {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("source"),
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_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_status: Option<&super::super::codec::Value> = None;
let mut raw_preferred: Option<&super::super::codec::Value> = None;
let mut raw_preferred_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_domain: Option<&super::super::codec::Value> = None;
let mut raw_jurisdiction: Option<&super::super::codec::Value> = None;
let mut raw_synonym: Option<&super::super::codec::Value> = None;
let mut raw_translation: Option<&super::super::codec::Value> = None;
let mut raw_official: Option<&super::super::codec::Value> = None;
let mut raw_source: 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);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"type" => {
raw_type = Some(value);
}
"status" => {
raw_status = Some(value);
}
"preferred" => {
raw_preferred = Some(value);
}
"_preferred" => {
raw_preferred_element = Some(value);
}
"language" => {
raw_language = Some(value);
}
"domain" => {
raw_domain = Some(value);
}
"jurisdiction" => {
raw_jurisdiction = Some(value);
}
"synonym" => {
raw_synonym = Some(value);
}
"translation" => {
raw_translation = Some(value);
}
"official" => {
raw_official = Some(value);
}
"source" => {
raw_source = 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_name = path.with("name", |path| {
super::super::codec::Primitive::from_json_parts(raw_name, raw_name_element, path)
})?;
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 field_status = raw_status
.map(|value| {
path.with("status", |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 = match (raw_preferred, raw_preferred_element) {
(None, None) => None,
(value, element) => Some(path.with("preferred", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_language = Vec::new();
if let Some(raw) = raw_language {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_language.push(path.with_index("language", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_domain = Vec::new();
if let Some(raw) = raw_domain {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_domain.push(path.with_index("domain", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_jurisdiction = Vec::new();
if let Some(raw) = raw_jurisdiction {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_jurisdiction.push(path.with_index("jurisdiction", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_synonym = Vec::new();
if let Some(raw) = raw_synonym {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_synonym.push(path.with_index("synonym", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_translation = Vec::new();
if let Some(raw) = raw_translation {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_translation.push(path.with_index("translation", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_official = Vec::new();
if let Some(raw) = raw_official {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_official.push(path.with_index("official", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_source = Vec::new();
if let Some(raw) = raw_source {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_source.push(path.with_index("source", 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,
name: field_name,
r#type: field_type,
status: field_status,
preferred: field_preferred,
language: field_language,
domain: field_domain,
jurisdiction: field_jurisdiction,
synonym: field_synonym,
translation: field_translation,
official: field_official,
source: field_source,
})
}
}
impl serde::Serialize for SubstanceSpecificationName {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_name", &self.name)?;
if let Some(item) = &self.preferred {
super::super::codec::element_entry(&mut map, "_preferred", item)?;
}
if !self.domain.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "domain", &self.domain)?;
}
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.jurisdiction.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"jurisdiction",
&self.jurisdiction,
)?;
}
if !self.language.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "language", &self.language)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
super::super::codec::value_entry(&mut map, "name", &self.name)?;
if !self.official.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "official", &self.official)?;
}
if let Some(item) = &self.preferred {
super::super::codec::value_entry(&mut map, "preferred", item)?;
}
if !self.source.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "source", &self.source)?;
}
if let Some(item) = &self.status {
serde::ser::SerializeMap::serialize_entry(&mut map, "status", item)?;
}
if !self.synonym.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "synonym", &self.synonym)?;
}
if !self.translation.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "translation", &self.translation)?;
}
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 SubstanceSpecificationName {
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("SubstanceSpecificationName");
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 SubstanceSpecificationNameOfficial {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub authority: Option<super::codeable_concept::CodeableConcept>,
pub status: Option<super::codeable_concept::CodeableConcept>,
pub date: Option<super::primitives::DateTime>,
}
impl super::super::codec::Json for SubstanceSpecificationNameOfficial {
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.authority {
object.insert(
std::string::String::from("authority"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.status {
object.insert(
std::string::String::from("status"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("date"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_date"), 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_authority: Option<&super::super::codec::Value> = None;
let mut raw_status: Option<&super::super::codec::Value> = None;
let mut raw_date: Option<&super::super::codec::Value> = None;
let mut raw_date_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);
}
"authority" => {
raw_authority = Some(value);
}
"status" => {
raw_status = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_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 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_authority = raw_authority
.map(|value| {
path.with("authority", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_status = raw_status
.map(|value| {
path.with("status", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_date = match (raw_date, raw_date_element) {
(None, None) => None,
(value, element) => Some(path.with("date", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
authority: field_authority,
status: field_status,
date: field_date,
})
}
}
impl serde::Serialize for SubstanceSpecificationNameOfficial {
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.date {
super::super::codec::element_entry(&mut map, "_date", item)?;
}
if let Some(item) = &self.authority {
serde::ser::SerializeMap::serialize_entry(&mut map, "authority", item)?;
}
if let Some(item) = &self.date {
super::super::codec::value_entry(&mut map, "date", 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.status {
serde::ser::SerializeMap::serialize_entry(&mut map, "status", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceSpecificationNameOfficial {
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("SubstanceSpecificationNameOfficial");
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 SubstanceSpecificationProperty {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub parameters: Option<super::primitives::String>,
pub defining_substance: Option<SubstanceSpecificationPropertyDefiningSubstance>,
pub amount: Option<SubstanceSpecificationPropertyAmount>,
}
impl super::super::codec::Json for SubstanceSpecificationProperty {
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 {
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.code {
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.parameters {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("parameters"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_parameters"), e);
}
}
if let Some(item) = &self.defining_substance {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("definingSubstance{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_definingSubstance{suffix}"), element);
}
}
if let Some(item) = &self.amount {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("amount{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_amount{suffix}"), element);
}
}
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_code: Option<&super::super::codec::Value> = None;
let mut raw_parameters: Option<&super::super::codec::Value> = None;
let mut raw_parameters_element: Option<&super::super::codec::Value> = None;
let mut raw_defining_substance = super::super::codec::ChoiceSlot::default();
let mut raw_amount = super::super::codec::ChoiceSlot::default();
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);
}
"code" => {
raw_code = Some(value);
}
"parameters" => {
raw_parameters = Some(value);
}
"_parameters" => {
raw_parameters_element = Some(value);
}
"definingSubstanceReference" => {
raw_defining_substance.value("Reference", value, path)?;
}
"_definingSubstanceReference" => {
raw_defining_substance.element("Reference", value, path)?;
}
"definingSubstanceCodeableConcept" => {
raw_defining_substance.value("CodeableConcept", value, path)?;
}
"_definingSubstanceCodeableConcept" => {
raw_defining_substance.element("CodeableConcept", value, path)?;
}
"amountQuantity" => {
raw_amount.value("Quantity", value, path)?;
}
"_amountQuantity" => {
raw_amount.element("Quantity", value, path)?;
}
"amountString" => {
raw_amount.value("String", value, path)?;
}
"_amountString" => {
raw_amount.element("String", value, path)?;
}
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_category = raw_category
.map(|value| {
path.with("category", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_code = raw_code
.map(|value| {
path.with("code", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_parameters = match (raw_parameters, raw_parameters_element) {
(None, None) => None,
(value, element) => Some(path.with("parameters", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_defining_substance = match raw_defining_substance.suffix {
None => None,
Some(suffix) => Some(path.with("definingSubstance", |path| {
SubstanceSpecificationPropertyDefiningSubstance::from_json_parts(
suffix,
raw_defining_substance.value,
raw_defining_substance.element,
path,
)
})?),
};
let field_amount = match raw_amount.suffix {
None => None,
Some(suffix) => Some(path.with("amount", |path| {
SubstanceSpecificationPropertyAmount::from_json_parts(
suffix,
raw_amount.value,
raw_amount.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
category: field_category,
code: field_code,
parameters: field_parameters,
defining_substance: field_defining_substance,
amount: field_amount,
})
}
}
impl serde::Serialize for SubstanceSpecificationProperty {
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(SubstanceSpecificationPropertyAmount::String(inner)) = &self.amount {
super::super::codec::element_entry(&mut map, "_amountString", inner)?;
}
if let Some(item) = &self.parameters {
super::super::codec::element_entry(&mut map, "_parameters", item)?;
}
match &self.amount {
Some(SubstanceSpecificationPropertyAmount::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"amountQuantity",
inner.as_ref(),
)?;
}
Some(SubstanceSpecificationPropertyAmount::String(inner)) => {
super::super::codec::value_entry(&mut map, "amountString", inner)?;
}
None => {}
}
if let Some(item) = &self.category {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", item)?;
}
if let Some(item) = &self.code {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", item)?;
}
match &self.defining_substance {
Some(SubstanceSpecificationPropertyDefiningSubstance::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"definingSubstanceCodeableConcept",
inner.as_ref(),
)?;
}
Some(SubstanceSpecificationPropertyDefiningSubstance::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"definingSubstanceReference",
inner.as_ref(),
)?;
}
None => {}
}
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.parameters {
super::super::codec::value_entry(&mut map, "parameters", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceSpecificationProperty {
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("SubstanceSpecificationProperty");
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 SubstanceSpecificationPropertyAmount {
Quantity(Box<super::quantity::Quantity>),
String(super::primitives::String),
}
impl SubstanceSpecificationPropertyAmount {
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::String(inner) => Ok((
"String",
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 {
"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)))
}
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SubstanceSpecificationPropertyDefiningSubstance {
Reference(Box<super::reference::Reference>),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
}
impl SubstanceSpecificationPropertyDefiningSubstance {
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::Reference(inner) => Ok((
"Reference",
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,
)),
}
}
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 {
"Reference" => {
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::Reference(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)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SubstanceSpecificationRelationship {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub substance: Option<SubstanceSpecificationRelationshipSubstance>,
pub relationship: Option<super::codeable_concept::CodeableConcept>,
pub is_defining: Option<super::primitives::Boolean>,
pub amount: Option<SubstanceSpecificationRelationshipAmount>,
pub amount_ratio_low_limit: Option<super::ratio::Ratio>,
pub amount_type: Option<super::codeable_concept::CodeableConcept>,
pub source: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for SubstanceSpecificationRelationship {
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.substance {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("substance{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_substance{suffix}"), element);
}
}
if let Some(item) = &self.relationship {
object.insert(
std::string::String::from("relationship"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.is_defining {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("isDefining"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_isDefining"), e);
}
}
if let Some(item) = &self.amount {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("amount{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_amount{suffix}"), element);
}
}
if let Some(item) = &self.amount_ratio_low_limit {
object.insert(
std::string::String::from("amountRatioLowLimit"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.amount_type {
object.insert(
std::string::String::from("amountType"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.source.is_empty() {
let mut items = Vec::with_capacity(self.source.len());
for item in &self.source {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("source"),
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_substance = super::super::codec::ChoiceSlot::default();
let mut raw_relationship: Option<&super::super::codec::Value> = None;
let mut raw_is_defining: Option<&super::super::codec::Value> = None;
let mut raw_is_defining_element: Option<&super::super::codec::Value> = None;
let mut raw_amount = super::super::codec::ChoiceSlot::default();
let mut raw_amount_ratio_low_limit: Option<&super::super::codec::Value> = None;
let mut raw_amount_type: Option<&super::super::codec::Value> = None;
let mut raw_source: 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);
}
"substanceReference" => {
raw_substance.value("Reference", value, path)?;
}
"_substanceReference" => {
raw_substance.element("Reference", value, path)?;
}
"substanceCodeableConcept" => {
raw_substance.value("CodeableConcept", value, path)?;
}
"_substanceCodeableConcept" => {
raw_substance.element("CodeableConcept", value, path)?;
}
"relationship" => {
raw_relationship = Some(value);
}
"isDefining" => {
raw_is_defining = Some(value);
}
"_isDefining" => {
raw_is_defining_element = Some(value);
}
"amountQuantity" => {
raw_amount.value("Quantity", value, path)?;
}
"_amountQuantity" => {
raw_amount.element("Quantity", value, path)?;
}
"amountRange" => {
raw_amount.value("Range", value, path)?;
}
"_amountRange" => {
raw_amount.element("Range", value, path)?;
}
"amountRatio" => {
raw_amount.value("Ratio", value, path)?;
}
"_amountRatio" => {
raw_amount.element("Ratio", value, path)?;
}
"amountString" => {
raw_amount.value("String", value, path)?;
}
"_amountString" => {
raw_amount.element("String", value, path)?;
}
"amountRatioLowLimit" => {
raw_amount_ratio_low_limit = Some(value);
}
"amountType" => {
raw_amount_type = Some(value);
}
"source" => {
raw_source = 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_substance = match raw_substance.suffix {
None => None,
Some(suffix) => Some(path.with("substance", |path| {
SubstanceSpecificationRelationshipSubstance::from_json_parts(
suffix,
raw_substance.value,
raw_substance.element,
path,
)
})?),
};
let field_relationship = raw_relationship
.map(|value| {
path.with("relationship", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_is_defining = match (raw_is_defining, raw_is_defining_element) {
(None, None) => None,
(value, element) => Some(path.with("isDefining", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_amount = match raw_amount.suffix {
None => None,
Some(suffix) => Some(path.with("amount", |path| {
SubstanceSpecificationRelationshipAmount::from_json_parts(
suffix,
raw_amount.value,
raw_amount.element,
path,
)
})?),
};
let field_amount_ratio_low_limit = raw_amount_ratio_low_limit
.map(|value| {
path.with("amountRatioLowLimit", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_amount_type = raw_amount_type
.map(|value| {
path.with("amountType", |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_source = Vec::new();
if let Some(raw) = raw_source {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_source.push(path.with_index("source", 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,
substance: field_substance,
relationship: field_relationship,
is_defining: field_is_defining,
amount: field_amount,
amount_ratio_low_limit: field_amount_ratio_low_limit,
amount_type: field_amount_type,
source: field_source,
})
}
}
impl serde::Serialize for SubstanceSpecificationRelationship {
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(SubstanceSpecificationRelationshipAmount::String(inner)) = &self.amount {
super::super::codec::element_entry(&mut map, "_amountString", inner)?;
}
if let Some(item) = &self.is_defining {
super::super::codec::element_entry(&mut map, "_isDefining", item)?;
}
match &self.amount {
Some(SubstanceSpecificationRelationshipAmount::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"amountQuantity",
inner.as_ref(),
)?;
}
Some(SubstanceSpecificationRelationshipAmount::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "amountRange", inner.as_ref())?;
}
Some(SubstanceSpecificationRelationshipAmount::Ratio(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "amountRatio", inner.as_ref())?;
}
_ => {}
}
if let Some(item) = &self.amount_ratio_low_limit {
serde::ser::SerializeMap::serialize_entry(&mut map, "amountRatioLowLimit", item)?;
}
if let Some(SubstanceSpecificationRelationshipAmount::String(inner)) = &self.amount {
super::super::codec::value_entry(&mut map, "amountString", inner)?;
}
if let Some(item) = &self.amount_type {
serde::ser::SerializeMap::serialize_entry(&mut map, "amountType", 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 let Some(item) = &self.is_defining {
super::super::codec::value_entry(&mut map, "isDefining", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.relationship {
serde::ser::SerializeMap::serialize_entry(&mut map, "relationship", item)?;
}
if !self.source.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "source", &self.source)?;
}
match &self.substance {
Some(SubstanceSpecificationRelationshipSubstance::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"substanceCodeableConcept",
inner.as_ref(),
)?;
}
Some(SubstanceSpecificationRelationshipSubstance::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"substanceReference",
inner.as_ref(),
)?;
}
None => {}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceSpecificationRelationship {
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("SubstanceSpecificationRelationship");
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 SubstanceSpecificationRelationshipAmount {
Quantity(Box<super::quantity::Quantity>),
Range(Box<super::range::Range>),
Ratio(Box<super::ratio::Ratio>),
String(super::primitives::String),
}
impl SubstanceSpecificationRelationshipAmount {
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::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::String(inner) => Ok((
"String",
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 {
"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)))
}
"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)))
}
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SubstanceSpecificationRelationshipSubstance {
Reference(Box<super::reference::Reference>),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
}
impl SubstanceSpecificationRelationshipSubstance {
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::Reference(inner) => Ok((
"Reference",
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,
)),
}
}
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 {
"Reference" => {
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::Reference(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)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SubstanceSpecificationStructure {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub stereochemistry: Option<super::codeable_concept::CodeableConcept>,
pub optical_activity: Option<super::codeable_concept::CodeableConcept>,
pub molecular_formula: Option<super::primitives::String>,
pub molecular_formula_by_moiety: Option<super::primitives::String>,
pub isotope: Vec<SubstanceSpecificationStructureIsotope>,
pub molecular_weight: Option<SubstanceSpecificationStructureIsotopeMolecularWeight>,
pub source: Vec<super::reference::Reference>,
pub representation: Vec<SubstanceSpecificationStructureRepresentation>,
}
impl super::super::codec::Json for SubstanceSpecificationStructure {
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.stereochemistry {
object.insert(
std::string::String::from("stereochemistry"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.optical_activity {
object.insert(
std::string::String::from("opticalActivity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.molecular_formula {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("molecularFormula"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_molecularFormula"), e);
}
}
if let Some(item) = &self.molecular_formula_by_moiety {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("molecularFormulaByMoiety"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_molecularFormulaByMoiety"), e);
}
}
if !self.isotope.is_empty() {
let mut items = Vec::with_capacity(self.isotope.len());
for item in &self.isotope {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("isotope"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.molecular_weight {
object.insert(
std::string::String::from("molecularWeight"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.source.is_empty() {
let mut items = Vec::with_capacity(self.source.len());
for item in &self.source {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("source"),
super::super::codec::Value::Array(items),
);
}
if !self.representation.is_empty() {
let mut items = Vec::with_capacity(self.representation.len());
for item in &self.representation {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("representation"),
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_stereochemistry: Option<&super::super::codec::Value> = None;
let mut raw_optical_activity: Option<&super::super::codec::Value> = None;
let mut raw_molecular_formula: Option<&super::super::codec::Value> = None;
let mut raw_molecular_formula_element: Option<&super::super::codec::Value> = None;
let mut raw_molecular_formula_by_moiety: Option<&super::super::codec::Value> = None;
let mut raw_molecular_formula_by_moiety_element: Option<&super::super::codec::Value> = None;
let mut raw_isotope: Option<&super::super::codec::Value> = None;
let mut raw_molecular_weight: Option<&super::super::codec::Value> = None;
let mut raw_source: Option<&super::super::codec::Value> = None;
let mut raw_representation: 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);
}
"stereochemistry" => {
raw_stereochemistry = Some(value);
}
"opticalActivity" => {
raw_optical_activity = Some(value);
}
"molecularFormula" => {
raw_molecular_formula = Some(value);
}
"_molecularFormula" => {
raw_molecular_formula_element = Some(value);
}
"molecularFormulaByMoiety" => {
raw_molecular_formula_by_moiety = Some(value);
}
"_molecularFormulaByMoiety" => {
raw_molecular_formula_by_moiety_element = Some(value);
}
"isotope" => {
raw_isotope = Some(value);
}
"molecularWeight" => {
raw_molecular_weight = Some(value);
}
"source" => {
raw_source = Some(value);
}
"representation" => {
raw_representation = 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_stereochemistry = raw_stereochemistry
.map(|value| {
path.with("stereochemistry", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_optical_activity = raw_optical_activity
.map(|value| {
path.with("opticalActivity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_molecular_formula = match (raw_molecular_formula, raw_molecular_formula_element) {
(None, None) => None,
(value, element) => Some(path.with("molecularFormula", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_molecular_formula_by_moiety = match (
raw_molecular_formula_by_moiety,
raw_molecular_formula_by_moiety_element,
) {
(None, None) => None,
(value, element) => Some(path.with("molecularFormulaByMoiety", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_isotope = Vec::new();
if let Some(raw) = raw_isotope {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_isotope.push(path.with_index("isotope", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_molecular_weight = raw_molecular_weight
.map(|value| {
path.with("molecularWeight", |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_source = Vec::new();
if let Some(raw) = raw_source {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_source.push(path.with_index("source", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_representation = Vec::new();
if let Some(raw) = raw_representation {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_representation.push(path.with_index("representation", 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,
stereochemistry: field_stereochemistry,
optical_activity: field_optical_activity,
molecular_formula: field_molecular_formula,
molecular_formula_by_moiety: field_molecular_formula_by_moiety,
isotope: field_isotope,
molecular_weight: field_molecular_weight,
source: field_source,
representation: field_representation,
})
}
}
impl serde::Serialize for SubstanceSpecificationStructure {
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.molecular_formula {
super::super::codec::element_entry(&mut map, "_molecularFormula", item)?;
}
if let Some(item) = &self.molecular_formula_by_moiety {
super::super::codec::element_entry(&mut map, "_molecularFormulaByMoiety", 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.isotope.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "isotope", &self.isotope)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.molecular_formula {
super::super::codec::value_entry(&mut map, "molecularFormula", item)?;
}
if let Some(item) = &self.molecular_formula_by_moiety {
super::super::codec::value_entry(&mut map, "molecularFormulaByMoiety", item)?;
}
if let Some(item) = &self.molecular_weight {
serde::ser::SerializeMap::serialize_entry(&mut map, "molecularWeight", item)?;
}
if let Some(item) = &self.optical_activity {
serde::ser::SerializeMap::serialize_entry(&mut map, "opticalActivity", item)?;
}
if !self.representation.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"representation",
&self.representation,
)?;
}
if !self.source.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "source", &self.source)?;
}
if let Some(item) = &self.stereochemistry {
serde::ser::SerializeMap::serialize_entry(&mut map, "stereochemistry", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceSpecificationStructure {
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("SubstanceSpecificationStructure");
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 SubstanceSpecificationStructureIsotope {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Option<super::identifier::Identifier>,
pub name: Option<super::codeable_concept::CodeableConcept>,
pub substitution: Option<super::codeable_concept::CodeableConcept>,
pub half_life: Option<super::quantity::Quantity>,
pub molecular_weight: Option<SubstanceSpecificationStructureIsotopeMolecularWeight>,
}
impl super::super::codec::Json for SubstanceSpecificationStructureIsotope {
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.identifier {
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.name {
object.insert(
std::string::String::from("name"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.substitution {
object.insert(
std::string::String::from("substitution"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.half_life {
object.insert(
std::string::String::from("halfLife"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.molecular_weight {
object.insert(
std::string::String::from("molecularWeight"),
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_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_name: Option<&super::super::codec::Value> = None;
let mut raw_substitution: Option<&super::super::codec::Value> = None;
let mut raw_half_life: Option<&super::super::codec::Value> = None;
let mut raw_molecular_weight: 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);
}
"identifier" => {
raw_identifier = Some(value);
}
"name" => {
raw_name = Some(value);
}
"substitution" => {
raw_substitution = Some(value);
}
"halfLife" => {
raw_half_life = Some(value);
}
"molecularWeight" => {
raw_molecular_weight = 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_identifier = raw_identifier
.map(|value| {
path.with("identifier", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_name = raw_name
.map(|value| {
path.with("name", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_substitution = raw_substitution
.map(|value| {
path.with("substitution", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_half_life = raw_half_life
.map(|value| {
path.with("halfLife", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_molecular_weight = raw_molecular_weight
.map(|value| {
path.with("molecularWeight", |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,
extension: field_extension,
modifier_extension: field_modifier_extension,
identifier: field_identifier,
name: field_name,
substitution: field_substitution,
half_life: field_half_life,
molecular_weight: field_molecular_weight,
})
}
}
impl serde::Serialize for SubstanceSpecificationStructureIsotope {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.half_life {
serde::ser::SerializeMap::serialize_entry(&mut map, "halfLife", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.molecular_weight {
serde::ser::SerializeMap::serialize_entry(&mut map, "molecularWeight", item)?;
}
if let Some(item) = &self.name {
serde::ser::SerializeMap::serialize_entry(&mut map, "name", item)?;
}
if let Some(item) = &self.substitution {
serde::ser::SerializeMap::serialize_entry(&mut map, "substitution", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceSpecificationStructureIsotope {
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("SubstanceSpecificationStructureIsotope");
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 SubstanceSpecificationStructureIsotopeMolecularWeight {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub method: Option<super::codeable_concept::CodeableConcept>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub amount: Option<super::quantity::Quantity>,
}
impl super::super::codec::Json for SubstanceSpecificationStructureIsotopeMolecularWeight {
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.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.r#type {
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.amount {
object.insert(
std::string::String::from("amount"),
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_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_method: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_amount: 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);
}
"method" => {
raw_method = Some(value);
}
"type" => {
raw_type = Some(value);
}
"amount" => {
raw_amount = 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_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_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 field_amount = raw_amount
.map(|value| {
path.with("amount", |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,
extension: field_extension,
modifier_extension: field_modifier_extension,
method: field_method,
r#type: field_type,
amount: field_amount,
})
}
}
impl serde::Serialize for SubstanceSpecificationStructureIsotopeMolecularWeight {
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.amount {
serde::ser::SerializeMap::serialize_entry(&mut map, "amount", 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 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.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceSpecificationStructureIsotopeMolecularWeight {
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(
"SubstanceSpecificationStructureIsotopeMolecularWeight",
);
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 SubstanceSpecificationStructureRepresentation {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub representation: Option<super::primitives::String>,
pub attachment: Option<super::attachment::Attachment>,
}
impl super::super::codec::Json for SubstanceSpecificationStructureRepresentation {
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.r#type {
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.representation {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("representation"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_representation"), e);
}
}
if let Some(item) = &self.attachment {
object.insert(
std::string::String::from("attachment"),
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_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_representation: Option<&super::super::codec::Value> = None;
let mut raw_representation_element: Option<&super::super::codec::Value> = None;
let mut raw_attachment: 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);
}
"type" => {
raw_type = Some(value);
}
"representation" => {
raw_representation = Some(value);
}
"_representation" => {
raw_representation_element = Some(value);
}
"attachment" => {
raw_attachment = 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_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 field_representation = match (raw_representation, raw_representation_element) {
(None, None) => None,
(value, element) => Some(path.with("representation", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_attachment = raw_attachment
.map(|value| {
path.with("attachment", |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,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
representation: field_representation,
attachment: field_attachment,
})
}
}
impl serde::Serialize for SubstanceSpecificationStructureRepresentation {
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.representation {
super::super::codec::element_entry(&mut map, "_representation", item)?;
}
if let Some(item) = &self.attachment {
serde::ser::SerializeMap::serialize_entry(&mut map, "attachment", 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.representation {
super::super::codec::value_entry(&mut map, "representation", 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 SubstanceSpecificationStructureRepresentation {
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("SubstanceSpecificationStructureRepresentation");
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)
}
}