Skip to content
New issue

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

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

Already on GitHub? # to your account

[new_profile] Fix date requirements and formats with EDC #8767

Merged
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
2 changes: 1 addition & 1 deletion modules/new_profile/jsx/NewProfileIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 47 additions & 23 deletions php/libraries/Candidate.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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') {
Expand Down