Exemplo n.º 1
0
function update_specimen_type($updated_entry, $new_test_list)
{
    # Updates specimen type info in DB catalog
    $saved_db = DbUtil::switchToLabConfigRevamp();
    $existing_entry = get_specimen_type_by_id($updated_entry->specimenTypeId);
    if ($existing_entry == null) {
        # No record found
        DbUtil::switchRestore($saved_db);
        return;
    }
    $query_string = "UPDATE specimen_type " . "SET name='{$updated_entry->name}', " . "description='{$updated_entry->description}' " . "WHERE specimen_type_id={$updated_entry->specimenTypeId}";
    query_blind($query_string);
    # Delete entries for removed compatible tests
    $existing_list = get_compatible_tests($updated_entry->specimenTypeId);
    foreach ($existing_list as $test_type_id) {
        if (in_array($test_type_id, $new_test_list)) {
            # Compatible test not removed
            # Do nothing
        } else {
            # Remove entry from mapping table
            $query_del = "DELETE from specimen_test " . "WHERE test_type_id={$test_type_id} " . "AND specimen_type_id={$updated_entry->specimenTypeId}";
            query_blind($query_del);
        }
    }
    # Add entries for new compatible tests
    foreach ($new_test_list as $test_type_id) {
        if (in_array($test_type_id, $existing_list)) {
            # Entry already exists
            # Do nothing
        } else {
            # Add entry in mapping table
            $query_ins = "INSERT INTO specimen_test (specimen_type_id, test_type_id) " . "VALUES ({$updated_entry->specimenTypeId}, {$test_type_id})";
            query_blind($query_ins);
        }
    }
    DbUtil::switchRestore($saved_db);
}
Exemplo n.º 2
0
#
# Main page for modifying an existing specimen type
#
include "redirect.php";
include "includes/header.php";
include "includes/ajax_lib.php";
LangUtil::setPageId("catalog");
$script_elems->enableJQueryForm();
$script_elems->enableTokenInput();
$specimen_type = get_specimen_type_by_id($_REQUEST['sid']);
?>
<script type='text/javascript'>
$(document).ready(function(){
	<?php 
$test_list = get_compatible_tests($specimen_type->specimenTypeId);
foreach ($test_list as $test_type_id) {
    # Mark existing compatible tests as checked
    ?>
		$('#t_type_<?php 
    echo $test_type_id;
    ?>
').attr("checked", "checked"); 
		<?php 
}
?>
});

function update_stype()
{
	var old_specimen_name = "<?php 
Exemplo n.º 3
0
	public function getCompatibilityJsArray($array_name, $lab_config_id=null)
	{
		# Returns a JavaScript array storing compatible test types for each specimen type
		$specimen_type_list = get_specimen_types_catalog($lab_config_id);
		echo "$array_name=new Array(); ";
		foreach($specimen_type_list as $key=>$value)
		{
			$test_list = get_compatible_tests($key);
			$test_csv = implode(",", $test_list);
			echo $array_name."[".$key."]='$test_csv'; ";
		}
	}
Exemplo n.º 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;
}