-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Candidate_parameters] Improve front-end validation for entering Cons…
…ent data (#4034) This makes entering consent data more rigorous. Implements the following workflow for data entry: - Date of consent being given is required for both answers to consent "yes" or "no" - Date of withdrawal of consent required if answer changes from "yes" to "no" - Consent status "yes" or "no" cannot be changed to an empty one - Replaces confirmation message to swal - Adds script to check errors in data
- Loading branch information
1 parent
846a979
commit 9ef6e11
Showing
4 changed files
with
181 additions
and
70 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,52 @@ | ||
<?php | ||
/** | ||
* This script is written for a one time use only to clean up existing data in the 'candidate_consent_rel' table to conform to the new front-end validation for entering consent. | ||
* | ||
* PHP Version 7 | ||
* | ||
* @category Main | ||
* @package Loris | ||
* @author Zaliqa Rosli <zaliqa.rosli@mcin.ca> | ||
* @licence Loris license | ||
* @link https://github.com/aces/Loris | ||
*/ | ||
require_once __DIR__ . '/../generic_includes.php'; | ||
|
||
$db = \Database::singleton(); | ||
$errors = array(); | ||
|
||
$query = "SELECT CandidateID, ConsentID, Status, DateGiven, DateWithdrawn | ||
FROM candidate_consent_rel"; | ||
$consentData = $db->pselect($query, array()); | ||
|
||
foreach($consentData as $key => $entry) { | ||
$candID = $entry['CandidateID']; | ||
$consentID = $entry['ConsentID']; | ||
$status = $entry['Status']; | ||
$consentDate = $entry['DateGiven']; | ||
$withdrawalDate = $entry['DateWithdrawn']; | ||
$row = $key + 1; | ||
|
||
switch ($status) { | ||
case '': | ||
array_push($errors, "An entry with a NULL consent status should not exist. Entry $row with CandidateID=$candID and ConsentID=$consentID has a NULL consent status. Please clear the entry or change the consent to either 'yes' or 'no'. \n\n"); | ||
break; | ||
case 'no': | ||
if (empty($consentDate)) { | ||
array_push($errors, "A consent date is now required for both a 'yes' and 'no' consent status. 'DateGiven' is missing for entry $row with CandidateID=$candID and ConsentID=$consentID. Please fill in missing date of consent or clear the entry. \n\n"); | ||
} | ||
break; | ||
case 'yes': | ||
if (empty($consentDate)) { | ||
array_push($errors, "A consent date is now required for both a 'yes' and 'no' answer to consent. The 'DateGiven' column is missing for entry $row with CandidateID=$candID and ConsentID=$consentID. Please fill in missing date of consent or clear the entry. \n\n"); | ||
} else if (!empty($withdrawalDate)) { | ||
array_push($errors, "An entry with a consent status 'yes' should not have a date of withdrawal. 'DateWithdrawn' exists for entry $row with CandidateID=$candID and ConsentID=$consentID. Please remove date of withdrawal or change the consent to 'no'. \n\n"); | ||
} | ||
break; | ||
} | ||
} | ||
if (empty($errors)) { | ||
echo "There are no errors. No additional steps required.\n"; | ||
} else { | ||
print_r($errors); | ||
} |