Skip to content

Commit

Permalink
Create module Battery Manager
Browse files Browse the repository at this point in the history
made sure everything is functional

minor format change

fixed error in code

reverted Modal form to original state

fixed user perm rel file
  • Loading branch information
Victoria Foing authored and HenriRabalais committed Feb 4, 2020
1 parent d4dafd1 commit 5165a39
Show file tree
Hide file tree
Showing 21 changed files with 1,662 additions and 1 deletion.
1 change: 1 addition & 0 deletions SQL/0000-00-02-Modules.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CREATE TABLE `modules` (

INSERT INTO modules (Name, Active) VALUES ('acknowledgements', 'Y');
INSERT INTO modules (Name, Active) VALUES ('api', 'Y');
INSERT INTO modules (Name, Active) VALUES ('battery_manager', 'Y');
INSERT INTO modules (Name, Active) VALUES ('behavioural_qc', 'Y');
INSERT INTO modules (Name, Active) VALUES ('brainbrowser', 'Y');
INSERT INTO modules (Name, Active) VALUES ('bvl_feedback', 'Y');
Expand Down
27 changes: 27 additions & 0 deletions SQL/New_patches/2018-07-23-battery_manager_permissions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Add view permission for battery manager
INSERT INTO permissions (code, description, categoryID)
VALUES (
'battery_manager_view',
'View Battery Manager',
(SELECT ID FROM permissions_category WHERE Description = 'Permission')
);

-- Add edit permission for battery manager
INSERT INTO permissions (code, description, categoryID)
VALUES (
'battery_manager_edit',
'Add, activate, and deactivate entries in Test Battery',
(SELECT ID FROM permissions_category WHERE Description = 'Permission')
);

-- Give view permission to admin
INSERT INTO user_perm_rel (userID, permID)
SELECT ID, permID FROM users u JOIN permissions p
WHERE UserID='admin' AND code = 'battery_manager_view';

-- Give edit permission to admin
INSERT INTO user_perm_rel (userID, permID)
SELECT ID, permID FROM users u JOIN permissions p
WHERE UserID='admin' AND code = 'battery_manager_edit';

INSERT INTO modules (Name, Active) VALUES ('battery_manager', 'Y');
1 change: 1 addition & 0 deletions jsx/FilterableDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ FilterableDataTable.propTypes = {
name: PropTypes.string.isRequired,
title: PropTypes.string,
data: PropTypes.object.isRequired,
filterPresets: PropTypes.object,
fields: PropTypes.object.isRequired,
columns: PropTypes.number,
getFormattedCell: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion jsx/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ class NumericElement extends Component {
id={this.props.id}
min={this.props.min}
max={this.props.max}
value={this.props.value}
value={this.props.value || ''}
disabled={disabled}
required={required}
onChange={this.handleChange}
Expand Down
1 change: 1 addition & 0 deletions modules/battery_manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
js/batteryManagerIndex.js
27 changes: 27 additions & 0 deletions modules/battery_manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Battery Manager

## Purpose
The Battery Manager module allows users to **browse**, **add**,
**edit**, **activate** and **deactivate** entries in the Test Battery. The
Test Battery is used to determine which Instruments are administered at
different timepoints.

## Intended Users
The Battery Manager module is used by study
administrators.

## Scope
The Battery Manager module provides a tool for browsing, adding,
editing, activating, and deactivating entries in the the Test Battery.

#### Interactions with LORIS
Changes, additions and deletion of data in this module affects the test
battery assigned to a candidate at each timepoint

## Permissions
In order to use the Battery Manager module the user needs
one or both of the following permissions:
- `battery_manager_view`: gives user read-only access to Battery Manager
module (browsing the Test Battery).
- `battery_manager_edit`: gives user edit access to Battery
Manager module (add/edit/activate/deactivate entries in Test Battery).
116 changes: 116 additions & 0 deletions modules/battery_manager/help/battery_manager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Battery Manager
The Battery Manager module serves as a front-end for manipulating the Test Battery.
This includes browsing, adding, editing, activating, and deactivating entries.

## Searching for an entry in the Test Battery
Under the `Browse` tab, use the `Selection Filters` to search for entries by fields such as:
`Instrument`,
`Minimum age (days)`,
`Maximum age (days)`,
`Stage`,
`Subproject`,
`Visit Label`,
`Site`,
`First Visit`,
`Instrument Order`,
`Active`.
As filters are selected, the data table below will dynamically update with relevant results.
Click the **Clear Filters** button to reset all filters.

Within the data table, results can be sorted in ascending or descending order by
clicking on any column header.

## Adding an entry to the Test Battery
Under the `Add` tab, you can add a new entry to the Test Battery.
You can specify information about the entry by using the searchable dropdowns, dropdown menus, and numeric text fields.
You will have to fill out the required fields `Instrument`, `Minimum age (days)`, `Maximum age (days)`, and `Stage`.
Finally, press the **Add entry** button to add the entry to the Test Battery.
You cannot add an entry if it has a duplicate entry in the Test Battery.

*For more information on the behaviour of each parameter refer to the [Behaviour of Parameters](#behaviour-of-parameters) section of this document*

## Editing an entry to the Test Battery
Under the `Browse` tab, you can edit an entry by clicking on the `Edit` link in the `Edit Metadata` column of the Menu Table.
The link will display a form that is populated with the values of the entry.
You can update information in the form by selecting from the dropdown menus and filling in the numeric text fields.
You will have to fill out the required fields `Instrument`, `Minimum age (days)`, `Maximum age (days)`, `Stage`, and `Active`.
Finally, press the **Edit entry** button to edit the entry in the Test Battery.
You cannot edit an entry if you make no changes in the form.
You cannot edit an entry if it becomes the same as another active entry in the Test Battery.

*For more information on the behaviour of each parameter refer to the [Behaviour of Parameters](#behaviour-of-parameters) section of this document*

## Activating/Deactivating an entry in the Test Battery

### Browse tab (activate/deactivate)
In the `Change Status` column of the Menu Table, you press the **Activate** or
**Deactivate** button to directly change the status of an entry.

### Add tab (activate)
Under the `Add` tab, you can add an entry that already exists in the Test
Battery but has been deactivated. A pop up will appear that will give you
the option to activate the existing entry.

### Edit window (activate/deactivate)
Select an entry in the Menu table and click on `Edit`.
In the `Edit` window, edit an entry and make sure the new entry has no duplicate in the Test Battery.
This will add the new entry to the table and deactivate the original one.
Alternatively, edit an entry so that it becomes the same as another deactivated entry in the Test Battery.
A pop up will appear that will give you the option to activate the other entry and deactivate the original one.

## Behaviour of Parameters

### Subproject:
- If the test battery entry does NOT have a `subprojectID`
(`subprojectID=NULL`), the instrument gets administered to ALL subprojects.
- If the test battery entry has a `subprojectID` set and the `subprojectID`
matches the one of the timepoint, the instrument is administered only to
that subproject.

### Stage:
- If the test battery entry has a `stage` set and the `stage` matches the
one of the timepoint, the instrument is administered at that stage.

### Center:
- If the test battery entry does NOT have a `CenterID` (`CenterID=NULL`),
the instrument gets administered at ALL centers.
- If the test battery entry has a `CenterID` set and the `CenterID` matches
the one of the timepoint, the instrument is administered at that CenterID.

### AgeMinDays/AgeMaxDays:
- If the test battery entry has `AgeMinDays` and `AgeMaxDays` set and they
are both set to `0`, the instrument gets administered at ALL ages;
- If the test battery entry has `AgeMinDays` and `AgeMaxDays` set and they
are set to any value other than `0`, the instrument gets administered IF AND
ONLY IF the age of the candidate at the timepoint is between `AgeMinDays`
and `AgeMaxDays`;

### VisitLabel:
- If the test battery entry does NOT have a `Visit_label`
(`Visit_label=NULL`), the instrument gets administered IF AND ONLY IF no
other test battery entries matches the timepoint's visit label and
subproject.
- If the test battery entry has a `Visit_label` set and the `Visit_label`
matches the one of the timepoint, the instrument is administered at that
Visit.
- **NOTE:** *In order to administer an instrument at all visits without
defining each visit individually in the battery, the test battery table
should NOT contain any entries for the subproject/visit_label combination
of the timepoint. If the timepoint's subproject/visit_label combination
has a specified set of instruments defined in the test_battery, all entries
of the battery with no visit labels (`Visit_label=NULL`) will be ignored.*

### FirstVisit:
- If `firstVisit` is set to `Y`, the test battery instance is applied
only if it is the first visit.
- If `firstVisit` is to `N`, the test battery instance is applied only if it
*not* the first visit.
- If `firstVisit` is set to null, the test battery instance is applied to any
visit.
- **NOTE:** *The `firstVisit` flag can allow to bypass all other rules in
some instances. In these instances, the `stage`, `CenterID`, `Visit_label`,
`AgeMinDays` and `AgeMaxDays` will not affect in any way the administration
of the instrument. Only the `subprojectID` value will impact if the
instrument gets administered or not; the `subprojectID` value must match
the timepoint's in order for the instrument to be administered in these
instances.*
143 changes: 143 additions & 0 deletions modules/battery_manager/jsx/batteryManagerForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';

/**
* Battery Manager Form
*
* Module component rendering Add tab
*
* @author Victoria Foing
*
*/
class BatteryManagerForm extends Component {
/**
* Render function
*
* @return {*}
*/
render() {
const {test, options, setTest, add} = this.props;

// Inform users about duplicate entries
const renderHelpText = () => {
if (add) {
return (
<span>
You cannot add an entry if it has a duplicate entry in the test
battery.<br/>
If the duplicate entry is inactive, you will be given the option
to activate it.
</span>
);
} else {
return (
<span>
Editing an entry will deactivate the current entry and create a
new entry.<br/>
You cannot edit an entry to have the same values as another active
entry.<br/>
If the duplicate entry is inactive, you will be given the option
to active it.
<br/>
<br/>
</span>
);
}
};

return (
<FormElement>
<StaticElement
label="Note"
text={renderHelpText()}
/>
<SelectElement
name="testName"
label="Instrument"
placeHolder="Search for instrument"
options={options.instruments}
onUserInput={setTest}
required={true}
value={test.testName}
/>
<NumericElement
name="ageMinDays"
label="Minimum age (days)"
onUserInput={setTest}
min="0"
max="99999"
required={true}
value={test.ageMinDays}
/>
<NumericElement
name="ageMaxDays"
label="Maximum age (days)"
onUserInput={setTest}
min="0"
max="99999"
required={true}
value={test.ageMaxDays}
/>
<SelectElement
name="stage"
label="Stage"
options={options.stages}
onUserInput={setTest}
required={true}
value={test.stage}
/>
<SelectElement
name="subproject"
label="Subproject"
options={options.subprojects}
onUserInput={setTest}
required={false}
value={test.subproject}
/>
<SelectElement
name="visitLabel"
label="Visit Label"
options={options.visits}
onUserInput={setTest}
required={false}
value={test.visitLabel}
/>
<SelectElement
name="centerId"
label="Site"
placeHolder="Search for site"
options={options.sites}
strictSearch={true}
onUserInput={setTest}
required={false}
value={test.centerId}
/>
<SelectElement
name="firstVisit"
label="First Visit"
options={options.firstVisits}
onUserInput={setTest}
required={false}
value={test.firstVisit}
/>
<NumericElement
name="instrumentOrder"
label="Instrument Order"
onUserInput={setTest}
required={false}
min="0"
max="127" // max value allowed by default column type of instr_order
value={test.instrumentOrder}
/>
</FormElement>
);
}
}

BatteryManagerForm.propTypes = {
test: PropTypes.object.isRequired,
setTest: PropTypes.func.isRequired,
options: PropTypes.object.isRequired,
};

export default BatteryManagerForm;
Loading

0 comments on commit 5165a39

Please sign in to comment.