Ejemplo n.º 1
0
function get_records_to_print($lab_config, $patient_id)
{
    global $date_from, $date_to;
    $retval = array();
    if (isset($_REQUEST['ip']) && $_REQUEST['ip'] == 0) {
        # Do not include pending tests
        $query_string = "SELECT t.* FROM test t, specimen sp " . "WHERE t.result <> '' " . "AND t.specimen_id=sp.specimen_id " . "AND sp.patient_id={$patient_id} ";
        if (isset($_REQUEST['yf'])) {
            $query_string .= "AND (sp.date_collected BETWEEN '{$date_from}' AND '{$date_to}') ";
        }
        $query_string .= "ORDER BY sp.date_collected DESC";
    } else {
        # Include pending tests
        $query_string = "SELECT t.* FROM test t, specimen sp " . "WHERE t.specimen_id=sp.specimen_id " . "AND sp.patient_id={$patient_id} ";
        if (isset($_REQUEST['yf'])) {
            $query_string .= "AND (sp.date_collected BETWEEN '{$date_from}' AND '{$date_to}') ";
        }
        $query_string .= "ORDER BY sp.date_collected DESC";
    }
    $resultset = query_associative_all($query_string, $row_count);
    if (count($resultset) == 0 || $resultset == null) {
        return $retval;
    }
    foreach ($resultset as $record) {
        $test = Test::getObject($record);
        $hide_patient_name = TestType::toHidePatientName($test->testTypeId);
        if ($hide_patient_name == 1) {
            $hidePatientName = 1;
        }
        $specimen = get_specimen_by_id($test->specimenId);
        $retval[] = array($test, $specimen, $hide_patient_name);
    }
    return $retval;
}
Ejemplo n.º 2
0
function get_activity_test($lab_config_id, $user_id, $date_from, $date_to)
{
    $query_string = "SELECT * from test " . "WHERE user_id={$user_id} " . "AND (ts BETWEEN '{$date_from}' AND '{$date_to}' ) " . "AND result <> '' ORDER BY ts DESC";
    $resultset = query_associative_all($query_string, $row_count);
    $retval = array();
    foreach ($resultset as $record) {
        $test_entry = Test::getObject($record);
        $retval[] = $test_entry;
    }
    return $retval;
}
Ejemplo n.º 3
0
function get_unverified_tests($test_type_id)
{
    # Fetches all unverified test results
    $query_string = "SELECT * FROM test " . "WHERE verified_by=0 " . "AND result <> '' " . "AND test_type_id={$test_type_id}";
    $resultset = query_associative_all($query_string, $row_count);
    $retval = array();
    foreach ($resultset as $record) {
        $test_entry = Test::getObject($record);
        $retval[] = $test_entry;
    }
    return $retval;
}
Ejemplo n.º 4
0
function get_records_to_print($lab_config, $test_type_id, $date_from, $date_to)
{
    $saved_db = DbUtil::switchToLabConfig($lab_config->id);
    $retval = array();
    $query_string = "SELECT * FROM test WHERE test_type_id={$test_type_id} " . "AND specimen_id IN ( " . "SELECT specimen_id FROM specimen " . "WHERE date_collected BETWEEN '{$date_from}' AND '{$date_to}' " . ")";
    $resultset = query_associative_all($query_string, $row_count);
    foreach ($resultset as $record) {
        $test = Test::getObject($record);
        $specimen = Specimen::getById($test->specimenId);
        $patient = Patient::getById($specimen->patientId);
        $retval[] = array($test, $specimen, $patient);
    }
    DbUtil::switchRestore($saved_db);
    return $retval;
}
Ejemplo n.º 5
0
function get_records_to_print($lab_config, $patient_id)
{
    $retval = array();
    # Include pending tests
    $query_string = "SELECT t.* FROM test t, specimen sp " . "WHERE t.specimen_id=sp.specimen_id " . "AND sp.patient_id={$patient_id} ";
    $resultset = query_associative_all($query_string, $row_count);
    if (count($resultset) == 0 || $resultset == null) {
        return $retval;
    }
    foreach ($resultset as $record) {
        $test = Test::getObject($record);
        $specimen = get_specimen_by_id($test->specimenId);
        $retval[] = array($test, $specimen);
    }
    return $retval;
}
Ejemplo n.º 6
0
function mergedata()
{
    if (!isset($_SESSION['lab_config_id'])) {
        return false;
    }
    $workedID = "";
    $lab_config = $_SESSION['lab_config_id'];
    $saved_db = DbUtil::switchToLabConfig($importLabConfigId);
    $querySelect = "SELECT patient_id,name,surr_id,addl_id FROM patient order by surr_id asc";
    $resultset = query_associative_all($querySelect, $rowCount);
    $rowCount = 0;
    foreach ($resultset as $record) {
        if (strstr($workedID, $record['surr_id'])) {
            continue;
        } else {
            $workedID .= "," . $record['surr_id'];
        }
        $querySelect = "SELECT patient_id,name,surr_id,addl_id FROM patient where \n\t\tsurr_id='" . $record['surr_id'] . "' and \n\t\tpatient_id <> " . $record['patient_id'];
        $Dupresult = query_associative_all($querySelect, $rowCount);
        foreach ($Dupresult as $Duprecord) {
            $rowCount += 1;
            echo '<br> Working... ' . $record['surr_id'];
            //update spacimen
            $updateQuery = "update specimen set patient_id=" . $record['patient_id'] . "where patient_id=" . $Duprecord['patient_id'];
            query_blind($updateQuery);
            //update bills
            $updateQuery = "update bills set patient_id=" . $record['patient_id'] . "where patient_id=" . $Duprecord['patient_id'];
            query_blind($updateQuery);
            //now delete from custom_data and patients table
            $deleteQuery = "delete from patient_custom_data where patient_id=" . $Duprecord['patient_id'];
            query_blind($deleteQuery);
            $deleteQuery = "delete from patient where patient_id=" . $Duprecord['patient_id'];
            query_blind($deleteQuery);
        }
    }
    //var_dump ( $resultset);
    if ($rowCount > 0) {
        echo '<br>' . $rowCount . " Duplicate Records corrected.";
    } else {
        echo '<br>' . "No Duplicate Records found.";
    }
    return true;
}
Ejemplo n.º 7
0
	public function listOwnedLabs($admin_user_id)
	{
		# Returns list of lab configurations / sites owned by the admin user
		$query_string =
			"SELECT * FROM lab_config WHERE admin_user_id=$admin_user_id";
		$resultset = query_associative_all($query_string, $row_count);
		$retval = "";
		if(count($resultset) == 0)
		{
			$retval = "-";
			return $retval;
		}
		foreach($resultset as $record)
		{
			$lab_config = LabConfig::getObject($record);
			$retval .= $lab_config->getSiteName()."<br>";
		}
		return $retval;
	}
