#[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: Vec<super::identifier::Identifier>,
pub status: super::primitives::Code,
pub actuality: super::primitives::Code,
pub category: Vec<super::codeable_concept::CodeableConcept>,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub subject: super::reference::Reference,
pub encounter: Option<super::reference::Reference>,
pub effect: Option<AdverseEventEffect>,
pub detected: Option<super::primitives::DateTime>,
pub recorded_date: Option<super::primitives::DateTime>,
pub resulting_effect: Vec<super::codeable_reference::CodeableReference>,
pub location: Option<super::reference::Reference>,
pub seriousness: Option<super::codeable_concept::CodeableConcept>,
pub outcome: Vec<super::codeable_concept::CodeableConcept>,
pub recorder: Option<super::reference::Reference>,
pub participant: Vec<AdverseEventParticipant>,
pub study: Vec<super::reference::Reference>,
pub expected_in_research_study: Option<super::primitives::Boolean>,
pub suspect_entity: Vec<AdverseEventSuspectEntity>,
pub contributing_factor: Vec<super::codeable_reference::CodeableReference>,
pub preventive_action: Vec<super::codeable_reference::CodeableReference>,
pub mitigating_action: Vec<super::codeable_reference::CodeableReference>,
pub supporting_info: Vec<super::codeable_reference::CodeableReference>,
pub note: Vec<super::annotation::Annotation>,
}
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 !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(v) = super::super::codec::Primitive::value_json(&self.status)? {
object.insert(std::string::String::from("status"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.status)? {
object.insert(std::string::String::from("_status"), e);
}
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.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("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.effect {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("effect{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_effect{suffix}"), element);
}
}
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_effect.is_empty() {
let mut items = Vec::with_capacity(self.resulting_effect.len());
for item in &self.resulting_effect {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("resultingEffect"),
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 !self.outcome.is_empty() {
let mut items = Vec::with_capacity(self.outcome.len());
for item in &self.outcome {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("outcome"),
super::super::codec::Value::Array(items),
);
}
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.participant.is_empty() {
let mut items = Vec::with_capacity(self.participant.len());
for item in &self.participant {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("participant"),
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),
);
}
if let Some(item) = &self.expected_in_research_study {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("expectedInResearchStudy"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_expectedInResearchStudy"), 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.contributing_factor.is_empty() {
let mut items = Vec::with_capacity(self.contributing_factor.len());
for item in &self.contributing_factor {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contributingFactor"),
super::super::codec::Value::Array(items),
);
}
if !self.preventive_action.is_empty() {
let mut items = Vec::with_capacity(self.preventive_action.len());
for item in &self.preventive_action {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("preventiveAction"),
super::super::codec::Value::Array(items),
);
}
if !self.mitigating_action.is_empty() {
let mut items = Vec::with_capacity(self.mitigating_action.len());
for item in &self.mitigating_action {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("mitigatingAction"),
super::super::codec::Value::Array(items),
);
}
if !self.supporting_info.is_empty() {
let mut items = Vec::with_capacity(self.supporting_info.len());
for item in &self.supporting_info {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("supportingInfo"),
super::super::codec::Value::Array(items),
);
}
if !self.note.is_empty() {
let mut items = Vec::with_capacity(self.note.len());
for item in &self.note {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("note"),
super::super::codec::Value::Array(items),
);
}
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_status: Option<&super::super::codec::Value> = None;
let mut raw_status_element: 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_code: 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_effect = super::super::codec::ChoiceSlot::default();
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_effect: 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_participant: Option<&super::super::codec::Value> = None;
let mut raw_study: Option<&super::super::codec::Value> = None;
let mut raw_expected_in_research_study: Option<&super::super::codec::Value> = None;
let mut raw_expected_in_research_study_element: Option<&super::super::codec::Value> = None;
let mut raw_suspect_entity: Option<&super::super::codec::Value> = None;
let mut raw_contributing_factor: Option<&super::super::codec::Value> = None;
let mut raw_preventive_action: Option<&super::super::codec::Value> = None;
let mut raw_mitigating_action: Option<&super::super::codec::Value> = None;
let mut raw_supporting_info: 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() {
"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);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"actuality" => {
raw_actuality = Some(value);
}
"_actuality" => {
raw_actuality_element = Some(value);
}
"category" => {
raw_category = Some(value);
}
"code" => {
raw_code = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"effectDateTime" => {
raw_effect.value("DateTime", value, path)?;
}
"_effectDateTime" => {
raw_effect.element("DateTime", value, path)?;
}
"effectPeriod" => {
raw_effect.value("Period", value, path)?;
}
"_effectPeriod" => {
raw_effect.element("Period", value, path)?;
}
"detected" => {
raw_detected = Some(value);
}
"_detected" => {
raw_detected_element = Some(value);
}
"recordedDate" => {
raw_recorded_date = Some(value);
}
"_recordedDate" => {
raw_recorded_date_element = Some(value);
}
"resultingEffect" => {
raw_resulting_effect = Some(value);
}
"location" => {
raw_location = Some(value);
}
"seriousness" => {
raw_seriousness = Some(value);
}
"outcome" => {
raw_outcome = Some(value);
}
"recorder" => {
raw_recorder = Some(value);
}
"participant" => {
raw_participant = Some(value);
}
"study" => {
raw_study = Some(value);
}
"expectedInResearchStudy" => {
raw_expected_in_research_study = Some(value);
}
"_expectedInResearchStudy" => {
raw_expected_in_research_study_element = Some(value);
}
"suspectEntity" => {
raw_suspect_entity = Some(value);
}
"contributingFactor" => {
raw_contributing_factor = Some(value);
}
"preventiveAction" => {
raw_preventive_action = Some(value);
}
"mitigatingAction" => {
raw_mitigating_action = Some(value);
}
"supportingInfo" => {
raw_supporting_info = 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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let 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_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
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_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_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_effect = match raw_effect.suffix {
None => None,
Some(suffix) => Some(path.with("effect", |path| {
AdverseEventEffect::from_json_parts(
suffix,
raw_effect.value,
raw_effect.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_effect = Vec::new();
if let Some(raw) = raw_resulting_effect {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_resulting_effect.push(path.with_index("resultingEffect", 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 mut field_outcome = Vec::new();
if let Some(raw) = raw_outcome {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_outcome.push(path.with_index("outcome", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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 mut field_participant = Vec::new();
if let Some(raw) = raw_participant {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_participant.push(path.with_index("participant", 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,
)
})?);
}
}
let field_expected_in_research_study = match (
raw_expected_in_research_study,
raw_expected_in_research_study_element,
) {
(None, None) => None,
(value, element) => Some(path.with("expectedInResearchStudy", |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_contributing_factor = Vec::new();
if let Some(raw) = raw_contributing_factor {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contributing_factor.push(path.with_index(
"contributingFactor",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_preventive_action = Vec::new();
if let Some(raw) = raw_preventive_action {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_preventive_action.push(path.with_index(
"preventiveAction",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_mitigating_action = Vec::new();
if let Some(raw) = raw_mitigating_action {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_mitigating_action.push(path.with_index(
"mitigatingAction",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_supporting_info = Vec::new();
if let Some(raw) = raw_supporting_info {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_supporting_info.push(path.with_index("supportingInfo", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_note = Vec::new();
if let Some(raw) = raw_note {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_note.push(path.with_index("note", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
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,
status: field_status,
actuality: field_actuality,
category: field_category,
code: field_code,
subject: field_subject,
encounter: field_encounter,
effect: field_effect,
detected: field_detected,
recorded_date: field_recorded_date,
resulting_effect: field_resulting_effect,
location: field_location,
seriousness: field_seriousness,
outcome: field_outcome,
recorder: field_recorder,
participant: field_participant,
study: field_study,
expected_in_research_study: field_expected_in_research_study,
suspect_entity: field_suspect_entity,
contributing_factor: field_contributing_factor,
preventive_action: field_preventive_action,
mitigating_action: field_mitigating_action,
supporting_info: field_supporting_info,
note: field_note,
})
}
}
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.detected {
super::super::codec::element_entry(&mut map, "_detected", item)?;
}
if let Some(AdverseEventEffect::DateTime(inner)) = &self.effect {
super::super::codec::element_entry(&mut map, "_effectDateTime", inner)?;
}
if let Some(item) = &self.expected_in_research_study {
super::super::codec::element_entry(&mut map, "_expectedInResearchStudy", 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::element_entry(&mut map, "_status", &self.status)?;
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 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 !self.contributing_factor.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"contributingFactor",
&self.contributing_factor,
)?;
}
if let Some(item) = &self.detected {
super::super::codec::value_entry(&mut map, "detected", item)?;
}
match &self.effect {
Some(AdverseEventEffect::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "effectDateTime", inner)?;
}
Some(AdverseEventEffect::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"effectPeriod",
inner.as_ref(),
)?;
}
None => {}
}
if let Some(item) = &self.encounter {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", item)?;
}
if let Some(item) = &self.expected_in_research_study {
super::super::codec::value_entry(&mut map, "expectedInResearchStudy", 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.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.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.mitigating_action.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"mitigatingAction",
&self.mitigating_action,
)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
if !self.outcome.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "outcome", &self.outcome)?;
}
if !self.participant.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "participant", &self.participant)?;
}
if !self.preventive_action.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"preventiveAction",
&self.preventive_action,
)?;
}
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)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "AdverseEvent")?;
if !self.resulting_effect.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"resultingEffect",
&self.resulting_effect,
)?;
}
if let Some(item) = &self.seriousness {
serde::ser::SerializeMap::serialize_entry(&mut map, "seriousness", item)?;
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
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.supporting_info.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"supportingInfo",
&self.supporting_info,
)?;
}
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, PartialEq, Eq)]
pub enum AdverseEventEffect {
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
}
impl AdverseEventEffect {
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::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"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)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AdverseEventParticipant {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub function: Option<super::codeable_concept::CodeableConcept>,
pub actor: super::reference::Reference,
}
impl super::super::codec::Json for AdverseEventParticipant {
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.function {
object.insert(
std::string::String::from("function"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
object.insert(
std::string::String::from("actor"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.actor)?),
);
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_function: Option<&super::super::codec::Value> = None;
let mut raw_actor: 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);
}
"function" => {
raw_function = Some(value);
}
"actor" => {
raw_actor = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_function = raw_function
.map(|value| {
path.with("function", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_actor = path.with("actor", |path| {
let value = raw_actor
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
function: field_function,
actor: field_actor,
})
}
}
impl serde::Serialize for AdverseEventParticipant {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "actor", &self.actor)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.function {
serde::ser::SerializeMap::serialize_entry(&mut map, "function", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for AdverseEventParticipant {
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("AdverseEventParticipant");
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::codeable_reference::CodeableReference,
pub causality: Option<AdverseEventSuspectEntityCausality>,
pub occurrence: Option<AdverseEventSuspectEntityOccurrence>,
}
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 {
object.insert(
std::string::String::from("causality"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.occurrence {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("occurrence{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_occurrence{suffix}"), element);
}
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_instance: Option<&super::super::codec::Value> = None;
let mut raw_causality: Option<&super::super::codec::Value> = None;
let mut raw_occurrence = super::super::codec::ChoiceSlot::default();
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"instance" => {
raw_instance = Some(value);
}
"causality" => {
raw_causality = Some(value);
}
"occurrenceDateTime" => {
raw_occurrence.value("DateTime", value, path)?;
}
"_occurrenceDateTime" => {
raw_occurrence.element("DateTime", value, path)?;
}
"occurrencePeriod" => {
raw_occurrence.value("Period", value, path)?;
}
"_occurrencePeriod" => {
raw_occurrence.element("Period", value, path)?;
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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 = raw_causality
.map(|value| {
path.with("causality", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_occurrence = match raw_occurrence.suffix {
None => None,
Some(suffix) => Some(path.with("occurrence", |path| {
AdverseEventSuspectEntityOccurrence::from_json_parts(
suffix,
raw_occurrence.value,
raw_occurrence.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
instance: field_instance,
causality: field_causality,
occurrence: field_occurrence,
})
}
}
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(AdverseEventSuspectEntityOccurrence::DateTime(inner)) = &self.occurrence {
super::super::codec::element_entry(&mut map, "_occurrenceDateTime", inner)?;
}
if let Some(item) = &self.causality {
serde::ser::SerializeMap::serialize_entry(&mut map, "causality", 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,
)?;
}
match &self.occurrence {
Some(AdverseEventSuspectEntityOccurrence::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "occurrenceDateTime", inner)?;
}
Some(AdverseEventSuspectEntityOccurrence::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"occurrencePeriod",
inner.as_ref(),
)?;
}
None => {}
}
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_method: Option<super::codeable_concept::CodeableConcept>,
pub entity_relatedness: Option<super::codeable_concept::CodeableConcept>,
pub author: Option<super::reference::Reference>,
}
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_method {
object.insert(
std::string::String::from("assessmentMethod"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.entity_relatedness {
object.insert(
std::string::String::from("entityRelatedness"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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)?),
);
}
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_method: Option<&super::super::codec::Value> = None;
let mut raw_entity_relatedness: Option<&super::super::codec::Value> = None;
let mut raw_author: 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);
}
"assessmentMethod" => {
raw_assessment_method = Some(value);
}
"entityRelatedness" => {
raw_entity_relatedness = Some(value);
}
"author" => {
raw_author = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_assessment_method = raw_assessment_method
.map(|value| {
path.with("assessmentMethod", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_entity_relatedness = raw_entity_relatedness
.map(|value| {
path.with("entityRelatedness", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
assessment_method: field_assessment_method,
entity_relatedness: field_entity_relatedness,
author: field_author,
})
}
}
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.assessment_method {
serde::ser::SerializeMap::serialize_entry(&mut map, "assessmentMethod", item)?;
}
if let Some(item) = &self.author {
serde::ser::SerializeMap::serialize_entry(&mut map, "author", item)?;
}
if let Some(item) = &self.entity_relatedness {
serde::ser::SerializeMap::serialize_entry(&mut map, "entityRelatedness", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
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)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AdverseEventSuspectEntityOccurrence {
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
}
impl AdverseEventSuspectEntityOccurrence {
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::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"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)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}