]> Softwares of Agnibho - simpleipd.git/commitdiff
Added discharge certificate
authorAgnibho Mondal <mondal@agnibho.com>
Mon, 17 May 2021 01:34:30 +0000 (07:04 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Mon, 17 May 2021 01:34:30 +0000 (07:04 +0530)
' [deleted file]
autocomplete/discharge.json [new file with mode: 0644]
discharge.php
discharge.tex [new file with mode: 0644]
lib/db.php
print-discharge.php [new file with mode: 0644]
res/script.js
view.php

diff --git a/' b/'
deleted file mode 100644 (file)
index 380aab9..0000000
--- a/'
+++ /dev/null
@@ -1,276 +0,0 @@
-<?php
-class DB extends SQLite3 {
-  function __construct(){
-    $this->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 (file)
index 0000000..b3d6b44
--- /dev/null
@@ -0,0 +1,3 @@
+{
+    "note":"To attend Tropical Medicine OPD after two weeks"
+}
index 1b0a5ccf2e34e678799a531e200b320476b8a61d..a7d6e9b427fcb4fe783fd763522b01412bbc5f10 100644 (file)
@@ -40,6 +40,10 @@ if(!empty($_GET["pid"])){
         </div>
       </div>
       <?php echo $form;?>
+      <form method="post" action="print-discharge.php?pid=<?php echo $pid;?>" class="mt-4">
+        <textarea class="form-control mb-2" id="discharge-note" name="discharge-note"></textarea>
+        <button type="submit" class="btn btn-danger">Discharge Patient</button>
+      </form>
     </div>
     <?php include("lib/foot.php");?>
   </body>
diff --git a/discharge.tex b/discharge.tex
new file mode 100644 (file)
index 0000000..89ddf62
--- /dev/null
@@ -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}
index a37bf669769cbeaad17ad5ee6a42f2a86017f696..50d1c084274c809055aa1b9ee2545275b8c23912 100644 (file)
@@ -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 (file)
index 0000000..e3e041c
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+require("lib/db.php");
+require("lib/functions.php");
+session_start();
+if(empty($_SESSION["user"])){
+  header("Location: login.php");
+  exit();
+}
+function json2tex($data){
+    $data=json_decode($data);
+    if(!empty($data->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."*");
+  }
+}
+?>
index f7cfddfa6da3566b5f38e86f7460959f86c99bc4..cc3a314edc84d0611acc1eabed8ef9860f99019f 100644 (file)
@@ -45,4 +45,9 @@ $(document).ready(function(){
       });
     });
   };
+  if($("#discharge-note").length){
+    $.get("autocomplete/discharge.json", function(data){
+      $("#discharge-note").val(data.note);
+    });
+  }
 });
index 050f92a31e1c406b99cd63729880dec7e4ffbc5f..be6888983853f82d95b8ff484699e3c2d8074e56 100644 (file)
--- 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()){