#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SubstanceDefinition {
pub id: Option<std::string::String>,
pub meta: Option<super::meta::Meta>,
pub implicit_rules: Option<super::primitives::Uri>,
pub language: Option<super::primitives::Code>,
pub text: Option<super::narrative::Narrative>,
pub contained: Vec<super::resource::Resource>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Vec<super::identifier::Identifier>,
pub version: Option<super::primitives::String>,
pub status: Option<super::codeable_concept::CodeableConcept>,
pub classification: Vec<super::codeable_concept::CodeableConcept>,
pub domain: Option<super::codeable_concept::CodeableConcept>,
pub grade: Vec<super::codeable_concept::CodeableConcept>,
pub description: Option<super::primitives::Markdown>,
pub information_source: Vec<super::reference::Reference>,
pub note: Vec<super::annotation::Annotation>,
pub manufacturer: Vec<super::reference::Reference>,
pub supplier: Vec<super::reference::Reference>,
pub moiety: Vec<SubstanceDefinitionMoiety>,
pub property: Vec<SubstanceDefinitionProperty>,
pub molecular_weight: Vec<SubstanceDefinitionMolecularWeight>,
pub structure: Option<SubstanceDefinitionStructure>,
pub code: Vec<SubstanceDefinitionCode>,
pub name: Vec<SubstanceDefinitionName>,
pub relationship: Vec<SubstanceDefinitionRelationship>,
pub source_material: Option<SubstanceDefinitionSourceMaterial>,
}
impl super::super::codec::Json for SubstanceDefinition {
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("SubstanceDefinition")),
);
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.version {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("version"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_version"), e);
}
}
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 !self.classification.is_empty() {
let mut items = Vec::with_capacity(self.classification.len());
for item in &self.classification {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("classification"),
super::super::codec::Value::Array(items),
);
}
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 !self.grade.is_empty() {
let mut items = Vec::with_capacity(self.grade.len());
for item in &self.grade {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("grade"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
if !self.information_source.is_empty() {
let mut items = Vec::with_capacity(self.information_source.len());
for item in &self.information_source {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("informationSource"),
super::super::codec::Value::Array(items),
);
}
if !self.note.is_empty() {
let mut items = Vec::with_capacity(self.note.len());
for item in &self.note {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("note"),
super::super::codec::Value::Array(items),
);
}
if !self.manufacturer.is_empty() {
let mut items = Vec::with_capacity(self.manufacturer.len());
for item in &self.manufacturer {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("manufacturer"),
super::super::codec::Value::Array(items),
);
}
if !self.supplier.is_empty() {
let mut items = Vec::with_capacity(self.supplier.len());
for item in &self.supplier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("supplier"),
super::super::codec::Value::Array(items),
);
}
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 !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 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.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.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_version: Option<&super::super::codec::Value> = None;
let mut raw_version_element: Option<&super::super::codec::Value> = None;
let mut raw_status: Option<&super::super::codec::Value> = None;
let mut raw_classification: Option<&super::super::codec::Value> = None;
let mut raw_domain: Option<&super::super::codec::Value> = None;
let mut raw_grade: 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_information_source: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_manufacturer: Option<&super::super::codec::Value> = None;
let mut raw_supplier: 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_molecular_weight: 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_relationship: 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("SubstanceDefinition") {
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);
}
"version" => {
raw_version = Some(value);
}
"_version" => {
raw_version_element = Some(value);
}
"status" => {
raw_status = Some(value);
}
"classification" => {
raw_classification = Some(value);
}
"domain" => {
raw_domain = Some(value);
}
"grade" => {
raw_grade = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"informationSource" => {
raw_information_source = Some(value);
}
"note" => {
raw_note = Some(value);
}
"manufacturer" => {
raw_manufacturer = Some(value);
}
"supplier" => {
raw_supplier = Some(value);
}
"moiety" => {
raw_moiety = Some(value);
}
"property" => {
raw_property = Some(value);
}
"molecularWeight" => {
raw_molecular_weight = Some(value);
}
"structure" => {
raw_structure = Some(value);
}
"code" => {
raw_code = Some(value);
}
"name" => {
raw_name = Some(value);
}
"relationship" => {
raw_relationship = 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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_version = match (raw_version, raw_version_element) {
(None, None) => None,
(value, element) => Some(path.with("version", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
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 mut field_classification = Vec::new();
if let Some(raw) = raw_classification {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_classification.push(path.with_index("classification", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
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 mut field_grade = Vec::new();
if let Some(raw) = raw_grade {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_grade.push(path.with_index("grade", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_information_source = Vec::new();
if let Some(raw) = raw_information_source {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_information_source.push(path.with_index(
"informationSource",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_note = Vec::new();
if let Some(raw) = raw_note {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_note.push(path.with_index("note", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_manufacturer = Vec::new();
if let Some(raw) = raw_manufacturer {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_manufacturer.push(path.with_index("manufacturer", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_supplier = Vec::new();
if let Some(raw) = raw_supplier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_supplier.push(path.with_index("supplier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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 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 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_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_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,
version: field_version,
status: field_status,
classification: field_classification,
domain: field_domain,
grade: field_grade,
description: field_description,
information_source: field_information_source,
note: field_note,
manufacturer: field_manufacturer,
supplier: field_supplier,
moiety: field_moiety,
property: field_property,
molecular_weight: field_molecular_weight,
structure: field_structure,
code: field_code,
name: field_name,
relationship: field_relationship,
source_material: field_source_material,
})
}
}
impl serde::Serialize for SubstanceDefinition {
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.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(item) = &self.version {
super::super::codec::element_entry(&mut map, "_version", item)?;
}
if !self.classification.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"classification",
&self.classification,
)?;
}
if !self.code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.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 !self.grade.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "grade", &self.grade)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if !self.information_source.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"informationSource",
&self.information_source,
)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if !self.manufacturer.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"manufacturer",
&self.manufacturer,
)?;
}
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 !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
if !self.property.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "property", &self.property)?;
}
if !self.relationship.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"relationship",
&self.relationship,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "SubstanceDefinition")?;
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 !self.supplier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "supplier", &self.supplier)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.version {
super::super::codec::value_entry(&mut map, "version", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceDefinition {
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("SubstanceDefinition");
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 SubstanceDefinitionCode {
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 note: Vec<super::annotation::Annotation>,
pub source: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for SubstanceDefinitionCode {
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 !self.note.is_empty() {
let mut items = Vec::with_capacity(self.note.len());
for item in &self.note {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("note"),
super::super::codec::Value::Array(items),
);
}
if !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_note: 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);
}
"note" => {
raw_note = 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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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 mut field_note = Vec::new();
if let Some(raw) = raw_note {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_note.push(path.with_index("note", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let 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,
note: field_note,
source: field_source,
})
}
}
impl serde::Serialize for SubstanceDefinitionCode {
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.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 !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.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
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 SubstanceDefinitionCode {
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("SubstanceDefinitionCode");
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 SubstanceDefinitionMoiety {
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<SubstanceDefinitionMoietyAmount>,
pub measurement_type: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for SubstanceDefinitionMoiety {
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);
}
}
if let Some(item) = &self.measurement_type {
object.insert(
std::string::String::from("measurementType"),
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_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();
let mut raw_measurement_type: 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);
}
"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)?;
}
"measurementType" => {
raw_measurement_type = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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| {
SubstanceDefinitionMoietyAmount::from_json_parts(
suffix,
raw_amount.value,
raw_amount.element,
path,
)
})?),
};
let field_measurement_type = raw_measurement_type
.map(|value| {
path.with("measurementType", |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,
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,
measurement_type: field_measurement_type,
})
}
}
impl serde::Serialize for SubstanceDefinitionMoiety {
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(SubstanceDefinitionMoietyAmount::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(SubstanceDefinitionMoietyAmount::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"amountQuantity",
inner.as_ref(),
)?;
}
Some(SubstanceDefinitionMoietyAmount::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 let Some(item) = &self.measurement_type {
serde::ser::SerializeMap::serialize_entry(&mut map, "measurementType", 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 SubstanceDefinitionMoiety {
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("SubstanceDefinitionMoiety");
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 SubstanceDefinitionMoietyAmount {
Quantity(Box<super::quantity::Quantity>),
String(super::primitives::String),
}
impl SubstanceDefinitionMoietyAmount {
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 SubstanceDefinitionMolecularWeight {
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: super::quantity::Quantity,
}
impl super::super::codec::Json for SubstanceDefinitionMolecularWeight {
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)?),
);
}
object.insert(
std::string::String::from("amount"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.amount)?),
);
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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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 = path.with("amount", |path| {
let value = raw_amount
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
method: field_method,
r#type: field_type,
amount: field_amount,
})
}
}
impl serde::Serialize for SubstanceDefinitionMolecularWeight {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "amount", &self.amount)?;
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 SubstanceDefinitionMolecularWeight {
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("SubstanceDefinitionMolecularWeight");
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 SubstanceDefinitionName {
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<SubstanceDefinitionName>,
pub translation: Vec<SubstanceDefinitionName>,
pub official: Vec<SubstanceDefinitionNameOfficial>,
pub source: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for SubstanceDefinitionName {
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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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 SubstanceDefinitionName {
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 SubstanceDefinitionName {
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("SubstanceDefinitionName");
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 SubstanceDefinitionNameOfficial {
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 SubstanceDefinitionNameOfficial {
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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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 SubstanceDefinitionNameOfficial {
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 SubstanceDefinitionNameOfficial {
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("SubstanceDefinitionNameOfficial");
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 SubstanceDefinitionProperty {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub r#type: super::codeable_concept::CodeableConcept,
pub value: Option<SubstanceDefinitionPropertyValue>,
}
impl super::super::codec::Json for SubstanceDefinitionProperty {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.r#type)?),
);
if let Some(item) = &self.value {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("value{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_value{suffix}"), element);
}
}
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_value = 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);
}
"type" => {
raw_type = Some(value);
}
"valueCodeableConcept" => {
raw_value.value("CodeableConcept", value, path)?;
}
"_valueCodeableConcept" => {
raw_value.element("CodeableConcept", value, path)?;
}
"valueQuantity" => {
raw_value.value("Quantity", value, path)?;
}
"_valueQuantity" => {
raw_value.element("Quantity", value, path)?;
}
"valueDate" => {
raw_value.value("Date", value, path)?;
}
"_valueDate" => {
raw_value.element("Date", value, path)?;
}
"valueBoolean" => {
raw_value.value("Boolean", value, path)?;
}
"_valueBoolean" => {
raw_value.element("Boolean", value, path)?;
}
"valueAttachment" => {
raw_value.value("Attachment", value, path)?;
}
"_valueAttachment" => {
raw_value.element("Attachment", 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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_type = path.with("type", |path| {
let value = raw_type
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_value = match raw_value.suffix {
None => None,
Some(suffix) => Some(path.with("value", |path| {
SubstanceDefinitionPropertyValue::from_json_parts(
suffix,
raw_value.value,
raw_value.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
value: field_value,
})
}
}
impl serde::Serialize for SubstanceDefinitionProperty {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.value {
Some(SubstanceDefinitionPropertyValue::Boolean(inner)) => {
super::super::codec::element_entry(&mut map, "_valueBoolean", inner)?;
}
Some(SubstanceDefinitionPropertyValue::Date(inner)) => {
super::super::codec::element_entry(&mut map, "_valueDate", inner)?;
}
_ => {}
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
match &self.value {
Some(SubstanceDefinitionPropertyValue::Attachment(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueAttachment",
inner.as_ref(),
)?;
}
Some(SubstanceDefinitionPropertyValue::Boolean(inner)) => {
super::super::codec::value_entry(&mut map, "valueBoolean", inner)?;
}
Some(SubstanceDefinitionPropertyValue::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueCodeableConcept",
inner.as_ref(),
)?;
}
Some(SubstanceDefinitionPropertyValue::Date(inner)) => {
super::super::codec::value_entry(&mut map, "valueDate", inner)?;
}
Some(SubstanceDefinitionPropertyValue::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueQuantity",
inner.as_ref(),
)?;
}
None => {}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceDefinitionProperty {
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("SubstanceDefinitionProperty");
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 SubstanceDefinitionPropertyValue {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Quantity(Box<super::quantity::Quantity>),
Date(super::primitives::Date),
Boolean(super::primitives::Boolean),
Attachment(Box<super::attachment::Attachment>),
}
impl SubstanceDefinitionPropertyValue {
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::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Quantity(inner) => Ok((
"Quantity",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Date(inner) => Ok((
"Date",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Boolean(inner) => Ok((
"Boolean",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Attachment(inner) => Ok((
"Attachment",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"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)))
}
"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)))
}
"Date" => Ok(Self::Date(super::super::codec::Primitive::from_json_parts(
value, element, path,
)?)),
"Boolean" => Ok(Self::Boolean(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Attachment" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Attachment(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SubstanceDefinitionRelationship {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub substance_definition: Option<SubstanceDefinitionRelationshipSubstanceDefinition>,
pub r#type: super::codeable_concept::CodeableConcept,
pub is_defining: Option<super::primitives::Boolean>,
pub amount: Option<SubstanceDefinitionRelationshipAmount>,
pub ratio_high_limit_amount: Option<super::ratio::Ratio>,
pub comparator: Option<super::codeable_concept::CodeableConcept>,
pub source: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for SubstanceDefinitionRelationship {
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_definition {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("substanceDefinition{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_substanceDefinition{suffix}"), element);
}
}
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.r#type)?),
);
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.ratio_high_limit_amount {
object.insert(
std::string::String::from("ratioHighLimitAmount"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.comparator {
object.insert(
std::string::String::from("comparator"),
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_definition = super::super::codec::ChoiceSlot::default();
let mut raw_type: 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_ratio_high_limit_amount: Option<&super::super::codec::Value> = None;
let mut raw_comparator: 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);
}
"substanceDefinitionReference" => {
raw_substance_definition.value("Reference", value, path)?;
}
"_substanceDefinitionReference" => {
raw_substance_definition.element("Reference", value, path)?;
}
"substanceDefinitionCodeableConcept" => {
raw_substance_definition.value("CodeableConcept", value, path)?;
}
"_substanceDefinitionCodeableConcept" => {
raw_substance_definition.element("CodeableConcept", value, path)?;
}
"type" => {
raw_type = 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)?;
}
"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)?;
}
"ratioHighLimitAmount" => {
raw_ratio_high_limit_amount = Some(value);
}
"comparator" => {
raw_comparator = 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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_substance_definition = match raw_substance_definition.suffix {
None => None,
Some(suffix) => Some(path.with("substanceDefinition", |path| {
SubstanceDefinitionRelationshipSubstanceDefinition::from_json_parts(
suffix,
raw_substance_definition.value,
raw_substance_definition.element,
path,
)
})?),
};
let field_type = path.with("type", |path| {
let value = raw_type
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_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| {
SubstanceDefinitionRelationshipAmount::from_json_parts(
suffix,
raw_amount.value,
raw_amount.element,
path,
)
})?),
};
let field_ratio_high_limit_amount = raw_ratio_high_limit_amount
.map(|value| {
path.with("ratioHighLimitAmount", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_comparator = raw_comparator
.map(|value| {
path.with("comparator", |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_definition: field_substance_definition,
r#type: field_type,
is_defining: field_is_defining,
amount: field_amount,
ratio_high_limit_amount: field_ratio_high_limit_amount,
comparator: field_comparator,
source: field_source,
})
}
}
impl serde::Serialize for SubstanceDefinitionRelationship {
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(SubstanceDefinitionRelationshipAmount::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(SubstanceDefinitionRelationshipAmount::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"amountQuantity",
inner.as_ref(),
)?;
}
Some(SubstanceDefinitionRelationshipAmount::Ratio(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "amountRatio", inner.as_ref())?;
}
Some(SubstanceDefinitionRelationshipAmount::String(inner)) => {
super::super::codec::value_entry(&mut map, "amountString", inner)?;
}
None => {}
}
if let Some(item) = &self.comparator {
serde::ser::SerializeMap::serialize_entry(&mut map, "comparator", 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.ratio_high_limit_amount {
serde::ser::SerializeMap::serialize_entry(&mut map, "ratioHighLimitAmount", item)?;
}
if !self.source.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "source", &self.source)?;
}
match &self.substance_definition {
Some(SubstanceDefinitionRelationshipSubstanceDefinition::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"substanceDefinitionCodeableConcept",
inner.as_ref(),
)?;
}
Some(SubstanceDefinitionRelationshipSubstanceDefinition::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"substanceDefinitionReference",
inner.as_ref(),
)?;
}
None => {}
}
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceDefinitionRelationship {
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("SubstanceDefinitionRelationship");
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 SubstanceDefinitionRelationshipAmount {
Quantity(Box<super::quantity::Quantity>),
Ratio(Box<super::ratio::Ratio>),
String(super::primitives::String),
}
impl SubstanceDefinitionRelationshipAmount {
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::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)))
}
"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 SubstanceDefinitionRelationshipSubstanceDefinition {
Reference(Box<super::reference::Reference>),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
}
impl SubstanceDefinitionRelationshipSubstanceDefinition {
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 SubstanceDefinitionSourceMaterial {
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 genus: Option<super::codeable_concept::CodeableConcept>,
pub species: Option<super::codeable_concept::CodeableConcept>,
pub part: Option<super::codeable_concept::CodeableConcept>,
pub country_of_origin: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for SubstanceDefinitionSourceMaterial {
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.genus {
object.insert(
std::string::String::from("genus"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.species {
object.insert(
std::string::String::from("species"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.part {
object.insert(
std::string::String::from("part"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.country_of_origin.is_empty() {
let mut items = Vec::with_capacity(self.country_of_origin.len());
for item in &self.country_of_origin {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("countryOfOrigin"),
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_type: Option<&super::super::codec::Value> = None;
let mut raw_genus: Option<&super::super::codec::Value> = None;
let mut raw_species: Option<&super::super::codec::Value> = None;
let mut raw_part: Option<&super::super::codec::Value> = None;
let mut raw_country_of_origin: 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);
}
"genus" => {
raw_genus = Some(value);
}
"species" => {
raw_species = Some(value);
}
"part" => {
raw_part = Some(value);
}
"countryOfOrigin" => {
raw_country_of_origin = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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_genus = raw_genus
.map(|value| {
path.with("genus", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_species = raw_species
.map(|value| {
path.with("species", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_part = raw_part
.map(|value| {
path.with("part", |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_country_of_origin = Vec::new();
if let Some(raw) = raw_country_of_origin {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_country_of_origin.push(path.with_index(
"countryOfOrigin",
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,
r#type: field_type,
genus: field_genus,
species: field_species,
part: field_part,
country_of_origin: field_country_of_origin,
})
}
}
impl serde::Serialize for SubstanceDefinitionSourceMaterial {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.country_of_origin.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"countryOfOrigin",
&self.country_of_origin,
)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.genus {
serde::ser::SerializeMap::serialize_entry(&mut map, "genus", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.part {
serde::ser::SerializeMap::serialize_entry(&mut map, "part", item)?;
}
if let Some(item) = &self.species {
serde::ser::SerializeMap::serialize_entry(&mut map, "species", 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 SubstanceDefinitionSourceMaterial {
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("SubstanceDefinitionSourceMaterial");
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 SubstanceDefinitionStructure {
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 molecular_weight: Option<SubstanceDefinitionMolecularWeight>,
pub technique: Vec<super::codeable_concept::CodeableConcept>,
pub source_document: Vec<super::reference::Reference>,
pub representation: Vec<SubstanceDefinitionStructureRepresentation>,
}
impl super::super::codec::Json for SubstanceDefinitionStructure {
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 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.technique.is_empty() {
let mut items = Vec::with_capacity(self.technique.len());
for item in &self.technique {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("technique"),
super::super::codec::Value::Array(items),
);
}
if !self.source_document.is_empty() {
let mut items = Vec::with_capacity(self.source_document.len());
for item in &self.source_document {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("sourceDocument"),
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_molecular_weight: Option<&super::super::codec::Value> = None;
let mut raw_technique: Option<&super::super::codec::Value> = None;
let mut raw_source_document: 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);
}
"molecularWeight" => {
raw_molecular_weight = Some(value);
}
"technique" => {
raw_technique = Some(value);
}
"sourceDocument" => {
raw_source_document = 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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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 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_technique = Vec::new();
if let Some(raw) = raw_technique {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_technique.push(path.with_index("technique", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_source_document = Vec::new();
if let Some(raw) = raw_source_document {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_source_document.push(path.with_index("sourceDocument", 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,
molecular_weight: field_molecular_weight,
technique: field_technique,
source_document: field_source_document,
representation: field_representation,
})
}
}
impl serde::Serialize for SubstanceDefinitionStructure {
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.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_document.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"sourceDocument",
&self.source_document,
)?;
}
if let Some(item) = &self.stereochemistry {
serde::ser::SerializeMap::serialize_entry(&mut map, "stereochemistry", item)?;
}
if !self.technique.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "technique", &self.technique)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceDefinitionStructure {
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("SubstanceDefinitionStructure");
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 SubstanceDefinitionStructureRepresentation {
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 format: Option<super::codeable_concept::CodeableConcept>,
pub document: Option<super::reference::Reference>,
}
impl super::super::codec::Json for SubstanceDefinitionStructureRepresentation {
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.format {
object.insert(
std::string::String::from("format"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.document {
object.insert(
std::string::String::from("document"),
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_format: Option<&super::super::codec::Value> = None;
let mut raw_document: 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);
}
"format" => {
raw_format = Some(value);
}
"document" => {
raw_document = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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_format = raw_format
.map(|value| {
path.with("format", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_document = raw_document
.map(|value| {
path.with("document", |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,
format: field_format,
document: field_document,
})
}
}
impl serde::Serialize for SubstanceDefinitionStructureRepresentation {
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.document {
serde::ser::SerializeMap::serialize_entry(&mut map, "document", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.format {
serde::ser::SerializeMap::serialize_entry(&mut map, "format", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.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 SubstanceDefinitionStructureRepresentation {
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("SubstanceDefinitionStructureRepresentation");
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)
}
}