#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MedicationDispense {
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 part_of: Vec<super::reference::Reference>,
pub status: super::primitives::Code,
pub status_reason: Option<MedicationDispenseStatusReason>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub medication: MedicationDispenseMedication,
pub subject: Option<super::reference::Reference>,
pub context: Option<super::reference::Reference>,
pub supporting_information: Vec<super::reference::Reference>,
pub performer: Vec<MedicationDispensePerformer>,
pub location: Option<super::reference::Reference>,
pub authorizing_prescription: Vec<super::reference::Reference>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub quantity: Option<super::quantity::Quantity>,
pub days_supply: Option<super::quantity::Quantity>,
pub when_prepared: Option<super::primitives::DateTime>,
pub when_handed_over: Option<super::primitives::DateTime>,
pub destination: Option<super::reference::Reference>,
pub receiver: Vec<super::reference::Reference>,
pub note: Vec<super::annotation::Annotation>,
pub dosage_instruction: Vec<super::dosage::Dosage>,
pub substitution: Option<MedicationDispenseSubstitution>,
pub detected_issue: Vec<super::reference::Reference>,
pub event_history: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for MedicationDispense {
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("MedicationDispense")),
);
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.part_of.is_empty() {
let mut items = Vec::with_capacity(self.part_of.len());
for item in &self.part_of {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("partOf"),
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 {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("statusReason{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_statusReason{suffix}"), element);
}
}
if let Some(item) = &self.category {
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
let (suffix, value, element) = self.medication.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("medication{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_medication{suffix}"), element);
}
if let Some(item) = &self.subject {
object.insert(
std::string::String::from("subject"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.context {
object.insert(
std::string::String::from("context"),
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),
);
}
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 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 !self.authorizing_prescription.is_empty() {
let mut items = Vec::with_capacity(self.authorizing_prescription.len());
for item in &self.authorizing_prescription {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("authorizingPrescription"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.r#type {
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.quantity {
object.insert(
std::string::String::from("quantity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.days_supply {
object.insert(
std::string::String::from("daysSupply"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.when_prepared {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("whenPrepared"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_whenPrepared"), e);
}
}
if let Some(item) = &self.when_handed_over {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("whenHandedOver"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_whenHandedOver"), e);
}
}
if let Some(item) = &self.destination {
object.insert(
std::string::String::from("destination"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.receiver.is_empty() {
let mut items = Vec::with_capacity(self.receiver.len());
for item in &self.receiver {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("receiver"),
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.dosage_instruction.is_empty() {
let mut items = Vec::with_capacity(self.dosage_instruction.len());
for item in &self.dosage_instruction {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("dosageInstruction"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.substitution {
object.insert(
std::string::String::from("substitution"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.detected_issue.is_empty() {
let mut items = Vec::with_capacity(self.detected_issue.len());
for item in &self.detected_issue {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("detectedIssue"),
super::super::codec::Value::Array(items),
);
}
if !self.event_history.is_empty() {
let mut items = Vec::with_capacity(self.event_history.len());
for item in &self.event_history {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("eventHistory"),
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_part_of: 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 = super::super::codec::ChoiceSlot::default();
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_medication = super::super::codec::ChoiceSlot::default();
let mut raw_subject: Option<&super::super::codec::Value> = None;
let mut raw_context: Option<&super::super::codec::Value> = None;
let mut raw_supporting_information: Option<&super::super::codec::Value> = None;
let mut raw_performer: Option<&super::super::codec::Value> = None;
let mut raw_location: Option<&super::super::codec::Value> = None;
let mut raw_authorizing_prescription: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_quantity: Option<&super::super::codec::Value> = None;
let mut raw_days_supply: Option<&super::super::codec::Value> = None;
let mut raw_when_prepared: Option<&super::super::codec::Value> = None;
let mut raw_when_prepared_element: Option<&super::super::codec::Value> = None;
let mut raw_when_handed_over: Option<&super::super::codec::Value> = None;
let mut raw_when_handed_over_element: Option<&super::super::codec::Value> = None;
let mut raw_destination: Option<&super::super::codec::Value> = None;
let mut raw_receiver: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_dosage_instruction: Option<&super::super::codec::Value> = None;
let mut raw_substitution: Option<&super::super::codec::Value> = None;
let mut raw_detected_issue: Option<&super::super::codec::Value> = None;
let mut raw_event_history: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("MedicationDispense") {
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);
}
"partOf" => {
raw_part_of = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"statusReasonCodeableConcept" => {
raw_status_reason.value("CodeableConcept", value, path)?;
}
"_statusReasonCodeableConcept" => {
raw_status_reason.element("CodeableConcept", value, path)?;
}
"statusReasonReference" => {
raw_status_reason.value("Reference", value, path)?;
}
"_statusReasonReference" => {
raw_status_reason.element("Reference", value, path)?;
}
"category" => {
raw_category = Some(value);
}
"medicationCodeableConcept" => {
raw_medication.value("CodeableConcept", value, path)?;
}
"_medicationCodeableConcept" => {
raw_medication.element("CodeableConcept", value, path)?;
}
"medicationReference" => {
raw_medication.value("Reference", value, path)?;
}
"_medicationReference" => {
raw_medication.element("Reference", value, path)?;
}
"subject" => {
raw_subject = Some(value);
}
"context" => {
raw_context = Some(value);
}
"supportingInformation" => {
raw_supporting_information = Some(value);
}
"performer" => {
raw_performer = Some(value);
}
"location" => {
raw_location = Some(value);
}
"authorizingPrescription" => {
raw_authorizing_prescription = Some(value);
}
"type" => {
raw_type = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"daysSupply" => {
raw_days_supply = Some(value);
}
"whenPrepared" => {
raw_when_prepared = Some(value);
}
"_whenPrepared" => {
raw_when_prepared_element = Some(value);
}
"whenHandedOver" => {
raw_when_handed_over = Some(value);
}
"_whenHandedOver" => {
raw_when_handed_over_element = Some(value);
}
"destination" => {
raw_destination = Some(value);
}
"receiver" => {
raw_receiver = Some(value);
}
"note" => {
raw_note = Some(value);
}
"dosageInstruction" => {
raw_dosage_instruction = Some(value);
}
"substitution" => {
raw_substitution = Some(value);
}
"detectedIssue" => {
raw_detected_issue = Some(value);
}
"eventHistory" => {
raw_event_history = 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_part_of = Vec::new();
if let Some(raw) = raw_part_of {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_part_of.push(path.with_index("partOf", 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 = match raw_status_reason.suffix {
None => None,
Some(suffix) => Some(path.with("statusReason", |path| {
MedicationDispenseStatusReason::from_json_parts(
suffix,
raw_status_reason.value,
raw_status_reason.element,
path,
)
})?),
};
let field_category = raw_category
.map(|value| {
path.with("category", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_medication = path.with("medication", |path| {
let suffix = raw_medication
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
MedicationDispenseMedication::from_json_parts(
suffix,
raw_medication.value,
raw_medication.element,
path,
)
})?;
let field_subject = raw_subject
.map(|value| {
path.with("subject", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_context = raw_context
.map(|value| {
path.with("context", |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 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 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 mut field_authorizing_prescription = Vec::new();
if let Some(raw) = raw_authorizing_prescription {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_authorizing_prescription.push(path.with_index(
"authorizingPrescription",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_type = raw_type
.map(|value| {
path.with("type", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_quantity = raw_quantity
.map(|value| {
path.with("quantity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_days_supply = raw_days_supply
.map(|value| {
path.with("daysSupply", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_when_prepared = match (raw_when_prepared, raw_when_prepared_element) {
(None, None) => None,
(value, element) => Some(path.with("whenPrepared", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_when_handed_over = match (raw_when_handed_over, raw_when_handed_over_element) {
(None, None) => None,
(value, element) => Some(path.with("whenHandedOver", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_destination = raw_destination
.map(|value| {
path.with("destination", |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_receiver = Vec::new();
if let Some(raw) = raw_receiver {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_receiver.push(path.with_index("receiver", 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_dosage_instruction = Vec::new();
if let Some(raw) = raw_dosage_instruction {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_dosage_instruction.push(path.with_index(
"dosageInstruction",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_substitution = raw_substitution
.map(|value| {
path.with("substitution", |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_detected_issue = Vec::new();
if let Some(raw) = raw_detected_issue {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_detected_issue.push(path.with_index("detectedIssue", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_event_history = Vec::new();
if let Some(raw) = raw_event_history {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_event_history.push(path.with_index("eventHistory", 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,
part_of: field_part_of,
status: field_status,
status_reason: field_status_reason,
category: field_category,
medication: field_medication,
subject: field_subject,
context: field_context,
supporting_information: field_supporting_information,
performer: field_performer,
location: field_location,
authorizing_prescription: field_authorizing_prescription,
r#type: field_type,
quantity: field_quantity,
days_supply: field_days_supply,
when_prepared: field_when_prepared,
when_handed_over: field_when_handed_over,
destination: field_destination,
receiver: field_receiver,
note: field_note,
dosage_instruction: field_dosage_instruction,
substitution: field_substitution,
detected_issue: field_detected_issue,
event_history: field_event_history,
})
}
}
impl serde::Serialize for MedicationDispense {
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.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)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if let Some(item) = &self.when_handed_over {
super::super::codec::element_entry(&mut map, "_whenHandedOver", item)?;
}
if let Some(item) = &self.when_prepared {
super::super::codec::element_entry(&mut map, "_whenPrepared", item)?;
}
if !self.authorizing_prescription.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"authorizingPrescription",
&self.authorizing_prescription,
)?;
}
if let Some(item) = &self.category {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", item)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.context {
serde::ser::SerializeMap::serialize_entry(&mut map, "context", item)?;
}
if let Some(item) = &self.days_supply {
serde::ser::SerializeMap::serialize_entry(&mut map, "daysSupply", item)?;
}
if let Some(item) = &self.destination {
serde::ser::SerializeMap::serialize_entry(&mut map, "destination", item)?;
}
if !self.detected_issue.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"detectedIssue",
&self.detected_issue,
)?;
}
if !self.dosage_instruction.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"dosageInstruction",
&self.dosage_instruction,
)?;
}
if !self.event_history.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"eventHistory",
&self.event_history,
)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.location {
serde::ser::SerializeMap::serialize_entry(&mut map, "location", item)?;
}
match &self.medication {
MedicationDispenseMedication::CodeableConcept(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"medicationCodeableConcept",
inner.as_ref(),
)?;
}
MedicationDispenseMedication::Reference(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"medicationReference",
inner.as_ref(),
)?;
}
}
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)?;
}
if !self.part_of.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "partOf", &self.part_of)?;
}
if !self.performer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "performer", &self.performer)?;
}
if let Some(item) = &self.quantity {
serde::ser::SerializeMap::serialize_entry(&mut map, "quantity", item)?;
}
if !self.receiver.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "receiver", &self.receiver)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "MedicationDispense")?;
super::super::codec::value_entry(&mut map, "status", &self.status)?;
match &self.status_reason {
Some(MedicationDispenseStatusReason::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"statusReasonCodeableConcept",
inner.as_ref(),
)?;
}
Some(MedicationDispenseStatusReason::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"statusReasonReference",
inner.as_ref(),
)?;
}
None => {}
}
if let Some(item) = &self.subject {
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", item)?;
}
if let Some(item) = &self.substitution {
serde::ser::SerializeMap::serialize_entry(&mut map, "substitution", item)?;
}
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)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
if let Some(item) = &self.when_handed_over {
super::super::codec::value_entry(&mut map, "whenHandedOver", item)?;
}
if let Some(item) = &self.when_prepared {
super::super::codec::value_entry(&mut map, "whenPrepared", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for MedicationDispense {
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("MedicationDispense");
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 MedicationDispenseMedication {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Reference(Box<super::reference::Reference>),
}
impl MedicationDispenseMedication {
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::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct MedicationDispensePerformer {
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 MedicationDispensePerformer {
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 MedicationDispensePerformer {
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 MedicationDispensePerformer {
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("MedicationDispensePerformer");
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 MedicationDispenseStatusReason {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Reference(Box<super::reference::Reference>),
}
impl MedicationDispenseStatusReason {
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::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct MedicationDispenseSubstitution {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub was_substituted: super::primitives::Boolean,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub reason: Vec<super::codeable_concept::CodeableConcept>,
pub responsible_party: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for MedicationDispenseSubstitution {
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(v) = super::super::codec::Primitive::value_json(&self.was_substituted)? {
object.insert(std::string::String::from("wasSubstituted"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.was_substituted)? {
object.insert(std::string::String::from("_wasSubstituted"), e);
}
if let Some(item) = &self.r#type {
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.responsible_party.is_empty() {
let mut items = Vec::with_capacity(self.responsible_party.len());
for item in &self.responsible_party {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("responsibleParty"),
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_was_substituted: Option<&super::super::codec::Value> = None;
let mut raw_was_substituted_element: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_reason: Option<&super::super::codec::Value> = None;
let mut raw_responsible_party: 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);
}
"wasSubstituted" => {
raw_was_substituted = Some(value);
}
"_wasSubstituted" => {
raw_was_substituted_element = Some(value);
}
"type" => {
raw_type = Some(value);
}
"reason" => {
raw_reason = Some(value);
}
"responsibleParty" => {
raw_responsible_party = 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_was_substituted = path.with("wasSubstituted", |path| {
super::super::codec::Primitive::from_json_parts(
raw_was_substituted,
raw_was_substituted_element,
path,
)
})?;
let field_type = raw_type
.map(|value| {
path.with("type", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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_responsible_party = Vec::new();
if let Some(raw) = raw_responsible_party {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_responsible_party.push(path.with_index(
"responsibleParty",
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,
was_substituted: field_was_substituted,
r#type: field_type,
reason: field_reason,
responsible_party: field_responsible_party,
})
}
}
impl serde::Serialize for MedicationDispenseSubstitution {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_wasSubstituted", &self.was_substituted)?;
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.responsible_party.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"responsibleParty",
&self.responsible_party,
)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
super::super::codec::value_entry(&mut map, "wasSubstituted", &self.was_substituted)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for MedicationDispenseSubstitution {
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("MedicationDispenseSubstitution");
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)
}
}