]>
Softwares of Agnibho - simpleipd.git/blob - lib/functions.php
2ee182aee48354a17c8f01a7b2b5bd63f25e4180
2 function schema2form($file, $pid=null, $id=null, $cat=null, $data=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->getAdmissionData($pid)->fetchArray()["data"]);
14 elseif(!empty($pid) && $file=="forms/history.schema.json"){
15 $data=json_decode($db->getHistory($pid)->fetchArray()["history"]);
19 $form="<form method='post'>";
20 $form=$form."<input type='hidden' name='form' value='".str_replace(["forms/",".schema.json"], "", $file)."'>";
22 foreach($schema->properties
as $field=>$prop){
23 if($prop->type
== "integer") $prop->type
="number";
24 if($prop->type
== "string") $prop->type
="text";
25 if(!empty($data->$field)){
26 $value="value='".$data->$field."'";
27 $value2=$data->$field;
33 if(in_array($field, $schema->required
)){
39 if(isSet($prop->format
)){
47 $form=$form."<label class='form-label' for='".$field."'>".$prop->description
."</label>";
48 if(isSet($prop->enum
)){
49 $form=$form."<select class='form-control' ".$req." name='".$field."' id='".$field."'>";
50 foreach($prop->enum
as $opt){
51 $form=$form."<option>".$opt."</option>";
53 $form=$form."</select>";
55 elseif(isSet($prop->format
) && $prop->format
=="textarea"){
56 $form=$form."<textarea class='form-control' name='".$field."' id='".$field."'>".$value2."</textarea>";
58 elseif($field=="pid"){
59 $form=$form."<input class='form-control' ".$lockpid." ".$req." type='".$type."' step='any' name='".$field."' id='".$field."' ".$value.">";
62 $form=$form."<input class='form-control' ".$req." type='".$type."' step='any' name='".$field."' id='".$field."' ".$value.">";
67 $form=$form."<div><label class='form-label' for='extra-note'>Extra Notes</label><textarea class='form-control' name='extra-note' id='extra-note'></textarea></div>";
68 $form=$form."<button class='btn btn-primary mt-3' type='submit'>Save</button>";
69 $form=$form."</form>";
73 function getInfo($pid){
75 $info="<table class='table'>";
76 $info=$info."<tr><td>ID</td><td>".$pid."</td></tr>";
77 $info=$info."<tr><td>Name</td><td>".$db->getName($pid)->fetchArray()["name"]."</td></tr>";
78 $info=$info."<tr><td>Age</td><td>".$db->getAge($pid)->fetchArray()["age"]."</td></tr>";
79 $info=$info."<tr><td>Sex</td><td>".$db->getSex($pid)->fetchArray()["sex"]."</td></tr>";
80 $info=$info."<tr><td>Bed</td><td>".$db->getWard($pid)->fetchArray()["ward"]."-".$db->getBed($pid)->fetchArray()["bed"]."</td></tr>";
81 $info=$info."<tr><td>Diagnosis</td><td>".$db->getDiagnosis($pid)->fetchArray()["diagnosis"]."</td></tr>";
82 $info=$info."</table>";
86 function viewData($data, $edit=null){
88 $data=json_decode($data);
89 if(!empty($data->form
)){
90 $schema=json_decode(file_get_contents("forms/".$data->form
.".schema.json"));
93 $view="<table class='table'>";
94 if(!empty($schema->description
)){
95 $description=$schema->description
;
100 if(!empty($data->date
)){
101 if(!empty($data->time
)){
102 $date=$data->date
." ".$data->time
;
109 $view=$view."<tr><th>".$description."</th><th>".$date."</th></tr>";
110 foreach($data as $field=>$value){
111 if(!empty($value) && $field!="form" && $field!="date" && $field!="time"){
112 if(!empty($schema->properties
->$field)){
113 $view=$view."<tr><td>".$schema->properties
->$field->description
."</td><td>".$value."</td></tr>";
115 elseif($field=="extra-note"){
116 $view=$view."<tr><td>Extra Notes</td><td>".$value."</td></tr>";
119 $view=$view."<tr><td>".$field."</td><td>".$value."</td></tr>";
124 $view=$view."<tr><td colspan='2'><a href='".$edit."'>Edit</a>";
126 $view=$view."</table>";
134 function viewAntibiogram($data, $edit){
135 $data=json_decode($data);
136 $view="<table class='table table-striped'>";
137 $view=$view."<tr><th>Vitek Report</th><th colspan='2'>".$data->date
."</th></tr>";
138 $view=$view."<tr><td>Sample</td><td colspan='2'>".$data->sample
."</td></tr>";
139 $view=$view."<tr><th>Antibiotic</th><th>MIC</th><th>Interpretation</th>";
140 foreach($data as $k=>$v){
142 $view=$view."<tr><td>".$v->name
."</td><td>".$v->mic
."</td><td>".$v->interpretation
."</td></tr>";
145 if(!empty($data->note
)){
146 $view=$view."<tr><td>Note</td><td colspan='2'>".$data->note
."</td></tr>";
148 $view=$view."<tr><td colspan='2'><a href='".$edit."'>Edit</a></td></tr>";
149 $view=$view."</table>";
153 function view_drug($file){
155 $druglist=json_decode(file_get_contents($file));
160 $view="<form method='post' id='omitter'></form><table class='table'>";
161 $view=$view."<tr><th>Drug</th><th>Dose</th><th>Route</th><th>Frequency</th><th>Duration</th></tr>";
162 foreach($druglist as $id=>$drug){
164 $omit="style='display:none'";
169 $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>";
171 $view=$view."</table>";