push
This commit is contained in:
@@ -657,32 +657,17 @@ class AstmMessageService
|
|||||||
|
|
||||||
$lines = preg_split("/\r\n|\n|\r/", $clean);
|
$lines = preg_split("/\r\n|\n|\r/", $clean);
|
||||||
|
|
||||||
$messages = [];
|
$final = [];
|
||||||
$current = [];
|
|
||||||
|
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
|
if (!preg_match('/^[A-Z]\|/', $line)) {
|
||||||
// Ketemu H baru → simpan pesan sebelumnya
|
$final[count($final)-1] .= $line;
|
||||||
if (str_starts_with($line, 'H|') && !empty($current)) {
|
} else {
|
||||||
$messages[] = implode("\n", $current);
|
$final[] = $line;
|
||||||
$current = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$current[] = $line;
|
|
||||||
|
|
||||||
// Akhir pesan
|
|
||||||
if (str_starts_with($line, 'L|')) {
|
|
||||||
$messages[] = implode("\n", $current);
|
|
||||||
$current = [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$lines = $final;
|
||||||
|
|
||||||
// sisa buffer
|
return $lines;
|
||||||
if (!empty($current)) {
|
|
||||||
$messages[] = implode("\n", $current);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $messages;
|
|
||||||
}
|
}
|
||||||
protected function reassembleAstmFrames(string $raw): string
|
protected function reassembleAstmFrames(string $raw): string
|
||||||
{
|
{
|
||||||
@@ -699,8 +684,6 @@ class AstmMessageService
|
|||||||
|
|
||||||
return trim($buffer);
|
return trim($buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function processBDAstmResponse(string $raw, $data): bool
|
protected function processBDAstmResponse(string $raw, $data): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -766,15 +749,17 @@ 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[11] ?? null);
|
$resultDateTime = $this->astmToDateTime($f[9] ?? 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' => $this->astmToDateTime($f[11] ?? null),
|
'result_status_datetime' => $resultDateTime,
|
||||||
|
'updated_datetime' => $updated_date
|
||||||
];
|
];
|
||||||
|
|
||||||
$parsed['instrument'] = [
|
$parsed['instrument'] = [
|
||||||
@@ -827,7 +812,43 @@ class AstmMessageService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function processAstmMessagesLokal($dataListener) {
|
||||||
|
foreach ($dataListener as $data) {
|
||||||
|
try {
|
||||||
|
$response = $data->rawdt;
|
||||||
|
if ($data->no_id != ''){
|
||||||
|
$messages = $this->splitBDAstmMessages($data->rawdt);
|
||||||
|
foreach ($messages as $msg) {
|
||||||
|
$assembled = $this->reassembleAstmFrames($msg);
|
||||||
|
$ok = $this->processBDAstmResponse($assembled, $data);
|
||||||
|
}
|
||||||
|
DB::table('lis_phoenix')->where('id', $data->id)->update([
|
||||||
|
'processed' => $ok ? 1 : 9
|
||||||
|
]);
|
||||||
|
Periksa::where('nofoto', $data->no_id)->whereNotIn('status', ['Selesai', 'Arsip', 'Dibatalkan (Arsip)', 'Batal'])->update([
|
||||||
|
'status' => 'Data BD di Terima ('.$data->organisme.')',
|
||||||
|
]);
|
||||||
|
KomponenJawaban::updateOrCreate(
|
||||||
|
[
|
||||||
|
'accnumber' => $data->no_id,
|
||||||
|
'komponen' => 'bd_result',
|
||||||
|
'isidata' => $data->organisme,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'template' => 'Kultur',
|
||||||
|
'created_by' => 'BD'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
DB::table('lis_phoenix')->where('id', $data->id)->update([
|
||||||
|
'processed' => 9
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::critical($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Proses data ASTM Response
|
* Proses data ASTM Response
|
||||||
*/
|
*/
|
||||||
@@ -838,10 +859,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 != ''){
|
||||||
$assembled = $this->reassembleAstmFrames($data->rawdt);
|
$messages = $this->splitBDAstmMessages($data->rawdt);
|
||||||
$messages = $this->splitBDAstmMessages($assembled);
|
|
||||||
foreach ($messages as $msg) {
|
foreach ($messages as $msg) {
|
||||||
$ok = $this->processBDAstmResponse($msg, $data);
|
$assembled = $this->reassembleAstmFrames($msg);
|
||||||
|
$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
|
||||||
@@ -883,43 +904,5 @@ 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 != ''){
|
|
||||||
$assembled = $this->reassembleAstmFrames($data->rawdt);
|
|
||||||
$messages = $this->splitBDAstmMessages($assembled);
|
|
||||||
foreach ($messages as $msg) {
|
|
||||||
$ok = $this->processBDAstmResponse($msg, $data);
|
|
||||||
}
|
|
||||||
DB::table('lis_phoenix')->where('id', $data->id)->update([
|
|
||||||
'processed' => $ok ? 1 : 9
|
|
||||||
]);
|
|
||||||
Periksa::where('nofoto', $data->no_id)->whereNotIn('status', ['Selesai', 'Arsip', 'Dibatalkan (Arsip)', 'Batal'])->update([
|
|
||||||
'status' => 'Data BD di Terima ('.$data->organisme.')',
|
|
||||||
]);
|
|
||||||
KomponenJawaban::updateOrCreate(
|
|
||||||
[
|
|
||||||
'accnumber' => $data->no_id,
|
|
||||||
'komponen' => 'bd_result',
|
|
||||||
'isidata' => $data->organisme,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'template' => 'Kultur',
|
|
||||||
'created_by' => 'BD'
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
DB::table('lis_phoenix')->where('id', $data->id)->update([
|
|
||||||
'processed' => 9
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::critical($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user