#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct EvidenceVariable {
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 url: Option<super::primitives::Uri>,
pub identifier: Vec<super::identifier::Identifier>,
pub version: Option<super::primitives::String>,
pub name: Option<super::primitives::String>,
pub title: Option<super::primitives::String>,
pub short_title: Option<super::primitives::String>,
pub subtitle: Option<super::primitives::String>,
pub status: super::primitives::Code,
pub date: Option<super::primitives::DateTime>,
pub description: Option<super::primitives::Markdown>,
pub note: Vec<super::annotation::Annotation>,
pub use_context: Vec<super::usage_context::UsageContext>,
pub publisher: Option<super::primitives::String>,
pub contact: Vec<super::contact_detail::ContactDetail>,
pub author: Vec<super::contact_detail::ContactDetail>,
pub editor: Vec<super::contact_detail::ContactDetail>,
pub reviewer: Vec<super::contact_detail::ContactDetail>,
pub endorser: Vec<super::contact_detail::ContactDetail>,
pub related_artifact: Vec<super::related_artifact::RelatedArtifact>,
pub actual: Option<super::primitives::Boolean>,
pub characteristic_combination: Option<super::primitives::Code>,
pub characteristic: Vec<EvidenceVariableCharacteristic>,
pub handling: Option<super::primitives::Code>,
pub category: Vec<EvidenceVariableCategory>,
}
impl super::super::codec::Json for EvidenceVariable {
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("EvidenceVariable")),
);
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 let Some(item) = &self.url {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("url"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_url"), e);
}
}
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.version {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("version"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_version"), e);
}
}
if let Some(item) = &self.name {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_name"), e);
}
}
if let Some(item) = &self.title {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("title"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_title"), e);
}
}
if let Some(item) = &self.short_title {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("shortTitle"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_shortTitle"), e);
}
}
if let Some(item) = &self.subtitle {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("subtitle"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_subtitle"), e);
}
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.status)? {
object.insert(std::string::String::from("status"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.status)? {
object.insert(std::string::String::from("_status"), e);
}
if let Some(item) = &self.date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("date"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_date"), e);
}
}
if let Some(item) = &self.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
if !self.note.is_empty() {
let mut items = Vec::with_capacity(self.note.len());
for item in &self.note {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("note"),
super::super::codec::Value::Array(items),
);
}
if !self.use_context.is_empty() {
let mut items = Vec::with_capacity(self.use_context.len());
for item in &self.use_context {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("useContext"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.publisher {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("publisher"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_publisher"), e);
}
}
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.author.is_empty() {
let mut items = Vec::with_capacity(self.author.len());
for item in &self.author {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("author"),
super::super::codec::Value::Array(items),
);
}
if !self.editor.is_empty() {
let mut items = Vec::with_capacity(self.editor.len());
for item in &self.editor {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("editor"),
super::super::codec::Value::Array(items),
);
}
if !self.reviewer.is_empty() {
let mut items = Vec::with_capacity(self.reviewer.len());
for item in &self.reviewer {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reviewer"),
super::super::codec::Value::Array(items),
);
}
if !self.endorser.is_empty() {
let mut items = Vec::with_capacity(self.endorser.len());
for item in &self.endorser {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("endorser"),
super::super::codec::Value::Array(items),
);
}
if !self.related_artifact.is_empty() {
let mut items = Vec::with_capacity(self.related_artifact.len());
for item in &self.related_artifact {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("relatedArtifact"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.actual {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("actual"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_actual"), e);
}
}
if let Some(item) = &self.characteristic_combination {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("characteristicCombination"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_characteristicCombination"), e);
}
}
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 let Some(item) = &self.handling {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("handling"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_handling"), e);
}
}
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),
);
}
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_url: Option<&super::super::codec::Value> = None;
let mut raw_url_element: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_version: Option<&super::super::codec::Value> = None;
let mut raw_version_element: Option<&super::super::codec::Value> = None;
let mut raw_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: Option<&super::super::codec::Value> = None;
let mut raw_title: Option<&super::super::codec::Value> = None;
let mut raw_title_element: Option<&super::super::codec::Value> = None;
let mut raw_short_title: Option<&super::super::codec::Value> = None;
let mut raw_short_title_element: Option<&super::super::codec::Value> = None;
let mut raw_subtitle: Option<&super::super::codec::Value> = None;
let mut raw_subtitle_element: Option<&super::super::codec::Value> = None;
let mut raw_status: Option<&super::super::codec::Value> = None;
let mut raw_status_element: Option<&super::super::codec::Value> = None;
let mut raw_date: Option<&super::super::codec::Value> = None;
let mut raw_date_element: Option<&super::super::codec::Value> = None;
let mut raw_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_use_context: Option<&super::super::codec::Value> = None;
let mut raw_publisher: Option<&super::super::codec::Value> = None;
let mut raw_publisher_element: Option<&super::super::codec::Value> = None;
let mut raw_contact: Option<&super::super::codec::Value> = None;
let mut raw_author: Option<&super::super::codec::Value> = None;
let mut raw_editor: Option<&super::super::codec::Value> = None;
let mut raw_reviewer: Option<&super::super::codec::Value> = None;
let mut raw_endorser: Option<&super::super::codec::Value> = None;
let mut raw_related_artifact: Option<&super::super::codec::Value> = None;
let mut raw_actual: Option<&super::super::codec::Value> = None;
let mut raw_actual_element: Option<&super::super::codec::Value> = None;
let mut raw_characteristic_combination: Option<&super::super::codec::Value> = None;
let mut raw_characteristic_combination_element: Option<&super::super::codec::Value> = None;
let mut raw_characteristic: Option<&super::super::codec::Value> = None;
let mut raw_handling: Option<&super::super::codec::Value> = None;
let mut raw_handling_element: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("EvidenceVariable") {
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);
}
"url" => {
raw_url = Some(value);
}
"_url" => {
raw_url_element = Some(value);
}
"identifier" => {
raw_identifier = Some(value);
}
"version" => {
raw_version = Some(value);
}
"_version" => {
raw_version_element = Some(value);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"title" => {
raw_title = Some(value);
}
"_title" => {
raw_title_element = Some(value);
}
"shortTitle" => {
raw_short_title = Some(value);
}
"_shortTitle" => {
raw_short_title_element = Some(value);
}
"subtitle" => {
raw_subtitle = Some(value);
}
"_subtitle" => {
raw_subtitle_element = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_element = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"note" => {
raw_note = Some(value);
}
"useContext" => {
raw_use_context = Some(value);
}
"publisher" => {
raw_publisher = Some(value);
}
"_publisher" => {
raw_publisher_element = Some(value);
}
"contact" => {
raw_contact = Some(value);
}
"author" => {
raw_author = Some(value);
}
"editor" => {
raw_editor = Some(value);
}
"reviewer" => {
raw_reviewer = Some(value);
}
"endorser" => {
raw_endorser = Some(value);
}
"relatedArtifact" => {
raw_related_artifact = Some(value);
}
"actual" => {
raw_actual = Some(value);
}
"_actual" => {
raw_actual_element = Some(value);
}
"characteristicCombination" => {
raw_characteristic_combination = Some(value);
}
"_characteristicCombination" => {
raw_characteristic_combination_element = Some(value);
}
"characteristic" => {
raw_characteristic = Some(value);
}
"handling" => {
raw_handling = Some(value);
}
"_handling" => {
raw_handling_element = Some(value);
}
"category" => {
raw_category = 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 field_url = match (raw_url, raw_url_element) {
(None, None) => None,
(value, element) => Some(path.with("url", |path| {
super::super::codec::Primitive::from_json_parts(value, element, 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_version = match (raw_version, raw_version_element) {
(None, None) => None,
(value, element) => Some(path.with("version", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_name = match (raw_name, raw_name_element) {
(None, None) => None,
(value, element) => Some(path.with("name", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_title = match (raw_title, raw_title_element) {
(None, None) => None,
(value, element) => Some(path.with("title", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_short_title = match (raw_short_title, raw_short_title_element) {
(None, None) => None,
(value, element) => Some(path.with("shortTitle", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_subtitle = match (raw_subtitle, raw_subtitle_element) {
(None, None) => None,
(value, element) => Some(path.with("subtitle", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
let field_date = match (raw_date, raw_date_element) {
(None, None) => None,
(value, element) => Some(path.with("date", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_note = Vec::new();
if let Some(raw) = raw_note {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_note.push(path.with_index("note", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_use_context = Vec::new();
if let Some(raw) = raw_use_context {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_use_context.push(path.with_index("useContext", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_publisher = match (raw_publisher, raw_publisher_element) {
(None, None) => None,
(value, element) => Some(path.with("publisher", |path| {
super::super::codec::Primitive::from_json_parts(value, element, 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_author = Vec::new();
if let Some(raw) = raw_author {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_author.push(path.with_index("author", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_editor = Vec::new();
if let Some(raw) = raw_editor {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_editor.push(path.with_index("editor", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_reviewer = Vec::new();
if let Some(raw) = raw_reviewer {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reviewer.push(path.with_index("reviewer", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_endorser = Vec::new();
if let Some(raw) = raw_endorser {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_endorser.push(path.with_index("endorser", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_related_artifact = Vec::new();
if let Some(raw) = raw_related_artifact {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_related_artifact.push(path.with_index("relatedArtifact", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_actual = match (raw_actual, raw_actual_element) {
(None, None) => None,
(value, element) => Some(path.with("actual", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_characteristic_combination = match (
raw_characteristic_combination,
raw_characteristic_combination_element,
) {
(None, None) => None,
(value, element) => Some(path.with("characteristicCombination", |path| {
super::super::codec::Primitive::from_json_parts(value, element, 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 field_handling = match (raw_handling, raw_handling_element) {
(None, None) => None,
(value, element) => Some(path.with("handling", |path| {
super::super::codec::Primitive::from_json_parts(value, element, 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,
)
})?);
}
}
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,
url: field_url,
identifier: field_identifier,
version: field_version,
name: field_name,
title: field_title,
short_title: field_short_title,
subtitle: field_subtitle,
status: field_status,
date: field_date,
description: field_description,
note: field_note,
use_context: field_use_context,
publisher: field_publisher,
contact: field_contact,
author: field_author,
editor: field_editor,
reviewer: field_reviewer,
endorser: field_endorser,
related_artifact: field_related_artifact,
actual: field_actual,
characteristic_combination: field_characteristic_combination,
characteristic: field_characteristic,
handling: field_handling,
category: field_category,
})
}
}
impl serde::Serialize for EvidenceVariable {
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.actual {
super::super::codec::element_entry(&mut map, "_actual", item)?;
}
if let Some(item) = &self.characteristic_combination {
super::super::codec::element_entry(&mut map, "_characteristicCombination", item)?;
}
if let Some(item) = &self.date {
super::super::codec::element_entry(&mut map, "_date", item)?;
}
if let Some(item) = &self.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.handling {
super::super::codec::element_entry(&mut map, "_handling", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(item) = &self.name {
super::super::codec::element_entry(&mut map, "_name", item)?;
}
if let Some(item) = &self.publisher {
super::super::codec::element_entry(&mut map, "_publisher", item)?;
}
if let Some(item) = &self.short_title {
super::super::codec::element_entry(&mut map, "_shortTitle", item)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if let Some(item) = &self.subtitle {
super::super::codec::element_entry(&mut map, "_subtitle", item)?;
}
if let Some(item) = &self.title {
super::super::codec::element_entry(&mut map, "_title", item)?;
}
if let Some(item) = &self.url {
super::super::codec::element_entry(&mut map, "_url", item)?;
}
if let Some(item) = &self.version {
super::super::codec::element_entry(&mut map, "_version", item)?;
}
if let Some(item) = &self.actual {
super::super::codec::value_entry(&mut map, "actual", item)?;
}
if !self.author.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "author", &self.author)?;
}
if !self.category.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
}
if !self.characteristic.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"characteristic",
&self.characteristic,
)?;
}
if let Some(item) = &self.characteristic_combination {
super::super::codec::value_entry(&mut map, "characteristicCombination", item)?;
}
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 let Some(item) = &self.date {
super::super::codec::value_entry(&mut map, "date", item)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if !self.editor.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "editor", &self.editor)?;
}
if !self.endorser.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "endorser", &self.endorser)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.handling {
super::super::codec::value_entry(&mut map, "handling", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.meta {
serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.name {
super::super::codec::value_entry(&mut map, "name", item)?;
}
if !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
if let Some(item) = &self.publisher {
super::super::codec::value_entry(&mut map, "publisher", item)?;
}
if !self.related_artifact.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"relatedArtifact",
&self.related_artifact,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "EvidenceVariable")?;
if !self.reviewer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reviewer", &self.reviewer)?;
}
if let Some(item) = &self.short_title {
super::super::codec::value_entry(&mut map, "shortTitle", item)?;
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if let Some(item) = &self.subtitle {
super::super::codec::value_entry(&mut map, "subtitle", item)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.title {
super::super::codec::value_entry(&mut map, "title", item)?;
}
if let Some(item) = &self.url {
super::super::codec::value_entry(&mut map, "url", item)?;
}
if !self.use_context.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "useContext", &self.use_context)?;
}
if let Some(item) = &self.version {
super::super::codec::value_entry(&mut map, "version", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for EvidenceVariable {
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("EvidenceVariable");
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 EvidenceVariableCategory {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub name: Option<super::primitives::String>,
pub value: Option<EvidenceVariableCategoryValue>,
}
impl super::super::codec::Json for EvidenceVariableCategory {
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.name {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_name"), e);
}
}
if let Some(item) = &self.value {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("value{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_value{suffix}"), element);
}
}
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_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: 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);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"valueCodeableConcept" => {
raw_value.value("CodeableConcept", value, path)?;
}
"_valueCodeableConcept" => {
raw_value.element("CodeableConcept", value, path)?;
}
"valueQuantity" => {
raw_value.value("Quantity", value, path)?;
}
"_valueQuantity" => {
raw_value.element("Quantity", value, path)?;
}
"valueRange" => {
raw_value.value("Range", value, path)?;
}
"_valueRange" => {
raw_value.element("Range", value, path)?;
}
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_name = match (raw_name, raw_name_element) {
(None, None) => None,
(value, element) => Some(path.with("name", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_value = match raw_value.suffix {
None => None,
Some(suffix) => Some(path.with("value", |path| {
EvidenceVariableCategoryValue::from_json_parts(
suffix,
raw_value.value,
raw_value.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
name: field_name,
value: field_value,
})
}
}
impl serde::Serialize for EvidenceVariableCategory {
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.name {
super::super::codec::element_entry(&mut map, "_name", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.name {
super::super::codec::value_entry(&mut map, "name", item)?;
}
match &self.value {
Some(EvidenceVariableCategoryValue::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueCodeableConcept",
inner.as_ref(),
)?;
}
Some(EvidenceVariableCategoryValue::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"valueQuantity",
inner.as_ref(),
)?;
}
Some(EvidenceVariableCategoryValue::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "valueRange", inner.as_ref())?;
}
None => {}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for EvidenceVariableCategory {
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("EvidenceVariableCategory");
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 EvidenceVariableCategoryValue {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Quantity(Box<super::quantity::Quantity>),
Range(Box<super::range::Range>),
}
impl EvidenceVariableCategoryValue {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Quantity(inner) => Ok((
"Quantity",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Range(inner) => Ok((
"Range",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(Box::new(inner)))
}
"Quantity" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Quantity(Box::new(inner)))
}
"Range" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Range(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EvidenceVariableCharacteristic {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub description: Option<super::primitives::String>,
pub definition: EvidenceVariableCharacteristicDefinition,
pub method: Option<super::codeable_concept::CodeableConcept>,
pub device: Option<super::reference::Reference>,
pub exclude: Option<super::primitives::Boolean>,
pub time_from_start: Option<EvidenceVariableCharacteristicTimeFromStart>,
pub group_measure: Option<super::primitives::Code>,
}
impl super::super::codec::Json for EvidenceVariableCharacteristic {
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.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
let (suffix, value, element) = self.definition.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("definition{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_definition{suffix}"), element);
}
if let Some(item) = &self.method {
object.insert(
std::string::String::from("method"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.device {
object.insert(
std::string::String::from("device"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.exclude {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("exclude"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_exclude"), e);
}
}
if let Some(item) = &self.time_from_start {
object.insert(
std::string::String::from("timeFromStart"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.group_measure {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("groupMeasure"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_groupMeasure"), e);
}
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
let mut raw_definition = super::super::codec::ChoiceSlot::default();
let mut raw_method: Option<&super::super::codec::Value> = None;
let mut raw_device: Option<&super::super::codec::Value> = None;
let mut raw_exclude: Option<&super::super::codec::Value> = None;
let mut raw_exclude_element: Option<&super::super::codec::Value> = None;
let mut raw_time_from_start: Option<&super::super::codec::Value> = None;
let mut raw_group_measure: Option<&super::super::codec::Value> = None;
let mut raw_group_measure_element: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"definitionReference" => {
raw_definition.value("Reference", value, path)?;
}
"_definitionReference" => {
raw_definition.element("Reference", value, path)?;
}
"definitionCanonical" => {
raw_definition.value("Canonical", value, path)?;
}
"_definitionCanonical" => {
raw_definition.element("Canonical", value, path)?;
}
"definitionCodeableConcept" => {
raw_definition.value("CodeableConcept", value, path)?;
}
"_definitionCodeableConcept" => {
raw_definition.element("CodeableConcept", value, path)?;
}
"definitionExpression" => {
raw_definition.value("Expression", value, path)?;
}
"_definitionExpression" => {
raw_definition.element("Expression", value, path)?;
}
"method" => {
raw_method = Some(value);
}
"device" => {
raw_device = Some(value);
}
"exclude" => {
raw_exclude = Some(value);
}
"_exclude" => {
raw_exclude_element = Some(value);
}
"timeFromStart" => {
raw_time_from_start = Some(value);
}
"groupMeasure" => {
raw_group_measure = Some(value);
}
"_groupMeasure" => {
raw_group_measure_element = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::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_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_definition = path.with("definition", |path| {
let suffix = raw_definition
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
EvidenceVariableCharacteristicDefinition::from_json_parts(
suffix,
raw_definition.value,
raw_definition.element,
path,
)
})?;
let field_method = raw_method
.map(|value| {
path.with("method", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_device = raw_device
.map(|value| {
path.with("device", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_exclude = match (raw_exclude, raw_exclude_element) {
(None, None) => None,
(value, element) => Some(path.with("exclude", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_time_from_start = raw_time_from_start
.map(|value| {
path.with("timeFromStart", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_group_measure = match (raw_group_measure, raw_group_measure_element) {
(None, None) => None,
(value, element) => Some(path.with("groupMeasure", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
description: field_description,
definition: field_definition,
method: field_method,
device: field_device,
exclude: field_exclude,
time_from_start: field_time_from_start,
group_measure: field_group_measure,
})
}
}
impl serde::Serialize for EvidenceVariableCharacteristic {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let EvidenceVariableCharacteristicDefinition::Canonical(inner) = &self.definition {
super::super::codec::element_entry(&mut map, "_definitionCanonical", inner)?;
}
if let Some(item) = &self.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.exclude {
super::super::codec::element_entry(&mut map, "_exclude", item)?;
}
if let Some(item) = &self.group_measure {
super::super::codec::element_entry(&mut map, "_groupMeasure", item)?;
}
match &self.definition {
EvidenceVariableCharacteristicDefinition::Canonical(inner) => {
super::super::codec::value_entry(&mut map, "definitionCanonical", inner)?;
}
EvidenceVariableCharacteristicDefinition::CodeableConcept(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"definitionCodeableConcept",
inner.as_ref(),
)?;
}
EvidenceVariableCharacteristicDefinition::Expression(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"definitionExpression",
inner.as_ref(),
)?;
}
EvidenceVariableCharacteristicDefinition::Reference(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"definitionReference",
inner.as_ref(),
)?;
}
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if let Some(item) = &self.device {
serde::ser::SerializeMap::serialize_entry(&mut map, "device", item)?;
}
if let Some(item) = &self.exclude {
super::super::codec::value_entry(&mut map, "exclude", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.group_measure {
super::super::codec::value_entry(&mut map, "groupMeasure", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.method {
serde::ser::SerializeMap::serialize_entry(&mut map, "method", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.time_from_start {
serde::ser::SerializeMap::serialize_entry(&mut map, "timeFromStart", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for EvidenceVariableCharacteristic {
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("EvidenceVariableCharacteristic");
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 EvidenceVariableCharacteristicDefinition {
Reference(Box<super::reference::Reference>),
Canonical(super::primitives::Canonical),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Expression(Box<super::expression::Expression>),
}
impl EvidenceVariableCharacteristicDefinition {
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::Canonical(inner) => Ok((
"Canonical",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Expression(inner) => Ok((
"Expression",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"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)))
}
"Canonical" => Ok(Self::Canonical(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"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)))
}
"Expression" => {
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::Expression(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct EvidenceVariableCharacteristicTimeFromStart {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub description: Option<super::primitives::String>,
pub quantity: Option<super::quantity::Quantity>,
pub range: Option<super::range::Range>,
pub note: Vec<super::annotation::Annotation>,
}
impl super::super::codec::Json for EvidenceVariableCharacteristicTimeFromStart {
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.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
if let Some(item) = &self.quantity {
object.insert(
std::string::String::from("quantity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.range {
object.insert(
std::string::String::from("range"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.note.is_empty() {
let mut items = Vec::with_capacity(self.note.len());
for item in &self.note {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("note"),
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_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
let mut raw_quantity: Option<&super::super::codec::Value> = None;
let mut raw_range: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"quantity" => {
raw_quantity = Some(value);
}
"range" => {
raw_range = Some(value);
}
"note" => {
raw_note = 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_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_quantity = raw_quantity
.map(|value| {
path.with("quantity", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_range = raw_range
.map(|value| {
path.with("range", |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_note = Vec::new();
if let Some(raw) = raw_note {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_note.push(path.with_index("note", 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,
description: field_description,
quantity: field_quantity,
range: field_range,
note: field_note,
})
}
}
impl serde::Serialize for EvidenceVariableCharacteristicTimeFromStart {
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.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
if let Some(item) = &self.quantity {
serde::ser::SerializeMap::serialize_entry(&mut map, "quantity", item)?;
}
if let Some(item) = &self.range {
serde::ser::SerializeMap::serialize_entry(&mut map, "range", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for EvidenceVariableCharacteristicTimeFromStart {
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("EvidenceVariableCharacteristicTimeFromStart");
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)
}
}