added minimal report
This commit is contained in:
@@ -151,7 +151,7 @@ class ReportGeneratorService:
|
||||
}
|
||||
|
||||
def generate_html(
|
||||
self, patient_info: Dict[str, Any], contexts: Dict[str, Dict[str, Any]]
|
||||
self, patient_info: Dict[str, Any], contexts: Dict[str, Dict[str, Any]], report_type: str = "full"
|
||||
) -> str:
|
||||
"""
|
||||
Generate HTML content for the report.
|
||||
@@ -160,6 +160,7 @@ class ReportGeneratorService:
|
||||
patient_info: Dictionary containing patient information
|
||||
(patient_name, age, height, weight, focus)
|
||||
contexts: Dictionary with keys 'page_1', 'page_2', etc., each containing context data
|
||||
report_type: Type of report to generate ("full" or "minimal")
|
||||
|
||||
Returns:
|
||||
Complete HTML document as string
|
||||
@@ -175,8 +176,28 @@ class ReportGeneratorService:
|
||||
"focus": patient_info.get("focus", "Endurance"),
|
||||
}
|
||||
|
||||
# Get total number of pages
|
||||
num_pages = len(contexts)
|
||||
# Define page mappings for full vs minimal reports
|
||||
if report_type == "minimal":
|
||||
# Minimal report: pages 1, 2, 4, 5, 6, 16, 17, 19, 20
|
||||
# Map to minimal report pages 1-8
|
||||
# Page mapping: (original_page_num, template_name, minimal_page_num)
|
||||
page_mapping = [
|
||||
(1, "page_1.html", 1),
|
||||
(2, "page_2_minimal.html", 2),
|
||||
(4, "page_4.html", 3),
|
||||
(5, "page_5_minimal.html", 4),
|
||||
(6, "page_6.html", 5),
|
||||
(16, "page_16.html", 6),
|
||||
(17, "page_17_minimal.html", 7),
|
||||
(19, "page_19_20_minimal.html", 8), # Combined page
|
||||
]
|
||||
else:
|
||||
# Full report: all pages 1-20
|
||||
page_mapping = [
|
||||
(i, f"page_{i}.html", i) for i in range(1, 21)
|
||||
]
|
||||
|
||||
num_pages = len(page_mapping)
|
||||
|
||||
# Footer context
|
||||
footer_context = [
|
||||
@@ -198,13 +219,20 @@ class ReportGeneratorService:
|
||||
for context in footer_context
|
||||
]
|
||||
|
||||
# Render pages - iterate through pages in order
|
||||
for i in range(1, num_pages + 1):
|
||||
page_key = f"page_{i}"
|
||||
# Render pages based on mapping
|
||||
for idx, (original_page_num, template_name, minimal_page_num) in enumerate(page_mapping):
|
||||
# For combined page_19_20_minimal, use the combined context
|
||||
if template_name == "page_19_20_minimal.html":
|
||||
page_key = "page_19_20_minimal"
|
||||
else:
|
||||
page_key = f"page_{original_page_num}"
|
||||
context = contexts.get(page_key, {})
|
||||
template = self.env.get_template(f"page_{i}.html").render(context)
|
||||
template = self.env.get_template(template_name).render(context)
|
||||
|
||||
if i > 2:
|
||||
# Pages 1 and 2 don't have headers/footers in full report
|
||||
# In minimal report, only page 1 doesn't have header/footer
|
||||
page_num_in_report = minimal_page_num if report_type == "minimal" else original_page_num
|
||||
if page_num_in_report > 2:
|
||||
full_html = f"""
|
||||
<div class="page flex flex-col justify-between">
|
||||
<div>
|
||||
@@ -214,7 +242,7 @@ class ReportGeneratorService:
|
||||
{template}
|
||||
</main>
|
||||
<div class="border-t text-center text-sm text-gray-600">
|
||||
{footer_html_list[i - 1]}
|
||||
{footer_html_list[idx]}
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
@@ -300,6 +328,7 @@ class ReportGeneratorService:
|
||||
output_filename: str = None,
|
||||
metric_overrides: Optional[Dict[str, Any]] = None,
|
||||
oxygenation_csv_path: Optional[str] = None,
|
||||
report_type: str = "full",
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Generate complete medical report from uploaded files.
|
||||
@@ -535,6 +564,7 @@ class ReportGeneratorService:
|
||||
graphs_dict,
|
||||
metric_overrides=metric_overrides,
|
||||
graph_generator=self.graph_generator,
|
||||
report_type=report_type,
|
||||
)
|
||||
|
||||
# Step 5: Calculate analysis metrics
|
||||
@@ -542,7 +572,7 @@ class ReportGeneratorService:
|
||||
analysis_data["graphs_count"] = len(graphs_generated)
|
||||
|
||||
# Step 6: Generate HTML
|
||||
html_content = self.generate_html(patient_info, contexts)
|
||||
html_content = self.generate_html(patient_info, contexts, report_type=report_type)
|
||||
|
||||
# Step 7: Generate PDF
|
||||
if output_filename is None:
|
||||
|
||||
Reference in New Issue
Block a user