diff --git a/app/Views/abdm/opd_queue.php b/app/Views/abdm/opd_queue.php index cdd12ea..2483548 100644 --- a/app/Views/abdm/opd_queue.php +++ b/app/Views/abdm/opd_queue.php @@ -182,6 +182,12 @@ function esc(s) { return String(s ?? '').replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"'); } + function encodePayload(obj) { + return btoa(unescape(encodeURIComponent(JSON.stringify(obj)))); + } + function decodePayload(payload) { + return JSON.parse(decodeURIComponent(escape(atob(String(payload || ''))))); + } function loadQueue() { const date = document.getElementById('queueDate').value; @@ -255,12 +261,12 @@ actions += ``; } if (!isLinked && (isPend || isCalled)) { - const pl = JSON.stringify({ + const pl = encodePayload({ id: t.id, abha_number: t.abha_number ?? '', abha_address: t.abha_address ?? '', aadhaar_number: t.aadhaar_number ?? t.aadhar_number ?? t.udai ?? '', patient_name: t.patient_name ?? '', phone: t.phone ?? '', gender: t.gender ?? '', dob: t.dob ?? '' - }).replace(/'/g, '''); + }); actions += ``; } @@ -301,8 +307,8 @@ window.abdmQComplete = id => setStatus(id, 'COMPLETED'); window.abdmQCancel = id => { if (confirm('Cancel token #' + id + '?')) setStatus(id, 'CANCELLED'); }; - window.abdmQRegister = function (payloadJson) { - const t = JSON.parse(payloadJson); + window.abdmQRegister = function (payloadEncoded) { + const t = decodePayload(payloadEncoded); const body = document.getElementById('abdmProcessTokenBody'); body.innerHTML = `

Processing ABHA Scan token for:

@@ -341,7 +347,7 @@
${esc(m.p_code || 'UHID N/A')} - ${esc(m.p_fname || 'Unnamed')}
Phone: ${esc(m.mphone1 || '—')} | ABHA: ${esc(m.patient_abha || '—')} | Aadhaar: ${esc(m.patient_aadhaar || '—')}
Matched by: ${esc(reasons || 'Data match')}
- + `; }).join(''); @@ -351,11 +357,11 @@ Similar patient records found. Confirm existing patient or create a new record. ${cards} - + Open Manual Patient Registration (/billing/patient) `; } else { - abdmQCreateNewPatient(t.id, encodeURIComponent(JSON.stringify(t)), true); + abdmQCreateNewPatient(t.id, payloadEncoded, true); } }).catch(err => { body.innerHTML = `
Request error: ${esc(err.message)}
@@ -364,7 +370,7 @@ }; window.abdmQResolveExisting = function (tokenId, patientId, encodedPayload) { - const t = JSON.parse(decodeURIComponent(encodedPayload)); + const t = decodePayload(encodedPayload); const body = document.getElementById('abdmProcessTokenBody'); body.innerHTML = '

Linking token to selected patient…

'; @@ -381,7 +387,7 @@ }; window.abdmQCreateNewPatient = function (tokenId, encodedPayload, skipConfirm) { - const t = JSON.parse(decodeURIComponent(encodedPayload)); + const t = decodePayload(encodedPayload); const body = document.getElementById('abdmProcessTokenBody'); if (!skipConfirm && !confirm('Create a new patient record for this token?')) { return;