From 8a69147f262c367eb2285ce8d12b23c7a21f1c3e Mon Sep 17 00:00:00 2001 From: ridz1208 Date: Thu, 3 Dec 2020 12:49:03 -0500 Subject: [PATCH 1/4] [instrument_list/battery] Clean-up battery retrieval function --- .../php/instrument_list.class.inc | 83 +------ php/libraries/NDB_BVL_Battery.class.inc | 77 ++---- tools/assign_missing_instruments.php | 6 +- tools/fix_timepoint_date_problems.php | 234 +++++++++--------- 4 files changed, 150 insertions(+), 250 deletions(-) diff --git a/modules/instrument_list/php/instrument_list.class.inc b/modules/instrument_list/php/instrument_list.class.inc index 77e33cf8d21..a2f12b5b7e6 100644 --- a/modules/instrument_list/php/instrument_list.class.inc +++ b/modules/instrument_list/php/instrument_list.class.inc @@ -186,21 +186,16 @@ class Instrument_List extends \NDB_Menu_Filter // Don't call parent setup, we don't want it to try to run any SQL // set template data - $this->tpl_data['candID'] = $this->candidate->getCandID(); - $this->tpl_data['sessionID'] = $this->timePoint->getSessionID(); + $this->tpl_data['candID'] = $this->candidate->getCandID(); + $this->tpl_data['sessionID'] = $this->timePoint->getSessionID(); + $this->tpl_data['stage'] = \Utility::getStageUsingCandID( + new CandID(strval($this->tpl_data['candID'])) + ); // get behavioural battery for this visit (time point) $battery = new \NDB_BVL_Battery; $battery->selectBattery($this->timePoint->getSessionID()); - - $this->tpl_data['stage'] = \Utility::getStageUsingCandID( - new CandID(strval($this->tpl_data['candID'])) - ); - - // get the list of instruments - $listOfInstruments = $this->getBatteryInstrumentList( - $this->tpl_data['stage'] - ); + $listOfInstruments = $battery->getBatteryVerbose(); // display list of instruments if (!empty($listOfInstruments)) { @@ -321,72 +316,6 @@ class Instrument_List extends \NDB_Menu_Filter return $html; } - /** - * Gets an associative array of instruments which are members of the current - * battery for instrument list module - * - * @param string $stage Either 'visit' or 'screening' - determines - * whether to register only screening instruments - * or visit instruments - * - * @return array an associative array containing Test_name, - * Full_name, Sub_group, CommentID - */ - function getBatteryInstrumentList($stage=null) - { - $DB = \Database::singleton(); - - // assert that a battery has already been selected - if (is_null($this->timePoint)) { - throw new \Exception("No battery selected"); - } - - // craft the select query - $query = "SELECT DISTINCT f.Test_name, - t.Full_name, - f.CommentID, - CONCAT('DDE_', f.CommentID) AS DDECommentID, - ts.Subgroup_name as Sub_group, - ts.group_order as Subgroup_order, - t.isDirectEntry"; - if (!is_null($stage)) { - $query .= ", b.instr_order as instrument_order"; - } - $query .= " FROM flag f - JOIN test_names t ON (f.Test_name=t.Test_name) - JOIN test_subgroups ts ON (ts.ID = t.Sub_group) - LEFT JOIN session s ON (s.ID=f.SessionID) "; - $qparams = ['SID' => $this->timePoint->getSessionID()]; - - if (!is_null($stage)) { - $query .= " - LEFT JOIN test_battery b - ON ((t.Test_name=b.Test_name OR b.Test_name IS NULL) - AND (s.SubprojectID=b.SubprojectID OR b.SubprojectID IS NULL) - AND (s.Visit_label=b.Visit_label OR b.Visit_label IS NULL) - AND (s.CenterID=b.CenterID OR b.CenterID IS NULL)) "; - } - $query .= " WHERE f.SessionID=:SID - AND LEFT(f.CommentID, 3) != 'DDE'"; - - if (\Utility::columnsHasNull('test_subgroups', 'group_order')) { - $query .= " ORDER BY Subgroup_name"; - } else { - $query .= " ORDER BY Subgroup_order"; - } - if (!is_null($stage)) { - $query .= ", instrument_order"; - } else { - $query .= ", Full_name"; - } - - // get the list of instruments - $rows = $DB->pselect($query, $qparams); - - // return all the data selected - return $rows; - } - /** * Include the column formatter required to display the feedback link colours * in the candidate_list menu diff --git a/php/libraries/NDB_BVL_Battery.class.inc b/php/libraries/NDB_BVL_Battery.class.inc index 2bdcbeefe84..54cf47077c9 100644 --- a/php/libraries/NDB_BVL_Battery.class.inc +++ b/php/libraries/NDB_BVL_Battery.class.inc @@ -277,16 +277,9 @@ class NDB_BVL_Battery * Gets an array of instruments which are members of the currently * selected session's battery * - * @param string $stage Either 'visit' or 'screening' - determines - * whether to register only screening instruments - * or visit instruments - * @param integer $SubprojectID The SubprojectID of that we want the battery for. - * @param string $visit_label The visit label of the battery that we want to - * retrieve - * * @return array an array of instrument names */ - function getBattery($stage=null, $SubprojectID=null, $visit_label=null) + function getBattery() { $DB = Database::singleton(); // assert that a battery has already been selected @@ -315,67 +308,49 @@ class NDB_BVL_Battery * Gets an associative array of instruments which are members of the current * battery * - * @param string $stage Either 'visit' or 'screening' - determines - * whether to register only screening instruments - * or visit instruments - * @param integer $SubprojectID The SubprojectID of that we want the battery for. - * * @return array an associative array containing Test_name, * Full_name, Sub_group, CommentID */ - function getBatteryVerbose($stage=null, $SubprojectID=null) + function getBatteryVerbose() { $DB = Database::singleton(); // assert that a battery has already been selected $this->_assertBatterySelected(); // craft the select query - $query = "SELECT f.Test_name, - t.Full_name, - f.CommentID, - CONCAT('DDE_', f.CommentID) AS DDECommentID, - ts.Subgroup_name as Sub_group, - ts.group_order as Subgroup_order, - t.isDirectEntry"; - if (!is_null($stage)) { - $query .= ", b.instr_order as instrument_order"; - } - $query .= " FROM flag f - JOIN test_names t ON (f.Test_name=t.Test_name) - JOIN test_subgroups ts ON (ts.ID = t.Sub_group) "; - $qparams = ['SID' => $this->sessionID]; - - if (!is_null($stage)) { - $query .= " - LEFT JOIN test_battery b ON (t.Test_name=b.Test_name) "; - } - $query .= " WHERE f.SessionID=:SID - AND f.CommentID NOT LIKE 'DDE%'"; - if (!is_null($stage) && !is_null($SubprojectID)) { - $query .= " AND ( - b.SubprojectID IS NULL - OR b.SubprojectID=:SubprojID - )"; - $qparams['SubprojID'] = $SubprojectID; - } - - if (Utility::columnsHasNull('test_subgroups', 'group_order')) { + $query = "SELECT DISTINCT f.Test_name, + t.Full_name, + f.CommentID, + CONCAT('DDE_', f.CommentID) AS DDECommentID, + ts.Subgroup_name as Sub_group, + ts.group_order as Subgroup_order, + t.isDirectEntry, + b.instr_order as instrument_order + FROM flag f + JOIN test_names t ON (f.Test_name=t.Test_name) + JOIN test_subgroups ts ON (ts.ID = t.Sub_group) + LEFT JOIN session s ON (s.ID=f.SessionID) + LEFT JOIN test_battery b + ON ((t.Test_name=b.Test_name OR b.Test_name IS NULL) + AND (s.SubprojectID=b.SubprojectID OR b.SubprojectID IS NULL) + AND (s.Visit_label=b.Visit_label OR b.Visit_label IS NULL) + AND (s.CenterID=b.CenterID OR b.CenterID IS NULL)) + WHERE f.SessionID=:SID + AND LEFT(f.CommentID, 4) != 'DDE_' "; + if (\Utility::columnsHasNull('test_subgroups', 'group_order')) { $query .= " ORDER BY Subgroup_name"; } else { $query .= " ORDER BY Subgroup_order"; } - if (!is_null($stage)) { - $query .= ", instrument_order"; - } else { - $query .= ", Full_name"; - } - //print_r($query); + $query .= ", instrument_order, Full_name"; + $qparams = ['SID' => $this->timePoint->getSessionID()]; + // get the list of instruments $rows = $DB->pselect($query, $qparams); // return all the data selected return $rows; - } // end getBatteryVerbose() + } /** diff --git a/tools/assign_missing_instruments.php b/tools/assign_missing_instruments.php index 44334f9ade4..cc9d3598ee1 100755 --- a/tools/assign_missing_instruments.php +++ b/tools/assign_missing_instruments.php @@ -108,11 +108,7 @@ function populateVisitLabel($result, $visit_label) $timePoint->getCenterID(), $isFirstVisit ); - $actual_battery =$battery->getBattery( - $timePoint->getCurrentStage(), - $result['subprojectID'], - $visit_label - ); + $actual_battery =$battery->getBattery(); $diff = array_unique(array_diff($defined_battery, $actual_battery)); if (!empty($diff)) { diff --git a/tools/fix_timepoint_date_problems.php b/tools/fix_timepoint_date_problems.php index 6fe1939adc6..2fd3e65fc6d 100755 --- a/tools/fix_timepoint_date_problems.php +++ b/tools/fix_timepoint_date_problems.php @@ -84,34 +84,16 @@ // get the rest of the arguments switch ($action) { -case 'fix_date': - if (empty($argv[3]) || empty($argv[4])) { - printUsage(); - } - - // new date - $newDate = $argv[3]; - // date type - $dateType = strtolower($argv[4]); - // sessionID - if (in_array($dateType, ['screening', 'visit'])) { - if (empty($argv[5])) { + case 'fix_date': + if (empty($argv[3]) || empty($argv[4])) { printUsage(); } - $sessionID = $argv[5]; - } - break; - -case 'diagnose': - // new date - if (!empty($argv[3])) { + // new date $newDate = $argv[3]; - } - // date type - if (!empty($argv[4])) { + // date type $dateType = strtolower($argv[4]); - // sessionID only present when dateType defined + // sessionID if (in_array($dateType, ['screening', 'visit'])) { if (empty($argv[5])) { printUsage(); @@ -119,19 +101,37 @@ $sessionID = $argv[5]; } - } - break; + break; -case 'add_instrument': - if (empty($argv[3]) || empty($argv[4])) { - printUsage(); - } + case 'diagnose': + // new date + if (!empty($argv[3])) { + $newDate = $argv[3]; + } + // date type + if (!empty($argv[4])) { + $dateType = strtolower($argv[4]); + // sessionID only present when dateType defined + if (in_array($dateType, ['screening', 'visit'])) { + if (empty($argv[5])) { + printUsage(); + } + + $sessionID = $argv[5]; + } + } + break; - // sessionID - $sessionID = $argv[3]; - // test name - $testName = $argv[4]; - break; + case 'add_instrument': + if (empty($argv[3]) || empty($argv[4])) { + printUsage(); + } + + // sessionID + $sessionID = $argv[3]; + // test name + $testName = $argv[4]; + break; } /** @@ -206,45 +206,45 @@ * arguments: $candID, $sessionID, $testName * RUN THE DIAGNOSTICS BEFORE TO SEE WHAT NEEDS TO BE FIXED */ -case 'add_instrument': - // add a missing instrument (sessionID and test name are checked inside the - // function) - try { - $success = addInstrument($sessionID, $testName); - } catch (LorisException $e) { - fwrite( - STDERR, - "Error: failed to add the instrument $testName for " . - "timepoint ($sessionID):\n" - ); - fwrite(STDERR, $e->getMessage(). "\n"); - } + case 'add_instrument': + // add a missing instrument (sessionID and test name are checked inside the + // function) + try { + $success = addInstrument($sessionID, $testName); + } catch (LorisException $e) { + fwrite( + STDERR, + "Error: failed to add the instrument $testName for " . + "timepoint ($sessionID):\n" + ); + fwrite(STDERR, $e->getMessage(). "\n"); + } - break; + break; /** * Fixing the dates * arguments: $candID, $dateType, $newDate, $sessionID */ -case 'fix_date': - // fix the date (arguments are checked by the function - // wrapping in an if/else statement to avoid PHP Notice when $sessionID is - // empty - try { - if (!empty($sessionID)) { - $success = fixDate($candID, $dateType, $newDate, $sessionID); - } else { - $success = fixDate($candID, $dateType, $newDate); + case 'fix_date': + // fix the date (arguments are checked by the function + // wrapping in an if/else statement to avoid PHP Notice when $sessionID is + // empty + try { + if (!empty($sessionID)) { + $success = fixDate($candID, $dateType, $newDate, $sessionID); + } else { + $success = fixDate($candID, $dateType, $newDate); + } + } catch (LorisException $e) { + fwrite( + STDERR, + "Error: failed to fix the date for candidate ($candID):\n" + ); + fwrite(STDERR, $e->getMessage(). "\n"); } - } catch (LorisException $e) { - fwrite( - STDERR, - "Error: failed to fix the date for candidate ($candID):\n" - ); - fwrite(STDERR, $e->getMessage(). "\n"); - } - break; + break; /** * Timepoint Diagnostics @@ -252,65 +252,65 @@ * also pass the 'correct' date and the date type to see what changes * would happen if the dates were different */ -case 'diagnose': - if (!empty($sessionID)) { - // overwrite the array to include the provided $sessionID only - $listOfTimePoints = [$sessionID]; - } - - // print out candidate info - fwrite(STDERR, "Candidate: $candID \n"); + case 'diagnose': + if (!empty($sessionID)) { + // overwrite the array to include the provided $sessionID only + $listOfTimePoints = [$sessionID]; + } - // check/diagnose each timepoint separately - foreach ($listOfTimePoints as $sessionID) { - // create timepoint object - $timePoint =& TimePoint::singleton(new \SessionID(strval($sessionID))); + // print out candidate info + fwrite(STDERR, "Candidate: $candID \n"); - // print out the $sessionID - fwrite( - STDERR, - "\n Timepoint ".$timePoint->getVisitLabel()." ; SubProjectID: " - .$timePoint->getSubprojectID()." ; Effective DOB: " - .$timePoint->getEffectiveDateOfBirth(). - " ; (SessionID): $sessionID \n" - ); + // check/diagnose each timepoint separately + foreach ($listOfTimePoints as $sessionID) { + // create timepoint object + $timePoint =& TimePoint::singleton(new \SessionID(strval($sessionID))); - // diagnose - get the list of missing instruments - try { - // wrapping in if statement to avoid PHP notice. Checking for - // both dateType and newDate at the same time since - // one should not be set without the other. - if (isset($dateType) && isset($newDate)) { - $listNewInstruments = diagnose($sessionID, $dateType, $newDate); - } else { - $listNewInstruments = diagnose($sessionID); - } - } catch (LorisException $e) { - // handle the error and skip to next time point + // print out the $sessionID fwrite( STDERR, - "Error: failed to get the list of needed instruments for " . - "candidate ($candID), timepoint ($sessionID):\n" + "\n Timepoint ".$timePoint->getVisitLabel()." ; SubProjectID: " + .$timePoint->getSubprojectID()." ; Effective DOB: " + .$timePoint->getEffectiveDateOfBirth(). + " ; (SessionID): $sessionID \n" ); - //print error message from diagnose function - fwrite(STDERR, $e->getMessage(). "\n"); - continue; - } - // if there are missing instruments - //if (count($listNewInstruments) > 0) { - if (!empty($listNewInstruments) > 0) { - fwrite(STDERR, "\n Missing instruments are:\n"); + // diagnose - get the list of missing instruments + try { + // wrapping in if statement to avoid PHP notice. Checking for + // both dateType and newDate at the same time since + // one should not be set without the other. + if (isset($dateType) && isset($newDate)) { + $listNewInstruments = diagnose($sessionID, $dateType, $newDate); + } else { + $listNewInstruments = diagnose($sessionID); + } + } catch (LorisException $e) { + // handle the error and skip to next time point + fwrite( + STDERR, + "Error: failed to get the list of needed instruments for " . + "candidate ($candID), timepoint ($sessionID):\n" + ); + //print error message from diagnose function + fwrite(STDERR, $e->getMessage(). "\n"); + continue; + } + + // if there are missing instruments + //if (count($listNewInstruments) > 0) { + if (!empty($listNewInstruments) > 0) { + fwrite(STDERR, "\n Missing instruments are:\n"); - //print out the list of missing instruments - foreach ($listNewInstruments as $instrument) { - fwrite(STDERR, "$instrument \n"); + //print out the list of missing instruments + foreach ($listNewInstruments as $instrument) { + fwrite(STDERR, "$instrument \n"); + } + } else { + fwrite(STDERR, "\n There are no missing instruments \n"); } - } else { - fwrite(STDERR, "\n There are no missing instruments \n"); } - } - break; + break; } // end switch ($action) @@ -633,7 +633,7 @@ function diagnose($sessionID, $dateType = null, $newDate = null) || !in_array($dateType, ['dob', 'edc', 'screening', 'visit']) || empty($newDate) || (in_array($dateType, ['screening', 'visit']) - && empty($sessionID)) + && empty($sessionID)) ) { throw new LorisException("Please pass a valid set of arguments\n"); } @@ -718,7 +718,7 @@ function diagnose($sessionID, $dateType = null, $newDate = null) // compute subject age for the current stage $ageArray = Utility::calculateAge($dateBirth, $dateOfStage); $age = ($ageArray['year'] * 12 + $ageArray['mon']) * 30 - + $ageArray['day']; + + $ageArray['day']; if ($age < 0) { $age = 0; } @@ -733,7 +733,7 @@ function diagnose($sessionID, $dateType = null, $newDate = null) $success = $battery->selectBattery(new \SessionID(strval($sessionID))); // get the existing battery for the stage - $existingTests = $battery->getBattery($stage); + $existingTests = $battery->getBattery(); // determine the correct list of instruments $neededTests = Utility::lookupBattery($age, $stage); From f2cd8cf7ff4b1fe64e3eb42448fb7d12f7bdf8c3 Mon Sep 17 00:00:00 2001 From: ridz1208 Date: Thu, 3 Dec 2020 13:06:35 -0500 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2e102f6b8f..5a448c947f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,7 @@ requesting a new account and will be displayed in the User Accounts module (PR # #### API Documentation (**New Module**) - New module mostly intended for developers, this module provides a user interface to inspect and try LORIS modules API. ### Clean Up -- *Add item here* +- Removal of unused variables and unnecessary branching from `getBattery()` and `getBatteryVerbose()` functions (PR #7167) ### Notes For Existing Projects - New function Candidate::getSubjectForMostRecentVisit replaces Utility::getSubprojectIDUsingCandID, adding ability to determine which subproject a candidate belongs to given their most recent visit. - LINST instrument class was modified to implement the getFullName() and getSubtestList() functions thus making entries in the test_names and instrument_subtests tables respectively unnecessary for LINST instruments (PR #7169) From d47c750aed89cd71788fe2a0a0baec605edabe80 Mon Sep 17 00:00:00 2001 From: ridz1208 Date: Thu, 3 Dec 2020 13:52:41 -0500 Subject: [PATCH 3/4] missing session ID --- php/libraries/NDB_BVL_Battery.class.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/libraries/NDB_BVL_Battery.class.inc b/php/libraries/NDB_BVL_Battery.class.inc index 54cf47077c9..405c72e85af 100644 --- a/php/libraries/NDB_BVL_Battery.class.inc +++ b/php/libraries/NDB_BVL_Battery.class.inc @@ -343,7 +343,7 @@ class NDB_BVL_Battery $query .= " ORDER BY Subgroup_order"; } $query .= ", instrument_order, Full_name"; - $qparams = ['SID' => $this->timePoint->getSessionID()]; + $qparams = ['SID' => $this->sessionID]; // get the list of instruments $rows = $DB->pselect($query, $qparams); From ad121d02bc07396b7d76ccde1322286c3e3dba23 Mon Sep 17 00:00:00 2001 From: ridz1208 Date: Tue, 15 Jun 2021 08:35:41 -0400 Subject: [PATCH 4/4] first commit in a long loooong time --- .../php/instrument_list.class.inc | 6 +- php/libraries/NDB_BVL_Battery.class.inc | 2 +- tools/fix_timepoint_date_problems.php | 230 +++++++++--------- 3 files changed, 119 insertions(+), 119 deletions(-) diff --git a/modules/instrument_list/php/instrument_list.class.inc b/modules/instrument_list/php/instrument_list.class.inc index a2f12b5b7e6..c89d5febdfa 100644 --- a/modules/instrument_list/php/instrument_list.class.inc +++ b/modules/instrument_list/php/instrument_list.class.inc @@ -186,9 +186,9 @@ class Instrument_List extends \NDB_Menu_Filter // Don't call parent setup, we don't want it to try to run any SQL // set template data - $this->tpl_data['candID'] = $this->candidate->getCandID(); - $this->tpl_data['sessionID'] = $this->timePoint->getSessionID(); - $this->tpl_data['stage'] = \Utility::getStageUsingCandID( + $this->tpl_data['candID'] = $this->candidate->getCandID(); + $this->tpl_data['sessionID'] = $this->timePoint->getSessionID(); + $this->tpl_data['stage'] = \Utility::getStageUsingCandID( new CandID(strval($this->tpl_data['candID'])) ); diff --git a/php/libraries/NDB_BVL_Battery.class.inc b/php/libraries/NDB_BVL_Battery.class.inc index 405c72e85af..d7a5ea69190 100644 --- a/php/libraries/NDB_BVL_Battery.class.inc +++ b/php/libraries/NDB_BVL_Battery.class.inc @@ -302,7 +302,7 @@ class NDB_BVL_Battery // return an array of test names return $tests; - } // end getBattery() + } /** * Gets an associative array of instruments which are members of the current diff --git a/tools/fix_timepoint_date_problems.php b/tools/fix_timepoint_date_problems.php index 2fd3e65fc6d..64b445e4a21 100755 --- a/tools/fix_timepoint_date_problems.php +++ b/tools/fix_timepoint_date_problems.php @@ -84,16 +84,34 @@ // get the rest of the arguments switch ($action) { - case 'fix_date': - if (empty($argv[3]) || empty($argv[4])) { +case 'fix_date': + if (empty($argv[3]) || empty($argv[4])) { + printUsage(); + } + + // new date + $newDate = $argv[3]; + // date type + $dateType = strtolower($argv[4]); + // sessionID + if (in_array($dateType, ['screening', 'visit'])) { + if (empty($argv[5])) { printUsage(); } - // new date + $sessionID = $argv[5]; + } + break; + +case 'diagnose': + // new date + if (!empty($argv[3])) { $newDate = $argv[3]; - // date type + } + // date type + if (!empty($argv[4])) { $dateType = strtolower($argv[4]); - // sessionID + // sessionID only present when dateType defined if (in_array($dateType, ['screening', 'visit'])) { if (empty($argv[5])) { printUsage(); @@ -101,37 +119,19 @@ $sessionID = $argv[5]; } - break; - - case 'diagnose': - // new date - if (!empty($argv[3])) { - $newDate = $argv[3]; - } - // date type - if (!empty($argv[4])) { - $dateType = strtolower($argv[4]); - // sessionID only present when dateType defined - if (in_array($dateType, ['screening', 'visit'])) { - if (empty($argv[5])) { - printUsage(); - } - - $sessionID = $argv[5]; - } - } - break; + } + break; - case 'add_instrument': - if (empty($argv[3]) || empty($argv[4])) { - printUsage(); - } +case 'add_instrument': + if (empty($argv[3]) || empty($argv[4])) { + printUsage(); + } - // sessionID - $sessionID = $argv[3]; - // test name - $testName = $argv[4]; - break; + // sessionID + $sessionID = $argv[3]; + // test name + $testName = $argv[4]; + break; } /** @@ -206,45 +206,45 @@ * arguments: $candID, $sessionID, $testName * RUN THE DIAGNOSTICS BEFORE TO SEE WHAT NEEDS TO BE FIXED */ - case 'add_instrument': - // add a missing instrument (sessionID and test name are checked inside the - // function) - try { - $success = addInstrument($sessionID, $testName); - } catch (LorisException $e) { - fwrite( - STDERR, - "Error: failed to add the instrument $testName for " . - "timepoint ($sessionID):\n" - ); - fwrite(STDERR, $e->getMessage(). "\n"); - } +case 'add_instrument': + // add a missing instrument (sessionID and test name are checked inside the + // function) + try { + $success = addInstrument($sessionID, $testName); + } catch (LorisException $e) { + fwrite( + STDERR, + "Error: failed to add the instrument $testName for " . + "timepoint ($sessionID):\n" + ); + fwrite(STDERR, $e->getMessage(). "\n"); + } - break; + break; /** * Fixing the dates * arguments: $candID, $dateType, $newDate, $sessionID */ - case 'fix_date': - // fix the date (arguments are checked by the function - // wrapping in an if/else statement to avoid PHP Notice when $sessionID is - // empty - try { - if (!empty($sessionID)) { - $success = fixDate($candID, $dateType, $newDate, $sessionID); - } else { - $success = fixDate($candID, $dateType, $newDate); - } - } catch (LorisException $e) { - fwrite( - STDERR, - "Error: failed to fix the date for candidate ($candID):\n" - ); - fwrite(STDERR, $e->getMessage(). "\n"); +case 'fix_date': + // fix the date (arguments are checked by the function + // wrapping in an if/else statement to avoid PHP Notice when $sessionID is + // empty + try { + if (!empty($sessionID)) { + $success = fixDate($candID, $dateType, $newDate, $sessionID); + } else { + $success = fixDate($candID, $dateType, $newDate); } + } catch (LorisException $e) { + fwrite( + STDERR, + "Error: failed to fix the date for candidate ($candID):\n" + ); + fwrite(STDERR, $e->getMessage(). "\n"); + } - break; + break; /** * Timepoint Diagnostics @@ -252,65 +252,65 @@ * also pass the 'correct' date and the date type to see what changes * would happen if the dates were different */ - case 'diagnose': - if (!empty($sessionID)) { - // overwrite the array to include the provided $sessionID only - $listOfTimePoints = [$sessionID]; - } +case 'diagnose': + if (!empty($sessionID)) { + // overwrite the array to include the provided $sessionID only + $listOfTimePoints = [$sessionID]; + } - // print out candidate info - fwrite(STDERR, "Candidate: $candID \n"); + // print out candidate info + fwrite(STDERR, "Candidate: $candID \n"); + + // check/diagnose each timepoint separately + foreach ($listOfTimePoints as $sessionID) { + // create timepoint object + $timePoint =& TimePoint::singleton(new \SessionID(strval($sessionID))); - // check/diagnose each timepoint separately - foreach ($listOfTimePoints as $sessionID) { - // create timepoint object - $timePoint =& TimePoint::singleton(new \SessionID(strval($sessionID))); + // print out the $sessionID + fwrite( + STDERR, + "\n Timepoint ".$timePoint->getVisitLabel()." ; SubProjectID: " + .$timePoint->getSubprojectID()." ; Effective DOB: " + .$timePoint->getEffectiveDateOfBirth(). + " ; (SessionID): $sessionID \n" + ); - // print out the $sessionID + // diagnose - get the list of missing instruments + try { + // wrapping in if statement to avoid PHP notice. Checking for + // both dateType and newDate at the same time since + // one should not be set without the other. + if (isset($dateType) && isset($newDate)) { + $listNewInstruments = diagnose($sessionID, $dateType, $newDate); + } else { + $listNewInstruments = diagnose($sessionID); + } + } catch (LorisException $e) { + // handle the error and skip to next time point fwrite( STDERR, - "\n Timepoint ".$timePoint->getVisitLabel()." ; SubProjectID: " - .$timePoint->getSubprojectID()." ; Effective DOB: " - .$timePoint->getEffectiveDateOfBirth(). - " ; (SessionID): $sessionID \n" + "Error: failed to get the list of needed instruments for " . + "candidate ($candID), timepoint ($sessionID):\n" ); + //print error message from diagnose function + fwrite(STDERR, $e->getMessage(). "\n"); + continue; + } - // diagnose - get the list of missing instruments - try { - // wrapping in if statement to avoid PHP notice. Checking for - // both dateType and newDate at the same time since - // one should not be set without the other. - if (isset($dateType) && isset($newDate)) { - $listNewInstruments = diagnose($sessionID, $dateType, $newDate); - } else { - $listNewInstruments = diagnose($sessionID); - } - } catch (LorisException $e) { - // handle the error and skip to next time point - fwrite( - STDERR, - "Error: failed to get the list of needed instruments for " . - "candidate ($candID), timepoint ($sessionID):\n" - ); - //print error message from diagnose function - fwrite(STDERR, $e->getMessage(). "\n"); - continue; - } - - // if there are missing instruments - //if (count($listNewInstruments) > 0) { - if (!empty($listNewInstruments) > 0) { - fwrite(STDERR, "\n Missing instruments are:\n"); + // if there are missing instruments + //if (count($listNewInstruments) > 0) { + if (!empty($listNewInstruments) > 0) { + fwrite(STDERR, "\n Missing instruments are:\n"); - //print out the list of missing instruments - foreach ($listNewInstruments as $instrument) { - fwrite(STDERR, "$instrument \n"); - } - } else { - fwrite(STDERR, "\n There are no missing instruments \n"); + //print out the list of missing instruments + foreach ($listNewInstruments as $instrument) { + fwrite(STDERR, "$instrument \n"); } + } else { + fwrite(STDERR, "\n There are no missing instruments \n"); } - break; + } + break; } // end switch ($action) @@ -633,7 +633,7 @@ function diagnose($sessionID, $dateType = null, $newDate = null) || !in_array($dateType, ['dob', 'edc', 'screening', 'visit']) || empty($newDate) || (in_array($dateType, ['screening', 'visit']) - && empty($sessionID)) + && empty($sessionID)) ) { throw new LorisException("Please pass a valid set of arguments\n"); }