#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Citation {
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 version_algorithm: Option<CitationVersionAlgorithm>,
pub name: Option<super::primitives::String>,
pub title: Option<super::primitives::String>,
pub status: super::primitives::Code,
pub experimental: Option<super::primitives::Boolean>,
pub date: Option<super::primitives::DateTime>,
pub publisher: Option<super::primitives::String>,
pub contact: Vec<super::contact_detail::ContactDetail>,
pub description: Option<super::primitives::Markdown>,
pub use_context: Vec<super::usage_context::UsageContext>,
pub jurisdiction: Vec<super::codeable_concept::CodeableConcept>,
pub purpose: Option<super::primitives::Markdown>,
pub copyright: Option<super::primitives::Markdown>,
pub copyright_label: Option<super::primitives::String>,
pub approval_date: Option<super::primitives::Date>,
pub last_review_date: Option<super::primitives::Date>,
pub effective_period: Option<super::period::Period>,
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 summary: Vec<CitationSummary>,
pub classification: Vec<CitationClassification>,
pub note: Vec<super::annotation::Annotation>,
pub current_state: Vec<super::codeable_concept::CodeableConcept>,
pub status_date: Vec<CitationStatusDate>,
pub related_artifact: Vec<super::related_artifact::RelatedArtifact>,
pub cited_artifact: Option<CitationCitedArtifact>,
}
impl super::super::codec::Json for Citation {
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("Citation")),
);
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.version_algorithm {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("versionAlgorithm{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_versionAlgorithm{suffix}"), element);
}
}
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(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.experimental {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("experimental"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_experimental"), 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.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 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.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 !self.jurisdiction.is_empty() {
let mut items = Vec::with_capacity(self.jurisdiction.len());
for item in &self.jurisdiction {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("jurisdiction"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.purpose {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("purpose"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_purpose"), e);
}
}
if let Some(item) = &self.copyright {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("copyright"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_copyright"), e);
}
}
if let Some(item) = &self.copyright_label {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("copyrightLabel"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_copyrightLabel"), e);
}
}
if let Some(item) = &self.approval_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("approvalDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_approvalDate"), e);
}
}
if let Some(item) = &self.last_review_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("lastReviewDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_lastReviewDate"), e);
}
}
if let Some(item) = &self.effective_period {
object.insert(
std::string::String::from("effectivePeriod"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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.summary.is_empty() {
let mut items = Vec::with_capacity(self.summary.len());
for item in &self.summary {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("summary"),
super::super::codec::Value::Array(items),
);
}
if !self.classification.is_empty() {
let mut items = Vec::with_capacity(self.classification.len());
for item in &self.classification {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("classification"),
super::super::codec::Value::Array(items),
);
}
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.current_state.is_empty() {
let mut items = Vec::with_capacity(self.current_state.len());
for item in &self.current_state {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("currentState"),
super::super::codec::Value::Array(items),
);
}
if !self.status_date.is_empty() {
let mut items = Vec::with_capacity(self.status_date.len());
for item in &self.status_date {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("statusDate"),
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.cited_artifact {
object.insert(
std::string::String::from("citedArtifact"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_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_version_algorithm = super::super::codec::ChoiceSlot::default();
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_status: Option<&super::super::codec::Value> = None;
let mut raw_status_element: Option<&super::super::codec::Value> = None;
let mut raw_experimental: Option<&super::super::codec::Value> = None;
let mut raw_experimental_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_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_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
let mut raw_use_context: Option<&super::super::codec::Value> = None;
let mut raw_jurisdiction: Option<&super::super::codec::Value> = None;
let mut raw_purpose: Option<&super::super::codec::Value> = None;
let mut raw_purpose_element: Option<&super::super::codec::Value> = None;
let mut raw_copyright: Option<&super::super::codec::Value> = None;
let mut raw_copyright_element: Option<&super::super::codec::Value> = None;
let mut raw_copyright_label: Option<&super::super::codec::Value> = None;
let mut raw_copyright_label_element: Option<&super::super::codec::Value> = None;
let mut raw_approval_date: Option<&super::super::codec::Value> = None;
let mut raw_approval_date_element: Option<&super::super::codec::Value> = None;
let mut raw_last_review_date: Option<&super::super::codec::Value> = None;
let mut raw_last_review_date_element: Option<&super::super::codec::Value> = None;
let mut raw_effective_period: 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_summary: Option<&super::super::codec::Value> = None;
let mut raw_classification: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_current_state: Option<&super::super::codec::Value> = None;
let mut raw_status_date: Option<&super::super::codec::Value> = None;
let mut raw_related_artifact: Option<&super::super::codec::Value> = None;
let mut raw_cited_artifact: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("Citation") {
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);
}
"versionAlgorithmString" => {
raw_version_algorithm.value("String", value, path)?;
}
"_versionAlgorithmString" => {
raw_version_algorithm.element("String", value, path)?;
}
"versionAlgorithmCoding" => {
raw_version_algorithm.value("Coding", value, path)?;
}
"_versionAlgorithmCoding" => {
raw_version_algorithm.element("Coding", value, path)?;
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"title" => {
raw_title = Some(value);
}
"_title" => {
raw_title_element = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"experimental" => {
raw_experimental = Some(value);
}
"_experimental" => {
raw_experimental_element = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_element = Some(value);
}
"publisher" => {
raw_publisher = Some(value);
}
"_publisher" => {
raw_publisher_element = Some(value);
}
"contact" => {
raw_contact = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"useContext" => {
raw_use_context = Some(value);
}
"jurisdiction" => {
raw_jurisdiction = Some(value);
}
"purpose" => {
raw_purpose = Some(value);
}
"_purpose" => {
raw_purpose_element = Some(value);
}
"copyright" => {
raw_copyright = Some(value);
}
"_copyright" => {
raw_copyright_element = Some(value);
}
"copyrightLabel" => {
raw_copyright_label = Some(value);
}
"_copyrightLabel" => {
raw_copyright_label_element = Some(value);
}
"approvalDate" => {
raw_approval_date = Some(value);
}
"_approvalDate" => {
raw_approval_date_element = Some(value);
}
"lastReviewDate" => {
raw_last_review_date = Some(value);
}
"_lastReviewDate" => {
raw_last_review_date_element = Some(value);
}
"effectivePeriod" => {
raw_effective_period = Some(value);
}
"author" => {
raw_author = Some(value);
}
"editor" => {
raw_editor = Some(value);
}
"reviewer" => {
raw_reviewer = Some(value);
}
"endorser" => {
raw_endorser = Some(value);
}
"summary" => {
raw_summary = Some(value);
}
"classification" => {
raw_classification = Some(value);
}
"note" => {
raw_note = Some(value);
}
"currentState" => {
raw_current_state = Some(value);
}
"statusDate" => {
raw_status_date = Some(value);
}
"relatedArtifact" => {
raw_related_artifact = Some(value);
}
"citedArtifact" => {
raw_cited_artifact = 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_version_algorithm = match raw_version_algorithm.suffix {
None => None,
Some(suffix) => Some(path.with("versionAlgorithm", |path| {
CitationVersionAlgorithm::from_json_parts(
suffix,
raw_version_algorithm.value,
raw_version_algorithm.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_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
let field_experimental = match (raw_experimental, raw_experimental_element) {
(None, None) => None,
(value, element) => Some(path.with("experimental", |path| {
super::super::codec::Primitive::from_json_parts(value, 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_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 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_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 mut field_jurisdiction = Vec::new();
if let Some(raw) = raw_jurisdiction {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_jurisdiction.push(path.with_index("jurisdiction", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_purpose = match (raw_purpose, raw_purpose_element) {
(None, None) => None,
(value, element) => Some(path.with("purpose", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_copyright = match (raw_copyright, raw_copyright_element) {
(None, None) => None,
(value, element) => Some(path.with("copyright", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_copyright_label = match (raw_copyright_label, raw_copyright_label_element) {
(None, None) => None,
(value, element) => Some(path.with("copyrightLabel", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_approval_date = match (raw_approval_date, raw_approval_date_element) {
(None, None) => None,
(value, element) => Some(path.with("approvalDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_last_review_date = match (raw_last_review_date, raw_last_review_date_element) {
(None, None) => None,
(value, element) => Some(path.with("lastReviewDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_effective_period = raw_effective_period
.map(|value| {
path.with("effectivePeriod", |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_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_summary = Vec::new();
if let Some(raw) = raw_summary {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_summary.push(path.with_index("summary", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_classification = Vec::new();
if let Some(raw) = raw_classification {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_classification.push(path.with_index("classification", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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_current_state = Vec::new();
if let Some(raw) = raw_current_state {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_current_state.push(path.with_index("currentState", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_status_date = Vec::new();
if let Some(raw) = raw_status_date {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_status_date.push(path.with_index("statusDate", 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_cited_artifact = raw_cited_artifact
.map(|value| {
path.with("citedArtifact", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
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,
version_algorithm: field_version_algorithm,
name: field_name,
title: field_title,
status: field_status,
experimental: field_experimental,
date: field_date,
publisher: field_publisher,
contact: field_contact,
description: field_description,
use_context: field_use_context,
jurisdiction: field_jurisdiction,
purpose: field_purpose,
copyright: field_copyright,
copyright_label: field_copyright_label,
approval_date: field_approval_date,
last_review_date: field_last_review_date,
effective_period: field_effective_period,
author: field_author,
editor: field_editor,
reviewer: field_reviewer,
endorser: field_endorser,
summary: field_summary,
classification: field_classification,
note: field_note,
current_state: field_current_state,
status_date: field_status_date,
related_artifact: field_related_artifact,
cited_artifact: field_cited_artifact,
})
}
}
impl serde::Serialize for Citation {
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.approval_date {
super::super::codec::element_entry(&mut map, "_approvalDate", item)?;
}
if let Some(item) = &self.copyright {
super::super::codec::element_entry(&mut map, "_copyright", item)?;
}
if let Some(item) = &self.copyright_label {
super::super::codec::element_entry(&mut map, "_copyrightLabel", 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.experimental {
super::super::codec::element_entry(&mut map, "_experimental", 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.last_review_date {
super::super::codec::element_entry(&mut map, "_lastReviewDate", 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.purpose {
super::super::codec::element_entry(&mut map, "_purpose", item)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
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(CitationVersionAlgorithm::String(inner)) = &self.version_algorithm {
super::super::codec::element_entry(&mut map, "_versionAlgorithmString", inner)?;
}
if let Some(item) = &self.approval_date {
super::super::codec::value_entry(&mut map, "approvalDate", item)?;
}
if !self.author.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "author", &self.author)?;
}
if let Some(item) = &self.cited_artifact {
serde::ser::SerializeMap::serialize_entry(&mut map, "citedArtifact", item)?;
}
if !self.classification.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"classification",
&self.classification,
)?;
}
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.copyright {
super::super::codec::value_entry(&mut map, "copyright", item)?;
}
if let Some(item) = &self.copyright_label {
super::super::codec::value_entry(&mut map, "copyrightLabel", item)?;
}
if !self.current_state.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"currentState",
&self.current_state,
)?;
}
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 let Some(item) = &self.effective_period {
serde::ser::SerializeMap::serialize_entry(&mut map, "effectivePeriod", item)?;
}
if !self.endorser.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "endorser", &self.endorser)?;
}
if let Some(item) = &self.experimental {
super::super::codec::value_entry(&mut map, "experimental", 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.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 !self.jurisdiction.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"jurisdiction",
&self.jurisdiction,
)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.last_review_date {
super::super::codec::value_entry(&mut map, "lastReviewDate", 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 let Some(item) = &self.purpose {
super::super::codec::value_entry(&mut map, "purpose", 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", "Citation")?;
if !self.reviewer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reviewer", &self.reviewer)?;
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if !self.status_date.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "statusDate", &self.status_date)?;
}
if !self.summary.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "summary", &self.summary)?;
}
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)?;
}
match &self.version_algorithm {
Some(CitationVersionAlgorithm::Coding(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"versionAlgorithmCoding",
inner.as_ref(),
)?;
}
Some(CitationVersionAlgorithm::String(inner)) => {
super::super::codec::value_entry(&mut map, "versionAlgorithmString", inner)?;
}
None => {}
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Citation {
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("Citation");
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 CitationCitedArtifact {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub identifier: Vec<super::identifier::Identifier>,
pub related_identifier: Vec<super::identifier::Identifier>,
pub date_accessed: Option<super::primitives::DateTime>,
pub version: Option<CitationCitedArtifactVersion>,
pub current_state: Vec<super::codeable_concept::CodeableConcept>,
pub status_date: Vec<CitationCitedArtifactStatusDate>,
pub title: Vec<CitationCitedArtifactTitle>,
pub r#abstract: Vec<CitationCitedArtifactAbstract>,
pub part: Option<CitationCitedArtifactPart>,
pub relates_to: Vec<CitationCitedArtifactRelatesTo>,
pub publication_form: Vec<CitationCitedArtifactPublicationForm>,
pub web_location: Vec<CitationCitedArtifactWebLocation>,
pub classification: Vec<CitationCitedArtifactClassification>,
pub contributorship: Option<CitationCitedArtifactContributorship>,
pub note: Vec<super::annotation::Annotation>,
}
impl super::super::codec::Json for CitationCitedArtifact {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.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 !self.related_identifier.is_empty() {
let mut items = Vec::with_capacity(self.related_identifier.len());
for item in &self.related_identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("relatedIdentifier"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.date_accessed {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("dateAccessed"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_dateAccessed"), e);
}
}
if let Some(item) = &self.version {
object.insert(
std::string::String::from("version"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.current_state.is_empty() {
let mut items = Vec::with_capacity(self.current_state.len());
for item in &self.current_state {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("currentState"),
super::super::codec::Value::Array(items),
);
}
if !self.status_date.is_empty() {
let mut items = Vec::with_capacity(self.status_date.len());
for item in &self.status_date {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("statusDate"),
super::super::codec::Value::Array(items),
);
}
if !self.title.is_empty() {
let mut items = Vec::with_capacity(self.title.len());
for item in &self.title {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("title"),
super::super::codec::Value::Array(items),
);
}
if !self.r#abstract.is_empty() {
let mut items = Vec::with_capacity(self.r#abstract.len());
for item in &self.r#abstract {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("abstract"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.part {
object.insert(
std::string::String::from("part"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.relates_to.is_empty() {
let mut items = Vec::with_capacity(self.relates_to.len());
for item in &self.relates_to {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("relatesTo"),
super::super::codec::Value::Array(items),
);
}
if !self.publication_form.is_empty() {
let mut items = Vec::with_capacity(self.publication_form.len());
for item in &self.publication_form {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("publicationForm"),
super::super::codec::Value::Array(items),
);
}
if !self.web_location.is_empty() {
let mut items = Vec::with_capacity(self.web_location.len());
for item in &self.web_location {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("webLocation"),
super::super::codec::Value::Array(items),
);
}
if !self.classification.is_empty() {
let mut items = Vec::with_capacity(self.classification.len());
for item in &self.classification {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("classification"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.contributorship {
object.insert(
std::string::String::from("contributorship"),
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_identifier: Option<&super::super::codec::Value> = None;
let mut raw_related_identifier: Option<&super::super::codec::Value> = None;
let mut raw_date_accessed: Option<&super::super::codec::Value> = None;
let mut raw_date_accessed_element: Option<&super::super::codec::Value> = None;
let mut raw_version: Option<&super::super::codec::Value> = None;
let mut raw_current_state: Option<&super::super::codec::Value> = None;
let mut raw_status_date: Option<&super::super::codec::Value> = None;
let mut raw_title: Option<&super::super::codec::Value> = None;
let mut raw_abstract: Option<&super::super::codec::Value> = None;
let mut raw_part: Option<&super::super::codec::Value> = None;
let mut raw_relates_to: Option<&super::super::codec::Value> = None;
let mut raw_publication_form: Option<&super::super::codec::Value> = None;
let mut raw_web_location: Option<&super::super::codec::Value> = None;
let mut raw_classification: Option<&super::super::codec::Value> = None;
let mut raw_contributorship: 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);
}
"identifier" => {
raw_identifier = Some(value);
}
"relatedIdentifier" => {
raw_related_identifier = Some(value);
}
"dateAccessed" => {
raw_date_accessed = Some(value);
}
"_dateAccessed" => {
raw_date_accessed_element = Some(value);
}
"version" => {
raw_version = Some(value);
}
"currentState" => {
raw_current_state = Some(value);
}
"statusDate" => {
raw_status_date = Some(value);
}
"title" => {
raw_title = Some(value);
}
"abstract" => {
raw_abstract = Some(value);
}
"part" => {
raw_part = Some(value);
}
"relatesTo" => {
raw_relates_to = Some(value);
}
"publicationForm" => {
raw_publication_form = Some(value);
}
"webLocation" => {
raw_web_location = Some(value);
}
"classification" => {
raw_classification = Some(value);
}
"contributorship" => {
raw_contributorship = 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 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 mut field_related_identifier = Vec::new();
if let Some(raw) = raw_related_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_related_identifier.push(path.with_index(
"relatedIdentifier",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_date_accessed = match (raw_date_accessed, raw_date_accessed_element) {
(None, None) => None,
(value, element) => Some(path.with("dateAccessed", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_version = raw_version
.map(|value| {
path.with("version", |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_current_state = Vec::new();
if let Some(raw) = raw_current_state {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_current_state.push(path.with_index("currentState", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_status_date = Vec::new();
if let Some(raw) = raw_status_date {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_status_date.push(path.with_index("statusDate", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_title = Vec::new();
if let Some(raw) = raw_title {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_title.push(path.with_index("title", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_abstract = Vec::new();
if let Some(raw) = raw_abstract {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_abstract.push(path.with_index("abstract", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_part = raw_part
.map(|value| {
path.with("part", |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_relates_to = Vec::new();
if let Some(raw) = raw_relates_to {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_relates_to.push(path.with_index("relatesTo", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_publication_form = Vec::new();
if let Some(raw) = raw_publication_form {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_publication_form.push(path.with_index("publicationForm", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_web_location = Vec::new();
if let Some(raw) = raw_web_location {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_web_location.push(path.with_index("webLocation", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_classification = Vec::new();
if let Some(raw) = raw_classification {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_classification.push(path.with_index("classification", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_contributorship = raw_contributorship
.map(|value| {
path.with("contributorship", |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,
identifier: field_identifier,
related_identifier: field_related_identifier,
date_accessed: field_date_accessed,
version: field_version,
current_state: field_current_state,
status_date: field_status_date,
title: field_title,
r#abstract: field_abstract,
part: field_part,
relates_to: field_relates_to,
publication_form: field_publication_form,
web_location: field_web_location,
classification: field_classification,
contributorship: field_contributorship,
note: field_note,
})
}
}
impl serde::Serialize for CitationCitedArtifact {
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.date_accessed {
super::super::codec::element_entry(&mut map, "_dateAccessed", item)?;
}
if !self.r#abstract.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "abstract", &self.r#abstract)?;
}
if !self.classification.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"classification",
&self.classification,
)?;
}
if let Some(item) = &self.contributorship {
serde::ser::SerializeMap::serialize_entry(&mut map, "contributorship", item)?;
}
if !self.current_state.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"currentState",
&self.current_state,
)?;
}
if let Some(item) = &self.date_accessed {
super::super::codec::value_entry(&mut map, "dateAccessed", 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.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
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.part {
serde::ser::SerializeMap::serialize_entry(&mut map, "part", item)?;
}
if !self.publication_form.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"publicationForm",
&self.publication_form,
)?;
}
if !self.related_identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"relatedIdentifier",
&self.related_identifier,
)?;
}
if !self.relates_to.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "relatesTo", &self.relates_to)?;
}
if !self.status_date.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "statusDate", &self.status_date)?;
}
if !self.title.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "title", &self.title)?;
}
if let Some(item) = &self.version {
serde::ser::SerializeMap::serialize_entry(&mut map, "version", item)?;
}
if !self.web_location.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "webLocation", &self.web_location)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifact {
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("CitationCitedArtifact");
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 CitationCitedArtifactAbstract {
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 language: Option<super::codeable_concept::CodeableConcept>,
pub text: super::primitives::Markdown,
pub copyright: Option<super::primitives::Markdown>,
}
impl super::super::codec::Json for CitationCitedArtifactAbstract {
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 let Some(item) = &self.language {
object.insert(
std::string::String::from("language"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.text)? {
object.insert(std::string::String::from("text"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.text)? {
object.insert(std::string::String::from("_text"), e);
}
if let Some(item) = &self.copyright {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("copyright"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_copyright"), 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_type: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_text_element: Option<&super::super::codec::Value> = None;
let mut raw_copyright: Option<&super::super::codec::Value> = None;
let mut raw_copyright_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);
}
"type" => {
raw_type = Some(value);
}
"language" => {
raw_language = Some(value);
}
"text" => {
raw_text = Some(value);
}
"_text" => {
raw_text_element = Some(value);
}
"copyright" => {
raw_copyright = Some(value);
}
"_copyright" => {
raw_copyright_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_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 field_language = raw_language
.map(|value| {
path.with("language", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_text = path.with("text", |path| {
super::super::codec::Primitive::from_json_parts(raw_text, raw_text_element, path)
})?;
let field_copyright = match (raw_copyright, raw_copyright_element) {
(None, None) => None,
(value, element) => Some(path.with("copyright", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
language: field_language,
text: field_text,
copyright: field_copyright,
})
}
}
impl serde::Serialize for CitationCitedArtifactAbstract {
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.copyright {
super::super::codec::element_entry(&mut map, "_copyright", item)?;
}
super::super::codec::element_entry(&mut map, "_text", &self.text)?;
if let Some(item) = &self.copyright {
super::super::codec::value_entry(&mut map, "copyright", 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 let Some(item) = &self.language {
serde::ser::SerializeMap::serialize_entry(&mut map, "language", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
super::super::codec::value_entry(&mut map, "text", &self.text)?;
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactAbstract {
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("CitationCitedArtifactAbstract");
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 CitationCitedArtifactClassification {
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 classifier: Vec<super::codeable_concept::CodeableConcept>,
pub artifact_assessment: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for CitationCitedArtifactClassification {
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.classifier.is_empty() {
let mut items = Vec::with_capacity(self.classifier.len());
for item in &self.classifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("classifier"),
super::super::codec::Value::Array(items),
);
}
if !self.artifact_assessment.is_empty() {
let mut items = Vec::with_capacity(self.artifact_assessment.len());
for item in &self.artifact_assessment {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("artifactAssessment"),
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_classifier: Option<&super::super::codec::Value> = None;
let mut raw_artifact_assessment: 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);
}
"classifier" => {
raw_classifier = Some(value);
}
"artifactAssessment" => {
raw_artifact_assessment = 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_classifier = Vec::new();
if let Some(raw) = raw_classifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_classifier.push(path.with_index("classifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_artifact_assessment = Vec::new();
if let Some(raw) = raw_artifact_assessment {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_artifact_assessment.push(path.with_index(
"artifactAssessment",
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,
classifier: field_classifier,
artifact_assessment: field_artifact_assessment,
})
}
}
impl serde::Serialize for CitationCitedArtifactClassification {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.artifact_assessment.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"artifactAssessment",
&self.artifact_assessment,
)?;
}
if !self.classifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "classifier", &self.classifier)?;
}
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.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactClassification {
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("CitationCitedArtifactClassification");
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 CitationCitedArtifactContributorship {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub complete: Option<super::primitives::Boolean>,
pub entry: Vec<CitationCitedArtifactContributorshipEntry>,
pub summary: Vec<CitationCitedArtifactContributorshipSummary>,
}
impl super::super::codec::Json for CitationCitedArtifactContributorship {
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.complete {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("complete"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_complete"), e);
}
}
if !self.entry.is_empty() {
let mut items = Vec::with_capacity(self.entry.len());
for item in &self.entry {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("entry"),
super::super::codec::Value::Array(items),
);
}
if !self.summary.is_empty() {
let mut items = Vec::with_capacity(self.summary.len());
for item in &self.summary {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("summary"),
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_complete: Option<&super::super::codec::Value> = None;
let mut raw_complete_element: Option<&super::super::codec::Value> = None;
let mut raw_entry: Option<&super::super::codec::Value> = None;
let mut raw_summary: 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);
}
"complete" => {
raw_complete = Some(value);
}
"_complete" => {
raw_complete_element = Some(value);
}
"entry" => {
raw_entry = Some(value);
}
"summary" => {
raw_summary = 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_complete = match (raw_complete, raw_complete_element) {
(None, None) => None,
(value, element) => Some(path.with("complete", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_entry = Vec::new();
if let Some(raw) = raw_entry {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_entry.push(path.with_index("entry", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_summary = Vec::new();
if let Some(raw) = raw_summary {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_summary.push(path.with_index("summary", 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,
complete: field_complete,
entry: field_entry,
summary: field_summary,
})
}
}
impl serde::Serialize for CitationCitedArtifactContributorship {
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.complete {
super::super::codec::element_entry(&mut map, "_complete", item)?;
}
if let Some(item) = &self.complete {
super::super::codec::value_entry(&mut map, "complete", item)?;
}
if !self.entry.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "entry", &self.entry)?;
}
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.summary.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "summary", &self.summary)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactContributorship {
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("CitationCitedArtifactContributorship");
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 CitationCitedArtifactContributorshipEntry {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub contributor: super::reference::Reference,
pub forename_initials: Option<super::primitives::String>,
pub affiliation: Vec<super::reference::Reference>,
pub contribution_type: Vec<super::codeable_concept::CodeableConcept>,
pub role: Option<super::codeable_concept::CodeableConcept>,
pub contribution_instance: Vec<CitationCitedArtifactContributorshipEntryContributionInstance>,
pub corresponding_contact: Option<super::primitives::Boolean>,
pub ranking_order: Option<super::primitives::PositiveInt>,
}
impl super::super::codec::Json for CitationCitedArtifactContributorshipEntry {
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("contributor"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.contributor,
)?),
);
if let Some(item) = &self.forename_initials {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("forenameInitials"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_forenameInitials"), e);
}
}
if !self.affiliation.is_empty() {
let mut items = Vec::with_capacity(self.affiliation.len());
for item in &self.affiliation {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("affiliation"),
super::super::codec::Value::Array(items),
);
}
if !self.contribution_type.is_empty() {
let mut items = Vec::with_capacity(self.contribution_type.len());
for item in &self.contribution_type {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contributionType"),
super::super::codec::Value::Array(items),
);
}
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.contribution_instance.is_empty() {
let mut items = Vec::with_capacity(self.contribution_instance.len());
for item in &self.contribution_instance {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contributionInstance"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.corresponding_contact {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("correspondingContact"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_correspondingContact"), e);
}
}
if let Some(item) = &self.ranking_order {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("rankingOrder"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_rankingOrder"), 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_contributor: Option<&super::super::codec::Value> = None;
let mut raw_forename_initials: Option<&super::super::codec::Value> = None;
let mut raw_forename_initials_element: Option<&super::super::codec::Value> = None;
let mut raw_affiliation: Option<&super::super::codec::Value> = None;
let mut raw_contribution_type: Option<&super::super::codec::Value> = None;
let mut raw_role: Option<&super::super::codec::Value> = None;
let mut raw_contribution_instance: Option<&super::super::codec::Value> = None;
let mut raw_corresponding_contact: Option<&super::super::codec::Value> = None;
let mut raw_corresponding_contact_element: Option<&super::super::codec::Value> = None;
let mut raw_ranking_order: Option<&super::super::codec::Value> = None;
let mut raw_ranking_order_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);
}
"contributor" => {
raw_contributor = Some(value);
}
"forenameInitials" => {
raw_forename_initials = Some(value);
}
"_forenameInitials" => {
raw_forename_initials_element = Some(value);
}
"affiliation" => {
raw_affiliation = Some(value);
}
"contributionType" => {
raw_contribution_type = Some(value);
}
"role" => {
raw_role = Some(value);
}
"contributionInstance" => {
raw_contribution_instance = Some(value);
}
"correspondingContact" => {
raw_corresponding_contact = Some(value);
}
"_correspondingContact" => {
raw_corresponding_contact_element = Some(value);
}
"rankingOrder" => {
raw_ranking_order = Some(value);
}
"_rankingOrder" => {
raw_ranking_order_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_contributor = path.with("contributor", |path| {
let value = raw_contributor
.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_forename_initials = match (raw_forename_initials, raw_forename_initials_element) {
(None, None) => None,
(value, element) => Some(path.with("forenameInitials", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_affiliation = Vec::new();
if let Some(raw) = raw_affiliation {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_affiliation.push(path.with_index("affiliation", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_contribution_type = Vec::new();
if let Some(raw) = raw_contribution_type {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contribution_type.push(path.with_index(
"contributionType",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
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_contribution_instance = Vec::new();
if let Some(raw) = raw_contribution_instance {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contribution_instance.push(path.with_index(
"contributionInstance",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_corresponding_contact =
match (raw_corresponding_contact, raw_corresponding_contact_element) {
(None, None) => None,
(value, element) => Some(path.with("correspondingContact", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_ranking_order = match (raw_ranking_order, raw_ranking_order_element) {
(None, None) => None,
(value, element) => Some(path.with("rankingOrder", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
contributor: field_contributor,
forename_initials: field_forename_initials,
affiliation: field_affiliation,
contribution_type: field_contribution_type,
role: field_role,
contribution_instance: field_contribution_instance,
corresponding_contact: field_corresponding_contact,
ranking_order: field_ranking_order,
})
}
}
impl serde::Serialize for CitationCitedArtifactContributorshipEntry {
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.corresponding_contact {
super::super::codec::element_entry(&mut map, "_correspondingContact", item)?;
}
if let Some(item) = &self.forename_initials {
super::super::codec::element_entry(&mut map, "_forenameInitials", item)?;
}
if let Some(item) = &self.ranking_order {
super::super::codec::element_entry(&mut map, "_rankingOrder", item)?;
}
if !self.affiliation.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "affiliation", &self.affiliation)?;
}
if !self.contribution_instance.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"contributionInstance",
&self.contribution_instance,
)?;
}
if !self.contribution_type.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"contributionType",
&self.contribution_type,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "contributor", &self.contributor)?;
if let Some(item) = &self.corresponding_contact {
super::super::codec::value_entry(&mut map, "correspondingContact", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.forename_initials {
super::super::codec::value_entry(&mut map, "forenameInitials", item)?;
}
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.ranking_order {
super::super::codec::value_entry(&mut map, "rankingOrder", item)?;
}
if let Some(item) = &self.role {
serde::ser::SerializeMap::serialize_entry(&mut map, "role", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactContributorshipEntry {
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("CitationCitedArtifactContributorshipEntry");
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 CitationCitedArtifactContributorshipEntryContributionInstance {
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 time: Option<super::primitives::DateTime>,
}
impl super::super::codec::Json for CitationCitedArtifactContributorshipEntryContributionInstance {
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)?),
);
if let Some(item) = &self.time {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("time"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_time"), 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_type: Option<&super::super::codec::Value> = None;
let mut raw_time: Option<&super::super::codec::Value> = None;
let mut raw_time_element: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"type" => {
raw_type = Some(value);
}
"time" => {
raw_time = Some(value);
}
"_time" => {
raw_time_element = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::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_time = match (raw_time, raw_time_element) {
(None, None) => None,
(value, element) => Some(path.with("time", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
time: field_time,
})
}
}
impl serde::Serialize for CitationCitedArtifactContributorshipEntryContributionInstance {
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.time {
super::super::codec::element_entry(&mut map, "_time", 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.time {
super::super::codec::value_entry(&mut map, "time", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de>
for CitationCitedArtifactContributorshipEntryContributionInstance
{
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(
"CitationCitedArtifactContributorshipEntryContributionInstance",
);
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 CitationCitedArtifactContributorshipSummary {
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 style: Option<super::codeable_concept::CodeableConcept>,
pub source: Option<super::codeable_concept::CodeableConcept>,
pub value: super::primitives::Markdown,
}
impl super::super::codec::Json for CitationCitedArtifactContributorshipSummary {
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 let Some(item) = &self.style {
object.insert(
std::string::String::from("style"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.source {
object.insert(
std::string::String::from("source"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.value)? {
object.insert(std::string::String::from("value"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.value)? {
object.insert(std::string::String::from("_value"), 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_type: Option<&super::super::codec::Value> = None;
let mut raw_style: Option<&super::super::codec::Value> = None;
let mut raw_source: Option<&super::super::codec::Value> = None;
let mut raw_value: Option<&super::super::codec::Value> = None;
let mut raw_value_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);
}
"type" => {
raw_type = Some(value);
}
"style" => {
raw_style = Some(value);
}
"source" => {
raw_source = Some(value);
}
"value" => {
raw_value = Some(value);
}
"_value" => {
raw_value_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_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 field_style = raw_style
.map(|value| {
path.with("style", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_source = raw_source
.map(|value| {
path.with("source", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_value = path.with("value", |path| {
super::super::codec::Primitive::from_json_parts(raw_value, raw_value_element, path)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
style: field_style,
source: field_source,
value: field_value,
})
}
}
impl serde::Serialize for CitationCitedArtifactContributorshipSummary {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_value", &self.value)?;
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.source {
serde::ser::SerializeMap::serialize_entry(&mut map, "source", item)?;
}
if let Some(item) = &self.style {
serde::ser::SerializeMap::serialize_entry(&mut map, "style", item)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
super::super::codec::value_entry(&mut map, "value", &self.value)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactContributorshipSummary {
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("CitationCitedArtifactContributorshipSummary");
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 CitationCitedArtifactPart {
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 value: Option<super::primitives::String>,
pub base_citation: Option<super::reference::Reference>,
}
impl super::super::codec::Json for CitationCitedArtifactPart {
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 let Some(item) = &self.value {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("value"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_value"), e);
}
}
if let Some(item) = &self.base_citation {
object.insert(
std::string::String::from("baseCitation"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_value: Option<&super::super::codec::Value> = None;
let mut raw_value_element: Option<&super::super::codec::Value> = None;
let mut raw_base_citation: 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);
}
"value" => {
raw_value = Some(value);
}
"_value" => {
raw_value_element = Some(value);
}
"baseCitation" => {
raw_base_citation = 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 field_value = match (raw_value, raw_value_element) {
(None, None) => None,
(value, element) => Some(path.with("value", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_base_citation = raw_base_citation
.map(|value| {
path.with("baseCitation", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
value: field_value,
base_citation: field_base_citation,
})
}
}
impl serde::Serialize for CitationCitedArtifactPart {
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.value {
super::super::codec::element_entry(&mut map, "_value", item)?;
}
if let Some(item) = &self.base_citation {
serde::ser::SerializeMap::serialize_entry(&mut map, "baseCitation", 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.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
if let Some(item) = &self.value {
super::super::codec::value_entry(&mut map, "value", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactPart {
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("CitationCitedArtifactPart");
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 CitationCitedArtifactPublicationForm {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub published_in: Option<CitationCitedArtifactPublicationFormPublishedIn>,
pub cited_medium: Option<super::codeable_concept::CodeableConcept>,
pub volume: Option<super::primitives::String>,
pub issue: Option<super::primitives::String>,
pub article_date: Option<super::primitives::DateTime>,
pub publication_date_text: Option<super::primitives::String>,
pub publication_date_season: Option<super::primitives::String>,
pub last_revision_date: Option<super::primitives::DateTime>,
pub language: Vec<super::codeable_concept::CodeableConcept>,
pub accession_number: Option<super::primitives::String>,
pub page_string: Option<super::primitives::String>,
pub first_page: Option<super::primitives::String>,
pub last_page: Option<super::primitives::String>,
pub page_count: Option<super::primitives::String>,
pub copyright: Option<super::primitives::Markdown>,
}
impl super::super::codec::Json for CitationCitedArtifactPublicationForm {
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.published_in {
object.insert(
std::string::String::from("publishedIn"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.cited_medium {
object.insert(
std::string::String::from("citedMedium"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.volume {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("volume"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_volume"), e);
}
}
if let Some(item) = &self.issue {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("issue"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_issue"), e);
}
}
if let Some(item) = &self.article_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("articleDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_articleDate"), e);
}
}
if let Some(item) = &self.publication_date_text {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("publicationDateText"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_publicationDateText"), e);
}
}
if let Some(item) = &self.publication_date_season {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("publicationDateSeason"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_publicationDateSeason"), e);
}
}
if let Some(item) = &self.last_revision_date {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("lastRevisionDate"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_lastRevisionDate"), e);
}
}
if !self.language.is_empty() {
let mut items = Vec::with_capacity(self.language.len());
for item in &self.language {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("language"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.accession_number {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("accessionNumber"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_accessionNumber"), e);
}
}
if let Some(item) = &self.page_string {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("pageString"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_pageString"), e);
}
}
if let Some(item) = &self.first_page {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("firstPage"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_firstPage"), e);
}
}
if let Some(item) = &self.last_page {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("lastPage"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_lastPage"), e);
}
}
if let Some(item) = &self.page_count {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("pageCount"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_pageCount"), e);
}
}
if let Some(item) = &self.copyright {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("copyright"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_copyright"), 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_published_in: Option<&super::super::codec::Value> = None;
let mut raw_cited_medium: Option<&super::super::codec::Value> = None;
let mut raw_volume: Option<&super::super::codec::Value> = None;
let mut raw_volume_element: Option<&super::super::codec::Value> = None;
let mut raw_issue: Option<&super::super::codec::Value> = None;
let mut raw_issue_element: Option<&super::super::codec::Value> = None;
let mut raw_article_date: Option<&super::super::codec::Value> = None;
let mut raw_article_date_element: Option<&super::super::codec::Value> = None;
let mut raw_publication_date_text: Option<&super::super::codec::Value> = None;
let mut raw_publication_date_text_element: Option<&super::super::codec::Value> = None;
let mut raw_publication_date_season: Option<&super::super::codec::Value> = None;
let mut raw_publication_date_season_element: Option<&super::super::codec::Value> = None;
let mut raw_last_revision_date: Option<&super::super::codec::Value> = None;
let mut raw_last_revision_date_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_accession_number: Option<&super::super::codec::Value> = None;
let mut raw_accession_number_element: Option<&super::super::codec::Value> = None;
let mut raw_page_string: Option<&super::super::codec::Value> = None;
let mut raw_page_string_element: Option<&super::super::codec::Value> = None;
let mut raw_first_page: Option<&super::super::codec::Value> = None;
let mut raw_first_page_element: Option<&super::super::codec::Value> = None;
let mut raw_last_page: Option<&super::super::codec::Value> = None;
let mut raw_last_page_element: Option<&super::super::codec::Value> = None;
let mut raw_page_count: Option<&super::super::codec::Value> = None;
let mut raw_page_count_element: Option<&super::super::codec::Value> = None;
let mut raw_copyright: Option<&super::super::codec::Value> = None;
let mut raw_copyright_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);
}
"publishedIn" => {
raw_published_in = Some(value);
}
"citedMedium" => {
raw_cited_medium = Some(value);
}
"volume" => {
raw_volume = Some(value);
}
"_volume" => {
raw_volume_element = Some(value);
}
"issue" => {
raw_issue = Some(value);
}
"_issue" => {
raw_issue_element = Some(value);
}
"articleDate" => {
raw_article_date = Some(value);
}
"_articleDate" => {
raw_article_date_element = Some(value);
}
"publicationDateText" => {
raw_publication_date_text = Some(value);
}
"_publicationDateText" => {
raw_publication_date_text_element = Some(value);
}
"publicationDateSeason" => {
raw_publication_date_season = Some(value);
}
"_publicationDateSeason" => {
raw_publication_date_season_element = Some(value);
}
"lastRevisionDate" => {
raw_last_revision_date = Some(value);
}
"_lastRevisionDate" => {
raw_last_revision_date_element = Some(value);
}
"language" => {
raw_language = Some(value);
}
"accessionNumber" => {
raw_accession_number = Some(value);
}
"_accessionNumber" => {
raw_accession_number_element = Some(value);
}
"pageString" => {
raw_page_string = Some(value);
}
"_pageString" => {
raw_page_string_element = Some(value);
}
"firstPage" => {
raw_first_page = Some(value);
}
"_firstPage" => {
raw_first_page_element = Some(value);
}
"lastPage" => {
raw_last_page = Some(value);
}
"_lastPage" => {
raw_last_page_element = Some(value);
}
"pageCount" => {
raw_page_count = Some(value);
}
"_pageCount" => {
raw_page_count_element = Some(value);
}
"copyright" => {
raw_copyright = Some(value);
}
"_copyright" => {
raw_copyright_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_published_in = raw_published_in
.map(|value| {
path.with("publishedIn", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_cited_medium = raw_cited_medium
.map(|value| {
path.with("citedMedium", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_volume = match (raw_volume, raw_volume_element) {
(None, None) => None,
(value, element) => Some(path.with("volume", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_issue = match (raw_issue, raw_issue_element) {
(None, None) => None,
(value, element) => Some(path.with("issue", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_article_date = match (raw_article_date, raw_article_date_element) {
(None, None) => None,
(value, element) => Some(path.with("articleDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_publication_date_text =
match (raw_publication_date_text, raw_publication_date_text_element) {
(None, None) => None,
(value, element) => Some(path.with("publicationDateText", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_publication_date_season = match (
raw_publication_date_season,
raw_publication_date_season_element,
) {
(None, None) => None,
(value, element) => Some(path.with("publicationDateSeason", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_last_revision_date =
match (raw_last_revision_date, raw_last_revision_date_element) {
(None, None) => None,
(value, element) => Some(path.with("lastRevisionDate", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_language = Vec::new();
if let Some(raw) = raw_language {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_language.push(path.with_index("language", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_accession_number = match (raw_accession_number, raw_accession_number_element) {
(None, None) => None,
(value, element) => Some(path.with("accessionNumber", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_page_string = match (raw_page_string, raw_page_string_element) {
(None, None) => None,
(value, element) => Some(path.with("pageString", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_first_page = match (raw_first_page, raw_first_page_element) {
(None, None) => None,
(value, element) => Some(path.with("firstPage", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_last_page = match (raw_last_page, raw_last_page_element) {
(None, None) => None,
(value, element) => Some(path.with("lastPage", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_page_count = match (raw_page_count, raw_page_count_element) {
(None, None) => None,
(value, element) => Some(path.with("pageCount", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_copyright = match (raw_copyright, raw_copyright_element) {
(None, None) => None,
(value, element) => Some(path.with("copyright", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
published_in: field_published_in,
cited_medium: field_cited_medium,
volume: field_volume,
issue: field_issue,
article_date: field_article_date,
publication_date_text: field_publication_date_text,
publication_date_season: field_publication_date_season,
last_revision_date: field_last_revision_date,
language: field_language,
accession_number: field_accession_number,
page_string: field_page_string,
first_page: field_first_page,
last_page: field_last_page,
page_count: field_page_count,
copyright: field_copyright,
})
}
}
impl serde::Serialize for CitationCitedArtifactPublicationForm {
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.accession_number {
super::super::codec::element_entry(&mut map, "_accessionNumber", item)?;
}
if let Some(item) = &self.article_date {
super::super::codec::element_entry(&mut map, "_articleDate", item)?;
}
if let Some(item) = &self.copyright {
super::super::codec::element_entry(&mut map, "_copyright", item)?;
}
if let Some(item) = &self.first_page {
super::super::codec::element_entry(&mut map, "_firstPage", item)?;
}
if let Some(item) = &self.issue {
super::super::codec::element_entry(&mut map, "_issue", item)?;
}
if let Some(item) = &self.last_page {
super::super::codec::element_entry(&mut map, "_lastPage", item)?;
}
if let Some(item) = &self.last_revision_date {
super::super::codec::element_entry(&mut map, "_lastRevisionDate", item)?;
}
if let Some(item) = &self.page_count {
super::super::codec::element_entry(&mut map, "_pageCount", item)?;
}
if let Some(item) = &self.page_string {
super::super::codec::element_entry(&mut map, "_pageString", item)?;
}
if let Some(item) = &self.publication_date_season {
super::super::codec::element_entry(&mut map, "_publicationDateSeason", item)?;
}
if let Some(item) = &self.publication_date_text {
super::super::codec::element_entry(&mut map, "_publicationDateText", item)?;
}
if let Some(item) = &self.volume {
super::super::codec::element_entry(&mut map, "_volume", item)?;
}
if let Some(item) = &self.accession_number {
super::super::codec::value_entry(&mut map, "accessionNumber", item)?;
}
if let Some(item) = &self.article_date {
super::super::codec::value_entry(&mut map, "articleDate", item)?;
}
if let Some(item) = &self.cited_medium {
serde::ser::SerializeMap::serialize_entry(&mut map, "citedMedium", item)?;
}
if let Some(item) = &self.copyright {
super::super::codec::value_entry(&mut map, "copyright", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(item) = &self.first_page {
super::super::codec::value_entry(&mut map, "firstPage", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.issue {
super::super::codec::value_entry(&mut map, "issue", item)?;
}
if !self.language.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "language", &self.language)?;
}
if let Some(item) = &self.last_page {
super::super::codec::value_entry(&mut map, "lastPage", item)?;
}
if let Some(item) = &self.last_revision_date {
super::super::codec::value_entry(&mut map, "lastRevisionDate", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.page_count {
super::super::codec::value_entry(&mut map, "pageCount", item)?;
}
if let Some(item) = &self.page_string {
super::super::codec::value_entry(&mut map, "pageString", item)?;
}
if let Some(item) = &self.publication_date_season {
super::super::codec::value_entry(&mut map, "publicationDateSeason", item)?;
}
if let Some(item) = &self.publication_date_text {
super::super::codec::value_entry(&mut map, "publicationDateText", item)?;
}
if let Some(item) = &self.published_in {
serde::ser::SerializeMap::serialize_entry(&mut map, "publishedIn", item)?;
}
if let Some(item) = &self.volume {
super::super::codec::value_entry(&mut map, "volume", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactPublicationForm {
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("CitationCitedArtifactPublicationForm");
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 CitationCitedArtifactPublicationFormPublishedIn {
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 identifier: Vec<super::identifier::Identifier>,
pub title: Option<super::primitives::String>,
pub publisher: Option<super::reference::Reference>,
pub publisher_location: Option<super::primitives::String>,
}
impl super::super::codec::Json for CitationCitedArtifactPublicationFormPublishedIn {
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.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.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.publisher {
object.insert(
std::string::String::from("publisher"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.publisher_location {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("publisherLocation"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_publisherLocation"), 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_type: Option<&super::super::codec::Value> = None;
let mut raw_identifier: 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_publisher: Option<&super::super::codec::Value> = None;
let mut raw_publisher_location: Option<&super::super::codec::Value> = None;
let mut raw_publisher_location_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);
}
"type" => {
raw_type = Some(value);
}
"identifier" => {
raw_identifier = Some(value);
}
"title" => {
raw_title = Some(value);
}
"_title" => {
raw_title_element = Some(value);
}
"publisher" => {
raw_publisher = Some(value);
}
"publisherLocation" => {
raw_publisher_location = Some(value);
}
"_publisherLocation" => {
raw_publisher_location_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_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_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_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_publisher = raw_publisher
.map(|value| {
path.with("publisher", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_publisher_location =
match (raw_publisher_location, raw_publisher_location_element) {
(None, None) => None,
(value, element) => Some(path.with("publisherLocation", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
identifier: field_identifier,
title: field_title,
publisher: field_publisher,
publisher_location: field_publisher_location,
})
}
}
impl serde::Serialize for CitationCitedArtifactPublicationFormPublishedIn {
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.publisher_location {
super::super::codec::element_entry(&mut map, "_publisherLocation", item)?;
}
if let Some(item) = &self.title {
super::super::codec::element_entry(&mut map, "_title", 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.identifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.publisher {
serde::ser::SerializeMap::serialize_entry(&mut map, "publisher", item)?;
}
if let Some(item) = &self.publisher_location {
super::super::codec::value_entry(&mut map, "publisherLocation", item)?;
}
if let Some(item) = &self.title {
super::super::codec::value_entry(&mut map, "title", item)?;
}
if let Some(item) = &self.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactPublicationFormPublishedIn {
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("CitationCitedArtifactPublicationFormPublishedIn");
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 CitationCitedArtifactRelatesTo {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub r#type: super::primitives::Code,
pub classifier: Vec<super::codeable_concept::CodeableConcept>,
pub label: Option<super::primitives::String>,
pub display: Option<super::primitives::String>,
pub citation: Option<super::primitives::Markdown>,
pub document: Option<super::attachment::Attachment>,
pub resource: Option<super::primitives::Canonical>,
pub resource_reference: Option<super::reference::Reference>,
}
impl super::super::codec::Json for CitationCitedArtifactRelatesTo {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.r#type)? {
object.insert(std::string::String::from("type"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.r#type)? {
object.insert(std::string::String::from("_type"), e);
}
if !self.classifier.is_empty() {
let mut items = Vec::with_capacity(self.classifier.len());
for item in &self.classifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("classifier"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.label {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("label"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_label"), e);
}
}
if let Some(item) = &self.display {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("display"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_display"), e);
}
}
if let Some(item) = &self.citation {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("citation"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_citation"), e);
}
}
if let Some(item) = &self.document {
object.insert(
std::string::String::from("document"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.resource {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("resource"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_resource"), e);
}
}
if let Some(item) = &self.resource_reference {
object.insert(
std::string::String::from("resourceReference"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_type_element: Option<&super::super::codec::Value> = None;
let mut raw_classifier: Option<&super::super::codec::Value> = None;
let mut raw_label: Option<&super::super::codec::Value> = None;
let mut raw_label_element: Option<&super::super::codec::Value> = None;
let mut raw_display: Option<&super::super::codec::Value> = None;
let mut raw_display_element: Option<&super::super::codec::Value> = None;
let mut raw_citation: Option<&super::super::codec::Value> = None;
let mut raw_citation_element: Option<&super::super::codec::Value> = None;
let mut raw_document: Option<&super::super::codec::Value> = None;
let mut raw_resource: Option<&super::super::codec::Value> = None;
let mut raw_resource_element: Option<&super::super::codec::Value> = None;
let mut raw_resource_reference: 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);
}
"_type" => {
raw_type_element = Some(value);
}
"classifier" => {
raw_classifier = Some(value);
}
"label" => {
raw_label = Some(value);
}
"_label" => {
raw_label_element = Some(value);
}
"display" => {
raw_display = Some(value);
}
"_display" => {
raw_display_element = Some(value);
}
"citation" => {
raw_citation = Some(value);
}
"_citation" => {
raw_citation_element = Some(value);
}
"document" => {
raw_document = Some(value);
}
"resource" => {
raw_resource = Some(value);
}
"_resource" => {
raw_resource_element = Some(value);
}
"resourceReference" => {
raw_resource_reference = 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 = path.with("type", |path| {
super::super::codec::Primitive::from_json_parts(raw_type, raw_type_element, path)
})?;
let mut field_classifier = Vec::new();
if let Some(raw) = raw_classifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_classifier.push(path.with_index("classifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_label = match (raw_label, raw_label_element) {
(None, None) => None,
(value, element) => Some(path.with("label", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_display = match (raw_display, raw_display_element) {
(None, None) => None,
(value, element) => Some(path.with("display", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_citation = match (raw_citation, raw_citation_element) {
(None, None) => None,
(value, element) => Some(path.with("citation", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_document = raw_document
.map(|value| {
path.with("document", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_resource = match (raw_resource, raw_resource_element) {
(None, None) => None,
(value, element) => Some(path.with("resource", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_resource_reference = raw_resource_reference
.map(|value| {
path.with("resourceReference", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
classifier: field_classifier,
label: field_label,
display: field_display,
citation: field_citation,
document: field_document,
resource: field_resource,
resource_reference: field_resource_reference,
})
}
}
impl serde::Serialize for CitationCitedArtifactRelatesTo {
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.citation {
super::super::codec::element_entry(&mut map, "_citation", item)?;
}
if let Some(item) = &self.display {
super::super::codec::element_entry(&mut map, "_display", item)?;
}
if let Some(item) = &self.label {
super::super::codec::element_entry(&mut map, "_label", item)?;
}
if let Some(item) = &self.resource {
super::super::codec::element_entry(&mut map, "_resource", item)?;
}
super::super::codec::element_entry(&mut map, "_type", &self.r#type)?;
if let Some(item) = &self.citation {
super::super::codec::value_entry(&mut map, "citation", item)?;
}
if !self.classifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "classifier", &self.classifier)?;
}
if let Some(item) = &self.display {
super::super::codec::value_entry(&mut map, "display", item)?;
}
if let Some(item) = &self.document {
serde::ser::SerializeMap::serialize_entry(&mut map, "document", 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 let Some(item) = &self.label {
super::super::codec::value_entry(&mut map, "label", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.resource {
super::super::codec::value_entry(&mut map, "resource", item)?;
}
if let Some(item) = &self.resource_reference {
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceReference", item)?;
}
super::super::codec::value_entry(&mut map, "type", &self.r#type)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactRelatesTo {
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("CitationCitedArtifactRelatesTo");
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 CitationCitedArtifactStatusDate {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub activity: super::codeable_concept::CodeableConcept,
pub actual: Option<super::primitives::Boolean>,
pub period: super::period::Period,
}
impl super::super::codec::Json for CitationCitedArtifactStatusDate {
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("activity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.activity)?),
);
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);
}
}
object.insert(
std::string::String::from("period"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.period)?),
);
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_activity: 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_period: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"activity" => {
raw_activity = Some(value);
}
"actual" => {
raw_actual = Some(value);
}
"_actual" => {
raw_actual_element = Some(value);
}
"period" => {
raw_period = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_activity = path.with("activity", |path| {
let value = raw_activity
.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_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_period = path.with("period", |path| {
let value = raw_period
.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,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
activity: field_activity,
actual: field_actual,
period: field_period,
})
}
}
impl serde::Serialize for CitationCitedArtifactStatusDate {
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)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "activity", &self.activity)?;
if let Some(item) = &self.actual {
super::super::codec::value_entry(&mut map, "actual", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "period", &self.period)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactStatusDate {
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("CitationCitedArtifactStatusDate");
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 CitationCitedArtifactTitle {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub r#type: Vec<super::codeable_concept::CodeableConcept>,
pub language: Option<super::codeable_concept::CodeableConcept>,
pub text: super::primitives::Markdown,
}
impl super::super::codec::Json for CitationCitedArtifactTitle {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.r#type.is_empty() {
let mut items = Vec::with_capacity(self.r#type.len());
for item in &self.r#type {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("type"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.language {
object.insert(
std::string::String::from("language"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.text)? {
object.insert(std::string::String::from("text"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.text)? {
object.insert(std::string::String::from("_text"), 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_type: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_text_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);
}
"type" => {
raw_type = Some(value);
}
"language" => {
raw_language = Some(value);
}
"text" => {
raw_text = Some(value);
}
"_text" => {
raw_text_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 mut field_type = Vec::new();
if let Some(raw) = raw_type {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_type.push(path.with_index("type", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_language = raw_language
.map(|value| {
path.with("language", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_text = path.with("text", |path| {
super::super::codec::Primitive::from_json_parts(raw_text, raw_text_element, path)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
language: field_language,
text: field_text,
})
}
}
impl serde::Serialize for CitationCitedArtifactTitle {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_text", &self.text)?;
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.language {
serde::ser::SerializeMap::serialize_entry(&mut map, "language", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
super::super::codec::value_entry(&mut map, "text", &self.text)?;
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 CitationCitedArtifactTitle {
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("CitationCitedArtifactTitle");
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 CitationCitedArtifactVersion {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub value: super::primitives::String,
pub base_citation: Option<super::reference::Reference>,
}
impl super::super::codec::Json for CitationCitedArtifactVersion {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.value)? {
object.insert(std::string::String::from("value"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.value)? {
object.insert(std::string::String::from("_value"), e);
}
if let Some(item) = &self.base_citation {
object.insert(
std::string::String::from("baseCitation"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_value: Option<&super::super::codec::Value> = None;
let mut raw_value_element: Option<&super::super::codec::Value> = None;
let mut raw_base_citation: 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);
}
"value" => {
raw_value = Some(value);
}
"_value" => {
raw_value_element = Some(value);
}
"baseCitation" => {
raw_base_citation = 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_value = path.with("value", |path| {
super::super::codec::Primitive::from_json_parts(raw_value, raw_value_element, path)
})?;
let field_base_citation = raw_base_citation
.map(|value| {
path.with("baseCitation", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
value: field_value,
base_citation: field_base_citation,
})
}
}
impl serde::Serialize for CitationCitedArtifactVersion {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_value", &self.value)?;
if let Some(item) = &self.base_citation {
serde::ser::SerializeMap::serialize_entry(&mut map, "baseCitation", 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,
)?;
}
super::super::codec::value_entry(&mut map, "value", &self.value)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactVersion {
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("CitationCitedArtifactVersion");
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 CitationCitedArtifactWebLocation {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub classifier: Vec<super::codeable_concept::CodeableConcept>,
pub url: Option<super::primitives::Uri>,
}
impl super::super::codec::Json for CitationCitedArtifactWebLocation {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.classifier.is_empty() {
let mut items = Vec::with_capacity(self.classifier.len());
for item in &self.classifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("classifier"),
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);
}
}
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_classifier: 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;
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);
}
"classifier" => {
raw_classifier = Some(value);
}
"url" => {
raw_url = Some(value);
}
"_url" => {
raw_url_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 mut field_classifier = Vec::new();
if let Some(raw) = raw_classifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_classifier.push(path.with_index("classifier", 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)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
classifier: field_classifier,
url: field_url,
})
}
}
impl serde::Serialize for CitationCitedArtifactWebLocation {
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.url {
super::super::codec::element_entry(&mut map, "_url", item)?;
}
if !self.classifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "classifier", &self.classifier)?;
}
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.url {
super::super::codec::value_entry(&mut map, "url", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationCitedArtifactWebLocation {
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("CitationCitedArtifactWebLocation");
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 CitationClassification {
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 classifier: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for CitationClassification {
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.classifier.is_empty() {
let mut items = Vec::with_capacity(self.classifier.len());
for item in &self.classifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("classifier"),
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_classifier: 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);
}
"classifier" => {
raw_classifier = 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_classifier = Vec::new();
if let Some(raw) = raw_classifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_classifier.push(path.with_index("classifier", 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,
classifier: field_classifier,
})
}
}
impl serde::Serialize for CitationClassification {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if !self.classifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "classifier", &self.classifier)?;
}
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.r#type {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationClassification {
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("CitationClassification");
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 CitationStatusDate {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub activity: super::codeable_concept::CodeableConcept,
pub actual: Option<super::primitives::Boolean>,
pub period: super::period::Period,
}
impl super::super::codec::Json for CitationStatusDate {
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("activity"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.activity)?),
);
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);
}
}
object.insert(
std::string::String::from("period"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.period)?),
);
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_activity: 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_period: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"activity" => {
raw_activity = Some(value);
}
"actual" => {
raw_actual = Some(value);
}
"_actual" => {
raw_actual_element = Some(value);
}
"period" => {
raw_period = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_string(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_activity = path.with("activity", |path| {
let value = raw_activity
.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_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_period = path.with("period", |path| {
let value = raw_period
.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,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
activity: field_activity,
actual: field_actual,
period: field_period,
})
}
}
impl serde::Serialize for CitationStatusDate {
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)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "activity", &self.activity)?;
if let Some(item) = &self.actual {
super::super::codec::value_entry(&mut map, "actual", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "period", &self.period)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationStatusDate {
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("CitationStatusDate");
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 CitationSummary {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub style: Option<super::codeable_concept::CodeableConcept>,
pub text: super::primitives::Markdown,
}
impl super::super::codec::Json for CitationSummary {
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.style {
object.insert(
std::string::String::from("style"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.text)? {
object.insert(std::string::String::from("text"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.text)? {
object.insert(std::string::String::from("_text"), 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_style: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_text_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);
}
"style" => {
raw_style = Some(value);
}
"text" => {
raw_text = Some(value);
}
"_text" => {
raw_text_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_style = raw_style
.map(|value| {
path.with("style", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_text = path.with("text", |path| {
super::super::codec::Primitive::from_json_parts(raw_text, raw_text_element, path)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
style: field_style,
text: field_text,
})
}
}
impl serde::Serialize for CitationSummary {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
super::super::codec::element_entry(&mut map, "_text", &self.text)?;
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.style {
serde::ser::SerializeMap::serialize_entry(&mut map, "style", item)?;
}
super::super::codec::value_entry(&mut map, "text", &self.text)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for CitationSummary {
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("CitationSummary");
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 CitationVersionAlgorithm {
String(super::primitives::String),
Coding(Box<super::coding::Coding>),
}
impl CitationVersionAlgorithm {
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::String(inner) => Ok((
"String",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Coding(inner) => Ok((
"Coding",
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 {
"String" => Ok(Self::String(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Coding" => {
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::Coding(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}