update
This commit is contained in:
parent
ea544ad4af
commit
f4696e0b31
|
@ -118,13 +118,7 @@ impl Journal for JSONJournal {
|
||||||
Some(substance) => Some(Unit::Simple(substance.unit)),
|
Some(substance) => Some(Unit::Simple(substance.unit)),
|
||||||
None => None,
|
None => None,
|
||||||
},
|
},
|
||||||
Some(custom_unit_id) => match self.get_custom_unit(custom_unit_id) {
|
Some(custom_unit_id) => self.get_custom_unit(custom_unit_id).map(Unit::Custom),
|
||||||
Some(custom_unit) => Some(Unit::Custom {
|
|
||||||
id: custom_unit_id,
|
|
||||||
unit: Some(custom_unit),
|
|
||||||
}),
|
|
||||||
None => None,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,8 @@ impl Display for DoseWithUnitRefs<'_> {
|
||||||
|
|
||||||
f.write_str((" ".to_string() + unit).as_str())
|
f.write_str((" ".to_string() + unit).as_str())
|
||||||
}
|
}
|
||||||
Unit::Custom { id: _id, unit } => {
|
Unit::Custom(unit) => {
|
||||||
let unit = unit.clone().unwrap();
|
let unit = unit.clone();
|
||||||
let unit_unit = Unit::Simple(unit.unit.clone());
|
let unit_unit = Unit::Simple(unit.unit.clone());
|
||||||
|
|
||||||
let ingestion_dose = &unit.dose * dose;
|
let ingestion_dose = &unit.dose * dose;
|
||||||
|
@ -165,9 +165,7 @@ mod tests {
|
||||||
fn format_unknown_dose_with_custom_unit() {
|
fn format_unknown_dose_with_custom_unit() {
|
||||||
let result = super::format_dose(
|
let result = super::format_dose(
|
||||||
&Dose::new_unknown(),
|
&Dose::new_unknown(),
|
||||||
&Unit::Custom {
|
&Unit::Custom(CustomUnit {
|
||||||
id: 0,
|
|
||||||
unit: Some(CustomUnit {
|
|
||||||
name: "Beverage".to_string(),
|
name: "Beverage".to_string(),
|
||||||
substance_name: "Caffeine".to_string(),
|
substance_name: "Caffeine".to_string(),
|
||||||
unit: "sip".to_string(),
|
unit: "sip".to_string(),
|
||||||
|
@ -176,7 +174,6 @@ mod tests {
|
||||||
administration_route: AdministrationRoute::Oral,
|
administration_route: AdministrationRoute::Oral,
|
||||||
..CustomUnit::default()
|
..CustomUnit::default()
|
||||||
}),
|
}),
|
||||||
},
|
|
||||||
);
|
);
|
||||||
assert_eq!(result, "Unknown mg (~10 mg * Unknown sip)");
|
assert_eq!(result, "Unknown mg (~10 mg * Unknown sip)");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
use super::{dose::Dose, from_unix_millis, AdministrationRoute, Consumer, Unit};
|
use super::{dose::Dose, from_unix_millis, AdministrationRoute, Consumer};
|
||||||
|
|
||||||
#[derive(PartialEq, Default, Debug, Clone)]
|
#[derive(PartialEq, Default, Debug, Clone)]
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
@ -16,6 +16,22 @@ pub struct Ingestion {
|
||||||
pub stomach_fullness: Option<String>,
|
pub stomach_fullness: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum IngestionKind {
|
||||||
|
Substance(SubstanceIngestion),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Default, Debug, Clone)]
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct SubstanceIngestion {
|
||||||
|
pub substance_name: String,
|
||||||
|
pub dose: Dose,
|
||||||
|
pub custom_unit_id: Option<i32>,
|
||||||
|
pub roa: AdministrationRoute,
|
||||||
|
pub consumer: Consumer,
|
||||||
|
pub notes: String,
|
||||||
|
pub stomach_fullness: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
impl From<psychonaut_journal_types::Ingestion> for Ingestion {
|
impl From<psychonaut_journal_types::Ingestion> for Ingestion {
|
||||||
fn from(ingestion: psychonaut_journal_types::Ingestion) -> Self {
|
fn from(ingestion: psychonaut_journal_types::Ingestion) -> Self {
|
||||||
Ingestion {
|
Ingestion {
|
||||||
|
@ -55,7 +71,7 @@ impl From<psychonaut_journal_types::Ingestion> for Ingestion {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::types::{from_unix_millis, AdministrationRoute, Consumer, Dose, Unit};
|
use crate::types::{from_unix_millis, AdministrationRoute, Consumer, Dose};
|
||||||
|
|
||||||
use super::Ingestion;
|
use super::Ingestion;
|
||||||
use psychonaut_journal_types::Ingestion as PsychonautIngestion;
|
use psychonaut_journal_types::Ingestion as PsychonautIngestion;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use super::CustomUnit;
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
pub enum Unit {
|
pub enum Unit {
|
||||||
Simple(String),
|
Simple(String),
|
||||||
Custom { id: i32, unit: Option<CustomUnit> },
|
Custom(CustomUnit),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Unit {
|
impl Default for Unit {
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub fn print_ingestion_log(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let unit = journal.resolve_unit(&ingestion).unwrap();
|
let unit = journal.resolve_unit(ingestion).unwrap();
|
||||||
// println!("{:#?} {:#?}", &ingestion, &custom_unit);
|
// println!("{:#?} {:#?}", &ingestion, &custom_unit);
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
|
|
@ -9,8 +9,8 @@ pub fn format_ingestion_time(ingestion: &Ingestion) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_ingestion_roa(ingestion: &Ingestion, unit: &Unit) -> String {
|
pub fn format_ingestion_roa(ingestion: &Ingestion, unit: &Unit) -> String {
|
||||||
if let Unit::Custom { id: _id, unit } = unit {
|
if let Unit::Custom(unit) = unit {
|
||||||
format!("{:?} ({})", ingestion.roa, &unit.as_ref().unwrap().name)
|
format!("{:?} ({})", ingestion.roa, &unit.name)
|
||||||
} else {
|
} else {
|
||||||
format!("{:?}", ingestion.roa)
|
format!("{:?}", ingestion.roa)
|
||||||
}
|
}
|
||||||
|
@ -61,13 +61,10 @@ mod tests {
|
||||||
roa: AdministrationRoute::Oral,
|
roa: AdministrationRoute::Oral,
|
||||||
..Ingestion::default()
|
..Ingestion::default()
|
||||||
},
|
},
|
||||||
&Unit::Custom {
|
&Unit::Custom(CustomUnit {
|
||||||
id: 0,
|
|
||||||
unit: Some(CustomUnit {
|
|
||||||
name: "32mg/ml".to_string(),
|
name: "32mg/ml".to_string(),
|
||||||
..CustomUnit::default()
|
..CustomUnit::default()
|
||||||
}),
|
}),
|
||||||
},
|
|
||||||
);
|
);
|
||||||
assert_eq!(result, "Oral (32mg/ml)");
|
assert_eq!(result, "Oral (32mg/ml)");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue