#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AdverseEvent {
pub id: Option<std::string::String>,
pub meta: Option<super::meta::Meta>,
pub implicit_rules: Option<super::primitives::Uri>,
pub language: Option<super::primitives::Code>,
pub text: Option<super::narrative::Narrative>,
pub contained: Vec<super::resource::Resource>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Option<super::identifier::Identifier>,
pub actuality: super::primitives::Code,
pub category: Vec<super::codeable_concept::CodeableConcept>,
pub event: Option<super::codeable_concept::CodeableConcept>,
pub subject: super::reference::Reference,
pub encounter: Option<super::reference::Reference>,
pub date: Option<super::primitives::DateTime>,
pub detected: Option<super::primitives::DateTime>,
pub recorded_date: Option<super::primitives::DateTime>,
pub resulting_condition: Vec<super::reference::Reference>,
pub location: Option<super::reference::Reference>,
pub seriousness: Option<super::codeable_concept::CodeableConcept>,
pub severity: Option<super::codeable_concept::CodeableConcept>,
pub outcome: Option<super::codeable_concept::CodeableConcept>,
pub recorder: Option<super::reference::Reference>,
pub contributor: Vec<super::reference::Reference>,
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(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.identifier {
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.actuality)? {
object.insert(std::string::String::from("actuality"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.actuality)? {
object.insert(std::string::String::from("_actuality"), e);
}
if !self.category.is_empty() {
let mut items = Vec::with_capacity(self.category.len());
for item in &self.category {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.event {
object.insert(
std::string::String::from("event"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
object.insert(
std::string::String::from("subject"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.subject)?),
);
if let Some(item) = &self.encounter {
object.insert(
std::string::String::from("encounter"),
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 let Some(item) = &self.detected {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("detected"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_detected"), e);
}
}
if let Some(item) = &self.recorded_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("recordedDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_recordedDate"), e);
}
}
if !self.resulting_condition.is_empty() {
let mut items = Vec::with_capacity(self.resulting_condition.len());
for item in &self.resulting_condition {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("resultingCondition"),
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.severity {
object.insert(
std::string::String::from("severity"),
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 !self.contributor.is_empty() {
let mut items = Vec::with_capacity(self.contributor.len());
for item in &self.contributor {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contributor"),
super::super::codec::Value::Array(items),
);
}
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_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_actuality: Option<&super::super::codec::Value> = None;
let mut raw_actuality_element: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_event: Option<&super::super::codec::Value> = None;
let mut raw_subject: Option<&super::super::codec::Value> = None;
let mut raw_encounter: 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_detected: Option<&super::super::codec::Value> = None;
let mut raw_detected_element: Option<&super::super::codec::Value> = None;
let mut raw_recorded_date: Option<&super::super::codec::Value> = None;
let mut raw_recorded_date_element: Option<&super::super::codec::Value> = None;
let mut raw_resulting_condition: 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_severity: 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_contributor: 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);
}
"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);
}
"actuality" => {
raw_actuality = Some(value);
}
"_actuality" => {
raw_actuality_element = Some(value);
}
"category" => {
raw_category = Some(value);
}
"event" => {
raw_event = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_element = Some(value);
}
"detected" => {
raw_detected = Some(value);
}
"_detected" => {
raw_detected_element = Some(value);
}
"recordedDate" => {
raw_recorded_date = Some(value);
}
"_recordedDate" => {
raw_recorded_date_element = Some(value);
}
"resultingCondition" => {
raw_resulting_condition = Some(value);
}
"location" => {
raw_location = Some(value);
}
"seriousness" => {
raw_seriousness = Some(value);
}
"severity" => {
raw_severity = Some(value);
}
"outcome" => {
raw_outcome = Some(value);
}
"recorder" => {
raw_recorder = Some(value);
}
"contributor" => {
raw_contributor = 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 = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let 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_actuality = path.with("actuality", |path| {
super::super::codec::Primitive::from_json_parts(
raw_actuality,
raw_actuality_element,
path,
)
})?;
let mut field_category = Vec::new();
if let Some(raw) = raw_category {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_category.push(path.with_index("category", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_event = raw_event
.map(|value| {
path.with("event", |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 = path.with("subject", |path| {
let value = raw_subject
.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_encounter = raw_encounter
.map(|value| {
path.with("encounter", |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 field_detected = match (raw_detected, raw_detected_element) {
(None, None) => None,
(value, element) => Some(path.with("detected", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_recorded_date = match (raw_recorded_date, raw_recorded_date_element) {
(None, None) => None,
(value, element) => Some(path.with("recordedDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_resulting_condition = Vec::new();
if let Some(raw) = raw_resulting_condition {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_resulting_condition.push(path.with_index(
"resultingCondition",
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_severity = raw_severity
.map(|value| {
path.with("severity", |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 mut field_contributor = Vec::new();
if let Some(raw) = raw_contributor {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contributor.push(path.with_index("contributor", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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,
actuality: field_actuality,
category: field_category,
event: field_event,
subject: field_subject,
encounter: field_encounter,
date: field_date,
detected: field_detected,
recorded_date: field_recorded_date,
resulting_condition: field_resulting_condition,
location: field_location,
seriousness: field_seriousness,
severity: field_severity,
outcome: field_outcome,
recorder: field_recorder,
contributor: field_contributor,
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)?;
super::super::codec::element_entry(&mut map, "_actuality", &self.actuality)?;
if let Some(item) = &self.date {
super::super::codec::element_entry(&mut map, "_date", item)?;
}
if let Some(item) = &self.detected {
super::super::codec::element_entry(&mut map, "_detected", 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.recorded_date {
super::super::codec::element_entry(&mut map, "_recordedDate", item)?;
}
super::super::codec::value_entry(&mut map, "actuality", &self.actuality)?;
if !self.category.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if !self.contributor.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contributor", &self.contributor)?;
}
if let Some(item) = &self.date {
super::super::codec::value_entry(&mut map, "date", item)?;
}
if let Some(item) = &self.detected {
super::super::codec::value_entry(&mut map, "detected", item)?;
}
if let Some(item) = &self.encounter {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", item)?;
}
if let Some(item) = &self.event {
serde::ser::SerializeMap::serialize_entry(&mut map, "event", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.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 let Some(item) = &self.recorded_date {
super::super::codec::value_entry(&mut map, "recordedDate", item)?;
}
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 !self.resulting_condition.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"resultingCondition",
&self.resulting_condition,
)?;
}
if let Some(item) = &self.seriousness {
serde::ser::SerializeMap::serialize_entry(&mut map, "seriousness", item)?;
}
if let Some(item) = &self.severity {
serde::ser::SerializeMap::serialize_entry(&mut map, "severity", item)?;
}
if !self.study.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "study", &self.study)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", &self.subject)?;
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)?;
}
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: Vec<AdverseEventSuspectEntityCausality>,
}
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 !self.causality.is_empty() {
let mut items = Vec::with_capacity(self.causality.len());
for item in &self.causality {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("causality"),
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_instance: Option<&super::super::codec::Value> = None;
let mut raw_causality: 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);
}
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 mut field_causality = Vec::new();
if let Some(raw) = raw_causality {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_causality.push(path.with_index("causality", 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,
instance: field_instance,
causality: field_causality,
})
}
}
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 !self.causality.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "causality", &self.causality)?;
}
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)
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AdverseEventSuspectEntityCausality {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub assessment: Option<super::codeable_concept::CodeableConcept>,
pub product_relatedness: Option<super::primitives::String>,
pub author: Option<super::reference::Reference>,
pub method: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for AdverseEventSuspectEntityCausality {
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.assessment {
object.insert(
std::string::String::from("assessment"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.product_relatedness {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("productRelatedness"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_productRelatedness"), e);
}
}
if let Some(item) = &self.author {
object.insert(
std::string::String::from("author"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.method {
object.insert(
std::string::String::from("method"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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_assessment: Option<&super::super::codec::Value> = None;
let mut raw_product_relatedness: Option<&super::super::codec::Value> = None;
let mut raw_product_relatedness_element: Option<&super::super::codec::Value> = None;
let mut raw_author: Option<&super::super::codec::Value> = None;
let mut raw_method: 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);
}
"assessment" => {
raw_assessment = Some(value);
}
"productRelatedness" => {
raw_product_relatedness = Some(value);
}
"_productRelatedness" => {
raw_product_relatedness_element = Some(value);
}
"author" => {
raw_author = Some(value);
}
"method" => {
raw_method = 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_assessment = raw_assessment
.map(|value| {
path.with("assessment", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_product_relatedness =
match (raw_product_relatedness, raw_product_relatedness_element) {
(None, None) => None,
(value, element) => Some(path.with("productRelatedness", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_author = raw_author
.map(|value| {
path.with("author", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_method = raw_method
.map(|value| {
path.with("method", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
assessment: field_assessment,
product_relatedness: field_product_relatedness,
author: field_author,
method: field_method,
})
}
}
impl serde::Serialize for AdverseEventSuspectEntityCausality {
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.product_relatedness {
super::super::codec::element_entry(&mut map, "_productRelatedness", item)?;
}
if let Some(item) = &self.assessment {
serde::ser::SerializeMap::serialize_entry(&mut map, "assessment", item)?;
}
if let Some(item) = &self.author {
serde::ser::SerializeMap::serialize_entry(&mut map, "author", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.method {
serde::ser::SerializeMap::serialize_entry(&mut map, "method", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.product_relatedness {
super::super::codec::value_entry(&mut map, "productRelatedness", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for AdverseEventSuspectEntityCausality {
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("AdverseEventSuspectEntityCausality");
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)
}
}