From ea75fa4fe942facf74fd51bf44a5421bd45ba716 Mon Sep 17 00:00:00 2001 From: Victoria Hoang <118122474+victori444@users.noreply.github.com> Date: Thu, 23 Jan 2025 11:12:16 -0500 Subject: [PATCH] [timepoint] Add Default Site to Dropdown (#9408) In the create timepoint module, adds a candidate's most recent site as the default site for the "Site" dropdown. --- .../create_timepoint/jsx/createTimepointIndex.js | 3 +++ modules/create_timepoint/php/timepoint.class.inc | 14 ++++++++++++++ 2 files changed, 17 insertions(+) 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(