#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct CarePlan {
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 based_on: Vec<super::reference::Reference>,
pub replaces: Vec<super::reference::Reference>,
pub part_of: Vec<super::reference::Reference>,
pub status: super::primitives::Code,
pub intent: super::primitives::Code,
pub category: Vec<super::codeable_concept::CodeableConcept>,
pub title: Option<super::primitives::String>,
pub description: Option<super::primitives::String>,
pub subject: super::reference::Reference,
pub context: Option<super::reference::Reference>,
pub period: Option<super::period::Period>,
pub author: Vec<super::reference::Reference>,
pub care_team: Vec<super::reference::Reference>,
pub addresses: Vec<super::reference::Reference>,
pub supporting_info: Vec<super::reference::Reference>,
pub goal: Vec<super::reference::Reference>,
pub activity: Vec<CarePlanActivity>,
pub note: Vec<super::annotation::Annotation>,
}
impl super::super::codec::Json for CarePlan {
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("CarePlan")),
);
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.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.replaces.is_empty() {
let mut items = Vec::with_capacity(self.replaces.len());
for item in &self.replaces {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("replaces"),
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(v) = super::super::codec::Primitive::value_json(&self.intent)? {
object.insert(std::string::String::from("intent"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.intent)? {
object.insert(std::string::String::from("_intent"), e);
}
if !self.category.is_empty() {
let mut items = Vec::with_capacity(self.category.len());
for item in &self.category {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.title {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("title"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_title"), e);
}
}
if let Some(item) = &self.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
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 let Some(item) = &self.period {
object.insert(
std::string::String::from("period"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.author.is_empty() {
let mut items = Vec::with_capacity(self.author.len());
for item in &self.author {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("author"),
super::super::codec::Value::Array(items),
);
}
if !self.care_team.is_empty() {
let mut items = Vec::with_capacity(self.care_team.len());
for item in &self.care_team {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("careTeam"),
super::super::codec::Value::Array(items),
);
}
if !self.addresses.is_empty() {
let mut items = Vec::with_capacity(self.addresses.len());
for item in &self.addresses {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("addresses"),
super::super::codec::Value::Array(items),
);
}
if !self.supporting_info.is_empty() {
let mut items = Vec::with_capacity(self.supporting_info.len());
for item in &self.supporting_info {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("supportingInfo"),
super::super::codec::Value::Array(items),
);
}
if !self.goal.is_empty() {
let mut items = Vec::with_capacity(self.goal.len());
for item in &self.goal {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("goal"),
super::super::codec::Value::Array(items),
);
}
if !self.activity.is_empty() {
let mut items = Vec::with_capacity(self.activity.len());
for item in &self.activity {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("activity"),
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),
);
}
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_based_on: Option<&super::super::codec::Value> = None;
let mut raw_replaces: 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_intent: Option<&super::super::codec::Value> = None;
let mut raw_intent_element: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_title: Option<&super::super::codec::Value> = None;
let mut raw_title_element: Option<&super::super::codec::Value> = None;
let mut raw_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
let mut raw_subject: Option<&super::super::codec::Value> = None;
let mut raw_context: Option<&super::super::codec::Value> = None;
let mut raw_period: Option<&super::super::codec::Value> = None;
let mut raw_author: Option<&super::super::codec::Value> = None;
let mut raw_care_team: Option<&super::super::codec::Value> = None;
let mut raw_addresses: Option<&super::super::codec::Value> = None;
let mut raw_supporting_info: Option<&super::super::codec::Value> = None;
let mut raw_goal: Option<&super::super::codec::Value> = None;
let mut raw_activity: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("CarePlan") {
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);
}
"basedOn" => {
raw_based_on = Some(value);
}
"replaces" => {
raw_replaces = Some(value);
}
"partOf" => {
raw_part_of = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"intent" => {
raw_intent = Some(value);
}
"_intent" => {
raw_intent_element = Some(value);
}
"category" => {
raw_category = Some(value);
}
"title" => {
raw_title = Some(value);
}
"_title" => {
raw_title_element = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"context" => {
raw_context = Some(value);
}
"period" => {
raw_period = Some(value);
}
"author" => {
raw_author = Some(value);
}
"careTeam" => {
raw_care_team = Some(value);
}
"addresses" => {
raw_addresses = Some(value);
}
"supportingInfo" => {
raw_supporting_info = Some(value);
}
"goal" => {
raw_goal = Some(value);
}
"activity" => {
raw_activity = Some(value);
}
"note" => {
raw_note = 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_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_replaces = Vec::new();
if let Some(raw) = raw_replaces {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_replaces.push(path.with_index("replaces", 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_intent = path.with("intent", |path| {
super::super::codec::Primitive::from_json_parts(raw_intent, raw_intent_element, path)
})?;
let mut field_category = Vec::new();
if let Some(raw) = raw_category {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_category.push(path.with_index("category", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_title = match (raw_title, raw_title_element) {
(None, None) => None,
(value, element) => Some(path.with("title", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_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 field_period = raw_period
.map(|value| {
path.with("period", |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_author = Vec::new();
if let Some(raw) = raw_author {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_author.push(path.with_index("author", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_care_team = Vec::new();
if let Some(raw) = raw_care_team {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_care_team.push(path.with_index("careTeam", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_addresses = Vec::new();
if let Some(raw) = raw_addresses {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_addresses.push(path.with_index("addresses", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_supporting_info = Vec::new();
if let Some(raw) = raw_supporting_info {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_supporting_info.push(path.with_index("supportingInfo", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_goal = Vec::new();
if let Some(raw) = raw_goal {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_goal.push(path.with_index("goal", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_activity = Vec::new();
if let Some(raw) = raw_activity {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_activity.push(path.with_index("activity", 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,
)
})?);
}
}
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,
based_on: field_based_on,
replaces: field_replaces,
part_of: field_part_of,
status: field_status,
intent: field_intent,
category: field_category,
title: field_title,
description: field_description,
subject: field_subject,
context: field_context,
period: field_period,
author: field_author,
care_team: field_care_team,
addresses: field_addresses,
supporting_info: field_supporting_info,
goal: field_goal,
activity: field_activity,
note: field_note,
})
}
}
impl serde::Serialize for CarePlan {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.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)?;
}
super::super::codec::element_entry(&mut map, "_intent", &self.intent)?;
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if let Some(item) = &self.title {
super::super::codec::element_entry(&mut map, "_title", item)?;
}
if !self.activity.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "activity", &self.activity)?;
}
if !self.addresses.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "addresses", &self.addresses)?;
}
if !self.author.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "author", &self.author)?;
}
if !self.based_on.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "basedOn", &self.based_on)?;
}
if !self.care_team.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "careTeam", &self.care_team)?;
}
if !self.category.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
}
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 let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if !self.goal.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "goal", &self.goal)?;
}
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)?;
}
super::super::codec::value_entry(&mut map, "intent", &self.intent)?;
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", 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 !self.part_of.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "partOf", &self.part_of)?;
}
if let Some(item) = &self.period {
serde::ser::SerializeMap::serialize_entry(&mut map, "period", item)?;
}
if !self.replaces.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "replaces", &self.replaces)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "CarePlan")?;
super::super::codec::value_entry(&mut map, "status", &self.status)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", &self.subject)?;
if !self.supporting_info.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"supportingInfo",
&self.supporting_info,
)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.title {
super::super::codec::value_entry(&mut map, "title", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CarePlan {
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("CarePlan");
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 CarePlanActivity {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub outcome_codeable_concept: Vec<super::codeable_concept::CodeableConcept>,
pub outcome_reference: Vec<super::reference::Reference>,
pub progress: Vec<super::annotation::Annotation>,
pub reference: Option<super::reference::Reference>,
pub detail: Option<CarePlanActivityDetail>,
}
impl super::super::codec::Json for CarePlanActivity {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.outcome_codeable_concept.is_empty() {
let mut items = Vec::with_capacity(self.outcome_codeable_concept.len());
for item in &self.outcome_codeable_concept {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("outcomeCodeableConcept"),
super::super::codec::Value::Array(items),
);
}
if !self.outcome_reference.is_empty() {
let mut items = Vec::with_capacity(self.outcome_reference.len());
for item in &self.outcome_reference {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("outcomeReference"),
super::super::codec::Value::Array(items),
);
}
if !self.progress.is_empty() {
let mut items = Vec::with_capacity(self.progress.len());
for item in &self.progress {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("progress"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.reference {
object.insert(
std::string::String::from("reference"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.detail {
object.insert(
std::string::String::from("detail"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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_outcome_codeable_concept: Option<&super::super::codec::Value> = None;
let mut raw_outcome_reference: Option<&super::super::codec::Value> = None;
let mut raw_progress: Option<&super::super::codec::Value> = None;
let mut raw_reference: Option<&super::super::codec::Value> = None;
let mut raw_detail: 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);
}
"outcomeCodeableConcept" => {
raw_outcome_codeable_concept = Some(value);
}
"outcomeReference" => {
raw_outcome_reference = Some(value);
}
"progress" => {
raw_progress = Some(value);
}
"reference" => {
raw_reference = Some(value);
}
"detail" => {
raw_detail = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_outcome_codeable_concept = Vec::new();
if let Some(raw) = raw_outcome_codeable_concept {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_outcome_codeable_concept.push(path.with_index(
"outcomeCodeableConcept",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_outcome_reference = Vec::new();
if let Some(raw) = raw_outcome_reference {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_outcome_reference.push(path.with_index(
"outcomeReference",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_progress = Vec::new();
if let Some(raw) = raw_progress {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_progress.push(path.with_index("progress", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_reference = raw_reference
.map(|value| {
path.with("reference", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_detail = raw_detail
.map(|value| {
path.with("detail", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
outcome_codeable_concept: field_outcome_codeable_concept,
outcome_reference: field_outcome_reference,
progress: field_progress,
reference: field_reference,
detail: field_detail,
})
}
}
impl serde::Serialize for CarePlanActivity {
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.detail {
serde::ser::SerializeMap::serialize_entry(&mut map, "detail", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.outcome_codeable_concept.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"outcomeCodeableConcept",
&self.outcome_codeable_concept,
)?;
}
if !self.outcome_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"outcomeReference",
&self.outcome_reference,
)?;
}
if !self.progress.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "progress", &self.progress)?;
}
if let Some(item) = &self.reference {
serde::ser::SerializeMap::serialize_entry(&mut map, "reference", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CarePlanActivity {
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("CarePlanActivity");
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 CarePlanActivityDetail {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub definition: Option<super::reference::Reference>,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub reason_code: Vec<super::codeable_concept::CodeableConcept>,
pub reason_reference: Vec<super::reference::Reference>,
pub goal: Vec<super::reference::Reference>,
pub status: super::primitives::Code,
pub status_reason: Option<super::primitives::String>,
pub prohibited: Option<super::primitives::Boolean>,
pub scheduled: Option<CarePlanActivityDetailScheduled>,
pub location: Option<super::reference::Reference>,
pub performer: Vec<super::reference::Reference>,
pub product: Option<CarePlanActivityDetailProduct>,
pub daily_amount: Option<super::quantity::Quantity>,
pub quantity: Option<super::quantity::Quantity>,
pub description: Option<super::primitives::String>,
}
impl super::super::codec::Json for CarePlanActivityDetail {
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.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.definition {
object.insert(
std::string::String::from("definition"),
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)?),
);
}
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.goal.is_empty() {
let mut items = Vec::with_capacity(self.goal.len());
for item in &self.goal {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("goal"),
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 {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("statusReason"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_statusReason"), e);
}
}
if let Some(item) = &self.prohibited {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("prohibited"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_prohibited"), e);
}
}
if let Some(item) = &self.scheduled {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("scheduled{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_scheduled{suffix}"), element);
}
}
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.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.product {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("product{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_product{suffix}"), element);
}
}
if let Some(item) = &self.daily_amount {
object.insert(
std::string::String::from("dailyAmount"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.quantity {
object.insert(
std::string::String::from("quantity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
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_category: Option<&super::super::codec::Value> = None;
let mut raw_definition: Option<&super::super::codec::Value> = None;
let mut raw_code: 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_goal: 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_status_reason_element: Option<&super::super::codec::Value> = None;
let mut raw_prohibited: Option<&super::super::codec::Value> = None;
let mut raw_prohibited_element: Option<&super::super::codec::Value> = None;
let mut raw_scheduled = super::super::codec::ChoiceSlot::default();
let mut raw_location: Option<&super::super::codec::Value> = None;
let mut raw_performer: Option<&super::super::codec::Value> = None;
let mut raw_product = super::super::codec::ChoiceSlot::default();
let mut raw_daily_amount: Option<&super::super::codec::Value> = None;
let mut raw_quantity: Option<&super::super::codec::Value> = None;
let mut raw_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
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);
}
"category" => {
raw_category = Some(value);
}
"definition" => {
raw_definition = Some(value);
}
"code" => {
raw_code = Some(value);
}
"reasonCode" => {
raw_reason_code = Some(value);
}
"reasonReference" => {
raw_reason_reference = Some(value);
}
"goal" => {
raw_goal = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"statusReason" => {
raw_status_reason = Some(value);
}
"_statusReason" => {
raw_status_reason_element = Some(value);
}
"prohibited" => {
raw_prohibited = Some(value);
}
"_prohibited" => {
raw_prohibited_element = Some(value);
}
"scheduledTiming" => {
raw_scheduled.value("Timing", value, path)?;
}
"_scheduledTiming" => {
raw_scheduled.element("Timing", value, path)?;
}
"scheduledPeriod" => {
raw_scheduled.value("Period", value, path)?;
}
"_scheduledPeriod" => {
raw_scheduled.element("Period", value, path)?;
}
"scheduledString" => {
raw_scheduled.value("String", value, path)?;
}
"_scheduledString" => {
raw_scheduled.element("String", value, path)?;
}
"location" => {
raw_location = Some(value);
}
"performer" => {
raw_performer = Some(value);
}
"productCodeableConcept" => {
raw_product.value("CodeableConcept", value, path)?;
}
"_productCodeableConcept" => {
raw_product.element("CodeableConcept", value, path)?;
}
"productReference" => {
raw_product.value("Reference", value, path)?;
}
"_productReference" => {
raw_product.element("Reference", value, path)?;
}
"dailyAmount" => {
raw_daily_amount = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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_definition = raw_definition
.map(|value| {
path.with("definition", |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 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_goal = Vec::new();
if let Some(raw) = raw_goal {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_goal.push(path.with_index("goal", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
let field_status_reason = match (raw_status_reason, raw_status_reason_element) {
(None, None) => None,
(value, element) => Some(path.with("statusReason", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_prohibited = match (raw_prohibited, raw_prohibited_element) {
(None, None) => None,
(value, element) => Some(path.with("prohibited", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_scheduled = match raw_scheduled.suffix {
None => None,
Some(suffix) => Some(path.with("scheduled", |path| {
CarePlanActivityDetailScheduled::from_json_parts(
suffix,
raw_scheduled.value,
raw_scheduled.element,
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_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_product = match raw_product.suffix {
None => None,
Some(suffix) => Some(path.with("product", |path| {
CarePlanActivityDetailProduct::from_json_parts(
suffix,
raw_product.value,
raw_product.element,
path,
)
})?),
};
let field_daily_amount = raw_daily_amount
.map(|value| {
path.with("dailyAmount", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_quantity = raw_quantity
.map(|value| {
path.with("quantity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
category: field_category,
definition: field_definition,
code: field_code,
reason_code: field_reason_code,
reason_reference: field_reason_reference,
goal: field_goal,
status: field_status,
status_reason: field_status_reason,
prohibited: field_prohibited,
scheduled: field_scheduled,
location: field_location,
performer: field_performer,
product: field_product,
daily_amount: field_daily_amount,
quantity: field_quantity,
description: field_description,
})
}
}
impl serde::Serialize for CarePlanActivityDetail {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.prohibited {
super::super::codec::element_entry(&mut map, "_prohibited", item)?;
}
if let Some(CarePlanActivityDetailScheduled::String(inner)) = &self.scheduled {
super::super::codec::element_entry(&mut map, "_scheduledString", inner)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if let Some(item) = &self.status_reason {
super::super::codec::element_entry(&mut map, "_statusReason", item)?;
}
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 let Some(item) = &self.daily_amount {
serde::ser::SerializeMap::serialize_entry(&mut map, "dailyAmount", item)?;
}
if let Some(item) = &self.definition {
serde::ser::SerializeMap::serialize_entry(&mut map, "definition", item)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if !self.goal.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "goal", &self.goal)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.location {
serde::ser::SerializeMap::serialize_entry(&mut map, "location", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.performer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "performer", &self.performer)?;
}
match &self.product {
Some(CarePlanActivityDetailProduct::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"productCodeableConcept",
inner.as_ref(),
)?;
}
Some(CarePlanActivityDetailProduct::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"productReference",
inner.as_ref(),
)?;
}
None => {}
}
if let Some(item) = &self.prohibited {
super::super::codec::value_entry(&mut map, "prohibited", item)?;
}
if let Some(item) = &self.quantity {
serde::ser::SerializeMap::serialize_entry(&mut map, "quantity", item)?;
}
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,
)?;
}
match &self.scheduled {
Some(CarePlanActivityDetailScheduled::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"scheduledPeriod",
inner.as_ref(),
)?;
}
Some(CarePlanActivityDetailScheduled::String(inner)) => {
super::super::codec::value_entry(&mut map, "scheduledString", inner)?;
}
Some(CarePlanActivityDetailScheduled::Timing(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"scheduledTiming",
inner.as_ref(),
)?;
}
None => {}
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if let Some(item) = &self.status_reason {
super::super::codec::value_entry(&mut map, "statusReason", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CarePlanActivityDetail {
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("CarePlanActivityDetail");
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 CarePlanActivityDetailProduct {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Reference(Box<super::reference::Reference>),
}
impl CarePlanActivityDetailProduct {
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, PartialEq, Eq)]
pub enum CarePlanActivityDetailScheduled {
Timing(Box<super::timing::Timing>),
Period(Box<super::period::Period>),
String(super::primitives::String),
}
impl CarePlanActivityDetailScheduled {
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::Timing(inner) => Ok((
"Timing",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
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)?,
)),
}
}
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 {
"Timing" => {
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::Timing(Box::new(inner)))
}
"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)?,
)),
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}