Skip to content

Commit

Permalink
Merge pull request #86 from samply/develop
Browse files Browse the repository at this point in the history
Helpful error message when deserialization in obfuscation method fails
  • Loading branch information
enola-dkfz authored Dec 8, 2023
2 parents 5113864 + d455cfa commit 719c6e4
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 3 deletions.
117 changes: 117 additions & 0 deletions resources/test/measure_report_exliquid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"date": "2023-12-08T14:37:25.66727986Z",
"group": [
{
"stratifier": [
{
"code": [
{
"coding": [
{
"system": "https://dktk.dkfz.de/fhir/CodeSystem/exliquid-stratifier",
"code": "diagnosis"
}
]
}
]
}
],
"population": [
{
"subjectResults": {
"reference": "List/DDCJ3SRU5DPLO4N3"
},
"count": 0,
"code": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/measure-population",
"code": "initial-population"
}
]
}
}
],
"code": {
"coding": [
{
"system": "https://dktk.dkfz.de/fhir/CodeSystem/exliquid-measure-group",
"code": "patient"
}
]
}
},
{
"stratifier": [
{
"code": [
{
"coding": [
{
"system": "https://dktk.dkfz.de/fhir/CodeSystem/exliquid-stratifier",
"code": "sample-diagnosis"
}
]
},
{
"coding": [
{
"system": "https://dktk.dkfz.de/fhir/CodeSystem/exliquid-stratifier",
"code": "sample-type"
}
]
}
]
}
],
"population": [
{
"subjectResults": {
"reference": "List/DDCJ3SRU5DPLO4N4"
},
"count": 0,
"code": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/measure-population",
"code": "initial-population"
}
]
}
}
],
"code": {
"coding": [
{
"system": "https://dktk.dkfz.de/fhir/CodeSystem/exliquid-measure-group",
"code": "specimen"
}
]
}
}
],
"meta": {
"versionId": "615",
"lastUpdated": "2023-12-08T14:37:25.775Z"
},
"type": "subject-list",
"resourceType": "MeasureReport",
"measure": "urn:uuid:7ff542ad-69e4-48ed-a2d3-2efafb609f61",
"extension": [
{
"url": "https://samply.github.io/blaze/fhir/StructureDefinition/eval-duration",
"valueQuantity": {
"value": 0.027764815,
"unit": "s",
"system": "http://unitsofmeasure.org",
"code": "s"
}
}
],
"status": "complete",
"id": "DDCJ3SRWUBLWIFTI",
"period": {
"start": "2000",
"end": "2030"
}
}
35 changes: 32 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn obfuscate_counts_mr(
_ => ObfuscateBelow10Mode::Obfuscate,
};
let mut measure_report: MeasureReport = serde_json::from_str(&json_str)
.map_err(|e| FocusError::DeserializationError(e.to_string()))?;
.map_err(|e| FocusError::DeserializationError(format!(r#"{}. Is obfuscation turned on when it shouldn't be? Is the metadata in the task formatted correctly, like this {{"project": "name"}}? Are there any other projects stated in the projects_no_obfuscation parameter in the bridgehead?"#, e)))?;
for g in &mut measure_report.group {
match &g.code.text[..] {
"patients" => {
Expand Down Expand Up @@ -346,8 +346,11 @@ mod test {
use super::*;
use serde_json::json;

const EXAMPLE_MEASURE_REPORT_BBMRI: &str = include_str!("../resources/measure_report_bbmri.json");
const EXAMPLE_MEASURE_REPORT_BBMRI: &str =
include_str!("../resources/measure_report_bbmri.json");
const EXAMPLE_MEASURE_REPORT_DKTK: &str = include_str!("../resources/measure_report_dktk.json");
const EXAMPLE_MEASURE_REPORT_EXLIQUID: &str =
include_str!("../resources/test/measure_report_exliquid.json");

const DELTA_PATIENT: f64 = 1.;
const DELTA_SPECIMEN: f64 = 20.;
Expand Down Expand Up @@ -482,7 +485,8 @@ mod test {
assert_eq!(replace_cql(decoded_library), expected_result);

let decoded_library = "EXLIQUID_STRAT_W_ALIQUOTS";
let expected_result = "define InInitialPopulation: exists ExliquidSpecimenWithAliquot and \n\n";
let expected_result =
"define InInitialPopulation: exists ExliquidSpecimenWithAliquot and \n\n";

assert_eq!(replace_cql(decoded_library), expected_result);

Expand Down Expand Up @@ -587,4 +591,29 @@ mod test {
.unwrap();
assert_eq!(obfuscated_json, obfuscated_json_2);
}

#[test]
fn test_obfuscate_counts_bad_measure() {
let mut obf_cache = ObfCache {
cache: HashMap::new(),
};
let obfuscated_json = obfuscate_counts_mr(
EXAMPLE_MEASURE_REPORT_EXLIQUID,
&mut obf_cache,
false,
1,
DELTA_PATIENT,
DELTA_SPECIMEN,
DELTA_DIAGNOSIS,
DELTA_PROCEDURES,
DELTA_MEDICATION_STATEMENTS,
EPSILON,
ROUNDING_STEP,
);

assert_eq!(
obfuscated_json.unwrap_err().to_string(),
r#"Deserialization error: missing field `text` at line 42 column 13. Is obfuscation turned on when it shouldn't be? Is the metadata in the task formatted correctly, like this {"project": "name"}? Are there any other projects stated in the projects_no_obfuscation parameter in the bridgehead?"#
);
}
}

0 comments on commit 719c6e4

Please sign in to comment.