From 31d8c9b6b6ea908e45a201efacab87838ef95bef Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 28 Feb 2024 16:52:45 +0100 Subject: [PATCH] feat: display pat ID and diagnosis date in compare subcommand --- src/cli.rs | 2 ++ src/common.rs | 2 ++ src/main.rs | 85 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 383de4a..cfe5655 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -91,6 +91,8 @@ pub enum SubCommand { }, #[command(about = "Abgleich zwischen CSV-Datei für OPAL und Onkostar-Datenbank")] Compare { + #[arg(long, help = "Klartext-Patienten-ID anzeigen")] + pat_id: bool, #[arg(short = 'D', long, help = "Datenbank-Name", default_value = "onkostar")] database: String, #[arg( diff --git a/src/common.rs b/src/common.rs index 80b91ab..84f7ed3 100644 --- a/src/common.rs +++ b/src/common.rs @@ -32,7 +32,9 @@ pub struct Record { } pub struct DiffRecord { + pub pat_id: Option, pub condition_id: String, + pub diagnosis_date: String, pub csv_icd10_code: String, pub db_icd10_code: String, } diff --git a/src/main.rs b/src/main.rs index 636a070..a42e546 100644 --- a/src/main.rs +++ b/src/main.rs @@ -156,6 +156,7 @@ fn main() -> Result<(), Box> { ); } SubCommand::Compare { + pat_id, database, host, password, @@ -189,7 +190,7 @@ fn main() -> Result<(), Box> { let db = DatabaseSource::new(&database, &host, &password, port, &user); let db_items = db - .export(&year, false) + .export(&year, pat_id) .map_err(|_e| "Fehler bei Zugriff auf die Datenbank")?; let _ = term.clear_last_lines(1); @@ -218,7 +219,10 @@ fn main() -> Result<(), Box> { .to_string(), ); - let _ = term.write_line(&format!("{:<64} {:<5}", "Condition-ID", "ICD10")); + let _ = term.write_line(&format!( + "{:<64} {:<10} {:<5} {:<5} {}", + "Condition-ID", "Datum", "ICD10", "", "PAT-ID" + )); not_in_csv.sort_by_key(|item| item.condition_id.to_string()); @@ -227,15 +231,28 @@ fn main() -> Result<(), Box> { .for_each(|item| match Check::is_relevant(&item.icd_10_code) { true => { let _ = term.write_line(&format!( - "{} {:<5}", + "{:<64} {:<10} {:<5} {:<5} {}", item.condition_id, - style(&item.icd_10_code).bold().red() + item.diagnosis_date, + style(&item.icd_10_code).bold().red(), + "", + match &item.pat_id { + Some(ref pat_id) => pat_id.to_string(), + _ => "".to_string(), + } )); } false => { let _ = term.write_line(&format!( - "{} {:<5}", - item.condition_id, item.icd_10_code + "{:<64} {:<10} {:<5} {:<5} {}", + item.condition_id, + item.diagnosis_date, + item.icd_10_code, + "", + match &item.pat_id { + Some(ref pat_id) => pat_id.to_string(), + _ => "".to_string(), + } )); } }); @@ -261,7 +278,10 @@ fn main() -> Result<(), Box> { .to_string(), ); - let _ = term.write_line(&format!("{:<64} {:<5}", "Condition-ID", "ICD10")); + let _ = term.write_line(&format!( + "{:<64} {:<10} {:<5}", + "Condition-ID", "Datum", "ICD10" + )); not_in_db.sort_by_key(|item| item.condition_id.to_string()); @@ -270,42 +290,44 @@ fn main() -> Result<(), Box> { .for_each(|item| match Check::is_relevant(&item.icd_10_code) { true => { let _ = term.write_line(&format!( - "{} {:<5}", + "{:<64} {:<10} {:<5}", item.condition_id, + item.diagnosis_date, style(&item.icd_10_code).bold().red() )); } false => { let _ = term.write_line(&format!( - "{} {:<5}", - item.condition_id, item.icd_10_code + "{:<64} {:<10} {:<5}", + item.condition_id, item.diagnosis_date, item.icd_10_code )); } }); - let mut icd10diff = csv_items + let mut icd10diff = db_items .iter() - .filter(|csv_item| { - db_items + .filter(|db_item| { + csv_items .iter() .map(|db_item| &db_item.condition_id) - .contains(&csv_item.condition_id) + .contains(&db_item.condition_id) }) - .filter(|csv_item| { - !db_items + .filter(|db_item| { + !csv_items .iter() - .map(|db_item| format!("{}-{}", db_item.condition_id, db_item.icd_10_code)) - .contains(&format!( - "{}-{}", - csv_item.condition_id, csv_item.icd_10_code - )) + .map(|csv_item| { + format!("{}-{}", csv_item.condition_id, csv_item.icd_10_code) + }) + .contains(&format!("{}-{}", db_item.condition_id, db_item.icd_10_code)) }) - .map(|csv_item| DiffRecord { - condition_id: csv_item.condition_id.to_string(), - csv_icd10_code: csv_item.icd_10_code.to_string(), - db_icd10_code: db_items + .map(|db_item| DiffRecord { + pat_id: db_item.pat_id.as_ref().map(|pat_id| pat_id.to_string()), + condition_id: db_item.condition_id.to_string(), + diagnosis_date: db_item.diagnosis_date.to_string(), + csv_icd10_code: db_item.icd_10_code.to_string(), + db_icd10_code: csv_items .iter() - .filter(|db_item| db_item.condition_id == csv_item.condition_id) + .filter(|csv_item| csv_item.condition_id == db_item.condition_id) .collect_vec() .first() .unwrap() @@ -326,14 +348,15 @@ fn main() -> Result<(), Box> { icd10diff.sort_by_key(|item| item.condition_id.to_string()); let _ = term.write_line(&format!( - "{:<64} {:<5} {:<5}", - "Condition-ID", "CSV", "DB" + "{:<64} {:<10} {:<5} {:<5} {}", + "Condition-ID", "Datum", "CSV", "DB", "PAT-ID" )); icd10diff.iter().for_each(|item| { let _ = term.write_line(&format!( - "{} {} {}", + "{:<64} {:<10} {:<5} {:<5} {}", item.condition_id, + item.diagnosis_date, match Check::is_relevant(&item.csv_icd10_code) { true => style(format!("{:<5}", item.csv_icd10_code)).bold().red(), _ => style(format!("{:<5}", item.csv_icd10_code)), @@ -341,6 +364,10 @@ fn main() -> Result<(), Box> { match Check::is_relevant(&item.db_icd10_code) { true => style(format!("{:<5}", item.db_icd10_code)).bold().red(), _ => style(format!("{:<5}", item.db_icd10_code)), + }, + match &item.pat_id { + Some(ref pat_id) => pat_id.to_string(), + _ => "".to_string(), } )); });