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