mirror of
https://github.com/dnpm-dip/mv64e-mtb-dto-rs.git
synced 2025-07-04 03:42:54 +00:00
Initial commit
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.idea/
|
||||||
|
/target
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
Cargo.lock
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "mv64e-mtb-dto"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
license = "MIT"
|
||||||
|
authors = ["Paul-Christian Volkmer <code@pcvolkmer.de>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Paul-Christian Volkmer
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# DNPM:DIP MTB Data-Transfer-Objects for Rust
|
||||||
|
|
||||||
|
Serialization and deserialization of DNPM:DIP MTB DTOs for the Rust programming language.
|
||||||
|
|
||||||
|
This crate provides DNPM:DIP data model for use with "Modellvorhaben gem. §64e SGB V"
|
107
src/lib.rs
Normal file
107
src/lib.rs
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
//! This crate provides structs to serialize and deserialize DNPM:DIP MTB DTOs.
|
||||||
|
//! The base struct is `Mtb`.
|
||||||
|
|
||||||
|
#![allow(clippy::needless_doctest_main)]
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
pub use crate::mtb::*;
|
||||||
|
|
||||||
|
mod mtb;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SerdeError(String);
|
||||||
|
|
||||||
|
impl Display for SerdeError {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "MtbFile Serde Error: {}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for SerdeError {}
|
||||||
|
|
||||||
|
impl FromStr for Mtb {
|
||||||
|
type Err = SerdeError;
|
||||||
|
|
||||||
|
/// Deserialize an instance of `MtbFile` from a string of JSON text.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use mv64e_mtb_dto::Mtb;
|
||||||
|
/// use std::str::FromStr;
|
||||||
|
///
|
||||||
|
/// fn main() {
|
||||||
|
/// const MTB_JSON: &str = include_str!("../tests/fake_MTBFile.json");
|
||||||
|
///
|
||||||
|
/// let mtb_file = Mtb::from_str(MTB_JSON).unwrap();
|
||||||
|
/// println!("{:#?}", mtb_file);
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// If the conversion fails, an `SerdeError` will be returned.
|
||||||
|
fn from_str(value: &str) -> Result<Mtb, SerdeError> {
|
||||||
|
serde_json::from_str(value).map_err(|err| SerdeError(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Mtb {
|
||||||
|
/// Creates "dummy" Mtb with consent status `REJECTED`.
|
||||||
|
/// The created MtbFile does not contain all information, just enough to contain the
|
||||||
|
/// information, that the patient with given ID has rejected the consent.
|
||||||
|
pub fn new_with_consent_rejected(patient_id: &str) -> Mtb {
|
||||||
|
Mtb {
|
||||||
|
care_plans: None,
|
||||||
|
claim_responses: None,
|
||||||
|
claims: None,
|
||||||
|
consent: Consent {
|
||||||
|
id: None,
|
||||||
|
patient: None,
|
||||||
|
status: None,
|
||||||
|
},
|
||||||
|
diagnoses: None,
|
||||||
|
ecog_status: None,
|
||||||
|
episode: None,
|
||||||
|
genetic_counselling_requests: None,
|
||||||
|
histology_reports: None,
|
||||||
|
last_guideline_therapies: None,
|
||||||
|
molecular_therapies: None,
|
||||||
|
ngs_reports: None,
|
||||||
|
patient: MtbPatient {
|
||||||
|
address: None,
|
||||||
|
birth_date: String::new(),
|
||||||
|
date_of_death: None,
|
||||||
|
gender: CodingGender {
|
||||||
|
code: Gender::Male,
|
||||||
|
display: None,
|
||||||
|
system: None,
|
||||||
|
version: None,
|
||||||
|
},
|
||||||
|
id: patient_id.to_string(),
|
||||||
|
insurance: None,
|
||||||
|
},
|
||||||
|
previous_guideline_therapies: None,
|
||||||
|
recommendations: None,
|
||||||
|
responses: None,
|
||||||
|
specimens: None,
|
||||||
|
study_inclusion_requests: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
const MTB_JSON: &str = include_str!("../tests/mv64e-mtb-fake-patient.json");
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_deserialize_json_string() {
|
||||||
|
let mtbfile = Mtb::from_str(MTB_JSON);
|
||||||
|
assert!(mtbfile.is_ok())
|
||||||
|
}
|
||||||
|
}
|
1358
src/mtb.rs
Normal file
1358
src/mtb.rs
Normal file
File diff suppressed because it is too large
Load Diff
1531
tests/mv64e-mtb-fake-patient.json
Normal file
1531
tests/mv64e-mtb-fake-patient.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user