#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AdverseEvent {
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: Option<super::identifier::Identifier>,
pub category: Option<super::primitives::Code>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub subject: Option<super::reference::Reference>,
pub date: Option<super::primitives::DateTime>,
pub reaction: Vec<super::reference::Reference>,
pub location: Option<super::reference::Reference>,
pub seriousness: Option<super::codeable_concept::CodeableConcept>,
pub outcome: Option<super::codeable_concept::CodeableConcept>,
pub recorder: Option<super::reference::Reference>,
pub event_participant: Option<super::reference::Reference>,
pub description: Option<super::primitives::String>,
pub suspect_entity: Vec<AdverseEventSuspectEntity>,
pub subject_medical_history: Vec<super::reference::Reference>,
pub reference_document: Vec<super::reference::Reference>,
pub study: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for AdverseEvent {
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("AdverseEvent")),
);
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 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.category {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("category"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_category"), 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.subject {
object.insert(
std::string::String::from("subject"),
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);
}
}
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),
);
}
if let Some(item) = &self.location {
object.insert(
std::string::String::from("location"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.seriousness {
object.insert(
std::string::String::from("seriousness"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.outcome {
object.insert(
std::string::String::from("outcome"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.event_participant {
object.insert(
std::string::String::from("eventParticipant"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
if !self.suspect_entity.is_empty() {
let mut items = Vec::with_capacity(self.suspect_entity.len());
for item in &self.suspect_entity {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("suspectEntity"),
super::super::codec::Value::Array(items),
);
}
if !self.subject_medical_history.is_empty() {
let mut items = Vec::with_capacity(self.subject_medical_history.len());
for item in &self.subject_medical_history {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("subjectMedicalHistory"),
super::super::codec::Value::Array(items),
);
}
if !self.reference_document.is_empty() {
let mut items = Vec::with_capacity(self.reference_document.len());
for item in &self.reference_document {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("referenceDocument"),
super::super::codec::Value::Array(items),
);
}
if !self.study.is_empty() {
let mut items = Vec::with_capacity(self.study.len());
for item in &self.study {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("study"),
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_category: Option<&super::super::codec::Value> = None;
let mut raw_category_element: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_subject: 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;
let mut raw_reaction: Option<&super::super::codec::Value> = None;
let mut raw_location: Option<&super::super::codec::Value> = None;
let mut raw_seriousness: Option<&super::super::codec::Value> = None;
let mut raw_outcome: Option<&super::super::codec::Value> = None;
let mut raw_recorder: Option<&super::super::codec::Value> = None;
let mut raw_event_participant: 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_suspect_entity: Option<&super::super::codec::Value> = None;
let mut raw_subject_medical_history: Option<&super::super::codec::Value> = None;
let mut raw_reference_document: Option<&super::super::codec::Value> = None;
let mut raw_study: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("AdverseEvent") {
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);
}
"category" => {
raw_category = Some(value);
}
"_category" => {
raw_category_element = Some(value);
}
"type" => {
raw_type = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_element = Some(value);
}
"reaction" => {
raw_reaction = Some(value);
}
"location" => {
raw_location = Some(value);
}
"seriousness" => {
raw_seriousness = Some(value);
}
"outcome" => {
raw_outcome = Some(value);
}
"recorder" => {
raw_recorder = Some(value);
}
"eventParticipant" => {
raw_event_participant = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"suspectEntity" => {
raw_suspect_entity = Some(value);
}
"subjectMedicalHistory" => {
raw_subject_medical_history = Some(value);
}
"referenceDocument" => {
raw_reference_document = Some(value);
}
"study" => {
raw_study = 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 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_category = match (raw_category, raw_category_element) {
(None, None) => None,
(value, element) => Some(path.with("category", |path| {
super::super::codec::Primitive::from_json_parts(value, 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_subject = raw_subject
.map(|value| {
path.with("subject", |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)
})?),
};
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,
)
})?);
}
}
let field_location = raw_location
.map(|value| {
path.with("location", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_seriousness = raw_seriousness
.map(|value| {
path.with("seriousness", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_outcome = raw_outcome
.map(|value| {
path.with("outcome", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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_event_participant = raw_event_participant
.map(|value| {
path.with("eventParticipant", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_suspect_entity = Vec::new();
if let Some(raw) = raw_suspect_entity {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_suspect_entity.push(path.with_index("suspectEntity", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_subject_medical_history = Vec::new();
if let Some(raw) = raw_subject_medical_history {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_subject_medical_history.push(path.with_index(
"subjectMedicalHistory",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_reference_document = Vec::new();
if let Some(raw) = raw_reference_document {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reference_document.push(path.with_index(
"referenceDocument",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_study = Vec::new();
if let Some(raw) = raw_study {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_study.push(path.with_index("study", 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,
category: field_category,
r#type: field_type,
subject: field_subject,
date: field_date,
reaction: field_reaction,
location: field_location,
seriousness: field_seriousness,
outcome: field_outcome,
recorder: field_recorder,
event_participant: field_event_participant,
description: field_description,
suspect_entity: field_suspect_entity,
subject_medical_history: field_subject_medical_history,
reference_document: field_reference_document,
study: field_study,
})
}
}
impl serde::Serialize for AdverseEvent {
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.category {
super::super::codec::element_entry(&mut map, "_category", item)?;
}
if let Some(item) = &self.date {
super::super::codec::element_entry(&mut map, "_date", item)?;
}
if let Some(item) = &self.description {
super::super::codec::element_entry(&mut map, "_description", 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.category {
super::super::codec::value_entry(&mut map, "category", item)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.date {
super::super::codec::value_entry(&mut map, "date", item)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if let Some(item) = &self.event_participant {
serde::ser::SerializeMap::serialize_entry(&mut map, "eventParticipant", 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 let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.location {
serde::ser::SerializeMap::serialize_entry(&mut map, "location", 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.outcome {
serde::ser::SerializeMap::serialize_entry(&mut map, "outcome", item)?;
}
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)?;
}
if !self.reference_document.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"referenceDocument",
&self.reference_document,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "AdverseEvent")?;
if let Some(item) = &self.seriousness {
serde::ser::SerializeMap::serialize_entry(&mut map, "seriousness", item)?;
}
if !self.study.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "study", &self.study)?;
}
if let Some(item) = &self.subject {
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", item)?;
}
if !self.subject_medical_history.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"subjectMedicalHistory",
&self.subject_medical_history,
)?;
}
if !self.suspect_entity.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"suspectEntity",
&self.suspect_entity,
)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for AdverseEvent {
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("AdverseEvent");
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 AdverseEventSuspectEntity {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub instance: super::reference::Reference,
pub causality: Option<super::primitives::Code>,
pub causality_assessment: Option<super::codeable_concept::CodeableConcept>,
pub causality_product_relatedness: Option<super::primitives::String>,
pub causality_method: Option<super::codeable_concept::CodeableConcept>,
pub causality_author: Option<super::reference::Reference>,
pub causality_result: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for AdverseEventSuspectEntity {
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("instance"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.instance)?),
);
if let Some(item) = &self.causality {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("causality"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_causality"), e);
}
}
if let Some(item) = &self.causality_assessment {
object.insert(
std::string::String::from("causalityAssessment"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.causality_product_relatedness {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("causalityProductRelatedness"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_causalityProductRelatedness"), e);
}
}
if let Some(item) = &self.causality_method {
object.insert(
std::string::String::from("causalityMethod"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.causality_author {
object.insert(
std::string::String::from("causalityAuthor"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.causality_result {
object.insert(
std::string::String::from("causalityResult"),
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_instance: Option<&super::super::codec::Value> = None;
let mut raw_causality: Option<&super::super::codec::Value> = None;
let mut raw_causality_element: Option<&super::super::codec::Value> = None;
let mut raw_causality_assessment: Option<&super::super::codec::Value> = None;
let mut raw_causality_product_relatedness: Option<&super::super::codec::Value> = None;
let mut raw_causality_product_relatedness_element: Option<&super::super::codec::Value> =
None;
let mut raw_causality_method: Option<&super::super::codec::Value> = None;
let mut raw_causality_author: Option<&super::super::codec::Value> = None;
let mut raw_causality_result: 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);
}
"instance" => {
raw_instance = Some(value);
}
"causality" => {
raw_causality = Some(value);
}
"_causality" => {
raw_causality_element = Some(value);
}
"causalityAssessment" => {
raw_causality_assessment = Some(value);
}
"causalityProductRelatedness" => {
raw_causality_product_relatedness = Some(value);
}
"_causalityProductRelatedness" => {
raw_causality_product_relatedness_element = Some(value);
}
"causalityMethod" => {
raw_causality_method = Some(value);
}
"causalityAuthor" => {
raw_causality_author = Some(value);
}
"causalityResult" => {
raw_causality_result = 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_instance = path.with("instance", |path| {
let value = raw_instance
.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_causality = match (raw_causality, raw_causality_element) {
(None, None) => None,
(value, element) => Some(path.with("causality", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_causality_assessment = raw_causality_assessment
.map(|value| {
path.with("causalityAssessment", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_causality_product_relatedness = match (
raw_causality_product_relatedness,
raw_causality_product_relatedness_element,
) {
(None, None) => None,
(value, element) => Some(path.with("causalityProductRelatedness", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_causality_method = raw_causality_method
.map(|value| {
path.with("causalityMethod", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_causality_author = raw_causality_author
.map(|value| {
path.with("causalityAuthor", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_causality_result = raw_causality_result
.map(|value| {
path.with("causalityResult", |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,
instance: field_instance,
causality: field_causality,
causality_assessment: field_causality_assessment,
causality_product_relatedness: field_causality_product_relatedness,
causality_method: field_causality_method,
causality_author: field_causality_author,
causality_result: field_causality_result,
})
}
}
impl serde::Serialize for AdverseEventSuspectEntity {
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.causality {
super::super::codec::element_entry(&mut map, "_causality", item)?;
}
if let Some(item) = &self.causality_product_relatedness {
super::super::codec::element_entry(&mut map, "_causalityProductRelatedness", item)?;
}
if let Some(item) = &self.causality {
super::super::codec::value_entry(&mut map, "causality", item)?;
}
if let Some(item) = &self.causality_assessment {
serde::ser::SerializeMap::serialize_entry(&mut map, "causalityAssessment", item)?;
}
if let Some(item) = &self.causality_author {
serde::ser::SerializeMap::serialize_entry(&mut map, "causalityAuthor", item)?;
}
if let Some(item) = &self.causality_method {
serde::ser::SerializeMap::serialize_entry(&mut map, "causalityMethod", item)?;
}
if let Some(item) = &self.causality_product_relatedness {
super::super::codec::value_entry(&mut map, "causalityProductRelatedness", item)?;
}
if let Some(item) = &self.causality_result {
serde::ser::SerializeMap::serialize_entry(&mut map, "causalityResult", 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)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "instance", &self.instance)?;
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for AdverseEventSuspectEntity {
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("AdverseEventSuspectEntity");
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)
}
}