// @generated by fhir-codegen from hl7.fhir.r5.core 5.0.0. DO NOT EDIT.
// Change the emitter (tools/fhir-codegen) and regenerate.
// SPDX-FileCopyrightText: Cadasto B.V.
// SPDX-License-Identifier: Apache-2.0
//! A SubstanceProtein is defined as a single unit of a linear amino acid sequence, or a combination of subunits that are either covalently linked or have a defined invariant stoichiometric relationship. This includes all synthetic, recombinant and purified SubstanceProteins of defined sequence, whether the use is therapeutic or prophylactic. This set of elements will be used to describe albumins, coagulation factors, cytokines, growth factors, peptide/SubstanceProtein hormones, enzymes, toxins, toxoids, recombinant vaccines, and immunomodulators
/// A SubstanceProtein is defined as a single unit of a linear amino acid
/// sequence, or a combination of subunits that are either covalently linked or
/// have a defined invariant stoichiometric relationship. This includes all
/// synthetic, recombinant and purified SubstanceProteins of defined sequence,
/// whether the use is therapeutic or prophylactic. This set of elements will be
/// used to describe albumins, coagulation factors, cytokines, growth factors,
/// peptide/SubstanceProtein hormones, enzymes, toxins, toxoids, recombinant
/// vaccines, and immunomodulators.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SubstanceProtein {
/// Logical id of this artifact
///
/// The logical id of the resource, as used in the URL for the resource. Once
/// assigned, this value never changes.
pub id: Option<std::string::String>,
/// Metadata about the resource
///
/// The metadata about the resource. This is content that is maintained by the
/// infrastructure. Changes to the content might not always be associated with
/// version changes to the resource.
pub meta: Option<super::meta::Meta>,
/// A set of rules under which this content was created
///
/// A reference to a set of rules that were followed when the resource was
/// constructed, and which must be understood when processing the content.
/// Often, this is a reference to an implementation guide that defines the
/// special rules along with other profiles etc.
pub implicit_rules: Option<super::primitives::Uri>,
/// Language of the resource content
///
/// The base language in which the resource is written.
pub language: Option<super::primitives::Code>,
/// Text summary of the resource, for human interpretation
///
/// A human-readable narrative that contains a summary of the resource and can
/// be used to represent the content of the resource to a human. The narrative
/// need not encode all the structured data, but is required to contain
/// sufficient detail to make it "clinically safe" for a human to just read the
/// narrative. Resource definitions may define what content should be
/// represented in the narrative to ensure clinical safety.
pub text: Option<super::narrative::Narrative>,
/// Contained, inline Resources
///
/// These resources do not have an independent existence apart from the resource
/// that contains them - they cannot be identified independently, nor can they
/// have their own independent transaction scope. This is allowed to be a
/// Parameters resource if and only if it is referenced by a resource that
/// provides context/meaning.
pub contained: Vec<super::resource::Resource>,
/// Additional content defined by implementations
///
/// May be used to represent additional information that is not part of the
/// basic definition of the resource. To make the use of extensions safe and
/// managable, there is a strict set of governance applied to the definition and
/// use of extensions. Though any implementer can define an extension, there is
/// a set of requirements that SHALL be met as part of the definition of the
/// extension.
pub extension: Vec<super::extension::Extension>,
/// Extensions that cannot be ignored
///
/// May be used to represent additional information that is not part of the
/// basic definition of the resource and that modifies the understanding of the
/// element that contains it and/or the understanding of the containing
/// element's descendants. Usually modifier elements provide negation or
/// qualification. To make the use of extensions safe and managable, there is a
/// strict set of governance applied to the definition and use of extensions.
/// Though any implementer is allowed to define an extension, there is a set of
/// requirements that SHALL be met as part of the definition of the extension.
/// Applications processing a resource are required to check for modifier
/// extensions. Modifier extensions SHALL NOT change the meaning of any elements
/// on Resource or DomainResource (including cannot change the meaning of
/// modifierExtension itself).
pub modifier_extension: Vec<super::extension::Extension>,
/// The SubstanceProtein descriptive elements will only be used when a complete
/// or partial amino acid sequence is available or derivable from a nucleic acid
/// sequence.
pub sequence_type: Option<super::codeable_concept::CodeableConcept>,
/// Number of linear sequences of amino acids linked through peptide bonds. The
/// number of subunits constituting the SubstanceProtein shall be described. It
/// is possible that the number of subunits can be variable.
pub number_of_subunits: Option<super::primitives::Integer>,
/// The disulphide bond between two cysteine residues either on the same subunit
/// or on two different subunits shall be described. The position of the
/// disulfide bonds in the SubstanceProtein shall be listed in increasing order
/// of subunit number and position within subunit followed by the abbreviation
/// of the amino acids involved. The disulfide linkage positions shall actually
/// contain the amino acid Cysteine at the respective positions.
pub disulfide_linkage: Vec<super::primitives::String>,
/// This subclause refers to the description of each subunit constituting the
/// SubstanceProtein. A subunit is a linear sequence of amino acids linked
/// through peptide bonds. The Subunit information shall be provided when the
/// finished SubstanceProtein is a complex of multiple sequences; subunits are
/// not used to delineate domains within a single sequence. Subunits are listed
/// in order of decreasing length; sequences of the same length will be ordered
/// by decreasing molecular weight; subunits that have identical sequences will
/// be repeated multiple times.
pub subunit: Vec<SubstanceProteinSubunit>,
}
impl super::super::codec::Json for SubstanceProtein {
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("SubstanceProtein")),
);
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.sequence_type {
object.insert(
std::string::String::from("sequenceType"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.number_of_subunits {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("numberOfSubunits"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_numberOfSubunits"), e);
}
}
if !self.disulfide_linkage.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.disulfide_linkage)?;
if let Some(values) = values {
object.insert(std::string::String::from("disulfideLinkage"), values);
}
if let Some(elements) = elements {
object.insert(std::string::String::from("_disulfideLinkage"), elements);
}
}
if !self.subunit.is_empty() {
let mut items = Vec::with_capacity(self.subunit.len());
for item in &self.subunit {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("subunit"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_meta: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_language_element: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_contained: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_sequence_type: Option<&super::super::codec::Value> = None;
let mut raw_number_of_subunits: Option<&super::super::codec::Value> = None;
let mut raw_number_of_subunits_element: Option<&super::super::codec::Value> = None;
let mut raw_disulfide_linkage: Option<&super::super::codec::Value> = None;
let mut raw_disulfide_linkage_element: Option<&super::super::codec::Value> = None;
let mut raw_subunit: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("SubstanceProtein") {
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);
}
"sequenceType" => {
raw_sequence_type = Some(value);
}
"numberOfSubunits" => {
raw_number_of_subunits = Some(value);
}
"_numberOfSubunits" => {
raw_number_of_subunits_element = Some(value);
}
"disulfideLinkage" => {
raw_disulfide_linkage = Some(value);
}
"_disulfideLinkage" => {
raw_disulfide_linkage_element = Some(value);
}
"subunit" => {
raw_subunit = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_id(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_sequence_type = raw_sequence_type
.map(|value| {
path.with("sequenceType", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_number_of_subunits =
match (raw_number_of_subunits, raw_number_of_subunits_element) {
(None, None) => None,
(value, element) => Some(path.with("numberOfSubunits", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_disulfide_linkage = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_disulfide_linkage,
raw_disulfide_linkage_element,
path,
)?
.into_iter()
.enumerate()
{
field_disulfide_linkage.push(path.with_index("disulfideLinkage", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let mut field_subunit = Vec::new();
if let Some(raw) = raw_subunit {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_subunit.push(path.with_index("subunit", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
meta: field_meta,
implicit_rules: field_implicit_rules,
language: field_language,
text: field_text,
contained: field_contained,
extension: field_extension,
modifier_extension: field_modifier_extension,
sequence_type: field_sequence_type,
number_of_subunits: field_number_of_subunits,
disulfide_linkage: field_disulfide_linkage,
subunit: field_subunit,
})
}
}
impl serde::Serialize for SubstanceProtein {
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_list_entry(
&mut map,
"_disulfideLinkage",
&self.disulfide_linkage,
)?;
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.number_of_subunits {
super::super::codec::element_entry(&mut map, "_numberOfSubunits", item)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
super::super::codec::value_list_entry(
&mut map,
"disulfideLinkage",
&self.disulfide_linkage,
)?;
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.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.meta {
serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.number_of_subunits {
super::super::codec::value_entry(&mut map, "numberOfSubunits", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "SubstanceProtein")?;
if let Some(item) = &self.sequence_type {
serde::ser::SerializeMap::serialize_entry(&mut map, "sequenceType", item)?;
}
if !self.subunit.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "subunit", &self.subunit)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceProtein {
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("SubstanceProtein");
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)
}
}
/// This subclause refers to the description of each subunit constituting the
/// SubstanceProtein. A subunit is a linear sequence of amino acids linked
/// through peptide bonds. The Subunit information shall be provided when the
/// finished SubstanceProtein is a complex of multiple sequences; subunits are
/// not used to delineate domains within a single sequence. Subunits are listed
/// in order of decreasing length; sequences of the same length will be ordered
/// by decreasing molecular weight; subunits that have identical sequences will
/// be repeated multiple times.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SubstanceProteinSubunit {
/// Unique id for inter-element referencing
///
/// Unique id for the element within a resource (for internal references). This
/// may be any string value that does not contain spaces.
pub id: Option<std::string::String>,
/// Additional content defined by implementations
///
/// May be used to represent additional information that is not part of the
/// basic definition of the element. To make the use of extensions safe and
/// managable, there is a strict set of governance applied to the definition and
/// use of extensions. Though any implementer can define an extension, there is
/// a set of requirements that SHALL be met as part of the definition of the
/// extension.
pub extension: Vec<super::extension::Extension>,
/// Extensions that cannot be ignored even if unrecognized
///
/// May be used to represent additional information that is not part of the
/// basic definition of the element and that modifies the understanding of the
/// element in which it is contained and/or the understanding of the containing
/// element's descendants. Usually modifier elements provide negation or
/// qualification. To make the use of extensions safe and managable, there is a
/// strict set of governance applied to the definition and use of extensions.
/// Though any implementer can define an extension, there is a set of
/// requirements that SHALL be met as part of the definition of the extension.
/// Applications processing a resource are required to check for modifier
/// extensions. Modifier extensions SHALL NOT change the meaning of any elements
/// on Resource or DomainResource (including cannot change the meaning of
/// modifierExtension itself).
pub modifier_extension: Vec<super::extension::Extension>,
/// Index of primary sequences of amino acids linked through peptide bonds in
/// order of decreasing length. Sequences of the same length will be ordered by
/// molecular weight. Subunits that have identical sequences will be repeated
/// and have sequential subscripts.
pub subunit: Option<super::primitives::Integer>,
/// The sequence information shall be provided enumerating the amino acids from
/// N- to C-terminal end using standard single-letter amino acid codes.
/// Uppercase shall be used for L-amino acids and lowercase for D-amino acids.
/// Transcribed SubstanceProteins will always be described using the translated
/// sequence; for synthetic peptide containing amino acids that are not
/// represented with a single letter code an X should be used within the
/// sequence. The modified amino acids will be distinguished by their position
/// in the sequence.
pub sequence: Option<super::primitives::String>,
/// Length of linear sequences of amino acids contained in the subunit.
pub length: Option<super::primitives::Integer>,
/// The sequence information shall be provided enumerating the amino acids from
/// N- to C-terminal end using standard single-letter amino acid codes.
/// Uppercase shall be used for L-amino acids and lowercase for D-amino acids.
/// Transcribed SubstanceProteins will always be described using the translated
/// sequence; for synthetic peptide containing amino acids that are not
/// represented with a single letter code an X should be used within the
/// sequence. The modified amino acids will be distinguished by their position
/// in the sequence.
pub sequence_attachment: Option<super::attachment::Attachment>,
/// Unique identifier for molecular fragment modification based on the ISO 11238
/// Substance ID.
pub n_terminal_modification_id: Option<super::identifier::Identifier>,
/// The name of the fragment modified at the N-terminal of the SubstanceProtein
/// shall be specified.
pub n_terminal_modification: Option<super::primitives::String>,
/// Unique identifier for molecular fragment modification based on the ISO 11238
/// Substance ID.
pub c_terminal_modification_id: Option<super::identifier::Identifier>,
/// The modification at the C-terminal shall be specified.
pub c_terminal_modification: Option<super::primitives::String>,
}
impl super::super::codec::Json for SubstanceProteinSubunit {
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.subunit {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("subunit"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_subunit"), e);
}
}
if let Some(item) = &self.sequence {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_sequence"), e);
}
}
if let Some(item) = &self.length {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("length"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_length"), e);
}
}
if let Some(item) = &self.sequence_attachment {
object.insert(
std::string::String::from("sequenceAttachment"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.n_terminal_modification_id {
object.insert(
std::string::String::from("nTerminalModificationId"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.n_terminal_modification {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("nTerminalModification"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_nTerminalModification"), e);
}
}
if let Some(item) = &self.c_terminal_modification_id {
object.insert(
std::string::String::from("cTerminalModificationId"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.c_terminal_modification {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("cTerminalModification"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_cTerminalModification"), 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_subunit: Option<&super::super::codec::Value> = None;
let mut raw_subunit_element: Option<&super::super::codec::Value> = None;
let mut raw_sequence: Option<&super::super::codec::Value> = None;
let mut raw_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_length: Option<&super::super::codec::Value> = None;
let mut raw_length_element: Option<&super::super::codec::Value> = None;
let mut raw_sequence_attachment: Option<&super::super::codec::Value> = None;
let mut raw_n_terminal_modification_id: Option<&super::super::codec::Value> = None;
let mut raw_n_terminal_modification: Option<&super::super::codec::Value> = None;
let mut raw_n_terminal_modification_element: Option<&super::super::codec::Value> = None;
let mut raw_c_terminal_modification_id: Option<&super::super::codec::Value> = None;
let mut raw_c_terminal_modification: Option<&super::super::codec::Value> = None;
let mut raw_c_terminal_modification_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);
}
"subunit" => {
raw_subunit = Some(value);
}
"_subunit" => {
raw_subunit_element = Some(value);
}
"sequence" => {
raw_sequence = Some(value);
}
"_sequence" => {
raw_sequence_element = Some(value);
}
"length" => {
raw_length = Some(value);
}
"_length" => {
raw_length_element = Some(value);
}
"sequenceAttachment" => {
raw_sequence_attachment = Some(value);
}
"nTerminalModificationId" => {
raw_n_terminal_modification_id = Some(value);
}
"nTerminalModification" => {
raw_n_terminal_modification = Some(value);
}
"_nTerminalModification" => {
raw_n_terminal_modification_element = Some(value);
}
"cTerminalModificationId" => {
raw_c_terminal_modification_id = Some(value);
}
"cTerminalModification" => {
raw_c_terminal_modification = Some(value);
}
"_cTerminalModification" => {
raw_c_terminal_modification_element = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_subunit = match (raw_subunit, raw_subunit_element) {
(None, None) => None,
(value, element) => Some(path.with("subunit", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_sequence = match (raw_sequence, raw_sequence_element) {
(None, None) => None,
(value, element) => Some(path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_length = match (raw_length, raw_length_element) {
(None, None) => None,
(value, element) => Some(path.with("length", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_sequence_attachment = raw_sequence_attachment
.map(|value| {
path.with("sequenceAttachment", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_n_terminal_modification_id = raw_n_terminal_modification_id
.map(|value| {
path.with("nTerminalModificationId", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_n_terminal_modification = match (
raw_n_terminal_modification,
raw_n_terminal_modification_element,
) {
(None, None) => None,
(value, element) => Some(path.with("nTerminalModification", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_c_terminal_modification_id = raw_c_terminal_modification_id
.map(|value| {
path.with("cTerminalModificationId", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_c_terminal_modification = match (
raw_c_terminal_modification,
raw_c_terminal_modification_element,
) {
(None, None) => None,
(value, element) => Some(path.with("cTerminalModification", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
subunit: field_subunit,
sequence: field_sequence,
length: field_length,
sequence_attachment: field_sequence_attachment,
n_terminal_modification_id: field_n_terminal_modification_id,
n_terminal_modification: field_n_terminal_modification,
c_terminal_modification_id: field_c_terminal_modification_id,
c_terminal_modification: field_c_terminal_modification,
})
}
}
impl serde::Serialize for SubstanceProteinSubunit {
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.c_terminal_modification {
super::super::codec::element_entry(&mut map, "_cTerminalModification", item)?;
}
if let Some(item) = &self.length {
super::super::codec::element_entry(&mut map, "_length", item)?;
}
if let Some(item) = &self.n_terminal_modification {
super::super::codec::element_entry(&mut map, "_nTerminalModification", item)?;
}
if let Some(item) = &self.sequence {
super::super::codec::element_entry(&mut map, "_sequence", item)?;
}
if let Some(item) = &self.subunit {
super::super::codec::element_entry(&mut map, "_subunit", item)?;
}
if let Some(item) = &self.c_terminal_modification {
super::super::codec::value_entry(&mut map, "cTerminalModification", item)?;
}
if let Some(item) = &self.c_terminal_modification_id {
serde::ser::SerializeMap::serialize_entry(&mut map, "cTerminalModificationId", 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.length {
super::super::codec::value_entry(&mut map, "length", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.n_terminal_modification {
super::super::codec::value_entry(&mut map, "nTerminalModification", item)?;
}
if let Some(item) = &self.n_terminal_modification_id {
serde::ser::SerializeMap::serialize_entry(&mut map, "nTerminalModificationId", item)?;
}
if let Some(item) = &self.sequence {
super::super::codec::value_entry(&mut map, "sequence", item)?;
}
if let Some(item) = &self.sequence_attachment {
serde::ser::SerializeMap::serialize_entry(&mut map, "sequenceAttachment", item)?;
}
if let Some(item) = &self.subunit {
super::super::codec::value_entry(&mut map, "subunit", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for SubstanceProteinSubunit {
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("SubstanceProteinSubunit");
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)
}
}