#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Ingredient {
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: Option<super::identifier::Identifier>,
pub status: super::primitives::Code,
pub r#for: Vec<super::reference::Reference>,
pub role: super::codeable_concept::CodeableConcept,
pub function: Vec<super::codeable_concept::CodeableConcept>,
pub group: Option<super::codeable_concept::CodeableConcept>,
pub allergenic_indicator: Option<super::primitives::Boolean>,
pub comment: Option<super::primitives::Markdown>,
pub manufacturer: Vec<IngredientManufacturer>,
pub substance: IngredientSubstance,
}
impl super::super::codec::Json for Ingredient {
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("Ingredient")),
);
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.identifier {
object.insert(
std::string::String::from("identifier"),
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 !self.r#for.is_empty() {
let mut items = Vec::with_capacity(self.r#for.len());
for item in &self.r#for {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("for"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("role"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.role)?),
);
if !self.function.is_empty() {
let mut items = Vec::with_capacity(self.function.len());
for item in &self.function {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("function"),
super::super::codec::Value::Array(items),
);
}
if let Some(item) = &self.group {
object.insert(
std::string::String::from("group"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.allergenic_indicator {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("allergenicIndicator"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_allergenicIndicator"), e);
}
}
if let Some(item) = &self.comment {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("comment"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_comment"), e);
}
}
if !self.manufacturer.is_empty() {
let mut items = Vec::with_capacity(self.manufacturer.len());
for item in &self.manufacturer {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("manufacturer"),
super::super::codec::Value::Array(items),
);
}
object.insert(
std::string::String::from("substance"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.substance,
)?),
);
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_status: Option<&super::super::codec::Value> = None;
let mut raw_status_element: Option<&super::super::codec::Value> = None;
let mut raw_for: Option<&super::super::codec::Value> = None;
let mut raw_role: Option<&super::super::codec::Value> = None;
let mut raw_function: Option<&super::super::codec::Value> = None;
let mut raw_group: Option<&super::super::codec::Value> = None;
let mut raw_allergenic_indicator: Option<&super::super::codec::Value> = None;
let mut raw_allergenic_indicator_element: Option<&super::super::codec::Value> = None;
let mut raw_comment: Option<&super::super::codec::Value> = None;
let mut raw_comment_element: Option<&super::super::codec::Value> = None;
let mut raw_manufacturer: Option<&super::super::codec::Value> = None;
let mut raw_substance: Option<&super::super::codec::Value> = None;
for (key, value) in object {
match key.as_str() {
"resourceType" => {
if value.as_str() != Some("Ingredient") {
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);
}
"status" => {
raw_status = Some(value);
}
"_status" => {
raw_status_element = Some(value);
}
"for" => {
raw_for = Some(value);
}
"role" => {
raw_role = Some(value);
}
"function" => {
raw_function = Some(value);
}
"group" => {
raw_group = Some(value);
}
"allergenicIndicator" => {
raw_allergenic_indicator = Some(value);
}
"_allergenicIndicator" => {
raw_allergenic_indicator_element = Some(value);
}
"comment" => {
raw_comment = Some(value);
}
"_comment" => {
raw_comment_element = Some(value);
}
"manufacturer" => {
raw_manufacturer = Some(value);
}
"substance" => {
raw_substance = 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_identifier = raw_identifier
.map(|value| {
path.with("identifier", |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 mut field_for = Vec::new();
if let Some(raw) = raw_for {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_for.push(path.with_index("for", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
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_function = Vec::new();
if let Some(raw) = raw_function {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_function.push(path.with_index("function", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_group = raw_group
.map(|value| {
path.with("group", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_allergenic_indicator =
match (raw_allergenic_indicator, raw_allergenic_indicator_element) {
(None, None) => None,
(value, element) => Some(path.with("allergenicIndicator", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_comment = match (raw_comment, raw_comment_element) {
(None, None) => None,
(value, element) => Some(path.with("comment", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_manufacturer = Vec::new();
if let Some(raw) = raw_manufacturer {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_manufacturer.push(path.with_index("manufacturer", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_substance = path.with("substance", |path| {
let value = raw_substance
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
Ok(Self {
id: field_id,
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,
status: field_status,
r#for: field_for,
role: field_role,
function: field_function,
group: field_group,
allergenic_indicator: field_allergenic_indicator,
comment: field_comment,
manufacturer: field_manufacturer,
substance: field_substance,
})
}
}
impl serde::Serialize for Ingredient {
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.allergenic_indicator {
super::super::codec::element_entry(&mut map, "_allergenicIndicator", item)?;
}
if let Some(item) = &self.comment {
super::super::codec::element_entry(&mut map, "_comment", 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)?;
}
super::super::codec::element_entry(&mut map, "_status", &self.status)?;
if let Some(item) = &self.allergenic_indicator {
super::super::codec::value_entry(&mut map, "allergenicIndicator", item)?;
}
if let Some(item) = &self.comment {
super::super::codec::value_entry(&mut map, "comment", item)?;
}
if !self.contained.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
}
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if !self.r#for.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "for", &self.r#for)?;
}
if !self.function.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "function", &self.function)?;
}
if let Some(item) = &self.group {
serde::ser::SerializeMap::serialize_entry(&mut map, "group", item)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if let Some(item) = &self.identifier {
serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", item)?;
}
if let Some(item) = &self.implicit_rules {
super::super::codec::value_entry(&mut map, "implicitRules", item)?;
}
if let Some(item) = &self.language {
super::super::codec::value_entry(&mut map, "language", item)?;
}
if !self.manufacturer.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"manufacturer",
&self.manufacturer,
)?;
}
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,
)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "Ingredient")?;
serde::ser::SerializeMap::serialize_entry(&mut map, "role", &self.role)?;
super::super::codec::value_entry(&mut map, "status", &self.status)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "substance", &self.substance)?;
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 Ingredient {
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("Ingredient");
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 IngredientManufacturer {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub role: Option<super::primitives::Code>,
pub manufacturer: super::reference::Reference,
}
impl super::super::codec::Json for IngredientManufacturer {
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.role {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("role"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_role"), e);
}
}
object.insert(
std::string::String::from("manufacturer"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.manufacturer,
)?),
);
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_role: Option<&super::super::codec::Value> = None;
let mut raw_role_element: Option<&super::super::codec::Value> = None;
let mut raw_manufacturer: 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);
}
"role" => {
raw_role = Some(value);
}
"_role" => {
raw_role_element = Some(value);
}
"manufacturer" => {
raw_manufacturer = 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_role = match (raw_role, raw_role_element) {
(None, None) => None,
(value, element) => Some(path.with("role", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_manufacturer = path.with("manufacturer", |path| {
let value = raw_manufacturer
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
role: field_role,
manufacturer: field_manufacturer,
})
}
}
impl serde::Serialize for IngredientManufacturer {
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.role {
super::super::codec::element_entry(&mut map, "_role", 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)?;
}
serde::ser::SerializeMap::serialize_entry(&mut map, "manufacturer", &self.manufacturer)?;
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if let Some(item) = &self.role {
super::super::codec::value_entry(&mut map, "role", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for IngredientManufacturer {
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("IngredientManufacturer");
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 IngredientSubstance {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub code: super::codeable_reference::CodeableReference,
pub strength: Vec<IngredientSubstanceStrength>,
}
impl super::super::codec::Json for IngredientSubstance {
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("code"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.code)?),
);
if !self.strength.is_empty() {
let mut items = Vec::with_capacity(self.strength.len());
for item in &self.strength {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("strength"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_code: Option<&super::super::codec::Value> = None;
let mut raw_strength: 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);
}
"code" => {
raw_code = Some(value);
}
"strength" => {
raw_strength = 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_code = path.with("code", |path| {
let value = raw_code
.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_strength = Vec::new();
if let Some(raw) = raw_strength {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_strength.push(path.with_index("strength", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
code: field_code,
strength: field_strength,
})
}
}
impl serde::Serialize for IngredientSubstance {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serde::Serializer::serialize_map(serializer, None)?;
serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
if !self.extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
}
if let Some(v) = &self.id {
serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
if !self.strength.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "strength", &self.strength)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for IngredientSubstance {
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("IngredientSubstance");
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 IngredientSubstanceStrength {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub presentation: Option<IngredientSubstanceStrengthPresentation>,
pub text_presentation: Option<super::primitives::String>,
pub concentration: Option<IngredientSubstanceStrengthConcentration>,
pub text_concentration: Option<super::primitives::String>,
pub basis: Option<super::codeable_concept::CodeableConcept>,
pub measurement_point: Option<super::primitives::String>,
pub country: Vec<super::codeable_concept::CodeableConcept>,
pub reference_strength: Vec<IngredientSubstanceStrengthReferenceStrength>,
}
impl super::super::codec::Json for IngredientSubstanceStrength {
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.presentation {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("presentation{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_presentation{suffix}"), element);
}
}
if let Some(item) = &self.text_presentation {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("textPresentation"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_textPresentation"), e);
}
}
if let Some(item) = &self.concentration {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("concentration{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_concentration{suffix}"), element);
}
}
if let Some(item) = &self.text_concentration {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("textConcentration"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_textConcentration"), e);
}
}
if let Some(item) = &self.basis {
object.insert(
std::string::String::from("basis"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.measurement_point {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("measurementPoint"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_measurementPoint"), e);
}
}
if !self.country.is_empty() {
let mut items = Vec::with_capacity(self.country.len());
for item in &self.country {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("country"),
super::super::codec::Value::Array(items),
);
}
if !self.reference_strength.is_empty() {
let mut items = Vec::with_capacity(self.reference_strength.len());
for item in &self.reference_strength {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("referenceStrength"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_presentation = super::super::codec::ChoiceSlot::default();
let mut raw_text_presentation: Option<&super::super::codec::Value> = None;
let mut raw_text_presentation_element: Option<&super::super::codec::Value> = None;
let mut raw_concentration = super::super::codec::ChoiceSlot::default();
let mut raw_text_concentration: Option<&super::super::codec::Value> = None;
let mut raw_text_concentration_element: Option<&super::super::codec::Value> = None;
let mut raw_basis: Option<&super::super::codec::Value> = None;
let mut raw_measurement_point: Option<&super::super::codec::Value> = None;
let mut raw_measurement_point_element: Option<&super::super::codec::Value> = None;
let mut raw_country: Option<&super::super::codec::Value> = None;
let mut raw_reference_strength: 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);
}
"presentationRatio" => {
raw_presentation.value("Ratio", value, path)?;
}
"_presentationRatio" => {
raw_presentation.element("Ratio", value, path)?;
}
"presentationRatioRange" => {
raw_presentation.value("RatioRange", value, path)?;
}
"_presentationRatioRange" => {
raw_presentation.element("RatioRange", value, path)?;
}
"presentationCodeableConcept" => {
raw_presentation.value("CodeableConcept", value, path)?;
}
"_presentationCodeableConcept" => {
raw_presentation.element("CodeableConcept", value, path)?;
}
"presentationQuantity" => {
raw_presentation.value("Quantity", value, path)?;
}
"_presentationQuantity" => {
raw_presentation.element("Quantity", value, path)?;
}
"textPresentation" => {
raw_text_presentation = Some(value);
}
"_textPresentation" => {
raw_text_presentation_element = Some(value);
}
"concentrationRatio" => {
raw_concentration.value("Ratio", value, path)?;
}
"_concentrationRatio" => {
raw_concentration.element("Ratio", value, path)?;
}
"concentrationRatioRange" => {
raw_concentration.value("RatioRange", value, path)?;
}
"_concentrationRatioRange" => {
raw_concentration.element("RatioRange", value, path)?;
}
"concentrationCodeableConcept" => {
raw_concentration.value("CodeableConcept", value, path)?;
}
"_concentrationCodeableConcept" => {
raw_concentration.element("CodeableConcept", value, path)?;
}
"concentrationQuantity" => {
raw_concentration.value("Quantity", value, path)?;
}
"_concentrationQuantity" => {
raw_concentration.element("Quantity", value, path)?;
}
"textConcentration" => {
raw_text_concentration = Some(value);
}
"_textConcentration" => {
raw_text_concentration_element = Some(value);
}
"basis" => {
raw_basis = Some(value);
}
"measurementPoint" => {
raw_measurement_point = Some(value);
}
"_measurementPoint" => {
raw_measurement_point_element = Some(value);
}
"country" => {
raw_country = Some(value);
}
"referenceStrength" => {
raw_reference_strength = 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_presentation = match raw_presentation.suffix {
None => None,
Some(suffix) => Some(path.with("presentation", |path| {
IngredientSubstanceStrengthPresentation::from_json_parts(
suffix,
raw_presentation.value,
raw_presentation.element,
path,
)
})?),
};
let field_text_presentation = match (raw_text_presentation, raw_text_presentation_element) {
(None, None) => None,
(value, element) => Some(path.with("textPresentation", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_concentration = match raw_concentration.suffix {
None => None,
Some(suffix) => Some(path.with("concentration", |path| {
IngredientSubstanceStrengthConcentration::from_json_parts(
suffix,
raw_concentration.value,
raw_concentration.element,
path,
)
})?),
};
let field_text_concentration =
match (raw_text_concentration, raw_text_concentration_element) {
(None, None) => None,
(value, element) => Some(path.with("textConcentration", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_basis = raw_basis
.map(|value| {
path.with("basis", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_measurement_point = match (raw_measurement_point, raw_measurement_point_element) {
(None, None) => None,
(value, element) => Some(path.with("measurementPoint", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_country = Vec::new();
if let Some(raw) = raw_country {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_country.push(path.with_index("country", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_reference_strength = Vec::new();
if let Some(raw) = raw_reference_strength {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_reference_strength.push(path.with_index(
"referenceStrength",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
presentation: field_presentation,
text_presentation: field_text_presentation,
concentration: field_concentration,
text_concentration: field_text_concentration,
basis: field_basis,
measurement_point: field_measurement_point,
country: field_country,
reference_strength: field_reference_strength,
})
}
}
impl serde::Serialize for IngredientSubstanceStrength {
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.measurement_point {
super::super::codec::element_entry(&mut map, "_measurementPoint", item)?;
}
if let Some(item) = &self.text_concentration {
super::super::codec::element_entry(&mut map, "_textConcentration", item)?;
}
if let Some(item) = &self.text_presentation {
super::super::codec::element_entry(&mut map, "_textPresentation", item)?;
}
if let Some(item) = &self.basis {
serde::ser::SerializeMap::serialize_entry(&mut map, "basis", item)?;
}
match &self.concentration {
Some(IngredientSubstanceStrengthConcentration::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"concentrationCodeableConcept",
inner.as_ref(),
)?;
}
Some(IngredientSubstanceStrengthConcentration::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"concentrationQuantity",
inner.as_ref(),
)?;
}
Some(IngredientSubstanceStrengthConcentration::Ratio(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"concentrationRatio",
inner.as_ref(),
)?;
}
Some(IngredientSubstanceStrengthConcentration::RatioRange(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"concentrationRatioRange",
inner.as_ref(),
)?;
}
None => {}
}
if !self.country.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "country", &self.country)?;
}
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.measurement_point {
super::super::codec::value_entry(&mut map, "measurementPoint", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
match &self.presentation {
Some(IngredientSubstanceStrengthPresentation::CodeableConcept(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"presentationCodeableConcept",
inner.as_ref(),
)?;
}
Some(IngredientSubstanceStrengthPresentation::Quantity(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"presentationQuantity",
inner.as_ref(),
)?;
}
Some(IngredientSubstanceStrengthPresentation::Ratio(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"presentationRatio",
inner.as_ref(),
)?;
}
Some(IngredientSubstanceStrengthPresentation::RatioRange(inner)) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"presentationRatioRange",
inner.as_ref(),
)?;
}
None => {}
}
if !self.reference_strength.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"referenceStrength",
&self.reference_strength,
)?;
}
if let Some(item) = &self.text_concentration {
super::super::codec::value_entry(&mut map, "textConcentration", item)?;
}
if let Some(item) = &self.text_presentation {
super::super::codec::value_entry(&mut map, "textPresentation", item)?;
}
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for IngredientSubstanceStrength {
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("IngredientSubstanceStrength");
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 IngredientSubstanceStrengthConcentration {
Ratio(Box<super::ratio::Ratio>),
RatioRange(Box<super::ratio_range::RatioRange>),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Quantity(Box<super::quantity::Quantity>),
}
impl IngredientSubstanceStrengthConcentration {
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::RatioRange(inner) => Ok((
"RatioRange",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
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,
)),
}
}
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)))
}
"RatioRange" => {
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::RatioRange(Box::new(inner)))
}
"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)))
}
"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)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IngredientSubstanceStrengthPresentation {
Ratio(Box<super::ratio::Ratio>),
RatioRange(Box<super::ratio_range::RatioRange>),
CodeableConcept(Box<super::codeable_concept::CodeableConcept>),
Quantity(Box<super::quantity::Quantity>),
}
impl IngredientSubstanceStrengthPresentation {
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::RatioRange(inner) => Ok((
"RatioRange",
Some(super::super::codec::Value::Object(
super::super::codec::Json::to_json(inner.as_ref())?,
)),
None,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
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,
)),
}
}
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)))
}
"RatioRange" => {
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::RatioRange(Box::new(inner)))
}
"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)))
}
"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)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IngredientSubstanceStrengthReferenceStrength {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub substance: super::codeable_reference::CodeableReference,
pub strength: IngredientSubstanceStrengthReferenceStrengthStrength,
pub measurement_point: Option<super::primitives::String>,
pub country: Vec<super::codeable_concept::CodeableConcept>,
}
impl super::super::codec::Json for IngredientSubstanceStrengthReferenceStrength {
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("substance"),
super::super::codec::Value::Object(super::super::codec::Json::to_json(
&self.substance,
)?),
);
let (suffix, value, element) = self.strength.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("strength{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_strength{suffix}"), element);
}
if let Some(item) = &self.measurement_point {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("measurementPoint"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_measurementPoint"), e);
}
}
if !self.country.is_empty() {
let mut items = Vec::with_capacity(self.country.len());
for item in &self.country {
items.push(super::super::codec::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("country"),
super::super::codec::Value::Array(items),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&super::super::codec::Value> = None;
let mut raw_extension: Option<&super::super::codec::Value> = None;
let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
let mut raw_substance: Option<&super::super::codec::Value> = None;
let mut raw_strength = super::super::codec::ChoiceSlot::default();
let mut raw_measurement_point: Option<&super::super::codec::Value> = None;
let mut raw_measurement_point_element: Option<&super::super::codec::Value> = None;
let mut raw_country: 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);
}
"substance" => {
raw_substance = Some(value);
}
"strengthRatio" => {
raw_strength.value("Ratio", value, path)?;
}
"_strengthRatio" => {
raw_strength.element("Ratio", value, path)?;
}
"strengthRatioRange" => {
raw_strength.value("RatioRange", value, path)?;
}
"_strengthRatioRange" => {
raw_strength.element("RatioRange", value, path)?;
}
"strengthQuantity" => {
raw_strength.value("Quantity", value, path)?;
}
"_strengthQuantity" => {
raw_strength.element("Quantity", value, path)?;
}
"measurementPoint" => {
raw_measurement_point = Some(value);
}
"_measurementPoint" => {
raw_measurement_point_element = Some(value);
}
"country" => {
raw_country = 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_substance = path.with("substance", |path| {
let value = raw_substance
.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_strength = path.with("strength", |path| {
let suffix = raw_strength
.suffix
.ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
IngredientSubstanceStrengthReferenceStrengthStrength::from_json_parts(
suffix,
raw_strength.value,
raw_strength.element,
path,
)
})?;
let field_measurement_point = match (raw_measurement_point, raw_measurement_point_element) {
(None, None) => None,
(value, element) => Some(path.with("measurementPoint", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_country = Vec::new();
if let Some(raw) = raw_country {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_country.push(path.with_index("country", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
substance: field_substance,
strength: field_strength,
measurement_point: field_measurement_point,
country: field_country,
})
}
}
impl serde::Serialize for IngredientSubstanceStrengthReferenceStrength {
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.measurement_point {
super::super::codec::element_entry(&mut map, "_measurementPoint", item)?;
}
if !self.country.is_empty() {
serde::ser::SerializeMap::serialize_entry(&mut map, "country", &self.country)?;
}
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.measurement_point {
super::super::codec::value_entry(&mut map, "measurementPoint", item)?;
}
if !self.modifier_extension.is_empty() {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"modifierExtension",
&self.modifier_extension,
)?;
}
match &self.strength {
IngredientSubstanceStrengthReferenceStrengthStrength::Quantity(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"strengthQuantity",
inner.as_ref(),
)?;
}
IngredientSubstanceStrengthReferenceStrengthStrength::Ratio(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"strengthRatio",
inner.as_ref(),
)?;
}
IngredientSubstanceStrengthReferenceStrengthStrength::RatioRange(inner) => {
serde::ser::SerializeMap::serialize_entry(
&mut map,
"strengthRatioRange",
inner.as_ref(),
)?;
}
}
serde::ser::SerializeMap::serialize_entry(&mut map, "substance", &self.substance)?;
serde::ser::SerializeMap::end(map)
}
}
impl<'de> serde::Deserialize<'de> for IngredientSubstanceStrengthReferenceStrength {
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("IngredientSubstanceStrengthReferenceStrength");
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 IngredientSubstanceStrengthReferenceStrengthStrength {
Ratio(Box<super::ratio::Ratio>),
RatioRange(Box<super::ratio_range::RatioRange>),
Quantity(Box<super::quantity::Quantity>),
}
impl IngredientSubstanceStrengthReferenceStrengthStrength {
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::RatioRange(inner) => Ok((
"RatioRange",
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,
)),
}
}
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)))
}
"RatioRange" => {
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::RatioRange(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)))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}