#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ServiceRequest {
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 identifier: Vec<super::identifier::Identifier>,
pub instantiates_canonical: Vec<super::primitives::Canonical>,
pub instantiates_uri: Vec<super::primitives::Uri>,
pub based_on: Vec<super::reference::Reference>,
pub replaces: Vec<super::reference::Reference>,
pub requisition: Option<super::identifier::Identifier>,
pub status: super::primitives::Code,
pub intent: super::primitives::Code,
pub category: Vec<super::codeable_concept::CodeableConcept>,
pub priority: Option<super::primitives::Code>,
pub do_not_perform: Option<super::primitives::Boolean>,
pub code: Option<super::codeable_concept::CodeableConcept>,
pub order_detail: Vec<super::codeable_concept::CodeableConcept>,
pub quantity: Option<ServiceRequestQuantity>,
pub subject: super::reference::Reference,
pub encounter: Option<super::reference::Reference>,
pub occurrence: Option<ServiceRequestOccurrence>,
pub as_needed: Option<ServiceRequestAsNeeded>,
pub authored_on: Option<super::primitives::DateTime>,
pub requester: Option<super::reference::Reference>,
pub performer_type: Option<super::codeable_concept::CodeableConcept>,
pub performer: Vec<super::reference::Reference>,
pub location_code: Vec<super::codeable_concept::CodeableConcept>,
pub location_reference: Vec<super::reference::Reference>,
pub reason_code: Vec<super::codeable_concept::CodeableConcept>,
pub reason_reference: Vec<super::reference::Reference>,
pub insurance: Vec<super::reference::Reference>,
pub supporting_info: Vec<super::reference::Reference>,
pub specimen: Vec<super::reference::Reference>,
pub body_site: Vec<super::codeable_concept::CodeableConcept>,
pub note: Vec<super::annotation::Annotation>,
pub patient_instruction: Option<super::primitives::String>,
pub relevant_history: Vec<super::reference::Reference>,
}
impl super::super::codec::Json for ServiceRequest {
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("ServiceRequest")),
);
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if let Some(item) = &self.meta {
object.insert(
std::string::String::from("meta"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.implicit_rules {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("implicitRules"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_implicitRules"), e);
}
}
if let Some(item) = &self.language {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("language"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_language"), e);
}
}
if let Some(item) = &self.text {
object.insert(
std::string::String::from("text"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.contained.is_empty() {
let mut items = Vec::with_capacity(self.contained.len());
for item in &self.contained {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("contained"),
super::super::codec::Value::Array(items),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.identifier.is_empty() {
let mut items = Vec::with_capacity(self.identifier.len());
for item in &self.identifier {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("identifier"),
super::super::codec::Value::Array(items),
);
}
if !self.instantiates_canonical.is_empty() {
let (values, elements) =
super::super::codec::primitive_arrays(&self.instantiates_canonical)?;
object.insert(std::string::String::from("instantiatesCanonical"), values);
if let Some(elements) = elements {
object.insert(
std::string::String::from("_instantiatesCanonical"),
elements,
);
}
}
if !self.instantiates_uri.is_empty() {
let (values, elements) = super::super::codec::primitive_arrays(&self.instantiates_uri)?;
object.insert(std::string::String::from("instantiatesUri"), values);
if let Some(elements) = elements {
object.insert(std::string::String::from("_instantiatesUri"), elements);
}
}
if !self.based_on.is_empty() {
let mut items = Vec::with_capacity(self.based_on.len());
for item in &self.based_on {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("basedOn"),
super::super::codec::Value::Array(items),
);
}
if !self.replaces.is_empty() {
let mut items = Vec::with_capacity(self.replaces.len());
for item in &self.replaces {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("replaces"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.requisition {
object.insert(
std::string::String::from("requisition"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
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(v) = super::super::codec::Primitive::value_json(&self.intent)? {
object.insert(std::string::String::from("intent"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(&self.intent)? {
object.insert(std::string::String::from("_intent"), e);
}
if !self.category.is_empty() {
let mut items = Vec::with_capacity(self.category.len());
for item in &self.category {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("category"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.priority {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("priority"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_priority"), e);
}
}
if let Some(item) = &self.do_not_perform {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("doNotPerform"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_doNotPerform"), e);
}
}
if let Some(item) = &self.code {
object.insert(
std::string::String::from("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.order_detail.is_empty() {
let mut items = Vec::with_capacity(self.order_detail.len());
for item in &self.order_detail {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("orderDetail"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.quantity {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("quantity{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_quantity{suffix}"), element);
}
}
object.insert(
std::string::String::from("subject"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.subject)?),
);
if let Some(item) = &self.encounter {
object.insert(
std::string::String::from("encounter"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.occurrence {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("occurrence{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_occurrence{suffix}"), element);
}
}
if let Some(item) = &self.as_needed {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("asNeeded{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_asNeeded{suffix}"), element);
}
}
if let Some(item) = &self.authored_on {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("authoredOn"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_authoredOn"), e);
}
}
if let Some(item) = &self.requester {
object.insert(
std::string::String::from("requester"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.performer_type {
object.insert(
std::string::String::from("performerType"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.performer.is_empty() {
let mut items = Vec::with_capacity(self.performer.len());
for item in &self.performer {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("performer"),
super::super::codec::Value::Array(items),
);
}
if !self.location_code.is_empty() {
let mut items = Vec::with_capacity(self.location_code.len());
for item in &self.location_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("locationCode"),
super::super::codec::Value::Array(items),
);
}
if !self.location_reference.is_empty() {
let mut items = Vec::with_capacity(self.location_reference.len());
for item in &self.location_reference {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("locationReference"),
super::super::codec::Value::Array(items),
);
}
if !self.reason_code.is_empty() {
let mut items = Vec::with_capacity(self.reason_code.len());
for item in &self.reason_code {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reasonCode"),
super::super::codec::Value::Array(items),
);
}
if !self.reason_reference.is_empty() {
let mut items = Vec::with_capacity(self.reason_reference.len());
for item in &self.reason_reference {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("reasonReference"),
super::super::codec::Value::Array(items),
);
}
if !self.insurance.is_empty() {
let mut items = Vec::with_capacity(self.insurance.len());
for item in &self.insurance {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("insurance"),
super::super::codec::Value::Array(items),
);
}
if !self.supporting_info.is_empty() {
let mut items = Vec::with_capacity(self.supporting_info.len());
for item in &self.supporting_info {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("supportingInfo"),
super::super::codec::Value::Array(items),
);
}
if !self.specimen.is_empty() {
let mut items = Vec::with_capacity(self.specimen.len());
for item in &self.specimen {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("specimen"),
super::super::codec::Value::Array(items),
);
}
if !self.body_site.is_empty() {
let mut items = Vec::with_capacity(self.body_site.len());
for item in &self.body_site {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("bodySite"),
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 let Some(item) = &self.patient_instruction {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("patientInstruction"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_patientInstruction"), e);
}
}
if !self.relevant_history.is_empty() {
let mut items = Vec::with_capacity(self.relevant_history.len());
for item in &self.relevant_history {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("relevantHistory"),
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_identifier: Option<&super::super::codec::Value> = None;
let mut raw_instantiates_canonical: Option<&super::super::codec::Value> = None;
let mut raw_instantiates_canonical_element: Option<&super::super::codec::Value> = None;
let mut raw_instantiates_uri: Option<&super::super::codec::Value> = None;
let mut raw_instantiates_uri_element: Option<&super::super::codec::Value> = None;
let mut raw_based_on: Option<&super::super::codec::Value> = None;
let mut raw_replaces: Option<&super::super::codec::Value> = None;
let mut raw_requisition: 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_intent: Option<&super::super::codec::Value> = None;
let mut raw_intent_element: Option<&super::super::codec::Value> = None;
let mut raw_category: Option<&super::super::codec::Value> = None;
let mut raw_priority: Option<&super::super::codec::Value> = None;
let mut raw_priority_element: Option<&super::super::codec::Value> = None;
let mut raw_do_not_perform: Option<&super::super::codec::Value> = None;
let mut raw_do_not_perform_element: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_order_detail: Option<&super::super::codec::Value> = None;
let mut raw_quantity = super::super::codec::ChoiceSlot::default();
let mut raw_subject: Option<&super::super::codec::Value> = None;
let mut raw_encounter: Option<&super::super::codec::Value> = None;
let mut raw_occurrence = super::super::codec::ChoiceSlot::default();
let mut raw_as_needed = super::super::codec::ChoiceSlot::default();
let mut raw_authored_on: Option<&super::super::codec::Value> = None;
let mut raw_authored_on_element: Option<&super::super::codec::Value> = None;
let mut raw_requester: Option<&super::super::codec::Value> = None;
let mut raw_performer_type: Option<&super::super::codec::Value> = None;
let mut raw_performer: Option<&super::super::codec::Value> = None;
let mut raw_location_code: Option<&super::super::codec::Value> = None;
let mut raw_location_reference: Option<&super::super::codec::Value> = None;
let mut raw_reason_code: Option<&super::super::codec::Value> = None;
let mut raw_reason_reference: Option<&super::super::codec::Value> = None;
let mut raw_insurance: Option<&super::super::codec::Value> = None;
let mut raw_supporting_info: Option<&super::super::codec::Value> = None;
let mut raw_specimen: Option<&super::super::codec::Value> = None;
let mut raw_body_site: Option<&super::super::codec::Value> = None;
let mut raw_note: Option<&super::super::codec::Value> = None;
let mut raw_patient_instruction: Option<&super::super::codec::Value> = None;
let mut raw_patient_instruction_element: Option<&super::super::codec::Value> = None;
let mut raw_relevant_history: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("ServiceRequest") {
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);
}
"identifier" => {
raw_identifier = Some(value);
}
"instantiatesCanonical" => {
raw_instantiates_canonical = Some(value);
}
"_instantiatesCanonical" => {
raw_instantiates_canonical_element = Some(value);
}
"instantiatesUri" => {
raw_instantiates_uri = Some(value);
}
"_instantiatesUri" => {
raw_instantiates_uri_element = Some(value);
}
"basedOn" => {
raw_based_on = Some(value);
}
"replaces" => {
raw_replaces = Some(value);
}
"requisition" => {
raw_requisition = Some(value);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"intent" => {
raw_intent = Some(value);
}
"_intent" => {
raw_intent_element = Some(value);
}
"category" => {
raw_category = Some(value);
}
"priority" => {
raw_priority = Some(value);
}
"_priority" => {
raw_priority_element = Some(value);
}
"doNotPerform" => {
raw_do_not_perform = Some(value);
}
"_doNotPerform" => {
raw_do_not_perform_element = Some(value);
}
"code" => {
raw_code = Some(value);
}
"orderDetail" => {
raw_order_detail = Some(value);
}
"quantityQuantity" => {
raw_quantity.value("Quantity", value, path)?;
}
"_quantityQuantity" => {
raw_quantity.element("Quantity", value, path)?;
}
"quantityRatio" => {
raw_quantity.value("Ratio", value, path)?;
}
"_quantityRatio" => {
raw_quantity.element("Ratio", value, path)?;
}
"quantityRange" => {
raw_quantity.value("Range", value, path)?;
}
"_quantityRange" => {
raw_quantity.element("Range", value, path)?;
}
"subject" => {
raw_subject = Some(value);
}
"encounter" => {
raw_encounter = Some(value);
}
"occurrenceDateTime" => {
raw_occurrence.value("DateTime", value, path)?;
}
"_occurrenceDateTime" => {
raw_occurrence.element("DateTime", value, path)?;
}
"occurrencePeriod" => {
raw_occurrence.value("Period", value, path)?;
}
"_occurrencePeriod" => {
raw_occurrence.element("Period", value, path)?;
}
"occurrenceTiming" => {
raw_occurrence.value("Timing", value, path)?;
}
"_occurrenceTiming" => {
raw_occurrence.element("Timing", value, path)?;
}
"asNeededBoolean" => {
raw_as_needed.value("Boolean", value, path)?;
}
"_asNeededBoolean" => {
raw_as_needed.element("Boolean", value, path)?;
}
"asNeededCodeableConcept" => {
raw_as_needed.value("CodeableConcept", value, path)?;
}
"_asNeededCodeableConcept" => {
raw_as_needed.element("CodeableConcept", value, path)?;
}
"authoredOn" => {
raw_authored_on = Some(value);
}
"_authoredOn" => {
raw_authored_on_element = Some(value);
}
"requester" => {
raw_requester = Some(value);
}
"performerType" => {
raw_performer_type = Some(value);
}
"performer" => {
raw_performer = Some(value);
}
"locationCode" => {
raw_location_code = Some(value);
}
"locationReference" => {
raw_location_reference = Some(value);
}
"reasonCode" => {
raw_reason_code = Some(value);
}
"reasonReference" => {
raw_reason_reference = Some(value);
}
"insurance" => {
raw_insurance = Some(value);
}
"supportingInfo" => {
raw_supporting_info = Some(value);
}
"specimen" => {
raw_specimen = Some(value);
}
"bodySite" => {
raw_body_site = Some(value);
}
"note" => {
raw_note = Some(value);
}
"patientInstruction" => {
raw_patient_instruction = Some(value);
}
"_patientInstruction" => {
raw_patient_instruction_element = Some(value);
}
"relevantHistory" => {
raw_relevant_history = 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 field_meta = raw_meta
.map(|value| {
path.with("meta", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
(None, None) => None,
(value, element) => Some(path.with("implicitRules", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_language = match (raw_language, raw_language_element) {
(None, None) => None,
(value, element) => Some(path.with("language", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = raw_text
.map(|value| {
path.with("text", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_contained = Vec::new();
if let Some(raw) = raw_contained {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_contained.push(path.with_index("contained", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_identifier = Vec::new();
if let Some(raw) = raw_identifier {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_identifier.push(path.with_index("identifier", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_instantiates_canonical = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_instantiates_canonical,
raw_instantiates_canonical_element,
path,
)?
.into_iter()
.enumerate()
{
field_instantiates_canonical.push(path.with_index(
"instantiatesCanonical",
index,
|path| super::super::codec::Primitive::from_json_parts(value, element, path),
)?);
}
let mut field_instantiates_uri = Vec::new();
for (index, (value, element)) in super::super::codec::pair_arrays(
raw_instantiates_uri,
raw_instantiates_uri_element,
path,
)?
.into_iter()
.enumerate()
{
field_instantiates_uri.push(path.with_index("instantiatesUri", index, |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?);
}
let mut field_based_on = Vec::new();
if let Some(raw) = raw_based_on {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_based_on.push(path.with_index("basedOn", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_replaces = Vec::new();
if let Some(raw) = raw_replaces {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_replaces.push(path.with_index("replaces", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_requisition = raw_requisition
.map(|value| {
path.with("requisition", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_status = path.with("status", |path| {
super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
})?;
let field_intent = path.with("intent", |path| {
super::super::codec::Primitive::from_json_parts(raw_intent, raw_intent_element, path)
})?;
let mut field_category = Vec::new();
if let Some(raw) = raw_category {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_category.push(path.with_index("category", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_priority = match (raw_priority, raw_priority_element) {
(None, None) => None,
(value, element) => Some(path.with("priority", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_do_not_perform = match (raw_do_not_perform, raw_do_not_perform_element) {
(None, None) => None,
(value, element) => Some(path.with("doNotPerform", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_code = raw_code
.map(|value| {
path.with("code", |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_order_detail = Vec::new();
if let Some(raw) = raw_order_detail {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_order_detail.push(path.with_index("orderDetail", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_quantity = match raw_quantity.suffix {
None => None,
Some(suffix) => Some(path.with("quantity", |path| {
ServiceRequestQuantity::from_json_parts(
suffix,
raw_quantity.value,
raw_quantity.element,
path,
)
})?),
};
let field_subject = path.with("subject", |path| {
let value = raw_subject
.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_encounter = raw_encounter
.map(|value| {
path.with("encounter", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_occurrence = match raw_occurrence.suffix {
None => None,
Some(suffix) => Some(path.with("occurrence", |path| {
ServiceRequestOccurrence::from_json_parts(
suffix,
raw_occurrence.value,
raw_occurrence.element,
path,
)
})?),
};
let field_as_needed = match raw_as_needed.suffix {
None => None,
Some(suffix) => Some(path.with("asNeeded", |path| {
ServiceRequestAsNeeded::from_json_parts(
suffix,
raw_as_needed.value,
raw_as_needed.element,
path,
)
})?),
};
let field_authored_on = match (raw_authored_on, raw_authored_on_element) {
(None, None) => None,
(value, element) => Some(path.with("authoredOn", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_requester = raw_requester
.map(|value| {
path.with("requester", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_performer_type = raw_performer_type
.map(|value| {
path.with("performerType", |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_performer = Vec::new();
if let Some(raw) = raw_performer {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_performer.push(path.with_index("performer", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_location_code = Vec::new();
if let Some(raw) = raw_location_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_location_code.push(path.with_index("locationCode", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_location_reference = Vec::new();
if let Some(raw) = raw_location_reference {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_location_reference.push(path.with_index(
"locationReference",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let mut field_reason_code = Vec::new();
if let Some(raw) = raw_reason_code {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reason_code.push(path.with_index("reasonCode", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_reason_reference = Vec::new();
if let Some(raw) = raw_reason_reference {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reason_reference.push(path.with_index("reasonReference", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_insurance = Vec::new();
if let Some(raw) = raw_insurance {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_insurance.push(path.with_index("insurance", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_supporting_info = Vec::new();
if let Some(raw) = raw_supporting_info {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_supporting_info.push(path.with_index("supportingInfo", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_specimen = Vec::new();
if let Some(raw) = raw_specimen {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_specimen.push(path.with_index("specimen", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_body_site = Vec::new();
if let Some(raw) = raw_body_site {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_body_site.push(path.with_index("bodySite", 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 field_patient_instruction =
match (raw_patient_instruction, raw_patient_instruction_element) {
(None, None) => None,
(value, element) => Some(path.with("patientInstruction", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_relevant_history = Vec::new();
if let Some(raw) = raw_relevant_history {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_relevant_history.push(path.with_index("relevantHistory", 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,
identifier: field_identifier,
instantiates_canonical: field_instantiates_canonical,
instantiates_uri: field_instantiates_uri,
based_on: field_based_on,
replaces: field_replaces,
requisition: field_requisition,
status: field_status,
intent: field_intent,
category: field_category,
priority: field_priority,
do_not_perform: field_do_not_perform,
code: field_code,
order_detail: field_order_detail,
quantity: field_quantity,
subject: field_subject,
encounter: field_encounter,
occurrence: field_occurrence,
as_needed: field_as_needed,
authored_on: field_authored_on,
requester: field_requester,
performer_type: field_performer_type,
performer: field_performer,
location_code: field_location_code,
location_reference: field_location_reference,
reason_code: field_reason_code,
reason_reference: field_reason_reference,
insurance: field_insurance,
supporting_info: field_supporting_info,
specimen: field_specimen,
body_site: field_body_site,
note: field_note,
patient_instruction: field_patient_instruction,
relevant_history: field_relevant_history,
})
}
}
impl serde::Serialize for ServiceRequest {
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(ServiceRequestAsNeeded::Boolean(inner)) = &self.as_needed {
super::super::codec::element_entry(&mut map, "_asNeededBoolean", inner)?;
}
if let Some(item) = &self.authored_on {
super::super::codec::element_entry(&mut map, "_authoredOn", item)?;
}
if let Some(item) = &self.do_not_perform {
super::super::codec::element_entry(&mut map, "_doNotPerform", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
}
super::super::codec::element_list_entry(
&mut map,
"_instantiatesCanonical",
&self.instantiates_canonical,
)?;
super::super::codec::element_list_entry(
&mut map,
"_instantiatesUri",
&self.instantiates_uri,
)?;
super::super::codec::element_entry(&mut map, "_intent", &self.intent)?;
if let Some(item) = &self.language {
super::super::codec::element_entry(&mut map, "_language", item)?;
}
if let Some(ServiceRequestOccurrence::DateTime(inner)) = &self.occurrence {
super::super::codec::element_entry(&mut map, "_occurrenceDateTime", inner)?;
}
if let Some(item) = &self.patient_instruction {
super::super::codec::element_entry(&mut map, "_patientInstruction", item)?;
}
if let Some(item) = &self.priority {
super::super::codec::element_entry(&mut map, "_priority", item)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
match &self.as_needed {
Some(ServiceRequestAsNeeded::Boolean(inner)) => {
super::super::codec::value_entry(&mut map, "asNeededBoolean", inner)?;
}
Some(ServiceRequestAsNeeded::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"asNeededCodeableConcept",
inner.as_ref(),
)?;
}
None => {}
}
if let Some(item) = &self.authored_on {
super::super::codec::value_entry(&mut map, "authoredOn", item)?;
}
if !self.based_on.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "basedOn", &self.based_on)?;
}
if !self.body_site.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "bodySite", &self.body_site)?;
}
if !self.category.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
}
if let Some(item) = &self.code {
serde::ser::SerializeMap::serialize_entry(&mut map, "code", item)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if let Some(item) = &self.do_not_perform {
super::super::codec::value_entry(&mut map, "doNotPerform", item)?;
}
if let Some(item) = &self.encounter {
serde::ser::SerializeMap::serialize_entry(&mut map, "encounter", 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)?;
}
super::super::codec::value_list_entry(
&mut map,
"instantiatesCanonical",
&self.instantiates_canonical,
)?;
super::super::codec::value_list_entry(&mut map, "instantiatesUri", &self.instantiates_uri)?;
if !self.insurance.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "insurance", &self.insurance)?;
}
super::super::codec::value_entry(&mut map, "intent", &self.intent)?;
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if !self.location_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"locationCode",
&self.location_code,
)?;
}
if !self.location_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"locationReference",
&self.location_reference,
)?;
}
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 !self.note.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "note", &self.note)?;
}
match &self.occurrence {
Some(ServiceRequestOccurrence::DateTime(inner)) => {
super::super::codec::value_entry(&mut map, "occurrenceDateTime", inner)?;
}
Some(ServiceRequestOccurrence::Period(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"occurrencePeriod",
inner.as_ref(),
)?;
}
Some(ServiceRequestOccurrence::Timing(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"occurrenceTiming",
inner.as_ref(),
)?;
}
None => {}
}
if !self.order_detail.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "orderDetail", &self.order_detail)?;
}
if let Some(item) = &self.patient_instruction {
super::super::codec::value_entry(&mut map, "patientInstruction", item)?;
}
if !self.performer.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "performer", &self.performer)?;
}
if let Some(item) = &self.performer_type {
serde::ser::SerializeMap::serialize_entry(&mut map, "performerType", item)?;
}
if let Some(item) = &self.priority {
super::super::codec::value_entry(&mut map, "priority", item)?;
}
match &self.quantity {
Some(ServiceRequestQuantity::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"quantityQuantity",
inner.as_ref(),
)?;
}
Some(ServiceRequestQuantity::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"quantityRange",
inner.as_ref(),
)?;
}
Some(ServiceRequestQuantity::Ratio(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"quantityRatio",
inner.as_ref(),
)?;
}
None => {}
}
if !self.reason_code.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "reasonCode", &self.reason_code)?;
}
if !self.reason_reference.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"reasonReference",
&self.reason_reference,
)?;
}
if !self.relevant_history.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"relevantHistory",
&self.relevant_history,
)?;
}
if !self.replaces.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "replaces", &self.replaces)?;
}
if let Some(item) = &self.requester {
serde::ser::SerializeMap::serialize_entry(&mut map, "requester", item)?;
}
if let Some(item) = &self.requisition {
serde::ser::SerializeMap::serialize_entry(&mut map, "requisition", item)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "ServiceRequest")?;
if !self.specimen.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "specimen", &self.specimen)?;
}
super::super::codec::value_entry(&mut map, "status", &self.status)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "subject", &self.subject)?;
if !self.supporting_info.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"supportingInfo",
&self.supporting_info,
)?;
}
if let Some(item) = &self.text {
serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for ServiceRequest {
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("ServiceRequest");
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 ServiceRequestAsNeeded {
Boolean(super::primitives::Boolean),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
}
impl ServiceRequestAsNeeded {
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::Boolean(inner) => Ok((
"Boolean",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
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 {
"Boolean" => Ok(Self::Boolean(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ServiceRequestOccurrence {
DateTime(super::primitives::DateTime),
Period(Box<super::period::Period>),
Timing(Box<super::timing::Timing>),
}
impl ServiceRequestOccurrence {
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::DateTime(inner) => Ok((
"DateTime",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::Period(inner) => Ok((
"Period",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Timing(inner) => Ok((
"Timing",
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 {
"DateTime" => Ok(Self::DateTime(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"Period" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Period(Box::new(inner)))
}
"Timing" => {
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::Timing(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ServiceRequestQuantity {
Quantity(Box<super::quantity::Quantity>),
Ratio(Box<super::ratio::Ratio>),
Range(Box<super::range::Range>),
}
impl ServiceRequestQuantity {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<super::super::codec::Value>,
Option<super::super::codec::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::Quantity(inner) => Ok((
"Quantity",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Ratio(inner) => Ok((
"Ratio",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Range(inner) => Ok((
"Range",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Quantity" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Quantity(Box::new(inner)))
}
"Ratio" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Ratio(Box::new(inner)))
}
"Range" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Range(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}