Skip to content

Commit 071cb66

Browse files
authored
Merge pull request #21 from MyDigiTwinNL/fix/removing_assertion_fu_diab_undefined_date
Generating FHIR-Diabetes with undefined onsetdate, instead of assertion failing when the date cannot be calculated
2 parents faeedd3 + 5a8a931 commit 071cb66

File tree

5 files changed

+86
-36
lines changed

5 files changed

+86
-36
lines changed

fhirvalidation/sampleinputs/input-p675432-hf-followup-missing-date.json renamed to fhirvalidation/sampleinputs/input-p675432-hf-diab-followup-missing-date.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
"stroke_followup_adu_q_1":{"2a":"2","3a":"2","3b":"2"},
2525

2626

27-
"diabetes_presence_adu_q_1": {"1a":"1"},
28-
"diabetes_startage_adu_q_1": {"1a":"28"},
29-
"diabetes_followup_adu_q_1": {"1b":"2","1c":"2","2a":"2","3a":"2","3b":"2"},
27+
"diabetes_presence_adu_q_1": {"1a":"2"},
28+
"diabetes_startage_adu_q_1": {"1a":""},
29+
"diabetes_followup_adu_q_1": {"1b":"2","1c":"2","2a":"2","3a":"1","3b":"2"},
3030
"diabetes_type_adu_q_1": {"1a":"2"},
3131
"diabetes_type_adu_q_1_a": {"1a":""},
3232
"t1d_followup_adu_q_1": {"2a":"2","3a":"2","3b":"2"},
33-
"t2d_followup_adu_q_1": {"2a":"2","3a":"2","3b":"2"},
33+
"t2d_followup_adu_q_1": {"2a":"2","3a":"1","3b":"2"},
3434

3535
"bp_entrytype_all_m_1": {"1a":"2","2a":"2"},
3636
"bp_bandsize_all_m_1": {"1a":"1","2a":"1","3a":"1"},

src/__tests__/diabetes.test.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,38 @@ test('diabetes clinical status, when reported positive in a follow-up, diabetes
5353

5454

5555

56+
test('assertion test: diabetes clinical status, when reported positive in a follow-up, but no diabetes type is defined', () => {
57+
58+
const input = {
59+
"diabetes_presence_adu_q_1": { "1a": "2" },
60+
"diabetes_followup_adu_q_1": { "1b": "2", "1c": "2", "2a": "2", "3a": "1", "3b": "2" },
61+
"diabetes_startage_adu_q_1": { "1a": "" },
62+
"diabetes_type_adu_q_1": { "1a": "2" },
63+
"diabetes_type_adu_q_1_a": { "1a": "" },
64+
"t1d_followup_adu_q_1": { "2a": "2", "3a": "2", "3b": "2" },
65+
"t2d_followup_adu_q_1": { "2a": "2", "3a": "2", "3b": "2" },
66+
"date": {"1a":"1992-5","1b":"1995-5","1c":"1997-5",/*date1*/"2a":"2001-5",/*date2*/"3a":"2003-5","3b":"2005-5"},
67+
"age": { "1a": "22" },
68+
}
69+
70+
try{
71+
InputSingleton.getInstance().setInput(input);
72+
expect(diabetesmf.clinicalStatus()).toBe(clinicalStatusSNOMEDCodeList.active);
73+
expect(diabetesmf.isPresent()).toBe(true);
74+
expect(diabetesmf.code()).toBe(conditionsSNOMEDCodeList.diabetes_mellitus_type_1);
75+
expect(diabetesmf.onsetDateTime()).toBe("2002-05");
76+
//execution shouldn't reach this point
77+
throw new Error('Transformation should have failed with an UnexpectedInputException');
78+
}
79+
catch(error){
80+
if (!(error instanceof UnexpectedInputException)) throw new Error('Transformation should have failed with an UnexpectedInputException');
81+
}
82+
83+
});
84+
85+
86+
87+
5688
test('diabetes clinical status, when reported positive in a follow-up after multiple skipped assessments, diabetes type 1', () => {
5789

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

76108
});
77109

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

80112
const input = {
81113
"diabetes_presence_adu_q_1": { "1a": "2" },
82-
"diabetes_followup_adu_q_1": { "1b": "2", "1c": "2", "2a": "2", "3a": "", "3b": "1" },
114+
"diabetes_followup_adu_q_1": { "1b": "2", "1c": "2", "2a": "2", "3a": "1", "3b": "2" },
83115
"diabetes_startage_adu_q_1": { "1a": "" },
84116
"diabetes_type_adu_q_1": { "1a": "2" },
85117
"diabetes_type_adu_q_1_a": { "1a": "" },
@@ -89,16 +121,13 @@ test('diabetes clinical status, with inconsistencies, missing date on the assess
89121
"age": { "1a": "22" },
90122
}
91123

92-
try{
93-
InputSingleton.getInstance().setInput(input);
94-
expect(diabetesmf.clinicalStatus()).toBe(clinicalStatusSNOMEDCodeList.active);
95-
expect(diabetesmf.isPresent()).toBe(true);
96-
expect(diabetesmf.code()).toBe(conditionsSNOMEDCodeList.diabetes_mellitus_type_1);
97-
expect(diabetesmf.onsetDateTime()).toBe("2003-05");
98-
}
99-
catch(error){
100-
if (!(error instanceof UnexpectedInputException)) fail('Expected exception')
101-
}
124+
125+
InputSingleton.getInstance().setInput(input);
126+
expect(diabetesmf.clinicalStatus()).toBe(clinicalStatusSNOMEDCodeList.active);
127+
expect(diabetesmf.isPresent()).toBe(true);
128+
expect(diabetesmf.code()).toBe(conditionsSNOMEDCodeList.diabetes_mellitus_type_1);
129+
expect(diabetesmf.onsetDateTime()).toBe(undefined);
130+
102131

103132

104133
});

