Ejemplo n.º 1
0
/**
 * Adds the missing instruments based on the visit_label
 *
 * @param Array  $result      containing visit_label info
 * @param String $visit_label The name of the visit
 *
 * @return NULL
 */
function populateVisitLabel($result, $visit_label)
{
    global $argv, $confirm;
    // 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']);
    $DB = Database::singleton();
    $candidate = Candidate::singleton($result['CandID']);
    $result_firstVisit = $candidate->getFirstVisit();
    $isFirstVisit = false;
    //adding check for first visit
    if ($result_firstVisit == $visit_label) {
        $isFirstVisit = true;
    }
    //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(), $isFirstVisit);
    $actual_battery = $battery->getBattery($timePoint->getCurrentStage(), $result['subprojectID'], $visit_label);
    $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 ($confirm === true) {
        foreach ($diff as $test_name) {
            $battery->addInstrument($test_name);
        }
    }
    unset($battery);
    unset($timePoint);
}
Ejemplo n.º 2
0
        }
    }
    // Used for CSS for a specific instrument.
    if (file_exists($paths['base'] . "project/instruments/{$TestName}.css")) {
        if (strpos($_SERVER['REQUEST_URI'], "main.php") === false) {
            $tpl_data['test_name_css'] = "css/instruments/{$TestName}.css";
        } else {
            $tpl_data['test_name_css'] = "GetCSS.php?Instrument={$TestName}";
        }
    }
}
//--------------------------------------------------
// get candidate data
if (!empty($_REQUEST['candID'])) {
    try {
        $candidate =& Candidate::singleton($_REQUEST['candID']);
        $tpl_data['candidate'] = $candidate->getData();
    } catch (Exception $e) {
        $tpl_data['error_message'][] = $e->getMessage();
    }
}
// get time point data
if (!empty($_REQUEST['sessionID'])) {
    try {
        $timePoint =& TimePoint::singleton($_REQUEST['sessionID']);
        if ($config->getSetting("SupplementalSessionStatus")) {
            $tpl_data['SupplementalSessionStatuses'] = true;
        }
        $tpl_data['timePoint'] = $timePoint->getData();
    } catch (Exception $e) {
        $tpl_data['error_message'][] = "TimePoint Error (" . $_REQUEST['sessionID'] . "): " . $e->getMessage();
function fixDate($candID, $dateType, $newDate, $sessionID = null)
{
    // check the user $_ENV['USER']
    $user =& User::singleton(getenv('USER'));
    if ($user->getUsername() == null) {
        return PEAR::raiseError("Error: Database user named " . getenv('USER') . " does not exist. Please create and then retry script\n");
    }
    if (PEAR::isError($user)) {
        return "Error, failed to create User object for (" . getenv('USER') . "):" . $user->getMessage() . " \n";
    }
    $db =& Database::singleton();
    if (PEAR::isError($db)) {
        return PEAR::raiseError("Failed to create database object:\n" . $db->getMessage());
    }
    // check the args
    if (empty($dateType) || !in_array($dateType, array('dob', 'edc', 'screening', 'visit')) || empty($newDate) || in_array($dateType, array('screening', 'visit')) && empty($sessionID)) {
        return PEAR::raiseError("Please pass a valid set of arguments\n");
    }
    // check the date format (redundant)
    $dateArray = explode('-', $newDate);
    if (!is_array($dateArray) || !checkdate($dateArray[1], $dateArray[2], $dateArray[0])) {
        return PEAR::raiseError("Invalid Date! Please use the following format: YYYY-MM-DD \n");
    }
    unset($dateArray);
    // candidate object - needed to get the dob/edc
    $candidate =& Candidate::singleton($candID);
    if (PEAR::isError($candidate)) {
        return PEAR::raiseError("Error, failed to create candidate object:\n" . $candidate->getMessage());
    }
    // fixing DOB or EDC
    if (in_array($dateType, array('dob', 'edc'))) {
        // set and where arrays
        $setArray = array($dateType => $newDate);
        $whereArray = array('CandID' => $candID);
        // update candidate table record
        $success = $db->update('candidate', $setArray, $whereArray);
        if (PEAR::isError($success)) {
            return PEAR::raiseError("Failed to update the {$dateType}: " . $success->getMessage());
        }
        /*
         * add Feedback
         */
        // feedback object
        $feedback =& NDB_BVL_Feedback::singleton($user->getUsername(), $candID);
        if (PEAR::isError($feedback)) {
            return PEAR::raiseError("Failed to create feedback object: " . $feedback->getMessage());
        }
        // add the new thread
        $success = $feedback->createThread('profile', '5', "The date of {$dateType} has been changed to {$newDate}.", 'N');
        if (PEAR::isError($success)) {
            return PEAR::raiseError("Failed to create feedback: " . $success->getMessage());
        }
        // log the change
        fwrite(STDERR, "Updated {$dateType} to: {$newDate}, for candidate {$candID}. Check the record in the DB! \n");
    } else {
        // fixing Date_screening or Date_visit
        // create timepoint object
        $timePoint =& TimePoint::singleton($sessionID);
        if (PEAR::isError($timePoint)) {
            return PEAR::raiseError("Failed to create timepoint object: " . $timePoint->getMessage());
        }
        // check if the timepoint is started before attempting to make changes to it
        if ($timePoint->getCurrentStage() == 'Not Started') {
            return PEAR::raiseError("Error: Cannot perform screening/visit date fixes on the non-started timepoints!");
        }
        // get the stage statuses
        $screeningStage = $timePoint->getScreeningStatus();
        $visitStage = $timePoint->getVisitStatus();
        // make sure that the stage to fix is started
        if ($dateType == 'visit' && empty($visitStage) || $dateType == 'screening' && empty($screeningStage)) {
            return PEAR::raiseError("Error: failed to retrieve the date of {$dateType} (sessionID: {$sessionID}) b/c that stage was not started!");
        }
        // set and where arrays for the update
        $setArray = array("Date_" . $dateType => $newDate);
        $whereArray = array("ID" => $sessionID);
        // update session table record
        $success = $db->update('session', $setArray, $whereArray);
        if (PEAR::isError($success)) {
            return PEAR::raiseError("Failed to update the {$dateType} stage date to {$newDate}: " . $success->getMessage());
        }
        /*
         * add Feedback
         */
        // feedback object
        $feedback =& NDB_BVL_Feedback::singleton($user->getUsername(), null, $sessionID);
        if (PEAR::isError($feedback)) {
            return PEAR::raiseError("Failed to create feedback object: " . $feedback->getMessage());
        }
        // add the new thread
        $success = $feedback->createThread('session', '5', "The date of {$dateType} has been changed to {$newDate}.", 'N');
        if (PEAR::isError($success)) {
            return PEAR::raiseError("Failed to create feedback: " . $success->getMessage());
        }
        // log the change
        fwrite(STDERR, "Updated date of {$dateType} to {$newDate}, for candidate {$candID}, timepoint {$sessionID}. Check the DB record!\n");
    }
    // end if
    return;
}