mirror of
https://github.com/pcvolkmer/bzkf-rwdp-check.git
synced 2025-07-01 15:52:54 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
5a59deb75d | |||
f3c08a972b | |||
2ee397d4b4 | |||
299b4bcc39 | |||
88cd49db47 | |||
f8037caaf9 | |||
716b666153 | |||
5a162bc502 | |||
2297e20cba |
10
Cargo.toml
10
Cargo.toml
@ -1,12 +1,13 @@
|
||||
[package]
|
||||
name = "bzkf-rwdp-check"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
authors = ["Paul-Christian Volkmer <volkmer_p@ukw.de>"]
|
||||
description = "Anwendung zur Durchführung einer Plausibilitätsprüfung anhand der Daten für die BZKF Real World Data Platform."
|
||||
repository = "https://github.com/CCC-MF/bzkf-rwdp-check"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false }
|
||||
clap = { version = "4.5", features = ["std", "help", "usage", "derive", "error-context"], default-features = false }
|
||||
console = "0.15"
|
||||
csv = "1.3"
|
||||
dialoguer = "0.11"
|
||||
@ -14,6 +15,7 @@ itertools = "0.12"
|
||||
mysql = "24.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
urlencoding = "2.1"
|
||||
regex = "1.10"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
||||
|
@ -58,6 +58,10 @@ Options:
|
||||
-y, --year <YEAR> Jahr der Diagnose
|
||||
```
|
||||
|
||||
Der zusätzliche Parameter `--ignore-exports-since` ist optional.
|
||||
Wird er angegeben, werden keine Einträge mit Exportdatum ab diesem Datum verwendet.
|
||||
Dies eignet sich um nachträglich Zahlen zu einem bestimmten Datum zu ermitteln.
|
||||
|
||||
## Export aus der Onkostar-Datenbank
|
||||
|
||||
Die Anwendung ist in der Lage, mit dem Befehl `export` die Spalten
|
||||
|
19
src/cli.rs
19
src/cli.rs
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use regex::Regex;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about)]
|
||||
@ -58,6 +59,8 @@ pub enum SubCommand {
|
||||
user: String,
|
||||
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
||||
year: String,
|
||||
#[arg(long, value_parser = value_is_date, help = "Ignoriere LKR-Exporte seit Datum")]
|
||||
ignore_exports_since: Option<String>,
|
||||
},
|
||||
#[command(
|
||||
about = "Erstellt eine (reduzierte) CSV-Datei zum direkten Vergleich mit der OPAL-CSV-Datei"
|
||||
@ -88,6 +91,8 @@ pub enum SubCommand {
|
||||
output: String,
|
||||
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
||||
year: String,
|
||||
#[arg(long, value_parser = value_is_date, help = "Ignoriere LKR-Exporte seit Datum")]
|
||||
ignore_exports_since: Option<String>,
|
||||
},
|
||||
#[command(about = "Abgleich zwischen CSV-Datei für OPAL und Onkostar-Datenbank")]
|
||||
Compare {
|
||||
@ -116,5 +121,19 @@ pub enum SubCommand {
|
||||
file: String,
|
||||
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
||||
year: String,
|
||||
#[arg(long, value_parser = value_is_date, help = "Ignoriere LKR-Exporte seit Datum")]
|
||||
ignore_exports_since: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
fn value_is_date(value: &str) -> Result<String, String> {
|
||||
let re = Regex::new(r"^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$").unwrap();
|
||||
if re.is_match(value) {
|
||||
Ok(value.into())
|
||||
} else {
|
||||
Err(format!(
|
||||
"Ungültiges Datum '{}', bitte im Format 'yyyy-mm-dd' angeben",
|
||||
value
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ impl Check {
|
||||
.map(|(icd10, group)| (icd10, group.collect::<Vec<_>>()))
|
||||
.map(|record| Icd10GroupSize {
|
||||
name: record.0,
|
||||
size: record.1.iter().count(),
|
||||
size: record.1.len(),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@ -76,10 +76,7 @@ impl Check {
|
||||
}
|
||||
|
||||
pub fn is_relevant(code: &str) -> bool {
|
||||
match Self::map_icd_code(code).as_str() {
|
||||
"Other" => false,
|
||||
_ => true,
|
||||
}
|
||||
!matches!(Self::map_icd_code(code).as_str(), "Other")
|
||||
}
|
||||
|
||||
fn map_icd_code(code: &str) -> String {
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
use mysql::prelude::Queryable;
|
||||
use mysql::{params, Pool};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::common::{ExportData, Icd10GroupSize};
|
||||
use crate::resources::{EXPORT_QUERY, SQL_QUERY};
|
||||
@ -33,13 +34,13 @@ impl DatabaseSource {
|
||||
DatabaseSource(url)
|
||||
}
|
||||
|
||||
pub fn check(&self, year: &str) -> Result<Vec<Icd10GroupSize>, ()> {
|
||||
pub fn check(&self, year: &str, ignore_exports_since: &str) -> Result<Vec<Icd10GroupSize>, ()> {
|
||||
match Pool::new(self.0.as_str()) {
|
||||
Ok(pool) => {
|
||||
if let Ok(mut connection) = pool.get_conn() {
|
||||
if let Ok(mut connection) = pool.try_get_conn(Duration::from_secs(3)) {
|
||||
return match connection.exec_map(
|
||||
SQL_QUERY,
|
||||
params! {"year" => year},
|
||||
params! {"year" => year, "ignore_exports_since" => ignore_exports_since},
|
||||
|(icd10_group, count)| Icd10GroupSize {
|
||||
name: icd10_group,
|
||||
size: count,
|
||||
@ -58,13 +59,18 @@ impl DatabaseSource {
|
||||
Err(())
|
||||
}
|
||||
|
||||
pub fn export(&self, year: &str, use_pat_id: bool) -> Result<Vec<ExportData>, ()> {
|
||||
pub fn export(
|
||||
&self,
|
||||
year: &str,
|
||||
ignore_exports_since: &str,
|
||||
use_pat_id: bool,
|
||||
) -> Result<Vec<ExportData>, ()> {
|
||||
match Pool::new(self.0.as_str()) {
|
||||
Ok(pool) => {
|
||||
if let Ok(mut connection) = pool.get_conn() {
|
||||
if let Ok(mut connection) = pool.try_get_conn(Duration::from_secs(3)) {
|
||||
return match connection.exec_map(
|
||||
EXPORT_QUERY,
|
||||
params! {"year" => year},
|
||||
params! {"year" => year, "ignore_exports_since" => ignore_exports_since},
|
||||
|(condition_id, icd_10_code, diagnosis_date, pat_id)| ExportData {
|
||||
condition_id,
|
||||
icd_10_code,
|
||||
|
110
src/main.rs
110
src/main.rs
@ -36,6 +36,27 @@ mod database;
|
||||
mod opal;
|
||||
mod resources;
|
||||
|
||||
fn request_password_if_none(password: Option<String>) -> String {
|
||||
if let Some(password) = password {
|
||||
password
|
||||
} else {
|
||||
let password = dialoguer::Password::new()
|
||||
.with_prompt("Password")
|
||||
.interact()
|
||||
.unwrap_or_default();
|
||||
let _ = Term::stdout().clear_last_lines(1);
|
||||
password
|
||||
}
|
||||
}
|
||||
|
||||
fn sanitize_year(year: String) -> String {
|
||||
if year.len() == 4 {
|
||||
year
|
||||
} else {
|
||||
format!("2{:0>3}", year)
|
||||
}
|
||||
}
|
||||
|
||||
fn print_items(items: &[Icd10GroupSize]) {
|
||||
let term = Term::stdout();
|
||||
let _ = term.write_line(
|
||||
@ -46,6 +67,24 @@ fn print_items(items: &[Icd10GroupSize]) {
|
||||
items.iter().for_each(|item| {
|
||||
let _ = term.write_line(&format!("{:<20}={:>6}", item.name, item.size));
|
||||
});
|
||||
let sum: usize = items
|
||||
.iter()
|
||||
.filter(|item| item.name != "Other")
|
||||
.map(|item| item.size)
|
||||
.sum();
|
||||
let _ = term.write_line(&style("─".repeat(27)).dim().to_string());
|
||||
let _ = term.write_line(
|
||||
&style(format!("{:<20}={:>6}", "Summe (C**.*/D**.*)", sum))
|
||||
.dim()
|
||||
.to_string(),
|
||||
);
|
||||
let sum: usize = items.iter().map(|item| item.size).sum();
|
||||
let _ = term.write_line(
|
||||
&style(format!("{:<20}={:>6}", "Gesamtsumme", sum))
|
||||
.dim()
|
||||
.to_string(),
|
||||
);
|
||||
let _ = term.write_line(&style("─".repeat(27)).dim().to_string());
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
@ -65,23 +104,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
port,
|
||||
user,
|
||||
year,
|
||||
ignore_exports_since,
|
||||
} => {
|
||||
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 password = request_password_if_none(password);
|
||||
let year = sanitize_year(year);
|
||||
|
||||
let _ = term.write_line(
|
||||
&style(format!("Warte auf Daten für das Diagnosejahr {}...", year))
|
||||
@ -91,7 +117,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let db = DatabaseSource::new(&database, &host, &password, port, &user);
|
||||
let items = db
|
||||
.check(&year)
|
||||
.check(&year, &ignore_exports_since.unwrap_or("9999-12-31".into()))
|
||||
.map_err(|_e| "Fehler bei Zugriff auf die Datenbank")?;
|
||||
|
||||
let _ = term.clear_last_lines(1);
|
||||
@ -107,23 +133,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
user,
|
||||
output,
|
||||
year,
|
||||
ignore_exports_since,
|
||||
} => {
|
||||
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 password = request_password_if_none(password);
|
||||
let year = sanitize_year(year);
|
||||
|
||||
let _ = term.write_line(
|
||||
&style(format!("Warte auf Daten für das Diagnosejahr {}...", year))
|
||||
@ -133,7 +146,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let db = DatabaseSource::new(&database, &host, &password, port, &user);
|
||||
let items = db
|
||||
.export(&year, pat_id)
|
||||
.export(
|
||||
&year,
|
||||
&ignore_exports_since.unwrap_or("9999-12-31".into()),
|
||||
pat_id,
|
||||
)
|
||||
.map_err(|_e| "Fehler bei Zugriff auf die Datenbank")?;
|
||||
|
||||
let _ = term.clear_last_lines(1);
|
||||
@ -164,23 +181,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
user,
|
||||
file,
|
||||
year,
|
||||
ignore_exports_since,
|
||||
} => {
|
||||
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 password = request_password_if_none(password);
|
||||
let year = sanitize_year(year);
|
||||
|
||||
let _ = term.write_line(
|
||||
&style(format!("Warte auf Daten für das Diagnosejahr {}...", year))
|
||||
@ -190,7 +194,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let db = DatabaseSource::new(&database, &host, &password, port, &user);
|
||||
let db_items = db
|
||||
.export(&year, pat_id)
|
||||
.export(
|
||||
&year,
|
||||
&ignore_exports_since.unwrap_or("9999-12-31".into()),
|
||||
pat_id,
|
||||
)
|
||||
.map_err(|_e| "Fehler bei Zugriff auf die Datenbank")?;
|
||||
|
||||
let _ = term.clear_last_lines(1);
|
||||
|
@ -41,8 +41,7 @@ impl OpalCsvFile {
|
||||
|
||||
let items = reader
|
||||
.deserialize::<OpalRecord>()
|
||||
.filter(|record| record.is_ok())
|
||||
.map(|record| record.unwrap())
|
||||
.filter_map(|record| record.ok())
|
||||
.map(|record| Record {
|
||||
condition_id: record.cond_id,
|
||||
icd10_code: record.cond_coding_code,
|
||||
@ -57,8 +56,7 @@ impl OpalCsvFile {
|
||||
|
||||
let items = reader
|
||||
.deserialize::<ExportData>()
|
||||
.filter(|record| record.is_ok())
|
||||
.map(|record| record.unwrap())
|
||||
.filter_map(|record| record.ok())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(items)
|
||||
|
@ -34,10 +34,11 @@ FROM (
|
||||
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')
|
||||
JOIN lkr_export le ON (le.id = lme.lkr_export)
|
||||
WHERE lme.xml_daten LIKE '%ICD_Version%'
|
||||
AND SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) = :year
|
||||
AND (lme.xml_daten LIKE '%<cTNM%' OR lme.xml_daten LIKE '%<pTNM%' OR lme.xml_daten LIKE '%<Menge_Histologie>%' OR lme.xml_daten LIKE '%<Menge_Weitere_Klassifikation>%')
|
||||
|
||||
AND le.exportiert_am < :ignore_exports_since
|
||||
) o1
|
||||
LEFT OUTER JOIN (
|
||||
|
||||
|
@ -119,10 +119,11 @@ FROM (
|
||||
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')
|
||||
JOIN lkr_export le ON (le.id = lme.lkr_export)
|
||||
WHERE lme.xml_daten LIKE '%ICD_Version%'
|
||||
AND SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) = :year
|
||||
AND (lme.xml_daten LIKE '%<cTNM%' OR lme.xml_daten LIKE '%<pTNM%' OR lme.xml_daten LIKE '%<Menge_Histologie>%' OR lme.xml_daten LIKE '%<Menge_Weitere_Klassifikation>%')
|
||||
|
||||
AND le.exportiert_am < :ignore_exports_since
|
||||
) o1
|
||||
LEFT OUTER JOIN (
|
||||
|
||||
|
Reference in New Issue
Block a user