I'm trying to create a script to display patient status information by departments/stations and by patient type within each department. I query one table to get a list of stations/departments and another table to select the data posted for each department or station at midnight of each night. However, I fell off a ladder and clunked my head last week and I'm not thinking toooo well at the moment. (I just got out of the hospital)
I can't think of how to present a table of patients per station (rows) and patient types (cols). I want a seperate table for each class of patient(in, out, unknown and nursery) Here is an example of the output I am trying for:
days -> 1 2 3 4 5 ... 31
dept going dwn
ICU total
MS1
MS2
total
Here is the query I run for PostgreSQL:
$sql = "SELECT *
FROM census
WHERE c_time BETWEEN '$yesterday' AND '$yesterday2' AND substring(c_time,12,2) = '00'
ORDER BY station_id ASC
";
This gets me all of the patients counts at midnight ordered by station/department. But I can't think of how to sort this result and prsent the number of midnight inpatients, outpatients, unknown patients and nursing patients at each station in a table. The db has columns for inpatients, outpatients, unknown patients and nursing patients.
I then try to split the results into patient type groups: (if the var >0 patients of that type existed)
while($myrow = pg_fetch_assoc($result))
{
//---in Patients
if($myrow['in_pat']>0)
{
$day=(int)substr($myrow['c_time'],8,2);
$station=$ipId[$day] = $myrow['station_id'];
$ipDat[$station][$day] = substr($myrow['c_time'],0,10);
$ipCount[$station][$day]= $myrow['in_pat'];
$ipTot=$ipTot+(int)$ipCount[$station][$day];
echo "inpat day $day, stat=$station date= $ipDat[$station][$day] [$station] count=$ipCount[$station][$day] tot=$ipTot <br>";
// $ip++;
}
//---out Patients
if($myrow['out_pat']>0)
{
$opDat[$op] = substr($myrow['c_time'],0,10);
$opId[$op] = $myrow['station_id'];
$opCount[$op]= $myrow['op_pat'];
$opTot=$opTot+(int)$opCount[$op];
$op++;
}
//---unknown Patients
if($myrow['unknown']>0)
{
$unDat[$up] = substr($myrow['c_time'],0,10);
$unId[$up] = $myrow['station_id'];
$upCount[$up]= $myrow['up_pat'];
$upTot=$upTot+(int)$upCount[$up];
$up++;
}
//---Nursery Patients
if($myrow['nursery']>0)
{
$npDat[$np] = substr($myrow['c_time'],0,10);
$npId[$np] = $myrow['station_id'];
$npCount[$np]=$myrow['nursery'];
$npTot=$npTot+(int)$npCount[$np];
$np++;
}
}
But, the problem with this loop is I'm not seperating the patients into their Station. I was trying to set up a Stations class that contains arrays for inpat, outpat etc for each day of the month (I'm assuming results will be requested for a month or part of a month. but I can't think of how to do it at the moment.
So, I was trying to think if I could do it as an associate array, but it looks like I would need a multi dimmensional array [station][inpatients][1]=count, for example, but I've not heard of this type of multidimmensional associative and index array.
Can anyone point me in the right direction?
Thanks:
Brad