This commit is contained in:
Dwi Swandhana
2026-01-30 09:44:33 +07:00
parent ae32330ed7
commit b0586dac0a
+33 -23
View File
@@ -657,21 +657,32 @@ class AstmMessageService
$lines = preg_split("/\r\n|\n|\r/", $clean);
$final = [];
$messages = [];
$current = [];
foreach ($lines as $line) {
if (!preg_match('/^[A-Z]\|/', $line)) {
if (empty($final)) {
$final[] = $line;
continue;
}
$final[count($final)-1] .= $line;
} else {
$final[] = $line;
// Ketemu H baru → simpan pesan sebelumnya
if (str_starts_with($line, 'H|') && !empty($current)) {
$messages[] = implode("\n", $current);
$current = [];
}
$current[] = $line;
// Akhir pesan
if (str_starts_with($line, 'L|')) {
$messages[] = implode("\n", $current);
$current = [];
}
}
$lines = $final;
return $lines;
// sisa buffer
if (!empty($current)) {
$messages[] = implode("\n", $current);
}
return $messages;
}
protected function reassembleAstmFrames(string $raw): string
{
@@ -753,17 +764,15 @@ class AstmMessageService
elseif (str_starts_with($line, 'R|')) {
$f = explode('|', $line);
$test = explode('^', $f[2] ?? '');
$resultDateTime = $this->astmToDateTime($f[9] ?? null);
$updated_date = $this->parseUpdatedDate($f[10] ?? null);
$resultDateTime = $this->astmToDateTime($f[11] ?? null);
// Instrument detail di akhir baris
preg_match('/(MGIT960|BACTECFX)[^|]*/', $line, $inst);
$parsed['result'] = [
'organism' => $test[2] ?? null,
'test_status' => explode('^', $f[3] ?? '')[0],
'result_status_datetime' => $resultDateTime,
'updated_datetime' => $updated_date
'organism' => $test[2] ?? null,
'test_status' => explode('^', $f[3] ?? '')[0],
'result_status_datetime' => $this->astmToDateTime($f[11] ?? null),
];
$parsed['instrument'] = [
@@ -819,12 +828,13 @@ class AstmMessageService
public function processAstmMessagesLokal($dataListener) {
foreach ($dataListener as $data) {
try {
// Ambil pesan ASTM dari kolom 'message' atau yang relevan
$response = $data->rawdt;
if ($data->no_id != ''){
$messages = $this->splitBDAstmMessages($data->rawdt);
$assembled = $this->reassembleAstmFrames($data->rawdt);
$messages = $this->splitBDAstmMessages($assembled);
foreach ($messages as $msg) {
$assembled = $this->reassembleAstmFrames($msg);
$ok = $this->processBDAstmResponse($assembled, $data);
$ok = $this->processBDAstmResponse($msg, $data);
}
DB::table('lis_phoenix')->where('id', $data->id)->update([
'processed' => $ok ? 1 : 9
@@ -863,10 +873,10 @@ class AstmMessageService
$response = $data->rawdt;
if ($data->alat == 'BD Mikro 1'){
if ($data->no_id != ''){
$messages = $this->splitBDAstmMessages($data->rawdt);
$assembled = $this->reassembleAstmFrames($data->rawdt);
$messages = $this->splitBDAstmMessages($assembled);
foreach ($messages as $msg) {
$assembled = $this->reassembleAstmFrames($msg);
$ok = $this->processBDAstmResponse($assembled, $data);
$ok = $this->processBDAstmResponse($msg, $data);
}
DataListiner::where('urut', $data->urut)->update([
'processed' => $ok ? 1 : 9