#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Goal {
pub id: Option<super::primitives::Id>,
pub meta: Option<super::meta::Meta>,
pub implicit_rules: Option<super::primitives::Uri>,
pub language: Option<super::primitives::Code>,
pub text: Option<super::narrative::Narrative>,
pub contained: Vec<super::resource::Resource>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Vec<super::identifier::Identifier>,
pub status: super::primitives::Code,
pub category: Vec<super::codeable_concept::CodeableConcept>,
pub priority: Option<super::codeable_concept::CodeableConcept>,
pub description: super::codeable_concept::CodeableConcept,
pub subject: Option<super::reference::Reference>,
pub start: Option<GoalStart>,
pub target: Option<GoalTarget>,
pub status_date: Option<super::primitives::Date>,
pub status_reason: Option<super::primitives::String>,
pub expressed_by: Option<super::reference::Reference>,
pub addresses: Vec<super::reference::Reference>,
pub note: Vec<super::annotation::Annotation>,
pub outcome_code: Vec<super::codeable_concept::CodeableConcept>,
pub outcome_reference: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for Goal {
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("Goal")),
);
if let Some(item) = &self.id {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("id"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_id"), e);
}
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.status)? {
object.insert(std::string::String::from("status"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.status)? {
object.insert(std::string::String::from("_status"), e);
}
if !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.priority {
object.insert(
std::string::String::from("priority"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
object.insert(
std::string::String::from("description"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.description,
)?),
);
if let Some(item) = &self.subject {
object.insert(
std::string::String::from("subject"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.start {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("start{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_start{suffix}"), element);
}
}
if let Some(item) = &self.target {
object.insert(
std::string::String::from("target"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.status_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("statusDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_statusDate"), 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.expressed_by {
object.insert(
std::string::String::from("expressedBy"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.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.outcome_code.is_empty() {
let mut items = Vec::with_capacity(self.outcome_code.len());
for item in &self.outcome_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("outcomeCode"),
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),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_id_element: Option<&super::super::codec::Value> = None;
let mut raw_meta: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_language_element: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_contained: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_status: Option<&super::super::codec::Value> = None;
let mut raw_status_element: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_priority: Option<&super::super::codec::Value> = None;
let mut raw_description: Option<&super::super::codec::Value> = None;
let mut raw_subject: Option<&super::super::codec::Value> = None;
let mut raw_start = super::super::codec::ChoiceSlot::default();
let mut raw_target: Option<&super::super::codec::Value> = None;
let mut raw_status_date: Option<&super::super::codec::Value> = None;
let mut raw_status_date_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_expressed_by: Option<&super::super::codec::Value> = None;
let mut raw_addresses: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_outcome_code: Option<&super::super::codec::Value> = None;
let mut raw_outcome_reference: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("Goal") {
return Err(path.error(super::super::codec::DecodeErrorKind::ResourceType));
}
}
"id" => {
raw_id = Some(value);
}
"_id" => {
raw_id_element = Some(value);
}
"meta" => {
raw_meta = Some(value);
}
"implicitRules" => {
raw_implicit_rules = Some(value);
}
"_implicitRules" => {
raw_implicit_rules_element = Some(value);
}
"language" => {
raw_language = Some(value);
}
"_language" => {
raw_language_element = Some(value);
}
"text" => {
raw_text = Some(value);
}
"contained" => {
raw_contained = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"identifier" => {
raw_identifier = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"category" => {
raw_category = Some(value);
}
"priority" => {
raw_priority = Some(value);
}
"description" => {
raw_description = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"startDate" => {
raw_start.value("Date", value, path)?;
}
"_startDate" => {
raw_start.element("Date", value, path)?;
}
"startCodeableConcept" => {
raw_start.value("CodeableConcept", value, path)?;
}
"_startCodeableConcept" => {
raw_start.element("CodeableConcept", value, path)?;
}
"target" => {
raw_target = Some(value);
}
"statusDate" => {
raw_status_date = Some(value);
}
"_statusDate" => {
raw_status_date_element = Some(value);
}
"statusReason" => {
raw_status_reason = Some(value);
}
"_statusReason" => {
raw_status_reason_element = Some(value);
}
"expressedBy" => {
raw_expressed_by = Some(value);
}
"addresses" => {
raw_addresses = Some(value);
}
"note" => {
raw_note = Some(value);
}
"outcomeCode" => {
raw_outcome_code = Some(value);
}
"outcomeReference" => {
raw_outcome_reference = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = match (raw_id, raw_id_element) {
(None, None) => None,
(value, element) => Some(path.with("id", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
let 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_priority = raw_priority
.map(|value| {
path.with("priority", |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 = path.with("description", |path| {
let value = raw_description
.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_subject = raw_subject
.map(|value| {
path.with("subject", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_start = match raw_start.suffix {
None => None,
Some(suffix) => Some(path.with("start", |path| {
GoalStart::from_json_parts(suffix, raw_start.value, raw_start.element, path)
})?),
};
let field_target = raw_target
.map(|value| {
path.with("target", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_status_date = match (raw_status_date, raw_status_date_element) {
(None, None) => None,
(value, element) => Some(path.with("statusDate", |path| {
super::super::codec::Primitive::from_json_parts(value, 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_expressed_by = raw_expressed_by
.map(|value| {
path.with("expressedBy", |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_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_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_outcome_code = Vec::new();
if let Some(raw) = raw_outcome_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_outcome_code.push(path.with_index("outcomeCode", 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,
)
},
)?);
}
}
Ok(Self {
id: field_id,
meta: field_meta,
implicit_rules: field_implicit_rules,
language: field_language,
text: field_text,
contained: field_contained,
extension: field_extension,
modifier_extension: field_modifier_extension,
identifier: field_identifier,
status: field_status,
category: field_category,
priority: field_priority,
description: field_description,
subject: field_subject,
start: field_start,
target: field_target,
status_date: field_status_date,
status_reason: field_status_reason,
expressed_by: field_expressed_by,
addresses: field_addresses,
note: field_note,
outcome_code: field_outcome_code,
outcome_reference: field_outcome_reference,
})
}
}
impl serde::Serialize for Goal {
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.id {
super::super::codec::element_entry(&mut map, "_id", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(GoalStart::Date(inner)) = &self.start {
super::super::codec::element_entry(&mut map, "_startDate", inner)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if let Some(item) = &self.status_date {
super::super::codec::element_entry(&mut map, "_statusDate", item)?;
}
if let Some(item) = &self.status_reason {
super::super::codec::element_entry(&mut map, "_statusReason", item)?;
}
if !self.addresses.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "addresses", &self.addresses)?;
}
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)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "description", &self.description)?;
if let Some(item) = &self.expressed_by {
serde::ser::SerializeMap::serialize_entry(&mut map, "expressedBy", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.id {
super::super::codec::value_entry(&mut map, "id", item)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.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.outcome_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "outcomeCode", &self.outcome_code)?;
}
if !self.outcome_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"outcomeReference",
&self.outcome_reference,
)?;
}
if let Some(item) = &self.priority {
serde::ser::SerializeMap::serialize_entry(&mut map, "priority", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "Goal")?;
match &self.start {
Some(GoalStart::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"startCodeableConcept",
inner.as_ref(),
)?;
}
Some(GoalStart::Date(inner)) => {
super::super::codec::value_entry(&mut map, "startDate", inner)?;
}
None => {}
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if let Some(item) = &self.status_date {
super::super::codec::value_entry(&mut map, "statusDate", item)?;
}
if let Some(item) = &self.status_reason {
super::super::codec::value_entry(&mut map, "statusReason", item)?;
}
if let Some(item) = &self.subject {
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", item)?;
}
if let Some(item) = &self.target {
serde::ser::SerializeMap::serialize_entry(&mut map, "target", item)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Goal {
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("Goal");
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 GoalStart {
Date(super::primitives::Date),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
}
impl GoalStart {
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::Date(inner) => Ok((
"Date",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
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 {
"Date" => Ok(Self::Date(super::super::codec::Primitive::from_json_parts(
value, element, path,
)?)),
"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)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct GoalTarget {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub measure: Option<super::codeable_concept::CodeableConcept>,
pub detail: Option<GoalTargetDetail>,
pub due: Option<GoalTargetDue>,
}
impl super::super::codec::Json for GoalTarget {
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.measure {
object.insert(
std::string::String::from("measure"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.detail {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("detail{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_detail{suffix}"), element);
}
}
if let Some(item) = &self.due {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("due{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_due{suffix}"), element);
}
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_measure: Option<&super::super::codec::Value> = None;
let mut raw_detail = super::super::codec::ChoiceSlot::default();
let mut raw_due = super::super::codec::ChoiceSlot::default();
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"measure" => {
raw_measure = Some(value);
}
"detailQuantity" => {
raw_detail.value("Quantity", value, path)?;
}
"_detailQuantity" => {
raw_detail.element("Quantity", value, path)?;
}
"detailRange" => {
raw_detail.value("Range", value, path)?;
}
"_detailRange" => {
raw_detail.element("Range", value, path)?;
}
"detailCodeableConcept" => {
raw_detail.value("CodeableConcept", value, path)?;
}
"_detailCodeableConcept" => {
raw_detail.element("CodeableConcept", value, path)?;
}
"dueDate" => {
raw_due.value("Date", value, path)?;
}
"_dueDate" => {
raw_due.element("Date", value, path)?;
}
"dueDuration" => {
raw_due.value("Duration", value, path)?;
}
"_dueDuration" => {
raw_due.element("Duration", value, path)?;
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_measure = raw_measure
.map(|value| {
path.with("measure", |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 = match raw_detail.suffix {
None => None,
Some(suffix) => Some(path.with("detail", |path| {
GoalTargetDetail::from_json_parts(
suffix,
raw_detail.value,
raw_detail.element,
path,
)
})?),
};
let field_due = match raw_due.suffix {
None => None,
Some(suffix) => Some(path.with("due", |path| {
GoalTargetDue::from_json_parts(suffix, raw_due.value, raw_due.element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
measure: field_measure,
detail: field_detail,
due: field_due,
})
}
}
impl serde::Serialize for GoalTarget {
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(GoalTargetDue::Date(inner)) = &self.due {
super::super::codec::element_entry(&mut map, "_dueDate", inner)?;
}
match &self.detail {
Some(GoalTargetDetail::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"detailCodeableConcept",
inner.as_ref(),
)?;
}
Some(GoalTargetDetail::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"detailQuantity",
inner.as_ref(),
)?;
}
Some(GoalTargetDetail::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "detailRange", inner.as_ref())?;
}
None => {}
}
match &self.due {
Some(GoalTargetDue::Date(inner)) => {
super::super::codec::value_entry(&mut map, "dueDate", inner)?;
}
Some(GoalTargetDue::Duration(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "dueDuration", inner.as_ref())?;
}
None => {}
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.measure {
serde::ser::SerializeMap::serialize_entry(&mut map, "measure", item)?;
}
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 GoalTarget {
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("GoalTarget");
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 GoalTargetDetail {
Quantity(Box<super::quantity::Quantity>),
Range(Box<super::range::Range>),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
}
impl GoalTargetDetail {
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::Quantity(inner) => Ok((
"Quantity",
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,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
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 {
"Quantity" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Quantity(Box::new(inner)))
}
"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)))
}
"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)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GoalTargetDue {
Date(super::primitives::Date),
Duration(Box<super::duration::Duration>),
}
impl GoalTargetDue {
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::Date(inner) => Ok((
"Date",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Duration(inner) => Ok((
"Duration",
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 {
"Date" => Ok(Self::Date(super::super::codec::Primitive::from_json_parts(
value, element, path,
)?)),
"Duration" => {
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::Duration(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}