#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Immunization {
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 status_reason: Option<super::codeable_concept::CodeableConcept>,
pub vaccine_code: super::codeable_concept::CodeableConcept,
pub patient: super::reference::Reference,
pub encounter: Option<super::reference::Reference>,
pub occurrence: ImmunizationOccurrence,
pub recorded: Option<super::primitives::DateTime>,
pub primary_source: Option<super::primitives::Boolean>,
pub report_origin: Option<super::codeable_concept::CodeableConcept>,
pub location: Option<super::reference::Reference>,
pub manufacturer: Option<super::reference::Reference>,
pub lot_number: Option<super::primitives::String>,
pub expiration_date: Option<super::primitives::Date>,
pub site: Option<super::codeable_concept::CodeableConcept>,
pub route: Option<super::codeable_concept::CodeableConcept>,
pub dose_quantity: Option<super::quantity::Quantity>,
pub performer: Vec<ImmunizationPerformer>,
pub note: Vec<super::annotation::Annotation>,
pub reason_code: Vec<super::codeable_concept::CodeableConcept>,
pub reason_reference: Vec<super::reference::Reference>,
pub is_subpotent: Option<super::primitives::Boolean>,
pub subpotent_reason: Vec<super::codeable_concept::CodeableConcept>,
pub education: Vec<ImmunizationEducation>,
pub program_eligibility: Vec<super::codeable_concept::CodeableConcept>,
pub funding_source: Option<super::codeable_concept::CodeableConcept>,
pub reaction: Vec<ImmunizationReaction>,
pub protocol_applied: Vec<ImmunizationProtocolApplied>,
}
impl super::super::codec::Json for Immunization {
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("Immunization")),
);
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(item) = &self.status_reason {
object.insert(
std::string::String::from("statusReason"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
object.insert(
std::string::String::from("vaccineCode"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.vaccine_code,
)?),
);
object.insert(
std::string::String::from("patient"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.patient)?),
);
if let Some(item) = &self.encounter {
object.insert(
std::string::String::from("encounter"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
let (suffix, value, element) = self.occurrence.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);
}
if let Some(item) = &self.recorded {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("recorded"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_recorded"), e);
}
}
if let Some(item) = &self.primary_source {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("primarySource"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_primarySource"), e);
}
}
if let Some(item) = &self.report_origin {
object.insert(
std::string::String::from("reportOrigin"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.manufacturer {
object.insert(
std::string::String::from("manufacturer"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.lot_number {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("lotNumber"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_lotNumber"), e);
}
}
if let Some(item) = &self.expiration_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("expirationDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_expirationDate"), e);
}
}
if let Some(item) = &self.site {
object.insert(
std::string::String::from("site"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.route {
object.insert(
std::string::String::from("route"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.dose_quantity {
object.insert(
std::string::String::from("doseQuantity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.performer.is_empty() {
let mut items = Vec::with_capacity(self.performer.len());
for item in &self.performer {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("performer"),
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),
);
}
if !self.reason_code.is_empty() {
let mut items = Vec::with_capacity(self.reason_code.len());
for item in &self.reason_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reasonCode"),
super::super::codec::Value::Array(items),
);
}
if !self.reason_reference.is_empty() {
let mut items = Vec::with_capacity(self.reason_reference.len());
for item in &self.reason_reference {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reasonReference"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.is_subpotent {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("isSubpotent"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_isSubpotent"), e);
}
}
if !self.subpotent_reason.is_empty() {
let mut items = Vec::with_capacity(self.subpotent_reason.len());
for item in &self.subpotent_reason {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("subpotentReason"),
super::super::codec::Value::Array(items),
);
}
if !self.education.is_empty() {
let mut items = Vec::with_capacity(self.education.len());
for item in &self.education {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("education"),
super::super::codec::Value::Array(items),
);
}
if !self.program_eligibility.is_empty() {
let mut items = Vec::with_capacity(self.program_eligibility.len());
for item in &self.program_eligibility {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("programEligibility"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.funding_source {
object.insert(
std::string::String::from("fundingSource"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.reaction.is_empty() {
let mut items = Vec::with_capacity(self.reaction.len());
for item in &self.reaction {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reaction"),
super::super::codec::Value::Array(items),
);
}
if !self.protocol_applied.is_empty() {
let mut items = Vec::with_capacity(self.protocol_applied.len());
for item in &self.protocol_applied {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("protocolApplied"),
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_status_reason: Option<&super::super::codec::Value> = None;
let mut raw_vaccine_code: Option<&super::super::codec::Value> = None;
let mut raw_patient: Option<&super::super::codec::Value> = None;
let mut raw_encounter: Option<&super::super::codec::Value> = None;
let mut raw_occurrence = super::super::codec::ChoiceSlot::default();
let mut raw_recorded: Option<&super::super::codec::Value> = None;
let mut raw_recorded_element: Option<&super::super::codec::Value> = None;
let mut raw_primary_source: Option<&super::super::codec::Value> = None;
let mut raw_primary_source_element: Option<&super::super::codec::Value> = None;
let mut raw_report_origin: Option<&super::super::codec::Value> = None;
let mut raw_location: Option<&super::super::codec::Value> = None;
let mut raw_manufacturer: Option<&super::super::codec::Value> = None;
let mut raw_lot_number: Option<&super::super::codec::Value> = None;
let mut raw_lot_number_element: Option<&super::super::codec::Value> = None;
let mut raw_expiration_date: Option<&super::super::codec::Value> = None;
let mut raw_expiration_date_element: Option<&super::super::codec::Value> = None;
let mut raw_site: Option<&super::super::codec::Value> = None;
let mut raw_route: Option<&super::super::codec::Value> = None;
let mut raw_dose_quantity: Option<&super::super::codec::Value> = None;
let mut raw_performer: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_reason_code: Option<&super::super::codec::Value> = None;
let mut raw_reason_reference: Option<&super::super::codec::Value> = None;
let mut raw_is_subpotent: Option<&super::super::codec::Value> = None;
let mut raw_is_subpotent_element: Option<&super::super::codec::Value> = None;
let mut raw_subpotent_reason: Option<&super::super::codec::Value> = None;
let mut raw_education: Option<&super::super::codec::Value> = None;
let mut raw_program_eligibility: Option<&super::super::codec::Value> = None;
let mut raw_funding_source: Option<&super::super::codec::Value> = None;
let mut raw_reaction: Option<&super::super::codec::Value> = None;
let mut raw_protocol_applied: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("Immunization") {
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);
}
"statusReason" => {
raw_status_reason = Some(value);
}
"vaccineCode" => {
raw_vaccine_code = Some(value);
}
"patient" => {
raw_patient = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"occurrenceDateTime" => {
raw_occurrence.value("DateTime", value, path)?;
}
"_occurrenceDateTime" => {
raw_occurrence.element("DateTime", value, path)?;
}
"occurrenceString" => {
raw_occurrence.value("String", value, path)?;
}
"_occurrenceString" => {
raw_occurrence.element("String", value, path)?;
}
"recorded" => {
raw_recorded = Some(value);
}
"_recorded" => {
raw_recorded_element = Some(value);
}
"primarySource" => {
raw_primary_source = Some(value);
}
"_primarySource" => {
raw_primary_source_element = Some(value);
}
"reportOrigin" => {
raw_report_origin = Some(value);
}
"location" => {
raw_location = Some(value);
}
"manufacturer" => {
raw_manufacturer = Some(value);
}
"lotNumber" => {
raw_lot_number = Some(value);
}
"_lotNumber" => {
raw_lot_number_element = Some(value);
}
"expirationDate" => {
raw_expiration_date = Some(value);
}
"_expirationDate" => {
raw_expiration_date_element = Some(value);
}
"site" => {
raw_site = Some(value);
}
"route" => {
raw_route = Some(value);
}
"doseQuantity" => {
raw_dose_quantity = Some(value);
}
"performer" => {
raw_performer = Some(value);
}
"note" => {
raw_note = Some(value);
}
"reasonCode" => {
raw_reason_code = Some(value);
}
"reasonReference" => {
raw_reason_reference = Some(value);
}
"isSubpotent" => {
raw_is_subpotent = Some(value);
}
"_isSubpotent" => {
raw_is_subpotent_element = Some(value);
}
"subpotentReason" => {
raw_subpotent_reason = Some(value);
}
"education" => {
raw_education = Some(value);
}
"programEligibility" => {
raw_program_eligibility = Some(value);
}
"fundingSource" => {
raw_funding_source = Some(value);
}
"reaction" => {
raw_reaction = Some(value);
}
"protocolApplied" => {
raw_protocol_applied = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let 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_status_reason = raw_status_reason
.map(|value| {
path.with("statusReason", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_vaccine_code = path.with("vaccineCode", |path| {
let value = raw_vaccine_code
.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_patient = path.with("patient", |path| {
let value = raw_patient
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_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_occurrence = path.with("occurrence", |path| {
let suffix = raw_occurrence
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
ImmunizationOccurrence::from_json_parts(
suffix,
raw_occurrence.value,
raw_occurrence.element,
path,
)
})?;
let field_recorded = match (raw_recorded, raw_recorded_element) {
(None, None) => None,
(value, element) => Some(path.with("recorded", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_primary_source = match (raw_primary_source, raw_primary_source_element) {
(None, None) => None,
(value, element) => Some(path.with("primarySource", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_report_origin = raw_report_origin
.map(|value| {
path.with("reportOrigin", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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_manufacturer = raw_manufacturer
.map(|value| {
path.with("manufacturer", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_lot_number = match (raw_lot_number, raw_lot_number_element) {
(None, None) => None,
(value, element) => Some(path.with("lotNumber", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_expiration_date = match (raw_expiration_date, raw_expiration_date_element) {
(None, None) => None,
(value, element) => Some(path.with("expirationDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_site = raw_site
.map(|value| {
path.with("site", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_route = raw_route
.map(|value| {
path.with("route", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_dose_quantity = raw_dose_quantity
.map(|value| {
path.with("doseQuantity", |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_performer = Vec::new();
if let Some(raw) = raw_performer {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_performer.push(path.with_index("performer", 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,
)
})?);
}
}
let mut field_reason_code = Vec::new();
if let Some(raw) = raw_reason_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reason_code.push(path.with_index("reasonCode", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_reason_reference = Vec::new();
if let Some(raw) = raw_reason_reference {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reason_reference.push(path.with_index("reasonReference", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_is_subpotent = match (raw_is_subpotent, raw_is_subpotent_element) {
(None, None) => None,
(value, element) => Some(path.with("isSubpotent", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_subpotent_reason = Vec::new();
if let Some(raw) = raw_subpotent_reason {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_subpotent_reason.push(path.with_index("subpotentReason", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_education = Vec::new();
if let Some(raw) = raw_education {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_education.push(path.with_index("education", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_program_eligibility = Vec::new();
if let Some(raw) = raw_program_eligibility {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_program_eligibility.push(path.with_index(
"programEligibility",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_funding_source = raw_funding_source
.map(|value| {
path.with("fundingSource", |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_reaction = Vec::new();
if let Some(raw) = raw_reaction {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reaction.push(path.with_index("reaction", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_protocol_applied = Vec::new();
if let Some(raw) = raw_protocol_applied {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_protocol_applied.push(path.with_index("protocolApplied", 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,
status_reason: field_status_reason,
vaccine_code: field_vaccine_code,
patient: field_patient,
encounter: field_encounter,
occurrence: field_occurrence,
recorded: field_recorded,
primary_source: field_primary_source,
report_origin: field_report_origin,
location: field_location,
manufacturer: field_manufacturer,
lot_number: field_lot_number,
expiration_date: field_expiration_date,
site: field_site,
route: field_route,
dose_quantity: field_dose_quantity,
performer: field_performer,
note: field_note,
reason_code: field_reason_code,
reason_reference: field_reason_reference,
is_subpotent: field_is_subpotent,
subpotent_reason: field_subpotent_reason,
education: field_education,
program_eligibility: field_program_eligibility,
funding_source: field_funding_source,
reaction: field_reaction,
protocol_applied: field_protocol_applied,
})
}
}
impl serde::Serialize for Immunization {
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.expiration_date {
super::super::codec::element_entry(&mut map, "_expirationDate", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.is_subpotent {
super::super::codec::element_entry(&mut map, "_isSubpotent", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(item) = &self.lot_number {
super::super::codec::element_entry(&mut map, "_lotNumber", item)?;
}
match &self.occurrence {
ImmunizationOccurrence::DateTime(inner) => {
super::super::codec::element_entry(&mut map, "_occurrenceDateTime", inner)?;
}
ImmunizationOccurrence::String(inner) => {
super::super::codec::element_entry(&mut map, "_occurrenceString", inner)?;
}
}
if let Some(item) = &self.primary_source {
super::super::codec::element_entry(&mut map, "_primarySource", item)?;
}
if let Some(item) = &self.recorded {
super::super::codec::element_entry(&mut map, "_recorded", item)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.dose_quantity {
serde::ser::SerializeMap::serialize_entry(&mut map, "doseQuantity", item)?;
}
if !self.education.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "education", &self.education)?;
}
if let Some(item) = &self.encounter {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", item)?;
}
if let Some(item) = &self.expiration_date {
super::super::codec::value_entry(&mut map, "expirationDate", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.funding_source {
serde::ser::SerializeMap::serialize_entry(&mut map, "fundingSource", item)?;
}
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.is_subpotent {
super::super::codec::value_entry(&mut map, "isSubpotent", 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.lot_number {
super::super::codec::value_entry(&mut map, "lotNumber", item)?;
}
if let Some(item) = &self.manufacturer {
serde::ser::SerializeMap::serialize_entry(&mut map, "manufacturer", 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.occurrence {
ImmunizationOccurrence::DateTime(inner) => {
super::super::codec::value_entry(&mut map, "occurrenceDateTime", inner)?;
}
ImmunizationOccurrence::String(inner) => {
super::super::codec::value_entry(&mut map, "occurrenceString", inner)?;
}
}
serde::ser::SerializeMap::serialize_entry(&mut map, "patient", &self.patient)?;
if !self.performer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "performer", &self.performer)?;
}
if let Some(item) = &self.primary_source {
super::super::codec::value_entry(&mut map, "primarySource", item)?;
}
if !self.program_eligibility.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"programEligibility",
&self.program_eligibility,
)?;
}
if !self.protocol_applied.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"protocolApplied",
&self.protocol_applied,
)?;
}
if !self.reaction.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reaction", &self.reaction)?;
}
if !self.reason_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reasonCode", &self.reason_code)?;
}
if !self.reason_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"reasonReference",
&self.reason_reference,
)?;
}
if let Some(item) = &self.recorded {
super::super::codec::value_entry(&mut map, "recorded", item)?;
}
if let Some(item) = &self.report_origin {
serde::ser::SerializeMap::serialize_entry(&mut map, "reportOrigin", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "Immunization")?;
if let Some(item) = &self.route {
serde::ser::SerializeMap::serialize_entry(&mut map, "route", item)?;
}
if let Some(item) = &self.site {
serde::ser::SerializeMap::serialize_entry(&mut map, "site", item)?;
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if let Some(item) = &self.status_reason {
serde::ser::SerializeMap::serialize_entry(&mut map, "statusReason", item)?;
}
if !self.subpotent_reason.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"subpotentReason",
&self.subpotent_reason,
)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "vaccineCode", &self.vaccine_code)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Immunization {
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("Immunization");
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 ImmunizationEducation {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub document_type: Option<super::primitives::String>,
pub reference: Option<super::primitives::Uri>,
pub publication_date: Option<super::primitives::DateTime>,
pub presentation_date: Option<super::primitives::DateTime>,
}
impl super::super::codec::Json for ImmunizationEducation {
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.document_type {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("documentType"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_documentType"), e);
}
}
if let Some(item) = &self.reference {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("reference"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_reference"), e);
}
}
if let Some(item) = &self.publication_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("publicationDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_publicationDate"), e);
}
}
if let Some(item) = &self.presentation_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("presentationDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_presentationDate"), e);
}
}
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_document_type: Option<&super::super::codec::Value> = None;
let mut raw_document_type_element: Option<&super::super::codec::Value> = None;
let mut raw_reference: Option<&super::super::codec::Value> = None;
let mut raw_reference_element: Option<&super::super::codec::Value> = None;
let mut raw_publication_date: Option<&super::super::codec::Value> = None;
let mut raw_publication_date_element: Option<&super::super::codec::Value> = None;
let mut raw_presentation_date: Option<&super::super::codec::Value> = None;
let mut raw_presentation_date_element: 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);
}
"documentType" => {
raw_document_type = Some(value);
}
"_documentType" => {
raw_document_type_element = Some(value);
}
"reference" => {
raw_reference = Some(value);
}
"_reference" => {
raw_reference_element = Some(value);
}
"publicationDate" => {
raw_publication_date = Some(value);
}
"_publicationDate" => {
raw_publication_date_element = Some(value);
}
"presentationDate" => {
raw_presentation_date = Some(value);
}
"_presentationDate" => {
raw_presentation_date_element = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_document_type = match (raw_document_type, raw_document_type_element) {
(None, None) => None,
(value, element) => Some(path.with("documentType", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_reference = match (raw_reference, raw_reference_element) {
(None, None) => None,
(value, element) => Some(path.with("reference", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_publication_date = match (raw_publication_date, raw_publication_date_element) {
(None, None) => None,
(value, element) => Some(path.with("publicationDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_presentation_date = match (raw_presentation_date, raw_presentation_date_element) {
(None, None) => None,
(value, element) => Some(path.with("presentationDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
document_type: field_document_type,
reference: field_reference,
publication_date: field_publication_date,
presentation_date: field_presentation_date,
})
}
}
impl serde::Serialize for ImmunizationEducation {
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.document_type {
super::super::codec::element_entry(&mut map, "_documentType", item)?;
}
if let Some(item) = &self.presentation_date {
super::super::codec::element_entry(&mut map, "_presentationDate", item)?;
}
if let Some(item) = &self.publication_date {
super::super::codec::element_entry(&mut map, "_publicationDate", item)?;
}
if let Some(item) = &self.reference {
super::super::codec::element_entry(&mut map, "_reference", item)?;
}
if let Some(item) = &self.document_type {
super::super::codec::value_entry(&mut map, "documentType", 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,
)?;
}
if let Some(item) = &self.presentation_date {
super::super::codec::value_entry(&mut map, "presentationDate", item)?;
}
if let Some(item) = &self.publication_date {
super::super::codec::value_entry(&mut map, "publicationDate", item)?;
}
if let Some(item) = &self.reference {
super::super::codec::value_entry(&mut map, "reference", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ImmunizationEducation {
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("ImmunizationEducation");
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 ImmunizationOccurrence {
DateTime(super::primitives::DateTime),
String(super::primitives::String),
}
impl ImmunizationOccurrence {
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::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)?,
)),
"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 ImmunizationPerformer {
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 ImmunizationPerformer {
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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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 ImmunizationPerformer {
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 ImmunizationPerformer {
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("ImmunizationPerformer");
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 struct ImmunizationProtocolApplied {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub series: Option<super::primitives::String>,
pub authority: Option<super::reference::Reference>,
pub target_disease: Vec<super::codeable_concept::CodeableConcept>,
pub dose_number: ImmunizationProtocolAppliedDoseNumber,
pub series_doses: Option<ImmunizationProtocolAppliedSeriesDoses>,
}
impl super::super::codec::Json for ImmunizationProtocolApplied {
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.series {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("series"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_series"), e);
}
}
if let Some(item) = &self.authority {
object.insert(
std::string::String::from("authority"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.target_disease.is_empty() {
let mut items = Vec::with_capacity(self.target_disease.len());
for item in &self.target_disease {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("targetDisease"),
super::super::codec::Value::Array(items),
);
}
let (suffix, value, element) = self.dose_number.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("doseNumber{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_doseNumber{suffix}"), element);
}
if let Some(item) = &self.series_doses {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("seriesDoses{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_seriesDoses{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_series: Option<&super::super::codec::Value> = None;
let mut raw_series_element: Option<&super::super::codec::Value> = None;
let mut raw_authority: Option<&super::super::codec::Value> = None;
let mut raw_target_disease: Option<&super::super::codec::Value> = None;
let mut raw_dose_number = super::super::codec::ChoiceSlot::default();
let mut raw_series_doses = 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);
}
"series" => {
raw_series = Some(value);
}
"_series" => {
raw_series_element = Some(value);
}
"authority" => {
raw_authority = Some(value);
}
"targetDisease" => {
raw_target_disease = Some(value);
}
"doseNumberPositiveInt" => {
raw_dose_number.value("PositiveInt", value, path)?;
}
"_doseNumberPositiveInt" => {
raw_dose_number.element("PositiveInt", value, path)?;
}
"doseNumberString" => {
raw_dose_number.value("String", value, path)?;
}
"_doseNumberString" => {
raw_dose_number.element("String", value, path)?;
}
"seriesDosesPositiveInt" => {
raw_series_doses.value("PositiveInt", value, path)?;
}
"_seriesDosesPositiveInt" => {
raw_series_doses.element("PositiveInt", value, path)?;
}
"seriesDosesString" => {
raw_series_doses.value("String", value, path)?;
}
"_seriesDosesString" => {
raw_series_doses.element("String", 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::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_series = match (raw_series, raw_series_element) {
(None, None) => None,
(value, element) => Some(path.with("series", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_authority = raw_authority
.map(|value| {
path.with("authority", |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_target_disease = Vec::new();
if let Some(raw) = raw_target_disease {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_target_disease.push(path.with_index("targetDisease", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_dose_number = path.with("doseNumber", |path| {
let suffix = raw_dose_number
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
ImmunizationProtocolAppliedDoseNumber::from_json_parts(
suffix,
raw_dose_number.value,
raw_dose_number.element,
path,
)
})?;
let field_series_doses = match raw_series_doses.suffix {
None => None,
Some(suffix) => Some(path.with("seriesDoses", |path| {
ImmunizationProtocolAppliedSeriesDoses::from_json_parts(
suffix,
raw_series_doses.value,
raw_series_doses.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
series: field_series,
authority: field_authority,
target_disease: field_target_disease,
dose_number: field_dose_number,
series_doses: field_series_doses,
})
}
}
impl serde::Serialize for ImmunizationProtocolApplied {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.dose_number {
ImmunizationProtocolAppliedDoseNumber::PositiveInt(inner) => {
super::super::codec::element_entry(&mut map, "_doseNumberPositiveInt", inner)?;
}
ImmunizationProtocolAppliedDoseNumber::String(inner) => {
super::super::codec::element_entry(&mut map, "_doseNumberString", inner)?;
}
}
if let Some(item) = &self.series {
super::super::codec::element_entry(&mut map, "_series", item)?;
}
match &self.series_doses {
Some(ImmunizationProtocolAppliedSeriesDoses::PositiveInt(inner)) => {
super::super::codec::element_entry(&mut map, "_seriesDosesPositiveInt", inner)?;
}
Some(ImmunizationProtocolAppliedSeriesDoses::String(inner)) => {
super::super::codec::element_entry(&mut map, "_seriesDosesString", inner)?;
}
None => {}
}
if let Some(item) = &self.authority {
serde::ser::SerializeMap::serialize_entry(&mut map, "authority", item)?;
}
match &self.dose_number {
ImmunizationProtocolAppliedDoseNumber::PositiveInt(inner) => {
super::super::codec::value_entry(&mut map, "doseNumberPositiveInt", inner)?;
}
ImmunizationProtocolAppliedDoseNumber::String(inner) => {
super::super::codec::value_entry(&mut map, "doseNumberString", inner)?;
}
}
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.series {
super::super::codec::value_entry(&mut map, "series", item)?;
}
match &self.series_doses {
Some(ImmunizationProtocolAppliedSeriesDoses::PositiveInt(inner)) => {
super::super::codec::value_entry(&mut map, "seriesDosesPositiveInt", inner)?;
}
Some(ImmunizationProtocolAppliedSeriesDoses::String(inner)) => {
super::super::codec::value_entry(&mut map, "seriesDosesString", inner)?;
}
None => {}
}
if !self.target_disease.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"targetDisease",
&self.target_disease,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ImmunizationProtocolApplied {
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("ImmunizationProtocolApplied");
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 ImmunizationProtocolAppliedDoseNumber {
PositiveInt(super::primitives::PositiveInt),
String(super::primitives::String),
}
impl ImmunizationProtocolAppliedDoseNumber {
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::PositiveInt(inner) => Ok((
"PositiveInt",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
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 {
"PositiveInt" => Ok(Self::PositiveInt(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"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 ImmunizationProtocolAppliedSeriesDoses {
PositiveInt(super::primitives::PositiveInt),
String(super::primitives::String),
}
impl ImmunizationProtocolAppliedSeriesDoses {
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::PositiveInt(inner) => Ok((
"PositiveInt",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
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 {
"PositiveInt" => Ok(Self::PositiveInt(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"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 ImmunizationReaction {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub date: Option<super::primitives::DateTime>,
pub detail: Option<super::reference::Reference>,
pub reported: Option<super::primitives::Boolean>,
}
impl super::super::codec::Json for ImmunizationReaction {
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.date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("date"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_date"), e);
}
}
if let Some(item) = &self.detail {
object.insert(
std::string::String::from("detail"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.reported {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("reported"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_reported"), e);
}
}
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_date: Option<&super::super::codec::Value> = None;
let mut raw_date_element: Option<&super::super::codec::Value> = None;
let mut raw_detail: Option<&super::super::codec::Value> = None;
let mut raw_reported: Option<&super::super::codec::Value> = None;
let mut raw_reported_element: 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);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_element = Some(value);
}
"detail" => {
raw_detail = Some(value);
}
"reported" => {
raw_reported = Some(value);
}
"_reported" => {
raw_reported_element = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_date = match (raw_date, raw_date_element) {
(None, None) => None,
(value, element) => Some(path.with("date", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_detail = raw_detail
.map(|value| {
path.with("detail", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_reported = match (raw_reported, raw_reported_element) {
(None, None) => None,
(value, element) => Some(path.with("reported", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
date: field_date,
detail: field_detail,
reported: field_reported,
})
}
}
impl serde::Serialize for ImmunizationReaction {
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.date {
super::super::codec::element_entry(&mut map, "_date", item)?;
}
if let Some(item) = &self.reported {
super::super::codec::element_entry(&mut map, "_reported", item)?;
}
if let Some(item) = &self.date {
super::super::codec::value_entry(&mut map, "date", item)?;
}
if let Some(item) = &self.detail {
serde::ser::SerializeMap::serialize_entry(&mut map, "detail", 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,
)?;
}
if let Some(item) = &self.reported {
super::super::codec::value_entry(&mut map, "reported", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ImmunizationReaction {
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("ImmunizationReaction");
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)
}
}