rajkhanke commited on
Commit
938c8ca
·
verified ·
1 Parent(s): 63facf6

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +73 -47
templates/index.html CHANGED
@@ -783,53 +783,78 @@
783
  return html;
784
  }
785
 
786
- // Print functionality
787
- printButton.addEventListener('click', function() {
788
- const printWindow = window.open('', '_blank');
789
- const content = markdownContent.innerHTML;
790
-
791
- printWindow.document.write(`
792
- <!DOCTYPE html>
793
- <html>
794
- <head>
795
- <title>Medical Report & Prescription</title>
796
- <style>
797
- body { font-family: Arial, sans-serif; line-height: 1.6; padding: 20px; }
798
- h1 { color: #1a365d; font-size: 24px; margin-bottom: 20px; }
799
- h2 { color: #2c5282; font-size: 20px; margin-top: 25px; margin-bottom: 10px; }
800
- h3 { color: #2d3748; font-size: 18px; margin-top: 20px; margin-bottom: 10px; }
801
- p { margin-bottom: 15px; text-align: justify; }
802
- ul, ol { padding-left: 25px; margin: 10px 0; }
803
- li { margin-bottom: 8px; }
804
- .header { text-align: center; margin-bottom: 30px; padding-bottom: 10px; border-bottom: 1px solid #ccc; }
805
- .footer { text-align: center; margin-top: 30px; padding-top: 10px; border-top: 1px solid #ccc; font-size: 12px; color: #718096; }
806
- .justified { text-align: justify; text-justify: inter-word; }
807
- @media print {
808
- body { margin: 0; padding: 15px; }
809
- .no-print { display: none; }
810
- }
811
- </style>
812
- </head>
813
- <body>
814
- <div class="header">
815
- <h1>Medical Report & Prescription</h1>
816
- <p>Generated on: ${new Date().toLocaleDateString()} at ${new Date().toLocaleTimeString()}</p>
817
- </div>
818
- ${content}
819
- <div class="footer">
820
- <p>This report was generated by Medical Report & Prescription Generator.</p>
821
- <p>Please consult with your healthcare provider before making any changes to your treatment.</p>
822
- </div>
823
- </body>
824
- </html>
825
- `);
826
-
827
- printWindow.document.close();
828
- setTimeout(() => {
829
- printWindow.print();
830
- }, 500);
831
- });
832
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
833
  // New analysis button functionality
834
  newAnalysisButton.addEventListener('click', function() {
835
  // Reset form and hide results
@@ -851,5 +876,6 @@
851
  }, 2000);
852
  });
853
  </script>
 
854
  </body>
855
  </html>
 
783
  return html;
784
  }
785
 
786
+ // Fallback print via hidden iframe
787
+ function printViaIframe(html) {
788
+ const iframe = document.getElementById('printFrame');
789
+ const doc = iframe.contentWindow.document;
790
+ doc.open();
791
+ doc.write(html);
792
+ doc.close();
793
+ iframe.contentWindow.focus();
794
+ iframe.contentWindow.print();
795
+ }
796
+
797
+ // Updated click handler for "Print Report"
798
+ printButton.addEventListener('click', function() {
799
+ // Make sure there's something to print
800
+ const content = markdownContent.innerHTML;
801
+ if (!content.trim()) {
802
+ showError('Nothing to print yet.');
803
+ return;
804
+ }
805
+
806
+ // Build the full HTML for printing
807
+ const printHTML = `
808
+ <!DOCTYPE html>
809
+ <html>
810
+ <head>
811
+ <title>Medical Report & Prescription</title>
812
+ <style>
813
+ body { font-family: Arial, sans-serif; line-height: 1.6; padding: 20px; }
814
+ h1 { color: #1a365d; font-size: 24px; margin-bottom: 20px; }
815
+ h2 { color: #2c5282; font-size: 20px; margin-top: 25px; margin-bottom: 10px; }
816
+ h3 { color: #2d3748; font-size: 18px; margin-top: 20px; margin-bottom: 10px; }
817
+ p { margin-bottom: 15px; text-align: justify; }
818
+ ul, ol { padding-left: 25px; margin: 10px 0; }
819
+ li { margin-bottom: 8px; }
820
+ .header { text-align: center; margin-bottom: 30px; padding-bottom: 10px; border-bottom: 1px solid #ccc; }
821
+ .footer { text-align: center; margin-top: 30px; padding-top: 10px; border-top: 1px solid #ccc; font-size: 12px; color: #718096; }
822
+ .justified { text-align: justify; text-justify: inter-word; }
823
+ @media print {
824
+ body { margin: 0; padding: 15px; }
825
+ .no-print { display: none; }
826
+ }
827
+ </style>
828
+ </head>
829
+ <body>
830
+ <div class="header">
831
+ <h1>Medical Report & Prescription</h1>
832
+ <p>Generated on: ${new Date().toLocaleDateString()} at ${new Date().toLocaleTimeString()}</p>
833
+ </div>
834
+ ${content}
835
+ <div class="footer">
836
+ <p>This report was generated by Medical Report & Prescription Generator.</p>
837
+ <p>Please consult with your healthcare provider before making any changes to your treatment.</p>
838
+ </div>
839
+ </body>
840
+ </html>
841
+ `;
842
+
843
+ // Try opening a new window
844
+ const printWindow = window.open('', '_blank');
845
+ if (printWindow) {
846
+ // We got a window → proceed as before
847
+ printWindow.document.write(printHTML);
848
+ printWindow.document.close();
849
+ setTimeout(() => printWindow.print(), 500);
850
+ } else {
851
+ // Popup was blocked → fallback to iframe
852
+ alert('Pop-up blocked! Using in-page print instead.');
853
+ printViaIframe(printHTML);
854
+ }
855
+ });
856
+
857
+
858
  // New analysis button functionality
859
  newAnalysisButton.addEventListener('click', function() {
860
  // Reset form and hide results
 
876
  }, 2000);
877
  });
878
  </script>
879
+ <iframe id="printFrame" style="display:none;"></iframe>
880
  </body>
881
  </html>