Skip to content

Commit

Permalink
[Candidate_parameters] Consent status - Add NA option (aces#8732)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
charlottesce authored Jan 23, 2024
1 parent be39a57 commit efe0439
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
4 changes: 2 additions & 2 deletions SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions SQL/New_patches/2023-06-06-add_NA_to_consent_status.sql
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions modules/candidate_parameters/ajax/formHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,30 @@ 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.');
return;
}
}
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
Expand Down
24 changes: 18 additions & 6 deletions modules/candidate_parameters/jsx/ConsentStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class ConsentStatus extends Component {
constructor(props) {
super(props);
this.state = {
consentOptions: {
yes: 'Yes',
no: 'No',
},
Data: [],
formData: {},
error: false,
Expand Down Expand Up @@ -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';
Expand All @@ -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({
Expand Down Expand Up @@ -285,7 +296,7 @@ class ConsentStatus extends Component {
{dataEntry} - {user}
</b> updated for <i>{label}</i>:
<b> Status</b> to {' '}
{this.state.consentOptions[consentStatus]}
{consentStatus}
{dateHistory}
{withdrawalHistory}
</p>
Expand Down Expand Up @@ -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';
Expand All @@ -373,7 +385,7 @@ class ConsentStatus extends Component {
<SelectElement
label={statusLabel}
name={consentName}
options={this.state.consentOptions}
options={this.state.formData[consentOptions]}
value={this.state.formData[consentName]}
onUserInput={this.setFormData}
disabled={disabled}
Expand Down
4 changes: 4 additions & 0 deletions modules/candidate_parameters/test/TestPlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
5. Try updating the consent information. Do not fill out all required fields. Ensure that an error appears when you try to save.
6. For each of the date fields, try entering only one part of the date (eg. the year). Make sure there is an error when you try to save.
7. Enter the following combinations:
* Consent to Study = Not Applicable
* No error
* Make sure they update properly in the front-end and backend
* Consent to Study = No (error: must enter Date of 'No' Consent)
* Consent to Study = Yes (error: must enter Date of 'Yes' Consent)
* Consent to Study = Yes/No; Date of Consent = random date
Expand All @@ -66,6 +69,7 @@
* Consent to Study = No (changing/updating an already existing 'Yes' consent); Date (Withdrawal) of Consent = valid random date; Confirmation (Withdrawal) Date of Consent = same random date
* No error
* Make sure they update properly in the front-end and backend
* Check that Consent to Study = Not Applicable is not an option when changing/updating an already existing 'Yes' or 'No' consent

### Date of Birth Tab
1. Check that date of birth can only be amended if user has candidate_dob_edit permission.
Expand Down

0 comments on commit efe0439

Please sign in to comment.