Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ CREATE TABLE `candidate` (
`ExternalID` varchar(255) DEFAULT NULL,
`DoB` date DEFAULT NULL,
`DoD` date DEFAULT NULL,
`DoD_precision` enum('known_year_month','known_year','unknown') DEFAULT NULL,
`EDC` date DEFAULT NULL,
`Sex` varchar(255) DEFAULT NULL,
`RegistrationCenterID` integer unsigned NOT NULL,
Expand Down
2 changes: 2 additions & 0 deletions SQL/New_patches/2026-03-17-DoD-precision-field.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE candidate
ADD COLUMN DoD_precision enum('known_year_month','known_year','unknown') DEFAULT NULL AFTER DoD;
21 changes: 17 additions & 4 deletions modules/candidate_parameters/ajax/formHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,20 @@ function editCandidateDOB(\Database $db): void
function editCandidateDOD(\Database $db): void
{
$candID = new CandID($_POST['candID']);
$dod = new DateTime($_POST['dod']);
$dod = array_key_exists('dod', $_POST) ?
new DateTime($_POST['dod']) : null;
$precision = $_POST['dod_precision'];
$strippedDate = null;
$dodString = null;

if (!$dod) {
if (!$dod && $precision !== 'unknown') {
throw new \LorisException('Date not valid.');
}
if (!$precision) {
throw new \LorisException('Date of Death precision must be specified.');
}

$updateData = [];
if (!empty($dod)) {
$config = \NDB_Config::singleton();
$dodFormat = $config->getSetting('dodFormat');
Expand All @@ -646,10 +652,17 @@ function editCandidateDOD(\Database $db): void
} else {
$dodString = $dod->format('Y-m-d');
}
$updateData['DoD'] = $strippedDate ?? $dodString;
} else {
$updateData['DoD'] = null;
}

if ($precision) {
$updateData['DoD_precision'] = $precision;
$db->update(
'candidate',
['DoD' => $strippedDate ?? $dodString],
['ID' => $candID->__toString()]
$updateData,
['CandID' => $candID->__toString()]
);
}
}
19 changes: 13 additions & 6 deletions modules/candidate_parameters/ajax/getData.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,13 @@ function getDODFields(): array
$db = \NDB_Factory::singleton()->database();

$candidateData = $db->pselectRow(
'SELECT PSCID,DoD, DoB FROM candidate where CandID =:candid',
'SELECT
PSCID,
DoD,
DoD_precision,
DoB
FROM candidate
WHERE CandID =:candid',
['candid' => $candID]
);
if ($candidateData === null) {
Expand Down Expand Up @@ -606,11 +612,12 @@ function getDODFields(): array
$dob = $dobDate ? $dobDate->format($dobProcessedFormat) : null;

$result = [
'pscid' => $candidateData['PSCID'],
'candID' => $candID->__toString(),
'dod' => $dod,
'dob' => $dob,
'dodFormat' => $config->getSetting('dodFormat'),
'pscid' => $candidateData['PSCID'],
'candID' => $candID->__toString(),
'dod' => $dod,
'dob' => $dob,
'dod_precision' => $candidateData['DoD_precision'],
'dodFormat' => $config->getSetting('dodFormat'),
];
return $result;
}
Expand Down
8 changes: 7 additions & 1 deletion modules/candidate_parameters/jsx/CandidateDOB.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class CandidateDOB extends Component {
}

let dateFormat = this.state.data.dobFormat;

let dobValue = this.state.formData.dob || '';
if (dateFormat == 'Ym' && this.state.formData.dob) {
dobValue = dobValue.slice(0, 7);
}

let disabled = true;
let updateButton = null;
if (loris.userHasPermission('candidate_dob_edit')) {
Expand Down Expand Up @@ -126,7 +132,7 @@ class CandidateDOB extends Component {
<DateElement
label={t('DoB', {ns: 'loris'})}
name='dob'
dateFormat={dateFormat}
dateFormat={dobValue}
value={this.state.formData.dob}
onUserInput={this.setFormData}
disabled={disabled}
Expand Down
41 changes: 36 additions & 5 deletions modules/candidate_parameters/jsx/CandidateDOD.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
StaticElement,
DateElement,
ButtonElement,
SelectElement,
} from 'jsx/Form';

/**
Expand Down Expand Up @@ -64,7 +65,13 @@ class CandidateDOD extends Component {
* @param {*} value
*/
setFormData(formElement, value) {
let formData = this.state.formData;
let formData = {...this.state.formData};

// Clear the DOD if indicated as unknown
if (formElement === 'dod_precision' && value === 'unknown') {
formData.dod = '';
}

formData[formElement] = value;
this.setState({
formData: formData,
Expand All @@ -88,14 +95,30 @@ class CandidateDOD extends Component {
return <Loader/>;
}

let dateFormat = this.state.data.dodFormat;
let disabled = true;
let updateButton = null;
if (loris.userHasPermission('candidate_dod_edit')) {
disabled = false;
updateButton = <ButtonElement label={t('Update', {ns: 'loris'})}/>;
}

let precisionOptions = {
'known_year_month': t('I know the year and month of death'),
'known_year': t('I know the year of death'),
'unknown': t('I do not know the date of death'),
};

let required = this.state.formData.dod_precision != 'unknown';

let dateFormat = this.state.data.dodFormat;

let dodValue = this.state.formData.dod || '';
if (dateFormat == 'Ymd') {
precisionOptions['known_full'] = t('I know the full date of death');
} else if (dateFormat == 'Ym' && this.state.formData.dod) {
dodValue = dodValue.slice(0, 7);
}

return (
<div className='row'>
<FormElement
Expand All @@ -121,14 +144,23 @@ class CandidateDOD extends Component {
}
class='form-control-static text-danger bg-danger col-sm-10'
/>
<SelectElement
label={t('Precision of date:')}
name='dod_precision'
options={precisionOptions}
value={this.state.formData.dod_precision}
onUserInput={this.setFormData}
disabled={disabled}
required={true}
/>
<DateElement
label={t('Date Of Death:', {ns: 'candidate_parameters'})}
name='dod'
dateFormat={dateFormat}
value={this.state.formData.dod}
onUserInput={this.setFormData}
disabled={disabled}
required={true}
disabled={disabled || !required}
required={required}
/>
{updateButton}
</FormElement>
Expand Down Expand Up @@ -194,7 +226,6 @@ class CandidateDOD extends Component {
}

formObject.append('tab', this.props.tabName);

fetch(this.props.action, {
method: 'POST',
cache: 'no-cache',
Expand Down
15 changes: 15 additions & 0 deletions modules/candidate_parameters/locale/candidate_parameters.pot
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,18 @@ msgstr ""

msgid "Comments: "
msgstr ""

msgid "I know the year and month of death"
msgstr ""

msgid "I know the year of death"
msgstr ""

msgid "I do not know the date of death"
msgstr ""

msgid "I know the full date of death"
msgstr ""

msgid "Precision of date:"
msgstr ""
Loading