From 9fe9c971f1a2b8f98559bda958b2e730f0ec3121 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Tue, 19 May 2026 22:58:52 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20Healthplix-style=20complaint=20table=20?= =?UTF-8?q?=E2=80=94=20inline=20row=20editing=20with=20Frequency/Severity/?= =?UTF-8?q?Duration/Date=20columns,=20remove=20Extract=20Codes=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Views/billing/opd_prescription_basic.php | 279 ++++++++----------- 1 file changed, 114 insertions(+), 165 deletions(-) diff --git a/app/Views/billing/opd_prescription_basic.php b/app/Views/billing/opd_prescription_basic.php index 6a3889e..59394a6 100644 --- a/app/Views/billing/opd_prescription_basic.php +++ b/app/Views/billing/opd_prescription_basic.php @@ -851,47 +851,40 @@
-
Chief Complaints
- - -
-
- - - -
- +
+
Chief Complaints
+
- - - - - + + + - - + + + + + + + + + +
# ComplaintCodeDurationFrequency SeverityDurationDate
+ + +
-
No complaint selected yet
@@ -4687,8 +4680,10 @@ concept_id: item.concept_id || '', source: item.source || '', hierarchy: item.hierarchy || '', + frequency: item.frequency || '', + severity: item.severity || '', duration: item.duration || '', - severity: item.severity || '' + date: item.date || '' }; })); $('#complaint_snomed_json').val(json); @@ -4702,53 +4697,53 @@ var $tbody = $('#complaint_tbody'); $tbody.empty(); - if (!selectedComplaintItems.length) { - $('#complaint_table').hide(); - $('#complaint_empty_hint').show(); - syncComplaintSnomedJson(); - return; - } - - $('#complaint_empty_hint').hide(); - $('#complaint_table').show(); - selectedComplaintItems.forEach(function(item, idx) { var isSnomed = !!(item.concept_id); var $tr = $('').attr('data-idx', idx); - // Complaint name β€” SNOMED = blue text, local = muted gray - var $nameTd = $(''); - var nameColor = isSnomed ? 'color:#0d6efd;font-weight:600' : 'color:#6c757d;font-weight:600'; - $nameTd.append($('
').text(item.term)); + // # column + $tr.append($('').text(idx + 1)); + + // Complaint name β€” SNOMED = blue, local = default + var $nameTd = $(''); + var nameStyle = isSnomed ? 'color:#0d6efd;font-weight:600;max-width:210px' : 'max-width:210px'; + var $nameDiv = $('
').text(item.term); + if (item.concept_id) { $nameDiv.attr('title', 'SNOMED: ' + item.concept_id); } + $nameTd.append($nameDiv); $tr.append($nameTd); - // SNOMED code - var $codeComplaintTd = $(''); - if (item.concept_id) { - $codeComplaintTd.append( - $('').text(item.concept_id) - ); - } else { - $codeComplaintTd.append($('').text('\u2014')); - } - $tr.append($codeComplaintTd); - - // Duration input + // Frequency input $tr.append( $('').append( - $('') - .val(item.duration || '').attr('data-idx', idx) + $('') + .val(item.frequency || '').attr('data-idx', idx) ) ); // Severity input $tr.append( $('').append( - $('') + $('') .val(item.severity || '').attr('data-idx', idx) ) ); + // Duration input + $tr.append( + $('').append( + $('') + .val(item.duration || '').attr('data-idx', idx) + ) + ); + + // Date input + $tr.append( + $('').append( + $('') + .val(item.date || '').attr('data-idx', idx) + ) + ); + // Remove button $tr.append( $('').append( @@ -4783,123 +4778,24 @@ return false; } - selectedComplaintItems.push({ term: term, concept_id: conceptId, source: source, hierarchy: hierarchy, duration: '', severity: '' }); + selectedComplaintItems.push({ term: term, concept_id: conceptId, source: source, hierarchy: hierarchy, + frequency: '', severity: '', duration: '', date: '' }); var newIdx = selectedComplaintItems.length - 1; renderComplaintTable(); appendComplaintToTextarea(term); refreshCounters(); markDirty('Complaint added'); - // Focus the new row's Duration input + // Focus the new row's Frequency input setTimeout(function() { - $('#complaint_tbody').find('.complaint-dur-input[data-idx="' + newIdx + '"]').trigger('focus'); + $('#complaint_tbody').find('.complaint-freq-input[data-idx="' + newIdx + '"]').trigger('focus'); }, 60); return true; } - // ─── Extract Codes from free-text (SNOMED chips review) ───────────────── - $('#btn_extract_complaint_codes').on('click', function () { - var text = $.trim($('#complaint_lookup').val()); - if (!text) { $('#complaint_lookup').trigger('focus'); return; } - - var $btn = $(this); - var $panel = $('#complaint_extract_panel'); - var $wrap = $('#complaint_chips_wrap'); - - $btn.prop('disabled', true).text('Extracting…'); - $panel.show(); - $wrap.html('Searching SNOMED…'); - - $.get('', { q: text }) - .done(function (data) { - $btn.prop('disabled', false).text('Extract Codes'); - var rows = (data && data.rows) ? data.rows : []; - - if (!rows.length) { - $wrap.html('No SNOMED match. Added as free text.'); - addComplaintItem({ name: text, concept_id: '', source: 'local' }); - setTimeout(function () { $panel.hide(); $wrap.empty(); }, 1800); - return; - } - - $wrap.empty(); - rows.forEach(function (r) { - var pct = Math.round((parseFloat(r.confidence) || 0) * 100); - var meta = [r.duration, r.severity].filter(Boolean).join(' Β· '); - - var $chip = $(''); - $chip.append($('').text(r.term || r.snomed_term || '')); - if (r.concept_id) { - $chip.append($('').text(' ' + r.concept_id)); - } - if (meta) { - $chip.append($('').text(' Β· ' + meta)); - } - if (pct > 0) { - $chip.append($('').text(pct + '%')); - } - - var $bConfirm = $(''); - var $bReject = $(''); - - $bConfirm.on('click', function () { - var added = addComplaintItem({ - name: r.term || r.snomed_term || text, - concept_id: r.concept_id || '', - source: r.concept_id ? 'snomed' : 'local', - hierarchy: r.hierarchy || r.semantic_tag || '' - }); - // Pre-fill duration & severity on the new table row - var newIdx = selectedComplaintItems.length - 1; - if (newIdx >= 0) { - if (r.duration) { - selectedComplaintItems[newIdx].duration = r.duration; - $('#complaint_tbody .complaint-dur-input[data-idx="' + newIdx + '"]').val(r.duration); - } - if (r.severity) { - selectedComplaintItems[newIdx].severity = r.severity; - $('#complaint_tbody .complaint-sev-input[data-idx="' + newIdx + '"]').val(r.severity); - } - syncComplaintSnomedJson(); - } - $chip.addClass('chip-confirmed'); - $bConfirm.prop('disabled', true); - $bReject.hide(); - // Clear the lookup input after first confirmation - $('#complaint_lookup').val(''); - }); - - $bReject.on('click', function () { - $chip.addClass('chip-rejected'); - if (!$wrap.find('.snomed-chip:not(.chip-rejected)').length) { - $panel.hide(); $wrap.empty(); - } - }); - - $chip.append($bConfirm).append($bReject); - $wrap.append($chip); - }); - }) - .fail(function () { - $btn.prop('disabled', false).text('Extract Codes'); - $wrap.html('Search failed.'); - }); - }); - - $('#btn_confirm_all_chips').on('click', function () { - $('#complaint_chips_wrap .snomed-chip:not(.chip-rejected):not(.chip-confirmed) .chip-btn-confirm').each(function () { - $(this).trigger('click'); - }); - }); - - $('#btn_dismiss_extract').on('click', function () { - $('#complaint_extract_panel').hide(); - $('#complaint_chips_wrap').empty(); - }); - // ─── Per-complaint inline editor β€” stubs (table replaced the panel) ───── function openComplaintInlineEditor(idx) { setTimeout(function() { - $('#complaint_tbody').find('.complaint-dur-input[data-idx="' + idx + '"]').trigger('focus'); + $('#complaint_tbody').find('.complaint-freq-input[data-idx="' + idx + '"]').trigger('focus'); }, 60); } function closeComplaintInlineEditor() { /* no-op: table is always visible */ } @@ -4940,6 +4836,57 @@ .on('click', function() { onSelect(text); }); } + // ─── Frequency: event delegation on table rows ──────────────────── + var _FREQUENCY_OPTIONS = ['daily', 'twice daily', 'weekly', 'intermittent', 'continuous', 'occasional']; + + $(document).on('input focus', '.complaint-freq-input', function() { + var $inp = $(this); + var q = ($inp.val() || '').trim().toLowerCase(); + var sugs = q ? _FREQUENCY_OPTIONS.filter(function(s) { return s.indexOf(q) !== -1; }) : _FREQUENCY_OPTIONS; + var idx = parseInt($inp.attr('data-idx'), 10); + if (!sugs.length) { return; } + // reuse complaint_sev_dd div as a floating list (same fixed-position technique) + var $dd = $('
'); + $('#_freq_dd').remove(); + sugs.forEach(function(s) { + $dd.append(buildSmartDdItem(s, function(val) { + $inp.val(val); + if (idx >= 0 && idx < selectedComplaintItems.length) { + selectedComplaintItems[idx].frequency = val; + syncComplaintSnomedJson(); + } + $('#_freq_dd').remove(); + $inp.closest('tr').find('.complaint-sev-input').trigger('focus'); + })); + }); + var r = $inp[0].getBoundingClientRect(); + $dd.css({ top: (r.bottom + 2) + 'px', left: r.left + 'px', width: Math.max(r.width, 160) + 'px' }); + $('body').append($dd); + }); + $(document).on('blur', '.complaint-freq-input', function() { + var idx = parseInt($(this).attr('data-idx'), 10); + if (idx >= 0 && idx < selectedComplaintItems.length) { + selectedComplaintItems[idx].frequency = ($(this).val() || '').trim(); + syncComplaintSnomedJson(); + } + setTimeout(function() { $('#_freq_dd').remove(); }, 150); + }); + $(document).on('click', function(e) { + if (!$(e.target).closest('.complaint-freq-input, #_freq_dd').length) { + $('#_freq_dd').remove(); + } + }); + + // Date input save + $(document).on('change', '.complaint-date-input', function() { + var idx = parseInt($(this).attr('data-idx'), 10); + if (idx >= 0 && idx < selectedComplaintItems.length) { + selectedComplaintItems[idx].date = ($(this).val() || '').trim(); + syncComplaintSnomedJson(); + markDirty('Complaint date updated'); + } + }); + // ─── Duration: event delegation on table rows ──────────────────────────── $(document).on('input focus', '.complaint-dur-input', function() { _durDdIdx = -1; @@ -5258,8 +5205,10 @@ concept_id: (item.concept_id || '').toString(), source: (item.source || '').toString(), hierarchy: (item.hierarchy || '').toString(), + frequency: (item.frequency || '').toString(), + severity: (item.severity || '').toString(), duration: (item.duration || '').toString(), - severity: (item.severity || '').toString() + date: (item.date || '').toString() }); } });