]> Softwares of Agnibho - simpleipd.git/commitdiff
Rewritten with SQLite3
authorAgnibho Mondal <mondal@agnibho.com>
Fri, 14 May 2021 06:51:41 +0000 (12:21 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Fri, 14 May 2021 06:51:41 +0000 (12:21 +0530)
16 files changed:
admission.php
clinical.php
forms/admission.schema.json
forms/history.schema.json [new file with mode: 0644]
forms/report-ch.schema.json
forms/report-lft.schema.json
forms/report-rft.schema.json
history.php [new file with mode: 0644]
index.php
laboratory.php
lib/db.php [new file with mode: 0644]
lib/functions.php
report.php
schema.sql [new file with mode: 0644]
treatment.php
view.php

index 33f69fcd4fbd542559292f2a932e23eadc73281b..1dba68437135d17089c682863615db3e077c6676 100644 (file)
@@ -1,20 +1,12 @@
 <?php
 require("lib/functions.php");
-if(isSet($_POST["id"])){
-  $data=json_encode($_POST);
-  if(!is_dir("data/".$_POST["id"])){
-    mkdir("data/".$_POST["id"]);
-  }
-  file_put_contents("data/".$_POST["id"]."/info.json", $data);
-  header("Location: view.php?id=".$_POST["id"]);
-  exit();
-}
-if(isSet($_GET["id"])){
-  $form=schema2form("forms/admission.schema.json", "data/".$_GET["id"]."/info.json");
-}
-else{
-  $form=schema2form("forms/admission.schema.json");
+require("lib/db.php");
+if(!empty($_POST["pid"]) && !empty($_POST["name"]) && !empty($_POST["age"]) && !empty($_POST["sex"])){
+  $db->admit($_POST);
+  //header("Location: view.php?pid=".$_POST["pid"]);
+  //exit();
 }
+$form=schema2form("forms/admission.schema.json");
 ?>
 <!DOCTYPE html>
 <html>
index 58806b41118105e0e0d05249f4961dc14455c431..8538e125673f33a1a25d2db34a626cead2e87541 100644 (file)
@@ -1,19 +1,24 @@
 <?php
+require("lib/db.php");
 require("lib/functions.php");
-if(isSet($_GET["id"]) && isSet($_POST["date"]) && isSet($_POST["time"])){
-  $data=json_encode($_POST);
-  if(!is_dir("data/".$_GET["id"]."/clinical")){
-    mkdir("data/".$_GET["id"]."/clinical");
+if(!empty($_GET["pid"])){
+  $pid=$_GET["pid"];
+  if(!empty($_POST["date"]) && !empty($_POST["time"])){
+    if(!empty($_GET["id"])){
+      $db->editClinical($_POST, $pid, $_GET["id"]);
+    }
+    else{
+      $db->addClinical($_POST, $pid);
+    }
+    //header("Location: view.php?id=".$_GET["id"]);
+    //exit();
+  }
+  if(isSet($_GET["id"])){
+    $form=schema2form("forms/clinical.schema.json", $pid, $_GET["id"], "clinical");
+  }
+  else{
+    $form=schema2form("forms/clinical.schema.json");
   }
-  file_put_contents("data/".$_GET["id"]."/clinical/".$_POST["stamp"].".json", $data);
-  header("Location: view.php?id=".$_GET["id"]);
-  exit();
-}
-if(isSet($_GET["stamp"])){
-    $form=schema2form("forms/clinical.schema.json", $_GET["stamp"], "data/".$_GET["id"]."/clinical/".$_GET["stamp"].".json");
-}
-else{
-  $form=schema2form("forms/clinical.schema.json");
 }
 ?>
 <!DOCTYPE html>
@@ -24,6 +29,7 @@ else{
   </head>
   <body>
     <div class="container">
+      <?php echo getInfo($pid);?>
       <?php echo $form;?>
     </div>
   </body>
index 698dd08da2506745e2f9491eccf0f9292a03e28f..44fa8c659baf301dbe0877a152c04e6f3663b86d 100644 (file)
@@ -5,7 +5,7 @@
     "type": "object",
 
     "properties": {
-        "id": {
+        "pid": {
             "description": "Admission ID",
             "type": "string"
         },
@@ -28,7 +28,7 @@
             "format": "date"
         },
         "ward": {
-            "description": "Ward Number",
+            "description": "Ward",
             "type": "string"
         },
         "bed": {
@@ -41,5 +41,5 @@
             "enum": ["admitted","discharged","expired"]
         }
     },
-    "required": ["id"]
+    "required": ["pid", "name", "age", "sex", "date", "ward", "bed", "status"]
 }
diff --git a/forms/history.schema.json b/forms/history.schema.json
new file mode 100644 (file)
index 0000000..0647afa
--- /dev/null
@@ -0,0 +1,60 @@
+{
+    "$schema": "http://json-schema.org/draft/2020-12/schema",
+    "title": "History",
+    "description": "History",
+    "type": "object",
+
+    "properties": {
+        "date": {
+            "description": "Date",
+            "type": "string",
+            "format": "date"
+        },
+        "time": {
+            "description": "Time",
+            "type": "string",
+            "format": "time"
+        },
+        "cc": {
+            "description": "Chief complaint",
+            "type": "string"
+        },
+        "history": {
+            "description": "History",
+            "type": "string"
+        },
+        "comorb": {
+            "description": "Comorbidities",
+            "type": "string"
+        },
+        "oe": {
+            "description": "General Examination",
+            "type": "string"
+        },
+        "bp": {
+            "description": "Blood Pressure",
+            "type": "string"
+        },
+        "pr": {
+            "description": "Pulse",
+            "type": "integer"
+        },
+        "rr": {
+            "description": "Respiratory Rate",
+            "type": "integer"
+        },
+        "spo2": {
+            "description": "SpO2",
+            "type": "integer"
+        },
+        "chest": {
+            "description": "Chest Examination",
+            "type": "string"
+        },
+        "abdomen": {
+            "description": "Abdominal Examination",
+            "type": "string"
+        }
+    },
+    "required": ["date","time", "cc"]
+}
index f4971601ea654c71207d6b93e45edaf9ad3c0cf1..3c33b7143483e2d8ffda0cf917775032163c600d 100644 (file)
@@ -65,5 +65,5 @@
             "type": "number"
         }
     },
-    "required": []
+    "required": ["date"]
 }
index b2316465064e956a5b720836c82d42ac69517526..2f89980c7b45b7e1e3236e8753aa30fe60e2b15b 100644 (file)
@@ -45,5 +45,5 @@
             "type": "number"
         }
     },
