#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AuditEvent {
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 category: Vec<super::codeable_concept::CodeableConcept>,
pub code: super::codeable_concept::CodeableConcept,
pub action: Option<super::primitives::Code>,
pub severity: Option<super::primitives::Code>,
pub occurred: Option<AuditEventOccurred>,
pub recorded: super::primitives::Instant,
pub outcome: Option<AuditEventOutcome>,
pub authorization: Vec<super::codeable_concept::CodeableConcept>,
pub based_on: Vec<super::reference::Reference>,
pub patient: Option<super::reference::Reference>,
pub encounter: Option<super::reference::Reference>,
pub agent: Vec<AuditEventAgent>,
pub source: AuditEventSource,
pub entity: Vec<AuditEventEntity>,
}
impl super::super::codec::Json for AuditEvent {
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("AuditEvent")),
);
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.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),
);
}
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.code)?),
);
if let Some(item) = &self.action {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("action"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_action"), e);
}
}
if let Some(item) = &self.severity {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("severity"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_severity"), e);
}
}
if let Some(item) = &self.occurred {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("occurred{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_occurred{suffix}"), element);
}
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.recorded)? {
object.insert(std::string::String::from("recorded"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.recorded)? {
object.insert(std::string::String::from("_recorded"), e);
}
if let Some(item) = &self.outcome {
object.insert(
std::string::String::from("outcome"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.authorization.is_empty() {
let mut items = Vec::with_capacity(self.authorization.len());
for item in &self.authorization {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("authorization"),
super::super::codec::Value::Array(items),
);
}
if !self.based_on.is_empty() {
let mut items = Vec::with_capacity(self.based_on.len());
for item in &self.based_on {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("basedOn"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.patient {
object.insert(
std::string::String::from("patient"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.encounter {
object.insert(
std::string::String::from("encounter"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.agent.is_empty() {
let mut items = Vec::with_capacity(self.agent.len());
for item in &self.agent {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("agent"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("source"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.source)?),
);
if !self.entity.is_empty() {
let mut items = Vec::with_capacity(self.entity.len());
for item in &self.entity {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("entity"),
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_category: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_action: Option<&super::super::codec::Value> = None;
let mut raw_action_element: Option<&super::super::codec::Value> = None;
let mut raw_severity: Option<&super::super::codec::Value> = None;
let mut raw_severity_element: Option<&super::super::codec::Value> = None;
let mut raw_occurred = super::super::codec::ChoiceSlot::default();
let mut raw_recorded: Option<&super::super::codec::Value> = None;
let mut raw_recorded_element: Option<&super::super::codec::Value> = None;
let mut raw_outcome: Option<&super::super::codec::Value> = None;
let mut raw_authorization: Option<&super::super::codec::Value> = None;
let mut raw_based_on: Option<&super::super::codec::Value> = None;
let mut raw_patient: Option<&super::super::codec::Value> = None;
let mut raw_encounter: Option<&super::super::codec::Value> = None;
let mut raw_agent: Option<&super::super::codec::Value> = None;
let mut raw_source: Option<&super::super::codec::Value> = None;
let mut raw_entity: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("AuditEvent") {
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);
}
"category" => {
raw_category = Some(value);
}
"code" => {
raw_code = Some(value);
}
"action" => {
raw_action = Some(value);
}
"_action" => {
raw_action_element = Some(value);
}
"severity" => {
raw_severity = Some(value);
}
"_severity" => {
raw_severity_element = Some(value);
}
"occurredPeriod" => {
raw_occurred.value("Period", value, path)?;
}
"_occurredPeriod" => {
raw_occurred.element("Period", value, path)?;
}
"occurredDateTime" => {
raw_occurred.value("DateTime", value, path)?;
}
"_occurredDateTime" => {
raw_occurred.element("DateTime", value, path)?;
}
"recorded" => {
raw_recorded = Some(value);
}
"_recorded" => {
raw_recorded_element = Some(value);
}
"outcome" => {
raw_outcome = Some(value);
}
"authorization" => {
raw_authorization = Some(value);
}
"basedOn" => {
raw_based_on = Some(value);
}
"patient" => {
raw_patient = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"agent" => {
raw_agent = Some(value);
}
"source" => {
raw_source = Some(value);
}
"entity" => {
raw_entity = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_id(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_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 field_code = path.with("code", |path| {
let value = raw_code
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_action = match (raw_action, raw_action_element) {
(None, None) => None,
(value, element) => Some(path.with("action", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_severity = match (raw_severity, raw_severity_element) {
(None, None) => None,
(value, element) => Some(path.with("severity", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_occurred = match raw_occurred.suffix {
None => None,
Some(suffix) => Some(path.with("occurred", |path| {
AuditEventOccurred::from_json_parts(
suffix,
raw_occurred.value,
raw_occurred.element,
path,
)
})?),
};
let field_recorded = path.with("recorded", |path| {
super::super::codec::Primitive::from_json_parts(
raw_recorded,
raw_recorded_element,
path,
)
})?;
let field_outcome = raw_outcome
.map(|value| {
path.with("outcome", |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_authorization = Vec::new();
if let Some(raw) = raw_authorization {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_authorization.push(path.with_index("authorization", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_based_on = Vec::new();
if let Some(raw) = raw_based_on {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_based_on.push(path.with_index("basedOn", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_patient = raw_patient
.map(|value| {
path.with("patient", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_encounter = raw_encounter
.map(|value| {
path.with("encounter", |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_agent = Vec::new();
if let Some(raw) = raw_agent {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_agent.push(path.with_index("agent", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_source = path.with("source", |path| {
let value = raw_source
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let mut field_entity = Vec::new();
if let Some(raw) = raw_entity {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_entity.push(path.with_index("entity", 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,
category: field_category,
code: field_code,
action: field_action,
severity: field_severity,
occurred: field_occurred,
recorded: field_recorded,
outcome: field_outcome,
authorization: field_authorization,
based_on: field_based_on,
patient: field_patient,
encounter: field_encounter,
agent: field_agent,
source: field_source,
entity: field_entity,
})
}
}
impl serde::Serialize for AuditEvent {
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.action {
super::super::codec::element_entry(&mut map, "_action", 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(AuditEventOccurred::DateTime(inner)) = &self.occurred {
super::super::codec::element_entry(&mut map, "_occurredDateTime", inner)?;
}
super::super::codec::element_entry(&mut map, "_recorded", &self.recorded)?;
if let Some(item) = &self.severity {
super::super::codec::element_entry(&mut map, "_severity", item)?;
}
if let Some(item) = &self.action {
super::super::codec::value_entry(&mut map, "action", item)?;
}
if !self.agent.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "agent", &self.agent)?;
}
if !self.authorization.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"authorization",
&self.authorization,
)?;
}
if !self.based_on.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "basedOn", &self.based_on)?;
}
if !self.category.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
}
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 let Some(item) = &self.encounter {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", item)?;
}
if !self.entity.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "entity", &self.entity)?;
}
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 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 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,
)?;
}
match &self.occurred {
Some(AuditEventOccurred::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "occurredDateTime", inner)?;
}
Some(AuditEventOccurred::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"occurredPeriod",
inner.as_ref(),
)?;
}
None => {}
}
if let Some(item) = &self.outcome {
serde::ser::SerializeMap::serialize_entry(&mut map, "outcome", item)?;
}
if let Some(item) = &self.patient {
serde::ser::SerializeMap::serialize_entry(&mut map, "patient", item)?;
}
super::super::codec::value_entry(&mut map, "recorded", &self.recorded)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "AuditEvent")?;
if let Some(item) = &self.severity {
super::super::codec::value_entry(&mut map, "severity", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "source", &self.source)?;
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 AuditEvent {
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("AuditEvent");
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 AuditEventAgent {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub role: Vec<super::codeable_concept::CodeableConcept>,
pub who: super::reference::Reference,
pub requestor: Option<super::primitives::Boolean>,
pub location: Option<super::reference::Reference>,
pub policy: Vec<super::primitives::Uri>,
pub network: Option<AuditEventAgentNetwork>,
pub authorization: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for AuditEventAgent {
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.r#type {
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.role.is_empty() {
let mut items = Vec::with_capacity(self.role.len());
for item in &self.role {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("role"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("who"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.who)?),
);
if let Some(item) = &self.requestor {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("requestor"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_requestor"), e);
}
}
if let Some(item) = &self.location {
object.insert(
std::string::String::from("location"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.policy.is_empty() {
let (values, elements) = super::super::codec::primitive_arrays(&self.policy)?;
if let Some(values) = values {
object.insert(std::string::String::from("policy"), values);
}
if let Some(elements) = elements {
object.insert(std::string::String::from("_policy"), elements);
}
}
if let Some(item) = &self.network {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("network{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_network{suffix}"), element);
}
}
if !self.authorization.is_empty() {
let mut items = Vec::with_capacity(self.authorization.len());
for item in &self.authorization {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("authorization"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_role: Option<&super::super::codec::Value> = None;
let mut raw_who: Option<&super::super::codec::Value> = None;
let mut raw_requestor: Option<&super::super::codec::Value> = None;
let mut raw_requestor_element: Option<&super::super::codec::Value> = None;
let mut raw_location: Option<&super::super::codec::Value> = None;
let mut raw_policy: Option<&super::super::codec::Value> = None;
let mut raw_policy_element: Option<&super::super::codec::Value> = None;
let mut raw_network = super::super::codec::ChoiceSlot::default();
let mut raw_authorization: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"type" => {
raw_type = Some(value);
}
"role" => {
raw_role = Some(value);
}
"who" => {
raw_who = Some(value);
}
"requestor" => {
raw_requestor = Some(value);
}
"_requestor" => {
raw_requestor_element = Some(value);
}
"location" => {
raw_location = Some(value);
}
"policy" => {
raw_policy = Some(value);
}
"_policy" => {
raw_policy_element = Some(value);
}
"networkReference" => {
raw_network.value("Reference", value, path)?;
}
"_networkReference" => {
raw_network.element("Reference", value, path)?;
}
"networkUri" => {
raw_network.value("Uri", value, path)?;
}
"_networkUri" => {
raw_network.element("Uri", value, path)?;
}
"networkString" => {
raw_network.value("String", value, path)?;
}
"_networkString" => {
raw_network.element("String", value, path)?;
}
"authorization" => {
raw_authorization = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_type = raw_type
.map(|value| {
path.with("type", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_role = Vec::new();
if let Some(raw) = raw_role {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_role.push(path.with_index("role", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_who = path.with("who", |path| {
let value = raw_who
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_requestor = match (raw_requestor, raw_requestor_element) {
(None, None) => None,
(value, element) => Some(path.with("requestor", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_location = raw_location
.map(|value| {
path.with("location", |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_policy = Vec::new();
for (index, (value, element)) in
super::super::codec::pair_arrays(raw_policy, raw_policy_element, path)?
.into_iter()
.enumerate()
{
field_policy.push(path.with_index("policy", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let field_network = match raw_network.suffix {
None => None,
Some(suffix) => Some(path.with("network", |path| {
AuditEventAgentNetwork::from_json_parts(
suffix,
raw_network.value,
raw_network.element,
path,
)
})?),
};
let mut field_authorization = Vec::new();
if let Some(raw) = raw_authorization {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_authorization.push(path.with_index("authorization", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
role: field_role,
who: field_who,
requestor: field_requestor,
location: field_location,
policy: field_policy,
network: field_network,
authorization: field_authorization,
})
}
}
impl serde::Serialize for AuditEventAgent {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.network {
Some(AuditEventAgentNetwork::String(inner)) => {
super::super::codec::element_entry(&mut map, "_networkString", inner)?;
}
Some(AuditEventAgentNetwork::Uri(inner)) => {
super::super::codec::element_entry(&mut map, "_networkUri", inner)?;
}
_ => {}
}
super::super::codec::element_list_entry(&mut map, "_policy", &self.policy)?;
if let Some(item) = &self.requestor {
super::super::codec::element_entry(&mut map, "_requestor", item)?;
}
if !self.authorization.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"authorization",
&self.authorization,
)?;
}
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 let Some(item) = &self.location {
serde::ser::SerializeMap::serialize_entry(&mut map, "location", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
match &self.network {
Some(AuditEventAgentNetwork::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"networkReference",
inner.as_ref(),
)?;
}
Some(AuditEventAgentNetwork::String(inner)) => {
super::super::codec::value_entry(&mut map, "networkString", inner)?;
}
Some(AuditEventAgentNetwork::Uri(inner)) => {
super::super::codec::value_entry(&mut map, "networkUri", inner)?;
}
None => {}
}
super::super::codec::value_list_entry(&mut map, "policy", &self.policy)?;
if let Some(item) = &self.requestor {
super::super::codec::value_entry(&mut map, "requestor", item)?;
}
if !self.role.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "role", &self.role)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "who", &self.who)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for AuditEventAgent {
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("AuditEventAgent");
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 AuditEventAgentNetwork {
Reference(Box<super::reference::Reference>),
Uri(super::primitives::Uri),
String(super::primitives::String),
}
impl AuditEventAgentNetwork {
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::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Uri(inner) => Ok((
"Uri",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::String(inner) => Ok((
"String",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
}
}
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 {
"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)))
}
"Uri" => Ok(Self::Uri(super::super::codec::Primitive::from_json_parts(
value, element, path,
)?)),
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AuditEventEntity {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub what: Option<super::reference::Reference>,
pub role: Option<super::codeable_concept::CodeableConcept>,
pub security_label: Vec<super::codeable_concept::CodeableConcept>,
pub query: Option<super::primitives::Base64Binary>,
pub detail: Vec<AuditEventEntityDetail>,
pub agent: Vec<AuditEventAgent>,
}
impl super::super::codec::Json for AuditEventEntity {
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.what {
object.insert(
std::string::String::from("what"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.role {
object.insert(
std::string::String::from("role"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.security_label.is_empty() {
let mut items = Vec::with_capacity(self.security_label.len());
for item in &self.security_label {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("securityLabel"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.query {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("query"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_query"), e);
}
}
if !self.detail.is_empty() {
let mut items = Vec::with_capacity(self.detail.len());
for item in &self.detail {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("detail"),
super::super::codec::Value::Array(items),
);
}
if !self.agent.is_empty() {
let mut items = Vec::with_capacity(self.agent.len());
for item in &self.agent {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("agent"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_what: Option<&super::super::codec::Value> = None;
let mut raw_role: Option<&super::super::codec::Value> = None;
let mut raw_security_label: Option<&super::super::codec::Value> = None;
let mut raw_query: Option<&super::super::codec::Value> = None;
let mut raw_query_element: Option<&super::super::codec::Value> = None;
let mut raw_detail: Option<&super::super::codec::Value> = None;
let mut raw_agent: 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);
}
"what" => {
raw_what = Some(value);
}
"role" => {
raw_role = Some(value);
}
"securityLabel" => {
raw_security_label = Some(value);
}
"query" => {
raw_query = Some(value);
}
"_query" => {
raw_query_element = Some(value);
}
"detail" => {
raw_detail = Some(value);
}
"agent" => {
raw_agent = 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_what = raw_what
.map(|value| {
path.with("what", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_role = raw_role
.map(|value| {
path.with("role", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_security_label = Vec::new();
if let Some(raw) = raw_security_label {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_security_label.push(path.with_index("securityLabel", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_query = match (raw_query, raw_query_element) {
(None, None) => None,
(value, element) => Some(path.with("query", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_detail = Vec::new();
if let Some(raw) = raw_detail {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_detail.push(path.with_index("detail", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_agent = Vec::new();
if let Some(raw) = raw_agent {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_agent.push(path.with_index("agent", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
what: field_what,
role: field_role,
security_label: field_security_label,
query: field_query,
detail: field_detail,
agent: field_agent,
})
}
}
impl serde::Serialize for AuditEventEntity {
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.query {
super::super::codec::element_entry(&mut map, "_query", item)?;
}
if !self.agent.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "agent", &self.agent)?;
}
if !self.detail.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "detail", &self.detail)?;
}
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.query {
super::super::codec::value_entry(&mut map, "query", item)?;
}
if let Some(item) = &self.role {
serde::ser::SerializeMap::serialize_entry(&mut map, "role", item)?;
}
if !self.security_label.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"securityLabel",
&self.security_label,
)?;
}
if let Some(item) = &self.what {
serde::ser::SerializeMap::serialize_entry(&mut map, "what", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for AuditEventEntity {
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("AuditEventEntity");
let object =
super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AuditEventEntityDetail {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub r#type: super::codeable_concept::CodeableConcept,
pub value: AuditEventEntityDetailValue,
}
impl super::super::codec::Json for AuditEventEntityDetail {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.r#type)?),
);
let (suffix, value, element) = self.value.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);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_value = super::super::codec::ChoiceSlot::default();
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"type" => {
raw_type = Some(value);
}
"valueQuantity" => {
raw_value.value("Quantity", value, path)?;
}
"_valueQuantity" => {
raw_value.element("Quantity", value, path)?;
}
"valueCodeableConcept" => {
raw_value.value("CodeableConcept", value, path)?;
}
"_valueCodeableConcept" => {
raw_value.element("CodeableConcept", value, path)?;
}
"valueString" => {
raw_value.value("String", value, path)?;
}
"_valueString" => {
raw_value.element("String", value, path)?;
}
"valueBoolean" => {
raw_value.value("Boolean", value, path)?;
}
"_valueBoolean" => {
raw_value.element("Boolean", value, path)?;
}
"valueInteger" => {
raw_value.value("Integer", value, path)?;
}
"_valueInteger" => {
raw_value.element("Integer", value, path)?;
}
"valueRange" => {
raw_value.value("Range", value, path)?;
}
"_valueRange" => {
raw_value.element("Range", value, path)?;
}
"valueRatio" => {
raw_value.value("Ratio", value, path)?;
}
"_valueRatio" => {
raw_value.element("Ratio", value, path)?;
}
"valueTime" => {
raw_value.value("Time", value, path)?;
}
"_valueTime" => {
raw_value.element("Time", value, path)?;
}
"valueDateTime" => {
raw_value.value("DateTime", value, path)?;
}
"_valueDateTime" => {
raw_value.element("DateTime", value, path)?;
}
"valuePeriod" => {
raw_value.value("Period", value, path)?;
}
"_valuePeriod" => {
raw_value.element("Period", value, path)?;
}
"valueBase64Binary" => {
raw_value.value("Base64Binary", value, path)?;
}
"_valueBase64Binary" => {
raw_value.element("Base64Binary", value, path)?;
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_type = path.with("type", |path| {
let value = raw_type
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let field_value = path.with("value", |path| {
let suffix = raw_value
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
AuditEventEntityDetailValue::from_json_parts(
suffix,
raw_value.value,
raw_value.element,
path,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
value: field_value,
})
}
}
impl serde::Serialize for AuditEventEntityDetail {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.value {
AuditEventEntityDetailValue::Base64Binary(inner) => {
super::super::codec::element_entry(&mut map, "_valueBase64Binary", inner)?;
}
AuditEventEntityDetailValue::Boolean(inner) => {
super::super::codec::element_entry(&mut map, "_valueBoolean", inner)?;
}
AuditEventEntityDetailValue::DateTime(inner) => {
super::super::codec::element_entry(&mut map, "_valueDateTime", inner)?;
}
AuditEventEntityDetailValue::Integer(inner) => {
super::super::codec::element_entry(&mut map, "_valueInteger", inner)?;
}
AuditEventEntityDetailValue::String(inner) => {
super::super::codec::element_entry(&mut map, "_valueString", inner)?;
}
AuditEventEntityDetailValue::Time(inner) => {
super::super::codec::element_entry(&mut map, "_valueTime", inner)?;
}
_ => {}
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
match &self.value {
AuditEventEntityDetailValue::Base64Binary(inner) => {
super::super::codec::value_entry(&mut map, "valueBase64Binary", inner)?;
}
AuditEventEntityDetailValue::Boolean(inner) => {
super::super::codec::value_entry(&mut map, "valueBoolean", inner)?;
}
AuditEventEntityDetailValue::CodeableConcept(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueCodeableConcept",
inner.as_ref(),
)?;
}
AuditEventEntityDetailValue::DateTime(inner) => {
super::super::codec::value_entry(&mut map, "valueDateTime", inner)?;
}
AuditEventEntityDetailValue::Integer(inner) => {
super::super::codec::value_entry(&mut map, "valueInteger", inner)?;
}
AuditEventEntityDetailValue::Period(inner) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valuePeriod", inner.as_ref())?;
}
AuditEventEntityDetailValue::Quantity(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueQuantity",
inner.as_ref(),
)?;
}
AuditEventEntityDetailValue::Range(inner) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valueRange", inner.as_ref())?;
}
AuditEventEntityDetailValue::Ratio(inner) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valueRatio", inner.as_ref())?;
}
AuditEventEntityDetailValue::String(inner) => {
super::super::codec::value_entry(&mut map, "valueString", inner)?;
}
AuditEventEntityDetailValue::Time(inner) => {
super::super::codec::value_entry(&mut map, "valueTime", inner)?;
}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for AuditEventEntityDetail {
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("AuditEventEntityDetail");
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 AuditEventEntityDetailValue {
Quantity(Box<super::quantity::Quantity>),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
String(super::primitives::String),
Boolean(super::primitives::Boolean),
Integer(super::primitives::Integer),
Range(Box<super::range::Range>),
Ratio(Box<super::ratio::Ratio>),
Time(super::primitives::Time),
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
Base64Binary(super::primitives::Base64Binary),
}
impl AuditEventEntityDetailValue {
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::Quantity(inner) => Ok((
"Quantity",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::String(inner) => Ok((
"String",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Boolean(inner) => Ok((
"Boolean",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Integer(inner) => Ok((
"Integer",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Range(inner) => Ok((
"Range",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Ratio(inner) => Ok((
"Ratio",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Time(inner) => Ok((
"Time",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Base64Binary(inner) => Ok((
"Base64Binary",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
}
}
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 {
"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)))
}
"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)))
}
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Boolean" => Ok(Self::Boolean(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Integer" => Ok(Self::Integer(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"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)))
}
"Ratio" => {
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::Ratio(Box::new(inner)))
}
"Time" => Ok(Self::Time(super::super::codec::Primitive::from_json_parts(
value, element, path,
)?)),
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
"Base64Binary" => Ok(Self::Base64Binary(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AuditEventOccurred {
Period(Box<super::period::Period>),
DateTime(super::primitives::DateTime),
}
impl AuditEventOccurred {
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::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
}
}
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 {
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AuditEventOutcome {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub code: super::coding::Coding,
pub detail: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for AuditEventOutcome {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.code)?),
);
if !self.detail.is_empty() {
let mut items = Vec::with_capacity(self.detail.len());
for item in &self.detail {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("detail"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_detail: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"code" => {
raw_code = Some(value);
}
"detail" => {
raw_detail = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_code = path.with("code", |path| {
let value = raw_code
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let mut field_detail = Vec::new();
if let Some(raw) = raw_detail {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_detail.push(path.with_index("detail", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
code: field_code,
detail: field_detail,
})
}
}
impl serde::Serialize for AuditEventOutcome {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
if !self.detail.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "detail", &self.detail)?;
}
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 AuditEventOutcome {
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("AuditEventOutcome");
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 AuditEventSource {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub site: Option<super::reference::Reference>,
pub observer: super::reference::Reference,
pub r#type: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for AuditEventSource {
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.site {
object.insert(
std::string::String::from("site"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
object.insert(
std::string::String::from("observer"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.observer)?),
);
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),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_site: Option<&super::super::codec::Value> = None;
let mut raw_observer: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"site" => {
raw_site = Some(value);
}
"observer" => {
raw_observer = Some(value);
}
"type" => {
raw_type = 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_site = raw_site
.map(|value| {
path.with("site", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_observer = path.with("observer", |path| {
let value = raw_observer
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let 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,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
site: field_site,
observer: field_observer,
r#type: field_type,
})
}
}
impl serde::Serialize for AuditEventSource {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "observer", &self.observer)?;
if let Some(item) = &self.site {
serde::ser::SerializeMap::serialize_entry(&mut map, "site", 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 AuditEventSource {
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("AuditEventSource");
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)
}
}