-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from icgc-argo/develop
Dictionary release 1.21
- Loading branch information
Showing
4 changed files
with
165 additions
and
26 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
references/validationFunctions/specimen/percentageTumourCells.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <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 = () => | ||
(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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <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/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); | ||
}, | ||
); | ||
}); |