-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearchHistoryLookup.php
74 lines (68 loc) · 3.08 KB
/
searchHistoryLookup.php
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
<?php
require_once('base.php');
$metadata = $module->getMetadata($project);
if (array_key_exists('log_id', $_POST)) {
$vars = [];
/** @var mysqli_result $result */
$result = $module->queryLogs("select searchResults
where log_id = ?", $_POST['log_id']);
if ($result->num_rows != 1) {
echo "Incorrect number of entries found";
die();
}
$row = $result->fetch_assoc();
$recordOutputs = [];
$headerFields = [];
$results = json_decode($row['searchResults'], true);
foreach ($results as $recordId) {
$recordOutputs[$recordId] = $module->getDisplayDataforRecord($project, $recordId, false);
}
$recordOutputs = array_filter($recordOutputs);
$headerFields = $module->getDisplayHeaders($project);
//if(count($recordIds) == 0 ) {
// echo "No matching records found";
// die();
//}
$vars['records'] = $recordOutputs;
$vars['headers'] = $headerFields;
echo $twig->render('patientSearch.twig', $vars);
} else {
/** @var mysqli_result $result */
$result = $module->queryLogs("select log_id, user, timestamp, resultCount, searchParams
where message = 'searchHistory' order by timestamp desc");
$historyEntries = [];
$searchHeaders = ['Timestamp', 'User', 'Number of Results'];
$initialHeaderCount = count($searchHeaders);
while ($row = $result->fetch_assoc()) {
if (count($historyEntries) >= 25) {
break;
}
$historyEntries[$row['log_id']]['timestamp'] = $row['timestamp'];
$historyEntries[$row['log_id']]['user'] = $row['user'];
$historyEntries[$row['log_id']]['resultCount'] = $row['resultCount'];
$historyEntries[$row['log_id']]['params'] = json_decode($row['searchParams'], true);
$historyEntries[$row['log_id']]['paramsEncoded'] = $row['searchParams'];
foreach ($historyEntries[$row['log_id']]['params'] as $field => $value) {
if (in_array($metadata[$field]['field_type'], ['dropdown', 'checkbox', 'radio'])) {
$options = $module->getChoiceLabels($field);
if (is_array($value)) {
foreach ($value as $key => $item) {
$historyEntries[$row['log_id']]['params'][$field][$key] = $options[$item];
}
} else {
$historyEntries[$row['log_id']]['params'][$field] = $options[$value];
}
}
}
if ((count($historyEntries[$row['log_id']]['params']) + $initialHeaderCount) > count($searchHeaders)) {
foreach ($historyEntries[$row['log_id']]['params'] as $field => $value) {
$searchHeaders[] = $metadata[$field]["field_label"];
}
}
}
$vars['historyEntries'] = $historyEntries;
$vars['searchHeaders'] = $searchHeaders;
$vars['searchHistoryLookupLink'] = $module->getUrl("searchHistoryLookup.php");
$vars['patientSearchLink'] = $module->getUrl("patientSearchAjax.php");
echo $twig->render('searchHistory.twig', $vars);
}