#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ResearchStudy {
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 label: Vec<ResearchStudyLabel>,
pub protocol: Vec<super::reference::Reference>,
pub part_of: Vec<super::reference::Reference>,
pub related_artifact: Vec<super::related_artifact::RelatedArtifact>,
pub date: Option<super::primitives::DateTime>,
pub status: super::primitives::Code,
pub primary_purpose_type: Option<super::codeable_concept::CodeableConcept>,
pub phase: Option<super::codeable_concept::CodeableConcept>,
pub study_design: Vec<super::codeable_concept::CodeableConcept>,
pub focus: Vec<super::codeable_reference::CodeableReference>,
pub condition: Vec<super::codeable_concept::CodeableConcept>,
pub keyword: Vec<super::codeable_concept::CodeableConcept>,
pub region: Vec<super::codeable_concept::CodeableConcept>,
pub description_summary: Option<super::primitives::Markdown>,
pub description: Option<super::primitives::Markdown>,
pub period: Option<super::period::Period>,
pub site: Vec<super::reference::Reference>,
pub note: Vec<super::annotation::Annotation>,
pub classifier: Vec<super::codeable_concept::CodeableConcept>,
pub associated_party: Vec<ResearchStudyAssociatedParty>,
pub progress_status: Vec<ResearchStudyProgressStatus>,
pub why_stopped: Option<super::codeable_concept::CodeableConcept>,
pub recruitment: Option<ResearchStudyRecruitment>,
pub comparison_group: Vec<ResearchStudyComparisonGroup>,
pub objective: Vec<ResearchStudyObjective>,
pub outcome_measure: Vec<ResearchStudyOutcomeMeasure>,
pub result: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for ResearchStudy {
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("ResearchStudy")),
);
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 !self.label.is_empty() {
let mut items = Vec::with_capacity(self.label.len());
for item in &self.label {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("label"),
super::super::codec::Value::Array(items),
);
}
if !self.protocol.is_empty() {
let mut items = Vec::with_capacity(self.protocol.len());
for item in &self.protocol {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("protocol"),
super::super::codec::Value::Array(items),
);
}
if !self.part_of.is_empty() {
let mut items = Vec::with_capacity(self.part_of.len());
for item in &self.part_of {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("partOf"),
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.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(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.primary_purpose_type {
object.insert(
std::string::String::from("primaryPurposeType"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.phase {
object.insert(
std::string::String::from("phase"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.study_design.is_empty() {
let mut items = Vec::with_capacity(self.study_design.len());
for item in &self.study_design {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("studyDesign"),
super::super::codec::Value::Array(items),
);
}
if !self.focus.is_empty() {
let mut items = Vec::with_capacity(self.focus.len());
for item in &self.focus {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("focus"),
super::super::codec::Value::Array(items),
);
}
if !self.condition.is_empty() {
let mut items = Vec::with_capacity(self.condition.len());
for item in &self.condition {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("condition"),
super::super::codec::Value::Array(items),
);
}
if !self.keyword.is_empty() {
let mut items = Vec::with_capacity(self.keyword.len());
for item in &self.keyword {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("keyword"),
super::super::codec::Value::Array(items),
);
}
if !self.region.is_empty() {
let mut items = Vec::with_capacity(self.region.len());
for item in &self.region {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("region"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.description_summary {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("descriptionSummary"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_descriptionSummary"), e);
}
}
if let Some(item) = &self.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
if let Some(item) = &self.period {
object.insert(
std::string::String::from("period"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.site.is_empty() {
let mut items = Vec::with_capacity(self.site.len());
for item in &self.site {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("site"),
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.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.associated_party.is_empty() {
let mut items = Vec::with_capacity(self.associated_party.len());
for item in &self.associated_party {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("associatedParty"),
super::super::codec::Value::Array(items),
);
}
if !self.progress_status.is_empty() {
let mut items = Vec::with_capacity(self.progress_status.len());
for item in &self.progress_status {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("progressStatus"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.why_stopped {
object.insert(
std::string::String::from("whyStopped"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.recruitment {
object.insert(
std::string::String::from("recruitment"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.comparison_group.is_empty() {
let mut items = Vec::with_capacity(self.comparison_group.len());
for item in &self.comparison_group {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("comparisonGroup"),
super::super::codec::Value::Array(items),
);
}
if !self.objective.is_empty() {
let mut items = Vec::with_capacity(self.objective.len());
for item in &self.objective {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("objective"),
super::super::codec::Value::Array(items),
);
}
if !self.outcome_measure.is_empty() {
let mut items = Vec::with_capacity(self.outcome_measure.len());
for item in &self.outcome_measure {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("outcomeMeasure"),
super::super::codec::Value::Array(items),
);
}
if !self.result.is_empty() {
let mut items = Vec::with_capacity(self.result.len());
for item in &self.result {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("result"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_meta: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
let mut raw_language: Option<&super::super::codec::Value> = None;
let mut raw_language_element: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_contained: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_url: Option<&super::super::codec::Value> = None;
let mut raw_url_element: Option<&super::super::codec::Value> = None;
let mut raw_identifier: Option<&super::super::codec::Value> = None;
let mut raw_version: Option<&super::super::codec::Value> = None;
let mut raw_version_element: Option<&super::super::codec::Value> = None;
let mut raw_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: Option<&super::super::codec::Value> = None;
let mut raw_title: Option<&super::super::codec::Value> = None;
let mut raw_title_element: Option<&super::super::codec::Value> = None;
let mut raw_label: Option<&super::super::codec::Value> = None;
let mut raw_protocol: Option<&super::super::codec::Value> = None;
let mut raw_part_of: Option<&super::super::codec::Value> = None;
let mut raw_related_artifact: 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_status: Option<&super::super::codec::Value> = None;
let mut raw_status_element: Option<&super::super::codec::Value> = None;
let mut raw_primary_purpose_type: Option<&super::super::codec::Value> = None;
let mut raw_phase: Option<&super::super::codec::Value> = None;
let mut raw_study_design: Option<&super::super::codec::Value> = None;
let mut raw_focus: Option<&super::super::codec::Value> = None;
let mut raw_condition: Option<&super::super::codec::Value> = None;
let mut raw_keyword: Option<&super::super::codec::Value> = None;
let mut raw_region: Option<&super::super::codec::Value> = None;
let mut raw_description_summary: Option<&super::super::codec::Value> = None;
let mut raw_description_summary_element: Option<&super::super::codec::Value> = None;
let mut raw_description: Option<&super::super::codec::Value> = None;
let mut raw_description_element: Option<&super::super::codec::Value> = None;
let mut raw_period: Option<&super::super::codec::Value> = None;
let mut raw_site: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_classifier: Option<&super::super::codec::Value> = None;
let mut raw_associated_party: Option<&super::super::codec::Value> = None;
let mut raw_progress_status: Option<&super::super::codec::Value> = None;
let mut raw_why_stopped: Option<&super::super::codec::Value> = None;
let mut raw_recruitment: Option<&super::super::codec::Value> = None;
let mut raw_comparison_group: Option<&super::super::codec::Value> = None;
let mut raw_objective: Option<&super::super::codec::Value> = None;
let mut raw_outcome_measure: Option<&super::super::codec::Value> = None;
let mut raw_result: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("ResearchStudy") {
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);
}
"label" => {
raw_label = Some(value);
}
"protocol" => {
raw_protocol = Some(value);
}
"partOf" => {
raw_part_of = Some(value);
}
"relatedArtifact" => {
raw_related_artifact = Some(value);
}
"date" => {
raw_date = Some(value);
}
"_date" => {
raw_date_element = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"primaryPurposeType" => {
raw_primary_purpose_type = Some(value);
}
"phase" => {
raw_phase = Some(value);
}
"studyDesign" => {
raw_study_design = Some(value);
}
"focus" => {
raw_focus = Some(value);
}
"condition" => {
raw_condition = Some(value);
}
"keyword" => {
raw_keyword = Some(value);
}
"region" => {
raw_region = Some(value);
}
"descriptionSummary" => {
raw_description_summary = Some(value);
}
"_descriptionSummary" => {
raw_description_summary_element = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"period" => {
raw_period = Some(value);
}
"site" => {
raw_site = Some(value);
}
"note" => {
raw_note = Some(value);
}
"classifier" => {
raw_classifier = Some(value);
}
"associatedParty" => {
raw_associated_party = Some(value);
}
"progressStatus" => {
raw_progress_status = Some(value);
}
"whyStopped" => {
raw_why_stopped = Some(value);
}
"recruitment" => {
raw_recruitment = Some(value);
}
"comparisonGroup" => {
raw_comparison_group = Some(value);
}
"objective" => {
raw_objective = Some(value);
}
"outcomeMeasure" => {
raw_outcome_measure = Some(value);
}
"result" => {
raw_result = Some(value);
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::primitives::checked_id(
super::super::codec::expect_string(value, path)?,
path,
)
})
})
.transpose()?;
let field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_url = match (raw_url, raw_url_element) {
(None, None) => None,
(value, element) => Some(path.with("url", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_version = match (raw_version, raw_version_element) {
(None, None) => None,
(value, element) => Some(path.with("version", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_name = match (raw_name, raw_name_element) {
(None, None) => None,
(value, element) => Some(path.with("name", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_title = match (raw_title, raw_title_element) {
(None, None) => None,
(value, element) => Some(path.with("title", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_label = Vec::new();
if let Some(raw) = raw_label {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_label.push(path.with_index("label", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_protocol = Vec::new();
if let Some(raw) = raw_protocol {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_protocol.push(path.with_index("protocol", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_part_of = Vec::new();
if let Some(raw) = raw_part_of {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_part_of.push(path.with_index("partOf", 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_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_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
let field_primary_purpose_type = raw_primary_purpose_type
.map(|value| {
path.with("primaryPurposeType", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_phase = raw_phase
.map(|value| {
path.with("phase", |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_study_design = Vec::new();
if let Some(raw) = raw_study_design {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_study_design.push(path.with_index("studyDesign", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_focus = Vec::new();
if let Some(raw) = raw_focus {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_focus.push(path.with_index("focus", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_condition = Vec::new();
if let Some(raw) = raw_condition {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_condition.push(path.with_index("condition", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_keyword = Vec::new();
if let Some(raw) = raw_keyword {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_keyword.push(path.with_index("keyword", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_region = Vec::new();
if let Some(raw) = raw_region {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_region.push(path.with_index("region", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_description_summary =
match (raw_description_summary, raw_description_summary_element) {
(None, None) => None,
(value, element) => Some(path.with("descriptionSummary", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_period = raw_period
.map(|value| {
path.with("period", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_site = Vec::new();
if let Some(raw) = raw_site {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_site.push(path.with_index("site", 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_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_associated_party = Vec::new();
if let Some(raw) = raw_associated_party {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_associated_party.push(path.with_index("associatedParty", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_progress_status = Vec::new();
if let Some(raw) = raw_progress_status {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_progress_status.push(path.with_index("progressStatus", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_why_stopped = raw_why_stopped
.map(|value| {
path.with("whyStopped", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_recruitment = raw_recruitment
.map(|value| {
path.with("recruitment", |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_comparison_group = Vec::new();
if let Some(raw) = raw_comparison_group {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_comparison_group.push(path.with_index("comparisonGroup", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_objective = Vec::new();
if let Some(raw) = raw_objective {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_objective.push(path.with_index("objective", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_outcome_measure = Vec::new();
if let Some(raw) = raw_outcome_measure {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_outcome_measure.push(path.with_index("outcomeMeasure", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_result = Vec::new();
if let Some(raw) = raw_result {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_result.push(path.with_index("result", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
meta: field_meta,
implicit_rules: field_implicit_rules,
language: field_language,
text: field_text,
contained: field_contained,
extension: field_extension,
modifier_extension: field_modifier_extension,
url: field_url,
identifier: field_identifier,
version: field_version,
name: field_name,
title: field_title,
label: field_label,
protocol: field_protocol,
part_of: field_part_of,
related_artifact: field_related_artifact,
date: field_date,
status: field_status,
primary_purpose_type: field_primary_purpose_type,
phase: field_phase,
study_design: field_study_design,
focus: field_focus,
condition: field_condition,
keyword: field_keyword,
region: field_region,
description_summary: field_description_summary,
description: field_description,
period: field_period,
site: field_site,
note: field_note,
classifier: field_classifier,
associated_party: field_associated_party,
progress_status: field_progress_status,
why_stopped: field_why_stopped,
recruitment: field_recruitment,
comparison_group: field_comparison_group,
objective: field_objective,
outcome_measure: field_outcome_measure,
result: field_result,
})
}
}
impl serde::Serialize for ResearchStudy {
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 {
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.description_summary {
super::super::codec::element_entry(&mut map, "_descriptionSummary", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(item) = &self.name {
super::super::codec::element_entry(&mut map, "_name", item)?;
}
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 !self.associated_party.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"associatedParty",
&self.associated_party,
)?;
}
if !self.classifier.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "classifier", &self.classifier)?;
}
if !self.comparison_group.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"comparisonGroup",
&self.comparison_group,
)?;
}
if !self.condition.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "condition", &self.condition)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.date {
super::super::codec::value_entry(&mut map, "date", item)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if let Some(item) = &self.description_summary {
super::super::codec::value_entry(&mut map, "descriptionSummary", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if !self.focus.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "focus", &self.focus)?;
}
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.keyword.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "keyword", &self.keyword)?;
}
if !self.label.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "label", &self.label)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if let Some(item) = &self.meta {
serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.name {
super::super::codec::value_entry(&mut map, "name", item)?;
}
if !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
if !self.objective.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "objective", &self.objective)?;
}
if !self.outcome_measure.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"outcomeMeasure",
&self.outcome_measure,
)?;
}
if !self.part_of.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "partOf", &self.part_of)?;
}
if let Some(item) = &self.period {
serde::ser::SerializeMap::serialize_entry(&mut map, "period", item)?;
}
if let Some(item) = &self.phase {
serde::ser::SerializeMap::serialize_entry(&mut map, "phase", item)?;
}
if let Some(item) = &self.primary_purpose_type {
serde::ser::SerializeMap::serialize_entry(&mut map, "primaryPurposeType", item)?;
}
if !self.progress_status.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"progressStatus",
&self.progress_status,
)?;
}
if !self.protocol.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "protocol", &self.protocol)?;
}
if let Some(item) = &self.recruitment {
serde::ser::SerializeMap::serialize_entry(&mut map, "recruitment", item)?;
}
if !self.region.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "region", &self.region)?;
}
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", "ResearchStudy")?;
if !self.result.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "result", &self.result)?;
}
if !self.site.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "site", &self.site)?;
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
if !self.study_design.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "studyDesign", &self.study_design)?;
}
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 let Some(item) = &self.version {
super::super::codec::value_entry(&mut map, "version", item)?;
}
if let Some(item) = &self.why_stopped {
serde::ser::SerializeMap::serialize_entry(&mut map, "whyStopped", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ResearchStudy {
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("ResearchStudy");
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 ResearchStudyAssociatedParty {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub name: Option<super::primitives::String>,
pub role: super::codeable_concept::CodeableConcept,
pub period: Vec<super::period::Period>,
pub classifier: Vec<super::codeable_concept::CodeableConcept>,
pub party: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ResearchStudyAssociatedParty {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.name {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_name"), e);
}
}
object.insert(
std::string::String::from("role"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.role)?),
);
if !self.period.is_empty() {
let mut items = Vec::with_capacity(self.period.len());
for item in &self.period {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("period"),
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.party {
object.insert(
std::string::String::from("party"),
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_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: Option<&super::super::codec::Value> = None;
let mut raw_role: Option<&super::super::codec::Value> = None;
let mut raw_period: Option<&super::super::codec::Value> = None;
let mut raw_classifier: Option<&super::super::codec::Value> = None;
let mut raw_party: 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);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"role" => {
raw_role = Some(value);
}
"period" => {
raw_period = Some(value);
}
"classifier" => {
raw_classifier = Some(value);
}
"party" => {
raw_party = 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_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_role = path.with("role", |path| {
let value = raw_role
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
let mut field_period = Vec::new();
if let Some(raw) = raw_period {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_period.push(path.with_index("period", 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_party = raw_party
.map(|value| {
path.with("party", |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,
name: field_name,
role: field_role,
period: field_period,
classifier: field_classifier,
party: field_party,
})
}
}
impl serde::Serialize for ResearchStudyAssociatedParty {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.name {
super::super::codec::element_entry(&mut map, "_name", item)?;
}
if !self.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.name {
super::super::codec::value_entry(&mut map, "name", item)?;
}
if let Some(item) = &self.party {
serde::ser::SerializeMap::serialize_entry(&mut map, "party", item)?;
}
if !self.period.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "period", &self.period)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "role", &self.role)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ResearchStudyAssociatedParty {
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("ResearchStudyAssociatedParty");
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 ResearchStudyComparisonGroup {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub link_id: Option<super::primitives::Id>,
pub name: super::primitives::String,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub description: Option<super::primitives::Markdown>,
pub intended_exposure: Vec<super::reference::Reference>,
pub observed_group: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ResearchStudyComparisonGroup {
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.link_id {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("linkId"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_linkId"), e);
}
}
if let Some(v) = super::super::codec::Primitive::value_json(&self.name)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.name)? {
object.insert(std::string::String::from("_name"), e);
}
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.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.intended_exposure.is_empty() {
let mut items = Vec::with_capacity(self.intended_exposure.len());
for item in &self.intended_exposure {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("intendedExposure"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.observed_group {
object.insert(
std::string::String::from("observedGroup"),
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_link_id: Option<&super::super::codec::Value> = None;
let mut raw_link_id_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_type: 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_intended_exposure: Option<&super::super::codec::Value> = None;
let mut raw_observed_group: 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);
}
"linkId" => {
raw_link_id = Some(value);
}
"_linkId" => {
raw_link_id_element = Some(value);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"type" => {
raw_type = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"intendedExposure" => {
raw_intended_exposure = Some(value);
}
"observedGroup" => {
raw_observed_group = 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_link_id = match (raw_link_id, raw_link_id_element) {
(None, None) => None,
(value, element) => Some(path.with("linkId", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_name = path.with("name", |path| {
super::super::codec::Primitive::from_json_parts(raw_name, raw_name_element, 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_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_intended_exposure = Vec::new();
if let Some(raw) = raw_intended_exposure {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_intended_exposure.push(path.with_index(
"intendedExposure",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_observed_group = raw_observed_group
.map(|value| {
path.with("observedGroup", |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,
link_id: field_link_id,
name: field_name,
r#type: field_type,
description: field_description,
intended_exposure: field_intended_exposure,
observed_group: field_observed_group,
})
}
}
impl serde::Serialize for ResearchStudyComparisonGroup {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.link_id {
super::super::codec::element_entry(&mut map, "_linkId", item)?;
}
super::super::codec::element_entry(&mut map, "_name", &self.name)?;
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.intended_exposure.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"intendedExposure",
&self.intended_exposure,
)?;
}
if let Some(item) = &self.link_id {
super::super::codec::value_entry(&mut map, "linkId", 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, "name", &self.name)?;
if let Some(item) = &self.observed_group {
serde::ser::SerializeMap::serialize_entry(&mut map, "observedGroup", 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 ResearchStudyComparisonGroup {
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("ResearchStudyComparisonGroup");
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 ResearchStudyLabel {
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>,
}
impl super::super::codec::Json for ResearchStudyLabel {
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);
}
}
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;
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);
}
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)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
r#type: field_type,
value: field_value,
})
}
}
impl serde::Serialize for ResearchStudyLabel {
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 !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 ResearchStudyLabel {
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("ResearchStudyLabel");
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 ResearchStudyObjective {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub name: Option<super::primitives::String>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub description: Option<super::primitives::Markdown>,
}
impl super::super::codec::Json for ResearchStudyObjective {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.name {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_name"), e);
}
}
if let Some(item) = &self.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.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);
}
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: Option<&super::super::codec::Value> = None;
let mut raw_type: 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;
for (key, value) in object {
match key.as_str() {
"id" => {
raw_id = Some(value);
}
"extension" => {
raw_extension = Some(value);
}
"modifierExtension" => {
raw_modifier_extension = Some(value);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"type" => {
raw_type = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_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_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_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_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)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
name: field_name,
r#type: field_type,
description: field_description,
})
}
}
impl serde::Serialize for ResearchStudyObjective {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.name {
super::super::codec::element_entry(&mut map, "_name", item)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.name {
super::super::codec::value_entry(&mut map, "name", 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 ResearchStudyObjective {
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("ResearchStudyObjective");
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 ResearchStudyOutcomeMeasure {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub name: Option<super::primitives::String>,
pub r#type: Vec<super::codeable_concept::CodeableConcept>,
pub description: Option<super::primitives::Markdown>,
pub reference: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ResearchStudyOutcomeMeasure {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.name {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("name"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_name"), e);
}
}
if !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.description {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("description"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_description"), e);
}
}
if let Some(item) = &self.reference {
object.insert(
std::string::String::from("reference"),
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_name: Option<&super::super::codec::Value> = None;
let mut raw_name_element: Option<&super::super::codec::Value> = None;
let mut raw_type: 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_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);
}
"name" => {
raw_name = Some(value);
}
"_name" => {
raw_name_element = Some(value);
}
"type" => {
raw_type = Some(value);
}
"description" => {
raw_description = Some(value);
}
"_description" => {
raw_description_element = Some(value);
}
"reference" => {
raw_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_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 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_description = match (raw_description, raw_description_element) {
(None, None) => None,
(value, element) => Some(path.with("description", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_reference = raw_reference
.map(|value| {
path.with("reference", |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,
name: field_name,
r#type: field_type,
description: field_description,
reference: field_reference,
})
}
}
impl serde::Serialize for ResearchStudyOutcomeMeasure {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.description {
super::super::codec::element_entry(&mut map, "_description", item)?;
}
if let Some(item) = &self.name {
super::super::codec::element_entry(&mut map, "_name", item)?;
}
if let Some(item) = &self.description {
super::super::codec::value_entry(&mut map, "description", item)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.name {
super::super::codec::value_entry(&mut map, "name", item)?;
}
if let Some(item) = &self.reference {
serde::ser::SerializeMap::serialize_entry(&mut map, "reference", item)?;
}
if !self.r#type.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "type", &self.r#type)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ResearchStudyOutcomeMeasure {
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("ResearchStudyOutcomeMeasure");
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 ResearchStudyProgressStatus {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub state: super::codeable_concept::CodeableConcept,
pub actual: Option<super::primitives::Boolean>,
pub period: Option<super::period::Period>,
}
impl super::super::codec::Json for ResearchStudyProgressStatus {
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("state"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.state)?),
);
if let Some(item) = &self.actual {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("actual"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_actual"), e);
}
}
if let Some(item) = &self.period {
object.insert(
std::string::String::from("period"),
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_state: 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);
}
"state" => {
raw_state = 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_state = path.with("state", |path| {
let value = raw_state
.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 = raw_period
.map(|value| {
path.with("period", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
state: field_state,
actual: field_actual,
period: field_period,
})
}
}
impl serde::Serialize for ResearchStudyProgressStatus {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
if let Some(item) = &self.actual {
super::super::codec::element_entry(&mut map, "_actual", item)?;
}
if let Some(item) = &self.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,
)?;
}
if let Some(item) = &self.period {
serde::ser::SerializeMap::serialize_entry(&mut map, "period", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "state", &self.state)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ResearchStudyProgressStatus {
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("ResearchStudyProgressStatus");
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 ResearchStudyRecruitment {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub target_number: Option<super::primitives::UnsignedInt>,
pub actual_number: Option<super::primitives::UnsignedInt>,
pub eligibility: Option<super::reference::Reference>,
pub actual_group: Option<super::reference::Reference>,
}
impl super::super::codec::Json for ResearchStudyRecruitment {
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.target_number {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("targetNumber"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_targetNumber"), e);
}
}
if let Some(item) = &self.actual_number {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("actualNumber"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_actualNumber"), e);
}
}
if let Some(item) = &self.eligibility {
object.insert(
std::string::String::from("eligibility"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.actual_group {
object.insert(
std::string::String::from("actualGroup"),
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_target_number: Option<&super::super::codec::Value> = None;
let mut raw_target_number_element: Option<&super::super::codec::Value> = None;
let mut raw_actual_number: Option<&super::super::codec::Value> = None;
let mut raw_actual_number_element: Option<&super::super::codec::Value> = None;
let mut raw_eligibility: Option<&super::super::codec::Value> = None;
let mut raw_actual_group: 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);
}
"targetNumber" => {
raw_target_number = Some(value);
}
"_targetNumber" => {
raw_target_number_element = Some(value);
}
"actualNumber" => {
raw_actual_number = Some(value);
}
"_actualNumber" => {
raw_actual_number_element = Some(value);
}
"eligibility" => {
raw_eligibility = Some(value);
}
"actualGroup" => {
raw_actual_group = 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_target_number = match (raw_target_number, raw_target_number_element) {
(None, None) => None,
(value, element) => Some(path.with("targetNumber", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_actual_number = match (raw_actual_number, raw_actual_number_element) {
(None, None) => None,
(value, element) => Some(path.with("actualNumber", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_eligibility = raw_eligibility
.map(|value| {
path.with("eligibility", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_actual_group = raw_actual_group
.map(|value| {
path.with("actualGroup", |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,
target_number: field_target_number,
actual_number: field_actual_number,
eligibility: field_eligibility,
actual_group: field_actual_group,
})
}
}
impl serde::Serialize for ResearchStudyRecruitment {
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_number {
super::super::codec::element_entry(&mut map, "_actualNumber", item)?;
}
if let Some(item) = &self.target_number {
super::super::codec::element_entry(&mut map, "_targetNumber", item)?;
}
if let Some(item) = &self.actual_group {
serde::ser::SerializeMap::serialize_entry(&mut map, "actualGroup", item)?;
}
if let Some(item) = &self.actual_number {
super::super::codec::value_entry(&mut map, "actualNumber", item)?;
}
if let Some(item) = &self.eligibility {
serde::ser::SerializeMap::serialize_entry(&mut map, "eligibility", 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.target_number {
super::super::codec::value_entry(&mut map, "targetNumber", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ResearchStudyRecruitment {
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("ResearchStudyRecruitment");
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)
}
}