diff --git a/Cargo.toml b/Cargo.toml index a490fc7..8fd9e2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] plotlars = "0.5.0" evcxr = "0.17.0" -hashbrown = "0.15.0" +hashbrown = { version = "0.14", features = ["rayon", "ahash", "serde", "raw"] } linfa = "0.7.0" polars = { version = "0.42.0", features = [ "lazy", diff --git a/src/experiments/comorbidity.rs b/src/experiments/comorbidity.rs index e767316..6e502b4 100644 --- a/src/experiments/comorbidity.rs +++ b/src/experiments/comorbidity.rs @@ -3,6 +3,8 @@ use frames::hyperaktiv::*; use crate::frames; pub fn comorbidity_of_anxiety_or_mood_disorder() { + // TODO: This belongs in frames - the graphical element can be exposed here, however. + let dataset = load_patient_info(false) .filter( col("BIPOLAR") diff --git a/src/frames/mod.rs b/src/frames/mod.rs index 4ffa340..85deea8 100644 --- a/src/frames/mod.rs +++ b/src/frames/mod.rs @@ -1,4 +1,6 @@ -pub mod hyperaktiv; + +/// TODO: This module should stay internal +pub mod hyperaktiv; pub mod patient_info; pub mod subtypes; diff --git a/src/frames/patient_info.rs b/src/frames/patient_info.rs index d321f6c..726fde6 100644 --- a/src/frames/patient_info.rs +++ b/src/frames/patient_info.rs @@ -2,41 +2,7 @@ use polars::prelude::*; use crate::traits::patient_info_ext::{GenderAndADHDTypeFilter, SelectPatientInfoColumns}; -/// Returns all patients who have ADHD-PH -pub fn patient_info_has_adhd_hyperactive() -> DataFrame { - load_patient_info(false) - .filter( - col("ADHD").eq(1).and(col("ADD").eq(0)) - ) - .apply_gender_age_adhd_type_translation() - .select_patient_info_columns() - .collect() - .unwrap() -} - -/// Returns all patients who have ADHD-PI -pub fn patient_info_has_adhd_innattentive() -> DataFrame { - load_patient_info(false) - .filter( - col("ADHD").eq(0).and(col("ADD").eq(1)) - ) - .apply_gender_age_adhd_type_translation() - .select_patient_info_columns() - .collect() - .unwrap() -} -/// Returns all patients who have ADHD-C -pub fn patient_info_has_adhd_combined() -> DataFrame { - load_patient_info(false) - .filter( - col("ADHD").eq(1).and(col("ADD").eq(1)) - ) - .apply_gender_age_adhd_type_translation() - .select_patient_info_columns() - .collect() - .unwrap() -} /// Returns all patients who have Bipolar Disorder pub fn patient_info_has_bipolar_disorder() -> DataFrame { @@ -137,4 +103,10 @@ pub fn patient_info_patient_does_not_take_medication() -> DataFrame { .select_patient_info_columns() .collect() .unwrap() +} + +#[cfg(test)] +mod test { + + } \ No newline at end of file diff --git a/src/frames/subtypes.rs b/src/frames/subtypes.rs index 8e35db5..b273f73 100644 --- a/src/frames/subtypes.rs +++ b/src/frames/subtypes.rs @@ -1,7 +1,7 @@ use polars::frame::DataFrame; use polars::prelude::{col}; use crate::frames::hyperaktiv::load_patient_info; -use crate::traits::patient_info_ext::GenderAndADHDTypeFilter; +use crate::traits::patient_info_ext::{GenderAndADHDTypeFilter, SelectPatientInfoColumns}; /// Returns ADHD subtypes, gender, and age ranges of patients. @@ -45,6 +45,44 @@ pub fn adhd_subtypes_male() -> DataFrame { .unwrap() } +/// Returns all patients who have ADHD-PH +pub fn patient_info_has_adhd_hyperactive() -> DataFrame { + load_patient_info(false) + .filter( + col("ADHD").eq(1).and(col("ADD").eq(0)) + ) + .apply_gender_age_adhd_type_translation() + .select_patient_info_columns() + .collect() + .unwrap() +} + +/// Returns all patients who have ADHD-PI +/// Note - there are not actually any patients who are explicitly PI types reported in the dataset. +#[deprecated] +pub fn patient_info_has_adhd_inattentive() -> DataFrame { + load_patient_info(false) + .filter( + col("ADD").eq(1).and(col("ADHD").eq(0)) + ) + .apply_gender_age_adhd_type_translation() + .select_patient_info_columns() + .collect() + .unwrap() +} + +/// Returns all patients who have ADHD-C +pub fn patient_info_has_adhd_combined() -> DataFrame { + load_patient_info(false) + .filter( + col("ADHD").eq(1).and(col("ADD").eq(1)) + ) + .apply_gender_age_adhd_type_translation() + .select_patient_info_columns() + .collect() + .unwrap() +} + #[cfg(test)] mod test { @@ -52,7 +90,7 @@ mod test { use polars::export::arrow::legacy::utils::CustomIterTools; use polars::prelude::NamedFrom; use polars::series::Series; - + use crate::frames::subtypes::{adhd_subtypes_female, adhd_subtypes_male, adhd_subtypes_with_gender_and_age}; #[test] fn loads_adhd_subtypes_with_gender_and_age() { @@ -75,4 +113,31 @@ mod test { assert_eq!(df.column("Gender").unwrap().tail(Some(1)), Series::new("Gender", &["Male"])); assert!(df.column("Gender").unwrap().iter().all_equal()); } + + #[test] + fn loads_all_patients_adhd_primary_hyperactive() { + let df = patient_info_has_adhd_hyperactive(); + assert!(!df.is_empty()); + assert_eq!(df.column("ADHD Type").unwrap().tail(Some(1)), Series::new("ADHD Type", &["ADHD-PH"])); + assert!(df.column("ADHD Type").unwrap().iter().all_equal()); + } + + #[deprecated] + /// This test always fails because there are no patients matching this criteria. + /// Leaving this here more for informational purposes than anything. + fn loads_all_patients_adhd_primary_inattentive() { + let df = patient_info_has_adhd_inattentive(); + assert!(!df.is_empty()); + assert_eq!(df.column("ADHD Type").unwrap().tail(Some(1)), Series::new("ADHD Type", &["ADHD-PI"])); + assert!(df.column("ADHD Type").unwrap().iter().all_equal()); + } + + #[test] + fn loads_all_patients_adhd_combined_type() { + let df = patient_info_has_adhd_combined(); + assert!(!df.is_empty()); + assert_eq!(df.column("ADHD Type").unwrap().tail(Some(1)), Series::new("ADHD Type", &["ADHD-C"])); + assert!(df.column("ADHD Type").unwrap().iter().all_equal()); + } + } \ No newline at end of file