From: Agnibho Mondal Date: Mon, 17 May 2021 01:34:30 +0000 (+0530) Subject: Added discharge certificate X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=4711929f62ac249828427f2f9d235d28d12c119a;p=simpleipd.git Added discharge certificate --- diff --git a/' b/' deleted file mode 100644 index 380aab9..0000000 --- a/' +++ /dev/null @@ -1,276 +0,0 @@ -open("data/data.db"); - } - function checkUser($username, $password){ - $stmt=$this->prepare("SELECT hash FROM users WHERE user=:user"); - $stmt->bindValue(":user", $username); - $result=$stmt->execute(); - $hash=$result->fetchArray(); - if($hash){ - return(password_verify($password, $hash["hash"])); - } - else{ - return(false); - } - } - function admit($post){ - $quer=$this->prepare("SELECT count(rowid) FROM patients WHERE pid=:pid"); - $quer->bindValue(":pid", $post["pid"]); - $exist=$quer->execute(); - if($exist->fetchArray()[0]==0){ - $stmt=$this->prepare("INSERT INTO patients (pid,name,age,sex,status,summary,ward,bed,diagnosis,data) VALUES (:pid,:name,:age,:sex,'admitted',:summary,:ward,:bed,:diagnosis,:data);"); - } - else{ - $stmt=$this->prepare("UPDATE patients SET name=:name,age=:age,sex=:sex,ward=:ward,bed=:bed,diagnosis=:diagnosis,summary=:summary,data=:data WHERE pid=:pid;"); - } - $stmt->bindValue(":pid", $post["pid"]); - $stmt->bindValue(":name", $post["name"]); - $stmt->bindValue(":age", $post["age"]); - $stmt->bindValue(":sex", $post["sex"]); - $stmt->bindValue(":status", "admitted"); - $stmt->bindValue(":ward", $post["ward"]); - $stmt->bindValue(":bed", $post["bed"]); - $stmt->bindValue(":diagnosis", $post["diagnosis"]); - $stmt->bindValue(":summary", $post["summary"]); - $stmt->bindValue(":data", json_encode($post)); - $stmt->execute(); - } - function updateHistory($post, $pid){ - $stmt=$this->prepare("UPDATE patients SET history=:history WHERE pid=:pid;"); - $stmt->bindValue(":history", json_encode($post)); - $stmt->bindValue(":pid", $pid); - $stmt->execute(); - } - function addPhysician($post, $pid){ - $stmt=$this->prepare("INSERT INTO physician (pid, time, data) VALUES (:pid, :time, :data);"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":time", strtotime($post["date"].$post["time"])); - $stmt->bindValue(":data", json_encode($post)); - $stmt->execute(); - } - function editPhysician($post, $pid, $id){ - $stmt=$this->prepare("UPDATE physician SET time=:time,data=:data WHERE pid=:pid AND rowid=:id;"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":id", $id); - $stmt->bindValue(":time", strtotime($post["date"].$post["time"])); - $stmt->bindValue(":data", json_encode($post)); - $stmt->execute(); - } - function addNursing($post, $pid){ - $stmt=$this->prepare("INSERT INTO nursing (pid, time, data) VALUES (:pid, :time, :data);"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":time", strtotime($post["date"].$post["time"])); - $stmt->bindValue(":data", json_encode($post)); - $stmt->execute(); - } - function editNursing($post, $pid, $id){ - $stmt=$this->prepare("UPDATE nursing SET time=:time,data=:data WHERE pid=:pid AND rowid=:id;"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":id", $id); - $stmt->bindValue(":time", strtotime($post["date"].$post["time"])); - $stmt->bindValue(":data", json_encode($post)); - $stmt->execute(); - } - function addReport($post, $pid, $form){ - $stmt=$this->prepare("INSERT INTO reports (pid, time, form, data) VALUES (:pid, :time, :form, :data);"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":time", strtotime($post["date"].$post["time"])); - $stmt->bindValue(":form", $post["form"]); - $stmt->bindValue(":data", json_encode($post)); - $stmt->execute(); - } - function editReport($post, $pid, $id, $form){ - $stmt=$this->prepare("UPDATE reports SET time=:time,data=:data WHERE pid=:pid AND rowid=:id;"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":id", $id); - $stmt->bindValue(":time", strtotime($post["date"].$post["time"])); - $stmt->bindValue(":data", json_encode($post)); - $stmt->execute(); - } - function addDrug($pid, $drug, $dose, $route, $frequency, $date, $time, $duration, $addl){ - $stmt=$this->prepare("INSERT INTO treatment (pid, drug, dose, route, frequency, start, duration, omit, addl) VALUES (:pid, :drug, :dose, :route, :frequency, :start, :duration, :omit, :addl);"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":drug", $drug); - $stmt->bindValue(":dose", $dose); - $stmt->bindValue(":route", $route); - $stmt->bindValue(":frequency", $frequency); - $stmt->bindValue(":start", strtotime($date." ".$time)); - $stmt->bindValue(":duration", $duration); - $stmt->bindValue(":addl", $addl); - $stmt->bindValue(":omit", false); - $stmt->execute(); - } - function omitDrug($id){ - $stmt=$this->prepare("UPDATE treatment SET end=:end,omit=:omit WHERE rowid=:id;"); - $stmt->bindValue(":end", time()); - $stmt->bindValue(":omit", true); - $stmt->bindValue(":id", $id); - $stmt->execute(); - } - function addRequisition($pid, $test, $date, $time, $room){ - $stmt=$this->prepare("INSERT INTO requisition (pid, test, time, room, sample, status) VALUES (:pid, :test, :time, :room, :sample, :status);"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":test", $test); - $stmt->bindValue(":time", strtotime($date." ".$time)); - $stmt->bindValue(":room", $room); - $stmt->bindValue(":status", "sent"); - $stmt->execute(); - } - function omitRequisition($id){ - $stmt=$this->prepare("UPDATE requisition SET status=:status WHERE rowid=:id;"); - $stmt->bindValue(":status", "done"); - $stmt->bindValue(":id", $id); - $stmt->execute(); - } - function addAdvice($pid, $name, $dose, $route, $frequency, $duration, $addl){ - $stmt=$this->prepare("INSERT INTO discharge (pid, name, dose, route, frequency, duration, addl) VALUES (:pid, :name, :dose, :route, :frequency, :duration, :addl);"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":name", $name); - $stmt->bindValue(":dose", $dose); - $stmt->bindValue(":route", $route); - $stmt->bindValue(":frequency", $frequency); - $stmt->bindValue(":duration", $duration); - $stmt->bindValue(":addl", $addl); - $stmt->execute(); - } - function deleteAdvice($id){ - $stmt=$this->prepare("DELETE FROM discharge WHERE rowid=:id;"); - $stmt->bindValue(":id", $id); - $stmt->execute(); - } - function setDischarged($pid){ - $stmt=$this->prepare("UPDATE patients SET status=:discharged WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $stmt->execute(); - } - function setDead($pid, $post){ - $stmt=$this->prepare("INSERT INTO death (pid, time, data) VALUES (:pid, :time, :data);"); - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":time", strtotime($post["date"].$post["time"])); - $stmt->bindValue(":data", json_encode($post)); - $stmt->execute(); - $stmt=$this->prepare("UPDATE patients SET status='expired' WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $stmt->execute(); - } - function getDrugs($pid){ - $stmt=$this->prepare("SELECT rowid,* FROM treatment WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getRequisitions($pid){ - $stmt=$this->prepare("SELECT rowid,* FROM requisition WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getAdvice($pid){ - $stmt=$this->prepare("SELECT rowid,* FROM discharge WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getName($pid){ - $stmt=$this->prepare("SELECT name FROM patients WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getAge($pid){ - $stmt=$this->prepare("SELECT age FROM patients WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getSex($pid){ - $stmt=$this->prepare("SELECT sex FROM patients WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getWard($pid){ - $stmt=$this->prepare("SELECT ward FROM patients WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getBed($pid){ - $stmt=$this->prepare("SELECT bed FROM patients WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getStatus($pid){ - $stmt=$this->prepare("SELECT status FROM patients WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getDiagnosis($pid){ - $stmt=$this->prepare("SELECT diagnosis FROM patients WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getList(){ - $stmt=$this->prepare("SELECT pid FROM patients;"); - $result=$stmt->execute(); - return($result); - } - function getForm($id){ - $stmt=$this->prepare("SELECT form FROM reports WHERE rowid=:id;"); - $stmt->bindValue(":id", $id); - $result=$stmt->execute(); - return($result); - } - function getAdmission($pid){ - $stmt=$this->prepare("SELECT data FROM patients WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getHistory($pid){ - $stmt=$this->prepare("SELECT history FROM patients WHERE pid=:pid;"); - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } - function getData($pid, $id, $cat){ - if($cat=="physician"){ - $stmt=$this->prepare("SELECT data FROM physician WHERE pid=:pid AND rowid=:id;"); - } elseif($cat=="nursing"){ - $stmt=$this->prepare("SELECT data FROM nursing WHERE pid=:pid AND rowid=:id;"); - } elseif($cat=="reports"){ - $stmt=$this->prepare("SELECT data FROM reports WHERE pid=:pid AND rowid=:id;"); - } else{ - return(false); - } - $stmt->bindValue(":pid", $pid); - $stmt->bindValue(":id", $id); - $result=$stmt->execute(); - return($result); - } - function getAllData($pid, $cat){ - if($cat=="physician"){ - $stmt=$this->prepare("SELECT rowid,data FROM physician WHERE pid=:pid;"); - } elseif($cat=="nursing"){ - $stmt=$this->prepare("SELECT rowid,data FROM nursing WHERE pid=:pid;"); - } elseif($cat=="reports"){ - $stmt=$this->prepare("SELECT rowid,data FROM reports WHERE pid=:pid;"); - } elseif($cat=="info"){ - $stmt=$this->prepare("SELECT rowid,data FROM patients WHERE pid=:pid;"); - } elseif($cat=="history"){ - $stmt=$this->prepare("SELECT rowid,history FROM patients WHERE pid=:pid;"); - } else{ - return(false); - } - $stmt->bindValue(":pid", $pid); - $result=$stmt->execute(); - return($result); - } -} -$db = new DB(); -?> diff --git a/autocomplete/discharge.json b/autocomplete/discharge.json new file mode 100644 index 0000000..b3d6b44 --- /dev/null +++ b/autocomplete/discharge.json @@ -0,0 +1,3 @@ +{ + "note":"To attend Tropical Medicine OPD after two weeks" +} diff --git a/discharge.php b/discharge.php index 1b0a5cc..a7d6e9b 100644 --- a/discharge.php +++ b/discharge.php @@ -40,6 +40,10 @@ if(!empty($_GET["pid"])){ +
+ + +
diff --git a/discharge.tex b/discharge.tex new file mode 100644 index 0000000..89ddf62 --- /dev/null +++ b/discharge.tex @@ -0,0 +1,53 @@ +\documentclass{article} +\usepackage[a4paper]{geometry} +\usepackage{tabularx} +\usepackage{fancyhdr} + +\begin{document} +\pagenumbering{gobble} +\begin{center} +School of Tropical Medicine \\ +{\small 108, Chittaranjan Avenue, Kolkata-700073} +\rule{\textwidth}{0.4pt} +Discharge Certificate\\ +\rule{\textwidth}{0.4pt} +\end{center} +\flushright +%[vp]% \\ +\vspace{3em} +\begin{tabular}{r r} +Date of admission & %[doa]% \\ +Date of discharge & %[dod]% \\ +\end{tabular} +\flushleft +\vspace{-5em} +\begin{tabularx}{\textwidth}{l X} + Name & %[name]%\\ + Age & %[age]% \\ + Sex & %[sex]% \\ + Admission ID & %[pid]% \\ + Diagnosis & %[diagnosis]%\\ +\end{tabularx} +\rule{\textwidth}{0.4pt} +\paragraph{Summary} +%[summary]% +\rule{\textwidth}{0.4pt} +\paragraph{Advice on Discharge} +%[advice]% +\paragraph{} +%[advice]% +\vspace{2em} +%[note]% +\vfill +\flushright +\rule{10em}{0.4pt}\\ +Signature of Physician + +\newpage +\fancyhead[R]{%[name]%} +\fancyhead[C]{%[pid]%} +\fancyhead[L]{Investigations} +\setlength{\topmargin}{-5em} +\pagestyle{fancy} +%[reports]% +\end{document} diff --git a/lib/db.php b/lib/db.php index a37bf66..50d1c08 100644 --- a/lib/db.php +++ b/lib/db.php @@ -144,6 +144,7 @@ class DB extends SQLite3 { function setDischarged($pid){ $stmt=$this->prepare("UPDATE patients SET status=:discharged WHERE pid=:pid;"); $stmt->bindValue(":pid", $pid); + $stmt->bindValue(":discharged", "discharged"); $stmt->execute(); } function setDead($pid, $post){ @@ -235,11 +236,29 @@ class DB extends SQLite3 { return($result); } function getAdmission($pid){ + $stmt=$this->prepare("SELECT admission FROM patients WHERE pid=:pid;"); + $stmt->bindValue(":pid", $pid); + $result=$stmt->execute(); + return($result); + } + function getAdmissionData($pid){ $stmt=$this->prepare("SELECT data FROM patients WHERE pid=:pid;"); $stmt->bindValue(":pid", $pid); $result=$stmt->execute(); return($result); } + function getDeparture($pid){ + $stmt=$this->prepare("SELECT departure FROM patients WHERE pid=:pid;"); + $stmt->bindValue(":pid", $pid); + $result=$stmt->execute(); + return($result); + } + function getSummary($pid){ + $stmt=$this->prepare("SELECT summary FROM patients WHERE pid=:pid;"); + $stmt->bindValue(":pid", $pid); + $result=$stmt->execute(); + return($result); + } function getHistory($pid){ $stmt=$this->prepare("SELECT history FROM patients WHERE pid=:pid;"); $stmt->bindValue(":pid", $pid); diff --git a/print-discharge.php b/print-discharge.php new file mode 100644 index 0000000..e3e041c --- /dev/null +++ b/print-discharge.php @@ -0,0 +1,73 @@ +form)){ + $schema=json_decode(file_get_contents("forms/".$data->form.".schema.json")); + } + unset($data->cat); + $view="\begin{tabularx}{\\textwidth}{l X}\n"; + foreach($data as $field=>$value){ + if($field!="form" && !empty($value)){ + if(!empty($schema->properties->$field)){ + $view=$view.$schema->properties->$field->description." & ".$value."\\\\\n"; + } + else{ + $view=$view.$field." & ".$value."\n"; + } + } + } + $view=$view."\\end{tabularx}\n"; + return $view; +} +if(!empty($_GET["pid"])){ + $pid=$_GET["pid"]; + $template=file_get_contents("discharge.tex"); + if(!empty($_POST["discharge-note"])){ + $template=str_replace("%[note]%", $_POST["discharge-note"], $template); + } + $template=str_replace("%[name]%", $db->getName($pid)->fetcharray()["name"], $template); + $template=str_replace("%[age]%", $db->getAge($pid)->fetcharray()["age"], $template); + $template=str_replace("%[sex]%", $db->getSex($pid)->fetcharray()["sex"], $template); + $template=str_replace("%[pid]%", $pid, $template); + $template=str_replace("%[diagnosis]%", $db->getDiagnosis($pid)->fetcharray()["diagnosis"], $template); + $template=str_replace("%[doa]%", $db->getAdmission($pid)->fetcharray()["admission"], $template); + $template=str_replace("%[dod]%", $db->getDeparture($pid)->fetcharray()["departure"], $template); + $template=str_replace("%[summary]%", $db->getSummary($pid)->fetcharray()["summary"], $template); + $list=$db->getAdvice($pid); + $view=""; + while($drug=$list->fetchArray()){ + $view=$view."\item ".$drug["drug"]." ".$drug["dose"]." ".$drug["route"]." ".$drug["frequency"]." ".$drug["duration"]." ".$drug["addl"]."\n"; + } + if($view){ + $template=str_replace("%[advice]%", "\begin{enumerate}\n".$view."\\end{enumerate}", $template); + } + $reports=[]; + $reportsArray=$db->getAllData($pid, "reports"); + while($r=$reportsArray->fetchArray()){ + $template=str_replace("%[reports]%", json2tex($r["data"]), $template); + } + //echo $template; + $f=str_replace("/", "", $pid)."-".time()."-".rand(); + file_put_contents("data/discharge/".$f.".tex", $template); + exec("pdflatex --output-directory data/discharge/ data/discharge/".$f.".tex", $out, $ret); + //var_dump($out); + //var_dump($ret); + if($ret!=0){ + header("Content-Type: text/plain"); + echo "Failed to generate discharge certificate. Please check whether patient information, summary, reports, discharge advices are properly filled up."; + } + else{ + $db->setDischarged($pid); + header("Content-Type: application/pdf"); + readFile("data/discharge/".$f.".pdf"); + exec(" rm data/discharge/".$f."*"); + } +} +?> diff --git a/res/script.js b/res/script.js index f7cfddf..cc3a314 100644 --- a/res/script.js +++ b/res/script.js @@ -45,4 +45,9 @@ $(document).ready(function(){ }); }); }; + if($("#discharge-note").length){ + $.get("autocomplete/discharge.json", function(data){ + $("#discharge-note").val(data.note); + }); + } }); diff --git a/view.php b/view.php index 050f92a..be68889 100644 --- a/view.php +++ b/view.php @@ -13,7 +13,7 @@ $reports=[]; if(isSet($_GET["pid"])){ $pid=$_GET["pid"]; $status=$db->getStatus($pid)->fetchArray()["status"]; - $info=viewData($db->getAdmission($pid)->fetchArray()["data"]); + $info=viewData($db->getAdmissionData($pid)->fetchArray()["data"]); $history=viewData($db->getHistory($pid)->fetchArray()["history"]); $physicianArray=$db->getAllData($pid, "physician"); while($c=$physicianArray->fetchArray()){