src/lifelines/Diabetes.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,23 @@ const _clinicalStatus = moize((diab_presence:string|undefined,followup_assessmen
9090
* ------------------------------------------------------------------
9191
*
9292
* @precondition
93-
* - date is never a missing value (is a default variable)
9493
* - the problem is 'active' (see clinicalStatus function)
9594
* - if there is a diabetes report on a follow-up 'diabetes_followup_adu_q_1', there should be a 'yes' value
9695
* in either t2d_followup_adu_q_1 or t2d_followup_adu_q_1 (diabetes type)
9796
*
9897
*
9998
* @pairingrule
100-
* 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
101-
* (undefined if diabetes_startage_adu_q_1 has a missing value)
99+
* if diabetes_presence_adu_q_1 = yes in 1A =>
100+
* if start_age was reported, approximate year of the event given start_age reported (diabetes_startage_adu_q_1)
101+
* and the year of the year of the assessment.
102+
* else
103+
* undefined onset date
102104
* else
103-
* if there is a 'yes' in any diabetes_followup_adu_q_1 => mean date between the date of the assessment
104-
* where diabetes_followup_adu_q_1 = yes, and the date of the preceding one.
105+
* if there is a 'yes' in any diabetes_followup_adu_q_1 =>
106+
* If the date of the assessment where diabetes_followup_adu_q_1 = yes is available =>
107+
* mean date between that particular date (when diabetes_followup_adu_q_1 = yes), and the date of the preceding assessment.
108+
* Else
109+
* return undefined onset date
105110
* else
106111
* error/precondition violated ('diabetes' is not 'active' if the execution reached this point)
107112
*
@@ -135,19 +140,29 @@ export const onsetDateTime = ():string|undefined => {
135140
return lifelinesDateToISO(lifelinesMeanDate(date1,date2))
136141
}
137142
else{
138-
throw Error("Unexpected input (precondition violated): no 'yes' values in neither t2d_followup_adu_q_1 nor t2d_followup_adu_q_1")
143+
return undefined;
139144
}
140145

141146

142147
}
143148

144149
}
145150

