Skip to content

Commit

Permalink
Merge pull request #26 from ridz1208/PULL_24.1_INTO_CBIG
Browse files Browse the repository at this point in the history
Pull 24.1 into cbig
  • Loading branch information
ridz1208 authored Sep 13, 2023
2 parents 8be2d34 + 22b5c3b commit 1b12234
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 51 deletions.
14 changes: 12 additions & 2 deletions modules/api/php/endpoints/candidates.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class Candidates extends Endpoint implements \LORIS\Middleware\ETagCalculator

$candidate = \NDB_Factory::singleton()->candidate($candID);

if (!$candidate->isAccessibleBy($user)) {
return new \LORIS\Http\Response\JSON\Forbidden();
}

$endpoint = new Candidate\Candidate($candidate);

$pathparts = array_slice($pathparts, 2);
Expand Down Expand Up @@ -241,8 +245,14 @@ class Candidates extends Endpoint implements \LORIS\Middleware\ETagCalculator
$pscid,
$project->getId()
);
} catch (\LorisException | \InvalidArgumentException $e) {
return new \LORIS\Http\Response\JSON\BadRequest($e->getMessage());
} catch (\ConflictException $e) {
return new \LORIS\Http\Response\JSON\Conflict(
$e->getMessage()
);
} catch (\Exception | \LorisException | \InvalidArgumentException $e) {
return new \LORIS\Http\Response\JSON\BadRequest(
$e->getMessage()
);
}

$candidate = \NDB_Factory::singleton()->candidate($candid);
Expand Down
4 changes: 2 additions & 2 deletions modules/api/php/views/visit/flags.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class Flags
public function toArray(): array
{
$instrumentname = $this->_instrument->testName;
$instrumentdata = $this->_instrument->getInstanceData();
$commentid = $this->_instrument->getCommentID() ?? '';

$isDDE = strpos($instrumentdata['CommentID'], 'DDE_') === 0;
$isDDE = strpos($commentid, 'DDE_') === 0;

$meta = [
'Candidate' => $this->_timepoint->getCandID(),
Expand Down
3 changes: 2 additions & 1 deletion modules/api/php/views/visit/instrument.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class Instrument
{
$instrumentname = $this->_instrument->testName;
$instrumentdata = $this->_instrument->getInstanceData();
$commentid = $this->_instrument->getCommentID() ?? '';

$isDDE = strpos($instrumentdata['CommentID'], 'DDE_') === 0;
$isDDE = strpos($commentid, 'DDE_') === 0;

$meta = [
'Candidate' => $this->_timepoint->getCandID(),
Expand Down
10 changes: 8 additions & 2 deletions modules/battery_manager/php/testoptionsendpoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @link https://www.github.com/aces/Loris/
*/
namespace LORIS\battery_manager;
use LORIS\VisitController;
use \Psr\Http\Message\ServerRequestInterface;
use \Psr\Http\Message\ResponseInterface;

Expand Down Expand Up @@ -58,11 +59,16 @@ class TestOptionsEndpoint extends \NDB_Page
*/
private function _getOptions() : array
{
$visitController = new VisitController(
$this->loris->getDatabaseConnection()
);
return [
'instruments' => \Utility::getAllInstruments(),
'instruments' => \NDB_BVL_Instrument::getInstrumentNamesList(
$this->loris
),
'stages' => $this->_getStageList(),
'subprojects' => \Utility::getSubprojectList(null),
'visits' => \Utility::getVisitList(),
'visits' => $visitController->getVisitlabels(),
'sites' => \Utility::getSiteList(false),
'firstVisit' => $this->_getYesNoList(),
'active' => $this->_getYesNoList(),
Expand Down
36 changes: 30 additions & 6 deletions modules/imaging_uploader/jsx/UploadForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,22 @@ class UploadForm extends Component {
let ids = patientName.split('_');
formData.candID = ids[1];
formData.pSCID = ids[0];
// visitLabel can contain underscores
// join the remaining elements of patientName and use as visitLabel
// visitLabel can contain underscores, filename can have suffix appended to PSCID_CandID_VisitLabel
// join the remaining elements of patientName and pattern match
// against each visit label. Use as visitLabel the best (longest) match
ids.splice(0, 2);
formData.visitLabel = ids.join('_');
const suffix = ids.join('_');
const visitLabels = Object.keys(form.visitLabel.options);
let bestMatch = '';
visitLabels.map((visitLabel) => {
if (suffix.match(visitLabel) !== null) {
// consider the first match only
if (suffix.match(visitLabel)[0].length > bestMatch.length) {
bestMatch = suffix.match(visitLabel)[0];
}
}
});
formData.visitLabel = bestMatch;
}
}

Expand All @@ -81,10 +93,22 @@ class UploadForm extends Component {
let ids = patientName.split('_');
formData.candID = ids[1];
formData.pSCID = ids[0];
// visitLabel can contain underscores
// join the remaining elements of patientName and use as visitLabel
// visitLabel can contain underscores, filename can have suffix appended to PSCID_CandID_VisitLabel
// join the remaining elements of patientName and pattern match
// against each visit label. Use as visitLabel the best (longest) match
ids.splice(0, 2);
formData.visitLabel = ids.join('_');
const suffix = ids.join('_');
const visitLabels = Object.keys(form.visitLabel.options);
let bestMatch = '';
visitLabels.map((visitLabel) => {
if (suffix.match(visitLabel) !== null) {
// consider the first match only
if (suffix.match(visitLabel)[0].length > bestMatch.length) {
bestMatch = suffix.match(visitLabel)[0];
}
}
});
formData.visitLabel = bestMatch;
}
}

Expand Down
8 changes: 4 additions & 4 deletions modules/issue_tracker/php/edit.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ class Edit extends \NDB_Page implements ETagCalculator
$historyValues = $this->getChangedValues($issueValues, $issueID, $user);

if (!empty($issueID)) {
$db->update('issues', $issueValues, ['issueID' => $issueID]);
$db->unsafeUpdate('issues', $issueValues, ['issueID' => $issueID]);
} else {
$issueValues['reporter'] = $user->getUsername();
$issueValues['dateCreated'] = date('Y-m-d H:i:s');
$db->insert('issues', $issueValues);
$db->unsafeInsert('issues', $issueValues);
$issueID = intval($db->getLastInsertId());
}

Expand Down Expand Up @@ -815,7 +815,7 @@ class Edit extends \NDB_Page implements ETagCalculator
'issueID' => $issueID,
'addedBy' => $user->getUsername(),
];
$db->insert('issues_history', $changedValues);
$db->unsafeInsert('issues_history', $changedValues);
}
}
}
Expand All @@ -838,7 +838,7 @@ class Edit extends \NDB_Page implements ETagCalculator
'addedBy' => $user->getUsername(),
'issueID' => $issueID,
];
$db->insert('issues_comments', $commentValues);
$db->unsafeInsert('issues_comments', $commentValues);
}
}

