From 7b1b81ce66d56966433e9a25c1aa3df09f4df6b8 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Wed, 29 Jul 2026 03:53:13 +0530 Subject: [PATCH] ABDM Fetch Data modal: show attached images/PDFs per document (lazy-loaded via abdm_document_detail, since the list endpoint strips attachments to keep it light) --- app/Views/billing/Patient_Profile_Opd_V.php | 87 +++++++++++++++------ 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/app/Views/billing/Patient_Profile_Opd_V.php b/app/Views/billing/Patient_Profile_Opd_V.php index 581cc39..ec6f99b 100644 --- a/app/Views/billing/Patient_Profile_Opd_V.php +++ b/app/Views/billing/Patient_Profile_Opd_V.php @@ -781,9 +781,14 @@ $(function() { } var html = ''; + var docIds = []; docs.forEach(function(doc, di) { var summary = doc.summary || {}; var sections = Array.isArray(summary.sections) ? summary.sections : []; + var docId = doc.id; + if (docId) { + docIds.push(docId); + } html += '
' + '
' @@ -815,9 +820,35 @@ $(function() { html += '
No structured sections available for this record.
'; } + // Attachments (scanned images/PDFs) are stripped from the list payload + // to keep it light -- lazily fetch the full per-document detail (which + // includes them) after the modal is rendered, see below. + if (docId) { + html += '
Attached Files
' + + '
Loading attached files...
'; + } + html += '
'; }); $('#abdmFetchResultModalBody').html(html); + + docIds.forEach(function(docId) { + fetch(abdmDocDetailBaseUrl + '/' + encodeURIComponent(docId), { credentials: 'same-origin' }) + .then(function(resp) { return resp.json(); }) + .then(function(data) { + var item = (data && data.ok === 1) ? (data.item || {}) : null; + var summary = (item && item.summary) || {}; + var $target = $('.abdm-fetch-attachments[data-doc-id="' + docId + '"]'); + if (!item) { + $target.removeClass('text-muted').addClass('text-danger').text('Unable to load attached files.'); + return; + } + $target.removeClass('small text-muted').html(renderAttachmentsHtml(summary.attachments)); + }) + .catch(function() { + $('.abdm-fetch-attachments[data-doc-id="' + docId + '"]').removeClass('text-muted').addClass('text-danger').text('Unable to load attached files.'); + }); + }); } var zoom = 1; @@ -1017,35 +1048,41 @@ $(function() { html += ''; html += ''; - var attachments = Array.isArray(summary.attachments) ? summary.attachments : []; - html += '
Attached Files
'; - if (attachments.length) { - html += '
'; - attachments.forEach(function(att, idx) { - var ct = (att.content_type || '').toString().toLowerCase(); - var blobUrl = att.data ? base64ToBlobUrl(att.data, att.content_type) : ''; - html += '
'; - html += '
' + escHtml(att.title || ('Attachment ' + (idx + 1))) + '
'; - if (!blobUrl) { - html += '
Preview unavailable
'; - } else if (ct.indexOf('image/') === 0) { - html += 'Attached image'; - } else if (ct === 'application/pdf') { - html += '
PDF Document
View PDF'; - } else { - html += '
' + escHtml(att.content_type || 'Document') + '
Open Document'; - } - html += '
'; - }); - html += '
'; - } else { - html += '
No attached images, PDFs, or documents found in this record.
'; - } - html += '
'; + html += '
Attached Files
' + renderAttachmentsHtml(summary.attachments) + '
'; $('#abdmDocDetailBox').html(html); } + // Builds the "Attached Files" preview grid (images shown inline w/ zoom modal, + // PDFs/other docs as an "Open"/"View" link) from a document's summary.attachments + // array. Shared by the doc-detail box and the per-consent-request fetch modal. + function renderAttachmentsHtml(attachments) { + attachments = Array.isArray(attachments) ? attachments : []; + if (!attachments.length) { + return '
No attached images, PDFs, or documents found in this record.
'; + } + + var html = '
'; + attachments.forEach(function(att, idx) { + var ct = (att.content_type || '').toString().toLowerCase(); + var blobUrl = att.data ? base64ToBlobUrl(att.data, att.content_type) : ''; + html += '
'; + html += '
' + escHtml(att.title || ('Attachment ' + (idx + 1))) + '
'; + if (!blobUrl) { + html += '
Preview unavailable
'; + } else if (ct.indexOf('image/') === 0) { + html += 'Attached image'; + } else if (ct === 'application/pdf') { + html += '
PDF Document
View PDF'; + } else { + html += '
' + escHtml(att.content_type || 'Document') + '
Open Document'; + } + html += '
'; + }); + html += '
'; + return html; + } + function loadAbdmDocs() { var q = ($('#abdmDocSearch').val() || '').toString().trim(); var url = abdmDocumentsUrl + '?limit=200';