mirror of
https://github.com/pcvolkmer/bzkf-rwdp-check.git
synced 2025-04-19 19:16:51 +00:00
feat: request data from db and compare with file
This commit is contained in:
parent
6617ce76a0
commit
0dfc6a0083
26
src/cli.rs
26
src/cli.rs
@ -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> {
|
||||||
|
@ -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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
44
src/main.rs
44
src/main.rs
@ -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(())
|
||||||
|
25
src/resources/exported-to-lkr.sql
Normal file
25
src/resources/exported-to-lkr.sql
Normal 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));
|
@ -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");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user