diff --git a/modules/new_profile/jsx/NewProfileIndex.js b/modules/new_profile/jsx/NewProfileIndex.js index 36731b1b207..789270161f0 100644 --- a/modules/new_profile/jsx/NewProfileIndex.js +++ b/modules/new_profile/jsx/NewProfileIndex.js @@ -101,7 +101,7 @@ class NewProfileIndex extends React.Component { }; if (this.state.configData['edc'] === 'true') { - candidateObject.Candidate.EDC = formData.edc; + candidateObject.Candidate.EDC = formData.edcDate; } if (this.state.configData['pscidSet'] === 'true') { candidateObject.Candidate.PSCID = formData.pscid; diff --git a/php/libraries/Candidate.class.inc b/php/libraries/Candidate.class.inc index 4e4eff48f71..049fb5d6eaa 100644 --- a/php/libraries/Candidate.class.inc +++ b/php/libraries/Candidate.class.inc @@ -19,6 +19,7 @@ define('PSCID_INVALID_STRUCTURE', 4); define('EDC_NOT_SPECIFIED', 5); define('DOB_NOT_SPECIFIED', 6); define('DOB_INVALID', 7); +define('EDC_INVALID', 8); /** * Wrapper around a candidate in Loris. Mostly, it gets information @@ -268,35 +269,58 @@ class Candidate implements \LORIS\StudyEntities\AccessibleResource, $PSCIDSettings = $config->getSetting('PSCID'); $useEDC = $config->getSetting('useEDC'); - if (($useEDC === '1' || $useEDC === 'true') && empty($edc)) { - throw new \LorisException( - "EDC must be specified", - EDC_NOT_SPECIFIED - ); - } - if (empty($dateOfBirth)) { - throw new InvalidArgumentException( - "Date of Birth must be specified", - DOB_NOT_SPECIFIED - ); - } - // Get expected format from config $dobFormat = $config->getSetting('dobFormat'); $dobFormat = '!' . implode("-", str_split($dobFormat, 1)); - $dob = DateTime::createFromFormat($dobFormat, $dateOfBirth); - if ($dob === false) { - throw new InvalidArgumentException( - "Date of Birth is invalid (expected format: YYYY-MM-DD)", - DOB_INVALID - ); + if (($useEDC === '1' || $useEDC === 'true')) { + if (empty($edc)) { + throw new \LorisException( + "EDC must be specified", + EDC_NOT_SPECIFIED + ); + } else { + // Check valid format + $edcDate = DateTime::createFromFormat($dobFormat, $edc); + if ($edcDate === false) { + throw new InvalidArgumentException( + "EDC is invalid (expected format: YYYY-MM-DD)", + EDC_INVALID + ); + } + + // Add day as first of the month if Y-m dob format + // This allows insert into sql candidate table + if ($dobFormat === '!Y-m') { + $edc .= '-15'; + } + } } - // Add day as first of the month if Y-m dob format - // This allows insert into sql candidate table - if ($dobFormat === '!Y-m') { - $dateOfBirth .= '-15'; + if (empty($dateOfBirth)) { + // DoB not required if useEDC is on + if (!($useEDC === '1' || $useEDC === 'true')) { + throw new InvalidArgumentException( + "Date of Birth must be specified", + DOB_NOT_SPECIFIED + ); + } else { + $dateOfBirth = null; + } + } else { + $dob = DateTime::createFromFormat($dobFormat, $dateOfBirth); + if ($dob === false) { + throw new InvalidArgumentException( + "Date of Birth is invalid (expected format: YYYY-MM-DD)", + DOB_INVALID + ); + } + + // Add day as first of the month if Y-m dob format + // This allows insert into sql candidate table + if ($dobFormat === '!Y-m') { + $dateOfBirth .= '-15'; + } } if ($PSCIDSettings['generation'] == 'user') {