#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Claim {
pub id: Option<std::string::String>,
pub meta: Option<super::meta::Meta>,
pub implicit_rules: Option<super::primitives::Uri>,
pub language: Option<super::primitives::Code>,
pub text: Option<super::narrative::Narrative>,
pub contained: Vec<super::resource::Resource>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Vec<super::identifier::Identifier>,
pub trace_number: Vec<super::identifier::Identifier>,
pub status: super::primitives::Code,
pub r#type: super::codeable_concept::CodeableConcept,
pub sub_type: Option<super::codeable_concept::CodeableConcept>,
pub r#use: super::primitives::Code,
pub patient: super::reference::Reference,
pub billable_period: Option<super::period::Period>,
pub created: super::primitives::DateTime,
pub enterer: Option<super::reference::Reference>,
pub insurer: Option<super::reference::Reference>,
pub provider: 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 encounter: Vec<super::reference::Reference>,
pub facility: Option<super::reference::Reference>,
pub diagnosis_related_group: Option<super::codeable_concept::CodeableConcept>,
pub event: Vec<ClaimEvent>,
pub care_team: Vec<ClaimCareTeam>,
pub supporting_info: Vec<ClaimSupportingInfo>,
pub diagnosis: Vec<ClaimDiagnosis>,
pub procedure: Vec<ClaimProcedure>,
pub insurance: Vec<ClaimInsurance>,
pub accident: Option<ClaimAccident>,
pub patient_paid: Option<super::money::Money>,
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(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if !self.trace_number.is_empty() {
let mut items = Vec::with_capacity(self.trace_number.len());
for item in &self.trace_number {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("traceNumber"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.status)? {
object.insert(std::string::String::from("status"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.status)? {
object.insert(std::string::String::from("_status"), e);
}
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.sub_type {
object.insert(
std::string::String::from("subType"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.r#use)? {
object.insert(std::string::String::from("use"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.r#use)? {
object.insert(std::string::String::from("_use"), e);
}
object.insert(
std::string::String::from("patient"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.patient)?),
);
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(v) = super::super::codec::Primitive::value_json(&self.created)? {
object.insert(std::string::String::from("created"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.created)? {
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.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 !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 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 let Some(item) = &self.diagnosis_related_group {
object.insert(
std::string::String::from("diagnosisRelatedGroup"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.event.is_empty() {
let mut items = Vec::with_capacity(self.event.len());
for item in &self.event {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("event"),
super::super::codec::Value::Array(items),
);
}
if !self.care_team.is_empty() {
let mut items = Vec::with_capacity(self.care_team.len());
for item in &self.care_team {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("careTeam"),
super::super::codec::Value::Array(items),
);
}
if !self.supporting_info.is_empty() {
let mut items = Vec::with_capacity(self.supporting_info.len());
for item in &self.supporting_info {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("supportingInfo"),
super::super::codec::Value::Array(items),
);
}
if !self.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.patient_paid {
object.insert(
std::string::String::from("patientPaid"),
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_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_trace_number: 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_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_encounter: Option<&super::super::codec::Value> = None;
let mut raw_facility: Option<&super::super::codec::Value> = None;
let mut raw_diagnosis_related_group: Option<&super::super::codec::Value> = None;
let mut raw_event: Option<&super::super::codec::Value> = None;
let mut raw_care_team: Option<&super::super::codec::Value> = None;
let mut raw_supporting_info: 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_patient_paid: 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);
}
"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);
}
"traceNumber" => {
raw_trace_number = 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);
}
"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);
}
"encounter" => {
raw_encounter = Some(value);
}
"facility" => {
raw_facility = Some(value);
}
"diagnosisRelatedGroup" => {
raw_diagnosis_related_group = Some(value);
}
"event" => {
raw_event = Some(value);
}
"careTeam" => {
raw_care_team = Some(value);
}
"supportingInfo" => {
raw_supporting_info = Some(value);
}
"diagnosis" => {
raw_diagnosis = Some(value);
}
"procedure" => {
raw_procedure = Some(value);
}
"insurance" => {
raw_insurance = Some(value);
}
"accident" => {
raw_accident = Some(value);
}
"patientPaid" => {
raw_patient_paid = 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 = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_id(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_trace_number = Vec::new();
if let Some(raw) = raw_trace_number {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_trace_number.push(path.with_index("traceNumber", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
let field_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_sub_type = raw_sub_type
.map(|value| {
path.with("subType", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_use = path.with("use", |path| {
super::super::codec::Primitive::from_json_parts(raw_use, raw_use_element, path)
})?;
let field_patient = path.with("patient", |path| {
let value = raw_patient
.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_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 = path.with("created", |path| {
super::super::codec::Primitive::from_json_parts(raw_created, raw_created_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_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 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 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 field_diagnosis_related_group = raw_diagnosis_related_group
.map(|value| {
path.with("diagnosisRelatedGroup", |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_event = Vec::new();
if let Some(raw) = raw_event {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_event.push(path.with_index("event", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_care_team = Vec::new();
if let Some(raw) = raw_care_team {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_care_team.push(path.with_index("careTeam", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_supporting_info = Vec::new();
if let Some(raw) = raw_supporting_info {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_supporting_info.push(path.with_index("supportingInfo", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_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_patient_paid = raw_patient_paid
.map(|value| {
path.with("patientPaid", |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,
trace_number: field_trace_number,
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,
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,
encounter: field_encounter,
facility: field_facility,
diagnosis_related_group: field_diagnosis_related_group,
event: field_event,
care_team: field_care_team,
supporting_info: field_supporting_info,
diagnosis: field_diagnosis,
procedure: field_procedure,
insurance: field_insurance,
accident: field_accident,
patient_paid: field_patient_paid,
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)?;
super::super::codec::element_entry(&mut map, "_created", &self.created)?;
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
super::super::codec::element_entry(&mut map, "_use", &self.r#use)?;
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)?;
}
super::super::codec::value_entry(&mut map, "created", &self.created)?;
if !self.diagnosis.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "diagnosis", &self.diagnosis)?;
}
if let Some(item) = &self.diagnosis_related_group {
serde::ser::SerializeMap::serialize_entry(&mut map, "diagnosisRelatedGroup", item)?;
}
if !self.encounter.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", &self.encounter)?;
}
if let Some(item) = &self.enterer {
serde::ser::SerializeMap::serialize_entry(&mut map, "enterer", item)?;
}
if !self.event.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "event", &self.event)?;
}
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(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if !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.original_prescription {
serde::ser::SerializeMap::serialize_entry(&mut map, "originalPrescription", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "patient", &self.patient)?;
if let Some(item) = &self.patient_paid {
serde::ser::SerializeMap::serialize_entry(&mut map, "patientPaid", 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")?;
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if let Some(item) = &self.sub_type {
serde::ser::SerializeMap::serialize_entry(&mut map, "subType", item)?;
}
if !self.supporting_info.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"supportingInfo",
&self.supporting_info,
)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.total {
serde::ser::SerializeMap::serialize_entry(&mut map, "total", item)?;
}
if !self.trace_number.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "traceNumber", &self.trace_number)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
super::super::codec::value_entry(&mut map, "use", &self.r#use)?;
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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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 specialty: 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.specialty {
object.insert(
std::string::String::from("specialty"),
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_specialty: 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);
}
"specialty" => {
raw_specialty = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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_specialty = raw_specialty
.map(|value| {
path.with("specialty", |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,
specialty: field_specialty,
})
}
}
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.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)?;
if let Some(item) = &self.specialty {
serde::ser::SerializeMap::serialize_entry(&mut map, "specialty", item)?;
}
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 on_admission: 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.on_admission {
object.insert(
std::string::String::from("onAdmission"),
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_on_admission: 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);
}
"onAdmission" => {
raw_on_admission = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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_on_admission = raw_on_admission
.map(|value| {
path.with("onAdmission", |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,
on_admission: field_on_admission,
})
}
}
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.on_admission {
serde::ser::SerializeMap::serialize_entry(&mut map, "onAdmission", 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, PartialEq, Eq)]
pub struct ClaimEvent {
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 when: ClaimEventWhen,
}
impl super::super::codec::Json for ClaimEvent {
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)?),
);
let (suffix, value, element) = self.when.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("when{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_when{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_type: Option<&super::super::codec::Value> = None;
let mut raw_when = 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);
}
"type" => {
raw_type = Some(value);
}
"whenDateTime" => {
raw_when.value("DateTime", value, path)?;
}
"_whenDateTime" => {
raw_when.element("DateTime", value, path)?;
}
"whenPeriod" => {
raw_when.value("Period", value, path)?;
}
"_whenPeriod" => {
raw_when.element("Period", 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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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_when = path.with("when", |path| {
let suffix = raw_when
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
ClaimEventWhen::from_json_parts(suffix, raw_when.value, raw_when.element, path)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
when: field_when,
})
}
}
impl serde::Serialize for ClaimEvent {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let ClaimEventWhen::DateTime(inner) = &self.when {
super::super::codec::element_entry(&mut map, "_whenDateTime", inner)?;
}
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, "type", &self.r#type)?;
match &self.when {
ClaimEventWhen::DateTime(inner) => {
super::super::codec::value_entry(&mut map, "whenDateTime", inner)?;
}
ClaimEventWhen::Period(inner) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "whenPeriod", inner.as_ref())?;
}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimEvent {
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("ClaimEvent");
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 ClaimEventWhen {
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
}
impl ClaimEventWhen {
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::DateTime(inner) => Ok((
"DateTime",
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 {
"DateTime" => Ok(Self::DateTime(
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 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 identifier: Option<super::identifier::Identifier>,
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);
}
if let Some(item) = &self.identifier {
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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)?;
if let Some(values) = values {
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_identifier: 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);
}
"identifier" => {
raw_identifier = 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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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_identifier = raw_identifier
.map(|value| {
path.with("identifier", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_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,
identifier: field_identifier,
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 let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
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 trace_number: Vec<super::identifier::Identifier>,
pub care_team_sequence: Vec<super::primitives::PositiveInt>,
pub diagnosis_sequence: Vec<super::primitives::PositiveInt>,
pub procedure_sequence: Vec<super::primitives::PositiveInt>,
pub information_sequence: Vec<super::primitives::PositiveInt>,
pub revenue: Option<super::codeable_concept::CodeableConcept>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub product_or_service: Option<super::codeable_concept::CodeableConcept>,
pub product_or_service_end: Option<super::codeable_concept::CodeableConcept>,
pub request: Vec<super::reference::Reference>,
pub modifier: Vec<super::codeable_concept::CodeableConcept>,
pub program_code: Vec<super::codeable_concept::CodeableConcept>,
pub serviced: Option<ClaimItemServiced>,
pub location: Option<ClaimItemLocation>,
pub patient_paid: Option<super::money::Money>,
pub quantity: Option<super::quantity::Quantity>,
pub unit_price: Option<super::money::Money>,
pub factor: Option<super::primitives::Decimal>,
pub tax: Option<super::money::Money>,
pub net: Option<super::money::Money>,
pub udi: Vec<super::reference::Reference>,
pub body_site: Vec<ClaimItemBodySite>,
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.trace_number.is_empty() {
let mut items = Vec::with_capacity(self.trace_number.len());
for item in &self.trace_number {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("traceNumber"),
super::super::codec::Value::Array(items),
);
}
if !self.care_team_sequence.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.care_team_sequence)?;
if let Some(values) = values {
object.insert(std::string::String::from("careTeamSequence"), values);
}
if let Some(elements) = elements {
object.insert(std::string::String::from("_careTeamSequence"), elements);
}
}
if !self.diagnosis_sequence.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.diagnosis_sequence)?;
if let Some(values) = values {
object.insert(std::string::String::from("diagnosisSequence"), values);
}
if let Some(elements) = elements {
object.insert(std::string::String::from("_diagnosisSequence"), elements);
}
}
if !self.procedure_sequence.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.procedure_sequence)?;
if let Some(values) = values {
object.insert(std::string::String::from("procedureSequence"), values);
}
if let Some(elements) = elements {
object.insert(std::string::String::from("_procedureSequence"), elements);
}
}
if !self.information_sequence.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.information_sequence)?;
if let Some(values) = values {
object.insert(std::string::String::from("informationSequence"), values);
}
if let Some(elements) = elements {
object.insert(std::string::String::from("_informationSequence"), 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.product_or_service {
object.insert(
std::string::String::from("productOrService"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.product_or_service_end {
object.insert(
std::string::String::from("productOrServiceEnd"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.request.is_empty() {
let mut items = Vec::with_capacity(self.request.len());
for item in &self.request {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("request"),
super::super::codec::Value::Array(items),
);
}
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.patient_paid {
object.insert(
std::string::String::from("patientPaid"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.quantity {
object.insert(
std::string::String::from("quantity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.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.tax {
object.insert(
std::string::String::from("tax"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.body_site.is_empty() {
let mut items = Vec::with_capacity(self.body_site.len());
for item in &self.body_site {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("bodySite"),
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_trace_number: Option<&super::super::codec::Value> = None;
let mut raw_care_team_sequence: Option<&super::super::codec::Value> = None;
let mut raw_care_team_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_diagnosis_sequence: Option<&super::super::codec::Value> = None;
let mut raw_diagnosis_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_procedure_sequence: Option<&super::super::codec::Value> = None;
let mut raw_procedure_sequence_element: Option<&super::super::codec::Value> = None;
let mut raw_information_sequence: Option<&super::super::codec::Value> = None;
let mut raw_information_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_product_or_service: Option<&super::super::codec::Value> = None;
let mut raw_product_or_service_end: Option<&super::super::codec::Value> = None;
let mut raw_request: 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_patient_paid: 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_tax: 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_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);
}
"traceNumber" => {
raw_trace_number = Some(value);
}
"careTeamSequence" => {
raw_care_team_sequence = Some(value);
}
"_careTeamSequence" => {
raw_care_team_sequence_element = Some(value);
}
"diagnosisSequence" => {
raw_diagnosis_sequence = Some(value);
}
"_diagnosisSequence" => {
raw_diagnosis_sequence_element = Some(value);
}
"procedureSequence" => {
raw_procedure_sequence = Some(value);
}
"_procedureSequence" => {
raw_procedure_sequence_element = Some(value);
}
"informationSequence" => {
raw_information_sequence = Some(value);
}
"_informationSequence" => {
raw_information_sequence_element = Some(value);
}
"revenue" => {
raw_revenue = Some(value);
}
"category" => {
raw_category = Some(value);
}
"productOrService" => {
raw_product_or_service = Some(value);
}
"productOrServiceEnd" => {
raw_product_or_service_end = Some(value);
}
"request" => {
raw_request = 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)?;
}
"patientPaid" => {
raw_patient_paid = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"unitPrice" => {
raw_unit_price = Some(value);
}
"factor" => {
raw_factor = Some(value);
}
"_factor" => {
raw_factor_element = Some(value);
}
"tax" => {
raw_tax = Some(value);
}
"net" => {
raw_net = Some(value);
}
"udi" => {
raw_udi = Some(value);
}
"bodySite" => {
raw_body_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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let mut field_trace_number = Vec::new();
if let Some(raw) = raw_trace_number {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_trace_number.push(path.with_index("traceNumber", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_care_team_sequence = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_care_team_sequence,
raw_care_team_sequence_element,
path,
)?
.into_iter()
.enumerate()
{
field_care_team_sequence.push(path.with_index("careTeamSequence", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let mut field_diagnosis_sequence = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_diagnosis_sequence,
raw_diagnosis_sequence_element,
path,
)?
.into_iter()
.enumerate()
{
field_diagnosis_sequence.push(path.with_index("diagnosisSequence", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let mut field_procedure_sequence = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_procedure_sequence,
raw_procedure_sequence_element,
path,
)?
.into_iter()
.enumerate()
{
field_procedure_sequence.push(path.with_index("procedureSequence", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let mut field_information_sequence = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_information_sequence,
raw_information_sequence_element,
path,
)?
.into_iter()
.enumerate()
{
field_information_sequence.push(path.with_index(
"informationSequence",
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_product_or_service = raw_product_or_service
.map(|value| {
path.with("productOrService", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_product_or_service_end = raw_product_or_service_end
.map(|value| {
path.with("productOrServiceEnd", |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_request = Vec::new();
if let Some(raw) = raw_request {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_request.push(path.with_index("request", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
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_patient_paid = raw_patient_paid
.map(|value| {
path.with("patientPaid", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_quantity = raw_quantity
.map(|value| {
path.with("quantity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_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_tax = raw_tax
.map(|value| {
path.with("tax", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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_body_site = Vec::new();
if let Some(raw) = raw_body_site {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_body_site.push(path.with_index("bodySite", 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,
trace_number: field_trace_number,
care_team_sequence: field_care_team_sequence,
diagnosis_sequence: field_diagnosis_sequence,
procedure_sequence: field_procedure_sequence,
information_sequence: field_information_sequence,
revenue: field_revenue,
category: field_category,
product_or_service: field_product_or_service,
product_or_service_end: field_product_or_service_end,
request: field_request,
modifier: field_modifier,
program_code: field_program_code,
serviced: field_serviced,
location: field_location,
patient_paid: field_patient_paid,
quantity: field_quantity,
unit_price: field_unit_price,
factor: field_factor,
tax: field_tax,
net: field_net,
udi: field_udi,
body_site: field_body_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,
"_careTeamSequence",
&self.care_team_sequence,
)?;
super::super::codec::element_list_entry(
&mut map,
"_diagnosisSequence",
&self.diagnosis_sequence,
)?;
if let Some(item) = &self.factor {
super::super::codec::element_entry(&mut map, "_factor", item)?;
}
super::super::codec::element_list_entry(
&mut map,
"_informationSequence",
&self.information_sequence,
)?;
super::super::codec::element_list_entry(
&mut map,
"_procedureSequence",
&self.procedure_sequence,
)?;
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 !self.body_site.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "bodySite", &self.body_site)?;
}
super::super::codec::value_list_entry(
&mut map,
"careTeamSequence",
&self.care_team_sequence,
)?;
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,
"diagnosisSequence",
&self.diagnosis_sequence,
)?;
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,
"informationSequence",
&self.information_sequence,
)?;
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)?;
}
if let Some(item) = &self.patient_paid {
serde::ser::SerializeMap::serialize_entry(&mut map, "patientPaid", item)?;
}
super::super::codec::value_list_entry(
&mut map,
"procedureSequence",
&self.procedure_sequence,
)?;
if let Some(item) = &self.product_or_service {
serde::ser::SerializeMap::serialize_entry(&mut map, "productOrService", item)?;
}
if let Some(item) = &self.product_or_service_end {
serde::ser::SerializeMap::serialize_entry(&mut map, "productOrServiceEnd", 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 !self.request.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "request", &self.request)?;
}
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)?;
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 let Some(item) = &self.tax {
serde::ser::SerializeMap::serialize_entry(&mut map, "tax", item)?;
}
if !self.trace_number.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "traceNumber", &self.trace_number)?;
}
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 ClaimItemBodySite {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub site: Vec<super::codeable_reference::CodeableReference>,
pub sub_site: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ClaimItemBodySite {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.site.is_empty() {
let mut items = Vec::with_capacity(self.site.len());
for item in &self.site {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("site"),
super::super::codec::Value::Array(items),
);
}
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),
);
}
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_site: Option<&super::super::codec::Value> = None;
let mut raw_sub_site: 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);
}
"site" => {
raw_site = Some(value);
}
"subSite" => {
raw_sub_site = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_site = Vec::new();
if let Some(raw) = raw_site {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_site.push(path.with_index("site", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
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,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
site: field_site,
sub_site: field_sub_site,
})
}
}
impl serde::Serialize for ClaimItemBodySite {
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 !self.site.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "site", &self.site)?;
}
if !self.sub_site.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "subSite", &self.sub_site)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimItemBodySite {
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("ClaimItemBodySite");
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 trace_number: Vec<super::identifier::Identifier>,
pub revenue: Option<super::codeable_concept::CodeableConcept>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub product_or_service: Option<super::codeable_concept::CodeableConcept>,
pub product_or_service_end: Option<super::codeable_concept::CodeableConcept>,
pub modifier: Vec<super::codeable_concept::CodeableConcept>,
pub program_code: Vec<super::codeable_concept::CodeableConcept>,
pub patient_paid: Option<super::money::Money>,
pub quantity: Option<super::quantity::Quantity>,
pub unit_price: Option<super::money::Money>,
pub factor: Option<super::primitives::Decimal>,
pub tax: Option<super::money::Money>,
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 !self.trace_number.is_empty() {
let mut items = Vec::with_capacity(self.trace_number.len());
for item in &self.trace_number {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("traceNumber"),
super::super::codec::Value::Array(items),
);
}
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.product_or_service {
object.insert(
std::string::String::from("productOrService"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.product_or_service_end {
object.insert(
std::string::String::from("productOrServiceEnd"),
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.patient_paid {
object.insert(
std::string::String::from("patientPaid"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.quantity {
object.insert(
std::string::String::from("quantity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.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.tax {
object.insert(
std::string::String::from("tax"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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_trace_number: 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_product_or_service: Option<&super::super::codec::Value> = None;
let mut raw_product_or_service_end: 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_patient_paid: 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_tax: 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);
}
"traceNumber" => {
raw_trace_number = Some(value);
}
"revenue" => {
raw_revenue = Some(value);
}
"category" => {
raw_category = Some(value);
}
"productOrService" => {
raw_product_or_service = Some(value);
}
"productOrServiceEnd" => {
raw_product_or_service_end = Some(value);
}
"modifier" => {
raw_modifier = Some(value);
}
"programCode" => {
raw_program_code = Some(value);
}
"patientPaid" => {
raw_patient_paid = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"unitPrice" => {
raw_unit_price = Some(value);
}
"factor" => {
raw_factor = Some(value);
}
"_factor" => {
raw_factor_element = Some(value);
}
"tax" => {
raw_tax = 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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let mut field_trace_number = Vec::new();
if let Some(raw) = raw_trace_number {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_trace_number.push(path.with_index("traceNumber", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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_product_or_service = raw_product_or_service
.map(|value| {
path.with("productOrService", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_product_or_service_end = raw_product_or_service_end
.map(|value| {
path.with("productOrServiceEnd", |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_patient_paid = raw_patient_paid
.map(|value| {
path.with("patientPaid", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_quantity = raw_quantity
.map(|value| {
path.with("quantity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_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_tax = raw_tax
.map(|value| {
path.with("tax", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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,
trace_number: field_trace_number,
revenue: field_revenue,
category: field_category,
product_or_service: field_product_or_service,
product_or_service_end: field_product_or_service_end,
modifier: field_modifier,
program_code: field_program_code,
patient_paid: field_patient_paid,
quantity: field_quantity,
unit_price: field_unit_price,
factor: field_factor,
tax: field_tax,
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 let Some(item) = &self.patient_paid {
serde::ser::SerializeMap::serialize_entry(&mut map, "patientPaid", item)?;
}
if let Some(item) = &self.product_or_service {
serde::ser::SerializeMap::serialize_entry(&mut map, "productOrService", item)?;
}
if let Some(item) = &self.product_or_service_end {
serde::ser::SerializeMap::serialize_entry(&mut map, "productOrServiceEnd", 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 !self.sub_detail.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "subDetail", &self.sub_detail)?;
}
if let Some(item) = &self.tax {
serde::ser::SerializeMap::serialize_entry(&mut map, "tax", item)?;
}
if !self.trace_number.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "traceNumber", &self.trace_number)?;
}
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 trace_number: Vec<super::identifier::Identifier>,
pub revenue: Option<super::codeable_concept::CodeableConcept>,
pub category: Option<super::codeable_concept::CodeableConcept>,
pub product_or_service: Option<super::codeable_concept::CodeableConcept>,
pub product_or_service_end: Option<super::codeable_concept::CodeableConcept>,
pub modifier: Vec<super::codeable_concept::CodeableConcept>,
pub program_code: Vec<super::codeable_concept::CodeableConcept>,
pub patient_paid: Option<super::money::Money>,
pub quantity: Option<super::quantity::Quantity>,
pub unit_price: Option<super::money::Money>,
pub factor: Option<super::primitives::Decimal>,
pub tax: Option<super::money::Money>,
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 !self.trace_number.is_empty() {
let mut items = Vec::with_capacity(self.trace_number.len());
for item in &self.trace_number {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("traceNumber"),
super::super::codec::Value::Array(items),
);
}
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.product_or_service {
object.insert(
std::string::String::from("productOrService"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.product_or_service_end {
object.insert(
std::string::String::from("productOrServiceEnd"),
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.patient_paid {
object.insert(
std::string::String::from("patientPaid"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.quantity {
object.insert(
std::string::String::from("quantity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.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.tax {
object.insert(
std::string::String::from("tax"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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_trace_number: 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_product_or_service: Option<&super::super::codec::Value> = None;
let mut raw_product_or_service_end: 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_patient_paid: 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_tax: 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);
}
"traceNumber" => {
raw_trace_number = Some(value);
}
"revenue" => {
raw_revenue = Some(value);
}
"category" => {
raw_category = Some(value);
}
"productOrService" => {
raw_product_or_service = Some(value);
}
"productOrServiceEnd" => {
raw_product_or_service_end = Some(value);
}
"modifier" => {
raw_modifier = Some(value);
}
"programCode" => {
raw_program_code = Some(value);
}
"patientPaid" => {
raw_patient_paid = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"unitPrice" => {
raw_unit_price = Some(value);
}
"factor" => {
raw_factor = Some(value);
}
"_factor" => {
raw_factor_element = Some(value);
}
"tax" => {
raw_tax = 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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_element,
path,
)
})?;
let mut field_trace_number = Vec::new();
if let Some(raw) = raw_trace_number {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_trace_number.push(path.with_index("traceNumber", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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_product_or_service = raw_product_or_service
.map(|value| {
path.with("productOrService", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_product_or_service_end = raw_product_or_service_end
.map(|value| {
path.with("productOrServiceEnd", |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_patient_paid = raw_patient_paid
.map(|value| {
path.with("patientPaid", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_quantity = raw_quantity
.map(|value| {
path.with("quantity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_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_tax = raw_tax
.map(|value| {
path.with("tax", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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,
trace_number: field_trace_number,
revenue: field_revenue,
category: field_category,
product_or_service: field_product_or_service,
product_or_service_end: field_product_or_service_end,
modifier: field_modifier,
program_code: field_program_code,
patient_paid: field_patient_paid,
quantity: field_quantity,
unit_price: field_unit_price,
factor: field_factor,
tax: field_tax,
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 let Some(item) = &self.patient_paid {
serde::ser::SerializeMap::serialize_entry(&mut map, "patientPaid", item)?;
}
if let Some(item) = &self.product_or_service {
serde::ser::SerializeMap::serialize_entry(&mut map, "productOrService", item)?;
}
if let Some(item) = &self.product_or_service_end {
serde::ser::SerializeMap::serialize_entry(&mut map, "productOrServiceEnd", 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.tax {
serde::ser::SerializeMap::serialize_entry(&mut map, "tax", item)?;
}
if !self.trace_number.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "traceNumber", &self.trace_number)?;
}
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 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.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_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);
}
"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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_type = path.with("type", |path| {
let value = raw_type
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_party = 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,
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)?;
}
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 r#type: Vec<super::codeable_concept::CodeableConcept>,
pub date: Option<super::primitives::DateTime>,
pub procedure: ClaimProcedureProcedure,
pub udi: Vec<super::reference::Reference>,
}
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 !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.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);
}
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_type: 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();
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);
}
"type" => {
raw_type = 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)?;
}
"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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_sequence = path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(
raw_sequence,
raw_sequence_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_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,
)
})?;
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,
r#type: field_type,
date: field_date,
procedure: field_procedure,
udi: field_udi,
})
}
}
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)?;
if !self.r#type.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
}
if !self.udi.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "udi", &self.udi)?;
}
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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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)
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ClaimSupportingInfo {
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<ClaimSupportingInfoTiming>,
pub value: Option<ClaimSupportingInfoValue>,
pub reason: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for ClaimSupportingInfo {
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)?;
}
"valueBoolean" => {
raw_value.value("Boolean", value, path)?;
}
"_valueBoolean" => {
raw_value.element("Boolean", 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)?;
}
"valueIdentifier" => {
raw_value.value("Identifier", value, path)?;
}
"_valueIdentifier" => {
raw_value.element("Identifier", 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::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_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| {
ClaimSupportingInfoTiming::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| {
ClaimSupportingInfoValue::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 ClaimSupportingInfo {
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(ClaimSupportingInfoTiming::Date(inner)) = &self.timing {
super::super::codec::element_entry(&mut map, "_timingDate", inner)?;
}
match &self.value {
Some(ClaimSupportingInfoValue::Boolean(inner)) => {
super::super::codec::element_entry(&mut map, "_valueBoolean", inner)?;
}
Some(ClaimSupportingInfoValue::String(inner)) => {
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(ClaimSupportingInfoTiming::Date(inner)) => {
super::super::codec::value_entry(&mut map, "timingDate", inner)?;
}
Some(ClaimSupportingInfoTiming::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"timingPeriod",
inner.as_ref(),
)?;
}
None => {}
}
match &self.value {
Some(ClaimSupportingInfoValue::Attachment(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueAttachment",
inner.as_ref(),
)?;
}
Some(ClaimSupportingInfoValue::Boolean(inner)) => {
super::super::codec::value_entry(&mut map, "valueBoolean", inner)?;
}
Some(ClaimSupportingInfoValue::Identifier(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueIdentifier",
inner.as_ref(),
)?;
}
Some(ClaimSupportingInfoValue::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueQuantity",
inner.as_ref(),
)?;
}
Some(ClaimSupportingInfoValue::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueReference",
inner.as_ref(),
)?;
}
Some(ClaimSupportingInfoValue::String(inner)) => {
super::super::codec::value_entry(&mut map, "valueString", inner)?;
}
None => {}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ClaimSupportingInfo {
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("ClaimSupportingInfo");
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 ClaimSupportingInfoTiming {
Date(super::primitives::Date),
Period(Box<super::period::Period>),
}
impl ClaimSupportingInfoTiming {
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 ClaimSupportingInfoValue {
Boolean(super::primitives::Boolean),
String(super::primitives::String),
Quantity(Box<super::quantity::Quantity>),
Attachment(Box<super::attachment::Attachment>),
Reference(Box<super::reference::Reference>),
Identifier(Box<super::identifier::Identifier>),
}
impl ClaimSupportingInfoValue {
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::Boolean(inner) => Ok((
"Boolean",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
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,
)),
Self::Identifier(inner) => Ok((
"Identifier",
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 {
"Boolean" => Ok(Self::Boolean(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"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)))
}
"Identifier" => {
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::Identifier(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}