#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Dosage {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub condition: Vec<super::dosage_condition::DosageCondition>,
pub text: Option<super::primitives::String>,
pub additional_instruction: Vec<super::codeable_concept::CodeableConcept>,
pub patient_instruction: Option<super::primitives::String>,
pub timing: Option<super::timing::Timing>,
pub as_needed: Option<super::primitives::Boolean>,
pub as_needed_for: Vec<super::codeable_concept::CodeableConcept>,
pub site: Option<super::codeable_reference::CodeableReference>,
pub route: Option<super::codeable_concept::CodeableConcept>,
pub method: Option<super::codeable_concept::CodeableConcept>,
pub dose_and_rate: Vec<DosageDoseAndRate>,
pub safety: Option<super::dosage_safety::DosageSafety>,
}
impl super::super::codec::Json for Dosage {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
super::super::codec::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
super::super::codec::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
super::super::codec::Value::Array(items),
);
}
if !self.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 let Some(item) = &self.text {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("text"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_text"), e);
}
}
if !self.additional_instruction.is_empty() {
let mut items = Vec::with_capacity(self.additional_instruction.len());
for item in &self.additional_instruction {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("additionalInstruction"),
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 let Some(item) = &self.timing {
object.insert(
std::string::String::from("timing"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.as_needed {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("asNeeded"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_asNeeded"), e);
}
}
if !self.as_needed_for.is_empty() {
let mut items = Vec::with_capacity(self.as_needed_for.len());
for item in &self.as_needed_for {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("asNeededFor"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.site {
object.insert(
std::string::String::from("site"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.route {
object.insert(
std::string::String::from("route"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.method {
object.insert(
std::string::String::from("method"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.dose_and_rate.is_empty() {
let mut items = Vec::with_capacity(self.dose_and_rate.len());
for item in &self.dose_and_rate {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("doseAndRate"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.safety {
object.insert(
std::string::String::from("safety"),
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_condition: Option<&super::super::codec::Value> = None;
let mut raw_text: Option<&super::super::codec::Value> = None;
let mut raw_text_element: Option<&super::super::codec::Value> = None;
let mut raw_additional_instruction: 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_timing: Option<&super::super::codec::Value> = None;
let mut raw_as_needed: Option<&super::super::codec::Value> = None;
let mut raw_as_needed_element: Option<&super::super::codec::Value> = None;
let mut raw_as_needed_for: Option<&super::super::codec::Value> = None;
let mut raw_site: Option<&super::super::codec::Value> = None;
let mut raw_route: Option<&super::super::codec::Value> = None;
let mut raw_method: Option<&super::super::codec::Value> = None;
let mut raw_dose_and_rate: Option<&super::super::codec::Value> = None;
let mut raw_safety: 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),
"condition" => raw_condition = Some(value),
"text" => raw_text = Some(value),
"_text" => raw_text_element = Some(value),
"additionalInstruction" => raw_additional_instruction = Some(value),
"patientInstruction" => raw_patient_instruction = Some(value),
"_patientInstruction" => raw_patient_instruction_element = Some(value),
"timing" => raw_timing = Some(value),
"asNeeded" => raw_as_needed = Some(value),
"_asNeeded" => raw_as_needed_element = Some(value),
"asNeededFor" => raw_as_needed_for = Some(value),
"site" => raw_site = Some(value),
"route" => raw_route = Some(value),
"method" => raw_method = Some(value),
"doseAndRate" => raw_dose_and_rate = Some(value),
"safety" => raw_safety = Some(value),
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let 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_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 field_text = match (raw_text, raw_text_element) {
(None, None) => None,
(value, element) => Some(path.with("text", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_additional_instruction = Vec::new();
if let Some(raw) = raw_additional_instruction {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_additional_instruction.push(path.with_index(
"additionalInstruction",
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 field_timing = raw_timing
.map(|value| {
path.with("timing", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_as_needed = match (raw_as_needed, raw_as_needed_element) {
(None, None) => None,
(value, element) => Some(path.with("asNeeded", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_as_needed_for = Vec::new();
if let Some(raw) = raw_as_needed_for {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_as_needed_for.push(path.with_index("asNeededFor", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_site = raw_site
.map(|value| {
path.with("site", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_route = raw_route
.map(|value| {
path.with("route", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_method = raw_method
.map(|value| {
path.with("method", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_dose_and_rate = Vec::new();
if let Some(raw) = raw_dose_and_rate {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_dose_and_rate.push(path.with_index("doseAndRate", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_safety = raw_safety
.map(|value| {
path.with("safety", |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,
condition: field_condition,
text: field_text,
additional_instruction: field_additional_instruction,
patient_instruction: field_patient_instruction,
timing: field_timing,
as_needed: field_as_needed,
as_needed_for: field_as_needed_for,
site: field_site,
route: field_route,
method: field_method,
dose_and_rate: field_dose_and_rate,
safety: field_safety,
})
}
}
impl serde::Serialize for Dosage {
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.as_needed {
super::super::codec::element_entry(&mut map, "_asNeeded", item)?;
}
if let Some(item) = &self.patient_instruction {
super::super::codec::element_entry(&mut map, "_patientInstruction", item)?;
}
if let Some(item) = &self.text {
super::super::codec::element_entry(&mut map, "_text", item)?;
}
if !self.additional_instruction.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"additionalInstruction",
&self.additional_instruction,
)?;
}
if let Some(item) = &self.as_needed {
super::super::codec::value_entry(&mut map, "asNeeded", item)?;
}
if !self.as_needed_for.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"asNeededFor",
&self.as_needed_for,
)?;
}
if !self.condition.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "condition", &self.condition)?;
}
if !self.dose_and_rate.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"doseAndRate",
&self.dose_and_rate,
)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.method {
serde::ser::SerializeMap::serialize_entry(&mut map, "method", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.patient_instruction {
super::super::codec::value_entry(&mut map, "patientInstruction", item)?;
}
if let Some(item) = &self.route {
serde::ser::SerializeMap::serialize_entry(&mut map, "route", item)?;
}
if let Some(item) = &self.safety {
serde::ser::SerializeMap::serialize_entry(&mut map, "safety", item)?;
}
if let Some(item) = &self.site {
serde::ser::SerializeMap::serialize_entry(&mut map, "site", item)?;
}
if let Some(item) = &self.text {
super::super::codec::value_entry(&mut map, "text", item)?;
}
if let Some(item) = &self.timing {
serde::ser::SerializeMap::serialize_entry(&mut map, "timing", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for Dosage {
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("Dosage");
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 DosageDoseAndRate {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub dose: Option<DosageDoseAndRateDose>,
pub rate: Option<DosageDoseAndRateRate>,
}
impl super::super::codec::Json for DosageDoseAndRate {
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 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.dose {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("dose{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_dose{suffix}"), element);
}
}
if let Some(item) = &self.rate {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("rate{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_rate{suffix}"), element);
}
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_type: Option<&super::super::codec::Value> = None;
let mut raw_dose = super::super::codec::ChoiceSlot::default();
let mut raw_rate = super::super::codec::ChoiceSlot::default();
for (key, value) in object {
match key.as_str() {
"id" => raw_id = Some(value),
"extension" => raw_extension = Some(value),
"type" => raw_type = Some(value),
"doseRange" => {
raw_dose.value("Range", value, path)?;
}
"_doseRange" => {
raw_dose.element("Range", value, path)?;
}
"doseQuantity" => {
raw_dose.value("Quantity", value, path)?;
}
"_doseQuantity" => {
raw_dose.element("Quantity", value, path)?;
}
"doseExpression" => {
raw_dose.value("Expression", value, path)?;
}
"_doseExpression" => {
raw_dose.element("Expression", value, path)?;
}
"rateRatio" => {
raw_rate.value("Ratio", value, path)?;
}
"_rateRatio" => {
raw_rate.element("Ratio", value, path)?;
}
"rateRange" => {
raw_rate.value("Range", value, path)?;
}
"_rateRange" => {
raw_rate.element("Range", value, path)?;
}
"rateQuantity" => {
raw_rate.value("Quantity", value, path)?;
}
"_rateQuantity" => {
raw_rate.element("Quantity", value, path)?;
}
"rateExpression" => {
raw_rate.value("Expression", value, path)?;
}
"_rateExpression" => {
raw_rate.element("Expression", value, path)?;
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, 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 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_dose = match raw_dose.suffix {
None => None,
Some(suffix) => Some(path.with("dose", |path| {
DosageDoseAndRateDose::from_json_parts(
suffix,
raw_dose.value,
raw_dose.element,
path,
)
})?),
};
let field_rate = match raw_rate.suffix {
None => None,
Some(suffix) => Some(path.with("rate", |path| {
DosageDoseAndRateRate::from_json_parts(
suffix,
raw_rate.value,
raw_rate.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
r#type: field_type,
dose: field_dose,
rate: field_rate,
})
}
}
impl serde::Serialize for DosageDoseAndRate {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
match &self.dose {
Some(DosageDoseAndRateDose::Expression(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"doseExpression",
inner.as_ref(),
)?;
}
Some(DosageDoseAndRateDose::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"doseQuantity",
inner.as_ref(),
)?;
}
Some(DosageDoseAndRateDose::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "doseRange", inner.as_ref())?;
}
None => {}
}
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)?;
}
match &self.rate {
Some(DosageDoseAndRateRate::Expression(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"rateExpression",
inner.as_ref(),
)?;
}
Some(DosageDoseAndRateRate::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"rateQuantity",
inner.as_ref(),
)?;
}
Some(DosageDoseAndRateRate::Range(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "rateRange", inner.as_ref())?;
}
Some(DosageDoseAndRateRate::Ratio(inner)) => {
serde::ser::SerializeMap::serialize_entry(&mut map, "rateRatio", inner.as_ref())?;
}
None => {}
}
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 DosageDoseAndRate {
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("DosageDoseAndRate");
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 DosageDoseAndRateDose {
Range(Box<super::range::Range>),
Quantity(Box<super::quantity::Quantity>),
Expression(Box<super::expression::Expression>),
}
impl DosageDoseAndRateDose {
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::Range(inner) => Ok((
"Range",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Quantity(inner) => Ok((
"Quantity",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Expression(inner) => Ok((
"Expression",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"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)))
}
"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)))
}
"Expression" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Expression(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DosageDoseAndRateRate {
Ratio(Box<super::ratio::Ratio>),
Range(Box<super::range::Range>),
Quantity(Box<super::quantity::Quantity>),
Expression(Box<super::expression::Expression>),
}
impl DosageDoseAndRateRate {
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::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,
)),
Self::Quantity(inner) => Ok((
"Quantity",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::Expression(inner) => Ok((
"Expression",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&super::super::codec::Value>,
element: Option<&super::super::codec::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"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)))
}
"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)))
}
"Expression" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Expression(Box::new(inner)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}