Ejemplo n.º 8
0
function get_records_to_print($lab_config, $patient_id)
{
    global $date_from, $date_to, $LIS_DOCTOR;
    $retval = array();
    if (isset($_REQUEST['ip']) && $_REQUEST['ip'] == 0) {
        # Do not include pending tests
        $labsection = 0;
        if (isset($_REQUEST['labsection'])) {
            $labsection = $_REQUEST['labsection'];
        }
        if ($labsection == 0) {
            $query_string = "SELECT t.* FROM test t, specimen sp " . "WHERE t.result <> '' " . "AND t.specimen_id=sp.specimen_id " . "AND sp.patient_id={$patient_id} ";
        } else {
            $query_string = "SELECT distinct t.* FROM test t, specimen sp, test_type tt, test_category tc " . "WHERE t.specimen_id=sp.specimen_id " . "AND t.result <> '' " . "AND sp.patient_id={$patient_id} " . "AND t.test_type_id = tt.test_type_id " . "AND tt.test_type_id in (select test_type_id from test_type where test_category_id = {$labsection})";
        }
        #Taking care of removal tests cases
        $query_string .= " AND t.test_id not in (select distinct r_id from removal_record where `status` = 1) ";
        if (isset($_REQUEST['yf'])) {
            $query_string .= "AND (sp.date_collected BETWEEN '{$date_from}' AND '{$date_to}') ";
        }
        $query_string .= "ORDER BY sp.date_collected DESC";
    } else {
        # Include pending tests
        $labsection = 0;
        if (isset($_REQUEST['labsection'])) {
            $labsection = $_REQUEST['labsection'];
        }
        if ($labsection == 0) {
            $query_string = "SELECT t.* FROM test t, specimen sp " . "WHERE t.specimen_id=sp.specimen_id " . "AND sp.patient_id={$patient_id} ";
        } else {
            $query_string = "SELECT distinct t.* FROM test t, specimen sp, test_type tt, test_category tc " . "WHERE t.specimen_id=sp.specimen_id " . "AND sp.patient_id={$patient_id} " . "AND t.test_type_id = tt.test_type_id " . "AND tt.test_type_id in (select test_type_id from test_type where test_category_id = {$labsection})";
        }
        #Taking care of removal tests cases
        $query_string .= " AND t.test_id not in (select distinct r_id from removal_record where `status` = 1) ";
        if (isset($_REQUEST['yf'])) {
            $query_string .= "AND (sp.date_collected BETWEEN '{$date_from}' AND '{$date_to}') ";
        }
        $query_string .= "ORDER BY sp.date_collected DESC";
    }
    $resultset = query_associative_all($query_string, $row_count);
    if (count($resultset) == 0 || $resultset == null) {
        return $retval;
    }
    foreach ($resultset as $record) {
        $test = Test::getObject($record);
        if ($_SESSION['user_level'] == $LIS_DOCTOR) {
            if ($test->verifiedBy == 0) {
                continue;
            }
        }
        $hide_patient_name = TestType::toHidePatientName($test->testTypeId);
        if ($hide_patient_name == 1) {
            $hidePatientName = 1;
        }
        $specimen = get_specimen_by_id($test->specimenId);
        $retval[] = array($test, $specimen, $hide_patient_name);
    }
    return $retval;
}
Ejemplo n.º 9
0
$lab_config->testList = $selected_test_list;


