#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MedicationAdministration {
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 definition: Vec<super::reference::Reference>,
pub part_of: Vec<super::reference::Reference>,
pub status: super::primitives::Code,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub medication: MedicationAdministrationMedication,
pub subject: super::reference::Reference,
pub context: Option<super::reference::Reference>,
pub supporting_information: Vec<super::reference::Reference>,
pub effective: MedicationAdministrationEffective,
pub performer: Vec<MedicationAdministrationPerformer>,
pub not_given: Option<super::primitives::Boolean>,
pub reason_not_given: Vec<super::codeable_concept::CodeableConcept>,
pub reason_code: Vec<super::codeable_concept::CodeableConcept>,
pub reason_reference: Vec<super::reference::Reference>,
pub prescription: Option<super::reference::Reference>,
pub device: Vec<super::reference::Reference>,
pub note: Vec<super::annotation::Annotation>,
pub dosage: Option<MedicationAdministrationDosage>,
pub event_history: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for MedicationAdministration {
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(
"MedicationAdministration",
)),
);
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 !self.definition.is_empty() {
let mut items = Vec::with_capacity(self.definition.len());
for item in &self.definition {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("definition"),
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.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);
}
object.insert(
std::string::String::from("subject"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.subject)?),
);
if let Some(item) = &self.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),
);
}
let (suffix, value, element) = self.effective.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("effective{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_effective{suffix}"), element);
}
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.not_given {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("notGiven"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_notGiven"), e);
}
}
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),
);
}
if !self.reason_code.is_empty() {
let mut items = Vec::with_capacity(self.reason_code.len());
for item in &self.reason_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reasonCode"),
super::super::codec::Value::Array(items),
);
}
if !self.reason_reference.is_empty() {
let mut items = Vec::with_capacity(self.reason_reference.len());
for item in &self.reason_reference {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reasonReference"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.prescription {
object.insert(
std::string::String::from("prescription"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.device.is_empty() {
let mut items = Vec::with_capacity(self.device.len());
for item in &self.device {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("device"),
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.dosage {
object.insert(
std::string::String::from("dosage"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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_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_definition: 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_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_effective = super::super::codec::ChoiceSlot::default();
let mut raw_performer: 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_reason_not_given: Option<&super::super::codec::Value> = None;
let mut raw_reason_code: Option<&super::super::codec::Value> = None;
let mut raw_reason_reference: Option<&super::super::codec::Value> = None;
let mut raw_prescription: Option<&super::super::codec::Value> = None;
let mut raw_device: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_dosage: 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("MedicationAdministration") {
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);
}
"definition" => {
raw_definition = Some(value);
}
"partOf" => {
raw_part_of = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"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);
}
"effectiveDateTime" => {
raw_effective.value("DateTime", value, path)?;
}
"_effectiveDateTime" => {
raw_effective.element("DateTime", value, path)?;
}
"effectivePeriod" => {
raw_effective.value("Period", value, path)?;
}
"_effectivePeriod" => {
raw_effective.element("Period", value, path)?;
}
"performer" => {
raw_performer = Some(value);
}
"notGiven" => {
raw_not_given = Some(value);
}
"_notGiven" => {
raw_not_given_element = Some(value);
}
"reasonNotGiven" => {
raw_reason_not_given = Some(value);
}
"reasonCode" => {
raw_reason_code = Some(value);
}
"reasonReference" => {
raw_reason_reference = Some(value);
}
"prescription" => {
raw_prescription = Some(value);
}
"device" => {
raw_device = Some(value);
}
"note" => {
raw_note = Some(value);
}
"dosage" => {
raw_dosage = 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 = 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 mut field_definition = Vec::new();
if let Some(raw) = raw_definition {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_definition.push(path.with_index("definition", 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_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))?;
MedicationAdministrationMedication::from_json_parts(
suffix,
raw_medication.value,
raw_medication.element,
path,
)
})?;
let field_subject = path.with("subject", |path| {
let value = raw_subject
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_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 field_effective = path.with("effective", |path| {
let suffix = raw_effective
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
MedicationAdministrationEffective::from_json_parts(
suffix,
raw_effective.value,
raw_effective.element,
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_not_given = match (raw_not_given, raw_not_given_element) {
(None, None) => None,
(value, element) => Some(path.with("notGiven", |path| {
super::super::codec::Primitive::from_json_parts(value, element, 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,
)
})?);
}
}
let mut field_reason_code = Vec::new();
if let Some(raw) = raw_reason_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reason_code.push(path.with_index("reasonCode", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_reason_reference = Vec::new();
if let Some(raw) = raw_reason_reference {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reason_reference.push(path.with_index("reasonReference", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_prescription = raw_prescription
.map(|value| {
path.with("prescription", |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_device = Vec::new();
if let Some(raw) = raw_device {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_device.push(path.with_index("device", 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_dosage = raw_dosage
.map(|value| {
path.with("dosage", |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_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,
definition: field_definition,
part_of: field_part_of,
status: field_status,
category: field_category,
medication: field_medication,
subject: field_subject,
context: field_context,
supporting_information: field_supporting_information,
effective: field_effective,
performer: field_performer,
not_given: field_not_given,
reason_not_given: field_reason_not_given,
reason_code: field_reason_code,
reason_reference: field_reason_reference,
prescription: field_prescription,
device: field_device,
note: field_note,
dosage: field_dosage,
event_history: field_event_history,
})
}
}
impl serde::Serialize for MedicationAdministration {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let MedicationAdministrationEffective::DateTime(inner) = &self.effective {
super::super::codec::element_entry(&mut map, "_effectiveDateTime", inner)?;
}
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.not_given {
super::super::codec::element_entry(&mut map, "_notGiven", item)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
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 !self.definition.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "definition", &self.definition)?;
}
if !self.device.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "device", &self.device)?;
}
if let Some(item) = &self.dosage {
serde::ser::SerializeMap::serialize_entry(&mut map, "dosage", item)?;
}
match &self.effective {
MedicationAdministrationEffective::DateTime(inner) => {
super::super::codec::value_entry(&mut map, "effectiveDateTime", inner)?;
}
MedicationAdministrationEffective::Period(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"effectivePeriod",
inner.as_ref(),
)?;
}
}
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(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)?;
}
match &self.medication {
MedicationAdministrationMedication::CodeableConcept(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"medicationCodeableConcept",
inner.as_ref(),
)?;
}
MedicationAdministrationMedication::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 let Some(item) = &self.not_given {
super::super::codec::value_entry(&mut map, "notGiven", item)?;
}
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.prescription {
serde::ser::SerializeMap::serialize_entry(&mut map, "prescription", item)?;
}
if !self.reason_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reasonCode", &self.reason_code)?;
}
if !self.reason_not_given.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"reasonNotGiven",
&self.reason_not_given,
)?;
}
if !self.reason_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"reasonReference",
&self.reason_reference,
)?;
}
serde::ser::SerializeMap::serialize_entry(
&mut map,
"resourceType",
"MedicationAdministration",
)?;
super::super::codec::value_entry(&mut map, "status", &self.status)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", &self.subject)?;
if !self.supporting_information.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"supportingInformation",
&self.supporting_information,
)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for MedicationAdministration {
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("MedicationAdministration");
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 MedicationAdministrationDosage {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub text: Option<super::primitives::String>,
pub site: Option<super::codeable_concept::CodeableConcept>,
pub route: Option<super::codeable_concept::CodeableConcept>,
pub method: Option<super::codeable_concept::CodeableConcept>,
pub dose: Option<super::quantity::Quantity>,
pub rate: Option<MedicationAdministrationDosageRate>,
}
impl super::super::codec::Json for MedicationAdministrationDosage {
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.text {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("text"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_text"), 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.method {
object.insert(
std::string::String::from("method"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.dose {
object.insert(
std::string::String::from("dose"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.rate {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("rate{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_rate{suffix}"), element);
}
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_text_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_method: Option<&super::super::codec::Value> = None;
let mut raw_dose: Option<&super::super::codec::Value> = None;
let mut raw_rate = super::super::codec::ChoiceSlot::default();
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"text" => {
raw_text = Some(value);
}
"_text" => {
raw_text_element = Some(value);
}
"site" => {
raw_site = Some(value);
}
"route" => {
raw_route = Some(value);
}
"method" => {
raw_method = Some(value);
}
"dose" => {
raw_dose = Some(value);
}
"rateRatio" => {
raw_rate.value("Ratio", value, path)?;
}
"_rateRatio" => {
raw_rate.element("Ratio", value, path)?;
}
"rateQuantity" => {
raw_rate.value("Quantity", value, path)?;
}
"_rateQuantity" => {
raw_rate.element("Quantity", value, path)?;
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_text = match (raw_text, raw_text_element) {
(None, None) => None,
(value, element) => Some(path.with("text", |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_method = raw_method
.map(|value| {
path.with("method", |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 = raw_dose
.map(|value| {
path.with("dose", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_rate = match raw_rate.suffix {
None => None,
Some(suffix) => Some(path.with("rate", |path| {
MedicationAdministrationDosageRate::from_json_parts(
suffix,
raw_rate.value,
raw_rate.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
text: field_text,
site: field_site,
route: field_route,
method: field_method,
dose: field_dose,
rate: field_rate,
})
}
}
impl serde::Serialize for MedicationAdministrationDosage {
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.text {
super::super::codec::element_entry(&mut map, "_text", item)?;
}
if let Some(item) = &self.dose {
serde::ser::SerializeMap::serialize_entry(&mut map, "dose", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.method {
serde::ser::SerializeMap::serialize_entry(&mut map, "method", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
match &self.rate {
Some(MedicationAdministrationDosageRate::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"rateQuantity",
inner.as_ref(),
)?;
}
Some(MedicationAdministrationDosageRate::Ratio(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "rateRatio", inner.as_ref())?;
}
None => {}
}
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)?;
}
if let Some(item) = &self.text {
super::super::codec::value_entry(&mut map, "text", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for MedicationAdministrationDosage {
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("MedicationAdministrationDosage");
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 MedicationAdministrationDosageRate {
Ratio(Box<super::ratio::Ratio>),
Quantity(Box<super::quantity::Quantity>),
}
impl MedicationAdministrationDosageRate {
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::Ratio(inner) => Ok((
"Ratio",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Quantity(inner) => Ok((
"Quantity",
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 {
"Ratio" => {
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::Ratio(Box::new(inner)))
}
"Quantity" => {
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::Quantity(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MedicationAdministrationEffective {
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
}
impl MedicationAdministrationEffective {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Period(inner) => Ok((
"Period",
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 {
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MedicationAdministrationMedication {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Reference(Box<super::reference::Reference>),
}
impl MedicationAdministrationMedication {
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 MedicationAdministrationPerformer {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub actor: super::reference::Reference,
pub on_behalf_of: Option<super::reference::Reference>,
}
impl super::super::codec::Json for MedicationAdministrationPerformer {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("actor"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.actor)?),
);
if let Some(item) = &self.on_behalf_of {
object.insert(
std::string::String::from("onBehalfOf"),
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_actor: Option<&super::super::codec::Value> = None;
let mut raw_on_behalf_of: 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);
}
"actor" => {
raw_actor = Some(value);
}
"onBehalfOf" => {
raw_on_behalf_of = 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_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,
)
})?;
let field_on_behalf_of = raw_on_behalf_of
.map(|value| {
path.with("onBehalfOf", |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,
actor: field_actor,
on_behalf_of: field_on_behalf_of,
})
}
}
impl serde::Serialize for MedicationAdministrationPerformer {
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.on_behalf_of {
serde::ser::SerializeMap::serialize_entry(&mut map, "onBehalfOf", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for MedicationAdministrationPerformer {
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("MedicationAdministrationPerformer");
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)
}
}