Beispiel #1
0
function autoImportPatientEntry($importPatient, $patientName)
{
    $query_string = "SELECT * FROM patient " . "WHERE name LIKE '{$patientName}'";
    $record = query_associative_one($query_string);
    if ($record) {
        $saved_db = DbUtil::switchToGlobal();
        $userId = $_SESSION['user_id'];
        $query = "SELECT * FROM lab_config_access where user_id = {$userId}";
        $record = query_associative_one($query);
        $labConfigId = $record['lab_config_id'];
        $currentLabPatient = Patient::getObject($record);
        $globalPatientId = $importPatient->patientId;
        $importLabConfigId = substr($globalPatientId, 0, 3);
        if ($importLabConfigId == $labConfigId) {
            return;
        }
        $subValue = $importLabConfigId . "00000000000";
        $importPatientIdStr = bcsub($globalPatientId, $subValue);
        $importPatientId = intval($importPatientIdStr);
        $saved_db = DbUtil::switchToLabConfig($importLabConfigId);
        $querySelect = "SELECT * FROM specimen " . "WHERE patient_id={$importPatientId}";
        $resultset = query_associative_all($querySelect, $rowCount);
        if ($resultset) {
            foreach ($resultset as $record) {
                $specimenRecords[] = Specimen::getObject($record);
            }
            foreach ($specimenRecords as $specimenRecord) {
                $querySelect = "SELECT * FROM test " . "WHERE specimen_id={$specimenRecord->specimenId}";
                $resultset = query_associative_all($querySelect, $rowCount);
                foreach ($resultset as $record) {
                    $testRecords[] = Test::getObject($record);
                }
            }
        }
        DbUtil::switchRestore($saved_db);
        /* Build a mapping of Specimens from the Global Table & make appropriate substitutions */
        $saved_db = DbUtil::switchToGlobal();
        $querySelect = "SELECT * FROM specimen_mapping";
        $resultset = query_associative_all($querySelect, $rowCount);
        if ($resultset) {
            $specimenIds = array();
            foreach ($resultset as $record) {
                $labIdSpecimenIds = explode(";", $record['lab_id_specimen_id']);
                foreach ($labIdSpecimenIds as $labIdSpecimenId) {
                    $labIdSpecimenIdsSeparated = explode(":", $labIdSpecimenId);
                    $labId = $labIdSpecimenIdsSeparated[0];
                    $specimenId = $labIdSpecimenIdsSeparated[1];
                    $specimenIds[$labId] = $specimenId;
                }
                foreach ($specimenRecords as $specimenRecord) {
                    if ($specimenIds[$labConfigId] == $specimenRecord->specimenTypeId) {
                        $specimenRecord->specimenTypeId = $specimenIds[$importLabConfigId];
                    }
                }
            }
        }
        /* Build a mapping of Tests from the Global Table & make appropriate substitutions */
        $querySelect = "SELECT * FROM test_mapping";
        $resultset = query_associative_all($querySelect, $rowCount);
        if ($resultset) {
            $testIds = array();
            foreach ($resultset as $record) {
                $labIdTestIds = explode(";", $record['lab_id_test_id']);
                foreach ($labIdTestIds as $labIdTestId) {
                    $labIdTestIdsSeparated = explode(":", $labIdTestId);
                    $labId = $labIdTestIdsSeparated[0];
                    $testId = $labIdTestIdsSeparated[1];
                    $testIds[$labId] = $testId;
                }
                foreach ($testRecords as $testRecord) {
                    if ($testIds[$labConfigId] == $testRecord->testTypeId) {
                        $testRecord->testTypeId = $testIds[$importLabConfigId];
                    }
                }
            }
        }
        DbUtil::switchRestore($saved_db);
        $i = 0;
        if ($specimenRecords) {
            foreach ($specimenRecords as $specimenRecord) {
                $saved_db = DbUtil::switchToLabConfig($importLabConfigId);
                $querySelect = "SELECT * FROM test " . "WHERE specimen_id={$specimenRecord->specimenId}";
                $resultset = query_associative_all($querySelect, $rowcount);
                DbUtil::switchRestore($saved_db);
                $specimenRecord->specimenId = get_max_specimen_id() + 1;
                $specimenRecord->patientId = $currentLabPatient->patientId;
                $specimenRecord->userId = $_SESSION['user_id'];
                $specimenRecord->doctor = '';
                add_specimen($specimenRecord);
                for ($j = 0; $j < count($resultset); $j++) {
                    $testRecord = $testRecords[$i];
                    $testRecord->specimenId = $specimenRecord->specimenId;
                    $testRecord->userId = $_SESSION['user_id'];
                    $i++;
                    add_test($testRecord);
                }
            }
        }
        DbUtil::switchRestore($saved_db);
    }
}
Beispiel #2
0
	"WHERE name like '$patientName' ";
