Skip to content

Commit

Permalink
[Consent] Add ParentID to consent for consent grouping (aces#6042)
Browse files Browse the repository at this point in the history
Adds ConsentGroupID to consent table (schema + patch)
  
This keeps the Consent Status tab rendering the same. Only the back-end is affected in this PR. This feature is increasingly in demand from projects who would like to split up consents via e.g. consent forms.

See also aces#6044 for front-end changes.
  • Loading branch information
zaliqarosli authored and AlexandraLivadas committed Jun 29, 2021
1 parent 0893582 commit d2c1bbb
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
16 changes: 14 additions & 2 deletions SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2059,13 +2059,26 @@ CREATE TABLE `feedback_mri_comments` (
-- Consent tables
-- ********************************

CREATE TABLE `consent_group` (
`ConsentGroupID` integer unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
`Label` varchar(255) NOT NULL,
CONSTRAINT `PK_consent_group` PRIMARY KEY (`ConsentGroupID`),
CONSTRAINT `UK_consent_group_Name` UNIQUE KEY `Name` (`Name`),
CONSTRAINT `UK_consent_group_Label` UNIQUE KEY `Label` (`Label`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `consent_group` (`ConsentGroupID`, `Name`, `Label`) VALUES ('1', 'main_consent', 'Main consent');

CREATE TABLE `consent` (
`ConsentID` integer unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
`Label` varchar(255) NOT NULL,
`ConsentGroupID` integer unsigned NOT NULL DEFAULT 1,
CONSTRAINT `PK_consent` PRIMARY KEY (`ConsentID`),
CONSTRAINT `UK_consent_Name` UNIQUE KEY `Name` (`Name`),
CONSTRAINT `UK_consent_Label` UNIQUE KEY `Label` (`Label`)
CONSTRAINT `UK_consent_Label` UNIQUE KEY `Label` (`Label`),
CONSTRAINT `FK_consent_ConsentGroupID` FOREIGN KEY (`ConsentGroupID`) REFERENCES `consent_group` (`ConsentGroupID`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `candidate_consent_rel` (
Expand Down Expand Up @@ -2224,4 +2237,3 @@ CREATE TABLE `publication_users_edit_perm_rel` (
CONSTRAINT `FK_publication_users_edit_perm_rel_PublicationID` FOREIGN KEY (`PublicationID`) REFERENCES `publication` (`PublicationID`),
CONSTRAINT `FK_publication_users_edit_perm_rel_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET='utf8';

12 changes: 12 additions & 0 deletions SQL/New_patches/2020-02-10-AddConsentGrouping.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE `consent_group` (
`ConsentGroupID` integer unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
`Label` varchar(255) NOT NULL,
CONSTRAINT `PK_consent_group` PRIMARY KEY (`ConsentGroupID`),
CONSTRAINT `UK_consent_group_Name` UNIQUE KEY `Name` (`Name`),
CONSTRAINT `UK_consent_group_Label` UNIQUE KEY `Label` (`Label`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `consent_group` (`ConsentGroupID`, `Name`, `Label`) VALUES ('1', 'main_consent', 'Main consent');

ALTER TABLE `consent` ADD `ConsentGroupID` integer unsigned NOT NULL DEFAULT 1;
ALTER TABLE `consent` ADD CONSTRAINT `FK_consent_ConsentGroupID` FOREIGN KEY (`ConsentGroupID`) REFERENCES `consent_group` (`ConsentGroupID`) ON DELETE RESTRICT ON UPDATE CASCADE;
15 changes: 9 additions & 6 deletions modules/candidate_parameters/ajax/formHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,15 @@ function editConsentStatusFields(\Database $db)

// Process posted data
// Empty strings and type null are not passed (null is passed as a string)
$status = ($_POST[$consentName] !== 'null') ?
$_POST[$consentName] : null;
$date = ($_POST[$consentName . '_date'] !== 'null') ?
$_POST[$consentName . '_date'] : null;
$withdrawal = ($_POST[$consentName . '_withdrawal'] !== 'null') ?
$_POST[$consentName . '_withdrawal'] : null;
$status = (isset($_POST[$consentName]) &&
$_POST[$consentName] !== 'null') ?
$_POST[$consentName] : null;
$date = (isset($_POST[$consentName . '_date']) &&
$_POST[$consentName . '_date'] !== 'null') ?
$_POST[$consentName . '_date'] : null;
$withdrawal = (isset($_POST[$consentName . '_withdrawal']) &&
$_POST[$consentName . '_withdrawal'] !== 'null') ?
$_POST[$consentName . '_withdrawal'] : null;

$updateStatus = [
'CandidateID' => $candID,
Expand Down
7 changes: 4 additions & 3 deletions php/libraries/Utility.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ class Utility
/**
* Returns list of consents in the database
*
* @return array An associative array of consents, with their names and labels.
* The keys of the arrays are the IDs of the consents
* @return array An associative array of consents, with their names,
* labels, and group ID. The keys of the arrays are the
* IDs of the consents.
*/
static function getConsentList(): array
{
$factory = NDB_Factory::singleton();
$DB = $factory->database();

$query = "SELECT ConsentID, Name, Label FROM consent";
$query = "SELECT ConsentID, Name, Label, ConsentGroupID FROM consent";
$key = "ConsentID";

$result = $DB->pselectWithIndexKey($query, [], $key);
Expand Down
6 changes: 3 additions & 3 deletions raisinbread/RB_files/RB_consent.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE `consent`;
LOCK TABLES `consent` WRITE;
INSERT INTO `consent` (`ConsentID`, `Name`, `Label`) VALUES (1,'study_consent','Consent to Study');
INSERT INTO `consent` (`ConsentID`, `Name`, `Label`) VALUES (2,'raisin_consent','Consent to Raisin');
INSERT INTO `consent` (`ConsentID`, `Name`, `Label`) VALUES (3,'bread_consent','Consent to Bread');
INSERT INTO `consent` (`ConsentID`, `Name`, `Label`, `ConsentGroupID`) VALUES (1,'study_consent','Consent to Study', '1');
INSERT INTO `consent` (`ConsentID`, `Name`, `Label`, `ConsentGroupID`) VALUES (2,'raisin_consent','Consent to Raisin', '2');
INSERT INTO `consent` (`ConsentID`, `Name`, `Label`, `ConsentGroupID`) VALUES (3,'bread_consent','Consent to Bread', '2');
UNLOCK TABLES;
SET FOREIGN_KEY_CHECKS=1;
7 changes: 7 additions & 0 deletions raisinbread/RB_files/RB_consent_group.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE `consent_group`;
LOCK TABLES `consent_group` WRITE;
INSERT INTO `consent_group` (`ConsentGroupID`, `Name`, `Label`) VALUES (1,'study_consent_form','Study Information and Consent Form');
INSERT INTO `consent_group` (`ConsentGroupID`, `Name`, `Label`) VALUES (2,'bakery_consent_form','Bakery Information and Consent Form');
UNLOCK TABLES;
SET FOREIGN_KEY_CHECKS=1;

0 comments on commit d2c1bbb

Please sign in to comment.