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

Data Dictionary V1.23 #434

Merged
merged 11 commits into from
Aug 19, 2024
47 changes: 47 additions & 0 deletions references/validationFunctions/radiation/radiationBoost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2022 The Ontario Institute for Cancer Research. All rights reserved
justincorrigible marked this conversation as resolved.
Show resolved Hide resolved
*
* 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.
*
*
*/

/**
* If a radiation boost was given, then the 'reference_radiation_treatment_id' must be submitted.
*/
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;

if ($row.radiation_boost != null) {
const radiationBoost = $row.radiation_boost.trim().toLowerCase();

if (!currField && radiationBoost === "yes") {
result = {valid: false, message: `${$name} must be provided when if a radiation boost was given.`}
}
else if (currField && radiationBoost != "yes"){
result = {valid: false, message: `${$name} cannot be provided if the 'radiation_boost' field is '${radiationBoost}'.`}
}
}
else if ((!$row.radiation_boost) && (currField)) {
result = {valid: false, message: `'${$name}' requires the 'radiation_boost' field.` }
}
return result;
});


module.exports = validation;
22 changes: 22 additions & 0 deletions schemas/radiation.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,28 @@
"core": true,
"displayName": "Anatomical Site Irradiated"
}
},
{
"name": "radiation_boost",
"description": "A radiation boost is an extra radiation treatment targeted at the tumor bed, given after the regular sessions of radiation is complete (Reference NCIt: C137812). Indicate if this radiation treatment was a radiation boost.",
"valueType": "string",
"restrictions": {
"codeList": "#/list/yes_no_na"
},
"meta": {
"displayName": "Radiation Boost"
}
},
{
"name": "reference_radiation_treatment_id",
"description": "If a radiation boost was given, indicate the 'submitter_treatment_id' of the primary radiation treatment the radiation boost treatment is linked to.",
"valueType": "string",
"restrictions": {
"script": "#/script/radiation/radiationBoost"
},
"meta": {
"displayName": "Reference Radiation Treatment for Boost"
}
}
]
}
5 changes: 1 addition & 4 deletions schemas/specimen.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@
"displayName": "Specimen Acquisition Interval"
},
"restrictions": {
"required": true,
"range": {
"min": 0
}
"required": true
}
},
{
Expand Down
121 changes: 121 additions & 0 deletions tests/radiation/radiationBoost.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (c) 2022 The Ontario Institute for Cancer Research. All rights reserved
justincorrigible marked this conversation as resolved.
Show resolved Hide resolved
*
* 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/radiation/radiationBoost.js');
const universalTest = require('../universal');
const loadObjects = require('../loadObjects');

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

const myUnitTests = {
"reference_radiation_treatment_id": [
[
'reference_radiation_treatment_id submitted when radiation boost was given.',
true,
loadObjects(radiation,
{
"radiation_boost": "yes",
"reference_radiation_treatment_id": "tr2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there ever be a case when treatment ID is "unknown" or other generic values? if so, is that valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justincorrigible you pointed out a valid use case. However based on the current validation rule, if indicating radiation_boost as yes while treatment ID is "Unknown", the program will need to apply exception on field reference_radiation_treatment_id.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like something to be addressed in a different PR.
This one is good to go 👍

}
)
],
[
'reference_radiation_treatment_id is empty when radiation boost was given.',
false,
loadObjects(radiation,
{
"radiation_boost": "yes",
"reference_radiation_treatment_id": ""
}
)
],
[
'reference_radiation_treatment_id is not submitted when radiation boost was given.',
false,
loadObjects(radiation,
{
"radiation_boost": "yes",
}
)
],
[
'reference_radiation_treatment_id is submitted when radiation boost was not given.',
false,
loadObjects(radiation,
{
"radiation_boost": "no",
"reference_radiation_treatment_id": "tr40"
}
)
],
[
'reference_radiation_treatment_id is submitted when radiation boost was unknown.',
false,
loadObjects(radiation,
{
"radiation_boost": "unknown",
"reference_radiation_treatment_id": "tr25"
}
)
],
[
'reference_radiation_treatment_id is submitted when radiation boost is missing.',
false,
loadObjects(radiation,
{
"reference_radiation_treatment_id": "tr3"
}
)
],
[
'Both radiation_boost and reference_radiation_treatment_id are missing',
true,
loadObjects(radiation, {})
]
]
};

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 Radiation Boost",()=>{
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);
})
})
})
})

Loading