$record = query_associative_one($querySelect);
$newPatientId = $record['patient_id'];
*/
/* Create New Specimen & Test Records */
$i = 0;
foreach ($specimenRecords as $specimenRecord) {
    $saved_db = DbUtil::switchToLabConfig($importLabConfigId);
    $querySelect = "SELECT * FROM test " . "WHERE specimen_id={$specimenRecord->specimenId}";
    $resultset = query_associative_all($querySelect, $rowcount);
    DbUtil::switchRestore($saved_db);
    //$specimenRecord->specimenId = get_max_specimen_id() + 1;
    $specimenRecord->patientId = $importPatientId;
    $specimenRecord->userId = $_SESSION['user_id'];
    $specimenRecord->doctor = '';
    add_specimen($specimenRecord);
    for ($j = 0; $j < count($resultset); $j++) {
        $testRecord = $testRecords[$i];
        $testRecord->specimenId = $specimenRecord->specimenId;
        $testRecord->userId = $_SESSION['user_id'];
        $i++;
        add_test($testRecord, $testRecord['test_id']);
    }
}
DbUtil::switchRestore($saved_db);
?>
<script type="text/javascript">
window.location="../new_specimen.php?pid=<?php 
echo $importPatientId;
?>
";
Beispiel #3
0
    if (isset($_REQUEST['ref_out_name'])) {
        $specimen->referredToName = $_REQUEST['ref_out_name'];
    }
    if (isset($_REQUEST['ref_from_name'])) {
        $specimen->referredFromName = $_REQUEST['ref_from_name'];
    }
}
$specimen->referredTo = 0;
$specimen->reportTo = $report_to;
if ($doctor != "") {
    $specimen->doctor = $title . $doctor;
} else {
    $specimen->doctor = $doctor;
}
# Add entry to 'specimen' table
add_specimen($specimen);
# Add entries to 'specimen_custom_data'
$custom_field_list = get_custom_fields_specimen();
foreach ($custom_field_list as $custom_field) {
    $custom_value = get_custom_value($custom_field);
    $custom_data = new SpecimenCustomData();
    $custom_data->fieldId = $custom_field->id;
    $custom_data->fieldValue = $custom_value;
    $custom_data->specimenId = $specimen_id;
    add_custom_data_specimen($custom_data);
}
# Add entries to 'test' table
foreach ($tests_list as $test_type_id) {
    $test = new Test();
    $test->specimenId = $specimen_id;
    $test->testTypeId = $test_type_id;
Beispiel #4
0
function add_specimens_random($num_specimens, $user_list = array())
{
    # Adds random specimen entries with some tests scheduled
    global $MAX_NUM_SPECIMENS, $SPECIMEN_ID_START, $TESTS_ADDED, $NUM_SPECIMENS;
    global $MIN_COLLECTION_DATE, $MAX_COLLECTION_DATE, $P_NEW_TEST;
    $doctorNames = array('Buck', 'Harrel', 'Knight', 'Myers', 'Guzman', 'Jones', 'Fox', 'Hood', 'Sweeney', 'Dillards');
    $lab_config_id = $_SESSION['lab_config_id'];
    $min_date = $MIN_COLLECTION_DATE;
    $max_date = $MAX_COLLECTION_DATE;
    list($y_start, $m_start, $d_start) = explode("-", $min_date);
    list($y_end, $m_end, $d_end) = explode("-", $max_date);
    $ts_start = mktime(0, 0, 0, $m_start, $d_start, $y_start);
    $ts_end = mktime(0, 0, 0, $m_end, $d_end, $y_end);
    if ($num_specimens > $MAX_NUM_SPECIMENS) {
        $num_specimens = $MAX_NUM_SPECIMENS;
    }
    $specimen_type_list = get_lab_config_specimen_types($lab_config_id);
    $test_type_list = get_lab_config_test_types($lab_config_id);
    $count = 0;
    $specimen_id_count = $SPECIMEN_ID_START;
    while ($count < $num_specimens) {
        $user_id = 0;
        if (count($user_list) != 0) {
            $random_user_index = rand(1, count($user_list));
            $random_user = $user_list[$random_user_index - 1];
            $user_id = $random_user->userId;
        }
        $specimen_type_id = get_random_element($specimen_type_list);
        $patient_id = get_random_patient_id();
        # Create a new specimen entry
        $specimen = new Specimen();
        $specimen->specimenId = $specimen_id_count;
        $specimen->specimenTypeId = $specimen_type_id;
        $specimen->patientId = $patient_id;
        $specimen->userId = $user_id;
        # Alternatively, above userId can be linked to $_SESSION['user_id']
        $randomDate = get_random_date($ts_start, $ts_end);
        $specimen->dateCollected = $randomDate;
        $specimen->dateRecvd = $specimen->dateCollected;
        $specimen->statusCodeId = Specimen::$STATUS_PENDING;
        $specimen->reportTo = 1;
        $specimen->doctor = $doctorNames[rand(0, 9)];
        $specimen->referredTo = 0;
        $specimen->comments = "";
        $specimen->auxId = "";
        # Schedule tests for this specimen
        $compatible_test_list = get_compatible_tests($specimen_type_id);
        if (count($compatible_test_list) == 0) {
            # No compatible tests found in the lab configuration
            # Undo specimen entry addition
            //rollback_transaction();
            # TODO: Add error handling here (or do checking on front-end)
            # Update counters
            $TESTS_ADDED++;
            $specimen_id_count++;
            $count++;
            continue;
        }
        $candidate_test_list = array_values(array_intersect($compatible_test_list, $test_type_list));
        if (count($candidate_test_list) == 0) {
            # No compatible tests found in the lab configuration
            # Undo specimen entry addition
            //rollback_transaction();
            # Update counters
            $TESTS_ADDED++;
            $specimen_id_count++;
            $count++;
            continue;
        }
        $saved_db = DbUtil::switchToLabConfig($lab_config_id);
        add_specimen($specimen);
        list($y_end, $m_end, $d_end) = explode("-", $randomDate);
        $rstartTime = mktime(0, 0, 0, $m_end, $d_end, $y_end);
        $rendTime = mktime(23, 59, 59, $m_end, $d_end, $y_end);
        do {
            $testTs = getRandomDateWithTime($rstartTime, $rendTime);
            $test_entry = get_new_test($specimen_id_count, $candidate_test_list, $testTs);
            add_test_random($test_entry);
        } while (with_probability($P_NEW_TEST) && count($candidate_test_list) > 0);
        DbUtil::switchRestore($saved_db);
        //commit_transaction();
        # Update counters
        $TESTS_ADDED++;
        $specimen_id_count++;
        $count++;
    }
    # Update global count fo book-keeping
    $NUM_SPECIMENS = $num_specimens;
}