From b7713023efe12d3fe3816432a04bf9fa428b18a2 Mon Sep 17 00:00:00 2001 From: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com> Date: Tue, 31 Oct 2023 19:11:53 -0400 Subject: [PATCH 1/2] add percent tumour cell exception validations (#424) --- .../specimen/percentageTumourCells.js | 49 +++++++++++ schemas/specimen.json | 55 ++++++------ tests/specimen/percentageTumourCells.test.js | 86 +++++++++++++++++++ 3 files changed, 164 insertions(+), 26 deletions(-) create mode 100644 references/validationFunctions/specimen/percentageTumourCells.js create mode 100644 tests/specimen/percentageTumourCells.test.js diff --git a/references/validationFunctions/specimen/percentageTumourCells.js b/references/validationFunctions/specimen/percentageTumourCells.js new file mode 100644 index 0000000..4dcd9ab --- /dev/null +++ b/references/validationFunctions/specimen/percentageTumourCells.js @@ -0,0 +1,49 @@ +/* + * 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 . + * + * 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 = () => +(function validate(inputs) { + // When $name is percent_tumour_cells, and $field is a number between 0 and 1 + const {$row, $name, $field} = inputs; + + const result = { valid: true, message: 'Ok' }; + const measurementMethodExceptionTypes = ['not applicable']; + + // checks for a string just consisting of whitespace + const checkforEmpty = (entry) => { + return /^\s+$/g.test(decodeURI(entry).replace(/^"(.*)"$/, '$1')); + }; + + const fieldHasValue = $field && $field != null && !(checkforEmpty($field)); + const measurementMethod = $row?.percent_tumour_cells_measurement_method?.trim?.().toLowerCase(); + + if (fieldHasValue) { + if (measurementMethodExceptionTypes.includes(measurementMethod)) { + return { + valid: false, + message: `The '${$name}' field cannot be submitted when 'percent_tumour_cells_measurement_method' = 'Not applicable'` + }; + } + } + + return result; + }); + +module.exports = validation; diff --git a/schemas/specimen.json b/schemas/specimen.json index b7fc9a4..e5500a6 100644 --- a/schemas/specimen.json +++ b/schemas/specimen.json @@ -152,7 +152,7 @@ "restrictions": { "required": true, "range": { - "min": 0 + "min": 0 } } }, @@ -220,7 +220,9 @@ "Unknown" ] }, - "meta": { "displayName": "Specimen Processing" } + "meta": { + "displayName": "Specimen Processing" + } }, { "name": "specimen_storage", @@ -331,10 +333,11 @@ "displayName": "Percent Tumour Cells" }, "restrictions": { - "range": { - "min": 0, - "max": 1 - } + "range": { + "min": 0, + "max": 1 + }, + "script": "#/script/specimen/percentageTumourCells" } }, { @@ -349,9 +352,9 @@ }, "restrictions": { "codeList": [ - "Genomics", - "Image analysis", - "Pathology estimate by percent nuclei" + "Genomics", + "Image analysis", + "Pathology estimate by percent nuclei" ] } }, @@ -365,10 +368,10 @@ "displayName": "Percent Proliferating Cells" }, "restrictions": { - "range": { - "min": 0, - "max": 1 - } + "range": { + "min": 0, + "max": 1 + } } }, { @@ -381,10 +384,10 @@ "displayName": "Percent Inflammatory Tissue" }, "restrictions": { - "range": { - "min": 0, - "max": 1 - } + "range": { + "min": 0, + "max": 1 + } } }, { @@ -397,10 +400,10 @@ "displayName": "Percent Stromal Cells" }, "restrictions": { - "range": { - "min": 0, - "max": 1 - } + "range": { + "min": 0, + "max": 1 + } } }, { @@ -413,11 +416,11 @@ "displayName": "Percent Necrosis" }, "restrictions": { - "range": { - "min": 0, - "max": 1 - } + "range": { + "min": 0, + "max": 1 + } } } ] -} +} \ No newline at end of file diff --git a/tests/specimen/percentageTumourCells.test.js b/tests/specimen/percentageTumourCells.test.js new file mode 100644 index 0000000..55543db --- /dev/null +++ b/tests/specimen/percentageTumourCells.test.js @@ -0,0 +1,86 @@ +/* + * 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 . + * + * 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/specimen/percentageTumourCells.js'); +const universalTest = require('../universal'); +const loadObjects = require('../loadObjects'); + +// load in all fields with entries prepopulated to null +const specimen = require('../constructDummyData').getSchemaDummy('specimen'); + +// the name of the field being validateds +const name = 'percent_tumour_cells'; + +const unitTests = [ + [ + 'A percentage of tumour cells is given, and a measurement method is given too', + true, + loadObjects(specimen, { + percent_tumour_cells: 0.5, + percent_tumour_cells_measurement_method: 'Genomics', + }), + ], + [ + 'A percentage of tumour cells is given, and a measurement method does not apply', + false, + loadObjects(specimen, { + percent_tumour_cells: 0.5, + percent_tumour_cells_measurement_method: 'Not applicable', + }), + ], + [ + 'A percentage of tumour cells is given, and a measurement method is missing', + true, + loadObjects(specimen, { + percent_tumour_cells: 0.5, + }), + ], + [ + 'A percentage of tumour cells is missing, and a measurement method is given too', + true, + loadObjects(specimen, { + percent_tumour_cells_measurement_method: 'Image analysis', + }), + ], + [ + 'A percentage of tumour cells is missing, and a measurement method does not apply', + true, + loadObjects(specimen, { + percent_tumour_cells_measurement_method: 'Not applicable', + }), + ], + ['Both fields are undefined', true, specimen] +]; + +describe('Common Tests', () => { + unitTests.forEach(([description, expected, testInputs]) => { + universalTest(validation()({ $row: testInputs, $name: name, $field: testInputs[name]})); + }); +}); + +describe('Unit Tests for Tumour Grade', () => { + 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); + }, + ); +}); From 4c6f90cfb64511dac62a3538e39737a90e6cd470 Mon Sep 17 00:00:00 2001 From: Linda Xiang Date: Thu, 14 Dec 2023 11:23:49 -0500 Subject: [PATCH 2/2] add new value of end of life care into treatment_type --- schemas/treatment.json | 1 + 1 file changed, 1 insertion(+) diff --git a/schemas/treatment.json b/schemas/treatment.json index 9c15d49..ded341b 100644 --- a/schemas/treatment.json +++ b/schemas/treatment.json @@ -75,6 +75,7 @@ "Bone marrow transplant", "Chemotherapy", "Endoscopic therapy", + "End of life care", "Hormonal therapy", "Immunotherapy", "No treatment",