#[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 based_on: Vec<super::reference::Reference>,
pub status: super::primitives::Code,
pub status_reason: Option<super::codeable_concept::CodeableConcept>,
pub vaccine_code: super::codeable_concept::CodeableConcept,
pub administered_product: Option<super::codeable_reference::CodeableReference>,
pub manufacturer: Option<super::codeable_reference::CodeableReference>,
pub lot_number: Option<super::primitives::String>,
pub expiration_date: Option<super::primitives::Date>,
pub patient: super::reference::Reference,
pub encounter: Option<super::reference::Reference>,
pub supporting_information: Vec<super::reference::Reference>,
pub occurrence: ImmunizationOccurrence,
pub primary_source: Option<super::primitives::Boolean>,
pub information_source: Option<super::codeable_reference::CodeableReference>,
pub location: Option<super::reference::Reference>,
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: Vec<super::codeable_reference::CodeableReference>,
pub is_subpotent: Option<super::primitives::Boolean>,
pub subpotent_reason: Vec<super::codeable_concept::CodeableConcept>,
pub program_eligibility: Vec<ImmunizationProgramEligibility>,
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 !self.based_on.is_empty() {
let mut items = Vec::with_capacity(self.based_on.len());
for item in &self.based_on {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("basedOn"),
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,
)?),
);
if let Some(item) = &self.administered_product {
object.insert(
std::string::String::from("administeredProduct"),
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);
}
}
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)?),
);
}
if !self.supporting_information.is_empty() {
let mut items = Vec::with_capacity(self.supporting_information.len());
for item in &self.supporting_information {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("supportingInformation"),
super::super::codec::Value::Array(items),
);
}
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.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.information_source {
object.insert(
std::string::String::from("informationSource"),
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.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.is_empty() {
let mut items = Vec::with_capacity(self.reason.len());
for item in &self.reason {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reason"),
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.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_based_on: 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_administered_product: 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_patient: Option<&super::super::codec::Value> = None;
let mut raw_encounter: Option<&super::super::codec::Value> = None;
let mut raw_supporting_information: Option<&super::super::codec::Value> = None;
let mut raw_occurrence = super::super::codec::ChoiceSlot::default();
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_information_source: Option<&super::super::codec::Value> = None;
let mut raw_location: 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: 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_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);
}
"basedOn" => {
raw_based_on = 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);
}
"administeredProduct" => {
raw_administered_product = 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);
}
"patient" => {
raw_patient = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"supportingInformation" => {
raw_supporting_information = 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)?;
}
"primarySource" => {
raw_primary_source = Some(value);
}
"_primarySource" => {
raw_primary_source_element = Some(value);
}
"informationSource" => {
raw_information_source = Some(value);
}
"location" => {
raw_location = 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);
}
"reason" => {
raw_reason = Some(value);
}
"isSubpotent" => {
raw_is_subpotent = Some(value);
}
"_isSubpotent" => {
raw_is_subpotent_element = Some(value);
}
"subpotentReason" => {
raw_subpotent_reason = 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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_based_on = Vec::new();
if let Some(raw) = raw_based_on {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_based_on.push(path.with_index("basedOn", 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_administered_product = raw_administered_product
.map(|value| {
path.with("administeredProduct", |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_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 mut field_supporting_information = Vec::new();
if let Some(raw) = raw_supporting_information {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_supporting_information.push(path.with_index(
"supportingInformation",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
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_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_information_source = raw_information_source
.map(|value| {
path.with("informationSource", |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_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 = Vec::new();
if let Some(raw) = raw_reason {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reason.push(path.with_index("reason", 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_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,
based_on: field_based_on,
status: field_status,
status_reason: field_status_reason,
vaccine_code: field_vaccine_code,
administered_product: field_administered_product,
manufacturer: field_manufacturer,
lot_number: field_lot_number,
expiration_date: field_expiration_date,
patient: field_patient,
encounter: field_encounter,
supporting_information: field_supporting_information,
occurrence: field_occurrence,
primary_source: field_primary_source,
information_source: field_information_source,
location: field_location,
site: field_site,
route: field_route,
dose_quantity: field_dose_quantity,
performer: field_performer,
note: field_note,
reason: field_reason,
is_subpotent: field_is_subpotent,
subpotent_reason: field_subpotent_reason,
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)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if let Some(item) = &self.administered_product {
serde::ser::SerializeMap::serialize_entry(&mut map, "administeredProduct", item)?;
}
if !self.based_on.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "basedOn", &self.based_on)?;
}
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 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.information_source {
serde::ser::SerializeMap::serialize_entry(&mut map, "informationSource", 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.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reason", &self.reason)?;
}
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 !self.supporting_information.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"supportingInformation",
&self.supporting_information,
)?;
}
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, 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::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 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, Default, PartialEq, Eq)]
pub struct ImmunizationProgramEligibility {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub program: super::codeable_concept::CodeableConcept,
pub program_status: super::codeable_concept::CodeableConcept,
}
impl super::super::codec::Json for ImmunizationProgramEligibility {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("program"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.program)?),
);
object.insert(
std::string::String::from("programStatus"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.program_status,
)?),
);
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_program: Option<&super::super::codec::Value> = None;
let mut raw_program_status: 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);
}
"program" => {
raw_program = Some(value);
}
"programStatus" => {
raw_program_status = 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_program = path.with("program", |path| {
let value = raw_program
.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_program_status = path.with("programStatus", |path| {
let value = raw_program_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,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
program: field_program,
program_status: field_program_status,
})
}
}
impl serde::Serialize for ImmunizationProgramEligibility {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "program", &self.program)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "programStatus", &self.program_status)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ImmunizationProgramEligibility {
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("ImmunizationProgramEligibility");
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 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: Option<super::codeable_concept::CodeableConcept>,
pub series_doses: Option<super::codeable_concept::CodeableConcept>,
}
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),
);
}
if let Some(item) = &self.dose_number {
object.insert(
std::string::String::from("doseNumber"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.series_doses {
object.insert(
std::string::String::from("seriesDoses"),
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_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: Option<&super::super::codec::Value> = None;
let mut raw_series_doses: 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);
}
"series" => {
raw_series = Some(value);
}
"_series" => {
raw_series_element = Some(value);
}
"authority" => {
raw_authority = Some(value);
}
"targetDisease" => {
raw_target_disease = Some(value);
}
"doseNumber" => {
raw_dose_number = Some(value);
}
"seriesDoses" => {
raw_series_doses = 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_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 = raw_dose_number
.map(|value| {
path.with("doseNumber", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_series_doses = raw_series_doses
.map(|value| {
path.with("seriesDoses", |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,
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)?;
if let Some(item) = &self.series {
super::super::codec::element_entry(&mut map, "_series", item)?;
}
if let Some(item) = &self.authority {
serde::ser::SerializeMap::serialize_entry(&mut map, "authority", item)?;
}
if let Some(item) = &self.dose_number {
serde::ser::SerializeMap::serialize_entry(&mut map, "doseNumber", 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.series {
super::super::codec::value_entry(&mut map, "series", item)?;
}
if let Some(item) = &self.series_doses {
serde::ser::SerializeMap::serialize_entry(&mut map, "seriesDoses", item)?;
}
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, 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 manifestation: Option<super::codeable_reference::CodeableReference>,
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.manifestation {
object.insert(
std::string::String::from("manifestation"),
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_manifestation: 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);
}
"manifestation" => {
raw_manifestation = 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::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_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_manifestation = raw_manifestation
.map(|value| {
path.with("manifestation", |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,
manifestation: field_manifestation,
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 !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.manifestation {
serde::ser::SerializeMap::serialize_entry(&mut map, "manifestation", item)?;
}
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)
}
}