#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct EligibilityRequest {
pub id: Option<super::primitives::Id>,
pub meta: Option<super::meta::Meta>,
pub implicit_rules: Option<super::primitives::Uri>,
pub language: Option<super::primitives::Code>,
pub text: Option<super::narrative::Narrative>,
pub contained: Vec<super::resource::Resource>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Vec<super::identifier::Identifier>,
pub status: Option<super::primitives::Code>,
pub priority: Option<super::codeable_concept::CodeableConcept>,
pub patient: Option<super::reference::Reference>,
pub serviced: Option<EligibilityRequestServiced>,
pub created: Option<super::primitives::DateTime>,
pub enterer: Option<super::reference::Reference>,
pub provider: Option<super::reference::Reference>,
pub organization: Option<super::reference::Reference>,
pub insurer: Option<super::reference::Reference>,
pub facility: Option<super::reference::Reference>,
pub coverage: Option<super::reference::Reference>,
pub business_arrangement: Option<super::primitives::String>,
pub benefit_category: Option<super::codeable_concept::CodeableConcept>,
pub benefit_sub_category: Option<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for EligibilityRequest {
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("EligibilityRequest")),
);
if let Some(item) = &self.id {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("id"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_id"), e);
}
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.status {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("status"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_status"), e);
}
}
if let Some(item) = &self.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.patient {
object.insert(
std::string::String::from("patient"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.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.created {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("created"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_created"), e);
}
}
if let Some(item) = &self.enterer {
object.insert(
std::string::String::from("enterer"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.provider {
object.insert(
std::string::String::from("provider"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.organization {
object.insert(
std::string::String::from("organization"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.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.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.coverage {
object.insert(
std::string::String::from("coverage"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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 let Some(item) = &self.benefit_category {
object.insert(
std::string::String::from("benefitCategory"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.benefit_sub_category {
object.insert(
std::string::String::from("benefitSubCategory"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_id_element: Option<&super::super::codec::Value> = None;
let mut raw_meta: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_language_element: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_contained: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_status: Option<&super::super::codec::Value> = None;
let mut raw_status_element: Option<&super::super::codec::Value> = None;
let mut raw_priority: Option<&super::super::codec::Value> = None;
let mut raw_patient: Option<&super::super::codec::Value> = None;
let mut raw_serviced = super::super::codec::ChoiceSlot::default();
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_provider: Option<&super::super::codec::Value> = None;
let mut raw_organization: Option<&super::super::codec::Value> = None;
let mut raw_insurer: Option<&super::super::codec::Value> = None;
let mut raw_facility: 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_benefit_category: Option<&super::super::codec::Value> = None;
let mut raw_benefit_sub_category: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("EligibilityRequest") {
return Err(path.error(super::super::codec::DecodeErrorKind::ResourceType));
}
}
"id" => {
raw_id = Some(value);
}
"_id" => {
raw_id_element = Some(value);
}
"meta" => {
raw_meta = Some(value);
}
"implicitRules" => {
raw_implicit_rules = Some(value);
}
"_implicitRules" => {
raw_implicit_rules_element = Some(value);
}
"language" => {
raw_language = Some(value);
}
"_language" => {
raw_language_element = Some(value);
}
"text" => {
raw_text = Some(value);
}
"contained" => {
raw_contained = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"identifier" => {
raw_identifier = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"priority" => {
raw_priority = Some(value);
}
"patient" => {
raw_patient = 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)?;
}
"created" => {
raw_created = Some(value);
}
"_created" => {
raw_created_element = Some(value);
}
"enterer" => {
raw_enterer = Some(value);
}
"provider" => {
raw_provider = Some(value);
}
"organization" => {
raw_organization = Some(value);
}
"insurer" => {
raw_insurer = Some(value);
}
"facility" => {
raw_facility = Some(value);
}
"coverage" => {
raw_coverage = Some(value);
}
"businessArrangement" => {
raw_business_arrangement = Some(value);
}
"_businessArrangement" => {
raw_business_arrangement_element = Some(value);
}
"benefitCategory" => {
raw_benefit_category = Some(value);
}
"benefitSubCategory" => {
raw_benefit_sub_category = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = match (raw_id, raw_id_element) {
(None, None) => None,
(value, element) => Some(path.with("id", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_status = match (raw_status, raw_status_element) {
(None, None) => None,
(value, element) => Some(path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_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_patient = raw_patient
.map(|value| {
path.with("patient", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_serviced = match raw_serviced.suffix {
None => None,
Some(suffix) => Some(path.with("serviced", |path| {
EligibilityRequestServiced::from_json_parts(
suffix,
raw_serviced.value,
raw_serviced.element,
path,
)
})?),
};
let field_created = match (raw_created, raw_created_element) {
(None, None) => None,
(value, element) => Some(path.with("created", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_enterer = raw_enterer
.map(|value| {
path.with("enterer", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_provider = raw_provider
.map(|value| {
path.with("provider", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_organization = raw_organization
.map(|value| {
path.with("organization", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_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_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_coverage = raw_coverage
.map(|value| {
path.with("coverage", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
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 field_benefit_category = raw_benefit_category
.map(|value| {
path.with("benefitCategory", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_benefit_sub_category = raw_benefit_sub_category
.map(|value| {
path.with("benefitSubCategory", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
meta: field_meta,
implicit_rules: field_implicit_rules,
language: field_language,
text: field_text,
contained: field_contained,
extension: field_extension,
modifier_extension: field_modifier_extension,
identifier: field_identifier,
status: field_status,
priority: field_priority,
patient: field_patient,
serviced: field_serviced,
created: field_created,
enterer: field_enterer,
provider: field_provider,
organization: field_organization,
insurer: field_insurer,
facility: field_facility,
coverage: field_coverage,
business_arrangement: field_business_arrangement,
benefit_category: field_benefit_category,
benefit_sub_category: field_benefit_sub_category,
})
}
}
impl serde::Serialize for EligibilityRequest {
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)?;
}
if let Some(item) = &self.created {
super::super::codec::element_entry(&mut map, "_created", item)?;
}
if let Some(item) = &self.id {
super::super::codec::element_entry(&mut map, "_id", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(EligibilityRequestServiced::Date(inner)) = &self.serviced {
super::super::codec::element_entry(&mut map, "_servicedDate", inner)?;
}
if let Some(item) = &self.status {
super::super::codec::element_entry(&mut map, "_status", item)?;
}
if let Some(item) = &self.benefit_category {
serde::ser::SerializeMap::serialize_entry(&mut map, "benefitCategory", item)?;
}
if let Some(item) = &self.benefit_sub_category {
serde::ser::SerializeMap::serialize_entry(&mut map, "benefitSubCategory", item)?;
}
if let Some(item) = &self.business_arrangement {
super::super::codec::value_entry(&mut map, "businessArrangement", item)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.coverage {
serde::ser::SerializeMap::serialize_entry(&mut map, "coverage", item)?;
}
if let Some(item) = &self.created {
super::super::codec::value_entry(&mut map, "created", item)?;
}
if let Some(item) = &self.enterer {
serde::ser::SerializeMap::serialize_entry(&mut map, "enterer", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.facility {
serde::ser::SerializeMap::serialize_entry(&mut map, "facility", item)?;
}
if let Some(item) = &self.id {
super::super::codec::value_entry(&mut map, "id", item)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.insurer {
serde::ser::SerializeMap::serialize_entry(&mut map, "insurer", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.meta {
serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.organization {
serde::ser::SerializeMap::serialize_entry(&mut map, "organization", item)?;
}
if let Some(item) = &self.patient {
serde::ser::SerializeMap::serialize_entry(&mut map, "patient", item)?;
}
if let Some(item) = &self.priority {
serde::ser::SerializeMap::serialize_entry(&mut map, "priority", item)?;
}
if let Some(item) = &self.provider {
serde::ser::SerializeMap::serialize_entry(&mut map, "provider", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "EligibilityRequest")?;
match &self.serviced {
Some(EligibilityRequestServiced::Date(inner)) => {
super::super::codec::value_entry(&mut map, "servicedDate", inner)?;
}
Some(EligibilityRequestServiced::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"servicedPeriod",
inner.as_ref(),
)?;
}
None => {}
}
if let Some(item) = &self.status {
super::super::codec::value_entry(&mut map, "status", item)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for EligibilityRequest {
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("EligibilityRequest");
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 EligibilityRequestServiced {
Date(super::primitives::Date),
Period(Box<super::period::Period>),
}
impl EligibilityRequestServiced {
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)),
}
}
}