#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Claim {
pub id: Option<super::primitives::Id>,
pub meta: Option<super::meta::Meta>,
pub implicit_rules: Option<super::primitives::Uri>,
pub language: Option<super::primitives::Code>,
pub text: Option<super::narrative::Narrative>,
pub contained: Vec<super::resource::Resource>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Vec<super::identifier::Identifier>,
pub status: Option<super::primitives::Code>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub sub_type: Vec<super::codeable_concept::CodeableConcept>,
pub r#use: Option<super::primitives::Code>,
pub patient: Option<super::reference::Reference>,
pub billable_period: Option<super::period::Period>,
pub created: Option<super::primitives::DateTime>,
pub enterer: Option<super::reference::Reference>,
pub insurer: Option<super::reference::Reference>,
pub provider: Option<super::reference::Reference>,
pub organization: Option<super::reference::Reference>,
pub priority: Option<super::codeable_concept::CodeableConcept>,
pub funds_reserve: Option<super::codeable_concept::CodeableConcept>,
pub related: Vec<ClaimRelated>,
pub prescription: Option<super::reference::Reference>,
pub original_prescription: Option<super::reference::Reference>,
pub payee: Option<ClaimPayee>,
pub referral: Option<super::reference::Reference>,
pub facility: Option<super::reference::Reference>,
pub care_team: Vec<ClaimCareTeam>,
pub information: Vec<ClaimInformation>,
pub diagnosis: Vec<ClaimDiagnosis>,
pub procedure: Vec<ClaimProcedure>,
pub insurance: Vec<ClaimInsurance>,
pub accident: Option<ClaimAccident>,
pub employment_impacted: Option<super::period::Period>,
pub hospitalization: Option<super::period::Period>,
pub item: Vec<ClaimItem>,
pub total: Option<super::money::Money>,
}
impl super::super::codec::Json for Claim {
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("Claim")),
);
if let Some(item) = &self.id {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("id"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_id"), e);
}
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if let Some(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.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 let Some(item) = &self.r#use {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("use"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_use"), e);
}
}
if let Some(item) = &self.patient {
object.insert(
std::string::String::from("patient"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.billable_period {
object.insert(
std::string::String::from("billablePeriod"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.created {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("created"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_created"), e);
}
}
if let Some(item) = &self.enterer {
object.insert(
std::string::String::from("enterer"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.insurer {
object.insert(
std::string::String::from("insurer"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.provider {
object.insert(
std::string::String::from("provider"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.organization {
object.insert(
std::string::String::from("organization"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.priority {
object.insert(
std::string::String::from("priority"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.funds_reserve {
object.insert(
std::string::String::from("fundsReserve"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.related.is_empty() {
let mut items = Vec::with_capacity(self.related.len());
for item in &self.related {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("related"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.prescription {
object.insert(
std::string::String::from("prescription"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.original_prescription {
object.insert(
std::string::String::from("originalPrescription"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.payee {
object.insert(
std::string::String::from("payee"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.referral {
object.insert(
std::string::String::from("referral"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.facility {
object.insert(
std::string::String::from("facility"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.care_team.is_empty() {
let mut items = Vec::with_capacity(self.care_team.len());
for item in &self.care_team {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("careTeam"),
super::super::codec::Value::Array(items),
);
}
if !self.information.is_empty() {
let mut items = Vec::with_capacity(self.information.len());
for item in &self.information {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("information"),
super::super::codec::Value::Array(items),
);
}
if !self.diagnosis.is_empty() {
let mut items = Vec::with_capacity(self.diagnosis.len());
for item in &self.diagnosis {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("diagnosis"),
super::super::codec::Value::Array(items),
);
}
if !self.procedure.is_empty() {
let mut items = Vec::with_capacity(self.procedure.len());
for item in &self.procedure {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("procedure"),
super::super::codec::Value::Array(items),
);
}
if !self.insurance.is_empty() {
let mut items = Vec::with_capacity(self.insurance.len());
for item in &self.insurance {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("insurance"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.accident {
object.insert(
std::string::String::from("accident"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.employment_impacted {
object.insert(
std::string::String::from("employmentImpacted"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.hospitalization {
object.insert(
std::string::String::from("hospitalization"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.item.is_empty() {
let mut items = Vec::with_capacity(self.item.len());
for item in &self.item {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("item"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.total {
object.insert(
std::string::String::from("total"),
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_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_type: Option<&super::super::codec::Value> = None;
let mut raw_sub_type: Option<&super::super::codec::Value> = None;
let mut raw_use: Option<&super::super::codec::Value> = None;
let mut raw_use_element: Option<&super::super::codec::Value> = None;
let mut raw_patient: Option<&super::super::codec::Value> = None;
let mut raw_billable_period: Option<&super::super::codec::Value> = None;
let mut raw_created: Option<&super::super::codec::Value> = None;
let mut raw_created_element: Option<&super::super::codec::Value> = None;
let mut raw_enterer: Option<&super::super::codec::Value> = None;
let mut raw_insurer: Option<&super::super::codec::Value> = None;
let mut raw_provider: Option<&super::super::codec::Value> = None;
let mut raw_organization: Option<&super::super::codec::Value> = None;
let mut raw_priority: Option<&super::super::codec::Value> = None;
let mut raw_funds_reserve: Option<&super::super::codec::Value> = None;
let mut raw_related: Option<&super::super::codec::Value> = None;
let mut raw_prescription: Option<&super::super::codec::Value> = None;
let mut raw_original_prescription: Option<&super::super::codec::Value> = None;
let mut raw_payee: Option<&super::super::codec::Value> = None;
let mut raw_referral: Option<&super::super::codec::Value> = None;
let mut raw_facility: Option<&super::super::codec::Value> = None;
let mut raw_care_team: Option<&super::super::codec::Value> = None;
let mut raw_information: Option<&super::super::codec::Value> = None;
let mut raw_diagnosis: Option<&super::super::codec::Value> = None;
let mut raw_procedure: Option<&super::super::codec::Value> = None;
let mut raw_insurance: Option<&super::super::codec::Value> = None;
let mut raw_accident: Option<&super::super::codec::Value> = None;
let mut raw_employment_impacted: Option<&super::super::codec::Value> = None;
let mut raw_hospitalization: Option<&super::super::codec::Value> = None;
let mut raw_item: Option<&super::super::codec::Value> = None;
let mut raw_total: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("Claim") {
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);
}
"type" => {
raw_type = Some(value);
}
"subType" => {
raw_sub_type = Some(value);
}
"use" => {
raw_use = Some(value);
}
"_use" => {
raw_use_element = Some(value);
}
"patient" => {
raw_patient = Some(value);
}
"billablePeriod" => {
raw_billable_period = Some(value);
}
"created" => {
raw_created = Some(value);
}
"_created" => {
raw_created_element = Some(value);
}
"enterer" => {
raw_enterer = Some(value);
}
"insurer" => {
raw_insurer = Some(value);
}
"provider" => {
raw_provider = Some(value);
}
"organization" => {
raw_organization = Some(value);
}
"priority" => {
raw_priority = Some(value);
}
"fundsReserve" => {
raw_funds_reserve = Some(value);
}
"related" => {
raw_related = Some(value);
}
"prescription" => {
raw_prescription = Some(value);
}
"originalPrescription" => {
raw_original_prescription = Some(value);
}
"payee" => {
raw_payee = Some(value);
}
"referral" => {
raw_referral = Some(value);
}
"facility" => {
raw_facility = Some(value);
}
"careTeam" => {
raw_care_team = Some(value);
}
"information" => {
raw_information = Some(value);
}
"diagnosis" => {
raw_diagnosis = Some(value);
}
"procedure" => {
raw_procedure = Some(value);
}
"insurance" => {
raw_insurance = Some(value);
}
"accident" => {
raw_accident = Some(value);
}
"employmentImpacted" => {
raw_employment_impacted = Some(value);
}
"hospitalization" => {
raw_hospitalization = Some(value);
}
"item" => {
raw_item = Some(value);
}
"total" => {
raw_total = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = match (raw_id, raw_id_element) {
(None, None) => None,
(value, element) => Some(path.with("id", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_status = 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_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 field_use = match (raw_use, raw_use_element) {
(None, None) => None,
(value, element) => Some(path.with("use", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_patient = raw_patient
.map(|value| {
path.with("patient", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_billable_period = raw_billable_period
.map(|value| {
path.with("billablePeriod", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_created = match (raw_created, raw_created_element) {
(None, None) => None,
(value, element) => Some(path.with("created", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_enterer = raw_enterer
.map(|value| {
path.with("enterer", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_insurer = raw_insurer
.map(|value| {
path.with("insurer", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_provider = raw_provider
.map(|value| {
path.with("provider", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_organization = raw_organization
.map(|value| {
path.with("organization", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_priority = raw_priority
.map(|value| {
path.with("priority", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_funds_reserve = raw_funds_reserve
.map(|value| {
path.with("fundsReserve", |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_related = Vec::new();
if let Some(raw) = raw_related {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_related.push(path.with_index("related", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_prescription = raw_prescription
.map(|value| {
path.with("prescription", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_original_prescription = raw_original_prescription
.map(|value| {
path.with("originalPrescription", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_payee = raw_payee
.map(|value| {
path.with("payee", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_referral = raw_referral
.map(|value| {
path.with("referral", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_facility = raw_facility
.map(|value| {
path.with("facility", |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_care_team = Vec::new();
if let Some(raw) = raw_care_team {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_care_team.push(path.with_index("careTeam", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_information = Vec::new();
if let Some(raw) = raw_information {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_information.push(path.with_index("information", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_diagnosis = Vec::new();
if let Some(raw) = raw_diagnosis {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_diagnosis.push(path.with_index("diagnosis", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_procedure = Vec::new();
if let Some(raw) = raw_procedure {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_procedure.push(path.with_index("procedure", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_insurance = Vec::new();
if let Some(raw) = raw_insurance {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_insurance.push(path.with_index("insurance", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_accident = raw_accident
.map(|value| {
path.with("accident", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_employment_impacted = raw_employment_impacted
.map(|value| {
path.with("employmentImpacted", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_hospitalization = raw_hospitalization
.map(|value| {
path.with("hospitalization", |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_item = Vec::new();
if let Some(raw) = raw_item {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_item.push(path.with_index("item", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_total = raw_total
.map(|value| {
path.with("total", |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,
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,
r#type: field_type,
sub_type: field_sub_type,
r#use: field_use,
patient: field_patient,
billable_period: field_billable_period,
created: field_created,
enterer: field_enterer,
insurer: field_insurer,
provider: field_provider,
organization: field_organization,
priority: field_priority,
funds_reserve: field_funds_reserve,
related: field_related,
prescription: field_prescription,
original_prescription: field_original_prescription,
payee: field_payee,
referral: field_referral,
facility: field_facility,
care_team: field_care_team,
information: field_information,
diagnosis: field_diagnosis,
procedure: field_procedure,
insurance: field_insurance,
accident: field_accident,
employment_impacted: field_employment_impacted,
hospitalization: field_hospitalization,
item: field_item,
total: field_total,
})
}
}
impl serde::Serialize for Claim {
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.created {
super::super::codec::element_entry(&mut map, "_created", item)?;
}
if let Some(item) = &self.id {
super::super::codec::element_entry(&mut map, "_id", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
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 let Some(item) = &self.r#use {
super::super::codec::element_entry(&mut map, "_use", item)?;
}
if let Some(item) = &self.accident {
serde::ser::SerializeMap::serialize_entry(&mut map, "accident", item)?;
}
if let Some(item) = &self.billable_period {
serde::ser::SerializeMap::serialize_entry(&mut map, "billablePeriod", item)?;
}
if !self.care_team.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "careTeam", &self.care_team)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.created {
super::super::codec::value_entry(&mut map, "created", item)?;
}
if !self.diagnosis.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "diagnosis", &self.diagnosis)?;
}
if let Some(item) = &self.employment_impacted {
serde::ser::SerializeMap::serialize_entry(&mut map, "employmentImpacted", item)?;
}
if let Some(item) = &self.enterer {
serde::ser::SerializeMap::serialize_entry(&mut map, "enterer", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.facility {
serde::ser::SerializeMap::serialize_entry(&mut map, "facility", item)?;
}
if let Some(item) = &self.funds_reserve {
serde::ser::SerializeMap::serialize_entry(&mut map, "fundsReserve", item)?;
}
if let Some(item) = &self.hospitalization {
serde::ser::SerializeMap::serialize_entry(&mut map, "hospitalization", item)?;
}
if let Some(item) = &self.id {
super::super::codec::value_entry(&mut map, "id", item)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if !self.information.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "information", &self.information)?;
}
if !self.insurance.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "insurance", &self.insurance)?;
}
if let Some(item) = &self.insurer {
serde::ser::SerializeMap::serialize_entry(&mut map, "insurer", item)?;
}
if !self.item.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "item", &self.item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.meta {
serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.organization {
serde::ser::SerializeMap::serialize_entry(&mut map, "organization", item)?;
}
if let Some(item) = &self.original_prescription {
serde::ser::SerializeMap::serialize_entry(&mut map, "originalPrescription", item)?;
}
if let Some(item) = &self.patient {
serde::ser::SerializeMap::serialize_entry(&mut map, "patient", item)?;
}
if let Some(item) = &self.payee {
serde::ser::SerializeMap::serialize_entry(&mut map, "payee", item)?;
}
if let Some(item) = &self.prescription {
serde::ser::SerializeMap::serialize_entry(&mut map, "prescription", item)?;
}
if let Some(item) = &self.priority {
serde::ser::SerializeMap::serialize_entry(&mut map, "priority", item)?;
}
if !self.procedure.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "procedure", &self.procedure)?;
}
if let Some(item) = &self.provider {
serde::ser::SerializeMap::serialize_entry(&mut map, "provider", item)?;
}
if let Some(item) = &self.referral {
serde::ser::SerializeMap::serialize_entry(&mut map, "referral", item)?;
}
if !self.related.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "related", &self.related)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "Claim")?;
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 let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.total {
serde::ser::SerializeMap::serialize_entry(&mut map, "total", item)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
if let Some(item) = &self.r#use {
super::super::codec::value_entry(&mut map, "use", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Claim {
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("Claim");
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 ClaimAccident {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub date: super::primitives::Date,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub location: Option<ClaimAccidentLocation>,
}
impl super::super::codec::Json for ClaimAccident {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.date)? {
object.insert(std::string::String::from("date"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.date)? {
object.insert(std::string::String::from("_date"), e);
}
if let Some(item) = &self.r#type {
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.location {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("location{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_location{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_date: Option<&super::super::codec::Value> = None;
let mut raw_date_element: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_location = 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);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_element = Some(value);
}
"type" => {
raw_type = Some(value);
}
"locationAddress" => {
raw_location.value("Address", value, path)?;
}
"_locationAddress" => {
raw_location.element("Address", value, path)?;
}
"locationReference" => {
raw_location.value("Reference", value, path)?;
}
"_locationReference" => {
raw_location.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_date = path.with("date", |path| {
super::super::codec::Primitive::from_json_parts(raw_date, raw_date_element, path)
})?;
let field_type = raw_type
.map(|value| {
path.with("type", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_location = match raw_location.suffix {
None => None,
Some(suffix) => Some(path.with("location", |path| {
ClaimAccidentLocation::from_json_parts(
suffix,
raw_location.value,
raw_location.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
date: field_date,
r#type: field_type,
location: field_location,
})
}
}
impl serde::Serialize for ClaimAccident {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_date", &self.date)?;
super::super::codec::value_entry(&mut map, "date", &self.date)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
match &self.location {
Some(ClaimAccidentLocation::Address(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"locationAddress",
inner.as_ref(),
)?;
}
Some(ClaimAccidentLocation::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"locationReference",
inner.as_ref(),
)?;
}
None => {}
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimAccident {
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("ClaimAccident");
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 ClaimAccidentLocation {
Address(Box<super::address::Address>),
Reference(Box<super::reference::Reference>),
}
impl ClaimAccidentLocation {
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::Address(inner) => Ok((
"Address",
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 {
"Address" => {
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::Address(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 ClaimCareTeam {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub sequence: super::primitives::PositiveInt,
pub provider: super::reference::Reference,
pub responsible: Option<super::primitives::Boolean>,
pub role: Option<super::codeable_concept::CodeableConcept>,
pub qualification: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ClaimCareTeam {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.sequence)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.sequence)? {
object.insert(std::string::String::from("_sequence"), e);
}
object.insert(
std::string::String::from("provider"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.provider)?),
);
if let Some(item) = &self.responsible {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("responsible"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_responsible"), e);
}
}
if let Some(item) = &self.role {
object.insert(
std::string::String::from("role"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.qualification {
object.insert(
std::string::String::from("qualification"),
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_sequence: Option<&super::super::codec::Value> = None;
let mut raw_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_provider: Option<&super::super::codec::Value> = None;
let mut raw_responsible: Option<&super::super::codec::Value> = None;
let mut raw_responsible_element: Option<&super::super::codec::Value> = None;
let mut raw_role: Option<&super::super::codec::Value> = None;
let mut raw_qualification: 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);
}
"sequence" => {
raw_sequence = Some(value);
}
"_sequence" => {
raw_sequence_element = Some(value);
}
"provider" => {
raw_provider = Some(value);
}
"responsible" => {
raw_responsible = Some(value);
}
"_responsible" => {
raw_responsible_element = Some(value);
}
"role" => {
raw_role = Some(value);
}
"qualification" => {
raw_qualification = 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_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let field_provider = path.with("provider", |path| {
let value = raw_provider
.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_responsible = match (raw_responsible, raw_responsible_element) {
(None, None) => None,
(value, element) => Some(path.with("responsible", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_role = raw_role
.map(|value| {
path.with("role", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_qualification = raw_qualification
.map(|value| {
path.with("qualification", |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,
sequence: field_sequence,
provider: field_provider,
responsible: field_responsible,
role: field_role,
qualification: field_qualification,
})
}
}
impl serde::Serialize for ClaimCareTeam {
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.responsible {
super::super::codec::element_entry(&mut map, "_responsible", item)?;
}
super::super::codec::element_entry(&mut map, "_sequence", &self.sequence)?;
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, "provider", &self.provider)?;
if let Some(item) = &self.qualification {
serde::ser::SerializeMap::serialize_entry(&mut map, "qualification", item)?;
}
if let Some(item) = &self.responsible {
super::super::codec::value_entry(&mut map, "responsible", item)?;
}
if let Some(item) = &self.role {
serde::ser::SerializeMap::serialize_entry(&mut map, "role", item)?;
}
super::super::codec::value_entry(&mut map, "sequence", &self.sequence)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimCareTeam {
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("ClaimCareTeam");
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 struct ClaimDiagnosis {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub sequence: super::primitives::PositiveInt,
pub diagnosis: ClaimDiagnosisDiagnosis,
pub r#type: Vec<super::codeable_concept::CodeableConcept>,
pub package_code: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ClaimDiagnosis {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.sequence)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.sequence)? {
object.insert(std::string::String::from("_sequence"), e);
}
let (suffix, value, element) = self.diagnosis.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("diagnosis{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_diagnosis{suffix}"), element);
}
if !self.r#type.is_empty() {
let mut items = Vec::with_capacity(self.r#type.len());
for item in &self.r#type {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.package_code {
object.insert(
std::string::String::from("packageCode"),
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_sequence: Option<&super::super::codec::Value> = None;
let mut raw_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_diagnosis = super::super::codec::ChoiceSlot::default();
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_package_code: 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);
}
"sequence" => {
raw_sequence = Some(value);
}
"_sequence" => {
raw_sequence_element = Some(value);
}
"diagnosisCodeableConcept" => {
raw_diagnosis.value("CodeableConcept", value, path)?;
}
"_diagnosisCodeableConcept" => {
raw_diagnosis.element("CodeableConcept", value, path)?;
}
"diagnosisReference" => {
raw_diagnosis.value("Reference", value, path)?;
}
"_diagnosisReference" => {
raw_diagnosis.element("Reference", value, path)?;
}
"type" => {
raw_type = Some(value);
}
"packageCode" => {
raw_package_code = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::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_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let field_diagnosis = path.with("diagnosis", |path| {
let suffix = raw_diagnosis
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
ClaimDiagnosisDiagnosis::from_json_parts(
suffix,
raw_diagnosis.value,
raw_diagnosis.element,
path,
)
})?;
let mut field_type = Vec::new();
if let Some(raw) = raw_type {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_type.push(path.with_index("type", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_package_code = raw_package_code
.map(|value| {
path.with("packageCode", |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,
sequence: field_sequence,
diagnosis: field_diagnosis,
r#type: field_type,
package_code: field_package_code,
})
}
}
impl serde::Serialize for ClaimDiagnosis {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_sequence", &self.sequence)?;
match &self.diagnosis {
ClaimDiagnosisDiagnosis::CodeableConcept(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"diagnosisCodeableConcept",
inner.as_ref(),
)?;
}
ClaimDiagnosisDiagnosis::Reference(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"diagnosisReference",
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,
)?;
}
if let Some(item) = &self.package_code {
serde::ser::SerializeMap::serialize_entry(&mut map, "packageCode", item)?;
}
super::super::codec::value_entry(&mut map, "sequence", &self.sequence)?;
if !self.r#type.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimDiagnosis {
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("ClaimDiagnosis");
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 ClaimDiagnosisDiagnosis {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Reference(Box<super::reference::Reference>),
}
impl ClaimDiagnosisDiagnosis {
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 ClaimInformation {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub sequence: super::primitives::PositiveInt,
pub category: super::codeable_concept::CodeableConcept,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub timing: Option<ClaimInformationTiming>,
pub value: Option<ClaimInformationValue>,
pub reason: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ClaimInformation {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.sequence)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.sequence)? {
object.insert(std::string::String::from("_sequence"), e);
}
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.category)?),
);
if let Some(item) = &self.code {
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.timing {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("timing{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_timing{suffix}"), element);
}
}
if let Some(item) = &self.value {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("value{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_value{suffix}"), element);
}
}
if let Some(item) = &self.reason {
object.insert(
std::string::String::from("reason"),
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_sequence: Option<&super::super::codec::Value> = None;
let mut raw_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_timing = super::super::codec::ChoiceSlot::default();
let mut raw_value = super::super::codec::ChoiceSlot::default();
let mut raw_reason: 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);
}
"sequence" => {
raw_sequence = Some(value);
}
"_sequence" => {
raw_sequence_element = Some(value);
}
"category" => {
raw_category = Some(value);
}
"code" => {
raw_code = Some(value);
}
"timingDate" => {
raw_timing.value("Date", value, path)?;
}
"_timingDate" => {
raw_timing.element("Date", value, path)?;
}
"timingPeriod" => {
raw_timing.value("Period", value, path)?;
}
"_timingPeriod" => {
raw_timing.element("Period", value, path)?;
}
"valueString" => {
raw_value.value("String", value, path)?;
}
"_valueString" => {
raw_value.element("String", value, path)?;
}
"valueQuantity" => {
raw_value.value("Quantity", value, path)?;
}
"_valueQuantity" => {
raw_value.element("Quantity", value, path)?;
}
"valueAttachment" => {
raw_value.value("Attachment", value, path)?;
}
"_valueAttachment" => {
raw_value.element("Attachment", value, path)?;
}
"valueReference" => {
raw_value.value("Reference", value, path)?;
}
"_valueReference" => {
raw_value.element("Reference", value, path)?;
}
"reason" => {
raw_reason = 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_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let field_category = path.with("category", |path| {
let value = raw_category
.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_code = raw_code
.map(|value| {
path.with("code", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_timing = match raw_timing.suffix {
None => None,
Some(suffix) => Some(path.with("timing", |path| {
ClaimInformationTiming::from_json_parts(
suffix,
raw_timing.value,
raw_timing.element,
path,
)
})?),
};
let field_value = match raw_value.suffix {
None => None,
Some(suffix) => Some(path.with("value", |path| {
ClaimInformationValue::from_json_parts(
suffix,
raw_value.value,
raw_value.element,
path,
)
})?),
};
let field_reason = raw_reason
.map(|value| {
path.with("reason", |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,
sequence: field_sequence,
category: field_category,
code: field_code,
timing: field_timing,
value: field_value,
reason: field_reason,
})
}
}
impl serde::Serialize for ClaimInformation {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_sequence", &self.sequence)?;
if let Some(ClaimInformationTiming::Date(inner)) = &self.timing {
super::super::codec::element_entry(&mut map, "_timingDate", inner)?;
}
if let Some(ClaimInformationValue::String(inner)) = &self.value {
super::super::codec::element_entry(&mut map, "_valueString", inner)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
if let Some(item) = &self.code {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.reason {
serde::ser::SerializeMap::serialize_entry(&mut map, "reason", item)?;
}
super::super::codec::value_entry(&mut map, "sequence", &self.sequence)?;
match &self.timing {
Some(ClaimInformationTiming::Date(inner)) => {
super::super::codec::value_entry(&mut map, "timingDate", inner)?;
}
Some(ClaimInformationTiming::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"timingPeriod",
inner.as_ref(),
)?;
}
None => {}
}
match &self.value {
Some(ClaimInformationValue::Attachment(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueAttachment",
inner.as_ref(),
)?;
}
Some(ClaimInformationValue::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueQuantity",
inner.as_ref(),
)?;
}
Some(ClaimInformationValue::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueReference",
inner.as_ref(),
)?;
}
Some(ClaimInformationValue::String(inner)) => {
super::super::codec::value_entry(&mut map, "valueString", inner)?;
}
None => {}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimInformation {
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("ClaimInformation");
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 ClaimInformationTiming {
Date(super::primitives::Date),
Period(Box<super::period::Period>),
}
impl ClaimInformationTiming {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::Date(inner) => Ok((
"Date",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Date" => Ok(Self::Date(super::super::codec::Primitive::from_json_parts(
value, element, path,
)?)),
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ClaimInformationValue {
String(super::primitives::String),
Quantity(Box<super::quantity::Quantity>),
Attachment(Box<super::attachment::Attachment>),
Reference(Box<super::reference::Reference>),
}
impl ClaimInformationValue {
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::String(inner) => Ok((
"String",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Quantity(inner) => Ok((
"Quantity",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
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 {
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Quantity" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Quantity(Box::new(inner)))
}
"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 ClaimInsurance {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub sequence: super::primitives::PositiveInt,
pub focal: super::primitives::Boolean,
pub coverage: super::reference::Reference,
pub business_arrangement: Option<super::primitives::String>,
pub pre_auth_ref: Vec<super::primitives::String>,
pub claim_response: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ClaimInsurance {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.sequence)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.sequence)? {
object.insert(std::string::String::from("_sequence"), e);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.focal)? {
object.insert(std::string::String::from("focal"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.focal)? {
object.insert(std::string::String::from("_focal"), e);
}
object.insert(
std::string::String::from("coverage"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.coverage)?),
);
if let Some(item) = &self.business_arrangement {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("businessArrangement"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_businessArrangement"), e);
}
}
if !self.pre_auth_ref.is_empty() {
let (values, elements) = super::super::codec::primitive_arrays(&self.pre_auth_ref)?;
object.insert(std::string::String::from("preAuthRef"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_preAuthRef"), elements);
}
}
if let Some(item) = &self.claim_response {
object.insert(
std::string::String::from("claimResponse"),
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_sequence: Option<&super::super::codec::Value> = None;
let mut raw_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_focal: Option<&super::super::codec::Value> = None;
let mut raw_focal_element: Option<&super::super::codec::Value> = None;
let mut raw_coverage: Option<&super::super::codec::Value> = None;
let mut raw_business_arrangement: Option<&super::super::codec::Value> = None;
let mut raw_business_arrangement_element: Option<&super::super::codec::Value> = None;
let mut raw_pre_auth_ref: Option<&super::super::codec::Value> = None;
let mut raw_pre_auth_ref_element: Option<&super::super::codec::Value> = None;
let mut raw_claim_response: 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);
}
"sequence" => {
raw_sequence = Some(value);
}
"_sequence" => {
raw_sequence_element = Some(value);
}
"focal" => {
raw_focal = Some(value);
}
"_focal" => {
raw_focal_element = Some(value);
}
"coverage" => {
raw_coverage = Some(value);
}
"businessArrangement" => {
raw_business_arrangement = Some(value);
}
"_businessArrangement" => {
raw_business_arrangement_element = Some(value);
}
"preAuthRef" => {
raw_pre_auth_ref = Some(value);
}
"_preAuthRef" => {
raw_pre_auth_ref_element = Some(value);
}
"claimResponse" => {
raw_claim_response = 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_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let field_focal = path.with("focal", |path| {
super::super::codec::Primitive::from_json_parts(raw_focal, raw_focal_element, path)
})?;
let field_coverage = path.with("coverage", |path| {
let value = raw_coverage
.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_business_arrangement =
match (raw_business_arrangement, raw_business_arrangement_element) {
(None, None) => None,
(value, element) => Some(path.with("businessArrangement", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_pre_auth_ref = Vec::new();
for (index, (value, element)) in
super::super::codec::pair_arrays(raw_pre_auth_ref, raw_pre_auth_ref_element, path)?
.into_iter()
.enumerate()
{
field_pre_auth_ref.push(path.with_index("preAuthRef", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let field_claim_response = raw_claim_response
.map(|value| {
path.with("claimResponse", |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,
sequence: field_sequence,
focal: field_focal,
coverage: field_coverage,
business_arrangement: field_business_arrangement,
pre_auth_ref: field_pre_auth_ref,
claim_response: field_claim_response,
})
}
}
impl serde::Serialize for ClaimInsurance {
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.business_arrangement {
super::super::codec::element_entry(&mut map, "_businessArrangement", item)?;
}
super::super::codec::element_entry(&mut map, "_focal", &self.focal)?;
super::super::codec::element_list_entry(&mut map, "_preAuthRef", &self.pre_auth_ref)?;
super::super::codec::element_entry(&mut map, "_sequence", &self.sequence)?;
if let Some(item) = &self.business_arrangement {
super::super::codec::value_entry(&mut map, "businessArrangement", item)?;
}
if let Some(item) = &self.claim_response {
serde::ser::SerializeMap::serialize_entry(&mut map, "claimResponse", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "coverage", &self.coverage)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
super::super::codec::value_entry(&mut map, "focal", &self.focal)?;
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,
)?;
}
super::super::codec::value_list_entry(&mut map, "preAuthRef", &self.pre_auth_ref)?;
super::super::codec::value_entry(&mut map, "sequence", &self.sequence)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimInsurance {
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("ClaimInsurance");
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 ClaimItem {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub sequence: super::primitives::PositiveInt,
pub care_team_link_id: Vec<super::primitives::PositiveInt>,
pub diagnosis_link_id: Vec<super::primitives::PositiveInt>,
pub procedure_link_id: Vec<super::primitives::PositiveInt>,
pub information_link_id: Vec<super::primitives::PositiveInt>,
pub revenue: Option<super::codeable_concept::CodeableConcept>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub service: Option<super::codeable_concept::CodeableConcept>,
pub modifier: Vec<super::codeable_concept::CodeableConcept>,
pub program_code: Vec<super::codeable_concept::CodeableConcept>,
pub serviced: Option<ClaimItemServiced>,
pub location: Option<ClaimItemLocation>,
pub quantity: Option<super::quantity::Quantity>,
pub unit_price: Option<super::money::Money>,
pub factor: Option<super::primitives::Decimal>,
pub net: Option<super::money::Money>,
pub udi: Vec<super::reference::Reference>,
pub body_site: Option<super::codeable_concept::CodeableConcept>,
pub sub_site: Vec<super::codeable_concept::CodeableConcept>,
pub encounter: Vec<super::reference::Reference>,
pub detail: Vec<ClaimItemDetail>,
}
impl super::super::codec::Json for ClaimItem {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.sequence)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.sequence)? {
object.insert(std::string::String::from("_sequence"), e);
}
if !self.care_team_link_id.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.care_team_link_id)?;
object.insert(std::string::String::from("careTeamLinkId"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_careTeamLinkId"), elements);
}
}
if !self.diagnosis_link_id.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.diagnosis_link_id)?;
object.insert(std::string::String::from("diagnosisLinkId"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_diagnosisLinkId"), elements);
}
}
if !self.procedure_link_id.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.procedure_link_id)?;
object.insert(std::string::String::from("procedureLinkId"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_procedureLinkId"), elements);
}
}
if !self.information_link_id.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.information_link_id)?;
object.insert(std::string::String::from("informationLinkId"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_informationLinkId"), elements);
}
}
if let Some(item) = &self.revenue {
object.insert(
std::string::String::from("revenue"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.category {
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.service {
object.insert(
std::string::String::from("service"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.modifier.is_empty() {
let mut items = Vec::with_capacity(self.modifier.len());
for item in &self.modifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifier"),
super::super::codec::Value::Array(items),
);
}
if !self.program_code.is_empty() {
let mut items = Vec::with_capacity(self.program_code.len());
for item in &self.program_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("programCode"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.serviced {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("serviced{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_serviced{suffix}"), element);
}
}
if let Some(item) = &self.location {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("location{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_location{suffix}"), element);
}
}
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.net {
object.insert(
std::string::String::from("net"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.udi.is_empty() {
let mut items = Vec::with_capacity(self.udi.len());
for item in &self.udi {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("udi"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.body_site {
object.insert(
std::string::String::from("bodySite"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.sub_site.is_empty() {
let mut items = Vec::with_capacity(self.sub_site.len());
for item in &self.sub_site {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("subSite"),
super::super::codec::Value::Array(items),
);
}
if !self.encounter.is_empty() {
let mut items = Vec::with_capacity(self.encounter.len());
for item in &self.encounter {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("encounter"),
super::super::codec::Value::Array(items),
);
}
if !self.detail.is_empty() {
let mut items = Vec::with_capacity(self.detail.len());
for item in &self.detail {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("detail"),
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_sequence: Option<&super::super::codec::Value> = None;
let mut raw_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_care_team_link_id: Option<&super::super::codec::Value> = None;
let mut raw_care_team_link_id_element: Option<&super::super::codec::Value> = None;
let mut raw_diagnosis_link_id: Option<&super::super::codec::Value> = None;
let mut raw_diagnosis_link_id_element: Option<&super::super::codec::Value> = None;
let mut raw_procedure_link_id: Option<&super::super::codec::Value> = None;
let mut raw_procedure_link_id_element: Option<&super::super::codec::Value> = None;
let mut raw_information_link_id: Option<&super::super::codec::Value> = None;
let mut raw_information_link_id_element: Option<&super::super::codec::Value> = None;
let mut raw_revenue: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_service: Option<&super::super::codec::Value> = None;
let mut raw_modifier: Option<&super::super::codec::Value> = None;
let mut raw_program_code: Option<&super::super::codec::Value> = None;
let mut raw_serviced = super::super::codec::ChoiceSlot::default();
let mut raw_location = super::super::codec::ChoiceSlot::default();
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_net: Option<&super::super::codec::Value> = None;
let mut raw_udi: Option<&super::super::codec::Value> = None;
let mut raw_body_site: Option<&super::super::codec::Value> = None;
let mut raw_sub_site: Option<&super::super::codec::Value> = None;
let mut raw_encounter: Option<&super::super::codec::Value> = None;
let mut raw_detail: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"sequence" => {
raw_sequence = Some(value);
}
"_sequence" => {
raw_sequence_element = Some(value);
}
"careTeamLinkId" => {
raw_care_team_link_id = Some(value);
}
"_careTeamLinkId" => {
raw_care_team_link_id_element = Some(value);
}
"diagnosisLinkId" => {
raw_diagnosis_link_id = Some(value);
}
"_diagnosisLinkId" => {
raw_diagnosis_link_id_element = Some(value);
}
"procedureLinkId" => {
raw_procedure_link_id = Some(value);
}
"_procedureLinkId" => {
raw_procedure_link_id_element = Some(value);
}
"informationLinkId" => {
raw_information_link_id = Some(value);
}
"_informationLinkId" => {
raw_information_link_id_element = Some(value);
}
"revenue" => {
raw_revenue = Some(value);
}
"category" => {
raw_category = Some(value);
}
"service" => {
raw_service = Some(value);
}
"modifier" => {
raw_modifier = Some(value);
}
"programCode" => {
raw_program_code = Some(value);
}
"servicedDate" => {
raw_serviced.value("Date", value, path)?;
}
"_servicedDate" => {
raw_serviced.element("Date", value, path)?;
}
"servicedPeriod" => {
raw_serviced.value("Period", value, path)?;
}
"_servicedPeriod" => {
raw_serviced.element("Period", value, path)?;
}
"locationCodeableConcept" => {
raw_location.value("CodeableConcept", value, path)?;
}
"_locationCodeableConcept" => {
raw_location.element("CodeableConcept", value, path)?;
}
"locationAddress" => {
raw_location.value("Address", value, path)?;
}
"_locationAddress" => {
raw_location.element("Address", value, path)?;
}
"locationReference" => {
raw_location.value("Reference", value, path)?;
}
"_locationReference" => {
raw_location.element("Reference", value, path)?;
}
"quantity" => {
raw_quantity = Some(value);
}
"unitPrice" => {
raw_unit_price = Some(value);
}
"factor" => {
raw_factor = Some(value);
}
"_factor" => {
raw_factor_element = Some(value);
}
"net" => {
raw_net = Some(value);
}
"udi" => {
raw_udi = Some(value);
}
"bodySite" => {
raw_body_site = Some(value);
}
"subSite" => {
raw_sub_site = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"detail" => {
raw_detail = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let mut field_care_team_link_id = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_care_team_link_id,
raw_care_team_link_id_element,
path,
)?
.into_iter()
.enumerate()
{
field_care_team_link_id.push(path.with_index("careTeamLinkId", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let mut field_diagnosis_link_id = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_diagnosis_link_id,
raw_diagnosis_link_id_element,
path,
)?
.into_iter()
.enumerate()
{
field_diagnosis_link_id.push(path.with_index("diagnosisLinkId", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let mut field_procedure_link_id = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_procedure_link_id,
raw_procedure_link_id_element,
path,
)?
.into_iter()
.enumerate()
{
field_procedure_link_id.push(path.with_index("procedureLinkId", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let mut field_information_link_id = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_information_link_id,
raw_information_link_id_element,
path,
)?
.into_iter()
.enumerate()
{
field_information_link_id.push(path.with_index(
"informationLinkId",
index,
|path| super::super::codec::Primitive::from_json_parts(value, element, path),
)?);
}
let field_revenue = raw_revenue
.map(|value| {
path.with("revenue", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_category = raw_category
.map(|value| {
path.with("category", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_service = raw_service
.map(|value| {
path.with("service", |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_modifier = Vec::new();
if let Some(raw) = raw_modifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier.push(path.with_index("modifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_program_code = Vec::new();
if let Some(raw) = raw_program_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_program_code.push(path.with_index("programCode", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_serviced = match raw_serviced.suffix {
None => None,
Some(suffix) => Some(path.with("serviced", |path| {
ClaimItemServiced::from_json_parts(
suffix,
raw_serviced.value,
raw_serviced.element,
path,
)
})?),
};
let field_location = match raw_location.suffix {
None => None,
Some(suffix) => Some(path.with("location", |path| {
ClaimItemLocation::from_json_parts(
suffix,
raw_location.value,
raw_location.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_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()?;
let mut field_udi = Vec::new();
if let Some(raw) = raw_udi {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_udi.push(path.with_index("udi", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_body_site = raw_body_site
.map(|value| {
path.with("bodySite", |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_site = Vec::new();
if let Some(raw) = raw_sub_site {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_sub_site.push(path.with_index("subSite", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_encounter = Vec::new();
if let Some(raw) = raw_encounter {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_encounter.push(path.with_index("encounter", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_detail = Vec::new();
if let Some(raw) = raw_detail {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_detail.push(path.with_index("detail", 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,
sequence: field_sequence,
care_team_link_id: field_care_team_link_id,
diagnosis_link_id: field_diagnosis_link_id,
procedure_link_id: field_procedure_link_id,
information_link_id: field_information_link_id,
revenue: field_revenue,
category: field_category,
service: field_service,
modifier: field_modifier,
program_code: field_program_code,
serviced: field_serviced,
location: field_location,
quantity: field_quantity,
unit_price: field_unit_price,
factor: field_factor,
net: field_net,
udi: field_udi,
body_site: field_body_site,
sub_site: field_sub_site,
encounter: field_encounter,
detail: field_detail,
})
}
}
impl serde::Serialize for ClaimItem {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_list_entry(
&mut map,
"_careTeamLinkId",
&self.care_team_link_id,
)?;
super::super::codec::element_list_entry(
&mut map,
"_diagnosisLinkId",
&self.diagnosis_link_id,
)?;
if let Some(item) = &self.factor {
super::super::codec::element_entry(&mut map, "_factor", item)?;
}
super::super::codec::element_list_entry(
&mut map,
"_informationLinkId",
&self.information_link_id,
)?;
super::super::codec::element_list_entry(
&mut map,
"_procedureLinkId",
&self.procedure_link_id,
)?;
super::super::codec::element_entry(&mut map, "_sequence", &self.sequence)?;
if let Some(ClaimItemServiced::Date(inner)) = &self.serviced {
super::super::codec::element_entry(&mut map, "_servicedDate", inner)?;
}
if let Some(item) = &self.body_site {
serde::ser::SerializeMap::serialize_entry(&mut map, "bodySite", item)?;
}
super::super::codec::value_list_entry(&mut map, "careTeamLinkId", &self.care_team_link_id)?;
if let Some(item) = &self.category {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", item)?;
}
if !self.detail.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "detail", &self.detail)?;
}
super::super::codec::value_list_entry(
&mut map,
"diagnosisLinkId",
&self.diagnosis_link_id,
)?;
if !self.encounter.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", &self.encounter)?;
}
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)?;
}
super::super::codec::value_list_entry(
&mut map,
"informationLinkId",
&self.information_link_id,
)?;
match &self.location {
Some(ClaimItemLocation::Address(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"locationAddress",
inner.as_ref(),
)?;
}
Some(ClaimItemLocation::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"locationCodeableConcept",
inner.as_ref(),
)?;
}
Some(ClaimItemLocation::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"locationReference",
inner.as_ref(),
)?;
}
None => {}
}
if !self.modifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "modifier", &self.modifier)?;
}
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)?;
}
super::super::codec::value_list_entry(
&mut map,
"procedureLinkId",
&self.procedure_link_id,
)?;
if !self.program_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "programCode", &self.program_code)?;
}
if let Some(item) = &self.quantity {
serde::ser::SerializeMap::serialize_entry(&mut map, "quantity", item)?;
}
if let Some(item) = &self.revenue {
serde::ser::SerializeMap::serialize_entry(&mut map, "revenue", item)?;
}
super::super::codec::value_entry(&mut map, "sequence", &self.sequence)?;
if let Some(item) = &self.service {
serde::ser::SerializeMap::serialize_entry(&mut map, "service", item)?;
}
match &self.serviced {
Some(ClaimItemServiced::Date(inner)) => {
super::super::codec::value_entry(&mut map, "servicedDate", inner)?;
}
Some(ClaimItemServiced::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"servicedPeriod",
inner.as_ref(),
)?;
}
None => {}
}
if !self.sub_site.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "subSite", &self.sub_site)?;
}
if !self.udi.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "udi", &self.udi)?;
}
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 ClaimItem {
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("ClaimItem");
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 ClaimItemDetail {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub sequence: super::primitives::PositiveInt,
pub revenue: Option<super::codeable_concept::CodeableConcept>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub service: Option<super::codeable_concept::CodeableConcept>,
pub modifier: Vec<super::codeable_concept::CodeableConcept>,
pub program_code: Vec<super::codeable_concept::CodeableConcept>,
pub quantity: Option<super::quantity::Quantity>,
pub unit_price: Option<super::money::Money>,
pub factor: Option<super::primitives::Decimal>,
pub net: Option<super::money::Money>,
pub udi: Vec<super::reference::Reference>,
pub sub_detail: Vec<ClaimItemDetailSubDetail>,
}
impl super::super::codec::Json for ClaimItemDetail {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.sequence)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.sequence)? {
object.insert(std::string::String::from("_sequence"), e);
}
if let Some(item) = &self.revenue {
object.insert(
std::string::String::from("revenue"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.category {
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.service {
object.insert(
std::string::String::from("service"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.modifier.is_empty() {
let mut items = Vec::with_capacity(self.modifier.len());
for item in &self.modifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifier"),
super::super::codec::Value::Array(items),
);
}
if !self.program_code.is_empty() {
let mut items = Vec::with_capacity(self.program_code.len());
for item in &self.program_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("programCode"),
super::super::codec::Value::Array(items),
);
}
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.net {
object.insert(
std::string::String::from("net"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.udi.is_empty() {
let mut items = Vec::with_capacity(self.udi.len());
for item in &self.udi {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("udi"),
super::super::codec::Value::Array(items),
);
}
if !self.sub_detail.is_empty() {
let mut items = Vec::with_capacity(self.sub_detail.len());
for item in &self.sub_detail {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("subDetail"),
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_sequence: Option<&super::super::codec::Value> = None;
let mut raw_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_revenue: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_service: Option<&super::super::codec::Value> = None;
let mut raw_modifier: Option<&super::super::codec::Value> = None;
let mut raw_program_code: 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_net: Option<&super::super::codec::Value> = None;
let mut raw_udi: Option<&super::super::codec::Value> = None;
let mut raw_sub_detail: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"sequence" => {
raw_sequence = Some(value);
}
"_sequence" => {
raw_sequence_element = Some(value);
}
"revenue" => {
raw_revenue = Some(value);
}
"category" => {
raw_category = Some(value);
}
"service" => {
raw_service = Some(value);
}
"modifier" => {
raw_modifier = Some(value);
}
"programCode" => {
raw_program_code = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"unitPrice" => {
raw_unit_price = Some(value);
}
"factor" => {
raw_factor = Some(value);
}
"_factor" => {
raw_factor_element = Some(value);
}
"net" => {
raw_net = Some(value);
}
"udi" => {
raw_udi = Some(value);
}
"subDetail" => {
raw_sub_detail = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let field_revenue = raw_revenue
.map(|value| {
path.with("revenue", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_category = raw_category
.map(|value| {
path.with("category", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_service = raw_service
.map(|value| {
path.with("service", |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_modifier = Vec::new();
if let Some(raw) = raw_modifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier.push(path.with_index("modifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_program_code = Vec::new();
if let Some(raw) = raw_program_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_program_code.push(path.with_index("programCode", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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_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()?;
let mut field_udi = Vec::new();
if let Some(raw) = raw_udi {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_udi.push(path.with_index("udi", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_sub_detail = Vec::new();
if let Some(raw) = raw_sub_detail {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_sub_detail.push(path.with_index("subDetail", 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,
sequence: field_sequence,
revenue: field_revenue,
category: field_category,
service: field_service,
modifier: field_modifier,
program_code: field_program_code,
quantity: field_quantity,
unit_price: field_unit_price,
factor: field_factor,
net: field_net,
udi: field_udi,
sub_detail: field_sub_detail,
})
}
}
impl serde::Serialize for ClaimItemDetail {
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.factor {
super::super::codec::element_entry(&mut map, "_factor", item)?;
}
super::super::codec::element_entry(&mut map, "_sequence", &self.sequence)?;
if let Some(item) = &self.category {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", item)?;
}
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 !self.modifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "modifier", &self.modifier)?;
}
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 !self.program_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "programCode", &self.program_code)?;
}
if let Some(item) = &self.quantity {
serde::ser::SerializeMap::serialize_entry(&mut map, "quantity", item)?;
}
if let Some(item) = &self.revenue {
serde::ser::SerializeMap::serialize_entry(&mut map, "revenue", item)?;
}
super::super::codec::value_entry(&mut map, "sequence", &self.sequence)?;
if let Some(item) = &self.service {
serde::ser::SerializeMap::serialize_entry(&mut map, "service", item)?;
}
if !self.sub_detail.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "subDetail", &self.sub_detail)?;
}
if !self.udi.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "udi", &self.udi)?;
}
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 ClaimItemDetail {
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("ClaimItemDetail");
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 ClaimItemDetailSubDetail {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub sequence: super::primitives::PositiveInt,
pub revenue: Option<super::codeable_concept::CodeableConcept>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub service: Option<super::codeable_concept::CodeableConcept>,
pub modifier: Vec<super::codeable_concept::CodeableConcept>,
pub program_code: Vec<super::codeable_concept::CodeableConcept>,
pub quantity: Option<super::quantity::Quantity>,
pub unit_price: Option<super::money::Money>,
pub factor: Option<super::primitives::Decimal>,
pub net: Option<super::money::Money>,
pub udi: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for ClaimItemDetailSubDetail {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.sequence)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.sequence)? {
object.insert(std::string::String::from("_sequence"), e);
}
if let Some(item) = &self.revenue {
object.insert(
std::string::String::from("revenue"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.category {
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.service {
object.insert(
std::string::String::from("service"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.modifier.is_empty() {
let mut items = Vec::with_capacity(self.modifier.len());
for item in &self.modifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifier"),
super::super::codec::Value::Array(items),
);
}
if !self.program_code.is_empty() {
let mut items = Vec::with_capacity(self.program_code.len());
for item in &self.program_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("programCode"),
super::super::codec::Value::Array(items),
);
}
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.net {
object.insert(
std::string::String::from("net"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.udi.is_empty() {
let mut items = Vec::with_capacity(self.udi.len());
for item in &self.udi {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("udi"),
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_sequence: Option<&super::super::codec::Value> = None;
let mut raw_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_revenue: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_service: Option<&super::super::codec::Value> = None;
let mut raw_modifier: Option<&super::super::codec::Value> = None;
let mut raw_program_code: 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_net: Option<&super::super::codec::Value> = None;
let mut raw_udi: 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);
}
"sequence" => {
raw_sequence = Some(value);
}
"_sequence" => {
raw_sequence_element = Some(value);
}
"revenue" => {
raw_revenue = Some(value);
}
"category" => {
raw_category = Some(value);
}
"service" => {
raw_service = Some(value);
}
"modifier" => {
raw_modifier = Some(value);
}
"programCode" => {
raw_program_code = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"unitPrice" => {
raw_unit_price = Some(value);
}
"factor" => {
raw_factor = Some(value);
}
"_factor" => {
raw_factor_element = Some(value);
}
"net" => {
raw_net = Some(value);
}
"udi" => {
raw_udi = 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_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let field_revenue = raw_revenue
.map(|value| {
path.with("revenue", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_category = raw_category
.map(|value| {
path.with("category", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_service = raw_service
.map(|value| {
path.with("service", |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_modifier = Vec::new();
if let Some(raw) = raw_modifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier.push(path.with_index("modifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_program_code = Vec::new();
if let Some(raw) = raw_program_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_program_code.push(path.with_index("programCode", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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_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()?;
let mut field_udi = Vec::new();
if let Some(raw) = raw_udi {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_udi.push(path.with_index("udi", 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,
sequence: field_sequence,
revenue: field_revenue,
category: field_category,
service: field_service,
modifier: field_modifier,
program_code: field_program_code,
quantity: field_quantity,
unit_price: field_unit_price,
factor: field_factor,
net: field_net,
udi: field_udi,
})
}
}
impl serde::Serialize for ClaimItemDetailSubDetail {
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.factor {
super::super::codec::element_entry(&mut map, "_factor", item)?;
}
super::super::codec::element_entry(&mut map, "_sequence", &self.sequence)?;
if let Some(item) = &self.category {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", item)?;
}
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 !self.modifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "modifier", &self.modifier)?;
}
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 !self.program_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "programCode", &self.program_code)?;
}
if let Some(item) = &self.quantity {
serde::ser::SerializeMap::serialize_entry(&mut map, "quantity", item)?;
}
if let Some(item) = &self.revenue {
serde::ser::SerializeMap::serialize_entry(&mut map, "revenue", item)?;
}
super::super::codec::value_entry(&mut map, "sequence", &self.sequence)?;
if let Some(item) = &self.service {
serde::ser::SerializeMap::serialize_entry(&mut map, "service", item)?;
}
if !self.udi.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "udi", &self.udi)?;
}
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 ClaimItemDetailSubDetail {
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("ClaimItemDetailSubDetail");
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 ClaimItemLocation {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Address(Box<super::address::Address>),
Reference(Box<super::reference::Reference>),
}
impl ClaimItemLocation {
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::Address(inner) => Ok((
"Address",
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)))
}
"Address" => {
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::Address(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ClaimItemServiced {
Date(super::primitives::Date),
Period(Box<super::period::Period>),
}
impl ClaimItemServiced {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::Date(inner) => Ok((
"Date",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Date" => Ok(Self::Date(super::super::codec::Primitive::from_json_parts(
value, element, path,
)?)),
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ClaimPayee {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub r#type: super::codeable_concept::CodeableConcept,
pub resource_type: Option<super::coding::Coding>,
pub party: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ClaimPayee {
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)?),
);
if let Some(item) = &self.resource_type {
object.insert(
std::string::String::from("resourceType"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.party {
object.insert(
std::string::String::from("party"),
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_type: Option<&super::super::codec::Value> = None;
let mut raw_resource_type: Option<&super::super::codec::Value> = None;
let mut raw_party: 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);
}
"resourceType" => {
raw_resource_type = Some(value);
}
"party" => {
raw_party = 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_resource_type = raw_resource_type
.map(|value| {
path.with("resourceType", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_party = raw_party
.map(|value| {
path.with("party", |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,
r#type: field_type,
resource_type: field_resource_type,
party: field_party,
})
}
}
impl serde::Serialize for ClaimPayee {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.party {
serde::ser::SerializeMap::serialize_entry(&mut map, "party", item)?;
}
if let Some(item) = &self.resource_type {
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimPayee {
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("ClaimPayee");
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 struct ClaimProcedure {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub sequence: super::primitives::PositiveInt,
pub date: Option<super::primitives::DateTime>,
pub procedure: ClaimProcedureProcedure,
}
impl super::super::codec::Json for ClaimProcedure {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.sequence)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.sequence)? {
object.insert(std::string::String::from("_sequence"), e);
}
if let Some(item) = &self.date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("date"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_date"), e);
}
}
let (suffix, value, element) = self.procedure.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("procedure{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_procedure{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_sequence: Option<&super::super::codec::Value> = None;
let mut raw_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_date: Option<&super::super::codec::Value> = None;
let mut raw_date_element: Option<&super::super::codec::Value> = None;
let mut raw_procedure = 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);
}
"sequence" => {
raw_sequence = Some(value);
}
"_sequence" => {
raw_sequence_element = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_element = Some(value);
}
"procedureCodeableConcept" => {
raw_procedure.value("CodeableConcept", value, path)?;
}
"_procedureCodeableConcept" => {
raw_procedure.element("CodeableConcept", value, path)?;
}
"procedureReference" => {
raw_procedure.value("Reference", value, path)?;
}
"_procedureReference" => {
raw_procedure.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_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let field_date = match (raw_date, raw_date_element) {
(None, None) => None,
(value, element) => Some(path.with("date", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_procedure = path.with("procedure", |path| {
let suffix = raw_procedure
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
ClaimProcedureProcedure::from_json_parts(
suffix,
raw_procedure.value,
raw_procedure.element,
path,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
sequence: field_sequence,
date: field_date,
procedure: field_procedure,
})
}
}
impl serde::Serialize for ClaimProcedure {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.date {
super::super::codec::element_entry(&mut map, "_date", item)?;
}
super::super::codec::element_entry(&mut map, "_sequence", &self.sequence)?;
if let Some(item) = &self.date {
super::super::codec::value_entry(&mut map, "date", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
match &self.procedure {
ClaimProcedureProcedure::CodeableConcept(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"procedureCodeableConcept",
inner.as_ref(),
)?;
}
ClaimProcedureProcedure::Reference(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"procedureReference",
inner.as_ref(),
)?;
}
}
super::super::codec::value_entry(&mut map, "sequence", &self.sequence)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimProcedure {
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("ClaimProcedure");
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 ClaimProcedureProcedure {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Reference(Box<super::reference::Reference>),
}
impl ClaimProcedureProcedure {
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 ClaimRelated {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub claim: Option<super::reference::Reference>,
pub relationship: Option<super::codeable_concept::CodeableConcept>,
pub reference: Option<super::identifier::Identifier>,
}
impl super::super::codec::Json for ClaimRelated {
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.claim {
object.insert(
std::string::String::from("claim"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.relationship {
object.insert(
std::string::String::from("relationship"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.reference {
object.insert(
std::string::String::from("reference"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_claim: Option<&super::super::codec::Value> = None;
let mut raw_relationship: Option<&super::super::codec::Value> = None;
let mut raw_reference: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"claim" => {
raw_claim = Some(value);
}
"relationship" => {
raw_relationship = Some(value);
}
"reference" => {
raw_reference = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::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_claim = raw_claim
.map(|value| {
path.with("claim", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_relationship = raw_relationship
.map(|value| {
path.with("relationship", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_reference = raw_reference
.map(|value| {
path.with("reference", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
claim: field_claim,
relationship: field_relationship,
reference: field_reference,
})
}
}
impl serde::Serialize for ClaimRelated {
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.claim {
serde::ser::SerializeMap::serialize_entry(&mut map, "claim", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.reference {
serde::ser::SerializeMap::serialize_entry(&mut map, "reference", item)?;
}
if let Some(item) = &self.relationship {
serde::ser::SerializeMap::serialize_entry(&mut map, "relationship", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimRelated {
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("ClaimRelated");
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)
}
}