mirror of
https://github.com/pcvolkmer/bzkf-rwdp-check.git
synced 2025-04-19 19:16:51 +00:00
feat: parse LKR protocol file
This commit is contained in:
parent
66c02edccc
commit
6617ce76a0
167
src/lkrexport.rs
Normal file
167
src/lkrexport.rs
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
* 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::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
pub struct LkrExportProtocolFile {
|
||||||
|
pub patients: Vec<Patient>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LkrExportProtocolFile {
|
||||||
|
pub fn parse_file(path: &Path) -> Result<LkrExportProtocolFile, ()> {
|
||||||
|
let xml_file_content = fs::read_to_string(path).map_err(|_| ())?;
|
||||||
|
Self::parse(&xml_file_content)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse(content: &str) -> Result<LkrExportProtocolFile, ()> {
|
||||||
|
let re = Regex::new(r"(?s)(?<patient><Patient>(.*?)</Patient>)").unwrap();
|
||||||
|
|
||||||
|
if re.is_match(content) {
|
||||||
|
let patients = re
|
||||||
|
.find_iter(content)
|
||||||
|
.map(|m| Patient {
|
||||||
|
raw_value: m.as_str().to_string(),
|
||||||
|
})
|
||||||
|
.collect_vec();
|
||||||
|
return Ok(LkrExportProtocolFile { patients });
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Patient {
|
||||||
|
pub raw_value: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Patient {
|
||||||
|
pub fn meldungen(&self) -> Vec<Meldung> {
|
||||||
|
let re = Regex::new(r"(?s)(?<meldung><Meldung(.*?)</Meldung>)").unwrap();
|
||||||
|
|
||||||
|
if re.is_match(&self.raw_value) {
|
||||||
|
return re
|
||||||
|
.find_iter(&self.raw_value)
|
||||||
|
.map(|m| Meldung {
|
||||||
|
raw_value: m.as_str().to_string(),
|
||||||
|
})
|
||||||
|
.collect_vec();
|
||||||
|
}
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Meldung {
|
||||||
|
pub raw_value: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Meldung {
|
||||||
|
type Err = ();
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
Ok(Meldung {
|
||||||
|
raw_value: s.to_string(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Meldung {
|
||||||
|
pub fn id(&self) -> Option<String> {
|
||||||
|
let re = Regex::new(r#"Meldung_ID="(?<meldung_id>(.*?))""#).unwrap();
|
||||||
|
|
||||||
|
if re.is_match(&self.raw_value) {
|
||||||
|
let caps = re.captures(&self.raw_value).unwrap();
|
||||||
|
return Some(caps["meldung_id"].to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn database_id(&self) -> Option<String> {
|
||||||
|
return match self.id() {
|
||||||
|
Some(id) => {
|
||||||
|
let re1 = Regex::new(r"^(?<id>[0-9A-F]+)").unwrap();
|
||||||
|
let re2 = Regex::new(r"(?<id>[0-9]+)$").unwrap();
|
||||||
|
|
||||||
|
if re1.is_match(&id) {
|
||||||
|
match re1.find(&id).map(|m| m.as_str().to_string()) {
|
||||||
|
Some(val) => match u64::from_str_radix(&val, 16) {
|
||||||
|
Ok(val) => Some(val.to_string()),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
} else if re2.is_match(&id) {
|
||||||
|
re2.find(&id).map(|m| m.as_str().to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::lkrexport::LkrExportProtocolFile;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_read_xml_file_content() {
|
||||||
|
let actual = LkrExportProtocolFile::parse(include_str!("../testdaten/testdaten_1.xml"));
|
||||||
|
|
||||||
|
assert!(actual.is_ok());
|
||||||
|
assert_eq!(actual.unwrap().patients.len(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_get_meldungen() {
|
||||||
|
let actual = LkrExportProtocolFile::parse(include_str!("../testdaten/testdaten_1.xml"));
|
||||||
|
|
||||||
|
assert!(actual.is_ok());
|
||||||
|
|
||||||
|
let patients = actual.unwrap().patients;
|
||||||
|
|
||||||
|
assert_eq!(patients[0].meldungen().len(), 1);
|
||||||
|
assert_eq!(patients[1].meldungen().len(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_get_meldung_database_id() {
|
||||||
|
let actual = LkrExportProtocolFile::parse(include_str!("../testdaten/testdaten_1.xml"));
|
||||||
|
|
||||||
|
assert!(actual.is_ok());
|
||||||
|
|
||||||
|
let patients = actual.unwrap().patients;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
patients[0].meldungen()[0].database_id(),
|
||||||
|
Some("1727528".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
patients[1].meldungen()[0].database_id(),
|
||||||
|
Some("1727824".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -28,10 +28,12 @@ use itertools::Itertools;
|
|||||||
use crate::cli::{Cli, SubCommand};
|
use crate::cli::{Cli, SubCommand};
|
||||||
use crate::common::{Check, DiffRecord, Icd10GroupSize};
|
use crate::common::{Check, DiffRecord, Icd10GroupSize};
|
||||||
use crate::database::DatabaseSource;
|
use crate::database::DatabaseSource;
|
||||||
|
use crate::lkrexport::LkrExportProtocolFile;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod common;
|
mod common;
|
||||||
mod database;
|
mod database;
|
||||||
|
mod lkrexport;
|
||||||
mod opal;
|
mod opal;
|
||||||
mod resources;
|
mod resources;
|
||||||
|
|
||||||
|
89
testdaten/testdaten_1.xml
Normal file
89
testdaten/testdaten_1.xml
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ADT_GEKID xmlns="http://www.gekid.de/namespace" Schema_Version="2.2.3">
|
||||||
|
<Absender Absender_ID="TEST" Software_ID="ONKOSTAR" Installations_ID="2011">
|
||||||
|
<Absender_Bezeichnung>TEST</Absender_Bezeichnung>
|
||||||
|
<Absender_Anschrift>Musterstraße 1, 012345 Musterhausen</Absender_Anschrift>
|
||||||
|
</Absender>
|
||||||
|
<Menge_Patient>
|
||||||
|
<Patient>
|
||||||
|
<Patienten_Stammdaten Patient_ID="20001234">
|
||||||
|
<KrankenversichertenNr>E123456789</KrankenversichertenNr>
|
||||||
|
<KrankenkassenNr>123456789</KrankenkassenNr>
|
||||||
|
<Patienten_Nachname>Tester</Patienten_Nachname>
|
||||||
|
<Patienten_Titel></Patienten_Titel>
|
||||||
|
<Patienten_Vornamen>Patrick</Patienten_Vornamen>
|
||||||
|
<Patienten_Geburtsname>Tester</Patienten_Geburtsname>
|
||||||
|
<Patienten_Geschlecht>M</Patienten_Geschlecht>
|
||||||
|
<Patienten_Geburtsdatum>01.01.1980</Patienten_Geburtsdatum>
|
||||||
|
<Menge_Adresse>
|
||||||
|
<Adresse>
|
||||||
|
<Patienten_Strasse>Testweg</Patienten_Strasse>
|
||||||
|
<Patienten_Hausnummer>1</Patienten_Hausnummer>
|
||||||
|
<Patienten_Land>DE</Patienten_Land>
|
||||||
|
<Patienten_PLZ>01234</Patienten_PLZ>
|
||||||
|
<Patienten_Ort>Musterhausen</Patienten_Ort>
|
||||||
|
</Adresse>
|
||||||
|
</Menge_Adresse>
|
||||||
|
</Patienten_Stammdaten>
|
||||||
|
<Menge_Meldung>
|
||||||
|
<Meldung Meldung_ID="TEST1727528" Melder_ID="TEST">
|
||||||
|
<Meldedatum>11.06.2024</Meldedatum>
|
||||||
|
<Meldebegruendung>I</Meldebegruendung>
|
||||||
|
<Meldeanlass>statusaenderung</Meldeanlass>
|
||||||
|
<Tumorzuordnung Tumor_ID="1">
|
||||||
|
<Primaertumor_ICD_Code>C17.2</Primaertumor_ICD_Code>
|
||||||
|
<Primaertumor_ICD_Version>10 2015 GM</Primaertumor_ICD_Version>
|
||||||
|
<Diagnosedatum>10.06.2024</Diagnosedatum>
|
||||||
|
<Seitenlokalisation>T</Seitenlokalisation>
|
||||||
|
</Tumorzuordnung>
|
||||||
|
<Menge_Tumorkonferenz>
|
||||||
|
<Tumorkonferenz Tumorkonferenz_ID="1234567">
|
||||||
|
<Tumorkonferenz_Datum>11.06.2024</Tumorkonferenz_Datum>
|
||||||
|
<Tumorkonferenz_Typ>praeth</Tumorkonferenz_Typ>
|
||||||
|
</Tumorkonferenz>
|
||||||
|
</Menge_Tumorkonferenz>
|
||||||
|
</Meldung>
|
||||||
|
</Menge_Meldung>
|
||||||
|
</Patient>
|
||||||
|
<Patient>
|
||||||
|
<Patienten_Stammdaten Patient_ID="20004321">
|
||||||
|
<KrankenversichertenNr>E123456789</KrankenversichertenNr>
|
||||||
|
<KrankenkassenNr>123456789</KrankenkassenNr>
|
||||||
|
<Patienten_Nachname>Tester</Patienten_Nachname>
|
||||||
|
<Patienten_Titel></Patienten_Titel>
|
||||||
|
<Patienten_Vornamen>Patricia</Patienten_Vornamen>
|
||||||
|
<Patienten_Geburtsname>Tester</Patienten_Geburtsname>
|
||||||
|
<Patienten_Geschlecht>W</Patienten_Geschlecht>
|
||||||
|
<Patienten_Geburtsdatum>01.01.1980</Patienten_Geburtsdatum>
|
||||||
|
<Menge_Adresse>
|
||||||
|
<Adresse>
|
||||||
|
<Patienten_Strasse>Testweg</Patienten_Strasse>
|
||||||
|
<Patienten_Hausnummer>1</Patienten_Hausnummer>
|
||||||
|
<Patienten_Land>DE</Patienten_Land>
|
||||||
|
<Patienten_PLZ>01234</Patienten_PLZ>
|
||||||
|
<Patienten_Ort>Musterhausen</Patienten_Ort>
|
||||||
|
</Adresse>
|
||||||
|
</Menge_Adresse>
|
||||||
|
</Patienten_Stammdaten>
|
||||||
|
<Menge_Meldung>
|
||||||
|
<Meldung Meldung_ID="001A5D50-TEST" Melder_ID="TEST">
|
||||||
|
<Meldedatum>11.06.2024</Meldedatum>
|
||||||
|
<Meldebegruendung>I</Meldebegruendung>
|
||||||
|
<Meldeanlass>statusaenderung</Meldeanlass>
|
||||||
|
<Tumorzuordnung Tumor_ID="1">
|
||||||
|
<Primaertumor_ICD_Code>C17.2</Primaertumor_ICD_Code>
|
||||||
|
<Primaertumor_ICD_Version>10 2015 GM</Primaertumor_ICD_Version>
|
||||||
|
<Diagnosedatum>01.01.2024</Diagnosedatum>
|
||||||
|
<Seitenlokalisation>T</Seitenlokalisation>
|
||||||
|
</Tumorzuordnung>
|
||||||
|
<Menge_Tumorkonferenz>
|
||||||
|
<Tumorkonferenz Tumorkonferenz_ID="1234568">
|
||||||
|
<Tumorkonferenz_Datum>10.01.2024</Tumorkonferenz_Datum>
|
||||||
|
<Tumorkonferenz_Typ>praeth</Tumorkonferenz_Typ>
|
||||||
|
</Tumorkonferenz>
|
||||||
|
</Menge_Tumorkonferenz>
|
||||||
|
</Meldung>
|
||||||
|
</Menge_Meldung>
|
||||||
|
</Patient>
|
||||||
|
</Menge_Patient>
|
||||||
|
</ADT_GEKID>
|
Loading…
x
Reference in New Issue
Block a user