Expand Down
14 changes: 8 additions & 6 deletions modules/survey_accounts/js/survey_accounts_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ $(document).ready(function () {
// Handles cases where there was an error on the page and we're resubmitting
var email2 = $("input[name=Email2]").val();
var email = $("input[name=Email]").val();
if (email.length > 0 && email2.length > 0 && email == email2)
{
$('#email_survey').removeAttr('disabled');
} else {
$('#email_survey').attr('disabled','disabled');
if (email && email2) {
if (email.length > 0 && email2.length > 0 && email == email2)
{
$('#email_survey').removeAttr('disabled');
} else {
$('#email_survey').attr('disabled','disabled');
}
}
// Reset Test_name so that the template can be loaded by ajax below
$("select[name=Test_name]").val("");
Expand Down Expand Up @@ -93,7 +95,7 @@ $(document).ready(function () {
$("#emailContent").val(content);
}
);


});
});
6 changes: 5 additions & 1 deletion modules/survey_accounts/jsx/surveyAccountsIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ class SurveyAccountsIndex extends Component {
options: options.instruments,
}},
{label: 'URL', show: true},
{label: 'Status', show: true},
{label: 'Status', show: true, filter: {
name: 'Status',
type: 'select',
options: options.statusOptions,
}},
];
const addSurvey = () => {
location.href='/survey_accounts/addSurvey/';
Expand Down
9 changes: 5 additions & 4 deletions modules/survey_accounts/php/addsurvey.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ class AddSurvey extends \NDB_Form
];
}
}