-    "required": []
+    "required": ["date"]
 }
index 5f26bf2748e72e41d14cdffb62151fbf92ecc06d..65df1d767a731206e966d45311b621c6852608e9 100644 (file)
@@ -33,5 +33,5 @@
             "type": "number"
         }
     },
-    "required": []
+    "required": ["date"]
 }
diff --git a/history.php b/history.php
new file mode 100644 (file)
index 0000000..d055b44
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+require("lib/db.php");
+require("lib/functions.php");
+if(!empty($_GET["pid"])){
+  $pid=$_GET["pid"];
+  if(!empty($_POST["cc"])){
+    $db->history($_POST, $pid);
+    //header("Location: view.php?pid=".$pid);
+    //exit();
+  }
+}
+if(isSet($_GET["stamp"])){
+    $form=schema2form("forms/clinical.schema.json", $_GET["stamp"], "data/".$_GET["id"]."/clinical/".$_GET["stamp"].".json");
+}
+else{
+  $form=schema2form("forms/history.schema.json");
+}
+?>
+<!DOCTYPE html>
+<html>
+  <head>
+    <?php include("lib/head.php");?>
+    <title>History</title>
+  </head>
+  <body>
+    <div class="container">
+      <?php echo getInfo($pid);?>
+      <?php echo $form;?>
+    </div>
+  </body>
+</html>
index 427aa63924cc108c4a3c7c1ba6aaab3118390805..1af46e77855544e0069fc655f2438e43e2035167 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,10 +1,14 @@
 <?php
+require("lib/db.php");
 require("lib/functions.php");
