|
1 | 1 | <?php |
2 | 2 | // get-api-dashboard-metrics.php |
3 | | - |
| 3 | +use Laminas\Diactoros\ServerRequest; |
4 | 4 | use App\Services\TestsService; |
5 | 5 | use App\Utilities\DateUtility; |
6 | 6 | use App\Utilities\JsonUtility; |
|
10 | 10 | use App\Services\DatabaseService; |
11 | 11 | use App\Registries\ContainerRegistry; |
12 | 12 |
|
13 | | -/** @var Laminas\Diactoros\ServerRequest $request */ |
| 13 | +/** @var ServerRequest $request */ |
14 | 14 | $request = AppRegistry::get('request'); |
15 | 15 | $_POST = _sanitizeInput($request->getParsedBody()); |
16 | 16 |
|
|
25 | 25 | $sWhere = []; |
26 | 26 |
|
27 | 27 | // Date range filter |
28 | | - if (isset($_POST['dateRange']) && trim((string) $_POST['dateRange']) != '') { |
| 28 | + if (isset($_POST['dateRange']) && trim((string) $_POST['dateRange']) !== '') { |
29 | 29 | [$start_date, $end_date] = DateUtility::convertDateRange($_POST['dateRange'] ?? '', includeTime: true); |
30 | 30 | $sWhere[] = " t.request_created_datetime BETWEEN '$start_date' AND '$end_date' "; |
31 | 31 | } |
32 | 32 |
|
33 | 33 | // Lab filter |
34 | | - if (isset($_POST['labName']) && trim((string) $_POST['labName']) != '') { |
| 34 | + if (isset($_POST['labName']) && trim((string) $_POST['labName']) !== '') { |
35 | 35 | $sWhere[] = " t.lab_id IN (" . $_POST['labName'] . ")"; |
36 | 36 | } |
37 | 37 |
|
38 | 38 | // State filter |
39 | | - if (isset($_POST['state']) && trim((string) $_POST['state']) != '') { |
| 39 | + if (isset($_POST['state']) && trim((string) $_POST['state']) !== '') { |
40 | 40 | $provinceId = implode(',', $_POST['state']); |
41 | 41 | $sWhere[] = " f.facility_state_id IN ($provinceId)"; |
42 | 42 | } |
43 | 43 |
|
44 | 44 | // District filter |
45 | | - if (isset($_POST['district']) && trim((string) $_POST['district']) != '') { |
| 45 | + if (isset($_POST['district']) && trim((string) $_POST['district']) !== '') { |
46 | 46 | $districtId = implode(',', $_POST['district']); |
47 | 47 | $sWhere[] = " f.facility_district_id IN ($districtId)"; |
48 | 48 | } |
49 | 49 |
|
50 | 50 | // Facility filter |
51 | | - if (isset($_POST['facilityId']) && trim((string) $_POST['facilityId']) != '') { |
| 51 | + if (isset($_POST['facilityId']) && trim((string) $_POST['facilityId']) !== '') { |
52 | 52 | $facilityId = implode(',', $_POST['facilityId']); |
53 | 53 | $sWhere[] = " t.facility_id IN ($facilityId)"; |
54 | 54 | } |
55 | 55 |
|
56 | | - $whereSql = !empty($sWhere) ? (' WHERE ' . implode(' AND ', $sWhere)) : ''; |
| 56 | + $whereSql = $sWhere === [] ? ('') : ' WHERE ' . implode(' AND ', $sWhere); |
57 | 57 |
|
58 | 58 | // Add facility join if needed for geographic filters |
59 | 59 | $facilityJoin = ''; |
|
89 | 89 | $duplicatesWhere = []; |
90 | 90 |
|
91 | 91 | // Date range filter |
92 | | - if (isset($_POST['dateRange']) && trim((string) $_POST['dateRange']) != '') { |
| 92 | + if (isset($_POST['dateRange']) && trim((string) $_POST['dateRange']) !== '') { |
93 | 93 | [$start_date, $end_date] = DateUtility::convertDateRange($_POST['dateRange'] ?? '', includeTime: true); |
94 | 94 | $duplicatesWhere[] = " t1.request_created_datetime BETWEEN '$start_date' AND '$end_date' "; |
95 | 95 | } |
96 | 96 |
|
97 | 97 | // Lab filter |
98 | | - if (isset($_POST['labName']) && trim((string) $_POST['labName']) != '') { |
| 98 | + if (isset($_POST['labName']) && trim((string) $_POST['labName']) !== '') { |
99 | 99 | $duplicatesWhere[] = " t1.lab_id IN (" . $_POST['labName'] . ")"; |
100 | 100 | } |
101 | 101 |
|
102 | 102 | // Facility filter |
103 | | - if (isset($_POST['facilityId']) && trim((string) $_POST['facilityId']) != '') { |
| 103 | + if (isset($_POST['facilityId']) && trim((string) $_POST['facilityId']) !== '') { |
104 | 104 | $facilityId = implode(',', $_POST['facilityId']); |
105 | 105 | $duplicatesWhere[] = " t1.facility_id IN ($facilityId)"; |
106 | 106 | } |
|
110 | 110 | if (isset($_POST['state']) || isset($_POST['district'])) { |
111 | 111 | $duplicatesFacilityJoin = ' LEFT JOIN facility_details as f1 ON t1.facility_id = f1.facility_id '; |
112 | 112 |
|
113 | | - if (isset($_POST['state']) && trim((string) $_POST['state']) != '') { |
| 113 | + if (isset($_POST['state']) && trim((string) $_POST['state']) !== '') { |
114 | 114 | $provinceId = implode(',', $_POST['state']); |
115 | 115 | $duplicatesWhere[] = " f1.facility_state_id IN ($provinceId)"; |
116 | 116 | } |
117 | 117 |
|
118 | | - if (isset($_POST['district']) && trim((string) $_POST['district']) != '') { |
| 118 | + if (isset($_POST['district']) && trim((string) $_POST['district']) !== '') { |
119 | 119 | $districtId = implode(',', $_POST['district']); |
120 | 120 | $duplicatesWhere[] = " f1.facility_district_id IN ($districtId)"; |
121 | 121 | } |
|
130 | 130 | $duplicatesWhere[] = " (t1.$patientFirstNameColumn IS NOT NULL OR t1.$patientIdColumn IS NOT NULL) "; |
131 | 131 | $duplicatesWhere[] = " t1.sample_collection_date IS NOT NULL "; |
132 | 132 |
|
133 | | - $duplicatesWhereSql = !empty($duplicatesWhere) ? (' WHERE ' . implode(' AND ', $duplicatesWhere)) : ''; |
| 133 | + $duplicatesWhereSql = $duplicatesWhere === [] ? ('') : ' WHERE ' . implode(' AND ', $duplicatesWhere); |
134 | 134 |
|
135 | 135 | $duplicatesQuery = " |
136 | 136 | SELECT COUNT(*) as duplicateSuspects |
|
0 commit comments