#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AllergyIntolerance {
pub id: Option<super::primitives::Id>,
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 clinical_status: Option<super::primitives::Code>,
pub verification_status: super::primitives::Code,
pub r#type: Option<super::primitives::Code>,
pub category: Vec<super::primitives::Code>,
pub criticality: Option<super::primitives::Code>,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub patient: super::reference::Reference,
pub onset: Option<AllergyIntoleranceOnset>,
pub asserted_date: Option<super::primitives::DateTime>,
pub recorder: Option<super::reference::Reference>,
pub asserter: Option<super::reference::Reference>,
pub last_occurrence: Option<super::primitives::DateTime>,
pub note: Vec<super::annotation::Annotation>,
pub reaction: Vec<AllergyIntoleranceReaction>,
}
impl super::super::codec::Json for AllergyIntolerance {
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("AllergyIntolerance")),
);
if let Some(item) = &self.id {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("id"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_id"), e);
}
}
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.clinical_status {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("clinicalStatus"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_clinicalStatus"), e);
}
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.verification_status)? {
object.insert(std::string::String::from("verificationStatus"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.verification_status)? {
object.insert(std::string::String::from("_verificationStatus"), e);
}
if let Some(item) = &self.r#type {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("type"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_type"), e);
}
}
if !self.category.is_empty() {
let (values, elements) = super::super::codec::primitive_arrays(&self.category)?;
if let Some(values) = values {
object.insert(std::string::String::from("category"), values);
}
if let Some(elements) = elements {
object.insert(std::string::String::from("_category"), elements);
}
}
if let Some(item) = &self.criticality {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("criticality"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_criticality"), e);
}
}
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)?),
);
}
object.insert(
std::string::String::from("patient"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.patient)?),
);
if let Some(item) = &self.onset {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("onset{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_onset{suffix}"), element);
}
}
if let Some(item) = &self.asserted_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("assertedDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_assertedDate"), e);
}
}
if let Some(item) = &self.recorder {
object.insert(
std::string::String::from("recorder"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.asserter {
object.insert(
std::string::String::from("asserter"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.last_occurrence {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("lastOccurrence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_lastOccurrence"), 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.reaction.is_empty() {
let mut items = Vec::with_capacity(self.reaction.len());
for item in &self.reaction {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reaction"),
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_id_element: 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_clinical_status: Option<&super::super::codec::Value> = None;
let mut raw_clinical_status_element: Option<&super::super::codec::Value> = None;
let mut raw_verification_status: Option<&super::super::codec::Value> = None;
let mut raw_verification_status_element: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_type_element: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_category_element: Option<&super::super::codec::Value> = None;
let mut raw_criticality: Option<&super::super::codec::Value> = None;
let mut raw_criticality_element: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_patient: Option<&super::super::codec::Value> = None;
let mut raw_onset = super::super::codec::ChoiceSlot::default();
let mut raw_asserted_date: Option<&super::super::codec::Value> = None;
let mut raw_asserted_date_element: Option<&super::super::codec::Value> = None;
let mut raw_recorder: Option<&super::super::codec::Value> = None;
let mut raw_asserter: Option<&super::super::codec::Value> = None;
let mut raw_last_occurrence: Option<&super::super::codec::Value> = None;
let mut raw_last_occurrence_element: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_reaction: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("AllergyIntolerance") {
return Err(path.error(super::super::codec::DecodeErrorKind::ResourceType));
}
}
"id" => {
raw_id = Some(value);
}
"_id" => {
raw_id_element = 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);
}
"clinicalStatus" => {
raw_clinical_status = Some(value);
}
"_clinicalStatus" => {
raw_clinical_status_element = Some(value);
}
"verificationStatus" => {
raw_verification_status = Some(value);
}
"_verificationStatus" => {
raw_verification_status_element = Some(value);
}
"type" => {
raw_type = Some(value);
}
"_type" => {
raw_type_element = Some(value);
}
"category" => {
raw_category = Some(value);
}
"_category" => {
raw_category_element = Some(value);
}
"criticality" => {
raw_criticality = Some(value);
}
"_criticality" => {
raw_criticality_element = Some(value);
}
"code" => {
raw_code = Some(value);
}
"patient" => {
raw_patient = Some(value);
}
"onsetDateTime" => {
raw_onset.value("DateTime", value, path)?;
}
"_onsetDateTime" => {
raw_onset.element("DateTime", value, path)?;
}
"onsetAge" => {
raw_onset.value("Age", value, path)?;
}
"_onsetAge" => {
raw_onset.element("Age", value, path)?;
}
"onsetPeriod" => {
raw_onset.value("Period", value, path)?;
}
"_onsetPeriod" => {
raw_onset.element("Period", value, path)?;
}
"onsetRange" => {
raw_onset.value("Range", value, path)?;
}
"_onsetRange" => {
raw_onset.element("Range", value, path)?;
}
"onsetString" => {
raw_onset.value("String", value, path)?;
}
"_onsetString" => {
raw_onset.element("String", value, path)?;
}
"assertedDate" => {
raw_asserted_date = Some(value);
}
"_assertedDate" => {
raw_asserted_date_element = Some(value);
}
"recorder" => {
raw_recorder = Some(value);
}
"asserter" => {
raw_asserter = Some(value);
}
"lastOccurrence" => {
raw_last_occurrence = Some(value);
}
"_lastOccurrence" => {
raw_last_occurrence_element = Some(value);
}
"note" => {
raw_note = Some(value);
}
"reaction" => {
raw_reaction = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = match (raw_id, raw_id_element) {
(None, None) => None,
(value, element) => Some(path.with("id", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
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_clinical_status = match (raw_clinical_status, raw_clinical_status_element) {
(None, None) => None,
(value, element) => Some(path.with("clinicalStatus", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_verification_status = path.with("verificationStatus", |path| {
super::super::codec::Primitive::from_json_parts(
raw_verification_status,
raw_verification_status_element,
path,
)
})?;
let field_type = match (raw_type, raw_type_element) {
(None, None) => None,
(value, element) => Some(path.with("type", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_category = Vec::new();
for (index, (value, element)) in
super::super::codec::pair_arrays(raw_category, raw_category_element, path)?
.into_iter()
.enumerate()
{
field_category.push(path.with_index("category", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let field_criticality = match (raw_criticality, raw_criticality_element) {
(None, None) => None,
(value, element) => Some(path.with("criticality", |path| {
super::super::codec::Primitive::from_json_parts(value, element, 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_patient = path.with("patient", |path| {
let value = raw_patient
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_onset = match raw_onset.suffix {
None => None,
Some(suffix) => Some(path.with("onset", |path| {
AllergyIntoleranceOnset::from_json_parts(
suffix,
raw_onset.value,
raw_onset.element,
path,
)
})?),
};
let field_asserted_date = match (raw_asserted_date, raw_asserted_date_element) {
(None, None) => None,
(value, element) => Some(path.with("assertedDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_recorder = raw_recorder
.map(|value| {
path.with("recorder", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_asserter = raw_asserter
.map(|value| {
path.with("asserter", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_last_occurrence = match (raw_last_occurrence, raw_last_occurrence_element) {
(None, None) => None,
(value, element) => Some(path.with("lastOccurrence", |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_reaction = Vec::new();
if let Some(raw) = raw_reaction {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reaction.push(path.with_index("reaction", 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,
identifier: field_identifier,
clinical_status: field_clinical_status,
verification_status: field_verification_status,
r#type: field_type,
category: field_category,
criticality: field_criticality,
code: field_code,
patient: field_patient,
onset: field_onset,
asserted_date: field_asserted_date,
recorder: field_recorder,
asserter: field_asserter,
last_occurrence: field_last_occurrence,
note: field_note,
reaction: field_reaction,
})
}
}
impl serde::Serialize for AllergyIntolerance {
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.asserted_date {
super::super::codec::element_entry(&mut map, "_assertedDate", item)?;
}
super::super::codec::element_list_entry(&mut map, "_category", &self.category)?;
if let Some(item) = &self.clinical_status {
super::super::codec::element_entry(&mut map, "_clinicalStatus", item)?;
}
if let Some(item) = &self.criticality {
super::super::codec::element_entry(&mut map, "_criticality", item)?;
}
if let Some(item) = &self.id {
super::super::codec::element_entry(&mut map, "_id", 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.last_occurrence {
super::super::codec::element_entry(&mut map, "_lastOccurrence", item)?;
}
match &self.onset {
Some(AllergyIntoleranceOnset::DateTime(inner)) => {
super::super::codec::element_entry(&mut map, "_onsetDateTime", inner)?;
}
Some(AllergyIntoleranceOnset::String(inner)) => {
super::super::codec::element_entry(&mut map, "_onsetString", inner)?;
}
_ => {}
}
if let Some(item) = &self.r#type {
super::super::codec::element_entry(&mut map, "_type", item)?;
}
super::super::codec::element_entry(
&mut map,
"_verificationStatus",
&self.verification_status,
)?;
if let Some(item) = &self.asserted_date {
super::super::codec::value_entry(&mut map, "assertedDate", item)?;
}
if let Some(item) = &self.asserter {
serde::ser::SerializeMap::serialize_entry(&mut map, "asserter", item)?;
}
super::super::codec::value_list_entry(&mut map, "category", &self.category)?;
if let Some(item) = &self.clinical_status {
super::super::codec::value_entry(&mut map, "clinicalStatus", item)?;
}
if let Some(item) = &self.code {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", item)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.criticality {
super::super::codec::value_entry(&mut map, "criticality", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.id {
super::super::codec::value_entry(&mut map, "id", item)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.last_occurrence {
super::super::codec::value_entry(&mut map, "lastOccurrence", item)?;
}
if let Some(item) = &self.meta {
serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
match &self.onset {
Some(AllergyIntoleranceOnset::Age(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "onsetAge", inner.as_ref())?;
}
Some(AllergyIntoleranceOnset::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "onsetDateTime", inner)?;
}
Some(AllergyIntoleranceOnset::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "onsetPeriod", inner.as_ref())?;
}
Some(AllergyIntoleranceOnset::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "onsetRange", inner.as_ref())?;
}
Some(AllergyIntoleranceOnset::String(inner)) => {
super::super::codec::value_entry(&mut map, "onsetString", inner)?;
}
None => {}
}
serde::ser::SerializeMap::serialize_entry(&mut map, "patient", &self.patient)?;
if !self.reaction.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reaction", &self.reaction)?;
}
if let Some(item) = &self.recorder {
serde::ser::SerializeMap::serialize_entry(&mut map, "recorder", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "AllergyIntolerance")?;
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.r#type {
super::super::codec::value_entry(&mut map, "type", item)?;
}
super::super::codec::value_entry(
&mut map,
"verificationStatus",
&self.verification_status,
)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for AllergyIntolerance {
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("AllergyIntolerance");
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 AllergyIntoleranceOnset {
DateTime(super::primitives::DateTime),
Age(Box<super::age::Age>),
Period(Box<super::period::Period>),
Range(Box<super::range::Range>),
String(super::primitives::String),
}
impl AllergyIntoleranceOnset {
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::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Age(inner) => Ok((
"Age",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Range(inner) => Ok((
"Range",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::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 {
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Age" => {
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::Age(Box::new(inner)))
}
"Period" => {
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::Period(Box::new(inner)))
}
"Range" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Range(Box::new(inner)))
}
"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 AllergyIntoleranceReaction {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub substance: Option<super::codeable_concept::CodeableConcept>,
pub manifestation: Vec<super::codeable_concept::CodeableConcept>,
pub description: Option<super::primitives::String>,
pub onset: Option<super::primitives::DateTime>,
pub severity: Option<super::primitives::Code>,
pub exposure_route: Option<super::codeable_concept::CodeableConcept>,
pub note: Vec<super::annotation::Annotation>,
}
impl super::super::codec::Json for AllergyIntoleranceReaction {
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 {
object.insert(
std::string::String::from("substance"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.manifestation.is_empty() {
let mut items = Vec::with_capacity(self.manifestation.len());
for item in &self.manifestation {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("manifestation"),
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 let Some(item) = &self.onset {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("onset"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_onset"), e);
}
}
if let Some(item) = &self.severity {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("severity"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_severity"), e);
}
}
if let Some(item) = &self.exposure_route {
object.insert(
std::string::String::from("exposureRoute"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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),
);
}
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: Option<&super::super::codec::Value> = None;
let mut raw_manifestation: 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_onset: Option<&super::super::codec::Value> = None;
let mut raw_onset_element: Option<&super::super::codec::Value> = None;
let mut raw_severity: Option<&super::super::codec::Value> = None;
let mut raw_severity_element: Option<&super::super::codec::Value> = None;
let mut raw_exposure_route: Option<&super::super::codec::Value> = None;
let mut raw_note: 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);
}
"substance" => {
raw_substance = Some(value);
}
"manifestation" => {
raw_manifestation = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"onset" => {
raw_onset = Some(value);
}
"_onset" => {
raw_onset_element = Some(value);
}
"severity" => {
raw_severity = Some(value);
}
"_severity" => {
raw_severity_element = Some(value);
}
"exposureRoute" => {
raw_exposure_route = Some(value);
}
"note" => {
raw_note = 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 = raw_substance
.map(|value| {
path.with("substance", |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_manifestation = Vec::new();
if let Some(raw) = raw_manifestation {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_manifestation.push(path.with_index("manifestation", 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 field_onset = match (raw_onset, raw_onset_element) {
(None, None) => None,
(value, element) => Some(path.with("onset", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_severity = match (raw_severity, raw_severity_element) {
(None, None) => None,
(value, element) => Some(path.with("severity", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_exposure_route = raw_exposure_route
.map(|value| {
path.with("exposureRoute", |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_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,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
substance: field_substance,
manifestation: field_manifestation,
description: field_description,
onset: field_onset,
severity: field_severity,
exposure_route: field_exposure_route,
note: field_note,
})
}
}
impl serde::Serialize for AllergyIntoleranceReaction {
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.onset {
super::super::codec::element_entry(&mut map, "_onset", item)?;
}
if let Some(item) = &self.severity {
super::super::codec::element_entry(&mut map, "_severity", item)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if let Some(item) = &self.exposure_route {
serde::ser::SerializeMap::serialize_entry(&mut map, "exposureRoute", 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.manifestation.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"manifestation",
&self.manifestation,
)?;
}
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 let Some(item) = &self.onset {
super::super::codec::value_entry(&mut map, "onset", item)?;
}
if let Some(item) = &self.severity {
super::super::codec::value_entry(&mut map, "severity", item)?;
}
if let Some(item) = &self.substance {
serde::ser::SerializeMap::serialize_entry(&mut map, "substance", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for AllergyIntoleranceReaction {
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("AllergyIntoleranceReaction");
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)
}
}