Skip to content

Commit

Permalink
reversing TobaccoUse changes, participants with undefined assessment …
Browse files Browse the repository at this point in the history
…date still won't be included
  • Loading branch information
hcadavid committed Sep 23, 2024
1 parent 171ed2b commit eaad43a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 173 deletions.

This file was deleted.

52 changes: 0 additions & 52 deletions src/__tests__/tobaccouse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,58 +77,6 @@ test('participant started smoking before the baseline assessment and was still a
});




test('participant started smoking before the baseline assessment, but the date of his baseline assessment is unknown', () => {

const input = {
"current_smoker_adu_c_2": { "1a": "1", "1b": "1", "1c": "1", "2a": "1", "2b": "1", "3a": "1" },
"smoking_startage_adu_c_2": { "1a": "20", "1b": "20", "1c": "20", "2a": "20", "2b": "20", "3a": "20" },
"ex_smoker_adu_c_2": { "1a": "0", "1b": "0", "1c": "0", "2a": "0", "2b": "0", "3a": "0" },
"smoking_endage_adu_c_2": { "1a": "", "1b": "", "1c": "", "2a": "", "2b": "", "3a": "" },
"ever_smoker_adu_c_2": { "1a": "1", "1b": "1", "1c": "1", "2a": "1", "2b": "1", "3a": "1" },
"total_frequency_adu_c_1": { "1a": "5", "1b": "5", "1c": "5", "2a": "5", "2b": "5", "3a": "5" },
"packyears_cumulative_adu_c_2": { "1a": "200", "1b": "200", "1c": "200", "2a": "200", "2b": "200", "3a": "200" },
"date": { "1a": "", "1b": "1995-5", "1c": "1997-5", "2a": "2001-5", "2b": "2003-5", "3a": "2005-5", "3b": "2009-5" },
"age": { "1a": "40" }
}

InputSingleton.getInstance().setInput(input);
const mappingResult = tobbacousemf.results();

expect((mappingResult[0] as TobaccoUseProperties).useStatus).toBe(tobaccoUseStatusSNOMEDCodelist.daily);
expect((mappingResult[0] as TobaccoUseProperties).smokingStartDate).toBe(undefined);

});


test('participant was an ex-smoker before the first assessment, but the date of his baseline assessment is unknown', () => {

const input = {
"current_smoker_adu_c_2": { "1a": "0", "1b": "0", "1c": "0", "2a": "0", "2b": "0", "3a": "0" },
"smoking_startage_adu_c_2": { "1a": "20", "1b": "20", "1c": "20", "2a": "20", "2b": "20", "3a": "20" },
"ex_smoker_adu_c_2": { "1a": "1", "1b": "1", "1c": "1", "2a": "1", "2b": "1", "3a": "1" },
"smoking_endage_adu_c_2": { "1a": "30", "1b": "30", "1c": "30", "2a": "30", "2b": "30", "3a": "30" },
"ever_smoker_adu_c_2": { "1a": "1", "1b": "1", "1c": "1", "2a": "1", "2b": "1", "3a": "1" },
"total_frequency_adu_c_1": { "1a": "5", "1b": "5", "1c": "5", "2a": "5", "2b": "5", "3a": "5" },
"packyears_cumulative_adu_c_2": { "1a": "200", "1b": "200", "1c": "200", "2a": "200", "2b": "200", "3a": "200" },
"date": { "1a": "", "1b": "1995-5", "1c": "1997-5", "2a": "2001-5", "2b": "2003-5", "3a": "2005-5", "3b": "2009-5" },
"age": { "1a": "40" }
}


InputSingleton.getInstance().setInput(input);
const mappingResult = tobbacousemf.results();

expect((mappingResult[0] as TobaccoUseProperties).useStatus).toBe(tobaccoUseStatusSNOMEDCodelist.ex_smoker);
expect((mappingResult[0] as TobaccoUseProperties).smokingStartDate).toBe(undefined);
expect((mappingResult[0] as TobaccoUseProperties).smokingEndDate).toBe(undefined);

});




test('participant started smoking after the baseline assessment and was still a smoker in the last assessment', () => {

const input = {
Expand Down
67 changes: 27 additions & 40 deletions src/lifelines/TobaccoUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,28 @@ const exSmoker = function(wave:string):boolean{
*
* @pairingrule
* - the approximate year the participant had the age reported in A1 baseline assessment,
* given the date such baseline assessment was performed. An 'undefined' starting date is
* given when there is no date for the baseline assessment, or when the age on the
* baseline assessment or the smoking_startage were no reported.
*
*
* given the date such baseline assessment was performed
*/
const smokingStart = (wave:string):string|undefined => {
const assessmentDate = inputValue("date","1a");

if (assessmentDate === undefined){
return undefined
}
else{
const partAge = inputValue("age","1a");
assertIsDefined(assessmentDate,'non-null date expected for assessment 1a (TobaccoUse/smokingStart)')

const smokingStartAge = inputValue("smoking_startage_adu_c_2",wave)
const partAge = inputValue("age","1a");

if (smokingStartAge!=undefined && partAge!=undefined){
const surveyDateParts = assessmentDate!.split("-");
const surveyYear= Number(surveyDateParts[0]);
const startAge = Number(smokingStartAge);
//Age is only on baseline assessment 1A
const surveyAge = Number(partAge);
return (surveyYear - surveyAge + startAge).toString()
}
else{
return undefined
}
const smokingStartAge = inputValue("smoking_startage_adu_c_2",wave)

if (smokingStartAge!=undefined && partAge!=undefined){
const surveyDateParts = assessmentDate!.split("-");
const surveyYear= Number(surveyDateParts[0]);
const startAge = Number(smokingStartAge);
//Age is only on baseline assessment 1A
const surveyAge = Number(partAge);
return (surveyYear - surveyAge + startAge).toString()
}
else{
return undefined
}

};

/**
Expand All @@ -160,26 +152,21 @@ const smokingEnd = (wave:string):string|undefined => {

const assessmentDate = inputValue("date","1a");

if (assessmentDate === undefined){
return undefined
assertIsDefined(assessmentDate,'non-null date expected for assessment 1a (TobaccoUse/smokingEnd)')

const partAge = inputValue("age","1a");
const smokingEndAge = inputValue("smoking_endage_adu_c_2",wave);

if (smokingEndAge!==undefined && partAge!==undefined){
const surveyDateParts = assessmentDate!.split("-");
const surveyYear= Number(surveyDateParts[0]);
const endAge = Number(smokingEndAge);
const surveyAge = Number(partAge);
return (surveyYear - surveyAge + endAge).toString()
}
else{
const partAge = inputValue("age","1a");
const smokingEndAge = inputValue("smoking_endage_adu_c_2",wave);

if (smokingEndAge!==undefined && partAge!==undefined){
const surveyDateParts = assessmentDate!.split("-");
const surveyYear= Number(surveyDateParts[0]);
const endAge = Number(smokingEndAge);
const surveyAge = Number(partAge);
return (surveyYear - surveyAge + endAge).toString()
}
else{
return undefined
}

return undefined
}


};

Expand Down

0 comments on commit eaad43a

Please sign in to comment.