').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('= base_url('Opd_prescription/complaints_extract') ?>', { 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()
});
}
});
|