Skip to content

Commit 371fc10

Browse files
committed
[candidate_parameters] Add date precision field for DoD
1 parent d86a46f commit 371fc10

4 files changed

Lines changed: 38 additions & 7 deletions

File tree

SQL/0000-00-00-schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ CREATE TABLE `candidate` (
159159
`ExternalID` varchar(255) DEFAULT NULL,
160160
`DoB` date DEFAULT NULL,
161161
`DoD` date DEFAULT NULL,
162+
`DoD_precision` enum('known_year_month','known_year','unknown') DEFAULT NULL,
162163
`EDC` date DEFAULT NULL,
163164
`Sex` varchar(255) DEFAULT NULL,
164165
`RegistrationCenterID` integer unsigned NOT NULL,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE candidate
2+
ADD COLUMN DoD_precision enum('known_year_month','known_year','unknown') DEFAULT NULL AFTER DoD;

modules/candidate_parameters/ajax/formHandler.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,14 +630,20 @@ function editCandidateDOB(\Database $db): void
630630
function editCandidateDOD(\Database $db): void
631631
{
632632
$candID = new CandID($_POST['candID']);
633-
$dod = new DateTime($_POST['dod']);
633+
$dod = array_key_exists('dod', $_POST) ?
634+
new DateTime($_POST['dod']) : null;
635+
$precision = $_POST['dod_precision'];
634636
$strippedDate = null;
635637
$dodString = null;
636638

637-
if (!$dod) {
639+
if (!$dod && $precision !== 'unknown') {
638640
throw new \LorisException('Date not valid.');
639641
}
642+
if (!$precision) {
643+
throw new \LorisException('Date of Death precision must be specified.');
644+
}
640645

646+
$updateData = [];
641647
if (!empty($dod)) {
642648
$config = \NDB_Config::singleton();
643649
$dodFormat = $config->getSetting('dodFormat');
@@ -646,10 +652,17 @@ function editCandidateDOD(\Database $db): void
646652
} else {
647653
$dodString = $dod->format('Y-m-d');
648654
}
655+
$updateData['DoD'] = $strippedDate ?? $dodString;
656+
} else {
657+
$updateData['DoD'] = null;
658+
}
659+
660+
if ($precision) {
661+
$updateData['DoD_precision'] = $precision;
649662
$db->update(
650663
'candidate',
651-
['DoD' => $strippedDate ?? $dodString],
652-
['ID' => $candID->__toString()]
664+
$updateData,
665+
['CandID' => $candID->__toString()]
653666
);
654667
}
655668
}

modules/candidate_parameters/jsx/CandidateDOD.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
StaticElement,
1010
DateElement,
1111
ButtonElement,
12+
SelectElement,
1213
} from 'jsx/Form';
1314

1415
/**
@@ -95,6 +96,12 @@ class CandidateDOD extends Component {
9596
disabled = false;
9697
updateButton = <ButtonElement label={t('Update', {ns: 'loris'})}/>;
9798
}
99+
let precisionOptions = {
100+
'known_year_month' : t('Known year and month'),
101+
'known_year' : t('Known year'),
102+
'unknown' : t('Unknown date'),
103+
};
104+
let required = this.state.formData.dod_precision != 'unknown';
98105

99106
return (
100107
<div className='row'>
@@ -121,14 +128,23 @@ class CandidateDOD extends Component {
121128
}
122129
class='form-control-static text-danger bg-danger col-sm-10'
123130
/>
131+
<SelectElement
132+
label={t('Precision of date:')}
133+
name='dod_precision'
134+
options={precisionOptions}
135+
value={this.state.formData.dod_precision}
136+
onUserInput={this.setFormData}
137+
disabled={disabled}
138+
required={true}
139+
/>
124140
<DateElement
125141
label={t('Date Of Death:', {ns: 'candidate_parameters'})}
126142
name='dod'
127143
dateFormat={dateFormat}
128144
value={this.state.formData.dod}
129145
onUserInput={this.setFormData}
130-
disabled={disabled}
131-
required={true}
146+
disabled={disabled || !required}
147+
required={required}
132148
/>
133149
{updateButton}
134150
</FormElement>
@@ -194,7 +210,6 @@ class CandidateDOD extends Component {
194210
}
195211

196212
formObject.append('tab', this.props.tabName);
197-
198213
fetch(this.props.action, {
199214
method: 'POST',
200215
cache: 'no-cache',

0 commit comments

Comments
 (0)