#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Immunization {
pub id: Option<super::primitives::Id>,
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 not_given: super::primitives::Boolean,
pub vaccine_code: super::codeable_concept::CodeableConcept,
pub patient: super::reference::Reference,
pub encounter: Option<super::reference::Reference>,
pub date: Option<super::primitives::DateTime>,
pub primary_source: 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 practitioner: Vec<ImmunizationPractitioner>,
pub note: Vec<super::annotation::Annotation>,
pub explanation: Option<ImmunizationExplanation>,
pub reaction: Vec<ImmunizationReaction>,
pub vaccination_protocol: Vec<ImmunizationVaccinationProtocol>,
}
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(item) = &self.id {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("id"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_id"), e);
}
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.status)? {
object.insert(std::string::String::from("status"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.status)? {
object.insert(std::string::String::from("_status"), e);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.not_given)? {
object.insert(std::string::String::from("notGiven"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.not_given)? {
object.insert(std::string::String::from("_notGiven"), e);
}
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)?),
);
}
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(v) = super::super::codec::Primitive::value_json(&self.primary_source)? {
object.insert(std::string::String::from("primarySource"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.primary_source)? {
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.practitioner.is_empty() {
let mut items = Vec::with_capacity(self.practitioner.len());
for item in &self.practitioner {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("practitioner"),
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 let Some(item) = &self.explanation {
object.insert(
std::string::String::from("explanation"),
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.vaccination_protocol.is_empty() {
let mut items = Vec::with_capacity(self.vaccination_protocol.len());
for item in &self.vaccination_protocol {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("vaccinationProtocol"),
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_id_element: 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_not_given: Option<&super::super::codec::Value> = None;
let mut raw_not_given_element: 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_date: Option<&super::super::codec::Value> = None;
let mut raw_date_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_practitioner: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_explanation: Option<&super::super::codec::Value> = None;
let mut raw_reaction: Option<&super::super::codec::Value> = None;
let mut raw_vaccination_protocol: 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);
}
"_id" => {
raw_id_element = 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);
}
"notGiven" => {
raw_not_given = Some(value);
}
"_notGiven" => {
raw_not_given_element = Some(value);
}
"vaccineCode" => {
raw_vaccine_code = Some(value);
}
"patient" => {
raw_patient = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_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);
}
"practitioner" => {
raw_practitioner = Some(value);
}
"note" => {
raw_note = Some(value);
}
"explanation" => {
raw_explanation = Some(value);
}
"reaction" => {
raw_reaction = Some(value);
}
"vaccinationProtocol" => {
raw_vaccination_protocol = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = match (raw_id, raw_id_element) {
(None, None) => None,
(value, element) => Some(path.with("id", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
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_not_given = path.with("notGiven", |path| {
super::super::codec::Primitive::from_json_parts(
raw_not_given,
raw_not_given_element,
path,
)
})?;
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_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_primary_source = path.with("primarySource", |path| {
super::super::codec::Primitive::from_json_parts(
raw_primary_source,
raw_primary_source_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_practitioner = Vec::new();
if let Some(raw) = raw_practitioner {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_practitioner.push(path.with_index("practitioner", 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 field_explanation = raw_explanation
.map(|value| {
path.with("explanation", |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_vaccination_protocol = Vec::new();
if let Some(raw) = raw_vaccination_protocol {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_vaccination_protocol.push(path.with_index(
"vaccinationProtocol",
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,
not_given: field_not_given,
vaccine_code: field_vaccine_code,
patient: field_patient,
encounter: field_encounter,
date: field_date,
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,
practitioner: field_practitioner,
note: field_note,
explanation: field_explanation,
reaction: field_reaction,
vaccination_protocol: field_vaccination_protocol,
})
}
}
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.date {
super::super::codec::element_entry(&mut map, "_date", item)?;
}
if let Some(item) = &self.expiration_date {
super::super::codec::element_entry(&mut map, "_expirationDate", item)?;
}
if let Some(item) = &self.id {
super::super::codec::element_entry(&mut map, "_id", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(item) = &self.lot_number {
super::super::codec::element_entry(&mut map, "_lotNumber", item)?;
}
super::super::codec::element_entry(&mut map, "_notGiven", &self.not_given)?;
super::super::codec::element_entry(&mut map, "_primarySource", &self.primary_source)?;
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.date {
super::super::codec::value_entry(&mut map, "date", item)?;
}
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 let Some(item) = &self.explanation {
serde::ser::SerializeMap::serialize_entry(&mut map, "explanation", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.id {
super::super::codec::value_entry(&mut map, "id", item)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.location {
serde::ser::SerializeMap::serialize_entry(&mut map, "location", item)?;
}
if let Some(item) = &self.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,
)?;
}
super::super::codec::value_entry(&mut map, "notGiven", &self.not_given)?;
if !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "patient", &self.patient)?;
if !self.practitioner.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"practitioner",
&self.practitioner,
)?;
}
super::super::codec::value_entry(&mut map, "primarySource", &self.primary_source)?;
if !self.reaction.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reaction", &self.reaction)?;
}
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.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if !self.vaccination_protocol.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"vaccinationProtocol",
&self.vaccination_protocol,
)?;
}
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 ImmunizationExplanation {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub reason: Vec<super::codeable_concept::CodeableConcept>,
pub reason_not_given: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ImmunizationExplanation {
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 !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 !self.reason_not_given.is_empty() {
let mut items = Vec::with_capacity(self.reason_not_given.len());
for item in &self.reason_not_given {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reasonNotGiven"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_reason: Option<&super::super::codec::Value> = None;
let mut raw_reason_not_given: 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);
}
"reason" => {
raw_reason = Some(value);
}
"reasonNotGiven" => {
raw_reason_not_given = 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 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 mut field_reason_not_given = Vec::new();
if let Some(raw) = raw_reason_not_given {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reason_not_given.push(path.with_index("reasonNotGiven", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
reason: field_reason,
reason_not_given: field_reason_not_given,
})
}
}
impl serde::Serialize for ImmunizationExplanation {
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,
)?;
}
if !self.reason.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reason", &self.reason)?;
}
if !self.reason_not_given.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"reasonNotGiven",
&self.reason_not_given,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ImmunizationExplanation {
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("ImmunizationExplanation");
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 ImmunizationPractitioner {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub role: Option<super::codeable_concept::CodeableConcept>,
pub actor: super::reference::Reference,
}
impl super::super::codec::Json for ImmunizationPractitioner {
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.role {
object.insert(
std::string::String::from("role"),
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_role: 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);
}
"role" => {
raw_role = 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_role = raw_role
.map(|value| {
path.with("role", |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,
role: field_role,
actor: field_actor,
})
}
}
impl serde::Serialize for ImmunizationPractitioner {
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(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.role {
serde::ser::SerializeMap::serialize_entry(&mut map, "role", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ImmunizationPractitioner {
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("ImmunizationPractitioner");
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 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)
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ImmunizationVaccinationProtocol {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub dose_sequence: Option<super::primitives::PositiveInt>,
pub description: Option<super::primitives::String>,
pub authority: Option<super::reference::Reference>,
pub series: Option<super::primitives::String>,
pub series_doses: Option<super::primitives::PositiveInt>,
pub target_disease: Vec<super::codeable_concept::CodeableConcept>,
pub dose_status: super::codeable_concept::CodeableConcept,
pub dose_status_reason: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ImmunizationVaccinationProtocol {
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.dose_sequence {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("doseSequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_doseSequence"), e);
}
}
if let Some(item) = &self.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), 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 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.series_doses {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("seriesDoses"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_seriesDoses"), e);
}
}
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),
);
}
object.insert(
std::string::String::from("doseStatus"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.dose_status,
)?),
);
if let Some(item) = &self.dose_status_reason {
object.insert(
std::string::String::from("doseStatusReason"),
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_dose_sequence: Option<&super::super::codec::Value> = None;
let mut raw_dose_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
let mut raw_authority: 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_series_doses: Option<&super::super::codec::Value> = None;
let mut raw_series_doses_element: Option<&super::super::codec::Value> = None;
let mut raw_target_disease: Option<&super::super::codec::Value> = None;
let mut raw_dose_status: Option<&super::super::codec::Value> = None;
let mut raw_dose_status_reason: 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);
}
"doseSequence" => {
raw_dose_sequence = Some(value);
}
"_doseSequence" => {
raw_dose_sequence_element = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"authority" => {
raw_authority = Some(value);
}
"series" => {
raw_series = Some(value);
}
"_series" => {
raw_series_element = Some(value);
}
"seriesDoses" => {
raw_series_doses = Some(value);
}
"_seriesDoses" => {
raw_series_doses_element = Some(value);
}
"targetDisease" => {
raw_target_disease = Some(value);
}
"doseStatus" => {
raw_dose_status = Some(value);
}
"doseStatusReason" => {
raw_dose_status_reason = 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_dose_sequence = match (raw_dose_sequence, raw_dose_sequence_element) {
(None, None) => None,
(value, element) => Some(path.with("doseSequence", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |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 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_series_doses = match (raw_series_doses, raw_series_doses_element) {
(None, None) => None,
(value, element) => Some(path.with("seriesDoses", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
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_status = path.with("doseStatus", |path| {
let value = raw_dose_status
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_dose_status_reason = raw_dose_status_reason
.map(|value| {
path.with("doseStatusReason", |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,
dose_sequence: field_dose_sequence,
description: field_description,
authority: field_authority,
series: field_series,
series_doses: field_series_doses,
target_disease: field_target_disease,
dose_status: field_dose_status,
dose_status_reason: field_dose_status_reason,
})
}
}
impl serde::Serialize for ImmunizationVaccinationProtocol {
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.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.dose_sequence {
super::super::codec::element_entry(&mut map, "_doseSequence", item)?;
}
if let Some(item) = &self.series {
super::super::codec::element_entry(&mut map, "_series", item)?;
}
if let Some(item) = &self.series_doses {
super::super::codec::element_entry(&mut map, "_seriesDoses", item)?;
}
if let Some(item) = &self.authority {
serde::ser::SerializeMap::serialize_entry(&mut map, "authority", item)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if let Some(item) = &self.dose_sequence {
super::super::codec::value_entry(&mut map, "doseSequence", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "doseStatus", &self.dose_status)?;
if let Some(item) = &self.dose_status_reason {
serde::ser::SerializeMap::serialize_entry(&mut map, "doseStatusReason", 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 {
super::super::codec::value_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 ImmunizationVaccinationProtocol {
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("ImmunizationVaccinationProtocol");
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)
}
}