#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Contract {
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: Option<super::identifier::Identifier>,
pub status: Option<super::primitives::Code>,
pub issued: Option<super::primitives::DateTime>,
pub applies: Option<super::period::Period>,
pub subject: Vec<super::reference::Reference>,
pub topic: Vec<super::reference::Reference>,
pub authority: Vec<super::reference::Reference>,
pub domain: Vec<super::reference::Reference>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub sub_type: Vec<super::codeable_concept::CodeableConcept>,
pub action: Vec<super::codeable_concept::CodeableConcept>,
pub action_reason: Vec<super::codeable_concept::CodeableConcept>,
pub decision_type: Option<super::codeable_concept::CodeableConcept>,
pub content_derivative: Option<super::codeable_concept::CodeableConcept>,
pub security_label: Vec<super::coding::Coding>,
pub agent: Vec<ContractAgent>,
pub signer: Vec<ContractSigner>,
pub valued_item: Vec<ContractValuedItem>,
pub term: Vec<ContractTerm>,
pub binding: Option<ContractBinding>,
pub friendly: Vec<ContractFriendly>,
pub legal: Vec<ContractLegal>,
pub rule: Vec<ContractRule>,
}
impl super::super::codec::Json for Contract {
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("Contract")),
);
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 let Some(item) = &self.identifier {
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.status {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("status"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_status"), e);
}
}
if let Some(item) = &self.issued {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("issued"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_issued"), e);
}
}
if let Some(item) = &self.applies {
object.insert(
std::string::String::from("applies"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.subject.is_empty() {
let mut items = Vec::with_capacity(self.subject.len());
for item in &self.subject {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("subject"),
super::super::codec::Value::Array(items),
);
}
if !self.topic.is_empty() {
let mut items = Vec::with_capacity(self.topic.len());
for item in &self.topic {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("topic"),
super::super::codec::Value::Array(items),
);
}
if !self.authority.is_empty() {
let mut items = Vec::with_capacity(self.authority.len());
for item in &self.authority {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("authority"),
super::super::codec::Value::Array(items),
);
}
if !self.domain.is_empty() {
let mut items = Vec::with_capacity(self.domain.len());
for item in &self.domain {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("domain"),
super::super::codec::Value::Array(items),
);
}
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 !self.sub_type.is_empty() {
let mut items = Vec::with_capacity(self.sub_type.len());
for item in &self.sub_type {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("subType"),
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.action_reason.is_empty() {
let mut items = Vec::with_capacity(self.action_reason.len());
for item in &self.action_reason {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("actionReason"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.decision_type {
object.insert(
std::string::String::from("decisionType"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.content_derivative {
object.insert(
std::string::String::from("contentDerivative"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.agent.is_empty() {
let mut items = Vec::with_capacity(self.agent.len());
for item in &self.agent {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("agent"),
super::super::codec::Value::Array(items),
);
}
if !self.signer.is_empty() {
let mut items = Vec::with_capacity(self.signer.len());
for item in &self.signer {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("signer"),
super::super::codec::Value::Array(items),
);
}
if !self.valued_item.is_empty() {
let mut items = Vec::with_capacity(self.valued_item.len());
for item in &self.valued_item {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("valuedItem"),
super::super::codec::Value::Array(items),
);
}
if !self.term.is_empty() {
let mut items = Vec::with_capacity(self.term.len());
for item in &self.term {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("term"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.binding {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("binding{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_binding{suffix}"), element);
}
}
if !self.friendly.is_empty() {
let mut items = Vec::with_capacity(self.friendly.len());
for item in &self.friendly {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("friendly"),
super::super::codec::Value::Array(items),
);
}
if !self.legal.is_empty() {
let mut items = Vec::with_capacity(self.legal.len());
for item in &self.legal {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("legal"),
super::super::codec::Value::Array(items),
);
}
if !self.rule.is_empty() {
let mut items = Vec::with_capacity(self.rule.len());
for item in &self.rule {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("rule"),
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_issued: Option<&super::super::codec::Value> = None;
let mut raw_issued_element: Option<&super::super::codec::Value> = None;
let mut raw_applies: Option<&super::super::codec::Value> = None;
let mut raw_subject: Option<&super::super::codec::Value> = None;
let mut raw_topic: Option<&super::super::codec::Value> = None;
let mut raw_authority: Option<&super::super::codec::Value> = None;
let mut raw_domain: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_sub_type: Option<&super::super::codec::Value> = None;
let mut raw_action: Option<&super::super::codec::Value> = None;
let mut raw_action_reason: Option<&super::super::codec::Value> = None;
let mut raw_decision_type: Option<&super::super::codec::Value> = None;
let mut raw_content_derivative: Option<&super::super::codec::Value> = None;
let mut raw_security_label: Option<&super::super::codec::Value> = None;
let mut raw_agent: Option<&super::super::codec::Value> = None;
let mut raw_signer: Option<&super::super::codec::Value> = None;
let mut raw_valued_item: Option<&super::super::codec::Value> = None;
let mut raw_term: Option<&super::super::codec::Value> = None;
let mut raw_binding = super::super::codec::ChoiceSlot::default();
let mut raw_friendly: Option<&super::super::codec::Value> = None;
let mut raw_legal: Option<&super::super::codec::Value> = None;
let mut raw_rule: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("Contract") {
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);
}
"issued" => {
raw_issued = Some(value);
}
"_issued" => {
raw_issued_element = Some(value);
}
"applies" => {
raw_applies = Some(value);
}
"subject" => {
raw_subject = Some(value);
}
"topic" => {
raw_topic = Some(value);
}
"authority" => {
raw_authority = Some(value);
}
"domain" => {
raw_domain = Some(value);
}
"type" => {
raw_type = Some(value);
}
"subType" => {
raw_sub_type = Some(value);
}
"action" => {
raw_action = Some(value);
}
"actionReason" => {
raw_action_reason = Some(value);
}
"decisionType" => {
raw_decision_type = Some(value);
}
"contentDerivative" => {
raw_content_derivative = Some(value);
}
"securityLabel" => {
raw_security_label = Some(value);
}
"agent" => {
raw_agent = Some(value);
}
"signer" => {
raw_signer = Some(value);
}
"valuedItem" => {
raw_valued_item = Some(value);
}
"term" => {
raw_term = Some(value);
}
"bindingAttachment" => {
raw_binding.value("Attachment", value, path)?;
}
"_bindingAttachment" => {
raw_binding.element("Attachment", value, path)?;
}
"bindingReference" => {
raw_binding.value("Reference", value, path)?;
}
"_bindingReference" => {
raw_binding.element("Reference", value, path)?;
}
"friendly" => {
raw_friendly = Some(value);
}
"legal" => {
raw_legal = Some(value);
}
"rule" => {
raw_rule = 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 field_identifier = raw_identifier
.map(|value| {
path.with("identifier", |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 = match (raw_status, raw_status_element) {
(None, None) => None,
(value, element) => Some(path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_issued = match (raw_issued, raw_issued_element) {
(None, None) => None,
(value, element) => Some(path.with("issued", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_applies = raw_applies
.map(|value| {
path.with("applies", |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_subject = Vec::new();
if let Some(raw) = raw_subject {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_subject.push(path.with_index("subject", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_topic = Vec::new();
if let Some(raw) = raw_topic {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_topic.push(path.with_index("topic", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_authority = Vec::new();
if let Some(raw) = raw_authority {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_authority.push(path.with_index("authority", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_domain = Vec::new();
if let Some(raw) = raw_domain {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_domain.push(path.with_index("domain", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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 mut field_sub_type = Vec::new();
if let Some(raw) = raw_sub_type {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_sub_type.push(path.with_index("subType", 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_action_reason = Vec::new();
if let Some(raw) = raw_action_reason {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_action_reason.push(path.with_index("actionReason", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_decision_type = raw_decision_type
.map(|value| {
path.with("decisionType", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_content_derivative = raw_content_derivative
.map(|value| {
path.with("contentDerivative", |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_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_agent = Vec::new();
if let Some(raw) = raw_agent {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_agent.push(path.with_index("agent", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_signer = Vec::new();
if let Some(raw) = raw_signer {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_signer.push(path.with_index("signer", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_valued_item = Vec::new();
if let Some(raw) = raw_valued_item {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_valued_item.push(path.with_index("valuedItem", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_term = Vec::new();
if let Some(raw) = raw_term {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_term.push(path.with_index("term", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_binding = match raw_binding.suffix {
None => None,
Some(suffix) => Some(path.with("binding", |path| {
ContractBinding::from_json_parts(
suffix,
raw_binding.value,
raw_binding.element,
path,
)
})?),
};
let mut field_friendly = Vec::new();
if let Some(raw) = raw_friendly {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_friendly.push(path.with_index("friendly", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_legal = Vec::new();
if let Some(raw) = raw_legal {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_legal.push(path.with_index("legal", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_rule = Vec::new();
if let Some(raw) = raw_rule {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_rule.push(path.with_index("rule", 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,
issued: field_issued,
applies: field_applies,
subject: field_subject,
topic: field_topic,
authority: field_authority,
domain: field_domain,
r#type: field_type,
sub_type: field_sub_type,
action: field_action,
action_reason: field_action_reason,
decision_type: field_decision_type,
content_derivative: field_content_derivative,
security_label: field_security_label,
agent: field_agent,
signer: field_signer,
valued_item: field_valued_item,
term: field_term,
binding: field_binding,
friendly: field_friendly,
legal: field_legal,
rule: field_rule,
})
}
}
impl serde::Serialize for Contract {
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.issued {
super::super::codec::element_entry(&mut map, "_issued", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(item) = &self.status {
super::super::codec::element_entry(&mut map, "_status", item)?;
}
if !self.action.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "action", &self.action)?;
}
if !self.action_reason.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"actionReason",
&self.action_reason,
)?;
}
if !self.agent.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "agent", &self.agent)?;
}
if let Some(item) = &self.applies {
serde::ser::SerializeMap::serialize_entry(&mut map, "applies", item)?;
}
if !self.authority.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "authority", &self.authority)?;
}
match &self.binding {
Some(ContractBinding::Attachment(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"bindingAttachment",
inner.as_ref(),
)?;
}
Some(ContractBinding::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"bindingReference",
inner.as_ref(),
)?;
}
None => {}
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.content_derivative {
serde::ser::SerializeMap::serialize_entry(&mut map, "contentDerivative", item)?;
}
if let Some(item) = &self.decision_type {
serde::ser::SerializeMap::serialize_entry(&mut map, "decisionType", item)?;
}
if !self.domain.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "domain", &self.domain)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if !self.friendly.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "friendly", &self.friendly)?;
}
if let Some(item) = &self.id {
super::super::codec::value_entry(&mut map, "id", item)?;
}
if let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.issued {
super::super::codec::value_entry(&mut map, "issued", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if !self.legal.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "legal", &self.legal)?;
}
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,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "Contract")?;
if !self.rule.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "rule", &self.rule)?;
}
if !self.security_label.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"securityLabel",
&self.security_label,
)?;
}
if !self.signer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "signer", &self.signer)?;
}
if let Some(item) = &self.status {
super::super::codec::value_entry(&mut map, "status", item)?;
}
if !self.sub_type.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "subType", &self.sub_type)?;
}
if !self.subject.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", &self.subject)?;
}
if !self.term.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "term", &self.term)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if !self.topic.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "topic", &self.topic)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
if !self.valued_item.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "valuedItem", &self.valued_item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Contract {
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("Contract");
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 ContractAgent {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub actor: super::reference::Reference,
pub role: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ContractAgent {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("actor"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.actor)?),
);
if !self.role.is_empty() {
let mut items = Vec::with_capacity(self.role.len());
for item in &self.role {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("role"),
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_actor: Option<&super::super::codec::Value> = None;
let mut raw_role: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"actor" => {
raw_actor = Some(value);
}
"role" => {
raw_role = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_actor = path.with("actor", |path| {
let value = raw_actor
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let mut field_role = Vec::new();
if let Some(raw) = raw_role {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_role.push(path.with_index("role", 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,
actor: field_actor,
role: field_role,
})
}
}
impl serde::Serialize for ContractAgent {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "actor", &self.actor)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.role.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "role", &self.role)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ContractAgent {
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("ContractAgent");
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 ContractBinding {
Attachment(Box<super::attachment::Attachment>),
Reference(Box<super::reference::Reference>),
}
impl ContractBinding {
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::Attachment(inner) => Ok((
"Attachment",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Attachment" => {
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::Attachment(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ContractFriendly {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub content: ContractFriendlyContent,
}
impl super::super::codec::Json for ContractFriendly {
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),
);
}
let (suffix, value, element) = self.content.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("content{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_content{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_content = 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);
}
"contentAttachment" => {
raw_content.value("Attachment", value, path)?;
}
"_contentAttachment" => {
raw_content.element("Attachment", value, path)?;
}
"contentReference" => {
raw_content.value("Reference", value, path)?;
}
"_contentReference" => {
raw_content.element("Reference", 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_content = path.with("content", |path| {
let suffix = raw_content
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
ContractFriendlyContent::from_json_parts(
suffix,
raw_content.value,
raw_content.element,
path,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
content: field_content,
})
}
}
impl serde::Serialize for ContractFriendly {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.content {
ContractFriendlyContent::Attachment(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"contentAttachment",
inner.as_ref(),
)?;
}
ContractFriendlyContent::Reference(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"contentReference",
inner.as_ref(),
)?;
}
}
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,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ContractFriendly {
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("ContractFriendly");
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 ContractFriendlyContent {
Attachment(Box<super::attachment::Attachment>),
Reference(Box<super::reference::Reference>),
}
impl ContractFriendlyContent {
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::Attachment(inner) => Ok((
"Attachment",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Attachment" => {
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::Attachment(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ContractLegal {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub content: ContractLegalContent,
}
impl super::super::codec::Json for ContractLegal {
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),
);
}
let (suffix, value, element) = self.content.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("content{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_content{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_content = 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);
}
"contentAttachment" => {
raw_content.value("Attachment", value, path)?;
}
"_contentAttachment" => {
raw_content.element("Attachment", value, path)?;
}
"contentReference" => {
raw_content.value("Reference", value, path)?;
}
"_contentReference" => {
raw_content.element("Reference", 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_content = path.with("content", |path| {
let suffix = raw_content
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
ContractLegalContent::from_json_parts(
suffix,
raw_content.value,
raw_content.element,
path,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
content: field_content,
})
}
}
impl serde::Serialize for ContractLegal {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.content {
ContractLegalContent::Attachment(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"contentAttachment",
inner.as_ref(),
)?;
}
ContractLegalContent::Reference(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"contentReference",
inner.as_ref(),
)?;
}
}
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,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ContractLegal {
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("ContractLegal");
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 ContractLegalContent {
Attachment(Box<super::attachment::Attachment>),
Reference(Box<super::reference::Reference>),
}
impl ContractLegalContent {
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::Attachment(inner) => Ok((
"Attachment",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Attachment" => {
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::Attachment(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ContractRule {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub content: ContractRuleContent,
}
impl super::super::codec::Json for ContractRule {
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),
);
}
let (suffix, value, element) = self.content.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("content{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_content{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_content = 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);
}
"contentAttachment" => {
raw_content.value("Attachment", value, path)?;
}
"_contentAttachment" => {
raw_content.element("Attachment", value, path)?;
}
"contentReference" => {
raw_content.value("Reference", value, path)?;
}
"_contentReference" => {
raw_content.element("Reference", 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_content = path.with("content", |path| {
let suffix = raw_content
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
ContractRuleContent::from_json_parts(
suffix,
raw_content.value,
raw_content.element,
path,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
content: field_content,
})
}
}
impl serde::Serialize for ContractRule {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.content {
ContractRuleContent::Attachment(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"contentAttachment",
inner.as_ref(),
)?;
}
ContractRuleContent::Reference(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"contentReference",
inner.as_ref(),
)?;
}
}
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,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ContractRule {
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("ContractRule");
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 ContractRuleContent {
Attachment(Box<super::attachment::Attachment>),
Reference(Box<super::reference::Reference>),
}
impl ContractRuleContent {
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::Attachment(inner) => Ok((
"Attachment",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Attachment" => {
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::Attachment(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ContractSigner {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub r#type: super::coding::Coding,
pub party: super::reference::Reference,
pub signature: Vec<super::signature::Signature>,
}
impl super::super::codec::Json for ContractSigner {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.r#type)?),
);
object.insert(
std::string::String::from("party"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.party)?),
);
if !self.signature.is_empty() {
let mut items = Vec::with_capacity(self.signature.len());
for item in &self.signature {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("signature"),
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_type: Option<&super::super::codec::Value> = None;
let mut raw_party: Option<&super::super::codec::Value> = None;
let mut raw_signature: 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);
}
"type" => {
raw_type = Some(value);
}
"party" => {
raw_party = Some(value);
}
"signature" => {
raw_signature = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_type = path.with("type", |path| {
let value = raw_type
.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_party = path.with("party", |path| {
let value = raw_party
.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 mut field_signature = Vec::new();
if let Some(raw) = raw_signature {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_signature.push(path.with_index("signature", 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,
r#type: field_type,
party: field_party,
signature: field_signature,
})
}
}
impl serde::Serialize for ContractSigner {
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,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "party", &self.party)?;
if !self.signature.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "signature", &self.signature)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ContractSigner {
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("ContractSigner");
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 ContractTerm {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Option<super::identifier::Identifier>,
pub issued: Option<super::primitives::DateTime>,
pub applies: Option<super::period::Period>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub sub_type: Option<super::codeable_concept::CodeableConcept>,
pub topic: Vec<super::reference::Reference>,
pub action: Vec<super::codeable_concept::CodeableConcept>,
pub action_reason: Vec<super::codeable_concept::CodeableConcept>,
pub security_label: Vec<super::coding::Coding>,
pub agent: Vec<ContractTermAgent>,
pub text: Option<super::primitives::String>,
pub valued_item: Vec<ContractTermValuedItem>,
pub group: Vec<ContractTerm>,
}
impl super::super::codec::Json for ContractTerm {
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.identifier {
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.issued {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("issued"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_issued"), e);
}
}
if let Some(item) = &self.applies {
object.insert(
std::string::String::from("applies"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.sub_type {
object.insert(
std::string::String::from("subType"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.topic.is_empty() {
let mut items = Vec::with_capacity(self.topic.len());
for item in &self.topic {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("topic"),
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.action_reason.is_empty() {
let mut items = Vec::with_capacity(self.action_reason.len());
for item in &self.action_reason {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("actionReason"),
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.agent.is_empty() {
let mut items = Vec::with_capacity(self.agent.len());
for item in &self.agent {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("agent"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.text {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("text"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_text"), e);
}
}
if !self.valued_item.is_empty() {
let mut items = Vec::with_capacity(self.valued_item.len());
for item in &self.valued_item {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("valuedItem"),
super::super::codec::Value::Array(items),
);
}
if !self.group.is_empty() {
let mut items = Vec::with_capacity(self.group.len());
for item in &self.group {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("group"),
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_identifier: Option<&super::super::codec::Value> = None;
let mut raw_issued: Option<&super::super::codec::Value> = None;
let mut raw_issued_element: Option<&super::super::codec::Value> = None;
let mut raw_applies: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_sub_type: Option<&super::super::codec::Value> = None;
let mut raw_topic: Option<&super::super::codec::Value> = None;
let mut raw_action: Option<&super::super::codec::Value> = None;
let mut raw_action_reason: Option<&super::super::codec::Value> = None;
let mut raw_security_label: Option<&super::super::codec::Value> = None;
let mut raw_agent: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_text_element: Option<&super::super::codec::Value> = None;
let mut raw_valued_item: Option<&super::super::codec::Value> = None;
let mut raw_group: 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);
}
"identifier" => {
raw_identifier = Some(value);
}
"issued" => {
raw_issued = Some(value);
}
"_issued" => {
raw_issued_element = Some(value);
}
"applies" => {
raw_applies = Some(value);
}
"type" => {
raw_type = Some(value);
}
"subType" => {
raw_sub_type = Some(value);
}
"topic" => {
raw_topic = Some(value);
}
"action" => {
raw_action = Some(value);
}
"actionReason" => {
raw_action_reason = Some(value);
}
"securityLabel" => {
raw_security_label = Some(value);
}
"agent" => {
raw_agent = Some(value);
}
"text" => {
raw_text = Some(value);
}
"_text" => {
raw_text_element = Some(value);
}
"valuedItem" => {
raw_valued_item = Some(value);
}
"group" => {
raw_group = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_identifier = raw_identifier
.map(|value| {
path.with("identifier", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_issued = match (raw_issued, raw_issued_element) {
(None, None) => None,
(value, element) => Some(path.with("issued", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_applies = raw_applies
.map(|value| {
path.with("applies", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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_sub_type = raw_sub_type
.map(|value| {
path.with("subType", |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_topic = Vec::new();
if let Some(raw) = raw_topic {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_topic.push(path.with_index("topic", 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_action_reason = Vec::new();
if let Some(raw) = raw_action_reason {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_action_reason.push(path.with_index("actionReason", 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_agent = Vec::new();
if let Some(raw) = raw_agent {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_agent.push(path.with_index("agent", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_text = match (raw_text, raw_text_element) {
(None, None) => None,
(value, element) => Some(path.with("text", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_valued_item = Vec::new();
if let Some(raw) = raw_valued_item {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_valued_item.push(path.with_index("valuedItem", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_group = Vec::new();
if let Some(raw) = raw_group {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_group.push(path.with_index("group", 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,
identifier: field_identifier,
issued: field_issued,
applies: field_applies,
r#type: field_type,
sub_type: field_sub_type,
topic: field_topic,
action: field_action,
action_reason: field_action_reason,
security_label: field_security_label,
agent: field_agent,
text: field_text,
valued_item: field_valued_item,
group: field_group,
})
}
}
impl serde::Serialize for ContractTerm {
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.issued {
super::super::codec::element_entry(&mut map, "_issued", item)?;
}
if let Some(item) = &self.text {
super::super::codec::element_entry(&mut map, "_text", item)?;
}
if !self.action.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "action", &self.action)?;
}
if !self.action_reason.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"actionReason",
&self.action_reason,
)?;
}
if !self.agent.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "agent", &self.agent)?;
}
if let Some(item) = &self.applies {
serde::ser::SerializeMap::serialize_entry(&mut map, "applies", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if !self.group.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "group", &self.group)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if let Some(item) = &self.issued {
super::super::codec::value_entry(&mut map, "issued", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.security_label.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"securityLabel",
&self.security_label,
)?;
}
if let Some(item) = &self.sub_type {
serde::ser::SerializeMap::serialize_entry(&mut map, "subType", item)?;
}
if let Some(item) = &self.text {
super::super::codec::value_entry(&mut map, "text", item)?;
}
if !self.topic.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "topic", &self.topic)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
if !self.valued_item.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "valuedItem", &self.valued_item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ContractTerm {
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("ContractTerm");
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 ContractTermAgent {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub actor: super::reference::Reference,
pub role: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ContractTermAgent {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("actor"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.actor)?),
);
if !self.role.is_empty() {
let mut items = Vec::with_capacity(self.role.len());
for item in &self.role {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("role"),
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_actor: Option<&super::super::codec::Value> = None;
let mut raw_role: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"actor" => {
raw_actor = Some(value);
}
"role" => {
raw_role = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_actor = path.with("actor", |path| {
let value = raw_actor
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let mut field_role = Vec::new();
if let Some(raw) = raw_role {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_role.push(path.with_index("role", 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,
actor: field_actor,
role: field_role,
})
}
}
impl serde::Serialize for ContractTermAgent {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "actor", &self.actor)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.role.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "role", &self.role)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ContractTermAgent {
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("ContractTermAgent");
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 ContractTermValuedItem {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub entity: Option<ContractTermValuedItemEntity>,
pub identifier: Option<super::identifier::Identifier>,
pub effective_time: Option<super::primitives::DateTime>,
pub quantity: Option<super::quantity::Quantity>,
pub unit_price: Option<super::money::Money>,
pub factor: Option<super::primitives::Decimal>,
pub points: Option<super::primitives::Decimal>,
pub net: Option<super::money::Money>,
}
impl super::super::codec::Json for ContractTermValuedItem {
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.entity {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("entity{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_entity{suffix}"), element);
}
}
if let Some(item) = &self.identifier {
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.effective_time {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("effectiveTime"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_effectiveTime"), e);
}
}
if let Some(item) = &self.quantity {
object.insert(
std::string::String::from("quantity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.unit_price {
object.insert(
std::string::String::from("unitPrice"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.factor {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("factor"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_factor"), e);
}
}
if let Some(item) = &self.points {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("points"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_points"), e);
}
}
if let Some(item) = &self.net {
object.insert(
std::string::String::from("net"),
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_entity = super::super::codec::ChoiceSlot::default();
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_effective_time: Option<&super::super::codec::Value> = None;
let mut raw_effective_time_element: Option<&super::super::codec::Value> = None;
let mut raw_quantity: Option<&super::super::codec::Value> = None;
let mut raw_unit_price: Option<&super::super::codec::Value> = None;
let mut raw_factor: Option<&super::super::codec::Value> = None;
let mut raw_factor_element: Option<&super::super::codec::Value> = None;
let mut raw_points: Option<&super::super::codec::Value> = None;
let mut raw_points_element: Option<&super::super::codec::Value> = None;
let mut raw_net: 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);
}
"entityCodeableConcept" => {
raw_entity.value("CodeableConcept", value, path)?;
}
"_entityCodeableConcept" => {
raw_entity.element("CodeableConcept", value, path)?;
}
"entityReference" => {
raw_entity.value("Reference", value, path)?;
}
"_entityReference" => {
raw_entity.element("Reference", value, path)?;
}
"identifier" => {
raw_identifier = Some(value);
}
"effectiveTime" => {
raw_effective_time = Some(value);
}
"_effectiveTime" => {
raw_effective_time_element = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"unitPrice" => {
raw_unit_price = Some(value);
}
"factor" => {
raw_factor = Some(value);
}
"_factor" => {
raw_factor_element = Some(value);
}
"points" => {
raw_points = Some(value);
}
"_points" => {
raw_points_element = Some(value);
}
"net" => {
raw_net = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_entity = match raw_entity.suffix {
None => None,
Some(suffix) => Some(path.with("entity", |path| {
ContractTermValuedItemEntity::from_json_parts(
suffix,
raw_entity.value,
raw_entity.element,
path,
)
})?),
};
let field_identifier = raw_identifier
.map(|value| {
path.with("identifier", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_effective_time = match (raw_effective_time, raw_effective_time_element) {
(None, None) => None,
(value, element) => Some(path.with("effectiveTime", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_quantity = raw_quantity
.map(|value| {
path.with("quantity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_unit_price = raw_unit_price
.map(|value| {
path.with("unitPrice", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_factor = match (raw_factor, raw_factor_element) {
(None, None) => None,
(value, element) => Some(path.with("factor", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_points = match (raw_points, raw_points_element) {
(None, None) => None,
(value, element) => Some(path.with("points", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_net = raw_net
.map(|value| {
path.with("net", |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,
entity: field_entity,
identifier: field_identifier,
effective_time: field_effective_time,
quantity: field_quantity,
unit_price: field_unit_price,
factor: field_factor,
points: field_points,
net: field_net,
})
}
}
impl serde::Serialize for ContractTermValuedItem {
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.effective_time {
super::super::codec::element_entry(&mut map, "_effectiveTime", item)?;
}
if let Some(item) = &self.factor {
super::super::codec::element_entry(&mut map, "_factor", item)?;
}
if let Some(item) = &self.points {
super::super::codec::element_entry(&mut map, "_points", item)?;
}
if let Some(item) = &self.effective_time {
super::super::codec::value_entry(&mut map, "effectiveTime", item)?;
}
match &self.entity {
Some(ContractTermValuedItemEntity::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"entityCodeableConcept",
inner.as_ref(),
)?;
}
Some(ContractTermValuedItemEntity::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"entityReference",
inner.as_ref(),
)?;
}
None => {}
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.factor {
super::super::codec::value_entry(&mut map, "factor", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.net {
serde::ser::SerializeMap::serialize_entry(&mut map, "net", item)?;
}
if let Some(item) = &self.points {
super::super::codec::value_entry(&mut map, "points", item)?;
}
if let Some(item) = &self.quantity {
serde::ser::SerializeMap::serialize_entry(&mut map, "quantity", item)?;
}
if let Some(item) = &self.unit_price {
serde::ser::SerializeMap::serialize_entry(&mut map, "unitPrice", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ContractTermValuedItem {
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("ContractTermValuedItem");
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 ContractTermValuedItemEntity {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Reference(Box<super::reference::Reference>),
}
impl ContractTermValuedItemEntity {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ContractValuedItem {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub entity: Option<ContractValuedItemEntity>,
pub identifier: Option<super::identifier::Identifier>,
pub effective_time: Option<super::primitives::DateTime>,
pub quantity: Option<super::quantity::Quantity>,
pub unit_price: Option<super::money::Money>,
pub factor: Option<super::primitives::Decimal>,
pub points: Option<super::primitives::Decimal>,
pub net: Option<super::money::Money>,
}
impl super::super::codec::Json for ContractValuedItem {
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.entity {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("entity{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_entity{suffix}"), element);
}
}
if let Some(item) = &self.identifier {
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.effective_time {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("effectiveTime"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_effectiveTime"), e);
}
}
if let Some(item) = &self.quantity {
object.insert(
std::string::String::from("quantity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.unit_price {
object.insert(
std::string::String::from("unitPrice"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.factor {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("factor"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_factor"), e);
}
}
if let Some(item) = &self.points {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("points"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_points"), e);
}
}
if let Some(item) = &self.net {
object.insert(
std::string::String::from("net"),
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_entity = super::super::codec::ChoiceSlot::default();
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_effective_time: Option<&super::super::codec::Value> = None;
let mut raw_effective_time_element: Option<&super::super::codec::Value> = None;
let mut raw_quantity: Option<&super::super::codec::Value> = None;
let mut raw_unit_price: Option<&super::super::codec::Value> = None;
let mut raw_factor: Option<&super::super::codec::Value> = None;
let mut raw_factor_element: Option<&super::super::codec::Value> = None;
let mut raw_points: Option<&super::super::codec::Value> = None;
let mut raw_points_element: Option<&super::super::codec::Value> = None;
let mut raw_net: 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);
}
"entityCodeableConcept" => {
raw_entity.value("CodeableConcept", value, path)?;
}
"_entityCodeableConcept" => {
raw_entity.element("CodeableConcept", value, path)?;
}
"entityReference" => {
raw_entity.value("Reference", value, path)?;
}
"_entityReference" => {
raw_entity.element("Reference", value, path)?;
}
"identifier" => {
raw_identifier = Some(value);
}
"effectiveTime" => {
raw_effective_time = Some(value);
}
"_effectiveTime" => {
raw_effective_time_element = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"unitPrice" => {
raw_unit_price = Some(value);
}
"factor" => {
raw_factor = Some(value);
}
"_factor" => {
raw_factor_element = Some(value);
}
"points" => {
raw_points = Some(value);
}
"_points" => {
raw_points_element = Some(value);
}
"net" => {
raw_net = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_entity = match raw_entity.suffix {
None => None,
Some(suffix) => Some(path.with("entity", |path| {
ContractValuedItemEntity::from_json_parts(
suffix,
raw_entity.value,
raw_entity.element,
path,
)
})?),
};
let field_identifier = raw_identifier
.map(|value| {
path.with("identifier", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_effective_time = match (raw_effective_time, raw_effective_time_element) {
(None, None) => None,
(value, element) => Some(path.with("effectiveTime", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_quantity = raw_quantity
.map(|value| {
path.with("quantity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_unit_price = raw_unit_price
.map(|value| {
path.with("unitPrice", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_factor = match (raw_factor, raw_factor_element) {
(None, None) => None,
(value, element) => Some(path.with("factor", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_points = match (raw_points, raw_points_element) {
(None, None) => None,
(value, element) => Some(path.with("points", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_net = raw_net
.map(|value| {
path.with("net", |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,
entity: field_entity,
identifier: field_identifier,
effective_time: field_effective_time,
quantity: field_quantity,
unit_price: field_unit_price,
factor: field_factor,
points: field_points,
net: field_net,
})
}
}
impl serde::Serialize for ContractValuedItem {
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.effective_time {
super::super::codec::element_entry(&mut map, "_effectiveTime", item)?;
}
if let Some(item) = &self.factor {
super::super::codec::element_entry(&mut map, "_factor", item)?;
}
if let Some(item) = &self.points {
super::super::codec::element_entry(&mut map, "_points", item)?;
}
if let Some(item) = &self.effective_time {
super::super::codec::value_entry(&mut map, "effectiveTime", item)?;
}
match &self.entity {
Some(ContractValuedItemEntity::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"entityCodeableConcept",
inner.as_ref(),
)?;
}
Some(ContractValuedItemEntity::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"entityReference",
inner.as_ref(),
)?;
}
None => {}
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.factor {
super::super::codec::value_entry(&mut map, "factor", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.net {
serde::ser::SerializeMap::serialize_entry(&mut map, "net", item)?;
}
if let Some(item) = &self.points {
super::super::codec::value_entry(&mut map, "points", item)?;
}
if let Some(item) = &self.quantity {
serde::ser::SerializeMap::serialize_entry(&mut map, "quantity", item)?;
}
if let Some(item) = &self.unit_price {
serde::ser::SerializeMap::serialize_entry(&mut map, "unitPrice", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ContractValuedItem {
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("ContractValuedItem");
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 ContractValuedItemEntity {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Reference(Box<super::reference::Reference>),
}
impl ContractValuedItemEntity {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}