Fix autocomplete selection - now adds to client-side array
BUGFIX: Autocomplete dropdown was showing but items weren't selectable PROBLEM: Clicking autocomplete suggestions didn't add complaints to table ROOT CAUSE: btnAdd click handler was using old database-submit logic instead of new client-side array management SOLUTION: Simplified btnAdd to: 1. Take value from lookup input 2. Check if already exists (prevent duplicates) 3. Add to selectedDischargeComplaints array 4. Call renderDischargeComplaintTable() to refresh 5. Clear input and show success message HOW IT WORKS NOW: - Type complaint name → autocomplete dropdown appears - Click suggestion → sets lookup input value - btnAdd triggered → adds to array → table refreshes - Complaint appears in table with editable Frequency/Severity/Duration All inline editing works without database calls!
This commit is contained in:
parent
58e79318fd
commit
4fc64be2a2
|
|
@ -1797,81 +1797,38 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller
|
|||
return;
|
||||
}
|
||||
|
||||
var chosen = '';
|
||||
complaintSuggestions.forEach(function(row) {
|
||||
var label = row.name || '';
|
||||
if (row.name_hinglish) {
|
||||
label += ' (' + row.name_hinglish + ')';
|
||||
}
|
||||
if (label.toUpperCase() === inputVal.toUpperCase() || (row.name || '').toUpperCase() === inputVal.toUpperCase()) {
|
||||
chosen = row.name || inputVal;
|
||||
}
|
||||
// Check if already exists
|
||||
var exists = selectedDischargeComplaints.some(function(item) {
|
||||
return item.term.toUpperCase() === inputVal.toUpperCase();
|
||||
});
|
||||
|
||||
function submitComplaint(value) {
|
||||
if (!nameInput || !addRowBtn) {
|
||||
return;
|
||||
}
|
||||
nameInput.value = value;
|
||||
if (remarkInput) {
|
||||
remarkInput.value = '';
|
||||
}
|
||||
addRowBtn.click();
|
||||
}
|
||||
|
||||
if (chosen !== '') {
|
||||
addComplaintValue(chosen);
|
||||
submitComplaint(chosen);
|
||||
|
||||
if (exists) {
|
||||
setComplaintStatus('Complaint already added.', 'error');
|
||||
if (lookup) {
|
||||
lookup.value = '';
|
||||
}
|
||||
setComplaintStatus('Complaint added.', 'success');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!window.jQuery) {
|
||||
submitComplaint(inputVal);
|
||||
return;
|
||||
}
|
||||
|
||||
var csrf = getCsrfPair(form);
|
||||
var payload = {
|
||||
text: inputVal
|
||||
};
|
||||
payload[csrf.name] = csrf.value;
|
||||
|
||||
$.post('<?= base_url('Opd_prescription/complaints_parse') ?>', payload, function(data) {
|
||||
if (data && data.csrfName && data.csrfHash) {
|
||||
var csrfInput = form.querySelector('input[name="' + data.csrfName + '"]');
|
||||
if (csrfInput) {
|
||||
csrfInput.value = data.csrfHash;
|
||||
}
|
||||
}
|
||||
|
||||
var rows = (data && data.rows) ? data.rows : [];
|
||||
if (!rows.length) {
|
||||
submitComplaint(inputVal);
|
||||
if (lookup) {
|
||||
lookup.value = '';
|
||||
}
|
||||
setComplaintStatus('Added custom complaint text.', 'success');
|
||||
return;
|
||||
}
|
||||
|
||||
var first = (rows[0] || '').toString().trim();
|
||||
if (first === '') {
|
||||
submitComplaint(inputVal);
|
||||
} else {
|
||||
addComplaintValue(first);
|
||||
submitComplaint(first);
|
||||
}
|
||||
if (lookup) {
|
||||
lookup.value = '';
|
||||
}
|
||||
setComplaintStatus((data && data.error_text) ? data.error_text : 'Complaint term matched.', 'success');
|
||||
}, 'json').fail(function() {
|
||||
setComplaintStatus('Unable to parse complaint text right now.', 'error');
|
||||
// Add to array
|
||||
selectedDischargeComplaints.push({
|
||||
id: 0,
|
||||
term: inputVal,
|
||||
frequency: '',
|
||||
severity: '',
|
||||
duration: '',
|
||||
date: ''
|
||||
});
|
||||
|
||||
// Refresh table
|
||||
renderDischargeComplaintTable();
|
||||
|
||||
// Clear input
|
||||
if (lookup) {
|
||||
lookup.value = '';
|
||||
}
|
||||
|
||||
setComplaintStatus('Complaint added. Edit inline if needed.', 'success');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user