146-
/**
151+
152+
/*
153+
*
154+
* Helper function for 'onsetDateTime'
147155
*
148156
* @param diabFollowUp
149-
* @returns
150-
* @precondition there is always a date on the assessment prior to the one where diabetes_followup_adu_q_1 was 'yes'
157+
*
158+
* @return
159+
* If the date of the assessment where diabetes_followup_adu_q_1 = yes is available =>
160+
* mean date between that particular date (when diabetes_followup_adu_q_1 = yes), and the date of the preceding assessment.
161+
* Else
162+
* return undefined date
163+
*
164+
* @precondition: there is at least one 'yes'/1 on diabetes_followup_adu_q_1
165+
* @precondition there is always a date on one of the assessment prior to the one where diabetes_followup_adu_q_1 was 'yes'
151166
*
152167
*/
153168
function findDatesBetweenDiabetesPresenceReport(): [string,string]|undefined{
@@ -160,18 +175,23 @@ function findDatesBetweenDiabetesPresenceReport(): [string,string]|undefined{
160175
assertIsDefined(diabetesRepWave,`A 'yes' value on diabetes_followup_adu_q_1 was expected`)
161176

162177
const diabetesRepWaveDate = inputValue("date",diabetesRepWave)
163-
assertIsDefined(diabetesRepWaveDate,`A non-null date is expected in the assessment where diabetes_followup_adu_q_1 is reported`)
178+
if (diabetesRepWaveDate === undefined){
179+
return undefined
180+
}
181+
else{
182+
//find the previous non-undefined assessment date
183+
const assessmentDates:variableAssessments = inputValues('date')
184+
const waves = ['1a','1b','1c','2a','3a','3b'];
185+
const previousWaves = waves.slice(0,waves.indexOf(diabetesRepWave))
186+
const previousAssessmentWave = previousWaves.reverse().find((pwave)=>assessmentDates[pwave]!==undefined)
187+
188+
assertIsDefined(previousAssessmentWave,`Assessment (with a defined date) expected to exist previous to the one where diabetes_followup_adu_q_1 is reported`)
189+
190+
const previousAssessmentDate:string = assessmentDates[previousAssessmentWave]!;
191+
return [previousAssessmentDate,diabetesRepWaveDate]
192+
}
164193

165-
//find the previous non-undefined assessment date
166-
const assessmentDates:variableAssessments = inputValues('date')
167-
const waves = ['1a','1b','1c','2a','3a','3b'];
168-
const previousWaves = waves.slice(0,waves.indexOf(diabetesRepWave))
169-
const previousAssessmentWave = previousWaves.reverse().find((pwave)=>assessmentDates[pwave]!==undefined)
170-
171-
assertIsDefined(previousAssessmentWave,`Assessment (with a defined date) expected to exist previous to the one where diabetes_followup_adu_q_1 is reported`)
172194

173-
const previousAssessmentDate:string = assessmentDates[previousAssessmentWave]!;
174-
return [previousAssessmentDate,diabetesRepWaveDate]
175195

176196

177197
}

src/lifelines/HeartFailure.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const _clinicalStatus = moize((heartfailure_presence:string|undefined,followup_a
154154
*
155155
*
156156
* @precondition: there is at least one 'yes'/1 on heartfailure_followup_adu_q_1
157+
* @precondition there is always a date on one of the assessment prior to the one where diabetes_followup_adu_q_1 was 'yes'
157158
*
158159
* If the date of the assessment where heartfailure_followup_adu_q_1 = yes is available =>
159160
* mean date between that particular date (when heartfailure_followup_adu_q_1 = yes), and the date of the preceding assessment.

src/viewerserver/serversettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ export const targets:MappingTarget[] = [
1919
//{ "module": './lifelines/HaemoglobinConcentration', "template": '../../zib-2017-mappings/generic/LabTestResult_Diagnostic_Report.jsonata' },
2020
//{ "module": './lifelines/HaemoglobinConcentration', "template": '../../zib-2017-mappings/generic/LabTestResult_Observation.jsonata' },
2121
//{ "module": './lifelines/HaemoglobinConcentration', "template": '../../zib-2017-mappings/generic/LabTestResult_Specimen.jsonata' },
22-
{ "template": '../../zib-2017-mappings/generic/Condition.jsonata', "module": './lifelines/HeartFailure' },
22+
{ "template": '../../zib-2017-mappings/Diabetes.jsonata', "module": './lifelines/Diabetes' },
2323

2424
]

0 commit comments

Comments
 (0)