-$list="";
-foreach(glob("data/*") as $id){
-  $data=json_decode(file_get_contents($id."/info.json"));
-  $id=str_replace("data/", "", $id);
-  $list=$list."<tr><td><a href='view.php?id=".$id."'>".$id."</a></td><td>".$data->name."</td><td>".$data->ward." ".$data->bed."</td></tr>";
+$list=$db->getList();
+$show="";
+if(!empty($list)){
+  while($arr=$list->fetchArray()){
+    $pid=$arr["pid"];
+    $name=$db->getName($pid)->fetchArray()["name"];
+    $show=$show."<tr><td><a href='view.php?pid=".$pid."'>".$pid."</a></td><td>".$name."</td><td> </td></tr>";
+  }
 }
 ?>
 <!DOCTYPE html>
@@ -21,7 +25,7 @@ foreach(glob("data/*") as $id){
           <h4 class="card-title">Patient List</h4>
           <table class="table">
             <tr><th>Patient ID</th><th>Name</th><th>Bed Number</th></tr>
-            <?php echo $list;?>
+            <?php echo $show;?>
           </table>
           <a class="btn btn-primary btn-lg" href="admission.php">Add New Patient</a>
         </div>
index 43c23ed36c37c67eaa7db592f43ffeb31b9cf5c2..add88619b33aa76d9a85a39b3560d6f9f85c2442 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 require("lib/functions.php");
 $list="";
-if(isSet($_GET["id"])){
+if(isSet($_GET["pid"])){
   foreach(glob("forms/report*.json") as $file){
     $form=json_decode(file_get_contents($file));
-    $list=$list."<li class='list-group-item'><a href='report.php?id=".$_GET["id"]."&form=".str_replace(["forms/",".schema.json"], "", $file)."'>".$form->description."</a></li>";
+    $list=$list."<li class='list-group-item'><a href='report.php?pid=".$_GET["pid"]."&form=".str_replace(["forms/",".schema.json"], "", $file)."'>".$form->description."</a></li>";
   }
 }
 ?>
diff --git a/lib/db.php b/lib/db.php
new file mode 100644 (file)
index 0000000..515642a
--- /dev/null
@@ -0,0 +1,133 @@
+<?php
+class DB extends SQLite3 {
+  function __construct(){
+    $this->open("data/data.db");
+  }
+  function admit($post){
+    $stmt=$this->prepare("INSERT INTO patients (pid, name, age, sex, addl) VALUES (:pid, :name, :age, :sex, :addl);");
+    $stmt->bindValue(":pid", $post["pid"]);
+    $stmt->bindValue(":name", $post["name"]);
+    $stmt->bindValue(":age", $post["age"]);
+    $stmt->bindValue(":sex", $post["sex"]);
+    $stmt->bindValue(":addl", json_encode($post));
+    $stmt->execute();
+  }
+  function updateHistory($post, $pid){
+    $stmt=$this->prepare("UPDATE patients SET data=:history WHERE pid=:pid;");
+    $stmt->bindValue(":history", json_encode($post));
+    $stmt->bindValue(":pid", $pid);
+    $stmt->execute();
+  }
+  function addClinical($post, $pid){
+    $stmt=$this->prepare("INSERT INTO clinical (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 editClinical($post, $pid, $id){
+    $stmt=$this->prepare("UPDATE clinical 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, $name, $dose, $route, $frequency, $start, $duration, $addl){
+    $stmt=$this->prepare("INSERT INTO drugs (pid, name, dose, route, frequency, start, duration, omit, addl) VALUES (:pid, :name, :dose, :route, :frequency, :start, :duration, :omit, :addl);");
+    $stmt->bindValue(":pid", $pid);
+    $stmt->bindValue(":name", $name);
+    $stmt->bindValue(":dose", $dose);
+    $stmt->bindValue(":route", $route);
+    $stmt->bindValue(":frequency", $frequency);
+    $stmt->bindValue(":start", $start);
+    $stmt->bindValue(":duration", $duration);
+    $stmt->bindValue(":addl", $addl);
+    $stmt->bindValue(":omit", false);
+    $stmt->execute();
+  }
+  function omitDrug($id){
+    $stmt=$this->prepare("UPDATE drugs SET omit=:omit WHERE rowid=:id;");
+    $stmt->bindValue(":omit", true);
+    $stmt->bindValue(":id", $id);
+    $stmt->execute();
+  }
+  function getDrugs($pid){
+    $stmt=$this->prepare("SELECT rowid,* FROM drugs 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 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 getData($pid, $id, $cat){
+    if($cat=="clinical"){
+      $stmt=$this->prepare("SELECT data FROM clinical WHERE pid=:pid AND rowid=:id;");
+    } elseif($cat=="reports"){
+      $stmt=$this->prepare("SELECT data FROM reports WHERE pid=:pid AND rowid=:id;");
+    } elseif($cat=="history"){
+      $stmt=$this->prepare("SELECT data FROM patients WHERE pid=:pid AND rowid=:id;");
+    }
+    $stmt->bindValue(":pid", $pid);
+    $stmt->bindValue(":id", $id);
+    $result=$stmt->execute();
+    return($result);
+  }
+  function getAllData($pid, $cat){
+    if($cat=="clinical"){
+      $stmt=$this->prepare("SELECT rowid,data FROM clinical WHERE pid=:pid;");
+    } elseif($cat=="reports"){
+      $stmt=$this->prepare("SELECT rowid,data FROM reports WHERE pid=:pid;");
+    } elseif($cat=="history"){
+      $stmt=$this->prepare("SELECT rowid,data FROM patients WHERE pid=:pid;");
+    }
+    $stmt->bindValue(":pid", $pid);
+    $result=$stmt->execute();
+    return($result);
+  }
+}
+$db = new DB();
+?>
index e48b6331bf49ebb1abd6f32298aa04f4ad04c2c7..562fb82b1af32d4b68d6c29694ff52f35444692b 100644 (file)
@@ -1,22 +1,22 @@
 <?php
-function schema2form($file, $stamp=false, $fill=false){
+function schema2form($file, $pid=null, $id=null, $cat=null){
+  global $db;
   $schema=json_decode(file_get_contents($file));
 
-  if($fill!==false){
-    $data=json_decode(file_get_contents($fill));
+  if(!empty($pid) && !empty($id) && !empty($cat)){
+    $data=json_decode($db->getData($pid, $id, $cat)->fetchArray()["data"]);
   }
-  if($stamp===false){
-    $stamp=time()."-".rand(1000,9999);
+  else{
+    $data=null;
   }
 
   $form="<form method='post'>";
-  $form=$form."<input type='hidden' name='stamp' value='".$stamp."'>";
-  $form=$form."<input type='hidden' name='form' value='".str_replace(["forms/", ".schema.json"], "", $file)."'>";
+  $form=$form."<input type='hidden' name='form' value='".str_replace(["forms/",".schema.json"], "", $file)."'>";
 
   foreach($schema->properties as $field=>$prop){
     if($prop->type == "integer") $prop->type="number";
     if($prop->type == "string") $prop->type="text";
-    if($fill!==false){
+    if(!empty($data)){
       $value="value='".$data->$field."'";
     }
     else{
@@ -56,48 +56,31 @@ function schema2form($file, $stamp=false, $fill=false){
   return $form;
 }
 
-function view_data($file, $edit=false){
-  if(is_file($file)){
-    $data=json_decode(file_get_contents($file));
-  }
-  else{
-    return "";
-  }
+function getInfo($pid){
+  global $db;
+  $info="<table class='table'>";
+  $info=$info."<tr><td>ID</td><td>".$pid."</td></tr>";
+  $info=$info."<tr><td>Name</td><td>".$db->getName($pid)->fetchArray()["name"]."</td></tr>";
+  $info=$info."<tr><td>Age</td><td>".$db->getAge($pid)->fetchArray()["age"]."</td></tr>";
+  $info=$info."<tr><td>Sex</td><td>".$db->getSex($pid)->fetchArray()["sex"]."</td></tr>";
+  $info=$info."</table>";
+  return $info;
+}
+
+function viewData($data, $edit=null){
+  $data=json_decode($data);
+  unset($data->cat);
   $view="<table class='table'>";
   foreach($data as $field=>$value){
     $view=$view."<tr><td>".$field."</td><td>".$value."</td></tr>";
   }
-  if($edit!==false){
-    $view=$view."<tr><td><a href='".$edit."&form=".$data->form."&stamp=".$data->stamp."'>Edit</a>";
+  if(!empty($edit)){
+    $view=$view."<tr><td><a href='".$edit."'>Edit</a>";
   }
   $view=$view."</table>";
   return $view;
 }
 
-function add_drug($file, $drug){
-  if(is_file($file)){
-    $druglist=json_decode(file_get_contents($file));
-  }
-  else{
-    $druglist=[];
-  }
-  $drug["omit"]=false;
-  array_push($druglist, $drug);
-  file_put_contents($file, json_encode($druglist));
-}
-
-function omit_drug($file, $id){
-  if(is_file($file)){
-    $druglist=json_decode(file_get_contents($file));
-    var_dump($druglist);
-    $druglist[$id]->omit=true;
-    file_put_contents($file, json_encode($druglist));
-  }
-  else{
-    echo "boo";
-  }
-}
-
 function view_drug($file){
   if(is_file($file)){
     $druglist=json_decode(file_get_contents($file));
index 146fa5fe0b9c34f0d4a201e3ab268294be278588..5a6fb4b12c4e6275a712c34105f15de594ece1a8 100644 (file)
@@ -1,25 +1,25 @@
 <?php
+require("lib/db.php");
 require("lib/functions.php");
-if(isSet($_GET["id"]) && isSet($_GET["form"])){
-  if(isSet($_GET["stamp"])){
-    $form=schema2form("forms/".$_GET["form"].".schema.json", $_GET["stamp"], "data/".$_GET["id"]."/report/".$_GET["stamp"].".json");
+if(!empty($_GET["pid"]) && !empty($_GET["form"])){
+  $pid=$_GET["pid"];
+  if(!empty($_POST["date"])){
+    if(!empty($_GET["id"])){
+      $db->editReport($_POST, $pid, $_GET["id"], $_POST["form"]);
+    }
+    else{
+      $db->addReport($_POST, $pid, $_POST["form"]);
+    }
+    //header("Location: view.php?id=".$_GET["id"]);
+    //exit();
+  }
+  if(isSet($_GET["id"])){
+    $form=schema2form("forms/".$_GET["form"].".schema.json", $pid, $_GET["id"], "reports");
   }
   else{
     $form=schema2form("forms/".$_GET["form"].".schema.json");
   }
 }
-else{
-  $form="";
-}
-if(isSet($_GET["id"]) && isSet($_POST["date"])){
-  $data=json_encode($_POST);
-  if(!is_dir("data/".$_GET["id"]."/report")){
-    mkdir("data/".$_GET["id"]."/report");
-  }
-  file_put_contents("data/".$_GET["id"]."/report/".$_POST["stamp"].".json", $data);
-  header("Location: view.php?id=".$_GET["id"]);
-  exit();
-}
 ?>
 <!DOCTYPE html>
 <html>
diff --git a/schema.sql b/schema.sql
new file mode 100644 (file)
index 0000000..11d20da
--- /dev/null
@@ -0,0 +1,31 @@
+CREATE TABLE clinical(
+pid int,
+time int,
+data text
+);
+CREATE TABLE drugs(
+pid int,
+name text,
+dose text,
+route text,
+frequency text,
+start int,
+duration text,
+omit boolean,
+addl text
+);
+CREATE TABLE patients(
+pid int unique,
+name text,
+age int,
+sex text,
+status text,
+addl text,
+data text
+);
+CREATE TABLE reports(
+pid int,
+time int,
+form text,
+data text
+);
index 51f5504595e44e9af62da0c1de5e2678e832fd29..f9347ca962a2e5e8aeddf0ffecb843a6308ea0d7 100644 (file)
@@ -1,16 +1,30 @@
 <?php
+require("lib/db.php");
 require("lib/functions.php");
-if(isSet($_GET["id"]) && isSet($_POST["omit"])){
-  if(filter_var($_POST["omit"], FILTER_VALIDATE_INT)!==false){
-    omit_drug("data/".$_GET["id"]."/treatment.json", $_POST["omit"]);
+if(!empty($_GET["pid"])){
+  $pid=$_GET["pid"];
+  if(!empty($_POST["omit"])){
+    $db->omitDrug($_POST["omit"]);
   }
-}
-if(isSet($_GET["id"]) && isSet($_POST["drug"])){
-  if($_POST["drug"]!==""){
-    add_drug("data/".$_GET["id"]."/treatment.json", $_POST);
+  elseif(!empty($_POST["name"])){
+    $db->addDrug($pid, $_POST["name"], $_POST["dose"], $_POST["route"], $_POST["frequency"], $_POST["start"], $_POST["duration"], $_POST["note"]);
+  }
+  $list=$db->getDrugs($pid);
+  $view="<form method='post' id='omitter'></form>";
+  $view=$view."<table class='table'>";
+  $view=$view."<tr><th>Drug</th><th>Dose</th><th>Route</th><th>Frequency</th><th>Start</th><th>Duration</th><th>Note</th></tr>";
+  while($drug=$list->fetchArray()){
+    if($drug["omit"]){
+      $omit="style='display:none'";
+    }
+    else{
+      $omit="";
+    }
+    $view=$view."<tr><td>".$drug["name"]."</td><td>".$drug["dose"]."</td><td>".$drug["route"]."</td><td>".$drug["frequency"]."</td><td>".$drug["start"]."</td><td>".$drug["duration"]."</td><td>".$drug["addl"]."</td><td><button class='btn btn-warning' name='omit' value='".$drug["rowid"]."' form='omitter' ".$omit.">Omit</button></td></tr>";
   }
+  $view=$view."</table>";
+
 }
-$list=view_drug("data/".$_GET["id"]."/treatment.json");
 ?>
 <!DOCTYPE html>
 <html>
@@ -20,23 +34,23 @@ $list=view_drug("data/".$_GET["id"]."/treatment.json");
   </head>
   <body>
     <div class="container">
-      <div class="card">
+      <div class="card mb-4">
         <div class="card-body">
           <h4 class="card-title">Medicine List</h4>
-          <?php echo $list;?>
+          <?php echo $view;?>
         </div>
       </div>
       <form method="post">
         <div>
-          <label class="form-label" for="drug">Add Drug</label>
+          <label class="form-label h4" for="drug">Add Drug</label>
           <div class="row">
-            <div class="col-sm-4">
-              <input class="form-control" type="text" name="drug" id="drug" placeholder="Drug">
+            <div class="col-sm-6 mb-3">
+              <input class="form-control" type="text" name="name" id="drug" placeholder="Drug" required>
             </div>
-            <div class="col-sm-2">
-              <input class="form-control" type="number" name="dose" id="dose" placeholder="Dose">
+            <div class="col-sm-2 mb-3">
+              <input class="form-control" type="text" name="dose" id="dose" placeholder="Dose">
             </div>
-            <div class="col-sm-2">
+            <div class="col-sm-2 mb-3">
               <select class="form-control" name="route" id="route">
                 <option value="oral">Oral</option>
                 <option value="im">IM</option>
@@ -49,14 +63,19 @@ $list=view_drug("data/".$_GET["id"]."/treatment.json");
                 <option value="pr">Per Rectal</option>
               </select>
             </div>
-            <div class="col-sm-2">
-              <input class="form-control" type="text" name="freq" id="freq" placeholder="Frequency">
+            <div class="col-sm-2 mb-3">
+              <input class="form-control" type="text" name="frequency" id="frequency" placeholder="Frequency">
             </div>
-            <div class="col-sm-2">
+            <div class="col-sm-2 mb-3">
+              <input class="form-control" type="text" name="start" id="start" placeholder="Start">
+            </div>
+            <div class="col-sm-2 mb-3">
               <input class="form-control" type="text" name="duration" id="duration" placeholder="Duration">
             </div>
+            <div class="col-sm-8 mb-3">
+              <input class="form-control" type="text" name="note" id="note" placeholder="Notes">
+            </div>
           </div>
-          <input class="form-control" type="text" name="note" id="note" placeholder="Notes">
           <button class="btn btn-primary" type="submit">Update</button>
         </div>
       </form>
index a68fe283e3b644e6cc8c11b241e516b19fead057..c7a1fcb95d9fa0919c6112881554a8dc69327e97 100644 (file)
--- a/view.php
+++ b/view.php
@@ -1,19 +1,21 @@
 <?php
+require("lib/db.php");
 require("lib/functions.php");
-if(isSet($_GET["id"])){
-  $id=$_GET["id"];
-}
-else{
-  $id=false;
-}
-$info=view_data("data/".$id."/info.json");
+$info="";
 $clinical=[];
-foreach(glob("data/".$id."/clinical/*.json") as $f){
-  array_push($clinical, view_data($f, "clinical.php?id=".$_GET["id"]));
-}
-$report=[];
-foreach(glob("data/".$id."/report/*.json") as $f){
-  array_push($report, view_data($f, "report.php?id=".$_GET["id"]));
+$reports=[];
+if(isSet($_GET["pid"])){
+  $pid=$_GET["pid"];
+  $info=getInfo($pid);
+  $clinicalArray=$db->getAllData($pid, "clinical");
+  while($c=$clinicalArray->fetchArray()){
+    array_push($clinical, viewData($c["data"], "clinical.php?pid=".$pid."&id=".$c["rowid"]));
+  }
+  $reportsArray=$db->getAllData($pid, "reports");
+  while($r=$reportsArray->fetchArray()){
+    var_dump($r);
+    array_push($reports, viewData($r["data"], "report.php?pid=".$pid."&id=".$r["rowid"]."&form=".$db->getForm($r["rowid"])->fetchArray()["form"]));
+  }
 }
 ?>
 <!DOCTYPE html>
@@ -25,39 +27,41 @@ foreach(glob("data/".$id."/report/*.json") as $f){
   <body>
     <div class="container">
       <h1>Patient Data</h1>
-      <ul class="nav nav-tabs">
-        <li class="nav-item">
-          <a class="nav-link active" aria-current="page" href="#info">Info</a>
-        </li>
-        <li class="nav-item">
-          <a class="nav-link" href="#clinical">Clinical Notes</a>
-        </li>
-        <li class="nav-item">
-          <a class="nav-link" href="#report">Lab Reports</a>
-        </li>
-      </ul>
-      <div id="info">
-        <?php echo $info;?>
-        <a class="mb-3 btn btn-primary" href="admission.php?id=<?php echo $id;?>">Edit Information</a>
-        <div id="clinical">
-          <?php foreach($clinical as $c) echo $c;?>
-          <a class="mb-3 btn btn-primary" href="clinical.php?id=<?php echo $id;?>">Add Clinical Note</a>
-        </div>
-        <div id="report">
-          <?php foreach($report as $r) echo $r;?>
-          <a class="mb-3 btn btn-primary" href="laboratory.php?id=<?php echo $id;?>">Add Laboratory Report</a>
-        </div>
-        <div id="treatment" <?php if($info=="") echo "style='display:none'";?>>
-          <a class="btn btn-success btn-lg" href="treatment.php?id=<?php echo $id;?>">Treatment</a>
-        </div>
-        <div <?php if($info!="") echo "style='display:none'";?>>
-          <h1>Please enter a valid patient ID</h1>
-          <form>
-            <input name="id">
-            <button type="submit">View</button>
-          </form>
+      <div <?php if(empty($pid)) echo "style='display:none'";?>>
+        <ul class="nav nav-tabs">
+          <li class="nav-item">
+            <a class="nav-link active" aria-current="page" href="#info">Info</a>
+          </li>
+          <li class="nav-item">
+            <a class="nav-link" href="#clinical">Clinical Notes</a>
+          </li>
+          <li class="nav-item">
+            <a class="nav-link" href="#report">Lab Reports</a>
+          </li>
+        </ul>
+        <div id="info">
+          <?php echo $info;?>
+          <a class="mb-3 btn btn-primary" href="admission.php?pid=<?php echo $pid;?>">Edit Information</a>
+          <div id="clinical">
+            <?php foreach($clinical as $c) echo $c;?>
+            <a class="mb-3 btn btn-primary" href="clinical.php?pid=<?php echo $pid;?>">Add Clinical Note</a>
+          </div>
+          <div id="report">
+            <?php foreach($reports as $r) echo $r;?>
+            <a class="mb-3 btn btn-primary" href="laboratory.php?pid=<?php echo $pid;?>">Add Laboratory Report</a>
+          </div>
+          <div id="treatment" <?php if($info=="") echo "style='display:none'";?>>
+            <a class="btn btn-success btn-lg" href="treatment.php?pid=<?php echo $pid;?>">Treatment</a>
+          </div>
         </div>
       </div>
+      <div <?php if(!empty($pid)) echo "style='display:none'";?>>
+        <h1>Please enter a valid patient ID</h1>
+        <form>
+          <input class="form-control" name="pid">
+          <button class="form-control" type="submit">View</button>
+        </form>
+      </div>
     </div>
   </body>
 </html>