Skip to content
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
1 change: 1 addition & 0 deletions SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,7 @@ CREATE TABLE `test_battery` (
`Stage` varchar(255) default NULL,
`SubprojectID` int(11) default NULL,
`Visit_label` varchar(255) default NULL,
`CenterID` int(11) default NULL,
PRIMARY KEY (`ID`),
KEY `age_test` (`AgeMinDays`,`AgeMaxDays`,`Test_name`),
KEY `FK_test_battery_1` (`Test_name`),
Expand Down
1 change: 1 addition & 0 deletions SQL/2012-01-11-TestBatteryCenterID.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE test_battery ADD COLUMN `CenterID` int(11) default NULL;
15 changes: 10 additions & 5 deletions php/libraries/NDB_BVL_Battery.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ class NDB_BVL_Battery extends PEAR
* @return void
* @access public
*/
function createBattery($SubprojectID, $stage=null,$visit_label=null)
function createBattery($SubprojectID, $stage=null, $visit_label=null, $center_ID=null)
{
// assert that a battery has already been selected
$error = $this->_assertBatterySelected();
if($this->isError($error)) return $error;

// get the current battery
$currentTests = $this->getBattery($stage, $SubprojectID,$visit_label);
// get the current battery (center id is irrelevant here, as is stage probably)
$currentTests = $this->getBattery($stage, $SubprojectID, $visit_label);
if($this->isError($currentTests)) {
return $this->raiseError("Could not get the current list of instruments, thus unable to assert that the battery is empty");
}
Expand All @@ -118,7 +118,7 @@ class NDB_BVL_Battery extends PEAR
}

// determine the list of instruments to register
$neededTests = $this->lookupBattery($this->age, $SubprojectID, $stage,$visit_label);
$neededTests = $this->lookupBattery($this->age, $SubprojectID, $stage, $visit_label, $center_ID);
if($this->isError($neededTests)) {
return $this->raiseError("Could not lookup the battery for age $this->age and subprojectID ".$this->getSubprojectID());
}
Expand Down Expand Up @@ -356,7 +356,7 @@ class NDB_BVL_Battery extends PEAR
* @return array an array of instrument names
* @access public
*/
function lookupBattery($age, $SubprojectID, $stage=null, $visit_label=null)
function lookupBattery($age, $SubprojectID, $stage=null, $visit_label=null, $center_ID=null)
{
if(empty($this->age)) $this->age = $age;
// The query to lookup the battery uses the min/max age ranges if they are not 0
Expand All @@ -374,6 +374,11 @@ class NDB_BVL_Battery extends PEAR
$query .= " AND b.Stage='$stage'";
}

if(!is_null($center_ID)) { // return all instruments that match this center or all centers (null)
$query .= " AND (b.CenterID='$center_ID' OR b.CenterID IS NULL)";
} else {
$query .= " AND b.CenterID IS NULL"; // Unless the center is specified & matched, don't return site-restricted instruments
}

// get the list of instruments
$rows = array();
Expand Down
2 changes: 1 addition & 1 deletion php/libraries/NDB_Form_next_stage.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NDB_Form_next_stage extends NDB_Form
$battery->selectBattery($timePoint->getData('SessionID'));

// add instruments to the time point (lower case stage)
$battery->createBattery($timePoint->getSubprojectID(), $newStage, $timePoint->getVisitLabel());
$battery->createBattery($timePoint->getSubprojectID(), $newStage, $timePoint->getVisitLabel(), $timePoint->getCenterID());

//------------------------------------------------------------

Expand Down
75 changes: 45 additions & 30 deletions tools/assign_missing_instruments.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,54 @@
$query="SELECT ID, subprojectID from session";
if(!empty($argv[1]) && $argv[1]!="confirm"){
$query.=" WHERE visit_label='$argv[1]'";
} else {
$visit_labels = $DB->pselect("SELECT DISTINCT Visit_label FROM session WHERE Active='Y' AND Cancelled='N' AND Visit_label NOT LIKE '%phantom%' AND Visit_label NOT LIKE 'Vsup%'", array());
}
$DB->select($query, $results);
foreach($results AS $result){
// create a new battery object && new battery
$battery =& new NDB_BVL_Battery;

// select a specific time point (sessionID) for the battery
$battery->selectBattery($result['ID']);
$timePoint =& TimePoint::singleton($result['ID']);

//To assign missing instruments to all sessions, sent to DCC or not.
$defined_battery=$battery->lookupBattery($battery->age, $result['subprojectID'], $timePoint->getCurrentStage());
$actual_battery=$battery->getBattery($timePoint->getCurrentStage());

//To assign missing instruments only for sessions in the Visit stage...
// $defined_battery=$battery->lookupBattery($battery->age, $result['subprojectID'], 'Visit');
// $actual_battery=$battery->getBattery('Visit');

$diff=array_diff($defined_battery, $actual_battery);
if(!empty($diff)){
echo "\n CandID: ".$timePoint->getCandID()." Visit Label: ".$timePoint->getVisitLabel()."\nMissing Instruments:\n";
print_r($diff);
}
if($argv[1]=="confirm" || $argv[2]=="confirm"){
foreach($diff AS $test_name){
$battery->addInstrument($test_name);
}

function PopulateVisitLabel($result, $visit_label) {
global $argv;
// create a new battery object && new battery
$battery =& new NDB_BVL_Battery;

// select a specific time point (sessionID) for the battery
$battery->selectBattery($result['ID']);
$timePoint =& TimePoint::singleton($result['ID']);

//To assign missing instruments to all sessions, sent to DCC or not.
$defined_battery=$battery->lookupBattery($battery->age, $result['subprojectID'], $timePoint->getCurrentStage(), $visit_label, $timePoint->getCenterID());
$actual_battery=$battery->getBattery($timePoint->getCurrentStage(), $result['subprojectID']);

$diff=array_diff($defined_battery, $actual_battery);
if(!empty($diff)){
echo "\n CandID: ".$timePoint->getCandID()." Visit Label: ".$timePoint->getVisitLabel()."\nMissing Instruments:\n";
print_r($diff);
}
if($argv[1]=="confirm" || $argv[2]=="confirm"){
foreach($diff AS $test_name){
$battery->addInstrument($test_name);
}

unset($battery);
unset($timePoint);
}

unset($battery);
unset($timePoint);

}

if(isset($visit_label)) {
$query="SELECT s.ID, s.subprojectID from session s LEFT JOIN candidate c USING (CandID) WHERE s.Active='Y' AND s.Cancelled='N' AND c.Active='Y' AND s.Cancelled='N' AND s.visit_label='$argv[1]'";
$DB->select($query, $results);
foreach($results AS $result){
PopulateVisitLabel($result, $visit_label);
}
} else if (isset($visit_labels)) {
$query="SELECT s.ID, s.subprojectID, s.Visit_label from session s LEFT JOIN candidate c USING (CandID) WHERE s.Active='Y' AND s.Cancelled='N' AND c.Active='Y' AND s.Cancelled='N' AND s.Visit_label NOT LIKE 'Vsup%'";
$DB->select($query, $results);
foreach($results AS $result) {
PopulateVisitLabel($result, $result['Visit_label']);
}
}

if($argv[1]!="confirm" && $argv[2]!="confirm"){
echo "\n\nRun this tool again with the argument 'confirm' to perform the changes\n\n";
}
?>
?>