Skip to content

Commit

Permalink
[SQL][Instrument List][Battery Manager] Move DDE Enabled to Test_Batt…
Browse files Browse the repository at this point in the history
…ery (#9264)

- Changed the logic for DDE being enabled to be moved from Config to Test_Battery so that it can be managed on a visit-instrument basis instead of just instrument.
- Modified Battery Manager to have a section for editing which battery has DDE enabled
  • Loading branch information
skarya22 authored Oct 31, 2024
1 parent 7523ece commit bf53274
Show file tree
Hide file tree
Showing 38 changed files with 463 additions and 338 deletions.
1 change: 1 addition & 0 deletions SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ CREATE TABLE `test_battery` (
`CenterID` int(11) default NULL,
`firstVisit` enum('Y','N') default NULL,
`instr_order` tinyint(4) default NULL,
`DoubleDataEntryEnabled` enum('Y','N') default 'N',
PRIMARY KEY (`ID`),
KEY `age_test` (`AgeMinDays`,`AgeMaxDays`,`Test_name`),
KEY `FK_test_battery_1` (`Test_name`),
Expand Down
1 change: 0 additions & 1 deletion SQL/0000-00-03-ConfigTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType,
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'useConsent', 'Enable if the study uses the loris architecture for consent', 1, 0, 'boolean', ID, 'Use consent', 16 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'additional_user_info', 'Display additional user profile fields on the User accounts page (e.g. Institution, Position, Country, Address)', 1, 0, 'boolean', ID, 'Additional user information', 17 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'excluded_instruments', "Instruments to be excluded from the Data Dictionary and download via the Data Query Tool", 1, 1, 'instrument', ID, 'Excluded instruments', 18 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'DoubleDataEntryInstruments', "Instruments for which double data entry should be enabled", 1, 1, 'instrument', ID, 'Double data entry instruments', 19 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'InstrumentResetting', 'Allows resetting of instrument data', 1, 0, 'boolean', ID, 'Instrument Resetting', 20 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'SupplementalSessionStatus', 'Display supplemental session status information on Timepoint List page', 1, 0, 'boolean', ID, 'Use Supplemental Session Status', 21 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'useScanDone', 'Used for identifying timepoints that have (or should have) imaging data', 1, 0, 'boolean', ID, 'Use Scan Done', 22 FROM ConfigSettings WHERE Name="study";
Expand Down
9 changes: 9 additions & 0 deletions SQL/New_patches/2024_05_13_Add_DDE_To_Battery.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE test_battery ADD COLUMN DoubleDataEntryEnabled enum("Y", "N") DEFAULT "N";

UPDATE test_battery SET DoubleDataEntryEnabled = 'Y' WHERE Test_name IN (
SELECT Value from Config WHERE ConfigID = (SELECT ID FROM ConfigSettings WHERE Name = 'DoubleDataEntryInstruments')
);

DELETE FROM Config WHERE ConfigID IN (SELECT ID FROM ConfigSettings WHERE Name = 'DoubleDataEntryInstruments');

DELETE FROM ConfigSettings WHERE Name = 'DoubleDataEntryInstruments';
2 changes: 2 additions & 0 deletions modules/api/docs/LorisRESTAPI_v0.0.4-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ Will return a JSON object of the form:
"FullName" : "Long Name",
"Subgroup" : "Subgroup Name",
"DoubleDataEntryEnabled" : boolean
"DoubleDataEntryVisits" : array
},
"Instrument2" : {
"FullName" : "Long Name",
"Subgroup" : "Subgroup Name",
"DoubleDataEntryEnabled" : boolean
"DoubleDataEntryVisits" : array
},
...
}
Expand Down
12 changes: 8 additions & 4 deletions modules/api/php/endpoints/project/instruments.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ class Instruments extends Endpoint implements \LORIS\Middleware\ETagCalculator
/**
* Contructor
*
* @param \Project $project The requested project
* @param \Project $project The requested project
* @param string $apiversion The version of the API being used
*/
public function __construct(\Project $project)
{
public function __construct(
\Project $project,
private string $apiversion = 'v0.0.3'
) {
$this->_project = $project;
}

Expand Down Expand Up @@ -146,7 +149,8 @@ class Instruments extends Endpoint implements \LORIS\Middleware\ETagCalculator

$array = (new \LORIS\api\Views\Project\Instruments(
$this->_project,
iterator_to_array($instruments)
iterator_to_array($instruments),
$this->apiversion
))->toArray();

$this->_cache = new \LORIS\Http\Response\JsonResponse($array);
Expand Down
4 changes: 3 additions & 1 deletion modules/api/php/endpoints/project/project.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Project extends Endpoint implements \LORIS\Middleware\ETagCalculator
}
}

