#[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 contact: Vec<super::extended_contact_detail::ExtendedContactDetail>,
pub characteristic: Vec<super::codeable_concept::CodeableConcept>,
pub communication: Vec<super::codeable_concept::CodeableConcept>,
pub availability: Vec<super::availability::Availability>,
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.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.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.availability.is_empty() {
let mut items = Vec::with_capacity(self.availability.len());
for item in &self.availability {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("availability"),
super::super::codec::Value::Array(items),
);
}
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_contact: 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_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("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);
}
"contact" => {
raw_contact = Some(value);
}
"characteristic" => {
raw_characteristic = Some(value);
}
"communication" => {
raw_communication = 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::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_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_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_availability = Vec::new();
if let Some(raw) = raw_availability {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_availability.push(path.with_index("availability", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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,
contact: field_contact,
characteristic: field_characteristic,
communication: field_communication,
availability: field_availability,
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.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 !self.availability.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"availability",
&self.availability,
)?;
}
if !self.characteristic.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"characteristic",
&self.characteristic,
)?;
}
if !self.code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
}
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.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 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 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)
}
}