#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct PractitionerRole {
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 period: Option<super::period::Period>,
pub practitioner: Option<super::reference::Reference>,
pub organization: Option<super::reference::Reference>,
pub code: Vec<super::codeable_concept::CodeableConcept>,
pub specialty: Vec<super::codeable_concept::CodeableConcept>,
pub location: Vec<super::reference::Reference>,
pub healthcare_service: Vec<super::reference::Reference>,
pub telecom: Vec<super::contact_point::ContactPoint>,
pub available_time: Vec<PractitionerRoleAvailableTime>,
pub not_available: Vec<PractitionerRoleNotAvailable>,
pub availability_exceptions: Option<super::primitives::String>,
pub endpoint: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for PractitionerRole {
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("PractitionerRole")),
);
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.period {
object.insert(
std::string::String::from("period"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.practitioner {
object.insert(
std::string::String::from("practitioner"),
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 !self.code.is_empty() {
let mut items = Vec::with_capacity(self.code.len());
for item in &self.code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("code"),
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 !self.healthcare_service.is_empty() {
let mut items = Vec::with_capacity(self.healthcare_service.len());
for item in &self.healthcare_service {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("healthcareService"),
super::super::codec::Value::Array(items),
);
}
if !self.telecom.is_empty() {
let mut items = Vec::with_capacity(self.telecom.len());
for item in &self.telecom {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("telecom"),
super::super::codec::Value::Array(items),
);
}
if !self.available_time.is_empty() {
let mut items = Vec::with_capacity(self.available_time.len());
for item in &self.available_time {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("availableTime"),
super::super::codec::Value::Array(items),
);
}
if !self.not_available.is_empty() {
let mut items = Vec::with_capacity(self.not_available.len());
for item in &self.not_available {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("notAvailable"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.availability_exceptions {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("availabilityExceptions"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_availabilityExceptions"), e);
}
}
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_period: Option<&super::super::codec::Value> = None;
let mut raw_practitioner: Option<&super::super::codec::Value> = None;
let mut raw_organization: Option<&super::super::codec::Value> = None;
let mut raw_code: 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_healthcare_service: Option<&super::super::codec::Value> = None;
let mut raw_telecom: Option<&super::super::codec::Value> = None;
let mut raw_available_time: Option<&super::super::codec::Value> = None;
let mut raw_not_available: Option<&super::super::codec::Value> = None;
let mut raw_availability_exceptions: Option<&super::super::codec::Value> = None;
let mut raw_availability_exceptions_element: 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("PractitionerRole") {
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);
}
"period" => {
raw_period = Some(value);
}
"practitioner" => {
raw_practitioner = Some(value);
}
"organization" => {
raw_organization = Some(value);
}
"code" => {
raw_code = Some(value);
}
"specialty" => {
raw_specialty = Some(value);
}
"location" => {
raw_location = Some(value);
}
"healthcareService" => {
raw_healthcare_service = Some(value);
}
"telecom" => {
raw_telecom = Some(value);
}
"availableTime" => {
raw_available_time = Some(value);
}
"notAvailable" => {
raw_not_available = Some(value);
}
"availabilityExceptions" => {
raw_availability_exceptions = Some(value);
}
"_availabilityExceptions" => {
raw_availability_exceptions_element = 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::super::codec::expect_string(value, 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_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()?;
let field_practitioner = raw_practitioner
.map(|value| {
path.with("practitioner", |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 mut field_code = Vec::new();
if let Some(raw) = raw_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_code.push(path.with_index("code", 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 mut field_healthcare_service = Vec::new();
if let Some(raw) = raw_healthcare_service {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_healthcare_service.push(path.with_index(
"healthcareService",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_telecom = Vec::new();
if let Some(raw) = raw_telecom {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_telecom.push(path.with_index("telecom", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_available_time = Vec::new();
if let Some(raw) = raw_available_time {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_available_time.push(path.with_index("availableTime", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_not_available = Vec::new();
if let Some(raw) = raw_not_available {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_not_available.push(path.with_index("notAvailable", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_availability_exceptions = match (
raw_availability_exceptions,
raw_availability_exceptions_element,
) {
(None, None) => None,
(value, element) => Some(path.with("availabilityExceptions", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
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,
period: field_period,
practitioner: field_practitioner,
organization: field_organization,
code: field_code,
specialty: field_specialty,
location: field_location,
healthcare_service: field_healthcare_service,
telecom: field_telecom,
available_time: field_available_time,
not_available: field_not_available,
availability_exceptions: field_availability_exceptions,
endpoint: field_endpoint,
})
}
}
impl serde::Serialize for PractitionerRole {
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.availability_exceptions {
super::super::codec::element_entry(&mut map, "_availabilityExceptions", 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.active {
super::super::codec::value_entry(&mut map, "active", item)?;
}
if let Some(item) = &self.availability_exceptions {
super::super::codec::value_entry(&mut map, "availabilityExceptions", item)?;
}
if !self.available_time.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"availableTime",
&self.available_time,
)?;
}
if !self.code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
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 !self.healthcare_service.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"healthcareService",
&self.healthcare_service,
)?;
}
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 !self.not_available.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"notAvailable",
&self.not_available,
)?;
}
if let Some(item) = &self.organization {
serde::ser::SerializeMap::serialize_entry(&mut map, "organization", item)?;
}
if let Some(item) = &self.period {
serde::ser::SerializeMap::serialize_entry(&mut map, "period", item)?;
}
if let Some(item) = &self.practitioner {
serde::ser::SerializeMap::serialize_entry(&mut map, "practitioner", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "PractitionerRole")?;
if !self.specialty.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "specialty", &self.specialty)?;
}
if !self.telecom.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "telecom", &self.telecom)?;
}
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 PractitionerRole {
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("PractitionerRole");
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 PractitionerRoleAvailableTime {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub days_of_week: Vec<super::primitives::Code>,
pub all_day: Option<super::primitives::Boolean>,
pub available_start_time: Option<super::primitives::Time>,
pub available_end_time: Option<super::primitives::Time>,
}
impl super::super::codec::Json for PractitionerRoleAvailableTime {
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.days_of_week.is_empty() {
let (values, elements) = super::super::codec::primitive_arrays(&self.days_of_week)?;
object.insert(std::string::String::from("daysOfWeek"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_daysOfWeek"), elements);
}
}
if let Some(item) = &self.all_day {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("allDay"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_allDay"), e);
}
}
if let Some(item) = &self.available_start_time {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("availableStartTime"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_availableStartTime"), e);
}
}
if let Some(item) = &self.available_end_time {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("availableEndTime"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_availableEndTime"), e);
}
}
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_days_of_week: Option<&super::super::codec::Value> = None;
let mut raw_days_of_week_element: Option<&super::super::codec::Value> = None;
let mut raw_all_day: Option<&super::super::codec::Value> = None;
let mut raw_all_day_element: Option<&super::super::codec::Value> = None;
let mut raw_available_start_time: Option<&super::super::codec::Value> = None;
let mut raw_available_start_time_element: Option<&super::super::codec::Value> = None;
let mut raw_available_end_time: Option<&super::super::codec::Value> = None;
let mut raw_available_end_time_element: 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);
}
"daysOfWeek" => {
raw_days_of_week = Some(value);
}
"_daysOfWeek" => {
raw_days_of_week_element = Some(value);
}
"allDay" => {
raw_all_day = Some(value);
}
"_allDay" => {
raw_all_day_element = Some(value);
}
"availableStartTime" => {
raw_available_start_time = Some(value);
}
"_availableStartTime" => {
raw_available_start_time_element = Some(value);
}
"availableEndTime" => {
raw_available_end_time = Some(value);
}
"_availableEndTime" => {
raw_available_end_time_element = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_days_of_week = Vec::new();
for (index, (value, element)) in
super::super::codec::pair_arrays(raw_days_of_week, raw_days_of_week_element, path)?
.into_iter()
.enumerate()
{
field_days_of_week.push(path.with_index("daysOfWeek", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let field_all_day = match (raw_all_day, raw_all_day_element) {
(None, None) => None,
(value, element) => Some(path.with("allDay", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_available_start_time =
match (raw_available_start_time, raw_available_start_time_element) {
(None, None) => None,
(value, element) => Some(path.with("availableStartTime", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_available_end_time =
match (raw_available_end_time, raw_available_end_time_element) {
(None, None) => None,
(value, element) => Some(path.with("availableEndTime", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
days_of_week: field_days_of_week,
all_day: field_all_day,
available_start_time: field_available_start_time,
available_end_time: field_available_end_time,
})
}
}
impl serde::Serialize for PractitionerRoleAvailableTime {
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.all_day {
super::super::codec::element_entry(&mut map, "_allDay", item)?;
}
if let Some(item) = &self.available_end_time {
super::super::codec::element_entry(&mut map, "_availableEndTime", item)?;
}
if let Some(item) = &self.available_start_time {
super::super::codec::element_entry(&mut map, "_availableStartTime", item)?;
}
super::super::codec::element_list_entry(&mut map, "_daysOfWeek", &self.days_of_week)?;
if let Some(item) = &self.all_day {
super::super::codec::value_entry(&mut map, "allDay", item)?;
}
if let Some(item) = &self.available_end_time {
super::super::codec::value_entry(&mut map, "availableEndTime", item)?;
}
if let Some(item) = &self.available_start_time {
super::super::codec::value_entry(&mut map, "availableStartTime", item)?;
}
super::super::codec::value_list_entry(&mut map, "daysOfWeek", &self.days_of_week)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for PractitionerRoleAvailableTime {
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("PractitionerRoleAvailableTime");
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 PractitionerRoleNotAvailable {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub description: super::primitives::String,
pub during: Option<super::period::Period>,
}
impl super::super::codec::Json for PractitionerRoleNotAvailable {
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.description)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.description)? {
object.insert(std::string::String::from("_description"), e);
}
if let Some(item) = &self.during {
object.insert(
std::string::String::from("during"),
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_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
let mut raw_during: 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);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"during" => {
raw_during = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_description = path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(
raw_description,
raw_description_element,
path,
)
})?;
let field_during = raw_during
.map(|value| {
path.with("during", |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,
description: field_description,
during: field_during,
})
}
}
impl serde::Serialize for PractitionerRoleNotAvailable {
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, "_description", &self.description)?;
super::super::codec::value_entry(&mut map, "description", &self.description)?;
if let Some(item) = &self.during {
serde::ser::SerializeMap::serialize_entry(&mut map, "during", 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,
)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for PractitionerRoleNotAvailable {
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("PractitionerRoleNotAvailable");
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)
}
}