From fb94247d8bb2ee044deccab7717fe9c117d81b18 Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Fri, 14 May 2021 13:56:34 +0530 Subject: [PATCH] Editable info --- admission.php | 9 +++++++-- lib/db.php | 21 +++++++++++++++++++-- lib/functions.php | 8 ++++++++ schema.sql | 1 - 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/admission.php b/admission.php index 1dba684..47deca1 100644 --- a/admission.php +++ b/admission.php @@ -1,12 +1,17 @@ admit($_POST); //header("Location: view.php?pid=".$_POST["pid"]); //exit(); } -$form=schema2form("forms/admission.schema.json"); +if(!empty($_GET["pid"])){ + $form=schema2form("forms/admission.schema.json", $_GET["pid"]); +} +else{ + $form=schema2form("forms/admission.schema.json"); +} ?> diff --git a/lib/db.php b/lib/db.php index 515642a..5385b22 100644 --- a/lib/db.php +++ b/lib/db.php @@ -4,12 +4,20 @@ class DB extends SQLite3 { $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);"); + $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, data) VALUES (:pid, :name, :age, :sex, :data);"); + } + else{ + $stmt=$this->prepare("UPDATE patients SET name=:name,age=:age,sex=:sex,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(":addl", json_encode($post)); + $stmt->bindValue(":data", json_encode($post)); $stmt->execute(); } function updateHistory($post, $pid){ @@ -103,6 +111,12 @@ class DB extends SQLite3 { $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 getData($pid, $id, $cat){ if($cat=="clinical"){ $stmt=$this->prepare("SELECT data FROM clinical WHERE pid=:pid AND rowid=:id;"); @@ -111,6 +125,9 @@ class DB extends SQLite3 { } elseif($cat=="history"){ $stmt=$this->prepare("SELECT data FROM patients WHERE pid=:pid AND rowid=:id;"); } + else{ + return(false); + } $stmt->bindValue(":pid", $pid); $stmt->bindValue(":id", $id); $result=$stmt->execute(); diff --git a/lib/functions.php b/lib/functions.php index 562fb82..c3b6923 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -3,9 +3,14 @@ function schema2form($file, $pid=null, $id=null, $cat=null){ global $db; $schema=json_decode(file_get_contents($file)); + $lockpid=""; if(!empty($pid) && !empty($id) && !empty($cat)){ $data=json_decode($db->getData($pid, $id, $cat)->fetchArray()["data"]); } + elseif(!empty($pid) && $file=="forms/admission.schema.json"){ + $data=json_decode($db->getAdmission($pid)->fetchArray()["data"]); + $lockpid="readonly"; + } else{ $data=null; } @@ -44,6 +49,9 @@ function schema2form($file, $pid=null, $id=null, $cat=null){ } $form=$form.""; } + elseif($field=="pid"){ + $form=$form.""; + } else{ $form=$form.""; } diff --git a/schema.sql b/schema.sql index 11d20da..a202092 100644 --- a/schema.sql +++ b/schema.sql @@ -20,7 +20,6 @@ name text, age int, sex text, status text, -addl text, data text ); CREATE TABLE reports( -- 2.39.5