clqms-be/app/Database/Seeds/AreaGeoSeeder.php

112 lines
3.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
feat(routes): add container alias endpoint for ContainerDefController Added an alternative route alias 'container' that points to ContainerDefController, providing backward compatibility and flexibility in API endpoint naming. - Routes '/api/specimen/container' to ContainerDefController methods - Supports GET, GET with ID, POST, and PATCH operations - Existing '/api/specimen/containerdef' routes remain unchanged File: app/Config/Routes.php (+7 lines) --- refactor(seeds): update and standardize seed data across multiple seeders Improved data consistency and coverage in database seeds: AreaGeoSeeder.php: - Updated geographic area data for better regional coverage - Standardized data format and field values DummySeeder.php: - Refactored dummy data generation for test environments - Improved data integrity and relationships PatientSeeder.php: - Enhanced patient test data with more realistic scenarios - Updated patient demographic information - Improved test result distributions Total: 111 lines changed across seed files --- docs: add CLQMS project documentation - Added project documentation file: "prj_clinical laboratory quality management system_3a.docx" - Comprehensive project specification and requirements document --- test: remove deprecated TestDefSiteTest.php - Removed obsolete test file that is no longer needed - Test coverage consolidated into other test classes File: tests/feature/TestDef/TestDefSiteTest.php (-374 lines) --- Summary: - +58 lines added (routes, seeds, docs) - -434 lines removed (deprecated test file) - 6 files affected
2026-01-07 16:55:25 +07:00
use CodeIgniter\HTTP\CURLRequest;
use Config\Services;
class AreaGeoSeeder extends Seeder
{
/**
* API configuration for fetching zones data
*/
protected string $apiUrl = 'https://services-summit.my.id/api/zones'; //DEV
//protected string $apiUrl = 'http://services-summit.my.id/api/zones'; //PROD
// public function run()
// {
// // Fetch data from external API
// $options = [
// 'baseURI' => $this->apiUrl,
// 'timeout' => 30,
// ];
// // $client = new CURLRequest($options);
// $client = Services::curlrequest([
// 'baseURI' => $this->apiUrl,
// 'timeout' => 30,
// ]);
// $response = $client->get('');
// if ($response->getStatusCode() !== 200) {
// echo "Failed to fetch data from API. Status: " . $response->getStatusCode() . "\n";
// return;
// }
// $externalData = $response->getJSON(true);
// if (empty($externalData)) {
// echo "No data found from API.\n";
// return;
// }
// // Prepare data for insertion (exclude AreaGeoID to allow auto-increment)
// $data = [];
// foreach ($externalData as $row) {
// $data[] = [
// 'AreaCode' => $row['zonecode'] ?? null,
// 'Class' => $row['zoneclass'] ?? null,
// 'AreaName' => str_replace('_', ' ', $row['zonename'] ?? ''),
// 'Parent' => $row['parentzoneid'] ?? null,
// ];
// }
// // Insert into local database
// $this->db->table('areageo')->insertBatch($data);
// echo "Successfully seeded " . count($data) . " area geo records.\n";
// }
public function run()
{
$client = Services::curlrequest([
'baseURI' => $this->apiUrl,
'timeout' => 30,
]);
$response = $client->get('');
if ($response->getStatusCode() !== 200) {
echo "HTTP Error: {$response->getStatusCode()}" . PHP_EOL;
return;
}
$payload = json_decode($response->getBody(), true);
if (json_last_error() !== JSON_ERROR_NONE) {
echo "Invalid JSON response: " . json_last_error_msg() . PHP_EOL;
return;
}
if (
!isset($payload['status'], $payload['data']) ||
$payload['status'] !== 'success'
) {
echo "Unexpected API structure." . PHP_EOL;
return;
}
$zones = $payload['data'];
if (empty($zones)) {
echo "No zone data found." . PHP_EOL;
return;
}
$data = [];
foreach ($zones as $row) {
$data[] = [
'AreaCode' => $row['zonecode'] ?? null,
'Class' => $row['zoneclass'] ?? null,
'AreaName' => str_replace('_', ' ', $row['zonename'] ?? ''),
'Parent' => $row['parentzoneid'],
];
}
$this->db->table('areageo')->insertBatch($data);
echo "Seeded " . count($data) . " records." . PHP_EOL;
}
}