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"
serde = { version = "1.0", features = ["derive"] }
urlencoding = "2.1"
regex = "1.10"
[profile.release]
opt-level = "s"

View File

@ -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

View File

@ -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
))
}
}

View File

@ -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() {
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() {
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,

View File

@ -104,6 +104,7 @@ fn main() -> Result<(), Box<dyn Error>> {
port,
user,
year,
ignore_exports_since,
} => {
let password = request_password_if_none(password);
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 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);
@ -132,6 +133,7 @@ fn main() -> Result<(), Box<dyn Error>> {
user,
output,
year,
ignore_exports_since,
} => {
let password = request_password_if_none(password);
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 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);
@ -175,6 +181,7 @@ fn main() -> Result<(), Box<dyn Error>> {
user,
file,
year,
ignore_exports_since,
} => {
let password = request_password_if_none(password);
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_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);

View File

@ -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 (

View File

@ -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 (