$master_specimen_list = get_specimen_types_catalog(true);
$selected_specimen_list = array();
foreach($master_specimen_list as $specimen_type_id=>$specimen_name)
{
	if(isset($_REQUEST['s_type_'.$specimen_type_id]))
		$selected_specimen_list[] = $specimen_type_id;
}
$lab_config->specimenList = $selected_specimen_list;
*/
$lab_config->idMode = $_REQUEST['id_mode'];
$saved_db = DbUtil::switchToGlobal();
$query = "SELECT country from lab_config";
$records = query_associative_all($query, $row_count);
foreach ($records as $record) {
    if (strcmp($record['country'], $country) == 0) {
        $count++;
    }
}
$count++;
DbUtil::switchRestore($saved_db);
/*
$query_string = "show databases";
$records = query_associative_all($query_string, $row_count);
$count = 0;
foreach($records as $record) {
	if( strpos($record['database'], $country) != FALSE ) {
		$count++;
	}
Ejemplo n.º 10
0
         }
         $date_ts = $second_day_ts;
         $i++;
     }
     DbUtil::switchRestore($saved_db);
     return $retval;
 }
 public static function getDiscreteInfectionStatsMonthly($lab_config, $test_type_id, $date_from, $date_to, $gender = null)
 {
     $i = 1;
     # Fetch all test types with one measure having discrete P/N range
     $retval = array();
     $saved_db = DbUtil::switchToLabConfig($lab_config->id);
     $date_from_parts = explode("-", $date_from);
     $date_to_parts = explode("-", $date_to);
     $month_ts = mktime(0, 0, 0, $date_from_parts[1], 0, $date_from_parts[0]);
     $date_to_ts = mktime(0, 0, 0, $date_to_parts[1], 0, $date_to_parts[0]);
     # For the test type, fetch negative records
     while ($month_ts < $date_to_ts) {
         $end_of_month_ts = mktime(0, 0, 0, $date_from_parts[1] + $i, 0, $date_from_parts[0]);
         $date_fromp = date("Y-m-d", $month_ts);
         $date_top = date("Y-m-d", $end_of_month_ts);
         if ($gender == 'M' || $gender == 'F') {
             $query_string = "SELECT COUNT(*) AS count_val  FROM test t, patient p, specimen s " . "WHERE t.test_type_id={$test_type_id} " . "AND p.patient_id=s.patient_id " . "AND p.sex LIKE '{$gender}' " . "AND t.specimen_id=s.specimen_id " . "AND (s.date_collected BETWEEN '{$date_fromp}' AND '{$date_top}') " . "AND  (t.result LIKE 'N,%' OR t.result LIKE 'n�gatif,%' OR t.result LIKE 'negatif,%' OR t.result LIKE 'n,%' OR t.result LIKE 'negative,%')";
         } else {
             $query_string = "SELECT COUNT(*) AS count_val  FROM test t, specimen s " . "WHERE t.test_type_id={$test_type_id} " . "AND t.specimen_id=s.specimen_id " . "AND ( s.date_collected BETWEEN '{$date_fromp}' AND '{$date_top}' )" . "AND  (result LIKE 'N,%' OR result LIKE 'n�gatif,%' OR result LIKE 'negatif,%' OR result LIKE 'n,%' OR result LIKE 'negative,%')";
         }
         $record = query_associative_one($query_string);
         $count_negative = $record['count_val'];
         $query_string = "SELECT COUNT(*) AS count_val  FROM test t, specimen s " . "WHERE t.test_type_id={$test_type_id} " . "AND t.specimen_id=s.specimen_id " . "AND result!=''" . "AND ( s.date_collected BETWEEN '{$date_fromp}' AND '{$date_top}' )";
         $record = query_associative_one($query_string);
         $count_all = $record['count_val'];
         # If total tests is 0, ignore
         if ($count_all != 0) {
             $retval[$month_ts] = array($count_all, $count_negative);
         }
         $month_ts = $end_of_month_ts;
Ejemplo n.º 11
0
<?php

include "../includes/db_lib.php";
include "../includes/user_lib.php";
$patientId = $_REQUEST['p_id'];
$logType = $_REQUEST['log_type'];
$saved_db = DbUtil::switchToGlobal();
$query_configs = "SELECT created_by, creation_date from user_log where patient_id =  " . $patientId . " and log_type = '" . $logType . "'";
$resultset = query_associative_all($query_configs, 0);
DbUtil::switchRestore($saved_db);
$saved_db = DbUtil::switchToLabConfig($_SESSION['lab_config_id']);
$queryString = "SELECT t_fields from report_config where report_id =1 ";
$record2 = query_associative_one($queryString);
$test_field_list = explode(",", $record2['t_fields']);
DbUtil::switchRestore($saved_db);
if ($resultset != null && ($logType == 'PRINT' && $test_field_list[10] || $logType == 'RESULT' && $test_field_list[11]) == '1') {
    $ret_str = "User id\t\t\t\t Print date";
    foreach ($resultset as $aish) {
        $ret_str .= "\n  " . $aish['created_by'] . "\t\t\t\t" . $aish['creation_date'];
    }
    echo $ret_str;
} else {
    echo "false";
}
Ejemplo n.º 12
0
function remarks_db2xml($langdata_path, $lab_config_id)
{
    # Creates XML file from existing test measures (indicators) in catalog
    global $VERSION;
    $new_version = $VERSION;
    $handle = fopen($langdata_path . "remarks.xml", "w");
    $string_data = <<<EOF
<?xml version="1.0"?>
<measures version="{$new_version}">

EOF;
    fwrite($handle, $string_data);
    $saved_db = DbUtil::switchToLabConfigRevamp($lab_config_id);
    $query_string = "SELECT * FROM measure";
    $resultset = query_associative_all($query_string, $row_count);
    foreach ($resultset as $record) {
        $curr_measure = Measure::getObject($record);
        $id = $curr_measure->measureId;
        $descr = $curr_measure->name;
        $string_data = <<<EOF
\t<measure id="{$id}" descr="{$descr}">

EOF;
        fwrite($handle, $string_data);
        $range_type = $curr_measure->getRangeType();
        $range_values = $curr_measure->getRangeValues();
        if ($range_type == Measure::$RANGE_NUMERIC) {
            $lower_bound = htmlspecialchars($range_values[0]);
            $upper_bound = htmlspecialchars($range_values[1]);
            $string_data = <<<EOF
\t\t<range>
\t\t\t<key>{$range_values['0']}:{$range_values['1']}</key>
\t\t\t<value></value>
\t\t</range>

EOF;
            fwrite($handle, $string_data);
        } else {
            if ($range_type == Measure::$RANGE_OPTIONS) {
                foreach ($range_values as $range_value) {
                    $range_value_xml = htmlspecialchars($range_value);
                    $string_data = <<<EOF
\t\t<range>
\t\t\t<key>{$range_value_xml}</key>
\t\t\t<value></value>
\t\t</range>

EOF;
                    fwrite($handle, $string_data);
                }
            }
        }
        $string_data = <<<EOF
\t</measure>

EOF;
        fwrite($handle, $string_data);
    }
    $string_data = <<<EOF
</measures>

EOF;
    fwrite($handle, $string_data);
    fclose($handle);
    DbUtil::switchRestore($saved_db);
}
Ejemplo n.º 13
0
 public function getConfigs($lab_config_id)
 {
     $sql = "select * from dhims2_api_config";
     $resultset = query_associative_all($sql, $row_count, $lab_config_id);
     $results = array();
     $larr = array();
     $orgunitTrimList = array();
     $datasetTrimList = array();
     $dataelementTrimList = array();
     $genderTrimList = array();
     $icount = count($resultset);
     for ($i = 0; $i < $icount; $i++) {
         $orgunit = explode('^', $resultset[$i]['orgunit']);
         if (!in_array($orgunit[0], $orgunitTrimList)) {
             $larr['id'] = $orgunit[0];
             $larr['pId'] = 0;
             $larr['name'] = $orgunit[1];
             $larr['open'] = true;
             $larr['ename'] = $resultset[$i]['id'];
             $results[] = $larr;
             $larr = array();
             $orgunitTrimList[] = $orgunit[0];
         }
         $dataset = explode('^', $resultset[$i]['dataset']);
         if (!in_array($dataset[0], $datasetTrimList)) {
             $larr['id'] = $dataset[0];
             $larr['pId'] = $orgunit[0];
             $larr['name'] = $dataset[1];
             $larr['isParent'] = true;
             $larr['open'] = true;
             $larr['ename'] = $resultset[$i]['id'];
             $results[] = $larr;
             $larr = array();
             $datasetTrimList[] = $dataset[0];
         }
         $dataelement = explode('|', $resultset[$i]['dataelement']);
         //$elementname = explode('|',$dataelement[1]);
         $elementname = "";
         $dsetparts = explode('^', $dataelement[0]);
         //.$elementname[1];
         for ($dcount = 1; $dcount < count($dataelement); $dcount++) {
             $tmp = explode('^', $dataelement[$dcount]);
             if (empty($elementname)) {
                 $elementname .= $tmp[1];
             } else {
                 $elementname .= '+' . $tmp[1];
             }
         }
         $dsetElem = $dsetparts[0];
         if (!in_array($dsetElem, $dataelementTrimList)) {
             $larr['id'] = $dsetElem;
             $larr['pId'] = $dataset[0];
             $larr['name'] = $dsetparts[1] . '-->' . $elementname;
             $larr['open'] = true;
             $larr['isParent'] = true;
             $larr['ename'] = $resultset[$i]['id'];
             $results[] = $larr;
             $larr = array();
             $dataelementTrimList[] = $dsetElem;
         }
         if ($resultset[$i]['gender'] == "M") {
             if (!in_array($dsetElem . '_M', $genderTrimList)) {
                 $larr['id'] = $dsetElem . '_M';
                 $larr['pId'] = $dsetElem;
                 $comboname = explode('|', $categorycombo[1]);
                 $larr['name'] = "Male";
                 $larr['open'] = true;
                 $larr['isParent'] = true;
                 $larr['ename'] = $resultset[$i]['id'];
                 $results[] = $larr;
                 $larr = array();
                 $genderTrimList[] = $dsetElem . '_M';
             }
             $categorycombo = explode('^', $resultset[$i]['categorycombo']);
             $larr['id'] = $categorycombo[0];
             $larr['pId'] = $dsetElem . '_M';
             $comboname = explode('|', $categorycombo[1]);
             $larr['name'] = $comboname[0] . '-->' . $comboname[1];
             $larr['open'] = true;
             $larr['ename'] = $resultset[$i]['id'];
             $results[] = $larr;
             $larr = array();
         } elseif ($resultset[$i]['gender'] == "F") {
             if (!in_array($dsetElem . '_F', $genderTrimList)) {
                 $larr['id'] = $dsetElem . '_F';
                 $larr['pId'] = $dsetElem;
                 $comboname = explode('|', $categorycombo[1]);
                 $larr['name'] = "Female";
                 $larr['open'] = true;
                 $larr['isParent'] = true;
                 $larr['ename'] = $resultset[$i]['id'];
                 $results[] = $larr;
                 $larr = array();
                 $genderTrimList[] = $dsetElem . '_F';
             }
             $categorycombo = explode('^', $resultset[$i]['categorycombo']);
             $larr['id'] = $categorycombo[0];
             $larr['pId'] = $dsetElem . '_F';
             $comboname = explode('|', $categorycombo[1]);
             $larr['name'] = $comboname[0] . '-->' . $comboname[1];
             $larr['open'] = true;
             $larr['ename'] = $resultset[$i]['id'];
             $results[] = $larr;
             $larr = array();
         } else {
             if (!in_array($dsetElem . '_B', $genderTrimList)) {
                 $larr['id'] = $dsetElem . '_B';
                 $larr['pId'] = $dsetElem;
                 $comboname = explode('|', $categorycombo[1]);
                 $larr['name'] = "Male & Female";
                 $larr['open'] = true;
                 $larr['isParent'] = true;
                 $larr['ename'] = $resultset[$i]['id'];
                 $results[] = $larr;
                 $larr = array();
                 $genderTrimList[] = $dsetElem . '_B';
             }
             $categorycombo = explode('^', $resultset[$i]['categorycombo']);
             $larr['id'] = $categorycombo[0];
             $larr['pId'] = $dsetElem . '_B';
             $comboname = explode('|', $categorycombo[1]);
             $larr['name'] = $comboname[0] . '-->' . $comboname[1];
             $larr['open'] = true;
             $larr['ename'] = $resultset[$i]['id'];
             $results[] = $larr;
             $larr = array();
         }
         //if($i==2)
         //break;
     }
     //file_put_contents("dhims2.txt",print_r($results));
     return $results;
     //print_r($results);
 }
Ejemplo n.º 14
0
 public function get_inv_usage_by_user($lid, $user)
 {
     $lab_config_id = $lid;
     $saved_db = DbUtil::switchToLabConfig($lab_config_id);
     $query_string = "SELECT * from inv_usage WHERE user_id = {$user}";
     $recordset = query_associative_all($query_string, $row_count);
     DbUtil::switchRestore($saved_db);
     return $recordset;
 }
Ejemplo n.º 15
0
function add_results_sequential($user_list = array())
{
    # Adds random result entries for scheduled specimen
    global $NUM_SPECIMENS, $F_PENDING, $SPECIMEN_ID_START;
    $lab_config_id = $_SESSION['lab_config_id'];
    $saved_db = DbUtil::switchToLabConfig($lab_config_id);
    $num_specimens2 = query_num_rows("specimen");
    $specimens_to_handle = floor($num_specimens2 * (1 - $F_PENDING));
    $specimen_target_list = array();
    $query_string = "SELECT * FROM specimen ORDER BY date_collected LIMIT " . $specimens_to_handle;
    $resultset = query_associative_all($query_string, $row_count);
    foreach ($resultset as $record) {
        $specimen_entry = Specimen::getObject($record);
        $specimen_target_list[] = $specimen_entry;
    }
    DbUtil::switchRestore($saved_db);
    $count = 0;
    $specimen_id_count = $SPECIMEN_ID_START;
    foreach ($specimen_target_list as $specimen) {
        if ($specimen == null) {
            # TODO:
        }
        $result_entry_ts = get_random_ts($specimen->dateCollected);
        if ($specimen == null) {
            #  Specimen does not exist
            //echo "Specimen does not exist<br>";
            //$count++;
            $specimen_id_count++;
            continue;
        }
        $saved_db = DbUtil::switchToLabConfig($_SESSION['lab_config_id']);
        $specimen_id = $specimen->specimenId;
        $status_code = get_specimen_status($specimen_id);
        DbUtil::switchRestore($saved_db);
        if ($status_code == Specimen::$STATUS_DONE) {
            # Results already entered
            //echo "Results already entered<br>";
            $count++;
            $specimen_id_count++;
            continue;
        }
        $patientId = $specimen->patientId;
        $currentPatient = Patient::getById($patientId);
        $hashValue = $currentPatient->generateHashValue();
        # Fetch tests scheduled for this specimen
        $test_list = get_tests_by_specimen_id($specimen_id);
        # For each test, fetch test measures and range from catalog
        foreach ($test_list as $test) {
            $measure_list = get_test_type_measures($test->testTypeId);
            $result_entry = "";
            foreach ($measure_list as $measure) {
                $range = get_measure_range($measure);
                # Select random result value
                $result_val = get_random_range_value($range);
                csv_append($result_val, $result_entry);
            }
            $test_id = $test->testId;
            # Update result field in test entry
            $saved_db = DbUtil::switchToLabConfig($lab_config_id);
            # Select random technician as the one of entered this result
            $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;
            }
            add_test_result($test_id, $result_entry, "", "", $user_id, $result_entry_ts, $hashValue);
            # Randomly this test result mark as verified or keep as unverified
            # null or 0 => not verified, non-zero => verified.
            if (with_probability(0.9)) {
                $is_verified = 2;
                $test->setVerifiedBy($is_verified);
            }
            DbUtil::switchRestore($saved_db);
        }
        $saved_db = DbUtil::switchToLabConfig($lab_config_id);
        # Mark specimen as 'all tests done'
        update_specimen_status($specimen_id);
        # Randomly mark this specimen as reported or keep as unreported
        if (with_probability(0.9)) {
            $date_reported = date("Y-m-d H:i:s");
            $specimen->setDateReported($date_reported);
        }
        DbUtil::switchRestore($saved_db);
        # Update counters
        $count++;
        $specimen_id_count++;
    }
}
Ejemplo n.º 16
0
 public static function getUnReportedByRegDateRange($date_from, $date_to)
 {
     $emp = "";
     $query_string = "SELECT DISTINCT patient_id FROM specimen , test " . "WHERE date_collected BETWEEN '{$date_from}' AND '{$date_to}' " . "AND result='{$emp}' " . "AND specimen.specimen_id=test.specimen_id";
     $resultset = query_associative_all($query_string, $row_count);
     $retval = array();
     $record_p = array();
     foreach ($resultset as $record) {
         foreach ($record as $key => $value) {
             $query_string = "SELECT * FROM patient WHERE patient_id={$value}";
         }
         $record_each = query_associative_one($query_string);
         $record_p[] = Patient::getObject($record_each);
     }
     return $record_p;
 }
Ejemplo n.º 17
0
<?php

#
# Returns a list of similar patient names
# To aid/help during new patient registration
#
include "../includes/db_lib.php";
LangUtil::setPageId("new_patient");
$q = $_REQUEST['q'];
$query_string = "SELECT * FROM patient " . "WHERE name LIKE '%{$q}%' ";
$resultset = query_associative_all($query_string, $row_count);
if (count($resultset) == 0 || $resultset == null) {
    return;
}
$patient_list = array();
foreach ($resultset as $record) {
    $patient_list[] = Patient::getObject($record);
}
?>
<table class='hor-minimalist-c' style='width:450px;'>
	<thead>
		<tr valign='top'>
			<th>
				<span style='background-color:#FFCC66'><?php 
echo LangUtil::$pageTerms['SIMILAR_NAMES'];
?>
</span>
			</th>
			<?php 
if ($_SESSION['pid'] != 0) {
    ?>
Ejemplo n.º 18
0
$patient->createdBy = $_SESSION['user_id'];
DbUtil::switchRestore($saved_db);
add_patient($patient, true);
/*
$querySelect =
	"SELECT patient_id FROM patient ".
	"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);
Ejemplo n.º 19
0
function processWeeklyTrends($lab_config_id, $test_type_id, $date_from, $date_to, $test_name = null)
{
    global $namesArray;
    global $stat_list;
    # All Tests & All Labs */
    if ($test_type_id == 0 && $lab_config_id == 0) {
        $site_list = get_site_list($_SESSION['user_id']);
        $userId = $_SESSION['user_id'];
        $saved_db = DbUtil::switchToGlobal();
        $query = "SELECT * FROM test_mapping WHERE user_id = {$userId}";
        $resultset = query_associative_all($query, $row_count);
        foreach ($resultset as $record) {
            $labIdTestIds = explode(';', $record['lab_id_test_id']);
            foreach ($labIdTestIds as $labIdTestId) {
                $labIdTestId = explode(':', $labIdTestId);
                $labId = $labIdTestId[0];
                $testId = $labIdTestId[1];
                $test_type_list_all[$labId][] = $testId;
                $test_type_names[$labId][] = $record['test_name'];
            }
        }
        DbUtil::switchRestore($saved_db);
        foreach ($site_list as $key => $value) {
            $lab_config = LabConfig::getById($key);
            $test_type_list = array();
            $test_type_list = $test_type_list_all[$key];
            $testNames = $test_type_names[$key];
            $saved_db = DbUtil::switchToLabConfig($lab_config->id);
            $testCount = -1;
            foreach ($test_type_list as $test_type_id) {
                $query_string = "SELECT COUNT(*) AS count_val FROM test t, specimen s " . "WHERE t.test_type_id={$test_type_id} " . "AND t.specimen_id=s.specimen_id " . "AND result!=''" . "AND ( s.date_collected BETWEEN '{$date_from}' AND '{$date_to}' )";
                $record = query_associative_one($query_string);
                $count_all = intval($record['count_val']);
                $testCount++;
                if ($count_all == 0) {
                    continue;
                }
                $namesArray[] = $lab_config->name . " - " . $testNames[$testCount];
                getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to);
            }
        }
    } else {
        if ($test_type_id == 0 && count($lab_config_id) == 1) {
            $lab_config = LabConfig::getById($lab_config_id[0]);
            $test_type_list = get_discrete_value_test_types($lab_config);
            foreach ($test_type_list as $test_type_id) {
                $namesArray[] = get_test_name_by_id($test_type_id, $lab_config_id[0]);
                getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to);
            }
        } else {
            if ($test_type_id == 0 && count($lab_config_id) > 1) {
                $userId = $_SESSION['user_id'];
                $saved_db = DbUtil::switchToGlobal();
                $query = "SELECT * FROM test_mapping WHERE user_id = {$userId}";
                $resultset = query_associative_all($query, $row_count);
                foreach ($resultset as $record) {
                    $labIdTestIds = explode(';', $record['lab_id_test_id']);
                    foreach ($labIdTestIds as $labIdTestId) {
                        $labIdTestId = explode(':', $labIdTestId);
                        $labId = $labIdTestId[0];
                        $testId = $labIdTestId[1];
                        $test_type_list_all[$labId][] = $testId;
                        $test_type_names[$labId][] = $record['test_name'];
                    }
                }
                DbUtil::switchRestore($saved_db);
                foreach ($lab_config_id as $key) {
                    $lab_config = LabConfig::getById($key);
                    $test_type_list = array();
                    $test_type_list = $test_type_list_all[$key];
                    $testNames = $test_type_names[$key];
                    $saved_db = DbUtil::switchToLabConfig($lab_config->id);
                    $testCount = -1;
                    foreach ($test_type_list as $test_type_id) {
                        $query_string = "SELECT COUNT(*) AS count_val FROM test t, specimen s " . "WHERE t.test_type_id={$test_type_id} " . "AND t.specimen_id=s.specimen_id " . "AND result!=''" . "AND ( s.date_collected BETWEEN '{$date_from}' AND '{$date_to}' )";
                        $record = query_associative_one($query_string);
                        $count_all = intval($record['count_val']);
                        $testCount++;
                        if ($count_all == 0) {
                            continue;
                        }
                        $namesArray[] = $lab_config->name . " - " . $testNames[$testCount];
                        getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to);
                    }
                }
            } else {
                /* Build Array Map with Lab Id as Key and Test Id as corresponding Value */
                $labIdTestIds = explode(";", $test_type_id);
                $testIds = array();
                foreach ($labIdTestIds as $labIdTestId) {
                    $labIdTestIdsSeparated = explode(":", $labIdTestId);
                    $labId = $labIdTestIdsSeparated[0];
                    $testId = $labIdTestIdsSeparated[1];
                    $testIds[$labId] = $testId;
                }
                # Particular Test & All Labs
                if ($test_type_id != 0 && $lab_config_id == 0) {
                    $site_list = get_site_list($_SESSION['user_id']);
                    foreach ($site_list as $key => $value) {
                        $lab_config = LabConfig::getById($key);
                        $test_type_id = $testIds[$lab_config->id];
                        $namesArray[] = $lab_config->name;
                        getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to);
                    }
                } else {
                    if ($test_type_id != 0 && count($lab_config_id) == 1) {
                        $lab_config = LabConfig::getById($lab_config_id[0]);
                        $test_type_id = $testIds[$lab_config->id];
                        $namesArray[] = $lab_config->name;
                        getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to);
                    } else {
                        if ($lab_config_id != 0 && $test_type_id != 0) {
                            foreach ($lab_config_id as $key) {
                                $lab_config = LabConfig::getById($key);
                                $test_type_id = $testIds[$lab_config->id];
                                $namesArray[] = $lab_config->name;
                                getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to);
                            }
                        }
                    }
                }
            }
        }
    }
    /*
    $lab_config = LabConfig::getById($lab_config_id[0]);
    if($lab_config) {
    	//$test_type_list = get_discrete_value_test_types($lab_config);
    		
    	foreach($test_type_list as $test_type_id) {
    		$namesArray[] = get_test_name_by_id($test_type_id, $lab_config_id[0]);
    		getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to);
    	}
    }
    */
}
Ejemplo n.º 20
0
 public function get_stock_usage($r_id, $lot)
 {
     if ($_SESSION['level'] < 2 || $_SESSION['level'] > 4) {
         $user = get_user_by_id($_SESSION['user_id']);
         $lid = $user->labConfigId;
     }
     if ($lid == null) {
         $lid = get_lab_config_id_admin($_SESSION['user_id']);
     }
     //$stocks_list = Inventory::getStocksList($lid, $r_id);
     $lab_config_id = $lid;
     $saved_db = DbUtil::switchToLabConfig($lab_config_id);
     $query_string = "SELECT * from inv_usage WHERE reagent_id = {$r_id} AND lot = '{$lot}'";
     $recordset = query_associative_all($query_string, $row_count);
     DbUtil::switchRestore($saved_db);
     $cc = 1;
     //echo "-".$recordset."-";
     //print_r($recordset);
     $spec = array();
     foreach ($recordset as $stock) {
         $quant = Inventory::getQuantity($lid, $reagent['id']);
         // $uni = $reagent['unit'];
         $spec[$cc]['id'] = $stock['id'];
         $spec[$cc]['quantity_used'] = $stock['quantity_used'];
         $spec[$cc]['user_id'] = $stock['user_id'];
         $spec[$cc]['remarks'] = $reagent['remarks'];
         $dp = explode("-", $stock['date_of_use']);
         $e_date = $dp[2] . "/" . $dp[1] . "/" . $dp[0];
         $spec[$cc]['date_of_use'] = $e_date;
         $cc++;
     }
     //$spec = get_specimen_by_id($specimen_id);
     if (count($spec) > 0) {
         $ret = $spec;
     } else {
         $ret = 0;
     }
     return $ret;
 }