Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[configuration] Add date_format as DataType in ConfigSettings #6719

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -42,8 +42,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 @@ -182,8 +182,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
jesscall marked this conversation as resolved.
Show resolved Hide resolved
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');
6 changes: 3 additions & 3 deletions modules/candidate_parameters/ajax/formHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,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 @@ -578,7 +578,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 All @@ -589,4 +589,4 @@ function editCandidateDOD(\Database $db): void
['CandID' => $candID->__toString()]
);
}
}
}
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',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be a good idea to show a more descriptive label for these on the frontend since it's a dropdown now?

Like 2015-12-29 (Ymd) and 2015-12 (Ym)?

(Date is arbitrary, just something that's unambiguous with the day of the month > 12.. I'm assuming m is numeric month, I haven't looked into it, but it would avoid that type of confusion for users to provide an example in the dropdown label..)

'Ym' => 'Ym'
];

$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