From 212dbdb3134a570356bcc0c6fec882254c6c3440 Mon Sep 17 00:00:00 2001 From: xqtc <xqtc@tutanota.com> Date: Mon, 14 Oct 2024 22:31:12 +0200 Subject: [PATCH] Parser for drugs.json --- client/src/drugs_parser/mod.rs | 271 +++++++++++++ client/src/drugs_parser/parser.rs | 7 + client/src/main.rs | 3 + drug_schema.json | 624 ++++++++++++++++++++++++++++++ 4 files changed, 905 insertions(+) create mode 100644 client/src/drugs_parser/mod.rs create mode 100644 client/src/drugs_parser/parser.rs create mode 100644 drug_schema.json diff --git a/client/src/drugs_parser/mod.rs b/client/src/drugs_parser/mod.rs new file mode 100644 index 0000000..1d98096 --- /dev/null +++ b/client/src/drugs_parser/mod.rs @@ -0,0 +1,271 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +mod parser; + +pub fn parse() { + let file = include_str!("../../../drugs.json"); + let db: DrugDatabase = serde_json::from_str(file).unwrap(); + println!("{:?}", db); +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct DrugDatabase(HashMap<String, Drug>); + +#[derive(Serialize, Deserialize, Debug)] +pub struct Drug { + pub aliases: Option<Vec<String>>, + pub categories: Option<Vec<Category>>, + #[serde(rename = "formatted_aftereffects")] + pub formatted_aftereffects: Option<Duration>, + #[serde(rename = "formatted_dose")] + pub formatted_dose: Option<Dose>, + #[serde(rename = "formatted_duration")] + pub formatted_duration: Option<Duration>, + #[serde(rename = "formatted_effects")] + pub formatted_effects: Option<Vec<String>>, + #[serde(rename = "formatted_onset")] + pub formatted_onset: Option<Duration>, + pub links: Option<Links>, + pub name: String, + #[serde(rename = "pretty_name")] + pub pretty_name: String, + pub properties: Properties, + pub pweffects: Option<HashMap<String, String>>, + #[serde(rename = "dose_note")] + pub dose_note: Option<String>, + pub sources: Option<Sources>, + pub combos: Option<Combos>, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "kebab-case")] +pub enum Category { + Depressant, + HabitForming, + Tentative, + ResearchChemical, + Psychedelic, + Stimulant, + Dissociative, + Inactive, + Empathogen, + Common, + Benzodiazepine, + Opioid, + Supplement, + Nootropic, + Barbiturate, + Deliriant, + Ssri, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Dose { + pub oral: Option<Dosage>, + pub insufflated: Option<Dosage>, + pub rectal: Option<Dosage>, + pub vapourized: Option<Dosage>, + pub intravenous: Option<Dosage>, + pub smoked: Option<Dosage>, + pub sublingual: Option<Dosage>, + pub buccal: Option<Dosage>, + pub intramuscular: Option<Dosage>, + pub transdermal: Option<Dosage>, + pub hbwr: Option<Dosage>, + #[serde(rename = "Morning_Glory")] + pub morning_glory: Option<Dosage>, + pub dried: Option<Dosage>, + pub fresh: Option<Dosage>, + #[serde(rename = "Insufflated(Pure)")] + pub insufflated_pure: Option<Dosage>, + #[serde(rename = "Oral(Benzedrex)")] + pub oral_benzedrex: Option<Dosage>, + #[serde(rename = "Oral(Pure)")] + pub oral_pure: Option<Dosage>, + pub dry: Option<Dosage>, + pub wet: Option<Dosage>, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Dosage { + pub common: Option<String>, + pub light: Option<String>, + pub strong: Option<String>, + pub threshold: Option<String>, + pub heavy: Option<String>, + pub dangerous: Option<String>, + pub fatal: Option<String>, + pub note: Option<String>, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Duration { + #[serde(rename = "_unit")] + pub unit: Option<Unit>, + pub value: Option<String>, + pub insufflated: Option<String>, + pub oral: Option<String>, + pub rectal: Option<String>, + pub vapourized: Option<String>, + pub smoked: Option<String>, + #[serde(rename = "Oral_ER")] + pub oral_er: Option<String>, + #[serde(rename = "Oral_IR")] + pub oral_ir: Option<String>, + pub intramuscular: Option<String>, + pub intravenous: Option<String>, + pub metabolites: Option<String>, + pub parent: Option<String>, + #[serde(rename = "Oral_MAOI")] + pub oral_maoi: Option<String>, + pub buccal: Option<String>, + pub transdermal: Option<String>, + pub sublingual: Option<String>, + #[serde(rename = "Insufflated_IR")] + pub insufflated_ir: Option<String>, + #[serde(rename = "Insufflated_XR")] + pub insufflated_xr: Option<String>, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Links { + pub experiences: String, + pub pihkal: Option<String>, + pub tihkal: Option<String>, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Properties { + #[serde(rename = "after-effects")] + pub after_effects: Option<String>, + pub aliases: Option<Vec<String>>, + pub avoid: Option<String>, + pub categories: Option<Vec<Category>>, + pub dose: Option<String>, + pub duration: Option<String>, + #[serde(rename = "half-life")] + pub half_life: Option<String>, + pub onset: Option<String>, + pub summary: Option<String>, + #[serde(rename = "test-kits")] + pub test_kits: Option<String>, + pub experiences: Option<String>, + pub warning: Option<String>, + pub marquis: Option<String>, + pub effects: Option<String>, + pub risks: Option<String>, + pub comeup: Option<String>, + pub note: Option<String>, + pub detection: Option<String>, + pub wiki: Option<String>, + pub mdma: Option<String>, + pub tolerance: Option<String>, + pub bioavailability: Option<String>, + #[serde(rename = "dose_to_diazepam")] + pub dose_to_diazepam: Option<String>, + #[serde(rename = "adverse-effects")] + pub adverse_effects: Option<String>, + pub chemistry: Option<String>, + pub contraindications: Option<String>, + pub legal: Option<String>, + #[serde(rename = "overdose-symptoms")] + pub overdose_symptoms: Option<String>, + pub pharmacokinetics: Option<String>, + pub pharmacology: Option<String>, + pub obtain: Option<String>, + pub pharmacodynamics: Option<String>, + #[serde(rename = "side-effects")] + pub side_effects: Option<String>, + pub molecule: Option<String>, + pub vaporization: Option<String>, + pub calculator: Option<String>, + pub chart: Option<String>, + pub oral: Option<String>, + #[serde(rename = "general-advice")] + pub general_advice: Option<String>, + pub potentiators: Option<String>, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Combos { + #[serde(rename = "2c-t-x")] + pub c2_t_x: Option<Combo>, + #[serde(rename = "2c-x")] + pub c2_x: Option<Combo>, + #[serde(rename = "5-meo-xxt")] + pub c5_meo_xxt: Option<Combo>, + pub alcohol: Option<Combo>, + pub amphetamines: Option<Combo>, + pub amt: Option<Combo>, + pub benzodiazepines: Option<Combo>, + pub caffeine: Option<Combo>, + pub cannabis: Option<Combo>, + pub cocaine: Option<Combo>, + pub dextromethorphan: Option<Combo>, + pub diphenhydramine: Option<Combo>, + pub dmt: Option<Combo>, + pub dox: Option<Combo>, + #[serde(rename = "ghb/gbl")] + pub ghb_gbl: Option<Combo>, + pub lithium: Option<Combo>, + pub ketamine: Option<Combo>, + pub lsd: Option<Combo>, + pub maois: Option<Combo>, + pub mdma: Option<Combo>, + pub mephedrone: Option<Combo>, + pub mescaline: Option<Combo>, + pub mushrooms: Option<Combo>, + pub mxe: Option<Combo>, + pub nbomes: Option<Combo>, + pub nitrous: Option<Combo>, + pub opioids: Option<Combo>, + pub pcp: Option<Combo>, + pub ssris: Option<Combo>, + pub tramadol: Option<Combo>, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Combo { + pub sources: Option<Vec<SourceData>>, + pub note: Option<String>, + pub status: Status, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct SourceData { + pub author: Option<String>, + pub title: Option<String>, + pub url: Option<String>, +} + +#[derive(Serialize, Deserialize, Debug)] +pub enum Status { + #[serde(rename = "Low Risk & Decrease")] + LowRiskAndDecrease, + Dangerous, + #[serde(rename = "Low Risk & No Synergy")] + LowRiskAndNoSynergy, + Caution, + Unsafe, + #[serde(rename = "Low Risk & Synergy")] + LowRiskAndSynergy, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub enum Unit { + Hours, + Minutes, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Sources { + #[serde(rename = "_general")] + pub general: Option<Vec<String>>, + pub dose: Option<Vec<String>>, + pub duration: Option<Vec<String>>, + pub bioavailability: Option<Vec<String>>, + pub legality: Option<Vec<String>>, + pub onset: Option<Vec<String>>, +} +// ssh NZrVk5tjc7aJVHbDmzwVbcNtZ@lon1.tmate.io diff --git a/client/src/drugs_parser/parser.rs b/client/src/drugs_parser/parser.rs new file mode 100644 index 0000000..70db75f --- /dev/null +++ b/client/src/drugs_parser/parser.rs @@ -0,0 +1,7 @@ +use bincode; +use serde_json; + +pub fn parse() -> Result<(), std::io::Error> { + let drugs = std::fs::read("drugs.json").unwrap(); + Ok(()) +} diff --git a/client/src/main.rs b/client/src/main.rs index 4a4057f..f36aca7 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -15,6 +15,8 @@ lazy_static! { } mod util; +mod drugs_parser; + mod ingestions; mod ingestions_util; mod substance_util; @@ -72,6 +74,7 @@ fn print_completions<G: Generator>(gen: G, cmd: &mut Command) { } fn main() { + drugs_parser::parse(); ensure_files(); let cli = Cli::parse(); diff --git a/drug_schema.json b/drug_schema.json new file mode 100644 index 0000000..dec4e20 --- /dev/null +++ b/drug_schema.json @@ -0,0 +1,624 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Drug" + }, + "definitions": { + "Drug": { + "type": "object", + "additionalProperties": false, + "properties": { + "aliases": { + "type": "array", + "items": { + "type": "string" + } + }, + "categories": { + "type": "array", + "items": { + "$ref": "#/definitions/Category" + } + }, + "formatted_aftereffects": { + "$ref": "#/definitions/Duration" + }, + "formatted_dose": { + "$ref": "#/definitions/Dose" + }, + "formatted_duration": { + "$ref": "#/definitions/Duration" + }, + "formatted_effects": { + "type": "array", + "items": { + "type": "string" + } + }, + "formatted_onset": { + "$ref": "#/definitions/Duration" + }, + "links": { + "$ref": "#/definitions/Links" + }, + "name": { + "type": "string" + }, + "pretty_name": { + "type": "string" + }, + "properties": { + "$ref": "#/definitions/Properties" + }, + "pweffects": { + "type": "object", + "additionalProperties": { + "type": "string", + "format": "uri" + } + }, + "dose_note": { + "type": "string" + }, + "sources": { + "$ref": "#/definitions/Sources" + }, + "combos": { + "type": "object", + "properties": { + "2c-t-x": { + "$ref": "#/definitions/Combo" + }, + "2c-x": { + "$ref": "#/definitions/Combo" + }, + "5-meo-xxt": { + "$ref": "#/definitions/Combo" + }, + "alcohol": { + "$ref": "#/definitions/Combo" + }, + "amphetamines": { + "$ref": "#/definitions/Combo" + }, + "amt": { + "$ref": "#/definitions/Combo" + }, + "benzodiazepines": { + "$ref": "#/definitions/Combo" + }, + "caffeine": { + "$ref": "#/definitions/Combo" + }, + "cannabis": { + "$ref": "#/definitions/Combo" + }, + "cocaine": { + "$ref": "#/definitions/Combo" + }, + "dextromethorphan": { + "$ref": "#/definitions/Combo" + }, + "diphenhydramine": { + "$ref": "#/definitions/Combo" + }, + "dmt": { + "$ref": "#/definitions/Combo" + }, + "dox": { + "$ref": "#/definitions/Combo" + }, + "ghb/gbl": { + "$ref": "#/definitions/Combo" + }, + "lithium": { + "$ref": "#/definitions/Combo" + }, + "ketamine": { + "$ref": "#/definitions/Combo" + }, + "lsd": { + "$ref": "#/definitions/Combo" + }, + "maois": { + "$ref": "#/definitions/Combo" + }, + "mdma": { + "$ref": "#/definitions/Combo" + }, + "mephedrone": { + "$ref": "#/definitions/Combo" + }, + "mescaline": { + "$ref": "#/definitions/Combo" + }, + "mushrooms": { + "$ref": "#/definitions/Combo" + }, + "mxe": { + "$ref": "#/definitions/Combo" + }, + "nbomes": { + "$ref": "#/definitions/Combo" + }, + "nitrous": { + "$ref": "#/definitions/Combo" + }, + "opioids": { + "$ref": "#/definitions/Combo" + }, + "pcp": { + "$ref": "#/definitions/Combo" + }, + "ssris": { + "$ref": "#/definitions/Combo" + }, + "tramadol": { + "$ref": "#/definitions/Combo" + } + }, + "additionalProperties": false + } + }, + "required": [ + "name", + "pretty_name", + "properties" + ], + "title": "Drug" + }, + "Category": { + "type": "string", + "enum": [ + "depressant", + "habit-forming", + "tentative", + "research-chemical", + "psychedelic", + "stimulant", + "dissociative", + "inactive", + "empathogen", + "common", + "benzodiazepine", + "opioid", + "supplement", + "nootropic", + "barbiturate", + "deliriant", + "ssri" + ], + "title": "Category" + }, + "Dose": { + "type": "object", + "additionalProperties": false, + "properties": { + "Oral": { + "$ref": "#/definitions/Dosage" + }, + "Insufflated": { + "$ref": "#/definitions/Dosage" + }, + "Rectal": { + "$ref": "#/definitions/Dosage" + }, + "Vapourized": { + "$ref": "#/definitions/Dosage" + }, + "Intravenous": { + "$ref": "#/definitions/Dosage" + }, + "Smoked": { + "$ref": "#/definitions/Dosage" + }, + "Sublingual": { + "$ref": "#/definitions/Dosage" + }, + "Buccal": { + "$ref": "#/definitions/Dosage" + }, + "Intramuscular": { + "$ref": "#/definitions/Dosage" + }, + "Transdermal": { + "$ref": "#/definitions/Dosage" + }, + "HBWR": { + "$ref": "#/definitions/Dosage" + }, + "Morning_Glory": { + "$ref": "#/definitions/Dosage" + }, + "Dried": { + "$ref": "#/definitions/Dosage" + }, + "Fresh": { + "$ref": "#/definitions/Dosage" + }, + "Insufflated(Pure)": { + "$ref": "#/definitions/Dosage" + }, + "Oral(Benzedrex)": { + "$ref": "#/definitions/Dosage" + }, + "Oral(Pure)": { + "$ref": "#/definitions/Dosage" + }, + "Dry": { + "$ref": "#/definitions/Dosage" + }, + "Wet": { + "$ref": "#/definitions/Dosage" + } + }, + "required": [], + "title": "FormattedDose" + }, + "Dosage": { + "type": "object", + "additionalProperties": false, + "properties": { + "Common": { + "type": "string" + }, + "Light": { + "type": "string" + }, + "Strong": { + "type": "string" + }, + "Threshold": { + "type": "string" + }, + "Heavy": { + "type": "string" + }, + "Dangerous": { + "type": "string" + }, + "Fatal": { + "type": "string" + }, + "Note": { + "type": "string" + } + }, + "required": [], + "title": "Buccal" + }, + "Duration": { + "type": "object", + "additionalProperties": false, + "properties": { + "_unit": { + "$ref": "#/definitions/Unit" + }, + "value": { + "type": "string" + }, + "Insufflated": { + "type": "string" + }, + "Oral": { + "type": "string" + }, + "Rectal": { + "type": "string" + }, + "Vapourized": { + "type": "string" + }, + "Smoked": { + "type": "string" + }, + "Oral_ER": { + "type": "string" + }, + "Oral_IR": { + "type": "string" + }, + "Intramuscular": { + "type": "string" + }, + "Intravenous": { + "type": "string" + }, + "Metabolites": { + "type": "string" + }, + "Parent": { + "type": "string" + }, + "Oral_MAOI": { + "type": "string" + }, + "Buccal": { + "type": "string" + }, + "Transdermal": { + "type": "string" + }, + "Sublingual": { + "type": "string" + }, + "Insufflated_IR": { + "type": "string" + }, + "Insufflated_XR": { + "type": "string" + } + }, + "required": [], + "title": "Formatted" + }, + "Links": { + "type": "object", + "additionalProperties": false, + "properties": { + "experiences": { + "type": "string", + "format": "uri" + }, + "pihkal": { + "type": "string", + "format": "uri" + }, + "tihkal": { + "type": "string", + "format": "uri" + } + }, + "required": [ + "experiences" + ], + "title": "Links" + }, + "Properties": { + "type": "object", + "additionalProperties": false, + "properties": { + "after-effects": { + "type": "string" + }, + "aliases": { + "type": "array", + "items": { + "type": "string" + } + }, + "avoid": { + "type": "string" + }, + "categories": { + "type": "array", + "items": { + "$ref": "#/definitions/Category" + } + }, + "dose": { + "type": "string" + }, + "duration": { + "type": "string" + }, + "half-life": { + "type": "string" + }, + "onset": { + "type": "string" + }, + "summary": { + "type": "string" + }, + "test-kits": { + "type": "string" + }, + "experiences": { + "type": "string", + "format": "uri" + }, + "warning": { + "type": "string" + }, + "marquis": { + "type": "string" + }, + "effects": { + "type": "string" + }, + "risks": { + "type": "string" + }, + "comeup": { + "type": "string" + }, + "note": { + "type": "string" + }, + "detection": { + "type": "string" + }, + "wiki": { + "type": "string", + "format": "uri" + }, + "mdma": { + "type": "string" + }, + "tolerance": { + "type": "string" + }, + "bioavailability": { + "type": "string" + }, + "dose_to_diazepam": { + "type": "string" + }, + "adverse-effects": { + "type": "string" + }, + "chemistry": { + "type": "string" + }, + "contraindications": { + "type": "string" + }, + "legal": { + "type": "string" + }, + "overdose-symptoms": { + "type": "string" + }, + "pharmacokinetics": { + "type": "string" + }, + "pharmacology": { + "type": "string" + }, + "obtain": { + "type": "string" + }, + "pharmacodynamics": { + "type": "string" + }, + "side-effects": { + "type": "string" + }, + "molecule": { + "type": "string", + "format": "uri" + }, + "vaporization": { + "type": "string" + }, + "calculator": { + "type": "string", + "format": "uri" + }, + "chart": { + "type": "string", + "format": "uri" + }, + "Oral": { + "type": "string" + }, + "general-advice": { + "type": "string" + }, + "potentiators": { + "type": "string" + } + }, + "required": [], + "title": "Properties" + }, + "Combo": { + "type": "object", + "additionalProperties": false, + "properties": { + "sources": { + "type": "array", + "items": { + "$ref": "#/definitions/SourceData" + } + }, + "note": { + "type": "string" + }, + "status": { + "$ref": "#/definitions/Status" + } + }, + "required": [ + "status" + ], + "title": "Combo" + }, + "SourceData": { + "type": "object", + "additionalProperties": false, + "properties": { + "author": { + "type": "string" + }, + "title": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "title": "SourceData" + }, + "Status": { + "type": "string", + "enum": [ + "Low Risk & Decrease", + "Dangerous", + "Low Risk & No Synergy", + "Caution", + "Unsafe", + "Low Risk & Synergy" + ], + "title": "Status" + }, + "Unit": { + "type": "string", + "enum": [ + "hours", + "minutes" + ], + "title": "Unit" + }, + "Sources": { + "type": "object", + "additionalProperties": false, + "properties": { + "_general": { + "type": "array", + "items": { + "type": "string" + } + }, + "dose": { + "type": "array", + "items": { + "type": "string", + "format": "uri" + } + }, + "duration": { + "type": "array", + "items": { + "type": "string", + "format": "uri" + } + }, + "bioavailability": { + "type": "array", + "items": { + "type": "string", + "format": "uri" + } + }, + "legality": { + "type": "array", + "items": { + "type": "string", + "format": "uri" + } + }, + "onset": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [], + "title": "Sources" + } + } +} \ No newline at end of file