Skip to content

Commit

Permalink
[configuration] Add date_format as DataType in ConfigSettings (aces#6719
Browse files Browse the repository at this point in the history
)

Add "date_format" config format type for DoB and DoD, which configures whether day of month is included in date.

    Resolves aces#6678
  • Loading branch information
jesscall authored and AlexandraLivadas committed Jun 29, 2021
1 parent 582de8f commit 8620da2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
10 changes: 5 additions & 5 deletions SQL/0000-00-03-ConfigTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CREATE TABLE `ConfigSettings` (
`Description` varchar(255) DEFAULT NULL,
`Visible` tinyint(1) DEFAULT '0',
`AllowMultiple` tinyint(1) DEFAULT '0',
`DataType` ENUM('text', 'boolean', 'email', 'instrument', 'textarea', 'scan_type', 'lookup_center', 'path', 'web_path') DEFAULT NULL,
`DataType` ENUM('text','boolean','email','instrument','textarea','scan_type','date_format','lookup_center','path','web_path') DEFAULT NULL,
`Parent` int(11) DEFAULT NULL,
`Label` varchar(255) DEFAULT NULL,
`OrderNumber` int(11) DEFAULT NULL,
Expand Down Expand Up @@ -41,8 +41,8 @@ INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType,
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'endYear', "End year for study recruitment or data collection", 1, 0, 'text', ID, 'End year', 6 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'ageMin', 'Minimum candidate age in years (0+)', 1, 0, 'text', ID, 'Minimum candidate age', 7 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'ageMax', 'Maximum candidate age in years', 1, 0, 'text', ID, 'Maximum candidate age', 8 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'dobFormat', "Format of the Date of Birth", 1, 0, 'text', ID, 'DOB Format', 9 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'dodFormat', 'Format of the Date of Death', 1, 0, 'text', ID, 'DOD Format', 10 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'dobFormat', "Format of the Date of Birth", 1, 0, 'date_format', ID, 'DOB Format', 9 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'dodFormat', 'Format of the Date of Death', 1, 0, 'date_format', ID, 'DOD Format', 10 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'useProband', "Enable for proband data collection", 1, 0, 'boolean', ID, 'Use proband', 11 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'useFamilyID', 'Enable if family members are recruited for the study', 1, 0, 'boolean', ID, 'Use family', 12 FROM ConfigSettings WHERE Name="study";
INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'useExternalID', "Enable if data is used for blind data distribution, or from external data sources", 1, 0, 'boolean', ID, 'Use external ID', 13 FROM ConfigSettings WHERE Name="study";
Expand Down Expand Up @@ -179,8 +179,8 @@ INSERT INTO Config (ConfigID, Value) SELECT ID, "true" FROM ConfigSettings WHERE
INSERT INTO Config (ConfigID, Value) SELECT ID, 0 FROM ConfigSettings WHERE Name="ImagingUploaderAutoLaunch";
INSERT INTO Config (ConfigID, Value) SELECT ID, "Modify this to your project's citation policy" FROM ConfigSettings WHERE Name="citation_policy";
INSERT INTO Config (ConfigID, Value) SELECT ID, "" FROM ConfigSettings WHERE Name="CSPAdditionalHeaders";
INSERT INTO Config (ConfigID, Value) SELECT ID, "YMd" FROM ConfigSettings WHERE Name="dobFormat";
INSERT INTO Config (ConfigID, Value) SELECT ID, "YMd" FROM ConfigSettings WHERE Name="dodFormat";
INSERT INTO Config (ConfigID, Value) SELECT ID, "Ymd" FROM ConfigSettings WHERE Name="dobFormat";
INSERT INTO Config (ConfigID, Value) SELECT ID, "Ymd" FROM ConfigSettings WHERE Name="dodFormat";


INSERT INTO Config (ConfigID, Value) SELECT ID, "/data/%PROJECTNAME%/data/" FROM ConfigSettings WHERE Name="imagePath";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Add date_format option to DataType
ALTER TABLE ConfigSettings
MODIFY COLUMN `DataType` enum('text','boolean','email','instrument','textarea','scan_type','date_format','lookup_center','path','web_path') DEFAULT NULL;

-- Update DataType of dobFormat
UPDATE ConfigSettings
SET DataType='date_format' WHERE Name='dobFormat';

-- Update DataType of dodFormat
UPDATE ConfigSettings
SET DataType='date_format' WHERE Name='dodFormat';

-- Convert old date casing combos to supported format
UPDATE Config SET Value='Ymd'
WHERE LOWER(Value)='ymd'
AND ConfigID=(SELECT ID FROM ConfigSettings WHERE Name='dobFormat');

UPDATE Config SET Value='Ymd'
WHERE LOWER(Value)='ymd'
AND ConfigID=(SELECT ID FROM ConfigSettings WHERE Name='dodFormat');

UPDATE Config SET Value='Ym'
WHERE LOWER(Value)='ym'
AND ConfigID=(SELECT ID FROM ConfigSettings WHERE Name='dobFormat');

UPDATE Config SET Value='Ym'
WHERE LOWER(Value)='ym'
AND ConfigID=(SELECT ID FROM ConfigSettings WHERE Name='dodFormat');
4 changes: 2 additions & 2 deletions modules/candidate_parameters/ajax/formHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ function editCandidateDOB(\Database $db): void
if (!empty($dob)) {
$config = \NDB_Config::singleton();
$dobFormat = $config->getSetting('dobFormat');
if ($dobFormat === 'YM') {
if ($dobFormat === 'Ym') {
$strippedDate = date("Y-m", strtotime($dob))."-01";
}
$db->update(
Expand Down Expand Up @@ -581,7 +581,7 @@ function editCandidateDOD(\Database $db): void
if (!empty($dod)) {
$config = \NDB_Config::singleton();
$dodFormat = $config->getSetting('dodFormat');
if ($dodFormat === 'YM') {
if ($dodFormat === 'Ym') {
$strippedDate = $dod->format('Y-m-01');
} else {
$dodString = $dod->format('Y-m-d');
Expand Down
7 changes: 7 additions & 0 deletions modules/configuration/php/configuration.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class Configuration extends \NDB_Form
$scan_types[$val] = $val;
}

$date_format = [
'' => '',
'Ymd' => 'Ymd (EX: 2015-12-28)',
'Ym' => 'Ym (EX: 2015-12)'
];

$instruments = \Utility::getAllInstruments();
$instruments[''] = '';

Expand All @@ -69,6 +75,7 @@ class Configuration extends \NDB_Form
$this->tpl_data['instruments'] = $instruments;
$this->tpl_data['sandbox'] = $config->getSetting("sandbox");
$this->tpl_data['scan_types'] = $scan_types;
$this->tpl_data['date_format'] = $date_format;
$this->tpl_data['lookup_center'] = [
'' => '',
'PatientID' => 'PatientID',
Expand Down
12 changes: 12 additions & 0 deletions modules/configuration/templates/form_configuration.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
</select>
{/function}

{function name=createDateFormat}
<select class="form-control" name="{$k}" {if $d eq "Yes"}disabled{/if}>
{foreach from=$date_format key=name item=label}
<option {if $v eq $name}selected{/if} value="{$name}">{$label}</option>
{/foreach}
</select>
{/function}

{function name=createLookUpCenterNameUsing}
<select class="form-control" name="{$k}" {if $d eq "Yes"}disabled{/if}>
{foreach from=$lookup_center key=name item=label}
Expand Down Expand Up @@ -80,6 +88,8 @@
{call createInstrument k=$k v=$v d=$node['Disabled']}
{elseif $node['DataType'] eq 'scan_type'}
{call createScanType k=$k v=$v d=$node['Disabled']}
{elseif $node['DataType'] eq 'date_format'}
{call createDateFormat k=$k v=$v d=$node['Disabled']}
{elseif $node['DataType'] eq 'email'}
{call createEmail k=$k v=$v d=$node['Disabled']}
{elseif $node['DataType'] eq 'textarea'}
Expand All @@ -106,6 +116,8 @@
{call createInstrument k=$id d=$node['Disabled']}
{elseif $node['DataType'] eq 'scan_type'}
{call createScanType k=$id d=$node['Disabled']}
{elseif $node['DataType'] eq 'date_format'}
{call createDateFormat k=$id d=$node['Disabled']}
{elseif $node['DataType'] eq 'email'}
{call createEmail k=$id d=$node['Disabled']}
{elseif $node['DataType'] eq 'textarea'}
Expand Down

0 comments on commit 8620da2

Please sign in to comment.