-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchProcessor.php
More file actions
365 lines (297 loc) · 12.7 KB
/
searchProcessor.php
File metadata and controls
365 lines (297 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<?php
include('conn.php');
$conn = mysqli_connect('localhost', 'root', '', 'ehealth');
include('functions.php');
include('conn.php');
if (!isLoggedIn()) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}
$user = $_SESSION['user']['id'];
$sql = "SELECT * FROM future WHERE user_id ='$user' ORDER BY id DESC LIMIT 1";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);
$first_symptom = $row['symptom'];
if (isset($_POST['symptom'])) {
search();
}
if (isset($_POST['symptoms3'])) {
search2();
}
if (isset($_POST['key'])) {
?>
<table class="table table-hover">
<tbody>
<?php
$count = 0;
$key = $_POST['key'];
$key = addslashes($key);
$sql = mysqli_query($conn, "select DISTINCT (name), symptoms.id as id from symptoms WHERE name LIKE '%$key%'") or die(mysqli_error());
While ($row = mysqli_fetch_array($sql)) {
$count++;
$name = $row['name'];
$id = $row['id'];
if ($count <= 10) {
?>
<tr>
<td> <?php echo $name; ?> </td>
<td>
<button type="button" class="add btn btn-info" id="<?php echo $name; ?>">
<span class="glyphicon glyphicon-plus"></span>
</button>
</td>
</tr>
<?php }
}
if ($count == "") {
echo "no match Found";
} else {
?>
<?php } ?>
</tbody>
</table>
<?php
}
if (isset($_POST['lat'])) {
$user = $_SESSION['user']['id'];
$lat = $_POST['lat'];
$lon = $_POST['lon'];
$query = "UPDATE `users` SET `longitude`=$lon,`latitude`=$lat WHERE id=$user ";
$conn = mysqli_connect('localhost', 'root', '', 'ehealth');
mysqli_query($conn, $query);
}
function search()
{
$user = $_SESSION['user']['id'];
$symptom = $_POST['symptom'];
$query = "INSERT INTO future (symptom,found,user_id)
VALUES('$symptom','1', '$user')";
$conn = mysqli_connect('localhost', 'root', '', 'ehealth');
mysqli_query($conn, $query);
global $first_symptom;
$select = "SELECT DISTINCT name
FROM disease JOIN symptoms ON disease.id = symptoms.disease_id
WHERE name NOT IN ('$symptom','$first_symptom')
GROUP BY disease_id ";
//var_dump($select);die();
$run_select = mysqli_query($conn, $select);
$num = mysqli_num_rows($run_select);
?>
<div>
<h4> Are you feeling the following Too</h4>
</div>
<?php
if ($num == 0) {
echo "No symptom matching";
} else {
while ($rows = mysqli_fetch_array($run_select)) {
//$id = $rows['disease_id'];
$name = $rows['name'];
?>
<ul class="connectedSortable ui-sortable" id="search">
<li class="ui-state-default" id="<?php echo $name; ?>"
name="<?php echo $name; ?>"><?php echo $name; ?></li>
</ul>
<?php
}
?>
<div><h4> If Yes choose the symptom</h4></div>
<form class="form-horizontal" id="submit_data">
<select class="form-control" id="symptoms3" name="symptoms3">
<option value="" selected="selected" disabled="disabled">Select Symptom</option>
<?php
$run_select1 = mysqli_query($conn, $select);
while ($rows = mysqli_fetch_array($run_select1)) {
$name2 = $rows['name'];
?>
<option value=<?php echo $name2; ?>><?php echo $name2; ?></option>
<?php
}
?>
</select>
<button type="button" onclick="searchOption3()" class="btn btn-success">Continue</button>
<button type="button" class="btn btn-danger" onchange="stopSearch()" class="btn btn-primary">None of above
</button>
</form>
<?php
}
}
function search2()
{
$conn = mysqli_connect('localhost', 'root', '', 'ehealth');
$user = $_SESSION['user']['id'];
$symptoms3 = $_POST['symptoms3'];
/*selects user cordinates*/
$select_user = "SELECT longitude,latitude FROM users WHERE id ='$user' ";
$conn = mysqli_connect('localhost', 'root', '', 'ehealth');
$result = mysqli_query($conn, $select_user);
$row = mysqli_fetch_array($result);
$latitudeFrom = $row['latitude'];
$longitudeFrom = $row['longitude'];
$select = "SELECT `id`, `name`, `city_id`, `address`, `latitude`, `longitude` FROM `facility`";
$run_select = mysqli_query($conn, $select);
while ($row = mysqli_fetch_array($run_select)) {
$id = $row['id'];
$name = $row['name'];
$address = $row['address'];
$latitudeTo = $row['latitude'];
$longitudeTo = $row['longitude'];
$city_id = $row['city_id'];
$theta = $longitudeFrom - $longitudeTo;
$dist = sin(deg2rad($latitudeFrom)) * sin(deg2rad($latitudeTo)) + cos(deg2rad($latitudeFrom)) * cos(deg2rad($latitudeTo)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$distance = ($miles * 1.609344);
$dis = round($distance, 3) . "km from here";
$insert = "INSERT INTO `tmp`(`name`, `city_id`, `address`, `distance`,`user_id`,`facility_id`)
VALUES ('$name','$city_id','$address','$distance','$user','$id')";
$run_insert = mysqli_query($conn, $insert);
}
/*end*/
$sql = "SELECT * FROM future WHERE user_id ='$user' ORDER by id DESC limit 2 ";
$conn = mysqli_connect('localhost', 'root', '', 'ehealth');
$result = mysqli_query($conn, $sql);
while ($row[] = mysqli_fetch_array($result)) {
}
$first_symptom = $row[0]['symptom'];
$second_symptom = $row[1]['symptom'];
$select = "SELECT DISTINCT name,disease, AVG(cutoff) AS cutoffPoints FROM disease JOIN symptoms ON disease.id = symptoms.disease_id
WHERE name IN ('$first_symptom','$second_symptom','$symptoms3')
GROUP BY disease_id ORDER BY cutoffPoints DESC";
$run_select = mysqli_query($conn, $select);
$num = mysqli_num_rows($run_select);
if ($num == 0) {
echo "<div class='alert alert-danger' role='alert'>No matching disease. Please try again later.</div>";
} else {
$row = mysqli_fetch_array($run_select);
$name = $row['disease'];
echo "<div class='alert alert-success' role='alert'>Disease Found -$name</div>";
?>
<div class="panel panel-info filterable">
<div class="panel-heading">
<h3 class="panel-title">List of Doctors</h3>
<div class="pull-right">
<button class="btn btn-default btn-xs btn-filter"><span class="fa fa-filter"></span> Filter</button>
</div>
</div>
<!-- panel heading end -->
<div class="panel-body">
<!-- panel content start -->
<!-- Table -->
<table class="table table-hover table-bordered">
<thead>
<tr class="filters">
<th><input type="text" class="form-control" placeholder="Firstname" disabled></th>
<th><input type="text" class="form-control" placeholder="Lastname" disabled></th>
<th><input type="text" class="form-control" placeholder="Doctor Contact" disabled></th>
<th><input type="text" class="form-control" placeholder="Facility" disabled></th>
<th><input type="text" class="form-control" placeholder="Facility Contact" disabled></th>
<th><input type="text" class="form-control" placeholder="Distance" disabled></th>
</tr>
</thead>
<?php
$result = mysqli_query($conn, "SELECT DISTINCT tmp.name as Facility , tmp.distance as Distance,practitioner.id ,practitioner.contact_details as Doc_Contact,
practitioner.firstname as Firstname,
practitioner.lastname as Lastname,
tmp.address as Facility_Contact FROM practitioner JOIN tmp ON practitioner.facility_id = tmp.facility_id WHERE
tmp.user_id='$user' ORDER BY Distance ASC ");
while ($doctors = mysqli_fetch_array($result)) {
echo "<tbody>";
echo "<tr>";
echo "<td>" . $doctors['Firstname'] . "</td>";
echo "<td>" . $doctors['Lastname'] . "</td>";
echo "<td>" . $doctors['Doc_Contact'] . "</td>";
echo "<td>" . $doctors['Facility'] . "</td>";
echo "<td>" . $doctors['Facility_Contact'] . "</td>";
echo "<td>" . $doctors['Distance'] . ".km from here" . "</td>";
echo "<form method='POST'>";
echo "<td class='text-center'><a href='appointment.php?&id=" . $doctors['id'] . "' class='glyphicon glyphicon-user'>Book Now</a></td>";
}
echo "</tr>";
echo "</tbody>";
echo "</table>";
$sql = "DELETE FROM `tmp` ";
$conn = mysqli_connect('localhost', 'root', '', 'ehealth');
$result = mysqli_query($conn, $sql);
?>
</div>
</div>
<?php
}
}
?>
<script src="assets/js/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
$(function () {
$("#search li").not('.emptyMessage').click(function () {
alert('Symptoms. ' + this.id);
});
});
$(function () {
$(".add").click(function () {
var element = $(this);
var info = element.attr("id");
$.ajax({
type: "POST",
url: "addSymptom.php",
data: ({info: info}),
success: function(data){
$(".result2").html(data);
window.location.reload();
}
}
);
$(this).parent().parent().fadeOut(300, function () {
$(this).remove();
});
return false;
});
});
</script>
<script type="text/javascript">
/*
Please consider that the JS part isn't production ready at all, I just code it to show the concept of merging filters and titles together !
*/
$(document).ready(function () {
$('.filterable .btn-filter').click(function () {
var $panel = $(this).parents('.filterable'),
$filters = $panel.find('.filters input'),
$tbody = $panel.find('.table tbody');
if ($filters.prop('disabled') == true) {
$filters.prop('disabled', false);
$filters.first().focus();
} else {
$filters.val('').prop('disabled', true);
$tbody.find('.no-result').remove();
$tbody.find('tr').show();
}
});
$('.filterable .filters input').keyup(function (e) {
/* Ignore tab key */
var code = e.keyCode || e.which;
if (code == '9') return;
/* Useful DOM data and selectors */
var $input = $(this),
inputContent = $input.val().toLowerCase(),
$panel = $input.parents('.filterable'),
column = $panel.find('.filters th').index($input.parents('th')),
$table = $panel.find('.table'),
$rows = $table.find('tbody tr');
/* Dirtiest filter function ever ;) */
var $filteredRows = $rows.filter(function () {
var value = $(this).find('td').eq(column).text().toLowerCase();
return value.indexOf(inputContent) === -1;
});
/* Clean previous no-result if exist */
$table.find('tbody .no-result').remove();
/* Show all rows, hide filtered ones (never do that outside of a demo ! xD) */
$rows.show();
$filteredRows.hide();
/* Prepend no-result row if all rows are filtered */
if ($filteredRows.length === $rows.length) {
$table.find('tbody').prepend($('<tr class="no-result text-center"><td colspan="' + $table.find('.filters th').length + '">No result found</td></tr>'));
}
});
});
</script>