diff --git a/main.py b/main.py new file mode 100644 index 0000000..0669d7f --- /dev/null +++ b/main.py @@ -0,0 +1,38 @@ +from jinja2 import Environment, FileSystemLoader +from weasyprint import HTML +import matplotlib.pyplot as plt +import os + +# 1. Generate a chart with matplotlib +os.makedirs("static/charts", exist_ok=True) +chart_path = "static/charts/resp_chart.png" + +plt.plot([1, 2, 3, 4], [1, 4, 2, 5], label="Breath Volume") +plt.legend() +plt.title("Respiratory Chart") +plt.savefig(chart_path) +plt.close() + +# 2. Patient data (this would usually come from your DB) +patient_data = { + "name": "Keirstyn Moran", + "age": 34, + "height": 163, + "weight": 56 +} + +context = { + "patient": patient_data, + "indications": "No Respiratory Capacity Limitation", + "chart_path": chart_path +} + +# 3. Render Jinja2 template +env = Environment(loader=FileSystemLoader("templates")) +template = env.get_template("report.html") +html_out = template.render(context) + +# 4. Generate PDF +HTML(string=html_out, base_url=".").write_pdf("lung_report.pdf") + +print("✅ Report generated: lung_report.pdf") \ No newline at end of file diff --git a/pdf_generation.ipynb b/pdf_generation.ipynb new file mode 100644 index 0000000..4bcc195 --- /dev/null +++ b/pdf_generation.ipynb @@ -0,0 +1,105 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 8, + "id": "6eee3ddd", + "metadata": {}, + "outputs": [], + "source": [ + "import camelot\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "d95cd8b1", + "metadata": {}, + "outputs": [], + "source": [ + "tables = camelot.read_pdf('data/KM6479696509 _ Keirstyn_Moran_SingleViewWithExplanation_2025-07-29.pdf')" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "759fd46e", + "metadata": {}, + "outputs": [], + "source": [ + "all_dfs = []\n", + "\n", + "# Append each table's dataframe to the list\n", + "for table in tables:\n", + " all_dfs.append(table.df)\n", + "\n", + "# Concatenate all dataframes into one\n", + "combined_df = pd.concat(all_dfs, ignore_index=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "e9c3b9f0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 0 1 2 3 \\\n", + "0 ← FM →\\nLow Fat\\nHigh Fat\\nBody Composition Ch... \n", + "1 \n", + "2 \n", + "3 \n", + "4 \n", + "5 \n", + "6 \n", + "\n", + " 4 5 \n", + "0 muscle mass in a coordinate system. A d... \n", + "1 \n", + "2 \n", + "3 \n", + "4 \n", + "5 \n", + "6 \n" + ] + } + ], + "source": [ + "print(combined_df)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6bbc907f", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "report_generation", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..27ae3ca --- /dev/null +++ b/templates/base.html @@ -0,0 +1,39 @@ + + + +
+ +