Skip to content

Commit e16fb67

Browse files
authored
[new_profile] Fix date requirements and formats with EDC (#8767)
Fixed NewProfileIndex to use the correct variable containing the EDC date To create a candidate, the date of birth for a candidate is now required only when useEDC = no in Candidate.class.inc. If useEDC = yes, DoB is null unless it's specified. Added the validation of the EDC date format If the Ym format is selected in the configuration, added a '-15' to the end of the EDC date to be compatible with the SQL type date Resolves #8742
1 parent f768560 commit e16fb67

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

modules/new_profile/jsx/NewProfileIndex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class NewProfileIndex extends React.Component {
101101
};
102102

103103
if (this.state.configData['edc'] === 'true') {
104-
candidateObject.Candidate.EDC = formData.edc;
104+
candidateObject.Candidate.EDC = formData.edcDate;
105105
}
106106
if (this.state.configData['pscidSet'] === 'true') {
107107
candidateObject.Candidate.PSCID = formData.pscid;

php/libraries/Candidate.class.inc

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ define('PSCID_INVALID_STRUCTURE', 4);
1919
define('EDC_NOT_SPECIFIED', 5);
2020
define('DOB_NOT_SPECIFIED', 6);
2121
define('DOB_INVALID', 7);
22+
define('EDC_INVALID', 8);
2223

2324
/**
2425
* Wrapper around a candidate in Loris. Mostly, it gets information
@@ -268,35 +269,58 @@ class Candidate implements \LORIS\StudyEntities\AccessibleResource,
268269
$PSCIDSettings = $config->getSetting('PSCID');
269270
$useEDC = $config->getSetting('useEDC');
270271

271-
if (($useEDC === '1' || $useEDC === 'true') && empty($edc)) {
272-
throw new \LorisException(
273-
"EDC must be specified",
274-
EDC_NOT_SPECIFIED
275-
);
276-
}
277-
if (empty($dateOfBirth)) {
278-
throw new InvalidArgumentException(
279-
"Date of Birth must be specified",
280-
DOB_NOT_SPECIFIED
281-
);
282-
}
283-
284272
// Get expected format from config
285273
$dobFormat = $config->getSetting('dobFormat');
286274
$dobFormat = '!' . implode("-", str_split($dobFormat, 1));
287-
$dob = DateTime::createFromFormat($dobFormat, $dateOfBirth);
288275

289-
if ($dob === false) {
290-
throw new InvalidArgumentException(
291-
"Date of Birth is invalid (expected format: YYYY-MM-DD)",
292-
DOB_INVALID
293-
);
276+
if (($useEDC === '1' || $useEDC === 'true')) {
277+
if (empty($edc)) {
278+
throw new \LorisException(
279+
"EDC must be specified",
280+
EDC_NOT_SPECIFIED
281+
);
282+
} else {
283+
// Check valid format
284+
$edcDate = DateTime::createFromFormat($dobFormat, $edc);
285+
if ($edcDate === false) {
286+
throw new InvalidArgumentException(
287+
"EDC is invalid (expected format: YYYY-MM-DD)",
288+
EDC_INVALID
289+
);
290+
}
291+
292+
// Add day as first of the month if Y-m dob format
293+
// This allows insert into sql candidate table
294+
if ($dobFormat === '!Y-m') {
295+
$edc .= '-15';
296+
}
297+
}
294298
}
295299

296-
// Add day as first of the month if Y-m dob format
297-
// This allows insert into sql candidate table
298-
if ($dobFormat === '!Y-m') {
299-
$dateOfBirth .= '-15';
300+
if (empty($dateOfBirth)) {
301+
// DoB not required if useEDC is on
302+
if (!($useEDC === '1' || $useEDC === 'true')) {
303+
throw new InvalidArgumentException(
304+
"Date of Birth must be specified",
305+
DOB_NOT_SPECIFIED
306+
);
307+
} else {
308+
$dateOfBirth = null;
309+
}
310+
} else {
311+
$dob = DateTime::createFromFormat($dobFormat, $dateOfBirth);
312+
if ($dob === false) {
313+
throw new InvalidArgumentException(
314+
"Date of Birth is invalid (expected format: YYYY-MM-DD)",
315+
DOB_INVALID
316+
);
317+
}
318+
319+
// Add day as first of the month if Y-m dob format
320+
// This allows insert into sql candidate table
321+
if ($dobFormat === '!Y-m') {
322+
$dateOfBirth .= '-15';
323+
}
300324
}
301325

302326
if ($PSCIDSettings['generation'] == 'user') {

0 commit comments

Comments
 (0)