]> Softwares of Agnibho - simpleipd.git/blob - lib/functions.php
2ee182aee48354a17c8f01a7b2b5bd63f25e4180
[simpleipd.git] / lib / functions.php
1 <?php
2 function schema2form($file, $pid=null, $id=null, $cat=null, $data=null){
3 global $db;
4 $schema=json_decode(file_get_contents($file));
5
6 $lockpid="";
7 if(!empty($pid) && !empty($id) && !empty($cat)){
8 $data=json_decode($db->getData($pid, $id, $cat)->fetchArray()["data"]);
9 }
10 elseif(!empty($pid) && $file=="forms/admission.schema.json"){
11 $data=json_decode($db->getAdmissionData($pid)->fetchArray()["data"]);
12 $lockpid="readonly";
13 }
14 elseif(!empty($pid) && $file=="forms/history.schema.json"){
15 $data=json_decode($db->getHistory($pid)->fetchArray()["history"]);
16 $lockpid="readonly";
17 }
18
19 $form="<form method='post'>";
20 $form=$form."<input type='hidden' name='form' value='".str_replace(["forms/",".schema.json"], "", $file)."'>";
21
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;
28 }
29 else{
30 $value="";
31 $value2="";
32 }
33 if(in_array($field, $schema->required)){
34 $req="required";
35 }
36 else{
37 $req="";
38 }
39 if(isSet($prop->format)){
40 $type=$prop->format;
41 }
42 else{
43 $type=$prop->type;
44 }
45
46 $form=$form."<div>";
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>";
52 }
53 $form=$form."</select>";
54 }
55 elseif(isSet($prop->format) && $prop->format=="textarea"){
56 $form=$form."<textarea class='form-control' name='".$field."' id='".$field."'>".$value2."</textarea>";
57 }
58 elseif($field=="pid"){
59 $form=$form."<input class='form-control' ".$lockpid." ".$req." type='".$type."' step='any' name='".$field."' id='".$field."' ".$value.">";
60 }
61 else{
62 $form=$form."<input class='form-control' ".$req." type='".$type."' step='any' name='".$field."' id='".$field."' ".$value.">";
63 }
64 $form=$form."</div>";
65
66 }
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>";
70 return $form;
71 }
72
73 function getInfo($pid){
74 global $db;
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>";
83 return $info;
84 }
85
86 function viewData($data, $edit=null){
87 if(!empty($data)){
88 $data=json_decode($data);
89 if(!empty($data->form)){
90 $schema=json_decode(file_get_contents("forms/".$data->form.".schema.json"));
91 }
92 unset($data->cat);
93 $view="<table class='table'>";
94 if(!empty($schema->description)){
95 $description=$schema->description;
96 }
97 else{
98 $description="";
99 }
100 if(!empty($data->date)){
101 if(!empty($data->time)){
102 $date=$data->date." ".$data->time;
103 }
104 $date=$data->date;
105 }
106 else{
107 $date="";
108 }
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>";
114 }
115 elseif($field=="extra-note"){
116 $view=$view."<tr><td>Extra Notes</td><td>".$value."</td></tr>";
117 }
118 else{
119 $view=$view."<tr><td>".$field."</td><td>".$value."</td></tr>";
120 }
121 }
122 }
123 if(!empty($edit)){
124 $view=$view."<tr><td colspan='2'><a href='".$edit."'>Edit</a>";
125 }
126 $view=$view."</table>";
127 return $view;
128 }
129 else{
130 return "";
131 }
132 }
133
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){
141 if(is_object($v)){
142 $view=$view."<tr><td>".$v->name."</td><td>".$v->mic."</td><td>".$v->interpretation."</td></tr>";
143 }
144 }
145 if(!empty($data->note)){
146 $view=$view."<tr><td>Note</td><td colspan='2'>".$data->note."</td></tr>";
147 }
148 $view=$view."<tr><td colspan='2'><a href='".$edit."'>Edit</a></td></tr>";
149 $view=$view."</table>";
150 return $view;
151 }
152
153 function view_drug($file){
154 if(is_file($file)){
155 $druglist=json_decode(file_get_contents($file));
156 }
157 else{
158 $druglist=[];
159 }
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){
163 if($drug->omit){
164 $omit="style='display:none'";
165 }
166 else{
167 $omit="";
168 }
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>";
170 }
171 $view=$view."</table>";
172 return $view;
173 }
174 ?>