]>
Softwares of Agnibho - simpleipd.git/blob - lib/functions.php
2 function schema2form($file, $pid=null, $id=null, $cat=null, $data=null, $time=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;
29 elseif(!empty($time) && $field=="date"){
30 $value="value='".date("Y-m-d", $time)."'";
31 $value2=date("Y-m-d", $time);
33 elseif(!empty($time) && $field=="time"){
34 $value="value='".date("H:i", $time)."'";
35 $value2=date("H:i", $time);
41 if(in_array($field, $schema->required
)){
47 if(isSet($prop->format
)){
55 $form=$form."<label class='form-label' for='".$field."'>".$prop->description
."</label>";
56 if(isSet($prop->enum
)){
57 $form=$form."<select class='form-control' ".$req." name='".$field."' id='".$field."'>";
58 foreach($prop->enum
as $opt){
60 $form=$form."<option selected>".$opt."</option>";
63 $form=$form."<option>".$opt."</option>";
66 $form=$form."</select>";
68 elseif(isSet($prop->format
) && $prop->format
=="textarea"){
69 $form=$form."<textarea class='form-control' name='".$field."' id='".$field."'>".$value2."</textarea>";
71 elseif($field=="pid"){
72 $form=$form."<input class='form-control' ".$lockpid." ".$req." type='".$type."' step='any' name='".$field."' id='".$field."' ".$value.">";
75 $form=$form."<input class='form-control' ".$req." type='".$type."' step='any' name='".$field."' id='".$field."' ".$value.">";
80 if(!empty($data->extra_note
)){
81 $extra_note=$data->extra_note
;
86 $form=$form."<div><label class='form-label' for='extra_note'>Extra Notes</label><textarea class='form-control' name='extra_note' id='extra_note'>".$extra_note."</textarea></div>";
87 $form=$form."<button class='btn btn-primary mt-3' type='submit'>Save</button>";
88 $form=$form."</form>";
92 function getInfo($pid){
94 $info="<table class='table'>";
95 $info=$info."<tr><td>ID</td><td>".$pid."</td></tr>";
96 $info=$info."<tr><td>Name</td><td>".$db->getName($pid)->fetchArray()["name"]."</td></tr>";
97 $info=$info."<tr><td>Age</td><td>".$db->getAge($pid)->fetchArray()["age"]."</td></tr>";
98 $info=$info."<tr><td>Sex</td><td>".$db->getSex($pid)->fetchArray()["sex"]."</td></tr>";
99 $info=$info."<tr><td>Bed</td><td>".$db->getWard($pid)->fetchArray()["ward"]."-".$db->getBed($pid)->fetchArray()["bed"]."</td></tr>";
100 $info=$info."<tr><td>Diagnosis</td><td>".$db->getDiagnosis($pid)->fetchArray()["diagnosis"]."</td></tr>";
101 $info=$info."</table>";
105 function viewData($data, $edit=null){
107 $data=json_decode($data);
108 if(!empty($data->form
)){
109 $schema=json_decode(file_get_contents("forms/".$data->form
.".schema.json"));
112 $view="<table class='table'>";
113 if(!empty($schema->description
)){
114 $description=$schema->description
;
119 if(!empty($data->date
)){
120 if(!empty($data->time
)){
121 $date=date("M d, Y h:i a", strtotime($data->date
." ".$data->time
));
130 $view=$view."<tr><th class='w-25'>".$description."</th><th>".$date."</th></tr>";
131 foreach($data as $field=>$value){
132 if(!empty($value) && $field!="form" && $field!="date" && $field!="time"){
133 if(!empty($schema->properties
->$field)){
134 $view=$view."<tr><td>".$schema->properties
->$field->description
."</td><td>".$value."</td></tr>";
136 elseif($field=="extra_note"){
137 $view=$view."<tr><td>Extra Notes</td><td><pre>".$value."</pre></td></tr>";
140 $view=$view."<tr><td>".$field."</td><td>".$value."</td></tr>";
145 $view=$view."<tr><td colspan='2'><a href='".$edit."'>Edit</a>";
147 $view=$view."</table>";
155 function viewAntibiogram($data, $edit){
156 $data=json_decode($data);
157 $view="<table class='table table-striped'>";
158 $view=$view."<tr><th>Vitek Report</th><th colspan='2'>".$data->date
."</th></tr>";
159 $view=$view."<tr><td>Sample</td><td colspan='2'>".$data->sample
."</td></tr>";
160 $view=$view."<tr><td>Organism</td><td colspan='2'>".$data->organism
."</td></tr>";
161 $view=$view."<tr><th>Antibiotic</th><th>MIC</th><th>Interpretation</th>";
162 foreach($data as $k=>$v){
164 $view=$view."<tr><td>".$v->name
."</td><td>".$v->mic
."</td><td>".$v->interpretation
."</td></tr>";
167 if(!empty($data->note
)){
168 $view=$view."<tr><td>Note</td><td colspan='2'>".$data->note
."</td></tr>";
170 $view=$view."<tr><td colspan='2'><a href='".$edit."'>Edit</a></td></tr>";
171 $view=$view."</table>";
175 function view_drug($file){
177 $druglist=json_decode(file_get_contents($file));
182 $view="<form method='post' id='omitter'></form><table class='table'>";
183 $view=$view."<tr><th>Drug</th><th>Dose</th><th>Route</th><th>Frequency</th><th>Duration</th></tr>";
184 foreach($druglist as $id=>$drug){
186 $omit="style='display:none'";
191 $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>";
193 $view=$view."</table>";