Skip to content

Commit

Permalink
Merge pull request #21 from MyDigiTwinNL/fix/removing_assertion_fu_di…
Browse files Browse the repository at this point in the history
…ab_undefined_date

Generating FHIR-Diabetes with undefined onsetdate, instead of assertion failing when the date cannot be calculated
  • Loading branch information
hcadavid authored Sep 17, 2024
2 parents faeedd3 + 5a8a931 commit 071cb66
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
"stroke_followup_adu_q_1":{"2a":"2","3a":"2","3b":"2"},


"diabetes_presence_adu_q_1": {"1a":"1"},
"diabetes_startage_adu_q_1": {"1a":"28"},
"diabetes_followup_adu_q_1": {"1b":"2","1c":"2","2a":"2","3a":"2","3b":"2"},
"diabetes_presence_adu_q_1": {"1a":"2"},
"diabetes_startage_adu_q_1": {"1a":""},
"diabetes_followup_adu_q_1": {"1b":"2","1c":"2","2a":"2","3a":"1","3b":"2"},
"diabetes_type_adu_q_1": {"1a":"2"},
"diabetes_type_adu_q_1_a": {"1a":""},
"t1d_followup_adu_q_1": {"2a":"2","3a":"2","3b":"2"},
"t2d_followup_adu_q_1": {"2a":"2","3a":"2","3b":"2"},
"t2d_followup_adu_q_1": {"2a":"2","3a":"1","3b":"2"},

