From efe043986a0b79a0241f5816f3f029ccd23cd1a3 Mon Sep 17 00:00:00 2001 From: charlottesce <75381352+charlottesce@users.noreply.github.com> Date: Tue, 23 Jan 2024 09:07:07 -0500 Subject: [PATCH] [Candidate_parameters] Consent status - Add NA option (#8732) Adding a N/A option for consent status. This is the expected behaviour: - Updating the consent status from Not Applicable to Yes/No is allowed - Updating the consent status from Yes/No to Not Applicable is NOT allowed - If Not Applicable is selected, no dates are required Removes CCNA override aces/CCNA#3822 --- SQL/0000-00-00-schema.sql | 4 ++-- .../2023-06-06-add_NA_to_consent_status.sql | 2 ++ .../candidate_parameters/ajax/formHandler.php | 17 +++++++++++++ .../candidate_parameters/jsx/ConsentStatus.js | 24 ++++++++++++++----- modules/candidate_parameters/test/TestPlan.md | 4 ++++ 5 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 SQL/New_patches/2023-06-06-add_NA_to_consent_status.sql diff --git a/SQL/0000-00-00-schema.sql b/SQL/0000-00-00-schema.sql index 5e15eba00d9..979a87e47c3 100644 --- a/SQL/0000-00-00-schema.sql +++ b/SQL/0000-00-00-schema.sql @@ -2278,7 +2278,7 @@ CREATE TABLE `consent` ( CREATE TABLE `candidate_consent_rel` ( `CandidateID` int(6) NOT NULL, `ConsentID` integer unsigned NOT NULL, - `Status` enum('yes','no') DEFAULT NULL, + `Status` enum('yes','no', 'not_applicable') DEFAULT NULL, `DateGiven` date DEFAULT NULL, `DateWithdrawn` date DEFAULT NULL, CONSTRAINT `PK_candidate_consent_rel` PRIMARY KEY (`CandidateID`,`ConsentID`), @@ -2294,7 +2294,7 @@ CREATE TABLE `candidate_consent_history` ( `PSCID` varchar(255) NOT NULL, `ConsentName` varchar(255) NOT NULL, `ConsentLabel` varchar(255) NOT NULL, - `Status` enum('yes','no') DEFAULT NULL, + `Status` enum('yes','no', 'not_applicable') DEFAULT NULL, `EntryStaff` varchar(255) DEFAULT NULL, CONSTRAINT `PK_candidate_consent_history` PRIMARY KEY (`CandidateConsentHistoryID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/SQL/New_patches/2023-06-06-add_NA_to_consent_status.sql b/SQL/New_patches/2023-06-06-add_NA_to_consent_status.sql new file mode 100644 index 00000000000..185e13b8a06 --- /dev/null +++ b/SQL/New_patches/2023-06-06-add_NA_to_consent_status.sql @@ -0,0 +1,2 @@ +ALTER TABLE candidate_consent_rel MODIFY COLUMN `Status` enum('yes', 'no', 'not_applicable') DEFAULT NULL; +ALTER TABLE candidate_consent_history MODIFY COLUMN `Status` enum('yes', 'no', 'not_applicable') DEFAULT NULL; \ No newline at end of file diff --git a/modules/candidate_parameters/ajax/formHandler.php b/modules/candidate_parameters/ajax/formHandler.php index f600bfe247f..70783909eac 100644 --- a/modules/candidate_parameters/ajax/formHandler.php +++ b/modules/candidate_parameters/ajax/formHandler.php @@ -501,6 +501,10 @@ function editConsentStatusFields(\Database $db) ) { // Withdrawing from 'yes' status required consent date // and withdrawal date $validated = true; + } else if ($oldStatus === 'not_applicable' && !empty($date) + && empty($withdrawal) + ) { // Add N/A option + $validated = true; } else { http_response_code(400); echo('Data failed validation. Resolve errors and try again.'); @@ -508,6 +512,19 @@ function editConsentStatusFields(\Database $db) } } break; + case 'not_applicable': + // If status is N/A, date is not required. + if (empty($date) && empty($withdrawal) + && ($oldStatus !== 'yes' || $oldStatus !== 'no') + ) { + $validated = true; + } else { + http_response_code(400); + echo('Answering not applicable to a consent type + does not require a date of consent.'); + return; + } + break; default: // If status is empty, and date fields are also empty, // validated is still false diff --git a/modules/candidate_parameters/jsx/ConsentStatus.js b/modules/candidate_parameters/jsx/ConsentStatus.js index 433ebd9ab4d..d25bd78e05b 100644 --- a/modules/candidate_parameters/jsx/ConsentStatus.js +++ b/modules/candidate_parameters/jsx/ConsentStatus.js @@ -26,10 +26,6 @@ class ConsentStatus extends Component { constructor(props) { super(props); this.state = { - consentOptions: { - yes: 'Yes', - no: 'No', - }, Data: [], formData: {}, error: false, @@ -68,6 +64,7 @@ class ConsentStatus extends Component { let consents = data.consents; for (let cStatus in consents) { if (consents.hasOwnProperty(cStatus)) { + let cOptions = cStatus + '_options'; let cDate = cStatus + '_date'; let cDate2 = cStatus + '_date2'; let cWithdrawal = cStatus + '_withdrawal'; @@ -77,6 +74,20 @@ class ConsentStatus extends Component { formData[cDate2] = data.consentDates[cStatus]; formData[cWithdrawal] = data.withdrawals[cStatus]; formData[cWithdrawal2] = data.withdrawals[cStatus]; + if (data.consentStatuses[cStatus] === 'yes' || + data.consentStatuses[cStatus] === 'no' + ) { + formData[cOptions] = { + yes: 'Yes', + no: 'No', + }; + } else { + formData[cOptions] = { + yes: 'Yes', + no: 'No', + not_applicable: 'Not applicable', + }; + } } } this.setState({ @@ -285,7 +296,7 @@ class ConsentStatus extends Component { {dataEntry} - {user} updated for {label}: Status to {' '} - {this.state.consentOptions[consentStatus]} + {consentStatus} {dateHistory} {withdrawalHistory}

@@ -354,6 +365,7 @@ class ConsentStatus extends Component { // Set up elements const label = this.state.Data.consents[consentName]; + const consentOptions = consentName + '_options'; const statusLabel = 'Response'; const consentDate = consentName + '_date'; const consentDate2 = consentName + '_date2'; @@ -373,7 +385,7 @@ class ConsentStatus extends Component {