]>
Softwares of Agnibho - simpleipd.git/blob - lib/functions.php
c3b6923361ae4c678f60b6bb5b9f7f4f4c403b5e
2 function schema2form($file, $pid=null, $id=null, $cat=null){
4 $schema=json_decode(file_get_contents($file));
7 if(!empty($pid) && !empty($id) && !empty($cat)){
8 $data=json_decode($db->getData($pid, $id, $cat)->fetchArray()["data"]);
10 elseif(!empty($pid) && $file=="forms/admission.schema.json"){
11 $data=json_decode($db->getAdmission($pid)->fetchArray()["data"]);
18 $form="<form method='post'>";
19 $form=$form."<input type='hidden' name='form' value='".str_replace(["forms/",".schema.json"], "", $file)."'>";
21 foreach($schema->properties
as $field=>$prop){
22 if($prop->type
== "integer") $prop->type
="number";
23 if($prop->type
== "string") $prop->type
="text";
25 $value="value='".$data->$field."'";
30 if(in_array($field, $schema->required
)){
36 if(isSet($prop->format
)){
44 $form=$form."<label class='form-label' for='".$field."'>".$prop->description
."</label>";
45 if(isSet($prop->enum
)){
46 $form=$form."<select class='form-control' ".$req." name='".$field."' id='".$field."'>";
47 foreach($prop->enum
as $opt){
48 $form=$form."<option>".$opt."</option>";
50 $form=$form."</select>";
52 elseif($field=="pid"){
53 $form=$form."<input class='form-control' ".$lockpid." ".$req." type='".$type."' name='".$field."' id='".$field."' ".$value.">";
56 $form=$form."<input class='form-control' ".$req." type='".$type."' name='".$field."' id='".$field."' ".$value.">";
61 $form=$form."<div><label class='form-label' for='extra-note'>Notes</label><textarea class='form-control' name='extra-note' id='extra-note'></textarea></div>";
62 $form=$form."<button class='btn btn-primary mt-3' type='submit'>Save</button>";
63 $form=$form."</form>";
67 function getInfo($pid){
69 $info="<table class='table'>";
70 $info=$info."<tr><td>ID</td><td>".$pid."</td></tr>";
71 $info=$info."<tr><td>Name</td><td>".$db->getName($pid)->fetchArray()["name"]."</td></tr>";
72 $info=$info."<tr><td>Age</td><td>".$db->getAge($pid)->fetchArray()["age"]."</td></tr>";
73 $info=$info."<tr><td>Sex</td><td>".$db->getSex($pid)->fetchArray()["sex"]."</td></tr>";
74 $info=$info."</table>";
78 function viewData($data, $edit=null){
79 $data=json_decode($data);
81 $view="<table class='table'>";
82 foreach($data as $field=>$value){
83 $view=$view."<tr><td>".$field."</td><td>".$value."</td></tr>";
86 $view=$view."<tr><td><a href='".$edit."'>Edit</a>";
88 $view=$view."</table>";
92 function view_drug($file){
94 $druglist=json_decode(file_get_contents($file));
99 $view="<form method='post' id='omitter'></form><table class='table'>";
100 $view=$view."<tr><th>Drug</th><th>Dose</th><th>Route</th><th>Frequency</th><th>Duration</th></tr>";
101 foreach($druglist as $id=>$drug){
103 $omit="style='display:none'";
108 $view=$view."<tr><td>".$drug->drug
."</td><td>".$drug->dose
."</td><td>".$drug->route
."</td><td>".$drug->freq
."</td><td>".$drug->duration
."</td><td>".$drug->note
."</td><td><button name='omit' value='".$id."' form='omitter' ".$omit.">Omit</button></td></tr>";
110 $view=$view."</table>";