diff --git a/modules/create_timepoint/jsx/createTimepointIndex.js b/modules/create_timepoint/jsx/createTimepointIndex.js index 1d2b218f003..304cb487299 100644 --- a/modules/create_timepoint/jsx/createTimepointIndex.js +++ b/modules/create_timepoint/jsx/createTimepointIndex.js @@ -134,6 +134,9 @@ class CreateTimepoint extends React.Component { if (data.psc) { state.form.options.psc = data.psc; state.form.display.psc = true; + if (data.defaultpsc) { + state.form.value.psc = data.defaultpsc; + } } // Populate the select options for project. if (data.project) { diff --git a/modules/create_timepoint/php/timepoint.class.inc b/modules/create_timepoint/php/timepoint.class.inc index 878a3a6ba4f..103061a767e 100644 --- a/modules/create_timepoint/php/timepoint.class.inc +++ b/modules/create_timepoint/php/timepoint.class.inc @@ -109,6 +109,20 @@ class Timepoint extends \NDB_Page implements ETagCalculator } if (empty($values['psc'])) { unset($values['psc']); + } else { + // Suggested site is the site of the last registered visit + $DB = $this->loris->getDatabaseConnection(); + + $query = " + SELECT CenterID + FROM session + WHERE CandID=:cid AND Date_visit IS NOT NULL + ORDER BY Date_visit DESC LIMIT 1 + "; + $where = ['cid' => $values['candID']]; + $result = iterator_to_array($DB->pselect($query, $where)); + + $values['defaultpsc'] = $result[0]['CenterID']; } return new \LORIS\Http\Response\JsonResponse(