#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Condition {
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 clinical_status: super::codeable_concept::CodeableConcept,
pub verification_status: Option<super::codeable_concept::CodeableConcept>,
pub category: Vec<super::codeable_concept::CodeableConcept>,
pub severity: Option<super::codeable_concept::CodeableConcept>,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub body_site: Vec<super::codeable_concept::CodeableConcept>,
pub subject: super::reference::Reference,
pub encounter: Option<super::reference::Reference>,
pub onset: Option<ConditionOnset>,
pub abatement: Option<ConditionAbatement>,
pub recorded_date: Option<super::primitives::DateTime>,
pub participant: Vec<ConditionParticipant>,
pub stage: Vec<ConditionStage>,
pub evidence: Vec<super::codeable_reference::CodeableReference>,
pub note: Vec<super::annotation::Annotation>,
}
impl super::super::codec::Json for Condition {
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("Condition")),
);
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),
);
}
object.insert(
std::string::String::from("clinicalStatus"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.clinical_status,
)?),
);
if let Some(item) = &self.verification_status {
object.insert(
std::string::String::from("verificationStatus"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.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.code {
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.body_site.is_empty() {
let mut items = Vec::with_capacity(self.body_site.len());
for item in &self.body_site {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("bodySite"),
super::super::codec::Value::Array(items),
);
}
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.onset {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("onset{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_onset{suffix}"), element);
}
}
if let Some(item) = &self.abatement {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("abatement{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_abatement{suffix}"), element);
}
}
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.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.stage.is_empty() {
let mut items = Vec::with_capacity(self.stage.len());
for item in &self.stage {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("stage"),
super::super::codec::Value::Array(items),
);
}
if !self.evidence.is_empty() {
let mut items = Vec::with_capacity(self.evidence.len());
for item in &self.evidence {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("evidence"),
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_clinical_status: Option<&super::super::codec::Value> = None;
let mut raw_verification_status: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_severity: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_body_site: 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_onset = super::super::codec::ChoiceSlot::default();
let mut raw_abatement = super::super::codec::ChoiceSlot::default();
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_participant: Option<&super::super::codec::Value> = None;
let mut raw_stage: Option<&super::super::codec::Value> = None;
let mut raw_evidence: 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("Condition") {
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);
}
"clinicalStatus" => {
raw_clinical_status = Some(value);
}
"verificationStatus" => {
raw_verification_status = Some(value);
}
"category" => {
raw_category = Some(value);
}
"severity" => {
raw_severity = Some(value);
}
"code" => {
raw_code = Some(value);
}
"bodySite" => {
raw_body_site = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"onsetDateTime" => {
raw_onset.value("DateTime", value, path)?;
}
"_onsetDateTime" => {
raw_onset.element("DateTime", value, path)?;
}
"onsetAge" => {
raw_onset.value("Age", value, path)?;
}
"_onsetAge" => {
raw_onset.element("Age", value, path)?;
}
"onsetPeriod" => {
raw_onset.value("Period", value, path)?;
}
"_onsetPeriod" => {
raw_onset.element("Period", value, path)?;
}
"onsetRange" => {
raw_onset.value("Range", value, path)?;
}
"_onsetRange" => {
raw_onset.element("Range", value, path)?;
}
"onsetString" => {
raw_onset.value("String", value, path)?;
}
"_onsetString" => {
raw_onset.element("String", value, path)?;
}
"abatementDateTime" => {
raw_abatement.value("DateTime", value, path)?;
}
"_abatementDateTime" => {
raw_abatement.element("DateTime", value, path)?;
}
"abatementAge" => {
raw_abatement.value("Age", value, path)?;
}
"_abatementAge" => {
raw_abatement.element("Age", value, path)?;
}
"abatementPeriod" => {
raw_abatement.value("Period", value, path)?;
}
"_abatementPeriod" => {
raw_abatement.element("Period", value, path)?;
}
"abatementRange" => {
raw_abatement.value("Range", value, path)?;
}
"_abatementRange" => {
raw_abatement.element("Range", value, path)?;
}
"abatementString" => {
raw_abatement.value("String", value, path)?;
}
"_abatementString" => {
raw_abatement.element("String", value, path)?;
}
"recordedDate" => {
raw_recorded_date = Some(value);
}
"_recordedDate" => {
raw_recorded_date_element = Some(value);
}
"participant" => {
raw_participant = Some(value);
}
"stage" => {
raw_stage = Some(value);
}
"evidence" => {
raw_evidence = 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_id(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_clinical_status = path.with("clinicalStatus", |path| {
let value = raw_clinical_status
.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_verification_status = raw_verification_status
.map(|value| {
path.with("verificationStatus", |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_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_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_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 mut field_body_site = Vec::new();
if let Some(raw) = raw_body_site {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_body_site.push(path.with_index("bodySite", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
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_onset = match raw_onset.suffix {
None => None,
Some(suffix) => Some(path.with("onset", |path| {
ConditionOnset::from_json_parts(suffix, raw_onset.value, raw_onset.element, path)
})?),
};
let field_abatement = match raw_abatement.suffix {
None => None,
Some(suffix) => Some(path.with("abatement", |path| {
ConditionAbatement::from_json_parts(
suffix,
raw_abatement.value,
raw_abatement.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_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_stage = Vec::new();
if let Some(raw) = raw_stage {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_stage.push(path.with_index("stage", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_evidence = Vec::new();
if let Some(raw) = raw_evidence {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_evidence.push(path.with_index("evidence", 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,
clinical_status: field_clinical_status,
verification_status: field_verification_status,
category: field_category,
severity: field_severity,
code: field_code,
body_site: field_body_site,
subject: field_subject,
encounter: field_encounter,
onset: field_onset,
abatement: field_abatement,
recorded_date: field_recorded_date,
participant: field_participant,
stage: field_stage,
evidence: field_evidence,
note: field_note,
})
}
}
impl serde::Serialize for Condition {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.abatement {
Some(ConditionAbatement::DateTime(inner)) => {
super::super::codec::element_entry(&mut map, "_abatementDateTime", inner)?;
}
Some(ConditionAbatement::String(inner)) => {
super::super::codec::element_entry(&mut map, "_abatementString", inner)?;
}
_ => {}
}
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)?;
}
match &self.onset {
Some(ConditionOnset::DateTime(inner)) => {
super::super::codec::element_entry(&mut map, "_onsetDateTime", inner)?;
}
Some(ConditionOnset::String(inner)) => {
super::super::codec::element_entry(&mut map, "_onsetString", inner)?;
}
_ => {}
}
if let Some(item) = &self.recorded_date {
super::super::codec::element_entry(&mut map, "_recordedDate", item)?;
}
match &self.abatement {
Some(ConditionAbatement::Age(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"abatementAge",
inner.as_ref(),
)?;
}
Some(ConditionAbatement::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "abatementDateTime", inner)?;
}
Some(ConditionAbatement::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"abatementPeriod",
inner.as_ref(),
)?;
}
Some(ConditionAbatement::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"abatementRange",
inner.as_ref(),
)?;
}
Some(ConditionAbatement::String(inner)) => {
super::super::codec::value_entry(&mut map, "abatementString", inner)?;
}
None => {}
}
if !self.body_site.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "bodySite", &self.body_site)?;
}
if !self.category.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
}
serde::ser::SerializeMap::serialize_entry(
&mut map,
"clinicalStatus",
&self.clinical_status,
)?;
if let Some(item) = &self.code {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", item)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.encounter {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", item)?;
}
if !self.evidence.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "evidence", &self.evidence)?;
}
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.meta {
serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
match &self.onset {
Some(ConditionOnset::Age(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "onsetAge", inner.as_ref())?;
}
Some(ConditionOnset::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "onsetDateTime", inner)?;
}
Some(ConditionOnset::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "onsetPeriod", inner.as_ref())?;
}
Some(ConditionOnset::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "onsetRange", inner.as_ref())?;
}
Some(ConditionOnset::String(inner)) => {
super::super::codec::value_entry(&mut map, "onsetString", inner)?;
}
None => {}
}
if !self.participant.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "participant", &self.participant)?;
}
if let Some(item) = &self.recorded_date {
super::super::codec::value_entry(&mut map, "recordedDate", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "Condition")?;
if let Some(item) = &self.severity {
serde::ser::SerializeMap::serialize_entry(&mut map, "severity", item)?;
}
if !self.stage.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "stage", &self.stage)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", &self.subject)?;
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.verification_status {
serde::ser::SerializeMap::serialize_entry(&mut map, "verificationStatus", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Condition {
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("Condition");
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 ConditionAbatement {
DateTime(super::primitives::DateTime),
Age(Box<super::age::Age>),
Period(Box<super::period::Period>),
Range(Box<super::range::Range>),
String(super::primitives::String),
}
impl ConditionAbatement {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Age(inner) => Ok((
"Age",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Range(inner) => Ok((
"Range",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::String(inner) => Ok((
"String",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Age" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Age(Box::new(inner)))
}
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
"Range" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Range(Box::new(inner)))
}
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConditionOnset {
DateTime(super::primitives::DateTime),
Age(Box<super::age::Age>),
Period(Box<super::period::Period>),
Range(Box<super::range::Range>),
String(super::primitives::String),
}
impl ConditionOnset {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Age(inner) => Ok((
"Age",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Range(inner) => Ok((
"Range",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::String(inner) => Ok((
"String",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Age" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Age(Box::new(inner)))
}
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
"Range" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Range(Box::new(inner)))
}
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ConditionParticipant {
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 ConditionParticipant {
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 ConditionParticipant {
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 ConditionParticipant {
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("ConditionParticipant");
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 ConditionStage {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub summary: Option<super::codeable_concept::CodeableConcept>,
pub assessment: Vec<super::reference::Reference>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ConditionStage {
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.summary {
object.insert(
std::string::String::from("summary"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.assessment.is_empty() {
let mut items = Vec::with_capacity(self.assessment.len());
for item in &self.assessment {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("assessment"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.r#type {
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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_summary: Option<&super::super::codec::Value> = None;
let mut raw_assessment: Option<&super::super::codec::Value> = None;
let mut raw_type: 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);
}
"summary" => {
raw_summary = Some(value);
}
"assessment" => {
raw_assessment = Some(value);
}
"type" => {
raw_type = 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_summary = raw_summary
.map(|value| {
path.with("summary", |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_assessment = Vec::new();
if let Some(raw) = raw_assessment {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_assessment.push(path.with_index("assessment", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_type = raw_type
.map(|value| {
path.with("type", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
summary: field_summary,
assessment: field_assessment,
r#type: field_type,
})
}
}
impl serde::Serialize for ConditionStage {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.assessment.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "assessment", &self.assessment)?;
}
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,
)?;
}
if let Some(item) = &self.summary {
serde::ser::SerializeMap::serialize_entry(&mut map, "summary", item)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ConditionStage {
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("ConditionStage");
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)
}
}