#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Procedure {
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 instantiates_canonical: Vec<super::primitives::Canonical>,
pub instantiates_uri: Vec<super::primitives::Uri>,
pub based_on: Vec<super::reference::Reference>,
pub part_of: Vec<super::reference::Reference>,
pub status: super::primitives::Code,
pub status_reason: Option<super::codeable_concept::CodeableConcept>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub subject: super::reference::Reference,
pub encounter: Option<super::reference::Reference>,
pub performed: Option<ProcedurePerformed>,
pub recorder: Option<super::reference::Reference>,
pub asserter: Option<super::reference::Reference>,
pub performer: Vec<ProcedurePerformer>,
pub location: Option<super::reference::Reference>,
pub reason_code: Vec<super::codeable_concept::CodeableConcept>,
pub reason_reference: Vec<super::reference::Reference>,
pub body_site: Vec<super::codeable_concept::CodeableConcept>,
pub outcome: Option<super::codeable_concept::CodeableConcept>,
pub report: Vec<super::reference::Reference>,
pub complication: Vec<super::codeable_concept::CodeableConcept>,
pub complication_detail: Vec<super::reference::Reference>,
pub follow_up: Vec<super::codeable_concept::CodeableConcept>,
pub note: Vec<super::annotation::Annotation>,
pub focal_device: Vec<ProcedureFocalDevice>,
pub used_reference: Vec<super::reference::Reference>,
pub used_code: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for Procedure {
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("Procedure")),
);
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.instantiates_canonical.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.instantiates_canonical)?;
if let Some(values) = values {
object.insert(std::string::String::from("instantiatesCanonical"), values);
}
if let Some(elements) = elements {
object.insert(
std::string::String::from("_instantiatesCanonical"),
elements,
);
}
}
if !self.instantiates_uri.is_empty() {
let (values, elements) = super::super::codec::primitive_arrays(&self.instantiates_uri)?;
if let Some(values) = values {
object.insert(std::string::String::from("instantiatesUri"), values);
}
if let Some(elements) = elements {
object.insert(std::string::String::from("_instantiatesUri"), elements);
}
}
if !self.based_on.is_empty() {
let mut items = Vec::with_capacity(self.based_on.len());
for item in &self.based_on {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("basedOn"),
super::super::codec::Value::Array(items),
);
}
if !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 {
object.insert(
std::string::String::from("statusReason"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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)?),
);
}
if let Some(item) = &self.code {
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.encounter {
object.insert(
std::string::String::from("encounter"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.performed {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("performed{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_performed{suffix}"), element);
}
}
if let Some(item) = &self.recorder {
object.insert(
std::string::String::from("recorder"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.asserter {
object.insert(
std::string::String::from("asserter"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.performer.is_empty() {
let mut items = Vec::with_capacity(self.performer.len());
for item in &self.performer {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("performer"),
super::super::codec::Value::Array(items),
);
}
if 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.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 !self.body_site.is_empty() {
let mut items = Vec::with_capacity(self.body_site.len());
for item in &self.body_site {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("bodySite"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.outcome {
object.insert(
std::string::String::from("outcome"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.report.is_empty() {
let mut items = Vec::with_capacity(self.report.len());
for item in &self.report {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("report"),
super::super::codec::Value::Array(items),
);
}
if !self.complication.is_empty() {
let mut items = Vec::with_capacity(self.complication.len());
for item in &self.complication {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("complication"),
super::super::codec::Value::Array(items),
);
}
if !self.complication_detail.is_empty() {
let mut items = Vec::with_capacity(self.complication_detail.len());
for item in &self.complication_detail {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("complicationDetail"),
super::super::codec::Value::Array(items),
);
}
if !self.follow_up.is_empty() {
let mut items = Vec::with_capacity(self.follow_up.len());
for item in &self.follow_up {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("followUp"),
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.focal_device.is_empty() {
let mut items = Vec::with_capacity(self.focal_device.len());
for item in &self.focal_device {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("focalDevice"),
super::super::codec::Value::Array(items),
);
}
if !self.used_reference.is_empty() {
let mut items = Vec::with_capacity(self.used_reference.len());
for item in &self.used_reference {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("usedReference"),
super::super::codec::Value::Array(items),
);
}
if !self.used_code.is_empty() {
let mut items = Vec::with_capacity(self.used_code.len());
for item in &self.used_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("usedCode"),
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_instantiates_canonical: Option<&super::super::codec::Value> = None;
let mut raw_instantiates_canonical_element: Option<&super::super::codec::Value> = None;
let mut raw_instantiates_uri: Option<&super::super::codec::Value> = None;
let mut raw_instantiates_uri_element: Option<&super::super::codec::Value> = None;
let mut raw_based_on: 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: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_subject: Option<&super::super::codec::Value> = None;
let mut raw_encounter: Option<&super::super::codec::Value> = None;
let mut raw_performed = super::super::codec::ChoiceSlot::default();
let mut raw_recorder: Option<&super::super::codec::Value> = None;
let mut raw_asserter: 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_reason_code: Option<&super::super::codec::Value> = None;
let mut raw_reason_reference: Option<&super::super::codec::Value> = None;
let mut raw_body_site: Option<&super::super::codec::Value> = None;
let mut raw_outcome: Option<&super::super::codec::Value> = None;
let mut raw_report: Option<&super::super::codec::Value> = None;
let mut raw_complication: Option<&super::super::codec::Value> = None;
let mut raw_complication_detail: Option<&super::super::codec::Value> = None;
let mut raw_follow_up: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_focal_device: Option<&super::super::codec::Value> = None;
let mut raw_used_reference: Option<&super::super::codec::Value> = None;
let mut raw_used_code: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("Procedure") {
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);
}
"instantiatesCanonical" => {
raw_instantiates_canonical = Some(value);
}
"_instantiatesCanonical" => {
raw_instantiates_canonical_element = Some(value);
}
"instantiatesUri" => {
raw_instantiates_uri = Some(value);
}
"_instantiatesUri" => {
raw_instantiates_uri_element = Some(value);
}
"basedOn" => {
raw_based_on = Some(value);
}
"partOf" => {
raw_part_of = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"statusReason" => {
raw_status_reason = Some(value);
}
"category" => {
raw_category = Some(value);
}
"code" => {
raw_code = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"performedDateTime" => {
raw_performed.value("DateTime", value, path)?;
}
"_performedDateTime" => {
raw_performed.element("DateTime", value, path)?;
}
"performedPeriod" => {
raw_performed.value("Period", value, path)?;
}
"_performedPeriod" => {
raw_performed.element("Period", value, path)?;
}
"performedString" => {
raw_performed.value("String", value, path)?;
}
"_performedString" => {
raw_performed.element("String", value, path)?;
}
"performedAge" => {
raw_performed.value("Age", value, path)?;
}
"_performedAge" => {
raw_performed.element("Age", value, path)?;
}
"performedRange" => {
raw_performed.value("Range", value, path)?;
}
"_performedRange" => {
raw_performed.element("Range", value, path)?;
}
"recorder" => {
raw_recorder = Some(value);
}
"asserter" => {
raw_asserter = Some(value);
}
"performer" => {
raw_performer = Some(value);
}
"location" => {
raw_location = Some(value);
}
"reasonCode" => {
raw_reason_code = Some(value);
}
"reasonReference" => {
raw_reason_reference = Some(value);
}
"bodySite" => {
raw_body_site = Some(value);
}
"outcome" => {
raw_outcome = Some(value);
}
"report" => {
raw_report = Some(value);
}
"complication" => {
raw_complication = Some(value);
}
"complicationDetail" => {
raw_complication_detail = Some(value);
}
"followUp" => {
raw_follow_up = Some(value);
}
"note" => {
raw_note = Some(value);
}
"focalDevice" => {
raw_focal_device = Some(value);
}
"usedReference" => {
raw_used_reference = Some(value);
}
"usedCode" => {
raw_used_code = 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_instantiates_canonical = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_instantiates_canonical,
raw_instantiates_canonical_element,
path,
)?
.into_iter()
.enumerate()
{
field_instantiates_canonical.push(path.with_index(
"instantiatesCanonical",
index,
|path| super::super::codec::Primitive::from_json_parts(value, element, path),
)?);
}
let mut field_instantiates_uri = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_instantiates_uri,
raw_instantiates_uri_element,
path,
)?
.into_iter()
.enumerate()
{
field_instantiates_uri.push(path.with_index("instantiatesUri", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let mut field_based_on = Vec::new();
if let Some(raw) = raw_based_on {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_based_on.push(path.with_index("basedOn", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let 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 = raw_status_reason
.map(|value| {
path.with("statusReason", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_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_code = raw_code
.map(|value| {
path.with("code", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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_encounter = raw_encounter
.map(|value| {
path.with("encounter", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_performed = match raw_performed.suffix {
None => None,
Some(suffix) => Some(path.with("performed", |path| {
ProcedurePerformed::from_json_parts(
suffix,
raw_performed.value,
raw_performed.element,
path,
)
})?),
};
let field_recorder = raw_recorder
.map(|value| {
path.with("recorder", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_asserter = raw_asserter
.map(|value| {
path.with("asserter", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_performer = Vec::new();
if let Some(raw) = raw_performer {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_performer.push(path.with_index("performer", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let 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_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 mut field_body_site = Vec::new();
if let Some(raw) = raw_body_site {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_body_site.push(path.with_index("bodySite", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_outcome = raw_outcome
.map(|value| {
path.with("outcome", |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_report = Vec::new();
if let Some(raw) = raw_report {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_report.push(path.with_index("report", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_complication = Vec::new();
if let Some(raw) = raw_complication {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_complication.push(path.with_index("complication", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_complication_detail = Vec::new();
if let Some(raw) = raw_complication_detail {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_complication_detail.push(path.with_index(
"complicationDetail",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_follow_up = Vec::new();
if let Some(raw) = raw_follow_up {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_follow_up.push(path.with_index("followUp", 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_focal_device = Vec::new();
if let Some(raw) = raw_focal_device {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_focal_device.push(path.with_index("focalDevice", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_used_reference = Vec::new();
if let Some(raw) = raw_used_reference {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_used_reference.push(path.with_index("usedReference", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_used_code = Vec::new();
if let Some(raw) = raw_used_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_used_code.push(path.with_index("usedCode", 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,
instantiates_canonical: field_instantiates_canonical,
instantiates_uri: field_instantiates_uri,
based_on: field_based_on,
part_of: field_part_of,
status: field_status,
status_reason: field_status_reason,
category: field_category,
code: field_code,
subject: field_subject,
encounter: field_encounter,
performed: field_performed,
recorder: field_recorder,
asserter: field_asserter,
performer: field_performer,
location: field_location,
reason_code: field_reason_code,
reason_reference: field_reason_reference,
body_site: field_body_site,
outcome: field_outcome,
report: field_report,
complication: field_complication,
complication_detail: field_complication_detail,
follow_up: field_follow_up,
note: field_note,
focal_device: field_focal_device,
used_reference: field_used_reference,
used_code: field_used_code,
})
}
}
impl serde::Serialize for Procedure {
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)?;
}
super::super::codec::element_list_entry(
&mut map,
"_instantiatesCanonical",
&self.instantiates_canonical,
)?;
super::super::codec::element_list_entry(
&mut map,
"_instantiatesUri",
&self.instantiates_uri,
)?;
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
match &self.performed {
Some(ProcedurePerformed::DateTime(inner)) => {
super::super::codec::element_entry(&mut map, "_performedDateTime", inner)?;
}
Some(ProcedurePerformed::String(inner)) => {
super::super::codec::element_entry(&mut map, "_performedString", inner)?;
}
_ => {}
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if let Some(item) = &self.asserter {
serde::ser::SerializeMap::serialize_entry(&mut map, "asserter", item)?;
}
if !self.based_on.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "basedOn", &self.based_on)?;
}
if !self.body_site.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "bodySite", &self.body_site)?;
}
if let Some(item) = &self.category {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", item)?;
}
if let Some(item) = &self.code {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", item)?;
}
if !self.complication.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"complication",
&self.complication,
)?;
}
if !self.complication_detail.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"complicationDetail",
&self.complication_detail,
)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.encounter {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if !self.focal_device.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "focalDevice", &self.focal_device)?;
}
if !self.follow_up.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "followUp", &self.follow_up)?;
}
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)?;
}
super::super::codec::value_list_entry(
&mut map,
"instantiatesCanonical",
&self.instantiates_canonical,
)?;
super::super::codec::value_list_entry(&mut map, "instantiatesUri", &self.instantiates_uri)?;
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.location {
serde::ser::SerializeMap::serialize_entry(&mut map, "location", item)?;
}
if let Some(item) = &self.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 let Some(item) = &self.outcome {
serde::ser::SerializeMap::serialize_entry(&mut map, "outcome", item)?;
}
if !self.part_of.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "partOf", &self.part_of)?;
}
match &self.performed {
Some(ProcedurePerformed::Age(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"performedAge",
inner.as_ref(),
)?;
}
Some(ProcedurePerformed::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "performedDateTime", inner)?;
}
Some(ProcedurePerformed::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"performedPeriod",
inner.as_ref(),
)?;
}
Some(ProcedurePerformed::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"performedRange",
inner.as_ref(),
)?;
}
Some(ProcedurePerformed::String(inner)) => {
super::super::codec::value_entry(&mut map, "performedString", inner)?;
}
None => {}
}
if !self.performer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "performer", &self.performer)?;
}
if !self.reason_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reasonCode", &self.reason_code)?;
}
if !self.reason_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"reasonReference",
&self.reason_reference,
)?;
}
if let Some(item) = &self.recorder {
serde::ser::SerializeMap::serialize_entry(&mut map, "recorder", item)?;
}
if !self.report.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "report", &self.report)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "Procedure")?;
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if let Some(item) = &self.status_reason {
serde::ser::SerializeMap::serialize_entry(&mut map, "statusReason", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", &self.subject)?;
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if !self.used_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "usedCode", &self.used_code)?;
}
if !self.used_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"usedReference",
&self.used_reference,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Procedure {
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("Procedure");
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 ProcedureFocalDevice {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub action: Option<super::codeable_concept::CodeableConcept>,
pub manipulated: super::reference::Reference,
}
impl super::super::codec::Json for ProcedureFocalDevice {
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.action {
object.insert(
std::string::String::from("action"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
object.insert(
std::string::String::from("manipulated"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.manipulated,
)?),
);
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_action: Option<&super::super::codec::Value> = None;
let mut raw_manipulated: 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);
}
"action" => {
raw_action = Some(value);
}
"manipulated" => {
raw_manipulated = 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_action = raw_action
.map(|value| {
path.with("action", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_manipulated = path.with("manipulated", |path| {
let value = raw_manipulated
.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,
action: field_action,
manipulated: field_manipulated,
})
}
}
impl serde::Serialize for ProcedureFocalDevice {
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.action {
serde::ser::SerializeMap::serialize_entry(&mut map, "action", 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)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "manipulated", &self.manipulated)?;
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 ProcedureFocalDevice {
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("ProcedureFocalDevice");
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 ProcedurePerformed {
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
String(super::primitives::String),
Age(Box<super::age::Age>),
Range(Box<super::range::Range>),
}
impl ProcedurePerformed {
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,
)),
Self::String(inner) => Ok((
"String",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Age(inner) => Ok((
"Age",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Range(inner) => Ok((
"Range",
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)))
}
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Age" => {
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::Age(Box::new(inner)))
}
"Range" => {
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::Range(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ProcedurePerformer {
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,
pub on_behalf_of: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ProcedurePerformer {
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)?),
);
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_function: 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);
}
"function" => {
raw_function = 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::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,
)
})?;
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,
function: field_function,
actor: field_actor,
on_behalf_of: field_on_behalf_of,
})
}
}
impl serde::Serialize for ProcedurePerformer {
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,
)?;
}
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 ProcedurePerformer {
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("ProcedurePerformer");
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)
}
}