Skip to content

Commit

Permalink
PIXI-147: Change validation logic in hotel scan record to prevent use…
Browse files Browse the repository at this point in the history
…r from accidentally creating a scan record when the subject ID is not set
  • Loading branch information
andylassiter committed Oct 16, 2024
1 parent b881b01 commit f1f71d6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- [PIXI-147]: Change validation logic in hotel scan record to prevent user from accidentally creating a scan record when
the subject ID is not set.
- [PIXI-150]: Update display XML listings for PET and CT to make them more user-friendly.
- [PIXI-152]: Allow for single mouses/rat hotels in the hotel scan record form.
- [PIXI-154]: Update PCIF naming scheme in the Inveon importer to include the timepoint as part of the XNAT session name
Expand Down Expand Up @@ -120,6 +122,7 @@ plugins directory and restart XNAT.
[PIXI-140]: https://radiologics.atlassian.net/browse/PIXI-140
[PIXI-144]: https://radiologics.atlassian.net/browse/PIXI-144
[PIXI-145]: https://radiologics.atlassian.net/browse/PIXI-145
[PIXI-147]: https://radiologics.atlassian.net/browse/PIXI-147
[PIXI-150]: https://radiologics.atlassian.net/browse/PIXI-150
[PIXI-151]: https://radiologics.atlassian.net/browse/PIXI-151
[PIXI-152]: https://radiologics.atlassian.net/browse/PIXI-152
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,9 +909,107 @@
<script type="text/javascript">
function validateForm()
{
//INSERT CUSTOM CONTENT HERE
let validation = validate();

if (!validation) {
return false;
}

validateExperimentForm();
return false;
}

// Check if a value is blank
const isBlank = (value) => {
// Check if the value is undefined or null
if (value === undefined || value === null) {
return true;
}

// Convert the value to a string and trim whitespace
const trimmedValue = String(value).trim();

// Check if the trimmed string is empty
return trimmedValue === '';
}

function validate() {
// Check if the hotel selector is empty
const hotelSelector = document.getElementById('pixi:hotelScanRecord/hotel');
if (hotelSelector.value === 'Select Hotel Type') {
XNAT.dialog.open({
title: 'Error',
content: 'Please select a hotel type.',
buttons: [
{
label: 'Close',
isDefault: true,
close: true,
action: function(){
XNAT.ui.dialog.closeAll();
xmodal.closeAll();
}
},
]
});

return false;
}

// Collect list of invalid hotel positions
// If a subject is not selected, the inputs should be empty
let invalidPositions = [];
document.querySelectorAll('.subject-selector').forEach((subjectSelector) => {
// Navigate upward to the hotel-unit div
const hotelUnit = subjectSelector.closest('.hotel-unit');

// Get the name of the hotel position
const position = hotelUnit.querySelector('[name*="position"]').value;

// Select the main inputs for a subject
const inputs = Array.from(hotelUnit.querySelectorAll('select[name*="orientation"], input[name*="weight"], input[name*="injection_time"], input[name*="activity"]'));

// If an input is non-empty, but the subject selector is empty, warn the user
if (isBlank(subjectSelector.value)) {
inputs.forEach(input => {
if (!isBlank(input.value)) {
// only add the position to the list once
if (!invalidPositions.includes(position)) {
invalidPositions.push(position);
}
}
});
}
});

// If there are invalid positions, warn the user
if (invalidPositions.length > 0) {
XNAT.dialog.open({
title: 'Error',
content: `You have entered data for a subjects in the <b>${invalidPositions.join(', ')}</b> position(s), but have not selected a subject. Please select a subject for each position or clear the data.`,
buttons: [
{
label: 'Close',
isDefault: true,
close: true,
action: function(){
XNAT.ui.dialog.closeAll();
xmodal.closeAll();
}
},
]
});

return false;
}

// Clear blank values from the form before submission
document.querySelector('#hotel-units')?.querySelectorAll('input, select').forEach((el) => {
if (isBlank(el.value)) {
el.value = '';
}
});

return true;
}
</script>

0 comments on commit f1f71d6

Please sign in to comment.