"bp_entrytype_all_m_1": {"1a":"2","2a":"2"},
"bp_bandsize_all_m_1": {"1a":"1","2a":"1","3a":"1"},
Expand Down
53 changes: 41 additions & 12 deletions src/__tests__/diabetes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,38 @@ test('diabetes clinical status, when reported positive in a follow-up, diabetes



test('assertion test: diabetes clinical status, when reported positive in a follow-up, but no diabetes type is defined', () => {

const input = {
"diabetes_presence_adu_q_1": { "1a": "2" },
"diabetes_followup_adu_q_1": { "1b": "2", "1c": "2", "2a": "2", "3a": "1", "3b": "2" },
"diabetes_startage_adu_q_1": { "1a": "" },
"diabetes_type_adu_q_1": { "1a": "2" },
"diabetes_type_adu_q_1_a": { "1a": "" },
"t1d_followup_adu_q_1": { "2a": "2", "3a": "2", "3b": "2" },
"t2d_followup_adu_q_1": { "2a": "2", "3a": "2", "3b": "2" },
"date": {"1a":"1992-5","1b":"1995-5","1c":"1997-5",/*date1*/"2a":"2001-5",/*date2*/"3a":"2003-5","3b":"2005-5"},
"age": { "1a": "22" },
}

try{
InputSingleton.getInstance().setInput(input);
expect(diabetesmf.clinicalStatus()).toBe(clinicalStatusSNOMEDCodeList.active);
expect(diabetesmf.isPresent()).toBe(true);
expect(diabetesmf.code()).toBe(conditionsSNOMEDCodeList.diabetes_mellitus_type_1);
expect(diabetesmf.onsetDateTime()).toBe("2002-05");
//execution shouldn't reach this point
throw new Error('Transformation should have failed with an UnexpectedInputException');
}
catch(error){
if (!(error instanceof UnexpectedInputException)) throw new Error('Transformation should have failed with an UnexpectedInputException');
}

});




test('diabetes clinical status, when reported positive in a follow-up after multiple skipped assessments, diabetes type 1', () => {

const input = {
Expand All @@ -75,11 +107,11 @@ test('diabetes clinical status, when reported positive in a follow-up after mult

});

test('diabetes clinical status, with inconsistencies, missing date on the assessment where diabetes is reported', () => {
test('diabetes clinical status (T1D) reported on a follow up, with missing date on the assessment where was reported', () => {

const input = {
"diabetes_presence_adu_q_1": { "1a": "2" },
"diabetes_followup_adu_q_1": { "1b": "2", "1c": "2", "2a": "2", "3a": "", "3b": "1" },
"diabetes_followup_adu_q_1": { "1b": "2", "1c": "2", "2a": "2", "3a": "1", "3b": "2" },
"diabetes_startage_adu_q_1": { "1a": "" },
"diabetes_type_adu_q_1": { "1a": "2" },
"diabetes_type_adu_q_1_a": { "1a": "" },
Expand All @@ -89,16 +121,13 @@ test('diabetes clinical status, with inconsistencies, missing date on the assess
"age": { "1a": "22" },
}

try{
InputSingleton.getInstance().setInput(input);
expect(diabetesmf.clinicalStatus()).toBe(clinicalStatusSNOMEDCodeList.active);
expect(diabetesmf.isPresent()).toBe(true);
expect(diabetesmf.code()).toBe(conditionsSNOMEDCodeList.diabetes_mellitus_type_1);
expect(diabetesmf.onsetDateTime()).toBe("2003-05");
}
catch(error){
if (!(error instanceof UnexpectedInputException)) fail('Expected exception')
}

InputSingleton.getInstance().setInput(input);
expect(diabetesmf.clinicalStatus()).toBe(clinicalStatusSNOMEDCodeList.active);
expect(diabetesmf.isPresent()).toBe(true);
expect(diabetesmf.code()).toBe(conditionsSNOMEDCodeList.diabetes_mellitus_type_1);
expect(diabetesmf.onsetDateTime()).toBe(undefined);



});
Expand Down
58 changes: 39 additions & 19 deletions src/lifelines/Diabetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,23 @@ const _clinicalStatus = moize((diab_presence:string|undefined,followup_assessmen
* ------------------------------------------------------------------
*
* @precondition
* - date is never a missing value (is a default variable)
* - the problem is 'active' (see clinicalStatus function)
* - if there is a diabetes report on a follow-up 'diabetes_followup_adu_q_1', there should be a 'yes' value
* in either t2d_followup_adu_q_1 or t2d_followup_adu_q_1 (diabetes type)
*
*
* @pairingrule
* if diabetes_presence_adu_q_1 = yes in 1A => approximate year on which the participant given the age reported by diabetes_startage_adu_q_1
* (undefined if diabetes_startage_adu_q_1 has a missing value)
* if diabetes_presence_adu_q_1 = yes in 1A =>
* if start_age was reported, approximate year of the event given start_age reported (diabetes_startage_adu_q_1)
* and the year of the year of the assessment.
* else
* undefined onset date
* else
* if there is a 'yes' in any diabetes_followup_adu_q_1 => mean date between the date of the assessment
* where diabetes_followup_adu_q_1 = yes, and the date of the preceding one.
* if there is a 'yes' in any diabetes_followup_adu_q_1 =>
* If the date of the assessment where diabetes_followup_adu_q_1 = yes is available =>
* mean date between that particular date (when diabetes_followup_adu_q_1 = yes), and the date of the preceding assessment.
* Else
* return undefined onset date
* else
* error/precondition violated ('diabetes' is not 'active' if the execution reached this point)
*
Expand Down Expand Up @@ -135,19 +140,29 @@ export const onsetDateTime = ():string|undefined => {
return lifelinesDateToISO(lifelinesMeanDate(date1,date2))
}
else{
throw Error("Unexpected input (precondition violated): no 'yes' values in neither t2d_followup_adu_q_1 nor t2d_followup_adu_q_1")
return undefined;
}


}

}

/**

/*
*
* Helper function for 'onsetDateTime'
*
* @param diabFollowUp
* @returns
* @precondition there is always a date on the assessment prior to the one where diabetes_followup_adu_q_1 was 'yes'
*
* @return
* If the date of the assessment where diabetes_followup_adu_q_1 = yes is available =>
* mean date between that particular date (when diabetes_followup_adu_q_1 = yes), and the date of the preceding assessment.
* Else
* return undefined date
*
* @precondition: there is at least one 'yes'/1 on diabetes_followup_adu_q_1
* @precondition there is always a date on one of the assessment prior to the one where diabetes_followup_adu_q_1 was 'yes'
*
*/
function findDatesBetweenDiabetesPresenceReport(): [string,string]|undefined{
Expand All @@ -160,18 +175,23 @@ function findDatesBetweenDiabetesPresenceReport(): [string,string]|undefined{
assertIsDefined(diabetesRepWave,`A 'yes' value on diabetes_followup_adu_q_1 was expected`)

const diabetesRepWaveDate = inputValue("date",diabetesRepWave)
assertIsDefined(diabetesRepWaveDate,`A non-null date is expected in the assessment where diabetes_followup_adu_q_1 is reported`)
if (diabetesRepWaveDate === undefined){
return undefined
}
else{
//find the previous non-undefined assessment date
const assessmentDates:variableAssessments = inputValues('date')
const waves = ['1a','1b','1c','2a','3a','3b'];
const previousWaves = waves.slice(0,waves.indexOf(diabetesRepWave))
const previousAssessmentWave = previousWaves.reverse().find((pwave)=>assessmentDates[pwave]!==undefined)

assertIsDefined(previousAssessmentWave,`Assessment (with a defined date) expected to exist previous to the one where diabetes_followup_adu_q_1 is reported`)

const previousAssessmentDate:string = assessmentDates[previousAssessmentWave]!;
return [previousAssessmentDate,diabetesRepWaveDate]
}

//find the previous non-undefined assessment date
const assessmentDates:variableAssessments = inputValues('date')
const waves = ['1a','1b','1c','2a','3a','3b'];
const previousWaves = waves.slice(0,waves.indexOf(diabetesRepWave))
const previousAssessmentWave = previousWaves.reverse().find((pwave)=>assessmentDates[pwave]!==undefined)

assertIsDefined(previousAssessmentWave,`Assessment (with a defined date) expected to exist previous to the one where diabetes_followup_adu_q_1 is reported`)

const previousAssessmentDate:string = assessmentDates[previousAssessmentWave]!;
return [previousAssessmentDate,diabetesRepWaveDate]


}
Expand Down
1 change: 1 addition & 0 deletions src/lifelines/HeartFailure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const _clinicalStatus = moize((heartfailure_presence:string|undefined,followup_a
*
*
* @precondition: there is at least one 'yes'/1 on heartfailure_followup_adu_q_1
* @precondition there is always a date on one of the assessment prior to the one where diabetes_followup_adu_q_1 was 'yes'
*
* If the date of the assessment where heartfailure_followup_adu_q_1 = yes is available =>
* mean date between that particular date (when heartfailure_followup_adu_q_1 = yes), and the date of the preceding assessment.
Expand Down
2 changes: 1 addition & 1 deletion src/viewerserver/serversettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export const targets:MappingTarget[] = [
//{ "module": './lifelines/HaemoglobinConcentration', "template": '../../zib-2017-mappings/generic/LabTestResult_Diagnostic_Report.jsonata' },
//{ "module": './lifelines/HaemoglobinConcentration', "template": '../../zib-2017-mappings/generic/LabTestResult_Observation.jsonata' },
//{ "module": './lifelines/HaemoglobinConcentration', "template": '../../zib-2017-mappings/generic/LabTestResult_Specimen.jsonata' },
{ "template": '../../zib-2017-mappings/generic/Condition.jsonata', "module": './lifelines/HeartFailure' },
{ "template": '../../zib-2017-mappings/Diabetes.jsonata', "module": './lifelines/Diabetes' },

]

0 comments on commit 071cb66

Please sign in to comment.