Skip to content

Commit

Permalink
Merge pull request #383 from icgc-argo/358_ltf
Browse files Browse the repository at this point in the history
Added optional field in Donor schema for lost to follow up
  • Loading branch information
hknahal authored Sep 22, 2023
2 parents e85698d + 02c270e commit 57b796b
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
44 changes: 44 additions & 0 deletions references/validationFunctions/donor/lost_to_followup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023 The Ontario Institute for Cancer Research. All rights reserved
*
* This program and the accompanying materials are made available under the terms of the GNU Affero General Public License v3.0.
* You should have received a copy of the GNU Affero General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/

/**
* The lost_to_followup_after_clinical_event_id field should only be submitted if vital_status is Alive. It should not be allowed to be submitted if vital_status is Deceased.
*/
const validation = () =>
(function validate(inputs) {
const {$row, $name, $field} = inputs;
let result = {valid: true, message: "Ok"};
const currField = typeof($field) === 'string' ? $field.trim().toLowerCase() : $field;

/* checks for a string just consisting of whitespace */
const checkforEmpty = (entry) => {return /^\s+$/g.test(decodeURI(entry).replace(/^"(.*)"$/, '$1'))};

if (currField != null && !(checkforEmpty(currField))) {
const vitalStatus = $row.vital_status.trim().toLowerCase();

if (vitalStatus === "deceased") {
result = {valid: false, message: `${$name} cannot be submitted if the donor's vital_status is deceased.`}
}
}
return result;
});


module.exports = validation;
13 changes: 13 additions & 0 deletions schemas/donor.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@
"units": "months",
"dependsOn": "donor.contraception_type"
}
},
{
"description": "If the donor became lost to follow up, indicate the identifier of the clinical event (eg. submitter_primary_diagnosis_id, submitter_treatment_id or submitter_follow_up_id) after which the donor became lost to follow up.",
"name": "lost_to_followup_after_clinical_event_id",
"valueType": "string",
"restrictions": {
"script": "#/script/donor/lost_to_followup"
},
"meta": {
"displayName": "Lost To Follow Up After Clinical Event",
"foreignKey": "primary_diagnosis.submitter_primary_diagnosis_id",
"validationDependency": true
}
}
]
}
79 changes: 79 additions & 0 deletions tests/donor/lost_to_followup.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2020 The Ontario Institute for Cancer Research. All rights reserved
*
* This program and the accompanying materials are made available under the terms of the GNU Affero General Public License v3.0.
* You should have received a copy of the GNU Affero General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/

const validation = require('./../../references/validationFunctions/donor/lost_to_followup.js');
const universalTest = require('../universal');
const loadObjects = require('../loadObjects');

// load in all fields with entries prepopulated to null
const donor = require('../constructDummyData').getSchemaDummy('donor');

const myUnitTests = {
"lost_to_followup_after_clinical_event_id": [
[
'Alive donor with lost to follow up indicated.',
true,
loadObjects(donor,
{
"vital_status": "alive",
"lost_to_followup_after_clinical_event_id": "PD1"
}
)
],
[
'Lost to follow up indicated when donor is known to be deceased.',
false,
loadObjects(donor,
{
"vital_status": "deceased",
"lost_to_followup_after_clinical_event_id" : "Tr-1"
}
)

]
]
};

describe("Common Tests",()=>{
Object.entries(myUnitTests).forEach(field =>{
const name = field[0];
const unitTests = field[1];
unitTests.forEach(test=>{
const testIndex = 2;
const testInputs = test[testIndex];
universalTest(validation()({ $row: testInputs, $name: name, $field: testInputs[name]}));
})
})

})

describe("Unit Tests for Lost to follow up",()=>{
Object.entries(myUnitTests).forEach(field => {
const name = field[0];
const unitTests = field[1];
describe(`Tests for the ${name} field.`,() => {
test.each(unitTests)('\n Test %# : %s \nExpecting result.valid to be: %s',(description,target,inputs) =>{
const scriptOutput = validation()({ $row: inputs, $field: inputs[name], $name: name});
expect(scriptOutput.valid).toBe(target);
})
})
})
})

0 comments on commit 57b796b

Please sign in to comment.