mirror of
https://github.com/pcvolkmer/bzkf-rwdp-check.git
synced 2025-04-19 19:16:51 +00:00
feat: add sub command to request values from database
This commit is contained in:
parent
0037e6c8bb
commit
0f7dff2d16
@ -9,6 +9,10 @@ edition = "2021"
|
|||||||
clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false }
|
clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false }
|
||||||
console = "0.15"
|
console = "0.15"
|
||||||
csv = "1.3"
|
csv = "1.3"
|
||||||
|
dialoguer = "0.11"
|
||||||
itertools = "0.12"
|
itertools = "0.12"
|
||||||
|
mysql = "24.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
urlencoding = "2.1"
|
||||||
|
|
||||||
|
|
||||||
|
23
README.md
23
README.md
@ -27,3 +27,26 @@ bzkf-rwdp-check opal-file --file <Opal-CSV-Datei>.csv
|
|||||||
```
|
```
|
||||||
|
|
||||||
Die Anwendung gibt nun eine Liste der ICD-10-Gruppen mit Anzahl der _Conditions_ aus.
|
Die Anwendung gibt nun eine Liste der ICD-10-Gruppen mit Anzahl der _Conditions_ aus.
|
||||||
|
|
||||||
|
## Prüfung der Daten in der Onkostar-Datenbank
|
||||||
|
|
||||||
|
Die Anzahl der _Conditions_, gruppiert nach ICD-10-Gruppe, kann auch mit dem Befehl `database` aus der Onkostar-Datenbank
|
||||||
|
abgerufen werden.
|
||||||
|
|
||||||
|
```
|
||||||
|
bzkf-rwdp-check database --user me --year 2024
|
||||||
|
```
|
||||||
|
|
||||||
|
Die Anwendung gibt auch hier eine Liste der ICD-10-Gruppen mit Anzahl der _Conditions_ aus.
|
||||||
|
|
||||||
|
Dieser Befehl hat noch weitere Parameter:
|
||||||
|
|
||||||
|
```
|
||||||
|
Options:
|
||||||
|
-D, --database <DATABASE> Datenbank-Name [default: onkostar]
|
||||||
|
-h, --host <HOST> Datenbank-Host [default: localhost]
|
||||||
|
-P, --port <PORT> Datenbank-Host [default: 3306]
|
||||||
|
-p, --password <PASSWORD> Passwort. Wenn nicht angegeben, wird danach gefragt
|
||||||
|
-u, --user <USER> Benutzername
|
||||||
|
-y, --year <YEAR> Jahr der Diagnose
|
||||||
|
```
|
41
src/cli.rs
41
src/cli.rs
@ -22,7 +22,7 @@ use clap::{Parser, Subcommand};
|
|||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(author, version, about)]
|
#[command(author, version, about)]
|
||||||
#[command(arg_required_else_help(true))]
|
#[command(arg_required_else_help(true), disable_help_flag(true))]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub cmd: SubCommand,
|
pub cmd: SubCommand,
|
||||||
@ -30,20 +30,33 @@ pub struct Cli {
|
|||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum SubCommand {
|
pub enum SubCommand {
|
||||||
#[command(
|
#[command(about = "Ermittelt die Prüfwerte aus einem CSV-File für OPAL")]
|
||||||
about = "Ermittelt die Prüfwerte aus einem CSV-File für OPAL"
|
|
||||||
)]
|
|
||||||
OpalFile {
|
OpalFile {
|
||||||
#[arg(short, long, help = "CSV-File für Opal")] file: String
|
#[arg(short, long, help = "CSV-File für Opal")]
|
||||||
|
file: String,
|
||||||
},
|
},
|
||||||
#[command(
|
#[command(about = "Ermittelt die Prüfwerte aus einem CSV-File für OPAL")]
|
||||||
about = "Ermittelt die Prüfwerte aus einem CSV-File für OPAL"
|
|
||||||
)]
|
|
||||||
Database {
|
Database {
|
||||||
#[arg(long, help = "Datenbank-Host", default_value="localhost")] host: String,
|
#[arg(short = 'D', long, help = "Datenbank-Name", default_value = "onkostar")]
|
||||||
#[arg(long, help = "Datenbank-Host", default_value="3306")] port: u16,
|
database: String,
|
||||||
#[arg(long, help = "Benutzername")] user: String,
|
#[arg(
|
||||||
}
|
short = 'h',
|
||||||
|
long,
|
||||||
|
help = "Datenbank-Host",
|
||||||
|
default_value = "localhost"
|
||||||
|
)]
|
||||||
|
host: String,
|
||||||
|
#[arg(short = 'P', long, help = "Datenbank-Host", default_value = "3306")]
|
||||||
|
port: u16,
|
||||||
|
#[arg(
|
||||||
|
short = 'p',
|
||||||
|
long,
|
||||||
|
help = "Passwort. Wenn nicht angegeben, wird danach gefragt"
|
||||||
|
)]
|
||||||
|
password: Option<String>,
|
||||||
|
#[arg(short = 'u', long, help = "Benutzername")]
|
||||||
|
user: String,
|
||||||
|
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
||||||
|
year: String,
|
||||||
|
},
|
||||||
}
|
}
|
61
src/database.rs
Normal file
61
src/database.rs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of bzkf-rwdp-check
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Comprehensive Cancer Center Mainfranken and contributors.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use mysql::prelude::Queryable;
|
||||||
|
use mysql::{params, Pool};
|
||||||
|
|
||||||
|
use crate::common::Icd10GroupSize;
|
||||||
|
use crate::resources::SQL_QUERY;
|
||||||
|
|
||||||
|
pub struct DatabaseSource(String);
|
||||||
|
|
||||||
|
impl DatabaseSource {
|
||||||
|
pub fn new(database: &str, host: &str, password: &str, port: u16, user: &str) -> Self {
|
||||||
|
let password = urlencoding::encode(password);
|
||||||
|
let url = format!("mysql://{user}:{password}@{host}:{port}/{database}");
|
||||||
|
DatabaseSource(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check(&self, year: &str) -> Result<Vec<Icd10GroupSize>, ()> {
|
||||||
|
match Pool::new(self.0.as_str()) {
|
||||||
|
Ok(pool) => {
|
||||||
|
if let Ok(mut connection) = pool.get_conn() {
|
||||||
|
return match connection.exec_map(
|
||||||
|
SQL_QUERY,
|
||||||
|
params! {"year" => year},
|
||||||
|
|(icd10_group, count)| Icd10GroupSize {
|
||||||
|
name: icd10_group,
|
||||||
|
size: count,
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Ok(result) => Ok(result),
|
||||||
|
Err(_) => Err(()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("{}", e);
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
68
src/main.rs
68
src/main.rs
@ -25,10 +25,26 @@ use clap::Parser;
|
|||||||
use console::{style, Term};
|
use console::{style, Term};
|
||||||
|
|
||||||
use crate::cli::{Cli, SubCommand};
|
use crate::cli::{Cli, SubCommand};
|
||||||
|
use crate::common::Icd10GroupSize;
|
||||||
|
use crate::database::DatabaseSource;
|
||||||
|
|
||||||
mod opal;
|
|
||||||
mod common;
|
|
||||||
mod cli;
|
mod cli;
|
||||||
|
mod common;
|
||||||
|
mod database;
|
||||||
|
mod opal;
|
||||||
|
mod resources;
|
||||||
|
|
||||||
|
fn print_items(items: &[Icd10GroupSize]) {
|
||||||
|
let term = Term::stdout();
|
||||||
|
let _ = term.write_line(
|
||||||
|
&style("Anzahl der Conditions nach ICD-10-Gruppe")
|
||||||
|
.yellow()
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
items.iter().for_each(|item| {
|
||||||
|
let _ = term.write_line(&format!("{:<20}={:>6}", item.name, item.size));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let term = Term::stdout();
|
let term = Term::stdout();
|
||||||
@ -38,13 +54,47 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let items = opal::OpalCsvFile::check(Path::new(&file))
|
let items = opal::OpalCsvFile::check(Path::new(&file))
|
||||||
.map_err(|_e| "Kann Datei nicht lesen")?;
|
.map_err(|_e| "Kann Datei nicht lesen")?;
|
||||||
|
|
||||||
let _ = term.write_line(&style("Anzahl der Conditions nach ICD-Gruppe").yellow().to_string());
|
print_items(&items);
|
||||||
items.iter().for_each(|item| {
|
}
|
||||||
let _ = term.write_line(&format!("{:<20}={:>6}", item.name, item.size));
|
SubCommand::Database {
|
||||||
});
|
database,
|
||||||
},
|
host,
|
||||||
SubCommand::Database { .. } => {
|
password,
|
||||||
todo!("Not implemented yet")
|
port,
|
||||||
|
user,
|
||||||
|
year,
|
||||||
|
} => {
|
||||||
|
let password = if let Some(password) = password {
|
||||||
|
password
|
||||||
|
} else {
|
||||||
|
let password = dialoguer::Password::new()
|
||||||
|
.with_prompt("Password")
|
||||||
|
.interact()
|
||||||
|
.unwrap_or_default();
|
||||||
|
let _ = term.clear_last_lines(1);
|
||||||
|
password
|
||||||
|
};
|
||||||
|
|
||||||
|
let year = if year.len() == 4 {
|
||||||
|
year
|
||||||
|
} else {
|
||||||
|
format!("2{:0>3}", year)
|
||||||
|
};
|
||||||
|
|
||||||
|
let _ = term.write_line(
|
||||||
|
&style(format!("Warte auf Daten für das Diagnosejahr {}...", year))
|
||||||
|
.blue()
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let db = DatabaseSource::new(&database, &host, &password, port, &user);
|
||||||
|
let items = db
|
||||||
|
.check(&year)
|
||||||
|
.map_err(|_e| "Fehler bei Zugriff auf die Datenbank")?;
|
||||||
|
|
||||||
|
let _ = term.clear_last_lines(1);
|
||||||
|
|
||||||
|
print_items(&items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
src/resources/mod.rs
Normal file
21
src/resources/mod.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of bzkf-rwdp-check
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Comprehensive Cancer Center Mainfranken and contributors.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub const SQL_QUERY: &str = include_str!("query.sql");
|
133
src/resources/query.sql
Normal file
133
src/resources/query.sql
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of bzkf-rwdp-check
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Comprehensive Cancer Center Mainfranken and contributors.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
SELECT CASE
|
||||||
|
WHEN condcodingcode LIKE 'C00%'
|
||||||
|
OR condcodingcode LIKE 'C01%'
|
||||||
|
OR condcodingcode LIKE 'C02%'
|
||||||
|
OR condcodingcode LIKE 'C03%'
|
||||||
|
OR condcodingcode LIKE 'C04%'
|
||||||
|
OR condcodingcode LIKE 'C05%'
|
||||||
|
OR condcodingcode LIKE 'C06%'
|
||||||
|
OR condcodingcode LIKE 'C07%'
|
||||||
|
OR condcodingcode LIKE 'C08%'
|
||||||
|
OR condcodingcode LIKE 'C09%'
|
||||||
|
OR condcodingcode LIKE 'C10%'
|
||||||
|
OR condcodingcode LIKE 'C11%'
|
||||||
|
OR condcodingcode LIKE 'C12%'
|
||||||
|
OR condcodingcode LIKE 'C13%'
|
||||||
|
OR condcodingcode LIKE 'C14%' THEN 'C00-C14'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C15%' THEN 'C15'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C16%' THEN 'C16'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C18%'
|
||||||
|
OR condcodingcode LIKE 'C19%'
|
||||||
|
OR condcodingcode LIKE 'C20%'
|
||||||
|
OR condcodingcode LIKE 'C21%' THEN 'C18-C21'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C22%' THEN 'C22'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C23%'
|
||||||
|
OR condcodingcode LIKE 'C24%' THEN 'C23-C24'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C25%' THEN 'C25'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C32%' THEN 'C32'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C33%'
|
||||||
|
OR condcodingcode LIKE 'C34%' THEN 'C33-C34'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C43%' THEN 'C43'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C50%'
|
||||||
|
OR condcodingcode LIKE 'D05%' THEN 'C50, D05'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C53%'
|
||||||
|
OR condcodingcode LIKE 'D06%' THEN 'C53, D06'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C54%'
|
||||||
|
OR condcodingcode LIKE 'C55%' THEN 'C54-C55'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C56%'
|
||||||
|
OR condcodingcode = 'D39.1' THEN 'C56, D39.1'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C61%' THEN 'C61'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C62%' THEN 'C62'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C64%' THEN 'C64'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C67%'
|
||||||
|
OR condcodingcode = 'D09.0'
|
||||||
|
OR condcodingcode = 'D41.4' THEN 'C67, D09.0, D41.4'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C70%'
|
||||||
|
OR condcodingcode LIKE 'C71%'
|
||||||
|
OR condcodingcode LIKE 'C72%' THEN 'C70-C72'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C73%' THEN 'C73'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C81%' THEN 'C81'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C82%'
|
||||||
|
OR condcodingcode LIKE 'C83%'
|
||||||
|
OR condcodingcode LIKE 'C84%'
|
||||||
|
OR condcodingcode LIKE 'C85%'
|
||||||
|
OR condcodingcode LIKE 'C86%'
|
||||||
|
OR condcodingcode LIKE 'C87%'
|
||||||
|
OR condcodingcode LIKE 'C88%'
|
||||||
|
OR condcodingcode LIKE 'C96%' THEN 'C82-C88, C96'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C90%' THEN 'C90'
|
||||||
|
|
||||||
|
WHEN condcodingcode LIKE 'C91%'
|
||||||
|
OR condcodingcode LIKE 'C92%'
|
||||||
|
OR condcodingcode LIKE 'C93%'
|
||||||
|
OR condcodingcode LIKE 'C94%'
|
||||||
|
OR condcodingcode LIKE 'C95%' THEN 'C91-C95'
|
||||||
|
|
||||||
|
ELSE 'Other'
|
||||||
|
END AS ICD10_GROUP,
|
||||||
|
|
||||||
|
COUNT(*) as COUNT
|
||||||
|
FROM (
|
||||||
|
|
||||||
|
SELECT DISTINCT
|
||||||
|
EXTRACTVALUE(lme.xml_daten, '//Patienten_Stammdaten/@Patient_ID') AS pid, lme.versionsnummer, SHA2(CONCAT('https://fhir.diz.uk-erlangen.de/identifiers/onkostar-xml-condition-id|', EXTRACTVALUE(lme.xml_daten, '//Patienten_Stammdaten/@Patient_ID'), 'condition', EXTRACTVALUE(lme.xml_daten, '//Diagnose/@Tumor_ID')), 256) AS cond_id, SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Primaertumor_ICD_Code'), ' ', 1) AS condcodingcode, SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) AS diagnosejahr
|
||||||
|
FROM lkr_meldung_export lme
|
||||||
|
JOIN lkr_meldung lm ON (lm.id = lme.lkr_meldung AND lme.typ <> '-1')
|
||||||
|
WHERE lme.xml_daten LIKE '%ICD_Version%'
|
||||||
|
AND (lme.xml_daten LIKE '%<cTNM%' OR lme.xml_daten LIKE '%<pTNM%' OR lme.xml_daten LIKE '%<Menge_Histologie>%')
|
||||||
|
|
||||||
|
) o1
|
||||||
|
LEFT OUTER JOIN (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
SHA2(CONCAT('https://fhir.diz.uk-erlangen.de/identifiers/onkostar-xml-condition-id|', EXTRACTVALUE(lme.xml_daten, '//Patienten_Stammdaten/@Patient_ID'), 'condition', EXTRACTVALUE(lme.xml_daten, '//Diagnose/@Tumor_ID')), 256) AS cond_id, MAX(versionsnummer) AS max_version
|
||||||
|
FROM lkr_meldung_export lme
|
||||||
|
WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) = :year
|
||||||
|
GROUP BY cond_id ORDER BY cond_id
|
||||||
|
|
||||||
|
) o2
|
||||||
|
ON (o1.cond_id = o2.cond_id AND o1.versionsnummer < max_version)
|
||||||
|
WHERE diagnosejahr = :year AND o2.cond_id IS NULL
|
||||||
|
GROUP BY ICD10_GROUP;
|
Loading…
x
Reference in New Issue
Block a user