#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Consent {
pub id: Option<std::string::String>,
pub meta: Option<super::meta::Meta>,
pub implicit_rules: Option<super::primitives::Uri>,
pub language: Option<super::primitives::Code>,
pub text: Option<super::narrative::Narrative>,
pub contained: Vec<super::resource::Resource>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Vec<super::identifier::Identifier>,
pub status: super::primitives::Code,
pub category: Vec<super::codeable_concept::CodeableConcept>,
pub subject: Option<super::reference::Reference>,
pub date: Option<super::primitives::Date>,
pub period: Option<super::period::Period>,
pub grantor: Vec<super::reference::Reference>,
pub grantee: Vec<super::reference::Reference>,
pub manager: Vec<super::reference::Reference>,
pub controller: Vec<super::reference::Reference>,
pub source_attachment: Vec<super::attachment::Attachment>,
pub source_reference: Vec<super::reference::Reference>,
pub regulatory_basis: Vec<super::codeable_concept::CodeableConcept>,
pub policy_basis: Option<ConsentPolicyBasis>,
pub policy_text: Vec<super::reference::Reference>,
pub verification: Vec<ConsentVerification>,
pub decision: Option<super::primitives::Code>,
pub provision: Vec<ConsentProvision>,
}
impl super::super::codec::Json for Consent {
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("Consent")),
);
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if 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.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.date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("date"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_date"), e);
}
}
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.grantor.is_empty() {
let mut items = Vec::with_capacity(self.grantor.len());
for item in &self.grantor {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("grantor"),
super::super::codec::Value::Array(items),
);
}
if !self.grantee.is_empty() {
let mut items = Vec::with_capacity(self.grantee.len());
for item in &self.grantee {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("grantee"),
super::super::codec::Value::Array(items),
);
}
if !self.manager.is_empty() {
let mut items = Vec::with_capacity(self.manager.len());
for item in &self.manager {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("manager"),
super::super::codec::Value::Array(items),
);
}
if !self.controller.is_empty() {
let mut items = Vec::with_capacity(self.controller.len());
for item in &self.controller {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("controller"),
super::super::codec::Value::Array(items),
);
}
if !self.source_attachment.is_empty() {
let mut items = Vec::with_capacity(self.source_attachment.len());
for item in &self.source_attachment {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("sourceAttachment"),
super::super::codec::Value::Array(items),
);
}
if !self.source_reference.is_empty() {
let mut items = Vec::with_capacity(self.source_reference.len());
for item in &self.source_reference {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("sourceReference"),
super::super::codec::Value::Array(items),
);
}
if !self.regulatory_basis.is_empty() {
let mut items = Vec::with_capacity(self.regulatory_basis.len());
for item in &self.regulatory_basis {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("regulatoryBasis"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.policy_basis {
object.insert(
std::string::String::from("policyBasis"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.policy_text.is_empty() {
let mut items = Vec::with_capacity(self.policy_text.len());
for item in &self.policy_text {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("policyText"),
super::super::codec::Value::Array(items),
);
}
if !self.verification.is_empty() {
let mut items = Vec::with_capacity(self.verification.len());
for item in &self.verification {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("verification"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.decision {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("decision"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_decision"), e);
}
}
if !self.provision.is_empty() {
let mut items = Vec::with_capacity(self.provision.len());
for item in &self.provision {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("provision"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_meta: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_language_element: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_contained: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_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_subject: Option<&super::super::codec::Value> = None;
let mut raw_date: Option<&super::super::codec::Value> = None;
let mut raw_date_element: Option<&super::super::codec::Value> = None;
let mut raw_period: Option<&super::super::codec::Value> = None;
let mut raw_grantor: Option<&super::super::codec::Value> = None;
let mut raw_grantee: Option<&super::super::codec::Value> = None;
let mut raw_manager: Option<&super::super::codec::Value> = None;
let mut raw_controller: Option<&super::super::codec::Value> = None;
let mut raw_source_attachment: Option<&super::super::codec::Value> = None;
let mut raw_source_reference: Option<&super::super::codec::Value> = None;
let mut raw_regulatory_basis: Option<&super::super::codec::Value> = None;
let mut raw_policy_basis: Option<&super::super::codec::Value> = None;
let mut raw_policy_text: Option<&super::super::codec::Value> = None;
let mut raw_verification: Option<&super::super::codec::Value> = None;
let mut raw_decision: Option<&super::super::codec::Value> = None;
let mut raw_decision_element: Option<&super::super::codec::Value> = None;
let mut raw_provision: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("Consent") {
return Err(path.error(super::super::codec::DecodeErrorKind::ResourceType));
}
}
"id" => {
raw_id = Some(value);
}
"meta" => {
raw_meta = Some(value);
}
"implicitRules" => {
raw_implicit_rules = Some(value);
}
"_implicitRules" => {
raw_implicit_rules_element = Some(value);
}
"language" => {
raw_language = Some(value);
}
"_language" => {
raw_language_element = Some(value);
}
"text" => {
raw_text = Some(value);
}
"contained" => {
raw_contained = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"identifier" => {
raw_identifier = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"category" => {
raw_category = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_element = Some(value);
}
"period" => {
raw_period = Some(value);
}
"grantor" => {
raw_grantor = Some(value);
}
"grantee" => {
raw_grantee = Some(value);
}
"manager" => {
raw_manager = Some(value);
}
"controller" => {
raw_controller = Some(value);
}
"sourceAttachment" => {
raw_source_attachment = Some(value);
}
"sourceReference" => {
raw_source_reference = Some(value);
}
"regulatoryBasis" => {
raw_regulatory_basis = Some(value);
}
"policyBasis" => {
raw_policy_basis = Some(value);
}
"policyText" => {
raw_policy_text = Some(value);
}
"verification" => {
raw_verification = Some(value);
}
"decision" => {
raw_decision = Some(value);
}
"_decision" => {
raw_decision_element = Some(value);
}
"provision" => {
raw_provision = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let 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_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_date = match (raw_date, raw_date_element) {
(None, None) => None,
(value, element) => Some(path.with("date", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
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_grantor = Vec::new();
if let Some(raw) = raw_grantor {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_grantor.push(path.with_index("grantor", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_grantee = Vec::new();
if let Some(raw) = raw_grantee {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_grantee.push(path.with_index("grantee", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_manager = Vec::new();
if let Some(raw) = raw_manager {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_manager.push(path.with_index("manager", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_controller = Vec::new();
if let Some(raw) = raw_controller {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_controller.push(path.with_index("controller", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_source_attachment = Vec::new();
if let Some(raw) = raw_source_attachment {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_source_attachment.push(path.with_index(
"sourceAttachment",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_source_reference = Vec::new();
if let Some(raw) = raw_source_reference {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_source_reference.push(path.with_index("sourceReference", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_regulatory_basis = Vec::new();
if let Some(raw) = raw_regulatory_basis {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_regulatory_basis.push(path.with_index("regulatoryBasis", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_policy_basis = raw_policy_basis
.map(|value| {
path.with("policyBasis", |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_policy_text = Vec::new();
if let Some(raw) = raw_policy_text {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_policy_text.push(path.with_index("policyText", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_verification = Vec::new();
if let Some(raw) = raw_verification {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_verification.push(path.with_index("verification", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_decision = match (raw_decision, raw_decision_element) {
(None, None) => None,
(value, element) => Some(path.with("decision", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_provision = Vec::new();
if let Some(raw) = raw_provision {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_provision.push(path.with_index("provision", 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,
subject: field_subject,
date: field_date,
period: field_period,
grantor: field_grantor,
grantee: field_grantee,
manager: field_manager,
controller: field_controller,
source_attachment: field_source_attachment,
source_reference: field_source_reference,
regulatory_basis: field_regulatory_basis,
policy_basis: field_policy_basis,
policy_text: field_policy_text,
verification: field_verification,
decision: field_decision,
provision: field_provision,
})
}
}
impl serde::Serialize for Consent {
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.date {
super::super::codec::element_entry(&mut map, "_date", item)?;
}
if let Some(item) = &self.decision {
super::super::codec::element_entry(&mut map, "_decision", 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)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
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 !self.controller.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "controller", &self.controller)?;
}
if let Some(item) = &self.date {
super::super::codec::value_entry(&mut map, "date", item)?;
}
if let Some(item) = &self.decision {
super::super::codec::value_entry(&mut map, "decision", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if !self.grantee.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "grantee", &self.grantee)?;
}
if !self.grantor.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "grantor", &self.grantor)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if !self.manager.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "manager", &self.manager)?;
}
if let Some(item) = &self.meta {
serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.period {
serde::ser::SerializeMap::serialize_entry(&mut map, "period", item)?;
}
if let Some(item) = &self.policy_basis {
serde::ser::SerializeMap::serialize_entry(&mut map, "policyBasis", item)?;
}
if !self.policy_text.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "policyText", &self.policy_text)?;
}
if !self.provision.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "provision", &self.provision)?;
}
if !self.regulatory_basis.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"regulatoryBasis",
&self.regulatory_basis,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "Consent")?;
if !self.source_attachment.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"sourceAttachment",
&self.source_attachment,
)?;
}
if !self.source_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"sourceReference",
&self.source_reference,
)?;
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if let Some(item) = &self.subject {
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", item)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if !self.verification.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"verification",
&self.verification,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Consent {
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("Consent");
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 ConsentPolicyBasis {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub reference: Option<super::reference::Reference>,
pub uri: Option<super::primitives::Uri>,
}
impl super::super::codec::Json for ConsentPolicyBasis {
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.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.uri {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("uri"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_uri"), 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_reference: Option<&super::super::codec::Value> = None;
let mut raw_uri: Option<&super::super::codec::Value> = None;
let mut raw_uri_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);
}
"reference" => {
raw_reference = Some(value);
}
"uri" => {
raw_uri = Some(value);
}
"_uri" => {
raw_uri_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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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_uri = match (raw_uri, raw_uri_element) {
(None, None) => None,
(value, element) => Some(path.with("uri", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
reference: field_reference,
uri: field_uri,
})
}
}
impl serde::Serialize for ConsentPolicyBasis {
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.uri {
super::super::codec::element_entry(&mut map, "_uri", 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 let Some(item) = &self.reference {
serde::ser::SerializeMap::serialize_entry(&mut map, "reference", item)?;
}
if let Some(item) = &self.uri {
super::super::codec::value_entry(&mut map, "uri", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ConsentPolicyBasis {
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("ConsentPolicyBasis");
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 ConsentProvision {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub period: Option<super::period::Period>,
pub actor: Vec<ConsentProvisionActor>,
pub action: Vec<super::codeable_concept::CodeableConcept>,
pub security_label: Vec<super::coding::Coding>,
pub purpose: Vec<super::coding::Coding>,
pub document_type: Vec<super::coding::Coding>,
pub resource_type: Vec<super::coding::Coding>,
pub code: Vec<super::codeable_concept::CodeableConcept>,
pub data_period: Option<super::period::Period>,
pub data: Vec<ConsentProvisionData>,
pub provision: Vec<ConsentProvision>,
}
impl super::super::codec::Json for ConsentProvision {
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.period {
object.insert(
std::string::String::from("period"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.actor.is_empty() {
let mut items = Vec::with_capacity(self.actor.len());
for item in &self.actor {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("actor"),
super::super::codec::Value::Array(items),
);
}
if !self.action.is_empty() {
let mut items = Vec::with_capacity(self.action.len());
for item in &self.action {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("action"),
super::super::codec::Value::Array(items),
);
}
if !self.security_label.is_empty() {
let mut items = Vec::with_capacity(self.security_label.len());
for item in &self.security_label {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("securityLabel"),
super::super::codec::Value::Array(items),
);
}
if !self.purpose.is_empty() {
let mut items = Vec::with_capacity(self.purpose.len());
for item in &self.purpose {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("purpose"),
super::super::codec::Value::Array(items),
);
}
if !self.document_type.is_empty() {
let mut items = Vec::with_capacity(self.document_type.len());
for item in &self.document_type {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("documentType"),
super::super::codec::Value::Array(items),
);
}
if !self.resource_type.is_empty() {
let mut items = Vec::with_capacity(self.resource_type.len());
for item in &self.resource_type {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("resourceType"),
super::super::codec::Value::Array(items),
);
}
if !self.code.is_empty() {
let mut items = Vec::with_capacity(self.code.len());
for item in &self.code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.data_period {
object.insert(
std::string::String::from("dataPeriod"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.data.is_empty() {
let mut items = Vec::with_capacity(self.data.len());
for item in &self.data {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("data"),
super::super::codec::Value::Array(items),
);
}
if !self.provision.is_empty() {
let mut items = Vec::with_capacity(self.provision.len());
for item in &self.provision {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("provision"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_period: Option<&super::super::codec::Value> = None;
let mut raw_actor: Option<&super::super::codec::Value> = None;
let mut raw_action: Option<&super::super::codec::Value> = None;
let mut raw_security_label: Option<&super::super::codec::Value> = None;
let mut raw_purpose: Option<&super::super::codec::Value> = None;
let mut raw_document_type: Option<&super::super::codec::Value> = None;
let mut raw_resource_type: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_data_period: Option<&super::super::codec::Value> = None;
let mut raw_data: Option<&super::super::codec::Value> = None;
let mut raw_provision: 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);
}
"period" => {
raw_period = Some(value);
}
"actor" => {
raw_actor = Some(value);
}
"action" => {
raw_action = Some(value);
}
"securityLabel" => {
raw_security_label = Some(value);
}
"purpose" => {
raw_purpose = Some(value);
}
"documentType" => {
raw_document_type = Some(value);
}
"resourceType" => {
raw_resource_type = Some(value);
}
"code" => {
raw_code = Some(value);
}
"dataPeriod" => {
raw_data_period = Some(value);
}
"data" => {
raw_data = Some(value);
}
"provision" => {
raw_provision = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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_actor = Vec::new();
if let Some(raw) = raw_actor {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_actor.push(path.with_index("actor", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_action = Vec::new();
if let Some(raw) = raw_action {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_action.push(path.with_index("action", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_security_label = Vec::new();
if let Some(raw) = raw_security_label {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_security_label.push(path.with_index("securityLabel", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_purpose = Vec::new();
if let Some(raw) = raw_purpose {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_purpose.push(path.with_index("purpose", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_document_type = Vec::new();
if let Some(raw) = raw_document_type {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_document_type.push(path.with_index("documentType", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_resource_type = Vec::new();
if let Some(raw) = raw_resource_type {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_resource_type.push(path.with_index("resourceType", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_code = Vec::new();
if let Some(raw) = raw_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_code.push(path.with_index("code", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_data_period = raw_data_period
.map(|value| {
path.with("dataPeriod", |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_data = Vec::new();
if let Some(raw) = raw_data {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_data.push(path.with_index("data", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_provision = Vec::new();
if let Some(raw) = raw_provision {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_provision.push(path.with_index("provision", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
period: field_period,
actor: field_actor,
action: field_action,
security_label: field_security_label,
purpose: field_purpose,
document_type: field_document_type,
resource_type: field_resource_type,
code: field_code,
data_period: field_data_period,
data: field_data,
provision: field_provision,
})
}
}
impl serde::Serialize for ConsentProvision {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.action.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "action", &self.action)?;
}
if !self.actor.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "actor", &self.actor)?;
}
if !self.code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
}
if !self.data.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "data", &self.data)?;
}
if let Some(item) = &self.data_period {
serde::ser::SerializeMap::serialize_entry(&mut map, "dataPeriod", item)?;
}
if !self.document_type.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"documentType",
&self.document_type,
)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.period {
serde::ser::SerializeMap::serialize_entry(&mut map, "period", item)?;
}
if !self.provision.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "provision", &self.provision)?;
}
if !self.purpose.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "purpose", &self.purpose)?;
}
if !self.resource_type.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"resourceType",
&self.resource_type,
)?;
}
if !self.security_label.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"securityLabel",
&self.security_label,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ConsentProvision {
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("ConsentProvision");
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 ConsentProvisionActor {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub role: Option<super::codeable_concept::CodeableConcept>,
pub reference: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ConsentProvisionActor {
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.role {
object.insert(
std::string::String::from("role"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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)?),
);
}
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_role: Option<&super::super::codec::Value> = None;
let mut raw_reference: 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);
}
"role" => {
raw_role = Some(value);
}
"reference" => {
raw_reference = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_role = raw_role
.map(|value| {
path.with("role", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
role: field_role,
reference: field_reference,
})
}
}
impl serde::Serialize for ConsentProvisionActor {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, 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 !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.reference {
serde::ser::SerializeMap::serialize_entry(&mut map, "reference", item)?;
}
if let Some(item) = &self.role {
serde::ser::SerializeMap::serialize_entry(&mut map, "role", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ConsentProvisionActor {
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("ConsentProvisionActor");
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 ConsentProvisionData {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub meaning: super::primitives::Code,
pub reference: super::reference::Reference,
}
impl super::super::codec::Json for ConsentProvisionData {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.meaning)? {
object.insert(std::string::String::from("meaning"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.meaning)? {
object.insert(std::string::String::from("_meaning"), e);
}
object.insert(
std::string::String::from("reference"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.reference,
)?),
);
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_meaning: Option<&super::super::codec::Value> = None;
let mut raw_meaning_element: Option<&super::super::codec::Value> = None;
let mut raw_reference: 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);
}
"meaning" => {
raw_meaning = Some(value);
}
"_meaning" => {
raw_meaning_element = Some(value);
}
"reference" => {
raw_reference = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_meaning = path.with("meaning", |path| {
super::super::codec::Primitive::from_json_parts(raw_meaning, raw_meaning_element, path)
})?;
let field_reference = path.with("reference", |path| {
let value = raw_reference
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
meaning: field_meaning,
reference: field_reference,
})
}
}
impl serde::Serialize for ConsentProvisionData {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_meaning", &self.meaning)?;
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)?;
}
super::super::codec::value_entry(&mut map, "meaning", &self.meaning)?;
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "reference", &self.reference)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ConsentProvisionData {
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("ConsentProvisionData");
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 ConsentVerification {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub verified: super::primitives::Boolean,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub verified_by: Option<super::reference::Reference>,
pub verified_with: Option<super::reference::Reference>,
pub date: Vec<super::primitives::DateTime>,
}
impl super::super::codec::Json for ConsentVerification {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.verified)? {
object.insert(std::string::String::from("verified"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.verified)? {
object.insert(std::string::String::from("_verified"), e);
}
if let Some(item) = &self.r#type {
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.verified_by {
object.insert(
std::string::String::from("verifiedBy"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.verified_with {
object.insert(
std::string::String::from("verifiedWith"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.date.is_empty() {
let (values, elements) = super::super::codec::primitive_arrays(&self.date)?;
if let Some(values) = values {
object.insert(std::string::String::from("date"), values);
}
if let Some(elements) = elements {
object.insert(std::string::String::from("_date"), elements);
}
}
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_verified: Option<&super::super::codec::Value> = None;
let mut raw_verified_element: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_verified_by: Option<&super::super::codec::Value> = None;
let mut raw_verified_with: Option<&super::super::codec::Value> = None;
let mut raw_date: Option<&super::super::codec::Value> = None;
let mut raw_date_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);
}
"verified" => {
raw_verified = Some(value);
}
"_verified" => {
raw_verified_element = Some(value);
}
"type" => {
raw_type = Some(value);
}
"verifiedBy" => {
raw_verified_by = Some(value);
}
"verifiedWith" => {
raw_verified_with = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_verified = path.with("verified", |path| {
super::super::codec::Primitive::from_json_parts(
raw_verified,
raw_verified_element,
path,
)
})?;
let field_type = raw_type
.map(|value| {
path.with("type", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_verified_by = raw_verified_by
.map(|value| {
path.with("verifiedBy", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_verified_with = raw_verified_with
.map(|value| {
path.with("verifiedWith", |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_date = Vec::new();
for (index, (value, element)) in
super::super::codec::pair_arrays(raw_date, raw_date_element, path)?
.into_iter()
.enumerate()
{
field_date.push(path.with_index("date", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
verified: field_verified,
r#type: field_type,
verified_by: field_verified_by,
verified_with: field_verified_with,
date: field_date,
})
}
}
impl serde::Serialize for ConsentVerification {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_list_entry(&mut map, "_date", &self.date)?;
super::super::codec::element_entry(&mut map, "_verified", &self.verified)?;
super::super::codec::value_list_entry(&mut map, "date", &self.date)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
super::super::codec::value_entry(&mut map, "verified", &self.verified)?;
if let Some(item) = &self.verified_by {
serde::ser::SerializeMap::serialize_entry(&mut map, "verifiedBy", item)?;
}
if let Some(item) = &self.verified_with {
serde::ser::SerializeMap::serialize_entry(&mut map, "verifiedWith", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ConsentVerification {
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("ConsentVerification");
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)
}
}