diff --git a/app/Views/billing/ipd/discharge_create.php b/app/Views/billing/ipd/discharge_create.php
index 9fd492b..f437ce6 100644
--- a/app/Views/billing/ipd/discharge_create.php
+++ b/app/Views/billing/ipd/discharge_create.php
@@ -714,58 +714,75 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -832,9 +849,7 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller
-
+
@@ -1689,7 +1704,7 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller
}
var lookup = document.getElementById('discharge_complaint_lookup');
- var suggest = document.getElementById('discharge_complaint_suggest');
+ var dropdown = document.getElementById('discharge_complaint_dropdown');
var nameInput = document.getElementById('new_complaint_name');
var remarkInput = document.getElementById('new_complaint_remark');
var addRowBtn = document.getElementById('btn_add_complaint_row');
@@ -1703,11 +1718,11 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller
var complaintSuggestions = [];
section.querySelectorAll('table tbody tr').forEach(function(row) {
- var firstCell = row.querySelector('td');
+ var firstCell = row.querySelector('.discharge-complaint-name-input');
if (!firstCell) {
return;
}
- var value = (firstCell.textContent || '').trim();
+ var value = (firstCell.value || '').trim();
if (value !== '' && value.toLowerCase() !== 'no complaint rows yet.') {
selectedComplaints.push(value);
}
@@ -1740,29 +1755,66 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller
});
}
- if (lookup) {
+ if (lookup && dropdown) {
lookup.addEventListener('input', function() {
var q = (lookup.value || '').trim();
if (q.length < 2 || !window.jQuery) {
+ dropdown.style.display = 'none';
return;
}
$.get('= base_url('Opd_prescription/complaints_search') ?>?q=' + encodeURIComponent(q), function(data) {
complaintSuggestions = (data && data.rows) ? data.rows : [];
- if (!suggest) {
+ if (!complaintSuggestions.length) {
+ dropdown.style.display = 'none';
return;
}
+
var html = '';
complaintSuggestions.forEach(function(row) {
var label = row.name || '';
- if (row.name_hinglish) {
- label += ' (' + row.name_hinglish + ')';
- }
- html += '';
+ var hinglish = row.name_hinglish ? ' (' + row.name_hinglish + ')' : '';
+ html += '' +
+ $('
').text(label).html() +
+ '' + hinglish + '
';
+ });
+ dropdown.innerHTML = html;
+ dropdown.style.display = 'block';
+
+ dropdown.querySelectorAll('.dropdown-item').forEach(function(item) {
+ item.addEventListener('mouseenter', function() {
+ this.style.backgroundColor = '#f8f9fa';
+ });
+ item.addEventListener('mouseleave', function() {
+ this.style.backgroundColor = '';
+ });
+ item.addEventListener('click', function() {
+ var value = this.getAttribute('data-value');
+ lookup.value = value;
+ dropdown.style.display = 'none';
+ if (btnAdd) {
+ btnAdd.click();
+ }
+ });
});
- suggest.innerHTML = html;
}, 'json');
});
+
+ lookup.addEventListener('keydown', function(e) {
+ if (e.key === 'Enter' && btnAdd) {
+ e.preventDefault();
+ dropdown.style.display = 'none';
+ btnAdd.click();
+ } else if (e.key === 'Escape') {
+ dropdown.style.display = 'none';
+ }
+ });
+
+ lookup.addEventListener('blur', function() {
+ setTimeout(function() {
+ dropdown.style.display = 'none';
+ }, 200);
+ });
}
if (btnAdd) {