Uploaded From CV. Swandhana Server

This commit is contained in:
Duidev Software House
2025-01-27 08:16:55 +07:00
commit 6b3be42361
15186 changed files with 2328862 additions and 0 deletions
@@ -0,0 +1,34 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Services\AstmMessageService;
use App\DataListiner;
class ProcessAstmMessages extends Command
{
protected $signature = 'astm:process-messages';
protected $description = 'Process pending ASTM messages';
private $astmMessageService;
public function __construct(AstmMessageService $astmMessageService)
{
parent::__construct();
$this->astmMessageService = $astmMessageService;
}
public function handle()
{
// Ambil data dari DataListener
$dataListener = DataListiner::whereNull('processed')->get();
if ($dataListener) {
$jumlah = count($dataListener);
$pesan = $this->astmMessageService->processAstmMessages($dataListener);
$this->info($jumlah.' Message processed '.$pesan.' at '.date('Y-m-d H:i:s'));
} else {
$this->info('Skipped Proses at '.date('Y-m-d H:i:s'));
}
}
}
+61
View File
@@ -0,0 +1,61 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use GuzzleHttp\Client;
use App\Models\TestResult;
use App\Pasien;
class SyncLabResults extends Command
{
// Nama dan deskripsi command
protected $signature = 'lab:sync-results';
protected $description = 'Sync lab results from external instruments';
public function __construct()
{
parent::__construct();
}
public function handle()
{
// Instance Guzzle client
$client = new Client();
// URL endpoint API dari alat (ganti dengan URL alat kamu)
$url = 'https://api.examplelab.com/results';
// Contoh request ke API alat untuk mengambil hasil tes
try {
$response = $client->request('GET', $url, [
'headers' => [
'Authorization' => 'Bearer your_api_token', // Jika alat memerlukan token API
'Accept' => 'application/json'
]
]);
// Parsing data JSON yang diterima dari API
$data = json_decode($response->getBody()->getContents(), true);
// Menyimpan hasil tes ke database
foreach ($data as $result) {
// Mencari pasien berdasarkan ID
$patient = Pasien::find($result['patient_id']);
if ($patient) {
TestResult::create([
'patient_id' => $patient->id,
'test_id' => $result['test_id'],
'result_value' => $result['result_value'],
'result_status' => $result['status'],
'timestamp' => $result['timestamp']
]);
}
}
$this->info('Lab results synchronized successfully.');
} catch (\Exception $e) {
$this->error('Error syncing lab results: ' . $e->getMessage());
}
}
}
@@ -0,0 +1,62 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class SyncLabResultsFTP extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:sync-lab-results-f-t-p';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle()
{
// Mengakses file di FTP server
$ftpDisk = Storage::disk('ftp'); // Pastikan konfigurasi FTP ada di config/filesystems.php
// Mendapatkan daftar file di FTP server
$files = $ftpDisk->files('results'); // Misalnya folder 'results'
foreach ($files as $file) {
// Mengambil file dari FTP dan membaca isinya
$fileContents = $ftpDisk->get($file);
// Proses konten file (misalnya parsing CSV atau XML)
$this->processFileContents($fileContents);
}
$this->info('Lab results synchronized from FTP.');
}
protected function processFileContents($contents)
{
// Misalnya, jika konten dalam format CSV
$rows = str_getcsv($contents, "\n");
foreach ($rows as $row) {
$data = str_getcsv($row);
// Menyimpan hasil tes ke database
TestResult::create([
'patient_id' => $data[0], // Misal, data pasien ada di kolom pertama
'test_id' => $data[1], // Misal, data tes ada di kolom kedua
'result_value' => $data[2],// Nilai hasil tes ada di kolom ketiga
'timestamp' => now(),
]);
}
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class SyncLabResultsSerial extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:sync-lab-results-serial';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle()
{
$host = '192.168.1.100'; // IP alat
$port = 4000; // Port alat
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, $host, $port);
$response = socket_read($socket, 1024);
// Proses response dari alat
$this->processSocketData($response);
socket_close($socket);
}
protected function processSocketData($data)
{
// Proses data yang diterima (misalnya parsing atau format hasil tes)
$testResult = json_decode($data, true);
// Simpan hasil tes ke database
TestResult::create([
'patient_id' => $testResult['patient_id'],
'test_id' => $testResult['test_id'],
'result_value' => $testResult['result_value'],
'timestamp' => $testResult['timestamp']
]);
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
//$schedule->command('lab:sync-results')->everyThirtyMinutes();
//$schedule->command('app:sync-lab-results-f-t-p')->everyThirtyMinutes();
//$schedule->command('app:sync-lab-results-serial')->everyThirtyMinutes();
$schedule->command('astm:process-messages')->everyFiveMinutes();
}
/**
* Register the commands for the application.
*/
protected function commands(): void
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}