update
This commit is contained in:
@@ -600,7 +600,6 @@ class AstmMessageService
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function processAstmMessagesgenExpert($response, $alat)
|
||||
{
|
||||
$normalizedData = str_replace(["\r\n", "\r"], "\n", $response);
|
||||
@@ -609,7 +608,7 @@ class AstmMessageService
|
||||
$patient_id = '';
|
||||
$patient_name = '';
|
||||
$accession_number = '';
|
||||
$waktu_periksa = date('d-m-Y H:i:s'); // Default jika tidak ada di ASTM
|
||||
$waktu_periksa = date('d-m-Y H:i:s');
|
||||
|
||||
$parsedResults = [];
|
||||
$hasil_list = [];
|
||||
@@ -631,7 +630,6 @@ class AstmMessageService
|
||||
// 2. Parsing Accession Number
|
||||
if ($recordType === 'O') {
|
||||
$accession_number = !empty($cekdata[2]) ? $cekdata[2] : $accession_number;
|
||||
// Jika ada waktu di record O (index 6), kita bisa format (opsional)
|
||||
if (!empty($cekdata[6])) {
|
||||
$rawTime = preg_replace('/[^0-9]/', '', $cekdata[6]);
|
||||
if (strlen($rawTime) >= 14) {
|
||||
@@ -640,30 +638,54 @@ class AstmMessageService
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Parsing Data Result, Ct, dan EndPt
|
||||
// 3. Parsing Data Result (Tahan Banting terhadap Pergeseran Index)
|
||||
if ($recordType === 'R') {
|
||||
if (isset($cekdata[2]) && isset($cekdata[3])) {
|
||||
$test_info_raw = $cekdata[2];
|
||||
$result_val = trim(str_replace('^', '', $cekdata[3]));
|
||||
|
||||
if ($result_val !== '') {
|
||||
$test_info = explode('^', $test_info_raw);
|
||||
$target_name = !empty($test_info[6]) ? $test_info[6] : 'Unknown Target';
|
||||
$metric_type = (!empty($test_info[7])) ? $test_info[7] : 'Result';
|
||||
// Pecah berdasarkan delimiter ^ dan buang elemen yang kosong
|
||||
$target_match = array_values(array_filter(explode('^', $test_info_raw), function($val) {
|
||||
return trim($val) !== '';
|
||||
}));
|
||||
|
||||
$target_name = '';
|
||||
$metric_type = 'Result';
|
||||
|
||||
if (!isset($parsedResults[$target_name])) {
|
||||
$parsedResults[$target_name] = [
|
||||
'Result' => '-',
|
||||
'Ct' => '-',
|
||||
'EndPt' => '-'
|
||||
];
|
||||
// Jika string test_info mengandung 'Ct' atau 'EndPt', elemen terakhir adalah metrik,
|
||||
// dan elemen sebelum terakhir adalah nama targetnya.
|
||||
if (strpos($rsegmen, 'Ct|') !== false) {
|
||||
$metric_type = 'Ct';
|
||||
// Mengambil nama target (elemen sebelum 'Ct')
|
||||
$target_name = count($target_match) > 1 ? $target_match[count($target_match) - 2] : '';
|
||||
} elseif (strpos($rsegmen, 'EndPt|') !== false) {
|
||||
$metric_type = 'EndPt';
|
||||
// Mengambil nama target (elemen sebelum 'EndPt')
|
||||
$target_name = count($target_match) > 1 ? $target_match[count($target_match) - 2] : '';
|
||||
} else {
|
||||
// Jika bukan Ct/EndPt, ini adalah Result murni.
|
||||
// Target name biasanya adalah elemen terakhir dari array yang tidak kosong.
|
||||
$target_name = count($target_match) > 0 ? end($target_match) : 'Unknown Target';
|
||||
}
|
||||
|
||||
$target_name = trim($target_name);
|
||||
|
||||
$parsedResults[$target_name][$metric_type] = $result_val;
|
||||
if ($target_name !== '') {
|
||||
if (!isset($parsedResults[$target_name])) {
|
||||
$parsedResults[$target_name] = [
|
||||
'Result' => '-',
|
||||
'Ct' => '-',
|
||||
'EndPt' => '-'
|
||||
];
|
||||
}
|
||||
|
||||
if ($metric_type === 'Result' && $result_val !== '') {
|
||||
// Simpan semua result ke dalam list untuk kesimpulan
|
||||
$hasil_list[$target_name] = "<strong>{$target_name}:</strong> {$result_val}";
|
||||
$parsedResults[$target_name][$metric_type] = $result_val;
|
||||
|
||||
// Hanya simpan Result utama sebagai kesimpulan (abaikan baris Ct/EndPt)
|
||||
if ($metric_type === 'Result') {
|
||||
$hasil_list[$target_name] = "<strong>{$target_name}:</strong> {$result_val}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -675,21 +697,18 @@ class AstmMessageService
|
||||
return false;
|
||||
}
|
||||
|
||||
// Buat string kesimpulan DULUAN sebelum membuat HTML
|
||||
$kesimpulan_html = implode(" | ", array_values($hasil_list));
|
||||
$kesimpulan_db = strip_tags($kesimpulan_html); // Versi tanpa tag HTML untuk kolom DB
|
||||
$kesimpulan_db = strip_tags($kesimpulan_html);
|
||||
$kesimpulan_safe = substr($kesimpulan_db, 0, 100);
|
||||
|
||||
// ====================================================================
|
||||
// MEMBUAT HTML REPORT & GRAFIK (CHART.JS)
|
||||
// ====================================================================
|
||||
|
||||
// Wrapper Utama
|
||||
$reporthtml = '<div class="genexpert-report" style="font-family: Arial, sans-serif; max-width: 900px; margin: auto; border: 1px solid #ddd; padding: 20px; border-radius: 8px;">';
|
||||
$reporthtml .= '<h3 style="text-align: center; margin-top: 0; color: #2c3e50;">Hasil Pemeriksaan GeneXpert</h3>';
|
||||
$reporthtml .= '<hr style="border: 0; border-top: 2px solid #3498db; margin-bottom: 20px;">';
|
||||
|
||||
// Bagian 1: Identitas Pasien (Grid Table)
|
||||
$reporthtml .= '<table style="width: 100%; margin-bottom: 20px; font-size: 14px; border: none;">';
|
||||
$reporthtml .= '<tr>';
|
||||
$reporthtml .= '<td style="width: 15%; padding: 4px 0;"><strong>No. Reg LIS</strong></td>';
|
||||
@@ -705,13 +724,11 @@ class AstmMessageService
|
||||
$reporthtml .= '</tr>';
|
||||
$reporthtml .= '</table>';
|
||||
|
||||
// Bagian 2: Kesimpulan / Hasil Utama
|
||||
$reporthtml .= '<div style="background-color: #f8f9fa; padding: 15px; border-left: 5px solid #2ecc71; margin-bottom: 25px; border-radius: 4px;">';
|
||||
$reporthtml .= '<h4 style="margin: 0 0 10px 0; color: #2c3e50;">Kesimpulan Hasil:</h4>';
|
||||
$reporthtml .= '<p style="margin: 0; font-size: 14px; line-height: 1.6;">' . $kesimpulan_html . '</p>';
|
||||
$reporthtml .= '</div>';
|
||||
|
||||
// Bagian 3: Tabel Detail Analit
|
||||
$reporthtml .= '<h4 style="margin-bottom:10px; color: #2c3e50;">Detail Target / Analit</h4>';
|
||||
$reporthtml .= '<table border="1" cellpadding="8" style="width: 100%; border-collapse: collapse; text-align: left; margin-bottom: 25px; font-size: 13px;">';
|
||||
$reporthtml .= '<tr style="background-color: #ecf0f1; color: #2c3e50;">
|
||||
@@ -741,7 +758,6 @@ class AstmMessageService
|
||||
}
|
||||
$reporthtml .= '</table>';
|
||||
|
||||
// Bagian 4: Grafik Chart.js
|
||||
if (!empty($chartLabels)) {
|
||||
$chartId = 'gxChart_' . preg_replace('/[^a-zA-Z0-9]/', '', $accession_number);
|
||||
$labelsJson = json_encode($chartLabels);
|
||||
@@ -806,7 +822,7 @@ class AstmMessageService
|
||||
</script>
|
||||
";
|
||||
}
|
||||
$reporthtml .= '</div>'; // End of Wrapper Utama
|
||||
$reporthtml .= '</div>';
|
||||
|
||||
// ====================================================================
|
||||
// SIMPAN KE DATABASE
|
||||
@@ -831,10 +847,12 @@ class AstmMessageService
|
||||
$resultSample->sender_name = $alat;
|
||||
$resultSample->patient_id = substr($patient_id, 0, 50);
|
||||
$resultSample->patient_name_first = substr($patient_name, 0, 100);
|
||||
$resultSample->organism = $kesimpulan_safe; // Disimpan versi plain text
|
||||
$resultSample->organism = $kesimpulan_safe;
|
||||
$resultSample->additional_result = json_encode($parsedResults);
|
||||
$resultSample->message_datetime = date('Y-m-d H:i:s');
|
||||
$resultSample->save();
|
||||
|
||||
Log::info("GeneXpert Result Disimpan", ["NoReg" => $accession_number, "Hasil" => $kesimpulan_safe]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::error("GeneXpert DB Save Error: " . $e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user