Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the treatment interval validation script to accept 0 (#441) #442

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
{
"name": "dictionary",
"version": "1.0.0",
"description": "Working space for the ARGO Data Dictionary collaboration",
"main": "index.js",
"scripts": {
"compile": "jest && node compile.js && npm run references",
"test": "jest",
"references": "node populateReferences.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/icgc-argo/argo-dictionary.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/icgc-argo/argo-dictionary/issues"
},
"homepage": "https://github.com/icgc-argo/argo-dictionary#readme",
"dependencies": {},
"devDependencies": {
"auto-load": "^3.0.4",
"chalk": "^3.0.0",
"inquirer": "^7.0.1",
"jest": "^25.2.3",
"json-beautify": "^1.1.1",
"prettier": "^1.19.1",
"querystring": "^0.2.0",
"yargs": "^15.0.2"
},
"prettier": {
"printWidth": 100,
"trailingComma": "all",
"singleQuote": true
}
"name": "dictionary",
"version": "1.0.0",
"description": "Working space for the ARGO Data Dictionary collaboration",
"main": "index.js",
"scripts": {
"compile": "jest && node compile.js && npm run references",
"test": "jest",
"references": "node populateReferences.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/icgc-argo/argo-dictionary.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/icgc-argo/argo-dictionary/issues"
},
"homepage": "https://github.com/icgc-argo/argo-dictionary#readme",
"devDependencies": {
"auto-load": "^3.0.4",
"chalk": "^3.0.0",
"inquirer": "^7.0.1",
"jest": "^25.2.3",
"json-beautify": "^1.1.1",
"prettier": "^1.19.1",
"querystring": "^0.2.0",
"yargs": "^15.0.2"
},
"prettier": {
"printWidth": 120,
"trailingComma": "all",
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"useTabs": true
}
}
107 changes: 55 additions & 52 deletions references/validationFunctions/treatment/checkWhenNoTreatment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 The Ontario Institute for Cancer Research. All rights reserved
* Copyright (c) 2024 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
Expand All @@ -23,63 +23,66 @@
*/

const validation = () =>
(function validate(inputs) {
const { $row, $name, $field } = inputs;
const result = { valid: true, message: 'Ok' };
function validate(inputs) {
const { $row, $name, $field } = inputs;
const result = { valid: true, message: 'Ok' };

const arrayItemsInSecondArray = (arr1, arr2) => {
return arr2.some(arr2Item => {
return arr1.includes(arr2Item);
});
};
const arrayItemsInSecondArray = (arr1, arr2) => {
return arr2.some(arr2Item => {
return arr1.includes(arr2Item);
});
};

const coreFields = [
'treatment_start_interval',
'treatment_duration',
'is_primary_treatment',
'treatment_intent',
'treatment_setting',
'response_to_treatment_criteria_method',
'response_to_treatment',
];
const coreFields = [
'treatment_start_interval',
'treatment_duration',
'is_primary_treatment',
'treatment_intent',
'treatment_setting',
'response_to_treatment_criteria_method',
'response_to_treatment',
];

const treatmentExceptionTypes = ['no treatment', 'unknown'];
const treatmentExceptionTypes = ['no treatment', 'unknown'];

// checks for a string just consisting of whitespace
const checkforEmpty = entry => {
return /^\s+$/g.test(decodeURI(entry).replace(/^"(.*)"$/, '$1'));
};
const treatmentTypes = $row.treatment_type.map(value => value.toLowerCase());
const checkforInvalid = entry => {
// note: negative numbers are allowed as per
// https://github.com/icgc-argo/argo-dictionary/issues/432 */

const recordHasTreatments = !arrayItemsInSecondArray(
treatmentExceptionTypes,
treatmentTypes,
);
return (
// regular falsy values
[null, undefined, ''].includes($field) ||
// whitespace-filled strings
/^\s+$/g.test(decodeURI(entry).replace(/^"(.*)"$/, '$1'))
);
};

if (recordHasTreatments) {
if (
coreFields.includes($name) &&
(!$field || $field === null || checkforEmpty($field))
) {
return {
valid: false,
message: `The '${$name}' field must be submitted when the 'treatment_type' field is '${treatmentTypes}'`,
};
}
const treatmentTypes = $row.treatment_type.map(value => value.toLowerCase());

} else if ($field && $field != null && !checkforEmpty($field)) {
if (
coreFields.includes($name) ||
(typeof $field === 'string' && $field.trim().toLowerCase() != 'not applicable') ||
typeof $field === 'number'
) {
return {
valid: false,
message: `The '${$name}' field cannot be submitted if the 'treatment_type' field is '${treatmentTypes}'`,
};
}
}
return result;
});
const recordHasTreatments = !arrayItemsInSecondArray(treatmentExceptionTypes, treatmentTypes);

if (recordHasTreatments) {
if (coreFields.includes($name) && checkforInvalid($field)) {
return {
valid: false,
message: `The '${$name}' field must be submitted when the 'treatment_type' field is '${treatmentTypes}'`,
};
}
} // otherwise, is there a valid value without a treatment defined
else if (!checkforInvalid($field)) {
if (
coreFields.includes($name) ||
(typeof $field === 'string' && $field.trim().toLowerCase() != 'not applicable') ||
!isNaN(parseFloat($field))
) {
return {
valid: false,
message: `The '${$name}' field cannot be submitted if the 'treatment_type' field is '${treatmentTypes}'`,
};
}
}

return result;
};

module.exports = validation;
Loading
Loading