diff --git a/htdocs/app/Services/AstmMessageService.php b/htdocs/app/Services/AstmMessageService.php index 244a0644..1b3c1696 100644 --- a/htdocs/app/Services/AstmMessageService.php +++ b/htdocs/app/Services/AstmMessageService.php @@ -302,91 +302,93 @@ class AstmMessageService $resultSample = new ResultSample(); foreach ($mltrData as $index => $field) { - if ($field == 'ra'){ - if ($antibiotic != ''){ - $parsedData['antibiotics'][] = [ - 'antibiotic' => $antibiotic, // Antibiotik - 'resistance' => $resistance, // Hasil Resistansi - 'value' => $value, // Nilai - 'interpretation'=> $interpretation // Interpretasi - ]; - $antibiotic = ''; - $resistance = ''; - $value = ''; - $interpretation = ''; - } else { - $mulaikirim = 1; + $cekbersih = trim($field, '"'); + if (strpos($cekbersih, 'a1') === 0) { + // Kode dari alat + } + if (strpos($cekbersih, 'a2') === 0) { + $antibiotic = substr($field, 2); // Nama antibiotik + $mulaikirim++; + } + if (strpos($cekbersih, 'a3') === 0) { + $value = substr($field, 2); // Nilai MIC + $mulaikirim++; + } + if (strpos($cekbersih, 'a4') === 0) { + $interpretation = substr($field, 2); // S, I, atau R + $mulaikirim++; + } + if (strpos($cekbersih, 'an') === 0) { + $resistance = substr($field, 2); // Catatan resistansi + $mulaikirim++; + } + if (strpos($cekbersih, 'mt') === 0) { + $resultSample->sender_name = substr($cekbersih, 2); + } + if (strpos($cekbersih, 'ii') === 0) { + $resultSample->version_number = substr($cekbersih, 2); + } + if (strpos($cekbersih, 'rr') === 0) { + $resultSample->isolate_number = substr($cekbersih, 2); + } + if (strpos($cekbersih, 'ci') === 0) { + $accession_number = substr($cekbersih, 2); + $resultSample->accession_number = $accession_number; + } + if (strpos($cekbersih, 'pi') === 0) { + $resultSample->patient_id = substr($cekbersih, 2); + } + if (strpos($cekbersih, 'pn') === 0) { + $patientNames = substr($cekbersih, 2); + $patientNames = explode(',', $patientNames ?? null); + if (count($patientNames) > 0) { + $resultSample->patient_name_first = trim($patientNames[0]); } + if (count($patientNames) > 1) { + $resultSample->patient_name_last = trim($patientNames[1]); + } + if (count($patientNames) > 2) { + $resultSample->patient_name_middle = trim($patientNames[2]); + } + } + + if (strpos($cekbersih, 'pl') === 0) { + $resultSample->hospital_service = substr($cekbersih, 2); + } + if (strpos($cekbersih, 'p2') === 0) { + $resultSample->hospital_client = substr($cekbersih, 2); + } + if (strpos($cekbersih, 'ss') === 0) { + $resultSample->specimen_type = substr($cekbersih, 2); + } + if (strpos($cekbersih, 'o2') === 0) { + $resultSample->organism = substr($cekbersih, 2); + } + if (strpos($cekbersih, 's1') === 0) { + $tanggalmasuk = substr($cekbersih, 2); + } + if (strpos($cekbersih, 's2') === 0) { + $tanggalmasuk = $tanggalmasuk.' '.substr($cekbersih, 2); + } + if (strpos($cekbersih, 's3') === 0) { + $tanggalkeluar = substr($cekbersih, 2); + } + if (strpos($cekbersih, 's4') === 0) { + $tanggalkeluar = $tanggalkeluar.' '.substr($cekbersih, 2); + } + if ($antibiotic != ''){ + $parsedData['antibiotics'][] = [ + 'antibiotic' => $antibiotic, // Antibiotik + 'resistance' => $resistance, // Hasil Resistansi + 'value' => $value, // Nilai + 'interpretation'=> $interpretation // Interpretasi + ]; + $antibiotic = ''; + $resistance = ''; + $value = ''; + $interpretation = ''; } else { - if ($mulaikirim == 1){ - $antibiotic = substr($field, 2); - $mulaikirim++; - } else if ($mulaikirim == 2){ - $resistance = substr($field, 2); - $mulaikirim++; - } else if ($mulaikirim == 3){ - $value = substr($field, 2); - $mulaikirim++; - } else if ($mulaikirim == 4){ - $interpretation = substr($field, 2); - $mulaikirim++; - } else { - $cekbersih = trim($field, '"'); - if (strpos($cekbersih, 'mt') === 0) { - $resultSample->sender_name = substr($cekbersih, 2); - } - if (strpos($cekbersih, 'ii') === 0) { - $resultSample->version_number = substr($cekbersih, 2); - } - if (strpos($cekbersih, 'rr') === 0) { - $resultSample->isolate_number = substr($cekbersih, 2); - } - if (strpos($cekbersih, 'ci') === 0) { - $accession_number = substr($cekbersih, 2); - $resultSample->accession_number = $accession_number; - } - if (strpos($cekbersih, 'pi') === 0) { - $resultSample->patient_id = substr($cekbersih, 2); - } - if (strpos($cekbersih, 'pn') === 0) { - $patientNames = substr($cekbersih, 2); - $patientNames = explode(',', $patientNames ?? null); - if (count($patientNames) > 0) { - $resultSample->patient_name_first = trim($patientNames[0]); - } - if (count($patientNames) > 1) { - $resultSample->patient_name_last = trim($patientNames[1]); - } - if (count($patientNames) > 2) { - $resultSample->patient_name_middle = trim($patientNames[2]); - } - } - - if (strpos($cekbersih, 'pl') === 0) { - $resultSample->hospital_service = substr($cekbersih, 2); - } - if (strpos($cekbersih, 'p2') === 0) { - $resultSample->hospital_client = substr($cekbersih, 2); - } - if (strpos($cekbersih, 'ss') === 0) { - $resultSample->specimen_type = substr($cekbersih, 2); - } - if (strpos($cekbersih, 'o2') === 0) { - $resultSample->organism = substr($cekbersih, 2); - } - if (strpos($cekbersih, 's1') === 0) { - $tanggalmasuk = substr($cekbersih, 2); - } - if (strpos($cekbersih, 's2') === 0) { - $tanggalmasuk = $tanggalmasuk.' '.substr($cekbersih, 2); - } - if (strpos($cekbersih, 's3') === 0) { - $tanggalkeluar = substr($cekbersih, 2); - } - if (strpos($cekbersih, 's4') === 0) { - $tanggalkeluar = $tanggalkeluar.' '.substr($cekbersih, 2); - } - } + $mulaikirim = 1; } }