From b0da4e543358908e0e5d3baf162547fd1fe708e4 Mon Sep 17 00:00:00 2001 From: Dwi Swandhana Date: Fri, 10 Apr 2026 18:11:25 +0700 Subject: [PATCH] update --- htdocs/app/Services/AstmMessageService.php | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/htdocs/app/Services/AstmMessageService.php b/htdocs/app/Services/AstmMessageService.php index 591606c9..d84189c5 100644 --- a/htdocs/app/Services/AstmMessageService.php +++ b/htdocs/app/Services/AstmMessageService.php @@ -14,6 +14,7 @@ use App\RekapAntibiotik; use App\PendaftaranOnListiner; use App\Organisms; use App\KomponenJawaban; +use App\Riwayat; // Proses untuk Growth and Detection Result function processGrowthDetectionResult($rawData){ @@ -869,6 +870,60 @@ class AstmMessageService return $messages; } + protected function formatLocalInstrumentText(array $parsed, string $alat, ?string $accessionNumber, ?string $messageDateTime): string + { + $msh = $parsed['MSH'][0] ?? []; + $pid = $parsed['PID'][0] ?? []; + $obr = $parsed['OBR'][0] ?? []; + $obx = $parsed['OBX'][0] ?? []; + $nte = $parsed['NTE'][0] ?? []; + $qpd = $parsed['QPD'][0] ?? []; + $qid = $parsed['QID'][0] ?? []; + $spm = $parsed['SPM'][0] ?? []; + + $messageType = $msh[8] ?? '-'; + $patientName = $pid[3] ?? $pid[5] ?? '-'; + $patientName = trim((string) $patientName, "\" \t\n\r\0\x0B"); + $testId = $obr[4] ?? ($qpd[1] ?? '-'); + $receivedAt = $messageDateTime ?? '-'; + + if (str_starts_with($alat, 'MYLA')) { + $organism = $obx[5] ?? '-'; + $status = $obx[11] ?? '-'; + $resultAt = $this->astmToDateTime($obx[14] ?? null) ?? '-'; + $comment = $nte[3] ?? '-'; + $specimen = $spm[3] ?? '-'; + + return trim(implode("\n", [ + 'HASIL ALAT MYLA', + 'No. Foto: '.($accessionNumber ?: '-'), + 'No. Spesimen: '.$specimen, + 'Pasien: '.$patientName, + 'Jenis Pesan: '.$messageType, + 'Test: '.$testId, + 'Hasil: '.$organism, + 'Status: '.$status, + 'Komentar: '.$comment, + 'Tanggal Hasil: '.$resultAt, + 'Tanggal Diterima LIS: '.$receivedAt, + ])); + } + + $orderAt = $this->astmToDateTime($parsed['ORC'][0][8] ?? null) ?? '-'; + $queryId = $qid[1] ?? ($msh[9] ?? '-'); + + return trim(implode("\n", [ + 'HASIL ALAT GENEXPERT', + 'No. Foto: '.($accessionNumber ?: '-'), + 'Pasien: '.$patientName, + 'Jenis Pesan: '.$messageType, + 'Test/Assay: '.$testId, + 'Order/Run ID: '.$queryId, + 'Tanggal Order: '.$orderAt, + 'Tanggal Diterima LIS: '.$receivedAt, + 'Catatan: Payload alat disimpan sebagai raw untuk ditinjau analis.', + ])); + } protected function saveInstrumentRawResult(string $raw, string $alat): bool { try { @@ -931,6 +986,18 @@ class AstmMessageService ]; $resultSample->save(); + if ($accessionNumber) { + $teksHasil = $this->formatLocalInstrumentText($parsed, $alat, $accessionNumber, $messageDateTime); + + Riwayat::create([ + 'nofoto' => $accessionNumber, + 'jawaban' => $teksHasil, + 'inputor' => $alat, + 'keterangan' => $messageDateTime ?: date('Y-m-d H:i:s'), + 'verifikasi' => '', + ]); + } + return true; } catch (\Throwable $e) { Log::error('Local instrument fallback parse error', [