Skip to content

Commit 4efac8c

Browse files
committed
Minor changes in FacilitiesService
1 parent e09ee9d commit 4efac8c

File tree

4 files changed

+37
-102
lines changed

4 files changed

+37
-102
lines changed

app/classes/Services/FacilitiesService.php

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -186,57 +186,53 @@ public function getTestingLabFacilityMap($labId)
186186
// $onlyActive = true/false
187187
public function getHealthFacilities($testType = null, $byPassFacilityMap = false, $allColumns = false, $condition = [], $onlyActive = true, $userId = null)
188188
{
189-
190-
return MemoUtility::remember(function () use ($testType, $byPassFacilityMap, $allColumns, $condition, $onlyActive, $userId): string|array|null|int|float|false {
191-
$userId ??= null;
192-
if (isset($_SESSION['userId']) && $userId === null) {
193-
$userId ??= $_SESSION['userId'];
194-
}
195-
if (!$byPassFacilityMap && !empty($userId)) {
196-
$facilityMap = $this->getUserFacilityMap($userId);
197-
if (!empty($facilityMap)) {
198-
$this->db->where("`facility_id` IN ($facilityMap)");
199-
}
189+
$userId ??= null;
190+
if (isset($_SESSION['userId']) && $userId === null) {
191+
$userId ??= $_SESSION['userId'];
192+
}
193+
if (!$byPassFacilityMap && !empty($userId)) {
194+
$facilityMap = $this->getUserFacilityMap($userId);
195+
if (!empty($facilityMap)) {
196+
$this->db->where("`facility_id` IN ($facilityMap)");
200197
}
198+
}
201199

202-
if (!empty($testType)) {
203-
// subquery
204-
$healthFacilities = $this->db->subQuery();
205-
// we want to fetch facilities that have test type is not specified as well as this specific test type
206-
$healthFacilities->where("test_type is null or test_type like '$testType'");
207-
$healthFacilities->get("health_facilities", null, "facility_id");
200+
if (!empty($testType)) {
201+
// subquery
202+
$healthFacilities = $this->db->subQuery();
203+
// we want to fetch facilities that have test type is not specified as well as this specific test type
204+
$healthFacilities->where("test_type is null or test_type like '$testType'");
205+
$healthFacilities->get("health_facilities", null, "facility_id");
208206

209-
$this->db->where("facility_id", $healthFacilities, 'IN');
210-
}
207+
$this->db->where("facility_id", $healthFacilities, 'IN');
208+
}
211209

212-
if ($onlyActive) {
213-
$this->db->where('status', 'active');
214-
}
210+
if ($onlyActive) {
211+
$this->db->where('status', 'active');
212+
}
215213

216-
if (!empty($condition)) {
217-
$condition = is_array($condition) ? $condition : [$condition];
218-
foreach ($condition as $cond) {
219-
$this->db->where($cond);
220-
}
214+
if (!empty($condition)) {
215+
$condition = is_array($condition) ? $condition : [$condition];
216+
foreach ($condition as $cond) {
217+
$this->db->where($cond);
221218
}
219+
}
222220

221+
$this->db->orderBy("facility_name", "asc");
223222

224-
$this->db->orderBy("facility_name", "asc");
225-
226-
if ($allColumns) {
227-
return $this->db->get("facility_details");
228-
} else {
223+
if ($allColumns) {
224+
return $this->db->get("facility_details");
225+
} else {
229226

230-
$response = [];
227+
$response = [];
231228

232-
$results = $this->db->get("facility_details", null, "facility_id,facility_name");
229+
$results = $this->db->get("facility_details", null, "facility_id,facility_name");
233230

234-
foreach ($results as $row) {
235-
$response[$row['facility_id']] = $row['facility_name'];
236-
}
237-
return $response;
231+
foreach ($results as $row) {
232+
$response[$row['facility_id']] = $row['facility_name'];
238233
}
239-
}, 300);
234+
return $response;
235+
}
240236
}
241237

242238

bin/db-tools.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
use App\Services\DatabaseService;
3535
use App\Exceptions\SystemException;
3636
use App\Services\SystemService;
37-
use Ifsnop\Mysqldump as IMysqldump;
3837
use App\Registries\ContainerRegistry;
3938
use Symfony\Component\Console\Output\ConsoleOutput;
4039
use Symfony\Component\Console\Helper\ProgressBar;
@@ -50,7 +49,7 @@
5049
// Database dumps routinely exceed the default 25MB safety limit; lift it for this CLI.
5150
ArchiveUtility::setMaxFileSize(null);
5251

53-
$backupFolder = APPLICATION_PATH . '/../backups/db';
52+
$backupFolder = BACKUP_PATH . DIRECTORY_SEPARATOR . 'db';
5453
if (!is_dir($backupFolder)) {
5554
MiscUtility::makeDirectory($backupFolder);
5655
}

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"guzzlehttp/guzzle": "^7.10",
3636
"hackzilla/password-generator": "^1.7",
3737
"halaxa/json-machine": "^1.2",
38-
"ifsnop/mysqldump-php": "^2.12",
3938
"league/csv": "^9.27",
4039
"maennchen/zipstream-php": "^3.1",
4140
"monolog/monolog": "^3.9",

composer.lock

Lines changed: 1 addition & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)