]> Softwares of Agnibho - simpleipd.git/commitdiff
Editable info
authorAgnibho Mondal <mondal@agnibho.com>
Fri, 14 May 2021 08:26:34 +0000 (13:56 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Fri, 14 May 2021 08:26:34 +0000 (13:56 +0530)
admission.php
lib/db.php
lib/functions.php
schema.sql

index 1dba68437135d17089c682863615db3e077c6676..47deca178121f5377622807fb739b3aeb5f42811 100644 (file)
@@ -1,12 +1,17 @@
 <?php
 require("lib/functions.php");
 require("lib/db.php");
-if(!empty($_POST["pid"]) && !empty($_POST["name"]) && !empty($_POST["age"]) && !empty($_POST["sex"])){
+if(!empty($_POST["pid"]) && !empty($_POST["name"])){
   $db->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");
+}
 ?>
 <!DOCTYPE html>
 <html>
index 515642ac1bdd8281a9a7b94b7cec373234836d9d..5385b22a290ac2ca6cf8177d1c91d7e43694e80b 100644 (file)
@@ -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();
index 562fb82b1af32d4b68d6c29694ff52f35444692b..c3b6923361ae4c678f60b6bb5b9f7f4f4c403b5e 100644 (file)
@@ -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."</select>";
     }
+    elseif($field=="pid"){
+      $form=$form."<input class='form-control' ".$lockpid." ".$req." type='".$type."' name='".$field."' id='".$field."' ".$value.">";
+    }
     else{
       $form=$form."<input class='form-control' ".$req." type='".$type."' name='".$field."' id='".$field."' ".$value.">";
     }
index 11d20da92331e0a15b950f16dfb598e33ec533cc..a202092ab6f30bc8ca2795a8b6df407c87ceab43 100644 (file)
@@ -20,7 +20,6 @@ name text,
 age int,
 sex text,
 status text,
-addl text,
 data text
 );
 CREATE TABLE reports(