<?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>
$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){
$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;");
} 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();
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;
}
}
$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.">";
}