#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ResearchDefinition {
pub id: Option<std::string::String>,
pub meta: Option<super::meta::Meta>,
pub implicit_rules: Option<super::primitives::Uri>,
pub language: Option<super::primitives::Code>,
pub text: Option<super::narrative::Narrative>,
pub contained: Vec<super::resource::Resource>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub url: Option<super::primitives::Uri>,
pub identifier: Vec<super::identifier::Identifier>,
pub version: Option<super::primitives::String>,
pub name: Option<super::primitives::String>,
pub title: Option<super::primitives::String>,
pub short_title: Option<super::primitives::String>,
pub subtitle: Option<super::primitives::String>,
pub status: super::primitives::Code,
pub experimental: Option<super::primitives::Boolean>,
pub subject: Option<ResearchDefinitionSubject>,
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 comment: Vec<super::primitives::String>,
pub use_context: Vec<super::usage_context::UsageContext>,
pub jurisdiction: Vec<super::codeable_concept::CodeableConcept>,
pub purpose: Option<super::primitives::Markdown>,
pub usage: Option<super::primitives::String>,
pub copyright: Option<super::primitives::Markdown>,
pub approval_date: Option<super::primitives::Date>,
pub last_review_date: Option<super::primitives::Date>,
pub effective_period: Option<super::period::Period>,
pub topic: Vec<super::codeable_concept::CodeableConcept>,
pub author: Vec<super::contact_detail::ContactDetail>,
pub editor: Vec<super::contact_detail::ContactDetail>,
pub reviewer: Vec<super::contact_detail::ContactDetail>,
pub endorser: Vec<super::contact_detail::ContactDetail>,
pub related_artifact: Vec<super::related_artifact::RelatedArtifact>,
pub library: Vec<super::primitives::Canonical>,
pub population: super::reference::Reference,
pub exposure: Option<super::reference::Reference>,
pub exposure_alternative: Option<super::reference::Reference>,
pub outcome: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ResearchDefinition {
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("ResearchDefinition")),
);
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.url {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("url"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_url"), e);
}
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.version {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("version"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_version"), e);
}
}
if let Some(item) = &self.name {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_name"), e);
}
}
if let Some(item) = &self.title {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("title"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_title"), e);
}
}
if let Some(item) = &self.short_title {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("shortTitle"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_shortTitle"), e);
}
}
if let Some(item) = &self.subtitle {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("subtitle"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_subtitle"), e);
}
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.status)? {
object.insert(std::string::String::from("status"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.status)? {
object.insert(std::string::String::from("_status"), e);
}
if let Some(item) = &self.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.subject {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("subject{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_subject{suffix}"), element);
}
}
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.comment.is_empty() {
let (values, elements) = super::super::codec::primitive_arrays(&self.comment)?;
object.insert(std::string::String::from("comment"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_comment"), elements);
}
}
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.usage {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("usage"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_usage"), 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.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.topic.is_empty() {
let mut items = Vec::with_capacity(self.topic.len());
for item in &self.topic {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("topic"),
super::super::codec::Value::Array(items),
);
}
if !self.author.is_empty() {
let mut items = Vec::with_capacity(self.author.len());
for item in &self.author {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("author"),
super::super::codec::Value::Array(items),
);
}
if !self.editor.is_empty() {
let mut items = Vec::with_capacity(self.editor.len());
for item in &self.editor {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("editor"),
super::super::codec::Value::Array(items),
);
}
if !self.reviewer.is_empty() {
let mut items = Vec::with_capacity(self.reviewer.len());
for item in &self.reviewer {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reviewer"),
super::super::codec::Value::Array(items),
);
}
if !self.endorser.is_empty() {
let mut items = Vec::with_capacity(self.endorser.len());
for item in &self.endorser {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("endorser"),
super::super::codec::Value::Array(items),
);
}
if !self.related_artifact.is_empty() {
let mut items = Vec::with_capacity(self.related_artifact.len());
for item in &self.related_artifact {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("relatedArtifact"),
super::super::codec::Value::Array(items),
);
}
if !self.library.is_empty() {
let (values, elements) = super::super::codec::primitive_arrays(&self.library)?;
object.insert(std::string::String::from("library"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_library"), elements);
}
}
object.insert(
std::string::String::from("population"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.population,
)?),
);
if let Some(item) = &self.exposure {
object.insert(
std::string::String::from("exposure"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.exposure_alternative {
object.insert(
std::string::String::from("exposureAlternative"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.outcome {
object.insert(
std::string::String::from("outcome"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_meta: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_language_element: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_contained: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_url: Option<&super::super::codec::Value> = None;
let mut raw_url_element: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_version: Option<&super::super::codec::Value> = None;
let mut raw_version_element: Option<&super::super::codec::Value> = None;
let mut raw_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: Option<&super::super::codec::Value> = None;
let mut raw_title: Option<&super::super::codec::Value> = None;
let mut raw_title_element: Option<&super::super::codec::Value> = None;
let mut raw_short_title: Option<&super::super::codec::Value> = None;
let mut raw_short_title_element: Option<&super::super::codec::Value> = None;
let mut raw_subtitle: Option<&super::super::codec::Value> = None;
let mut raw_subtitle_element: Option<&super::super::codec::Value> = None;
let mut raw_status: Option<&super::super::codec::Value> = None;
let mut raw_status_element: Option<&super::super::codec::Value> = None;
let mut raw_experimental: Option<&super::super::codec::Value> = None;
let mut raw_experimental_element: Option<&super::super::codec::Value> = None;
let mut raw_subject = super::super::codec::ChoiceSlot::default();
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_comment: Option<&super::super::codec::Value> = None;
let mut raw_comment_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_usage: Option<&super::super::codec::Value> = None;
let mut raw_usage_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_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_topic: Option<&super::super::codec::Value> = None;
let mut raw_author: Option<&super::super::codec::Value> = None;
let mut raw_editor: Option<&super::super::codec::Value> = None;
let mut raw_reviewer: Option<&super::super::codec::Value> = None;
let mut raw_endorser: Option<&super::super::codec::Value> = None;
let mut raw_related_artifact: Option<&super::super::codec::Value> = None;
let mut raw_library: Option<&super::super::codec::Value> = None;
let mut raw_library_element: Option<&super::super::codec::Value> = None;
let mut raw_population: Option<&super::super::codec::Value> = None;
let mut raw_exposure: Option<&super::super::codec::Value> = None;
let mut raw_exposure_alternative: Option<&super::super::codec::Value> = None;
let mut raw_outcome: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("ResearchDefinition") {
return Err(path.error(super::super::codec::DecodeErrorKind::ResourceType));
}
}
"id" => {
raw_id = Some(value);
}
"meta" => {
raw_meta = Some(value);
}
"implicitRules" => {
raw_implicit_rules = Some(value);
}
"_implicitRules" => {
raw_implicit_rules_element = Some(value);
}
"language" => {
raw_language = Some(value);
}
"_language" => {
raw_language_element = Some(value);
}
"text" => {
raw_text = Some(value);
}
"contained" => {
raw_contained = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"url" => {
raw_url = Some(value);
}
"_url" => {
raw_url_element = Some(value);
}
"identifier" => {
raw_identifier = Some(value);
}
"version" => {
raw_version = Some(value);
}
"_version" => {
raw_version_element = Some(value);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"title" => {
raw_title = Some(value);
}
"_title" => {
raw_title_element = Some(value);
}
"shortTitle" => {
raw_short_title = Some(value);
}
"_shortTitle" => {
raw_short_title_element = Some(value);
}
"subtitle" => {
raw_subtitle = Some(value);
}
"_subtitle" => {
raw_subtitle_element = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"experimental" => {
raw_experimental = Some(value);
}
"_experimental" => {
raw_experimental_element = Some(value);
}
"subjectCodeableConcept" => {
raw_subject.value("CodeableConcept", value, path)?;
}
"_subjectCodeableConcept" => {
raw_subject.element("CodeableConcept", value, path)?;
}
"subjectReference" => {
raw_subject.value("Reference", value, path)?;
}
"_subjectReference" => {
raw_subject.element("Reference", value, path)?;
}
"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);
}
"comment" => {
raw_comment = Some(value);
}
"_comment" => {
raw_comment_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);
}
"usage" => {
raw_usage = Some(value);
}
"_usage" => {
raw_usage_element = Some(value);
}
"copyright" => {
raw_copyright = Some(value);
}
"_copyright" => {
raw_copyright_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);
}
"topic" => {
raw_topic = Some(value);
}
"author" => {
raw_author = Some(value);
}
"editor" => {
raw_editor = Some(value);
}
"reviewer" => {
raw_reviewer = Some(value);
}
"endorser" => {
raw_endorser = Some(value);
}
"relatedArtifact" => {
raw_related_artifact = Some(value);
}
"library" => {
raw_library = Some(value);
}
"_library" => {
raw_library_element = Some(value);
}
"population" => {
raw_population = Some(value);
}
"exposure" => {
raw_exposure = Some(value);
}
"exposureAlternative" => {
raw_exposure_alternative = Some(value);
}
"outcome" => {
raw_outcome = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_url = match (raw_url, raw_url_element) {
(None, None) => None,
(value, element) => Some(path.with("url", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_version = match (raw_version, raw_version_element) {
(None, None) => None,
(value, element) => Some(path.with("version", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_name = match (raw_name, raw_name_element) {
(None, None) => None,
(value, element) => Some(path.with("name", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_title = match (raw_title, raw_title_element) {
(None, None) => None,
(value, element) => Some(path.with("title", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_short_title = match (raw_short_title, raw_short_title_element) {
(None, None) => None,
(value, element) => Some(path.with("shortTitle", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_subtitle = match (raw_subtitle, raw_subtitle_element) {
(None, None) => None,
(value, element) => Some(path.with("subtitle", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
let field_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_subject = match raw_subject.suffix {
None => None,
Some(suffix) => Some(path.with("subject", |path| {
ResearchDefinitionSubject::from_json_parts(
suffix,
raw_subject.value,
raw_subject.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_comment = Vec::new();
for (index, (value, element)) in
super::super::codec::pair_arrays(raw_comment, raw_comment_element, path)?
.into_iter()
.enumerate()
{
field_comment.push(path.with_index("comment", index, |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_usage = match (raw_usage, raw_usage_element) {
(None, None) => None,
(value, element) => Some(path.with("usage", |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_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_topic = Vec::new();
if let Some(raw) = raw_topic {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_topic.push(path.with_index("topic", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_author = Vec::new();
if let Some(raw) = raw_author {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_author.push(path.with_index("author", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_editor = Vec::new();
if let Some(raw) = raw_editor {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_editor.push(path.with_index("editor", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_reviewer = Vec::new();
if let Some(raw) = raw_reviewer {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reviewer.push(path.with_index("reviewer", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_endorser = Vec::new();
if let Some(raw) = raw_endorser {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_endorser.push(path.with_index("endorser", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_related_artifact = Vec::new();
if let Some(raw) = raw_related_artifact {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_related_artifact.push(path.with_index("relatedArtifact", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_library = Vec::new();
for (index, (value, element)) in
super::super::codec::pair_arrays(raw_library, raw_library_element, path)?
.into_iter()
.enumerate()
{
field_library.push(path.with_index("library", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let field_population = path.with("population", |path| {
let value = raw_population
.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_exposure = raw_exposure
.map(|value| {
path.with("exposure", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_exposure_alternative = raw_exposure_alternative
.map(|value| {
path.with("exposureAlternative", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_outcome = raw_outcome
.map(|value| {
path.with("outcome", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
meta: field_meta,
implicit_rules: field_implicit_rules,
language: field_language,
text: field_text,
contained: field_contained,
extension: field_extension,
modifier_extension: field_modifier_extension,
url: field_url,
identifier: field_identifier,
version: field_version,
name: field_name,
title: field_title,
short_title: field_short_title,
subtitle: field_subtitle,
status: field_status,
experimental: field_experimental,
subject: field_subject,
date: field_date,
publisher: field_publisher,
contact: field_contact,
description: field_description,
comment: field_comment,
use_context: field_use_context,
jurisdiction: field_jurisdiction,
purpose: field_purpose,
usage: field_usage,
copyright: field_copyright,
approval_date: field_approval_date,
last_review_date: field_last_review_date,
effective_period: field_effective_period,
topic: field_topic,
author: field_author,
editor: field_editor,
reviewer: field_reviewer,
endorser: field_endorser,
related_artifact: field_related_artifact,
library: field_library,
population: field_population,
exposure: field_exposure,
exposure_alternative: field_exposure_alternative,
outcome: field_outcome,
})
}
}
impl serde::Serialize for ResearchDefinition {
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)?;
}
super::super::codec::element_list_entry(&mut map, "_comment", &self.comment)?;
if let Some(item) = &self.copyright {
super::super::codec::element_entry(&mut map, "_copyright", 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)?;
}
super::super::codec::element_list_entry(&mut map, "_library", &self.library)?;
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)?;
}
if let Some(item) = &self.short_title {
super::super::codec::element_entry(&mut map, "_shortTitle", item)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if let Some(item) = &self.subtitle {
super::super::codec::element_entry(&mut map, "_subtitle", item)?;
}
if let Some(item) = &self.title {
super::super::codec::element_entry(&mut map, "_title", item)?;
}
if let Some(item) = &self.url {
super::super::codec::element_entry(&mut map, "_url", item)?;
}
if let Some(item) = &self.usage {
super::super::codec::element_entry(&mut map, "_usage", item)?;
}
if let Some(item) = &self.version {
super::super::codec::element_entry(&mut map, "_version", item)?;
}
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)?;
}
super::super::codec::value_list_entry(&mut map, "comment", &self.comment)?;
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.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 let Some(item) = &self.exposure {
serde::ser::SerializeMap::serialize_entry(&mut map, "exposure", item)?;
}
if let Some(item) = &self.exposure_alternative {
serde::ser::SerializeMap::serialize_entry(&mut map, "exposureAlternative", 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)?;
}
super::super::codec::value_list_entry(&mut map, "library", &self.library)?;
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 let Some(item) = &self.outcome {
serde::ser::SerializeMap::serialize_entry(&mut map, "outcome", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "population", &self.population)?;
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", "ResearchDefinition")?;
if !self.reviewer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reviewer", &self.reviewer)?;
}
if let Some(item) = &self.short_title {
super::super::codec::value_entry(&mut map, "shortTitle", item)?;
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
match &self.subject {
Some(ResearchDefinitionSubject::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"subjectCodeableConcept",
inner.as_ref(),
)?;
}
Some(ResearchDefinitionSubject::Reference(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"subjectReference",
inner.as_ref(),
)?;
}
None => {}
}
if let Some(item) = &self.subtitle {
super::super::codec::value_entry(&mut map, "subtitle", item)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.title {
super::super::codec::value_entry(&mut map, "title", item)?;
}
if !self.topic.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "topic", &self.topic)?;
}
if let Some(item) = &self.url {
super::super::codec::value_entry(&mut map, "url", item)?;
}
if let Some(item) = &self.usage {
super::super::codec::value_entry(&mut map, "usage", item)?;
}
if !self.use_context.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "useContext", &self.use_context)?;
}
if let Some(item) = &self.version {
super::super::codec::value_entry(&mut map, "version", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ResearchDefinition {
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("ResearchDefinition");
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 ResearchDefinitionSubject {
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Reference(Box<super::reference::Reference>),
}
impl ResearchDefinitionSubject {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Reference(inner) => Ok((
"Reference",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(Box::new(inner)))
}
"Reference" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Reference(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}