$apiversion = $request->getAttribute("LORIS-API-Version") ?? "unknown";

// Delegate to sub-endpoints
$subendpoint = array_shift($pathparts);
switch ($subendpoint) {
Expand All @@ -110,7 +112,7 @@ class Project extends Endpoint implements \LORIS\Middleware\ETagCalculator
$handler = new Images($this->_project);
break;
case 'instruments':
$handler = new Instruments($this->_project);
$handler = new Instruments($this->_project, $apiversion);
break;
case 'visits':
$handler = new Visits($this->_project);
Expand Down
41 changes: 29 additions & 12 deletions modules/api/php/models/projectinstrumentsrow.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@ class ProjectInstrumentsRow implements \LORIS\Data\DataInstance
private $_fullname;
private $_subgroupname;
private $_isDDE;
private $_ddeVisits;

/**
* Create a new ProjectImagesRow.
*
* @param array $row An array of image properties
* @param array $row An array of image properties
* @param string $apiversion The version of the API being used
*/
public function __construct(array $row)
{
$shortname = $row['shortname'] ?? null;
$ddeinstruments = array_keys(\Utility::getAllDDEInstruments());
public function __construct(
array $row,
private string $apiversion = 'v0.0.3'
) {
$this->_shortname = $row['shortname'] ?? null;
$this->_ddeVisits = \NDB_BVL_Battery::getDDEVisitsForInstrument(
$this->_shortname
);

$this->_shortname = $shortname;
$this->_fullname = $row['fullname'] ?? null;
$this->_subgroupname = $row['subgroupname'] ?? null;
$this->_isDDE = in_array(
$shortname,
$ddeinstruments,
true
);
$this->_isDDE = count($this->_ddeVisits) > 0;
}

/**
Expand Down Expand Up @@ -88,18 +89,34 @@ class ProjectInstrumentsRow implements \LORIS\Data\DataInstance
return $this->_isDDE;
}

/**
* Accessor for ddeVisits.
*
* @return array
*/
public function getddeVisits(): array
{
return $this->_ddeVisits;
}

/**
* Implements \LORIS\Data\DataInstance interface for this row.
*
* @return array which can be serialized by json_encode()
*/
public function jsonSerialize() : array
{
return [
$obj = [
'shortname' => $this->_shortname,
'fullname' => $this->_fullname,
'subgroup' => $this->_subgroupname,
'ddeenable' => $this->_isDDE,
'ddevisits' => $this->_ddeVisits,
];
if ($this->apiversion != 'v0.0.3') {
// api version >= v0.0.4
$obj['ddevisits'] = $this->_ddeVisits;
}
return $obj;
}
}
12 changes: 10 additions & 2 deletions modules/api/php/views/project/instruments.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ class Instruments
*
* @param \Project $project The requested project
* @param ProjectInstrumentsRow[] $instruments An array of ProjectInstrumentsRow
* @param string $apiversion The version of the API being used
*/
public function __construct(\Project $project, array $instruments)
{
public function __construct(
\Project $project,
array $instruments,
private string $apiversion = 'v0.0.3'
) {
$this->_project = $project;
$this->_instruments = $instruments;
}
Expand All @@ -70,6 +74,10 @@ class Instruments
'Subgroup' => $instrument->getSubgroupname(),
'DoubleDataEntryEnabled' => $instrument->isDDE(),
];
if ($this->apiversion != 'v0.0.3') {
// >= v0.0.4
$item['DoubleDataEntryVisits'] = $instrument->getddeVisits();
}

if (!is_null($shortname)) {
$instruments[$shortname] = $item;
Expand Down
8 changes: 8 additions & 0 deletions modules/battery_manager/jsx/batteryManagerForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ class BatteryManagerForm extends Component {
max={127} // max value allowed by default column type of instr_order
value={test.instrumentOrder}
/>
<SelectElement
name="DoubleDataEntryEnabled"
label="Enable Double Data Entry"
options={options.DoubleDataEntryEnabled}
onUserInput={setTest}
required={false}
value={test.DoubleDataEntryEnabled}
/>
<ButtonElement
label="Submit"
/>
Expand Down
9 changes: 8 additions & 1 deletion modules/battery_manager/jsx/batteryManagerIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ class BatteryManagerIndex extends Component {
name: 'instrumentOrder',
type: 'text',
}},
{label: 'Double Data Entry Enabled', show: true, filter: {
name: 'DoubleDataEntryEnabled',
type: 'select',
options: options.DoubleDataEntryEnabled,
}},
{label: 'Active', show: true, filter: {
name: 'active',
type: 'select',
Expand Down Expand Up @@ -365,6 +370,7 @@ class BatteryManagerIndex extends Component {
test.centerId,
test.firstVisit,
test.instrumentOrder,
test.DoubleDataEntryEnabled,
test.active,
];
});
Expand Down Expand Up @@ -420,7 +426,8 @@ class BatteryManagerIndex extends Component {
test.cohort == testCheck.cohort &&
test.visitLabel == testCheck.visitLabel &&
test.centerId == testCheck.centerId &&
test.firstVisit == testCheck.firstVisit
test.firstVisit == testCheck.firstVisit &&
test.DoubleDataEntryEnabled == testCheck.DoubleDataEntryEnabled
) {
duplicate = testCheck;
}
Expand Down
24 changes: 13 additions & 11 deletions modules/battery_manager/php/test.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ class Test implements
public function toSQL() : array
{
return [
'ID' => $this->row['id'] ?? null,
'Test_name' => $this->row['testName'] ?? null,
'AgeMinDays' => $this->row['ageMinDays'] ?? null,
'AgeMaxDays' => $this->row['ageMaxDays'] ?? null,
'Stage' => $this->row['stage'] ?? null,
'CohortID' => $this->row['cohort'] ?? null,
'Visit_label' => $this->row['visitLabel'] ?? null,
'CenterID' => $this->row['centerId'] ?? null,
'firstVisit' => $this->row['firstVisit'] ?? null,
'instr_order' => $this->row['instrumentOrder'] ?? null,
'Active' => $this->row['active'] ?? null,
'ID' => $this->row['id'] ?? null,
'Test_name' => $this->row['testName'] ?? null,
'AgeMinDays' => $this->row['ageMinDays'] ?? null,
'AgeMaxDays' => $this->row['ageMaxDays'] ?? null,
'Stage' => $this->row['stage'] ?? null,
'CohortID' => $this->row['cohort'] ?? null,
'Visit_label' => $this->row['visitLabel'] ?? null,
'CenterID' => $this->row['centerId'] ?? null,
'firstVisit' => $this->row['firstVisit'] ?? null,
'DoubleDataEntryEnabled' => $this->row['DoubleDataEntryEnabled']
?? null,
'instr_order' => $this->row['instrumentOrder'] ?? null,
'Active' => $this->row['active'] ?? null,
];
}
}
4 changes: 3 additions & 1 deletion modules/battery_manager/php/testendpoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ class TestEndpoint extends \NDB_Page implements RequestHandlerInterface
CohortID,
Visit_label,
CenterID,
firstVisit
firstVisit,
DoubleDataEntryEnabled as DDE_enabled
FROM test_battery";
// Select duplicate entry from Test Battery
$entries = $this->db->pselect($query, []);
Expand All @@ -235,6 +236,7 @@ class TestEndpoint extends \NDB_Page implements RequestHandlerInterface
&& $testArray['Visit_label'] == $entry['Visit_label']
&& $testArray['CenterID'] == $entry['CenterID']
&& $testArray['firstVisit'] == $entry['firstVisit']
&& $testArray['DoubleDataEntryEnabled'] == $entry['DDE_enabled']
) {
return true;
}
Expand Down
15 changes: 8 additions & 7 deletions modules/battery_manager/php/testoptionsendpoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ class TestOptionsEndpoint extends \NDB_Page
$this->loris->getDatabaseConnection()
);
return [
'instruments' => \NDB_BVL_Instrument::getInstrumentNamesList(
'instruments' => \NDB_BVL_Instrument::getInstrumentNamesList(
$this->loris
),
'stages' => $this->_getStageList(),
'cohorts' => \Utility::getCohortList(null),
'visits' => $visitController->getVisitlabels(),
'sites' => \Utility::getSiteList(false),
'firstVisit' => $this->_getYesNoList(),
'active' => $this->_getYesNoList(),
'stages' => $this->_getStageList(),
'cohorts' => \Utility::getCohortList(null),
'visits' => $visitController->getVisitlabels(),
'sites' => \Utility::getSiteList(false),
'firstVisit' => $this->_getYesNoList(),
'DoubleDataEntryEnabled' => $this->_getYesNoList(),
'active' => $this->_getYesNoList(),
];
}

