mirror of
https://github.com/pcvolkmer/bzkf-rwdp-check.git
synced 2025-07-03 08:32:53 +00:00
Initial commit
This commit is contained in:
49
src/cli.rs
Normal file
49
src/cli.rs
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about)]
|
||||
#[command(arg_required_else_help(true))]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub cmd: SubCommand,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum SubCommand {
|
||||
#[command(
|
||||
about = "Ermittelt die Prüfwerte aus einem CSV-File für OPAL"
|
||||
)]
|
||||
OpalFile {
|
||||
#[arg(short, long, help = "CSV-File für Opal")] file: String
|
||||
},
|
||||
#[command(
|
||||
about = "Ermittelt die Prüfwerte aus einem CSV-File für OPAL"
|
||||
)]
|
||||
Database {
|
||||
#[arg(long, help = "Datenbank-Host", default_value="localhost")] host: String,
|
||||
#[arg(long, help = "Datenbank-Host", default_value="3306")] port: u16,
|
||||
#[arg(long, help = "Benutzername")] user: String,
|
||||
}
|
||||
|
||||
|
||||
}
|
90
src/common.rs
Normal file
90
src/common.rs
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
pub struct Icd10GroupSize {
|
||||
pub name: String,
|
||||
pub size: usize
|
||||
}
|
||||
|
||||
pub struct Record {
|
||||
pub condition_id: String,
|
||||
pub icd10_code: String,
|
||||
}
|
||||
|
||||
pub struct Check;
|
||||
|
||||
impl Check {
|
||||
|
||||
/// Collects all records by grouping by ICD10 group
|
||||
pub fn collect(records: &[Record]) -> Result<Vec<Icd10GroupSize>, ()> {
|
||||
let items = records.iter()
|
||||
.map(|record| Record {
|
||||
condition_id: record.condition_id.to_string(),
|
||||
icd10_code: Self::map_icd_code(&record.icd10_code)
|
||||
})
|
||||
.sorted_by_key(|record| record.icd10_code.to_string())
|
||||
.group_by(|record| record.icd10_code.to_string())
|
||||
.into_iter()
|
||||
.map(|(icd10, group)| (icd10, group.collect::<Vec<_>>()))
|
||||
.map(|record| Icd10GroupSize {
|
||||
name: record.0,
|
||||
size: record.1.iter().count()
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
fn map_icd_code(code: &str) -> String {
|
||||
let icd10 = match code {
|
||||
"D39.1" | "D09.0" | "D41.4" => code,
|
||||
_ => code.split('.').collect::<Vec<_>>().first().unwrap()
|
||||
};
|
||||
|
||||
match icd10 {
|
||||
"C00" | "C01" | "C02" | "C03" | "C04" | "C05" | "C06" | "C07" | "C08" | "C09" | "C10" | "C11" | "C12" | "C13" | "C14" => "C00-C14",
|
||||
"C15" => "C15",
|
||||
"C16" => "C16",
|
||||
"C18" | "C19" | "C20" | "C21" => "C18-C21",
|
||||
"C22" => "C22",
|
||||
"C23" | "C24" => "C23-C24",
|
||||
"C25" => "C25",
|
||||
"C32" => "C32",
|
||||
"C33" | "C34" => "C33-C34",
|
||||
"C43" => "C43",
|
||||
"C50" | "D05" => "C50, D05",
|
||||
"C53" | "D06" => "C53, D06",
|
||||
"C54" | "C55" => "C54-C55",
|
||||
"C56" | "D39.1" => "C56, D39.1",
|
||||
"C61" => "C61",
|
||||
"C62" => "C62",
|
||||
"C64" => "C64",
|
||||
"C67" | "D09.0" | "D41.4" => "C67, D09.0, D41.4",
|
||||
"C70" | "C71" | "C72" => "C70-C72",
|
||||
"C73" => "C73",
|
||||
"C81" => "C81",
|
||||
"C82" | "C83" | "C84" | "C85" | "C86" | "C87" | "C88" | "C96" => "C82-C88, C96",
|
||||
"C90" => "C90",
|
||||
"C91" | "C92" | "C93" | "C94" | "C95" => "C91-C95",
|
||||
_ => "Other"
|
||||
}.to_string()
|
||||
}
|
||||
}
|
52
src/main.rs
Normal file
52
src/main.rs
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use std::error::Error;
|
||||
use std::path::Path;
|
||||
|
||||
use clap::Parser;
|
||||
use console::{style, Term};
|
||||
|
||||
use crate::cli::{Cli, SubCommand};
|
||||
|
||||
mod opal;
|
||||
mod common;
|
||||
mod cli;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let term = Term::stdout();
|
||||
|
||||
match Cli::parse().cmd {
|
||||
SubCommand::OpalFile { file } => {
|
||||
let items = opal::OpalCsvFile::check(Path::new(&file))
|
||||
.map_err(|_e| "Kann Datei nicht lesen")?;
|
||||
|
||||
let _ = term.write_line(&style("Anzahl der Conditions nach ICD-Gruppe").yellow().to_string());
|
||||
items.iter().for_each(|item| {
|
||||
let _ = term.write_line(&format!("{:<20}={:>6}", item.name, item.size));
|
||||
});
|
||||
},
|
||||
SubCommand::Database { .. } => {
|
||||
todo!("Not implemented yet")
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
54
src/opal.rs
Normal file
54
src/opal.rs
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use csv::Reader;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::common::{Check, Icd10GroupSize, Record};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct OpalRecord {
|
||||
#[serde(rename = "cond_id")]
|
||||
cond_id: String,
|
||||
#[serde(rename = "condcodingcode")]
|
||||
cond_coding_code: String,
|
||||
}
|
||||
|
||||
pub struct OpalCsvFile;
|
||||
|
||||
impl OpalCsvFile {
|
||||
pub fn check(path: &Path) -> Result<Vec<Icd10GroupSize>, ()> {
|
||||
let mut reader = Reader::from_path(path).expect("open file");
|
||||
|
||||
let items = reader.deserialize::<OpalRecord>()
|
||||
.filter(|record| record.is_ok())
|
||||
.map(|record| record.unwrap())
|
||||
.map(|record| Record {
|
||||
condition_id: record.cond_id,
|
||||
icd10_code: record.cond_coding_code
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Check::collect(&items)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user