Skip to content

Commit

Permalink
feat: display pat ID and diagnosis date in compare subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
pcvolkmer committed Feb 28, 2024
1 parent 540a7c7 commit 31d8c9b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub struct Record {
}

pub struct DiffRecord {
pub pat_id: Option<String>,
pub condition_id: String,
pub diagnosis_date: String,
pub csv_icd10_code: String,
pub db_icd10_code: String,
}
Expand Down
85 changes: 56 additions & 29 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ fn main() -> Result<(), Box<dyn Error>> {
);
}
SubCommand::Compare {
pat_id,
database,
host,
password,
Expand Down Expand Up @@ -189,7 +190,7 @@ fn main() -> Result<(), Box<dyn Error>> {

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);
Expand Down Expand Up @@ -218,7 +219,10 @@ fn main() -> Result<(), Box<dyn Error>> {
.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());

Expand All @@ -227,15 +231,28 @@ fn main() -> Result<(), Box<dyn Error>> {
.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(),
}
));
}
});
Expand All @@ -261,7 +278,10 @@ fn main() -> Result<(), Box<dyn Error>> {
.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());

Expand All @@ -270,42 +290,44 @@ fn main() -> Result<(), Box<dyn Error>> {
.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()
Expand All @@ -326,21 +348,26 @@ fn main() -> Result<(), Box<dyn Error>> {
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)),
},
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(),
}
));
});
Expand Down

0 comments on commit 31d8c9b

Please sign in to comment.