Expand Down
1 change: 1 addition & 0 deletions modules/battery_manager/php/testprovisioner.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TestProvisioner extends \LORIS\Data\Provisioners\DBRowProvisioner
b.Visit_label as visitLabel,
p.CenterID as centerId,
b.firstVisit,
b.DoubleDataEntryEnabled,
b.instr_order as instrumentOrder,
b.Active as active
FROM test_battery b
Expand Down
10 changes: 5 additions & 5 deletions modules/battery_manager/test/BatteryManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function testLoadsWithPermissionEdit()
);
$this->safeClick(
WebDriverBy::cssSelector(
"#dynamictable > tbody > tr:nth-child(1) > td:nth-child(13) > button"
"#dynamictable > tbody > tr:nth-child(1) > td:nth-child(14) > button"
)
);
$bodyText = $this->safeFindElement(
Expand All @@ -165,7 +165,7 @@ function testEditform()
$this->safeGet($this->url . "/battery_manager/");
$this->safeClick(
WebDriverBy::cssSelector(
"#dynamictable > tbody > tr > td:nth-child(13) > button"
"#dynamictable > tbody > tr > td:nth-child(14) > button"
)
);
$this->safeClick(
Expand Down Expand Up @@ -209,7 +209,7 @@ function testEditform()
$this->safeClick(
WebDriverBy::cssSelector(
"#lorisworkspace>div>div:nth-child(2)>div>div:nth-child(2)>form>".
" div > div:nth-child(11) > div > div > button"
" div > div:nth-child(12) > div > div > button"
)
);
$bodyText = $this->safeFindElement(
Expand Down Expand Up @@ -264,7 +264,7 @@ function testAddNew()
$this->safeClick(
WebDriverBy::cssSelector(
"#lorisworkspace > div >div:nth-child(2)>div>div:nth-child(2)>form ".
"> div > div:nth-child(11) > div > div > button"
"> div > div:nth-child(12) > div > div > button"
)
);
$bodyText = $this->safeFindElement(
Expand All @@ -286,7 +286,7 @@ function testActivebtn()
$this->safeGet($this->url . "/battery_manager/");
$this->safeClick(
WebDriverBy::cssSelector(
"#dynamictable > tbody > tr:nth-child(1) > td:nth-child(12) > button"
"#dynamictable > tbody > tr:nth-child(1) > td:nth-child(13) > button"
)
);
$bodyText = $this->safeFindElement(
Expand Down
Loading

0 comments on commit bf53274

Please sign in to comment.