--- inc/pgDS-ss.php 2001/08/27 09:17:40 1.2 +++ inc/pgDS-ss.php 2001/08/30 16:35:36 1.3 @@ -1,23 +1,95 @@ assign("symptom", strtoupper("Diarrohoea")); - $tpl->assign("bolesti", array( - "Gastro-enteritis", - "Antibiotics", - "IBS", - "Diverticulitis", - "Overflow" - )); - $tpl->assign("simptomi", array( - array("name" => "Vomiting too", "values" => array(0, 0, -1, 0, -1)), - array("name" => "Chronic or recurrent", "values" => array(-1, -1, 1, 0, 1)), - array("name" => "Colicky pain", "values" => array(1, -1, 1, 0, -1)), - array("name" => "Marked abdominal tenderness", "values" => array(-1, -1, -1, 1, -1)), - array("name" => "Blood in stool", "values" => array(0, 0, -1, 1, -1)) - )); - $tpl->assign("diag", array( - array() - )); - $tpl->assign("overview", "Tralala"); - $tpl->assign("investigations", "Tralala"); - $tpl->assign("red_flags", "Tralala"); + include_once("inc/conn.php"); + function mySS($a, $b) { + if ($a["name"] == $b["name"]) return 0; + return ($a["name"] < $b["name"]) ? -1 : 1; + } + function escape_quote($str) { + return str_replace('"', """, $str); + } + if (!$id) { + $simptomi = array(); + $sql = "SELECT simptom_id, naziv FROM simptomi WHERE (simptom_id <> 0)"; + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + while ($row = $sth->fetchrow_array()) + array_push($simptomi, array("id" => $row[0]."-0", "name" => MyEscape($row[1]))); + $sth->finish(); + $sql = "SELECT simptom_id, alias_id, alias FROM simptomi_aliasi"; + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + while ($row = $sth->fetchrow_array()) + array_push($simptomi, array("id" => $row[0]."-".$row[1], "name" => MyEscape($row[2]))); + $sth->finish(); + uasort($simptomi, "mySS"); + $slova = array(); + while (list($k, $v) = each($simptomi)) { + $fl = $v["name"][0]; + for ($i = 0; $i < count($slova); $i++) if ($slova[$i]["fl"] == $fl) break; + if (!$slova[$i]) $slova[$i] = array("fl" => $fl, "simptomi" => array()); + array_push($slova[$i]["simptomi"], $v); + } + $tpl->assign("slova", $slova); + } else { + list($sid, $aid) = explode("-", $id); + $sql = "SELECT ".($aid?"simptomi_aliasi.alias":"simptomi.naziv").", simptomi.opis, simptomi.overview, simptomi.investigations, simptomi.red_flags FROM simptomi".($aid?", simptomi_aliasi":"")." WHERE (simptomi.simptom_id = $sid)".($aid?" AND (simptomi_aliasi.simptom_id = simptomi.simptom_id) AND (simptomi_aliasi.alias_id = $aid)":""); + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + $row = $sth->fetchrow_array(); + $sth->finish(); + list($naziv, $opis, $overview, $invest, $redflags) = $row; + $tpl->assign("symptom", escape_quote($naziv)); + $tpl->assign("overview", escape_quote($overview)); + $tpl->assign("investigations", escape_quote($invest)); + $tpl->assign("red_flags", escape_quote($redflags)); + $sql = "SELECT bolesti.bolest_id, bolesti.naziv, simptomi_bolesti.vjerojatnost FROM bolesti, simptomi_bolesti WHERE (bolesti.bolest_id = simptomi_bolesti.bolest_id) AND (simptomi_bolesti.simptom_id = $sid) ORDER BY simptomi_bolesti.vjerojatnost, bolesti.naziv"; + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + $bolesti = array(); + $uobicajeno = $povremeno = $rijetko = false; + while ($row = $sth->fetchrow_array()) { + list($bid, $naziv, $vjer) = $row; + if ($vjer == 1) $uobicajeno = true; + if ($vjer == 2) $povremeno = true; + if ($vjer == 3) $rijetko = true; + array_push($bolesti, array( + "id" => "$bid-0", + "naziv" => escape_quote($naziv), + "vjerojatnost" => $vjer + )); + } + $sth->finish(); + $tpl->assign("bolesti", $bolesti); + $tpl->assign("uobicajeno", $uobicajeno); + $tpl->assign("povremeno", $povremeno); + $tpl->assign("rijetko", $rijetko); + $simptomi = array(); + for ($i = 0; $i < count($bolesti); $i++) { + if ($bolesti[$i]["vjerojatnost"] != 1) continue; + $sql = "SELECT simptomi.simptom_id, simptomi.naziv, sorter.value FROM simptomi, sorter WHERE (sorter.simptom_main_id = $sid) AND (sorter.simptom_id = simptomi.simptom_id) AND (sorter.bolest_id = ".$bolesti[$i]["id"].")"; + $sth2 = $dbh->prepare($sql); + if (!$sth2) error("Cannot prepare query: \"$sql\""); + if (!$sth2->execute()) error("Cannot execute query: \"$sql\""); + while ($row = $sth2->fetchrow_array()) { + list($id, $simpt, $val) = $row; + $simpt = escape_quote($simpt); + for ($j = 0; $j < count($simptomi); $j++) if ($simptomi[$j]["name"] == $simpt) break; + if (!$simptomi[$j]) { + $tmp = array(); + for ($k = 0; $k < count($bolesti); $k++) array_push($tmp, array("exists" => false)); + array_push($simptomi, array("id" => "$id-0", "name" => $simpt, "values" => $tmp)); + } + $simptomi[$j]["values"][$i]["exists"] = true; + $simptomi[$j]["values"][$i]["val"] = $val; + } + $sth2->finish(); + } + $tpl->assign("simptomi", $simptomi); + } + $dbh->disconnect(); + $tpl->assign("ID", $id); ?>