feat: request data from db and compare with file

This commit is contained in:
Paul-Christian Volkmer 2024-06-11 19:43:13 +02:00
parent 6617ce76a0
commit 0dfc6a0083
6 changed files with 131 additions and 1 deletions

View File

@ -148,6 +148,32 @@ pub enum SubCommand {
)] )]
include_histo_zyto: bool, include_histo_zyto: bool,
}, },
#[command(about = "Abgleich zwischen LKR-Export-Protokoll und Onkostar-Datenbank")]
CheckExport {
#[arg(short = 'D', long, help = "Datenbank-Name", default_value = "onkostar")]
database: 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, long, help = "LKR-Export-Protokoll-Datei")]
file: PathBuf,
#[arg(long, help = "Exportpaketnummer", default_value = "0")]
export_package: u16,
},
} }
fn value_is_date(value: &str) -> Result<String, String> { fn value_is_date(value: &str) -> Result<String, String> {

View File

@ -24,7 +24,7 @@ use mysql::prelude::Queryable;
use mysql::{params, Pool}; use mysql::{params, Pool};
use crate::common::{ExportData, Icd10GroupSize}; use crate::common::{ExportData, Icd10GroupSize};
use crate::resources::{EXPORT_QUERY, SQL_QUERY}; use crate::resources::{EXPORTED_TO_LKR, EXPORT_QUERY, SQL_QUERY};
pub struct DatabaseSource(String); pub struct DatabaseSource(String);
@ -111,4 +111,30 @@ impl DatabaseSource {
Err(()) Err(())
} }
pub fn exported(&self, export_id: u16) -> Result<Vec<(String, String)>, ()> {
match Pool::new(self.0.as_str()) {
Ok(pool) => {
if let Ok(mut connection) = pool.try_get_conn(Duration::from_secs(3)) {
return match connection.exec_map(
EXPORTED_TO_LKR,
params! {
"export_id" => export_id,
},
|(id, xml_data)| (id, xml_data),
) {
Ok(result) => Ok(result),
Err(_) => {
return Err(());
}
};
}
}
Err(_) => {
return Err(());
}
}
Err(())
}
} }

View File

@ -50,6 +50,13 @@ impl LkrExportProtocolFile {
Err(()) Err(())
} }
pub fn meldungen(&self) -> Vec<Meldung> {
self.patients
.iter()
.flat_map(|patient| patient.meldungen())
.collect_vec()
}
} }
pub struct Patient { pub struct Patient {

View File

@ -423,6 +423,50 @@ fn main() -> Result<(), Box<dyn Error>> {
)); ));
}); });
} }
SubCommand::CheckExport {
database,
host,
password,
port,
user,
file,
export_package,
} => {
let password = request_password_if_none(password);
let _ = term.write_line(
&style(format!(
"Warte auf Daten für den LKR-Export '{}'...",
export_package
))
.blue()
.to_string(),
);
let db = DatabaseSource::new(&database, &host, &password, port, &user);
let exported_db_msg = db
.exported(export_package)
.map_err(|_e| "Fehler bei Zugriff auf die Datenbank")?;
let xml_file_content = LkrExportProtocolFile::parse_file(file.as_path())
.map_err(|_e| "Fehler bei Zugriff auf die Protokolldatei")?;
let _ = term.clear_last_lines(1);
if exported_db_msg.len() != xml_file_content.meldungen().len() {
let _ = term.write_line(
&style(format!("Nicht übereinstimmende Anzahl an Meldungen:",))
.yellow()
.to_string(),
);
let _ = term.write_line(&format!(
"Datenbank: {:>10}\nProtokolldatei: {:>10}",
exported_db_msg.len(),
xml_file_content.meldungen().len()
));
}
}
} }
Ok(()) Ok(())

View File

@ -0,0 +1,25 @@
/*
* 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
id,
xml_daten
FROM lkr_meldung_export
WHERE lkr_export = :export_id OR (0 = :export_id AND lkr_export IN (SELECT MAX(lkr_export) FROM lkr_meldung_export));

View File

@ -21,3 +21,5 @@
pub const SQL_QUERY: &str = include_str!("query.sql"); pub const SQL_QUERY: &str = include_str!("query.sql");
pub const EXPORT_QUERY: &str = include_str!("export.sql"); pub const EXPORT_QUERY: &str = include_str!("export.sql");
pub const EXPORTED_TO_LKR: &str = include_str!("exported-to-lkr.sql");