From: Agnibho Mondal Date: Fri, 14 May 2021 06:51:41 +0000 (+0530) Subject: Rewritten with SQLite3 X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=8c967f535224eb354a6c8732bcb48c82df97f2c6;p=simpleipd.git Rewritten with SQLite3 --- diff --git a/admission.php b/admission.php index 33f69fc..1dba684 100644 --- a/admission.php +++ b/admission.php @@ -1,20 +1,12 @@ admit($_POST); + //header("Location: view.php?pid=".$_POST["pid"]); + //exit(); } +$form=schema2form("forms/admission.schema.json"); ?> diff --git a/clinical.php b/clinical.php index 58806b4..8538e12 100644 --- a/clinical.php +++ b/clinical.php @@ -1,19 +1,24 @@ 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"); } ?> @@ -24,6 +29,7 @@ else{
+
diff --git a/forms/admission.schema.json b/forms/admission.schema.json index 698dd08..44fa8c6 100644 --- a/forms/admission.schema.json +++ b/forms/admission.schema.json @@ -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 index 0000000..0647afa --- /dev/null +++ b/forms/history.schema.json @@ -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"] +} diff --git a/forms/report-ch.schema.json b/forms/report-ch.schema.json index f497160..3c33b71 100644 --- a/forms/report-ch.schema.json +++ b/forms/report-ch.schema.json @@ -65,5 +65,5 @@ "type": "number" } }, - "required": [] + "required": ["date"] } diff --git a/forms/report-lft.schema.json b/forms/report-lft.schema.json index b231646..2f89980 100644 --- a/forms/report-lft.schema.json +++ b/forms/report-lft.schema.json @@ -45,5 +45,5 @@ "type": "number" } }, - "required": [] + "required": ["date"] } diff --git a/forms/report-rft.schema.json b/forms/report-rft.schema.json index 5f26bf2..65df1d7 100644 --- a/forms/report-rft.schema.json +++ b/forms/report-rft.schema.json @@ -33,5 +33,5 @@ "type": "number" } }, - "required": [] + "required": ["date"] } diff --git a/history.php b/history.php new file mode 100644 index 0000000..d055b44 --- /dev/null +++ b/history.php @@ -0,0 +1,31 @@ +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"); +} +?> + + + + + History + + +
+ + +
+ + diff --git a/index.php b/index.php index 427aa63..1af46e7 100644 --- a/index.php +++ b/index.php @@ -1,10 +1,14 @@ ".$id."".$data->name."".$data->ward." ".$data->bed.""; +$list=$db->getList(); +$show=""; +if(!empty($list)){ + while($arr=$list->fetchArray()){ + $pid=$arr["pid"]; + $name=$db->getName($pid)->fetchArray()["name"]; + $show=$show."".$pid."".$name." "; + } } ?> @@ -21,7 +25,7 @@ foreach(glob("data/*") as $id){

Patient List

- +
Patient IDNameBed Number
Add New Patient diff --git a/laboratory.php b/laboratory.php index 43c23ed..add8861 100644 --- a/laboratory.php +++ b/laboratory.php @@ -1,10 +1,10 @@ ".$form->description.""; + $list=$list."
  • ".$form->description."
  • "; } } ?> diff --git a/lib/db.php b/lib/db.php new file mode 100644 index 0000000..515642a --- /dev/null +++ b/lib/db.php @@ -0,0 +1,133 @@ +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(); +?> diff --git a/lib/functions.php b/lib/functions.php index e48b633..562fb82 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -1,22 +1,22 @@ getData($pid, $id, $cat)->fetchArray()["data"]); } - if($stamp===false){ - $stamp=time()."-".rand(1000,9999); + else{ + $data=null; } $form="
    "; - $form=$form.""; - $form=$form.""; + $form=$form.""; 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=""; + $info=$info.""; + $info=$info.""; + $info=$info.""; + $info=$info.""; + $info=$info."
    ID".$pid."
    Name".$db->getName($pid)->fetchArray()["name"]."
    Age".$db->getAge($pid)->fetchArray()["age"]."
    Sex".$db->getSex($pid)->fetchArray()["sex"]."
    "; + return $info; +} + +function viewData($data, $edit=null){ + $data=json_decode($data); + unset($data->cat); $view=""; foreach($data as $field=>$value){ $view=$view.""; } - if($edit!==false){ - $view=$view."
    ".$field."".$value."
    Edit"; + if(!empty($edit)){ + $view=$view."
    Edit"; } $view=$view."
    "; 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)); diff --git a/report.php b/report.php index 146fa5f..5a6fb4b 100644 --- a/report.php +++ b/report.php @@ -1,25 +1,25 @@ 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(); -} ?> diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..11d20da --- /dev/null +++ b/schema.sql @@ -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 +); diff --git a/treatment.php b/treatment.php index 51f5504..f9347ca 100644 --- a/treatment.php +++ b/treatment.php @@ -1,16 +1,30 @@ 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="
    "; + $view=$view.""; + $view=$view.""; + while($drug=$list->fetchArray()){ + if($drug["omit"]){ + $omit="style='display:none'"; + } + else{ + $omit=""; + } + $view=$view.""; } + $view=$view."
    DrugDoseRouteFrequencyStartDurationNote
    ".$drug["name"]."".$drug["dose"]."".$drug["route"]."".$drug["frequency"]."".$drug["start"]."".$drug["duration"]."".$drug["addl"]."
    "; + } -$list=view_drug("data/".$_GET["id"]."/treatment.json"); ?> @@ -20,23 +34,23 @@ $list=view_drug("data/".$_GET["id"]."/treatment.json");
    -
    +

    Medicine List

    - +
    - +
    -
    - +
    +
    -
    - +
    +
    -
    +
    -
    - +
    +
    -
    +
    + +
    +
    +
    + +
    -
    diff --git a/view.php b/view.php index a68fe28..c7a1fcb 100644 --- a/view.php +++ b/view.php @@ -1,19 +1,21 @@ 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"])); + } } ?> @@ -25,39 +27,41 @@ foreach(glob("data/".$id."/report/*.json") as $f){

    Patient Data

    - -
    - - Edit Information - - -
    > - Treatment -
    -
    > -

    Please enter a valid patient ID

    -
    - - -
    + +
    > +

    Please enter a valid patient ID

    +
    + + +
    +