#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct HealthcareService {
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 active: Option<super::primitives::Boolean>,
pub provided_by: Option<super::reference::Reference>,
pub offered_in: Vec<super::reference::Reference>,
pub category: Vec<super::codeable_concept::CodeableConcept>,
pub r#type: Vec<super::codeable_concept::CodeableConcept>,
pub specialty: Vec<super::codeable_concept::CodeableConcept>,
pub location: Vec<super::reference::Reference>,
pub name: Option<super::primitives::String>,
pub comment: Option<super::primitives::Markdown>,
pub extra_details: Option<super::primitives::Markdown>,
pub photo: Option<super::attachment::Attachment>,
pub contact: Vec<super::extended_contact_detail::ExtendedContactDetail>,
pub coverage_area: Vec<super::reference::Reference>,
pub service_provision_code: Vec<super::codeable_concept::CodeableConcept>,
pub eligibility: Vec<HealthcareServiceEligibility>,
pub program: Vec<super::codeable_concept::CodeableConcept>,
pub characteristic: Vec<super::codeable_concept::CodeableConcept>,
pub communication: Vec<super::codeable_concept::CodeableConcept>,
pub referral_method: Vec<super::codeable_concept::CodeableConcept>,
pub referral_required: Option<super::primitives::Boolean>,
pub appointment_required: Option<super::primitives::Boolean>,
pub availability: Option<super::availability::Availability>,
pub endpoint: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for HealthcareService {
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("HealthcareService")),
);
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.active {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("active"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_active"), e);
}
}
if let Some(item) = &self.provided_by {
object.insert(
std::string::String::from("providedBy"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.offered_in.is_empty() {
let mut items = Vec::with_capacity(self.offered_in.len());
for item in &self.offered_in {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("offeredIn"),
super::super::codec::Value::Array(items),
);
}
if !self.category.is_empty() {
let mut items = Vec::with_capacity(self.category.len());
for item in &self.category {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Array(items),
);
}
if !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 !self.specialty.is_empty() {
let mut items = Vec::with_capacity(self.specialty.len());
for item in &self.specialty {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("specialty"),
super::super::codec::Value::Array(items),
);
}
if !self.location.is_empty() {
let mut items = Vec::with_capacity(self.location.len());
for item in &self.location {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("location"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.name {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_name"), e);
}
}
if let Some(item) = &self.comment {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("comment"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_comment"), e);
}
}
if let Some(item) = &self.extra_details {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("extraDetails"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_extraDetails"), e);
}
}
if let Some(item) = &self.photo {
object.insert(
std::string::String::from("photo"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contact.is_empty() {
let mut items = Vec::with_capacity(self.contact.len());
for item in &self.contact {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contact"),
super::super::codec::Value::Array(items),
);
}
if !self.coverage_area.is_empty() {
let mut items = Vec::with_capacity(self.coverage_area.len());
for item in &self.coverage_area {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("coverageArea"),
super::super::codec::Value::Array(items),
);
}
if !self.service_provision_code.is_empty() {
let mut items = Vec::with_capacity(self.service_provision_code.len());
for item in &self.service_provision_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("serviceProvisionCode"),
super::super::codec::Value::Array(items),
);
}
if !self.eligibility.is_empty() {
let mut items = Vec::with_capacity(self.eligibility.len());
for item in &self.eligibility {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("eligibility"),
super::super::codec::Value::Array(items),
);
}
if !self.program.is_empty() {
let mut items = Vec::with_capacity(self.program.len());
for item in &self.program {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("program"),
super::super::codec::Value::Array(items),
);
}
if !self.characteristic.is_empty() {
let mut items = Vec::with_capacity(self.characteristic.len());
for item in &self.characteristic {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("characteristic"),
super::super::codec::Value::Array(items),
);
}
if !self.communication.is_empty() {
let mut items = Vec::with_capacity(self.communication.len());
for item in &self.communication {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("communication"),
super::super::codec::Value::Array(items),
);
}
if !self.referral_method.is_empty() {
let mut items = Vec::with_capacity(self.referral_method.len());
for item in &self.referral_method {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("referralMethod"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.referral_required {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("referralRequired"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_referralRequired"), e);
}
}
if let Some(item) = &self.appointment_required {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("appointmentRequired"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_appointmentRequired"), e);
}
}
if let Some(item) = &self.availability {
object.insert(
std::string::String::from("availability"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.endpoint.is_empty() {
let mut items = Vec::with_capacity(self.endpoint.len());
for item in &self.endpoint {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("endpoint"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_meta: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_language_element: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_contained: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_active: Option<&super::super::codec::Value> = None;
let mut raw_active_element: Option<&super::super::codec::Value> = None;
let mut raw_provided_by: Option<&super::super::codec::Value> = None;
let mut raw_offered_in: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_specialty: Option<&super::super::codec::Value> = None;
let mut raw_location: Option<&super::super::codec::Value> = None;
let mut raw_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: Option<&super::super::codec::Value> = None;
let mut raw_comment: Option<&super::super::codec::Value> = None;
let mut raw_comment_element: Option<&super::super::codec::Value> = None;
let mut raw_extra_details: Option<&super::super::codec::Value> = None;
let mut raw_extra_details_element: Option<&super::super::codec::Value> = None;
let mut raw_photo: Option<&super::super::codec::Value> = None;
let mut raw_contact: Option<&super::super::codec::Value> = None;
let mut raw_coverage_area: Option<&super::super::codec::Value> = None;
let mut raw_service_provision_code: Option<&super::super::codec::Value> = None;
let mut raw_eligibility: Option<&super::super::codec::Value> = None;
let mut raw_program: Option<&super::super::codec::Value> = None;
let mut raw_characteristic: Option<&super::super::codec::Value> = None;
let mut raw_communication: Option<&super::super::codec::Value> = None;
let mut raw_referral_method: Option<&super::super::codec::Value> = None;
let mut raw_referral_required: Option<&super::super::codec::Value> = None;
let mut raw_referral_required_element: Option<&super::super::codec::Value> = None;
let mut raw_appointment_required: Option<&super::super::codec::Value> = None;
let mut raw_appointment_required_element: Option<&super::super::codec::Value> = None;
let mut raw_availability: Option<&super::super::codec::Value> = None;
let mut raw_endpoint: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("HealthcareService") {
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);
}
"active" => {
raw_active = Some(value);
}
"_active" => {
raw_active_element = Some(value);
}
"providedBy" => {
raw_provided_by = Some(value);
}
"offeredIn" => {
raw_offered_in = Some(value);
}
"category" => {
raw_category = Some(value);
}
"type" => {
raw_type = Some(value);
}
"specialty" => {
raw_specialty = Some(value);
}
"location" => {
raw_location = Some(value);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"comment" => {
raw_comment = Some(value);
}
"_comment" => {
raw_comment_element = Some(value);
}
"extraDetails" => {
raw_extra_details = Some(value);
}
"_extraDetails" => {
raw_extra_details_element = Some(value);
}
"photo" => {
raw_photo = Some(value);
}
"contact" => {
raw_contact = Some(value);
}
"coverageArea" => {
raw_coverage_area = Some(value);
}
"serviceProvisionCode" => {
raw_service_provision_code = Some(value);
}
"eligibility" => {
raw_eligibility = Some(value);
}
"program" => {
raw_program = Some(value);
}
"characteristic" => {
raw_characteristic = Some(value);
}
"communication" => {
raw_communication = Some(value);
}
"referralMethod" => {
raw_referral_method = Some(value);
}
"referralRequired" => {
raw_referral_required = Some(value);
}
"_referralRequired" => {
raw_referral_required_element = Some(value);
}
"appointmentRequired" => {
raw_appointment_required = Some(value);
}
"_appointmentRequired" => {
raw_appointment_required_element = Some(value);
}
"availability" => {
raw_availability = Some(value);
}
"endpoint" => {
raw_endpoint = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_active = match (raw_active, raw_active_element) {
(None, None) => None,
(value, element) => Some(path.with("active", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_provided_by = raw_provided_by
.map(|value| {
path.with("providedBy", |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_offered_in = Vec::new();
if let Some(raw) = raw_offered_in {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_offered_in.push(path.with_index("offeredIn", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_category = Vec::new();
if let Some(raw) = raw_category {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_category.push(path.with_index("category", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let 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 mut field_specialty = Vec::new();
if let Some(raw) = raw_specialty {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_specialty.push(path.with_index("specialty", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_location = Vec::new();
if let Some(raw) = raw_location {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_location.push(path.with_index("location", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_name = match (raw_name, raw_name_element) {
(None, None) => None,
(value, element) => Some(path.with("name", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_comment = match (raw_comment, raw_comment_element) {
(None, None) => None,
(value, element) => Some(path.with("comment", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_extra_details = match (raw_extra_details, raw_extra_details_element) {
(None, None) => None,
(value, element) => Some(path.with("extraDetails", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_photo = raw_photo
.map(|value| {
path.with("photo", |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_contact = Vec::new();
if let Some(raw) = raw_contact {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contact.push(path.with_index("contact", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_coverage_area = Vec::new();
if let Some(raw) = raw_coverage_area {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_coverage_area.push(path.with_index("coverageArea", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_service_provision_code = Vec::new();
if let Some(raw) = raw_service_provision_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_service_provision_code.push(path.with_index(
"serviceProvisionCode",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_eligibility = Vec::new();
if let Some(raw) = raw_eligibility {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_eligibility.push(path.with_index("eligibility", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_program = Vec::new();
if let Some(raw) = raw_program {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_program.push(path.with_index("program", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_characteristic = Vec::new();
if let Some(raw) = raw_characteristic {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_characteristic.push(path.with_index("characteristic", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_communication = Vec::new();
if let Some(raw) = raw_communication {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_communication.push(path.with_index("communication", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_referral_method = Vec::new();
if let Some(raw) = raw_referral_method {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_referral_method.push(path.with_index("referralMethod", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_referral_required = match (raw_referral_required, raw_referral_required_element) {
(None, None) => None,
(value, element) => Some(path.with("referralRequired", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_appointment_required =
match (raw_appointment_required, raw_appointment_required_element) {
(None, None) => None,
(value, element) => Some(path.with("appointmentRequired", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_availability = raw_availability
.map(|value| {
path.with("availability", |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_endpoint = Vec::new();
if let Some(raw) = raw_endpoint {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_endpoint.push(path.with_index("endpoint", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
meta: field_meta,
implicit_rules: field_implicit_rules,
language: field_language,
text: field_text,
contained: field_contained,
extension: field_extension,
modifier_extension: field_modifier_extension,
identifier: field_identifier,
active: field_active,
provided_by: field_provided_by,
offered_in: field_offered_in,
category: field_category,
r#type: field_type,
specialty: field_specialty,
location: field_location,
name: field_name,
comment: field_comment,
extra_details: field_extra_details,
photo: field_photo,
contact: field_contact,
coverage_area: field_coverage_area,
service_provision_code: field_service_provision_code,
eligibility: field_eligibility,
program: field_program,
characteristic: field_characteristic,
communication: field_communication,
referral_method: field_referral_method,
referral_required: field_referral_required,
appointment_required: field_appointment_required,
availability: field_availability,
endpoint: field_endpoint,
})
}
}
impl serde::Serialize for HealthcareService {
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.active {
super::super::codec::element_entry(&mut map, "_active", item)?;
}
if let Some(item) = &self.appointment_required {
super::super::codec::element_entry(&mut map, "_appointmentRequired", item)?;
}
if let Some(item) = &self.comment {
super::super::codec::element_entry(&mut map, "_comment", item)?;
}
if let Some(item) = &self.extra_details {
super::super::codec::element_entry(&mut map, "_extraDetails", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(item) = &self.name {
super::super::codec::element_entry(&mut map, "_name", item)?;
}
if let Some(item) = &self.referral_required {
super::super::codec::element_entry(&mut map, "_referralRequired", item)?;
}
if let Some(item) = &self.active {
super::super::codec::value_entry(&mut map, "active", item)?;
}
if let Some(item) = &self.appointment_required {
super::super::codec::value_entry(&mut map, "appointmentRequired", item)?;
}
if let Some(item) = &self.availability {
serde::ser::SerializeMap::serialize_entry(&mut map, "availability", item)?;
}
if !self.category.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
}
if !self.characteristic.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"characteristic",
&self.characteristic,
)?;
}
if let Some(item) = &self.comment {
super::super::codec::value_entry(&mut map, "comment", item)?;
}
if !self.communication.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"communication",
&self.communication,
)?;
}
if !self.contact.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contact", &self.contact)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if !self.coverage_area.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"coverageArea",
&self.coverage_area,
)?;
}
if !self.eligibility.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "eligibility", &self.eligibility)?;
}
if !self.endpoint.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "endpoint", &self.endpoint)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.extra_details {
super::super::codec::value_entry(&mut map, "extraDetails", 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 let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if !self.location.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "location", &self.location)?;
}
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.name {
super::super::codec::value_entry(&mut map, "name", item)?;
}
if !self.offered_in.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "offeredIn", &self.offered_in)?;
}
if let Some(item) = &self.photo {
serde::ser::SerializeMap::serialize_entry(&mut map, "photo", item)?;
}
if !self.program.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "program", &self.program)?;
}
if let Some(item) = &self.provided_by {
serde::ser::SerializeMap::serialize_entry(&mut map, "providedBy", item)?;
}
if !self.referral_method.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"referralMethod",
&self.referral_method,
)?;
}
if let Some(item) = &self.referral_required {
super::super::codec::value_entry(&mut map, "referralRequired", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "HealthcareService")?;
if !self.service_provision_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"serviceProvisionCode",
&self.service_provision_code,
)?;
}
if !self.specialty.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "specialty", &self.specialty)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
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 HealthcareService {
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("HealthcareService");
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 HealthcareServiceEligibility {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub value: Option<HealthcareServiceEligibilityValue>,
pub comment: Option<super::primitives::Markdown>,
pub period: Option<super::period::Period>,
}
impl super::super::codec::Json for HealthcareServiceEligibility {
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.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.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.comment {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("comment"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_comment"), e);
}
}
if let Some(item) = &self.period {
object.insert(
std::string::String::from("period"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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_code: Option<&super::super::codec::Value> = None;
let mut raw_value = super::super::codec::ChoiceSlot::default();
let mut raw_comment: Option<&super::super::codec::Value> = None;
let mut raw_comment_element: Option<&super::super::codec::Value> = None;
let mut raw_period: 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);
}
"code" => {
raw_code = Some(value);
}
"valueCodeableConcept" => {
raw_value.value("CodeableConcept", value, path)?;
}
"_valueCodeableConcept" => {
raw_value.element("CodeableConcept", value, path)?;
}
"valueBoolean" => {
raw_value.value("Boolean", value, path)?;
}
"_valueBoolean" => {
raw_value.element("Boolean", value, path)?;
}
"valueQuantity" => {
raw_value.value("Quantity", value, path)?;
}
"_valueQuantity" => {
raw_value.element("Quantity", value, path)?;
}
"valueRange" => {
raw_value.value("Range", value, path)?;
}
"_valueRange" => {
raw_value.element("Range", value, path)?;
}
"valueReference" => {
raw_value.value("Reference", value, path)?;
}
"_valueReference" => {
raw_value.element("Reference", value, path)?;
}
"comment" => {
raw_comment = Some(value);
}
"_comment" => {
raw_comment_element = Some(value);
}
"period" => {
raw_period = 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_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_value = match raw_value.suffix {
None => None,
Some(suffix) => Some(path.with("value", |path| {
HealthcareServiceEligibilityValue::from_json_parts(
suffix,
raw_value.value,
raw_value.element,
path,
)
})?),
};
let field_comment = match (raw_comment, raw_comment_element) {
(None, None) => None,
(value, element) => Some(path.with("comment", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_period = raw_period
.map(|value| {
path.with("period", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
code: field_code,
value: field_value,
comment: field_comment,
period: field_period,
})
}
}
impl serde::Serialize for HealthcareServiceEligibility {
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.comment {
super::super::codec::element_entry(&mut map, "_comment", item)?;
}
if let Some(HealthcareServiceEligibilityValue::Boolean(inner)) = &self.value {
super::super::codec::element_entry(&mut map, "_valueBoolean", inner)?;
}
if let Some(item) = &self.code {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", item)?;
}
if let Some(item) = &self.comment {
super::super::codec::value_entry(&mut map, "comment", 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.period {
serde::ser::SerializeMap::serialize_entry(&mut map, "period", item)?;
}
match &self.value {
Some(HealthcareServiceEligibilityValue::Boolean(inner)) => {
super::super::codec::value_entry(&mut map, "valueBoolean", inner)?;
}
Some(HealthcareServiceEligibilityValue::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueCodeableConcept",
inner.as_ref(),
)?;
}
Some(HealthcareServiceEligibilityValue::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueQuantity",
inner.as_ref(),
)?;
}
Some(HealthcareServiceEligibilityValue::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valueRange", inner.as_ref())?;
}
Some(HealthcareServiceEligibilityValue::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueReference",
inner.as_ref(),
)?;
}
None => {}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for HealthcareServiceEligibility {
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("HealthcareServiceEligibility");
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 HealthcareServiceEligibilityValue {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Boolean(super::primitives::Boolean),
Quantity(Box<super::quantity::Quantity>),
Range(Box<super::range::Range>),
Reference(Box<super::reference::Reference>),
}
impl HealthcareServiceEligibilityValue {
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::Boolean(inner) => Ok((
"Boolean",
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::Range(inner) => Ok((
"Range",
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)))
}
"Boolean" => Ok(Self::Boolean(
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)))
}
"Range" => {
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::Range(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)),
}
}
}