diff --git a/app/Views/billing/opd_prescription_basic.php b/app/Views/billing/opd_prescription_basic.php index e55b238..23c9c42 100644 --- a/app/Views/billing/opd_prescription_basic.php +++ b/app/Views/billing/opd_prescription_basic.php @@ -3159,11 +3159,55 @@ $('#patient_scan_history_body').html('
Loading scan history...
'); $.get('/' + opdId, function(html) { $('#patient_scan_history_body').html(html || '
No scan history found.
'); + $('#patient_scan_history_body .js-history-report').each(function() { + var raw = ($(this).text() || '').toString(); + $(this).html(formatAiReportHtml(raw)); + }); }).fail(function() { $('#patient_scan_history_body').html('
Unable to load scan history.
'); }); } + function formatAiReportHtml(report) { + report = (report || '').toString().trim(); + if (!report) { + return 'No AI report.'; + } + + var normalized = report.replace(/\s+/g, ' ').replace(/\s*\|\s*/g, '|').trim(); + var pieces = normalized.split('|').map(function(p) { + return p.trim(); + }).filter(function(p) { + return p.length > 0; + }); + + if (pieces.length <= 1) { + pieces = normalized.split(/(?=(?:Summary|Impression|Findings|Red flags|Suggested tests|Suitability|Confidence|Ventricular rate|PR interval|QRS duration|QT\/QTc|Axis|Risk level|Alert)\s*:)/i) + .map(function(p) { return p.trim(); }) + .filter(function(p) { return p.length > 0; }); + } + + if (!pieces.length) { + pieces = [normalized]; + } + + var html = ''; + pieces.slice(0, 16).forEach(function(seg) { + var m = seg.match(/^([A-Za-z][A-Za-z0-9\s\/.()%-]{1,50})\s*:\s*(.+)$/); + if (m) { + html += '
' + + '' + $('
').text(m[1].trim() + ':').html() + ' ' + + '' + $('
').text(m[2].trim()).html() + '' + + '
'; + return; + } + + html += '
' + $('
').text(seg).html() + '
'; + }); + + return html; + } + $('.rx-field').on('input', function() { refreshCounters(); updateScanBanner(); @@ -3364,7 +3408,7 @@ if ((data.content_description || '').toString().trim() !== '') { var report = (data.content_description || '').toString(); - $item.find('.js-history-report').text(report); + $item.find('.js-history-report').html(formatAiReportHtml(report)); $item.find('.btn-use-history-report').data('report', report); } diff --git a/app/Views/billing/opd_scan_history_panel.php b/app/Views/billing/opd_scan_history_panel.php index 4ecd1fe..31dd3c3 100644 --- a/app/Views/billing/opd_scan_history_panel.php +++ b/app/Views/billing/opd_scan_history_panel.php @@ -40,7 +40,7 @@ ⚠
-
+