feat: ignore items after optional export date param

This commit is contained in:
Paul-Christian Volkmer 2024-03-13 17:52:26 +01:00
parent 2ee397d4b4
commit f3c08a972b
7 changed files with 52 additions and 9 deletions

View File

@ -15,6 +15,7 @@ itertools = "0.12"
mysql = "24.0" mysql = "24.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
urlencoding = "2.1" urlencoding = "2.1"
regex = "1.10"
[profile.release] [profile.release]
opt-level = "s" opt-level = "s"

View File

@ -58,6 +58,10 @@ Options:
-y, --year <YEAR> Jahr der Diagnose -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 ## Export aus der Onkostar-Datenbank
Die Anwendung ist in der Lage, mit dem Befehl `export` die Spalten Die Anwendung ist in der Lage, mit dem Befehl `export` die Spalten

View File

@ -19,6 +19,7 @@
*/ */
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use regex::Regex;
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about)] #[command(author, version, about)]
@ -58,6 +59,8 @@ pub enum SubCommand {
user: String, user: String,
#[arg(short = 'y', long, help = "Jahr der Diagnose")] #[arg(short = 'y', long, help = "Jahr der Diagnose")]
year: String, year: String,
#[arg(long, value_parser = value_is_date, help = "Ignoriere LKR-Exporte seit Datum")]
ignore_exports_since: Option<String>,
}, },
#[command( #[command(
about = "Erstellt eine (reduzierte) CSV-Datei zum direkten Vergleich mit der OPAL-CSV-Datei" about = "Erstellt eine (reduzierte) CSV-Datei zum direkten Vergleich mit der OPAL-CSV-Datei"
@ -88,6 +91,8 @@ pub enum SubCommand {
output: String, output: String,
#[arg(short = 'y', long, help = "Jahr der Diagnose")] #[arg(short = 'y', long, help = "Jahr der Diagnose")]
year: String, 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")] #[command(about = "Abgleich zwischen CSV-Datei für OPAL und Onkostar-Datenbank")]
Compare { Compare {
@ -116,5 +121,19 @@ pub enum SubCommand {
file: String, file: String,
#[arg(short = 'y', long, help = "Jahr der Diagnose")] #[arg(short = 'y', long, help = "Jahr der Diagnose")]
year: String, 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
))
}
}

View File

@ -20,6 +20,7 @@
use mysql::prelude::Queryable; use mysql::prelude::Queryable;
use mysql::{params, Pool}; use mysql::{params, Pool};
use std::time::Duration;
use crate::common::{ExportData, Icd10GroupSize}; use crate::common::{ExportData, Icd10GroupSize};
use crate::resources::{EXPORT_QUERY, SQL_QUERY}; use crate::resources::{EXPORT_QUERY, SQL_QUERY};
@ -33,13 +34,13 @@ impl DatabaseSource {
DatabaseSource(url) 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()) { match Pool::new(self.0.as_str()) {
Ok(pool) => { Ok(pool) => {
if let Ok(mut connection) = pool.get_conn() { if let Ok(mut connection) = pool.get_conn() {
return match connection.exec_map( return match connection.exec_map(
SQL_QUERY, SQL_QUERY,
params! {"year" => year}, params! {"year" => year, "ignore_exports_since" => ignore_exports_since},
|(icd10_group, count)| Icd10GroupSize { |(icd10_group, count)| Icd10GroupSize {
name: icd10_group, name: icd10_group,
size: count, size: count,
@ -58,13 +59,18 @@ impl DatabaseSource {
Err(()) 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()) { match Pool::new(self.0.as_str()) {
Ok(pool) => { Ok(pool) => {
if let Ok(mut connection) = pool.get_conn() { if let Ok(mut connection) = pool.get_conn() {
return match connection.exec_map( return match connection.exec_map(
EXPORT_QUERY, 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, diagnosis_date, pat_id)| ExportData {
condition_id, condition_id,
icd_10_code, icd_10_code,

View File

@ -104,6 +104,7 @@ fn main() -> Result<(), Box<dyn Error>> {
port, port,
user, user,
year, year,
ignore_exports_since,
} => { } => {
let password = request_password_if_none(password); let password = request_password_if_none(password);
let year = sanitize_year(year); let year = sanitize_year(year);
@ -116,7 +117,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let db = DatabaseSource::new(&database, &host, &password, port, &user); let db = DatabaseSource::new(&database, &host, &password, port, &user);
let items = db 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")?; .map_err(|_e| "Fehler bei Zugriff auf die Datenbank")?;
let _ = term.clear_last_lines(1); let _ = term.clear_last_lines(1);
@ -132,6 +133,7 @@ fn main() -> Result<(), Box<dyn Error>> {
user, user,
output, output,
year, year,
ignore_exports_since,
} => { } => {
let password = request_password_if_none(password); let password = request_password_if_none(password);
let year = sanitize_year(year); let year = sanitize_year(year);
@ -144,7 +146,11 @@ fn main() -> Result<(), Box<dyn Error>> {
let db = DatabaseSource::new(&database, &host, &password, port, &user); let db = DatabaseSource::new(&database, &host, &password, port, &user);
let items = db 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")?; .map_err(|_e| "Fehler bei Zugriff auf die Datenbank")?;
let _ = term.clear_last_lines(1); let _ = term.clear_last_lines(1);
@ -175,6 +181,7 @@ fn main() -> Result<(), Box<dyn Error>> {
user, user,
file, file,
year, year,
ignore_exports_since,
} => { } => {
let password = request_password_if_none(password); let password = request_password_if_none(password);
let year = sanitize_year(year); let year = sanitize_year(year);
@ -187,7 +194,11 @@ fn main() -> Result<(), Box<dyn Error>> {
let db = DatabaseSource::new(&database, &host, &password, port, &user); let db = DatabaseSource::new(&database, &host, &password, port, &user);
let db_items = db 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")?; .map_err(|_e| "Fehler bei Zugriff auf die Datenbank")?;
let _ = term.clear_last_lines(1); let _ = term.clear_last_lines(1);

View File

@ -34,10 +34,11 @@ FROM (
SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) AS diagnosejahr SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) AS diagnosejahr
FROM lkr_meldung_export lme FROM lkr_meldung_export lme
JOIN lkr_meldung lm ON (lm.id = lme.lkr_meldung AND lme.typ <> '-1') 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%' WHERE lme.xml_daten LIKE '%ICD_Version%'
AND SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) = :year 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 (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 ) o1
LEFT OUTER JOIN ( LEFT OUTER JOIN (

View File

@ -119,10 +119,11 @@ FROM (
SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) AS diagnosejahr SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) AS diagnosejahr
FROM lkr_meldung_export lme FROM lkr_meldung_export lme
JOIN lkr_meldung lm ON (lm.id = lme.lkr_meldung AND lme.typ <> '-1') 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%' WHERE lme.xml_daten LIKE '%ICD_Version%'
AND SUBSTRING_INDEX(SUBSTRING_INDEX(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), ' ', 1), '.', -1) = :year 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 (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 ) o1
LEFT OUTER JOIN ( LEFT OUTER JOIN (