update
This commit is contained in:
@@ -115,6 +115,7 @@ class AstmMessageService
|
|||||||
return "H|{$senderName}|{$versionNumber}|{$messageDateTime}";
|
return "H|{$senderName}|{$versionNumber}|{$messageDateTime}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Fungsi untuk membuat Patient Record (P)
|
// Fungsi untuk membuat Patient Record (P)
|
||||||
public function createPatientRecord($patient)
|
public function createPatientRecord($patient)
|
||||||
{
|
{
|
||||||
@@ -636,6 +637,146 @@ class AstmMessageService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected function astmToDateTime(?string $value): ?string
|
||||||
|
{
|
||||||
|
if (!$value) return null;
|
||||||
|
|
||||||
|
if (preg_match('/(\d{14})/', $value, $m)) {
|
||||||
|
return Carbon::createFromFormat(
|
||||||
|
'YmdHis',
|
||||||
|
$m[1]
|
||||||
|
)->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processBDAstmResponse(string $raw, $data): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// =========================
|
||||||
|
// PREPARE
|
||||||
|
// =========================
|
||||||
|
$accnumber= '';
|
||||||
|
$resultDateTime = null;
|
||||||
|
$rawClean = preg_replace('/[\x02\x03\x04]/', '', $raw);
|
||||||
|
$lines = preg_split("/\r\n|\n|\r/", $rawClean);
|
||||||
|
|
||||||
|
$parsed = [
|
||||||
|
'header' => [],
|
||||||
|
'patient'=> [],
|
||||||
|
'order' => [],
|
||||||
|
'result' => [],
|
||||||
|
'instrument' => []
|
||||||
|
];
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// PARSE LOOP
|
||||||
|
// =========================
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
|
||||||
|
if (str_starts_with($line, 'H|')) {
|
||||||
|
$f = explode('|', $line);
|
||||||
|
$parsed['header'] = [
|
||||||
|
'sender_name' => $data->alat,
|
||||||
|
'version_number' => $f[12] ?? 'V1.0',
|
||||||
|
'message_datetime' => $this->astmToDateTime($f[13] ?? null)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif (str_starts_with($line, 'P|')) {
|
||||||
|
$f = explode('|', $line);
|
||||||
|
$name = explode(' ', $f[5] ?? '');
|
||||||
|
|
||||||
|
$parsed['patient'] = [
|
||||||
|
'patient_id' => $f[3] ?? null,
|
||||||
|
'patient_name_last' => $name[0] ?? null,
|
||||||
|
'patient_name_first'=> $name[1] ?? null,
|
||||||
|
'patient_dob' => $this->astmToDateTime($f[7] ?? null),
|
||||||
|
'patient_sex' => $f[8] ?? null,
|
||||||
|
'patient_phone' => $f[13] ?? null,
|
||||||
|
'address_street' => $f[11] ?? null,
|
||||||
|
'hospital_client' => $f[29] ?? null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif (str_starts_with($line, 'O|')) {
|
||||||
|
$f = explode('|', $line);
|
||||||
|
$test = explode('^', $f[4] ?? '');
|
||||||
|
$accnumber = $f[2] ?? null;
|
||||||
|
$parsed['order'] = [
|
||||||
|
'accession_number' => $f[2] ?? null,
|
||||||
|
'test_id' => $test[3] ?? null,
|
||||||
|
'specimen_type' => $f[15] ?? null,
|
||||||
|
'body_site' => $f[16] ?? null,
|
||||||
|
'test_start_datetime'=> $this->astmToDateTime($f[7] ?? null),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif (str_starts_with($line, 'R|')) {
|
||||||
|
$f = explode('|', $line);
|
||||||
|
$test = explode('^', $f[2] ?? '');
|
||||||
|
$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' => $this->astmToDateTime($f[11] ?? null),
|
||||||
|
];
|
||||||
|
|
||||||
|
$parsed['instrument'] = [
|
||||||
|
'instrument_type' => str_contains($line, 'MGIT960') ? 'MGIT960' : 'BACTECFX',
|
||||||
|
'instrument_number' => $inst[0] ?? null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// SAVE TO DATABASE
|
||||||
|
// =========================
|
||||||
|
$resultSample = new ResultSample();
|
||||||
|
$resultSample->fill(array_merge(
|
||||||
|
$parsed['header'],
|
||||||
|
$parsed['patient'],
|
||||||
|
$parsed['order'],
|
||||||
|
$parsed['result'],
|
||||||
|
$parsed['instrument']
|
||||||
|
));
|
||||||
|
|
||||||
|
$resultSample->additional_result = [
|
||||||
|
'raw_astm' => $raw,
|
||||||
|
'source' => 'BD'
|
||||||
|
];
|
||||||
|
|
||||||
|
$resultSample->save();
|
||||||
|
if ($accnumber != '' AND isset($resultDateTime)){
|
||||||
|
KomponenJawaban::updateOrCreate(
|
||||||
|
[
|
||||||
|
'accnumber' => $accnumber,
|
||||||
|
'komponen' => 'bd_result_date',
|
||||||
|
'isidata' => $resultDateTime,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'template' => 'Kultur',
|
||||||
|
'created_by' => 'BD'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('BD ASTM parse error', [
|
||||||
|
'msg' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proses data ASTM Response
|
* Proses data ASTM Response
|
||||||
*/
|
*/
|
||||||
@@ -646,29 +787,13 @@ 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 != ''){
|
||||||
$rnmpas = $data->rnmpas;
|
$result = $this->processBDAstmResponse($response, $data->alat);
|
||||||
$getnama = explode('|', $rnmpas);
|
|
||||||
$resultSample = new ResultSample();
|
|
||||||
$resultSample->sender_name = $data->alat;
|
|
||||||
$resultSample->message_datetime = $data->tgl_data;
|
|
||||||
$resultSample->version_number = 'V1.0';
|
|
||||||
$resultSample->patient_id = $data->urut;
|
|
||||||
$resultSample->patient_name_last= $getnama[0];
|
|
||||||
$resultSample->accession_number = $data->no_id;
|
|
||||||
$resultSample->test_status = $data->organisme;
|
|
||||||
$resultSample->save();
|
|
||||||
DataListiner::where('urut', $data->urut)->update([
|
DataListiner::where('urut', $data->urut)->update([
|
||||||
'processed' => 1
|
'processed' => $result ? 1 : 9
|
||||||
]);
|
]);
|
||||||
Periksa::where('nofoto', $data->no_id)->whereNotIn('status', ['Selesai', 'Arsip', 'Dibatalkan (Arsip)', 'Batal'])->update([
|
Periksa::where('nofoto', $data->no_id)->whereNotIn('status', ['Selesai', 'Arsip', 'Dibatalkan (Arsip)', 'Batal'])->update([
|
||||||
'status' => 'Data BD di Terima ('.$data->organisme.')',
|
'status' => 'Data BD di Terima ('.$data->organisme.')',
|
||||||
]);
|
]);
|
||||||
Log::info("Data ASTM BD ", $resultSample->toArray());
|
|
||||||
PendaftaranOnListiner::where('rnoreg', $data->no_id)->update([
|
|
||||||
'rtglast' => date('Y-m-d'),
|
|
||||||
'flg_vitek1' => 0,
|
|
||||||
'flg_vitek2' => 0
|
|
||||||
]);
|
|
||||||
KomponenJawaban::updateOrCreate(
|
KomponenJawaban::updateOrCreate(
|
||||||
[
|
[
|
||||||
'accnumber' => $data->no_id,
|
'accnumber' => $data->no_id,
|
||||||
@@ -680,17 +805,7 @@ class AstmMessageService
|
|||||||
'created_by' => 'BD'
|
'created_by' => 'BD'
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
KomponenJawaban::updateOrCreate(
|
|
||||||
[
|
|
||||||
'accnumber' => $data->no_id,
|
|
||||||
'komponen' => 'bd_result_date',
|
|
||||||
'isidata' => $data->tgl_data,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'template' => 'Kultur',
|
|
||||||
'created_by' => 'BD'
|
|
||||||
]
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
DataListiner::where('urut', $data->urut)->update([
|
DataListiner::where('urut', $data->urut)->update([
|
||||||
'processed' => 9
|
'processed' => 9
|
||||||
|
|||||||
Reference in New Issue
Block a user