if ($_REQUEST['fire_away'] !== 'Create survey') {
if (!isset($_REQUEST['fire_away'])
|| ($_REQUEST['fire_away'] !== 'Create survey')
) {
if (!filter_var(
$values['Email'],
FILTER_VALIDATE_EMAIL
Expand Down Expand Up @@ -241,11 +242,11 @@ class AddSurvey extends \NDB_Form
'CommentID' => $commentID,
]
);
$this->tpl_data['success'] = true;
} catch (\DatabaseException $e) {
error_log($e->getMessage());
$this->tpl_data['success'] = false;
}
$this->tpl_data['success'] = true;

if ($email && ($values['send_email'] == 'true')) {
$config = \NDB_Config::singleton();
Expand Down Expand Up @@ -291,7 +292,7 @@ class AddSurvey extends \NDB_Form
"Instrument",
array_merge(
['' => ''],
\Utility::getDirectInstruments()
\NDB_BVL_Instrument::getDirectEntryInstrumentNamesList($this->loris)
)
);
$this->addBasicText("Email", "Email address");
Expand Down
12 changes: 10 additions & 2 deletions modules/survey_accounts/php/survey_accounts.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,22 @@ class Survey_Accounts extends \DataFrameworkMenu
*/
public function getFieldOptions() : array
{
$statusOptions = [
'Created' => 'Created',
'Sent' => 'Sent',
'In Progress' => 'In Progress',
'Complete' => 'Complete',
];

$instruments
= \NDB_BVL_Instrument::getDirectEntryInstrumentNamesList(
$this->loris
);

return [
'visits' => \Utility::getVisitList(),
'instruments' => $instruments,
'visits' => \Utility::getVisitList(),
'instruments' => $instruments,
'statusOptions' => $statusOptions,
];
}

Expand Down
11 changes: 11 additions & 0 deletions php/exceptions/ConflictException.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* This file contains the Conflict exception type.
*
* PHP Version 7
*
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
*/
class ConflictException extends LorisException
{
}
10 changes: 9 additions & 1 deletion php/libraries/BVL_Feedback_Panel.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ class BVL_Feedback_Panel
$summary = $this->feedbackThread->getSummaryOfThreads();
$this->tpl_data['thread_summary_headers'] = json_encode($summary);

$field_names = Utility::getSourcefields($_REQUEST['test_name'] ?? '');
$test_name = '';
if (array_key_exists('test_name', $_REQUEST)) {
$test_name = $_REQUEST['test_name'];
} else if (array_key_exists('lorispath', $_REQUEST)) {
$test_name = preg_split("#/#", $_REQUEST['lorispath'])[1] ?? '';
}

// Get field names
$field_names = Utility::getSourcefields($test_name);
$fields = [];
$fields['Across All Fields'] = 'Across All Fields';
foreach ($field_names as $field_name) {
Expand Down
20 changes: 20 additions & 0 deletions php/libraries/Candidate.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class Candidate implements \LORIS\StudyEntities\AccessibleResource,
ProjectID $registrationProjectID = null
): CandID {
$factory = NDB_Factory::singleton();
$db = $factory->database();

$site = \Site::singleton($centerID);

Expand Down Expand Up @@ -264,6 +265,25 @@ class Candidate implements \LORIS\StudyEntities\AccessibleResource,
);
}

// check pscid uniqueness
$existing = $db->pselectOne(
'SELECT
COUNT(*)
FROM candidate
WHERE PSCID = :v_pscid
GROUP BY
PSCID
',
['v_pscid' => $PSCID]
);

if ($existing > 0) {
throw new \ConflictException(
"PSCID must be unique",
PSCID_NOT_UNIQUE
);
}

// check pscid structure
if (!Candidate::validatePSCID(
$PSCID,
Expand Down
6 changes: 5 additions & 1 deletion php/libraries/LorisForm.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,7 @@ class LorisForm
$checked = '';
$value = '';
$disabled = '';
$required = '';
if (!empty($val)) {
$checked = 'checked="checked"';
}
Expand All @@ -1601,6 +1602,9 @@ class LorisForm
if (isset($el['disabled']) || $this->frozen) {
$disabled = 'disabled';
}
if (isset($el['required'])) {
$required = 'required';
}
/// XXX: There seems to be a problem when using &nbsp; to separate the
// checkbox from the label. Both Firefox and Chrome will still put a
// linebreak between the space and the checkbox. Instead, we wrap use
Expand All @@ -1609,7 +1613,7 @@ class LorisForm
// label it's still allowed to have linebreaks.
return "<span style=\"white-space: nowrap\"><input name=\"$el[name]\""
. " type=\"checkbox\" $checked $value "
. "$disabled/>"
. "$disabled $required/>"
. " </span>$el[label]";
}

Expand Down
1 change: 1 addition & 0 deletions php/libraries/LorisFormDictionaryImpl.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ trait LorisFormDictionaryImpl
$t = new \LORIS\Data\Types\StringType(255);
break;
case 'header':
case 'hidden':
continue 2;
default:
throw new \LorisException(
Expand Down
14 changes: 7 additions & 7 deletions php/libraries/NDB_BVL_Instrument_LINST.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -734,14 +734,14 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
case 'numeric':
if ($addElements) {
$this->addNumericElement($pieces[1], $pieces[2]);
$this->dictionary[] = new DictionaryItem(
$this->testName."_".$pieces[1],
$pieces[2],
$scope,
new IntegerType(),
new Cardinality(Cardinality::SINGLE),
);
}
$this->dictionary[] = new DictionaryItem(
$this->testName."_".$pieces[1],
$pieces[2],
$scope,
new IntegerType(),
new Cardinality(Cardinality::SINGLE),
);
if ($firstFieldOfPage) {
$this->_requiredElements[] = $fieldname;
$firstFieldOfPage = false;
Expand Down
Loading

0 comments on commit 1b12234

Please sign in to comment.