191 lines
6.3 KiB
Python
191 lines
6.3 KiB
Python
import datetime
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
class PageGenerator:
|
|
def __init__(self, pnoe_df: pd.DataFrame, seca_df: pd.DataFrame, spirometry_df: pd.DataFrame, patient_info: dict):
|
|
self.pnoe_df = pnoe_df
|
|
self.seca_df = seca_df
|
|
self.spirometry_df = spirometry_df
|
|
self.patient_info = patient_info
|
|
|
|
|
|
def page_1_context(self):
|
|
# Extract patient information
|
|
patient_name = self.patient_info.get("patient_name", "N/A")
|
|
context = {
|
|
"first_name": patient_name.split()[0] if patient_name else "N/A",
|
|
"surname": patient_name.split()[-1] if patient_name else "N/A",
|
|
"date": datetime.datetime.now().strftime("%B %d, %Y"),
|
|
}
|
|
|
|
return context
|
|
|
|
def page_3_context(self):
|
|
# Example: Extract detailed PNOE data for page 3
|
|
pnoe_details = self.pnoe_df.head(10).to_dict(orient="records")
|
|
|
|
context = {
|
|
"pnoe_details": pnoe_details,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_4_context(self):
|
|
# Example: Extract detailed Spirometry data for page 4
|
|
# Filter df_2 for Keirstyn Moran
|
|
patient_data = self.patient_info[self.patient_info['LastName'].str.contains('Moran', case=False, na=False)]
|
|
fat_percentage = patient_data['Adult_FMP'].iloc[0]
|
|
weight_kg = patient_data['Weight'].iloc[0]
|
|
lean_percentage = 100 - fat_percentage
|
|
|
|
fat_mass_lbs = weight_kg * (fat_percentage / 100) * 2.20462
|
|
lean_mass_lbs = weight_kg * (lean_percentage / 100) * 2.20462
|
|
|
|
total_weight = fat_mass_lbs + lean_mass_lbs
|
|
fat_percentage = (fat_mass_lbs / total_weight) * 100
|
|
lean_percentage = (lean_mass_lbs / total_weight) * 100
|
|
|
|
sizes = [fat_percentage, lean_percentage]
|
|
colors = ['#fde3ac', '#ff9966'] # Light yellow/tan and orange from the image
|
|
|
|
plt.figure(figsize=(8, 8))
|
|
|
|
wedges, texts, autotexts = plt.pie(sizes, autopct='', startangle=90, wedgeprops=dict(width=0.5, edgecolor='w'), colors=colors, labels=['', '']) # Remove default labels
|
|
|
|
plt.text(-1, 1, f'Fat Mass ({fat_mass_lbs:.1f}lbs)\n{fat_percentage:.1f}%',
|
|
fontsize=14, fontweight='bold', ha='center', va='center',
|
|
bbox=dict(boxstyle="round,pad=0.3", facecolor='white', alpha=0.8))
|
|
|
|
plt.text(1, -1, f'Lean Mass ({lean_mass_lbs:.1f}lbs)\n{lean_percentage:.1f}%',
|
|
fontsize=14, fontweight='bold', ha='center', va='center',
|
|
bbox=dict(boxstyle="round,pad=0.3", facecolor='white', alpha=0.8))
|
|
|
|
plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle
|
|
spirometry_details = self.spirometry_df.head(10).to_dict(orient="records")
|
|
|
|
context = {
|
|
"spirometry_details": spirometry_details,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_5_context(self):
|
|
# Example: Summary and conclusions for page 5
|
|
summary = {
|
|
"pnoe_summary": self.pnoe_df.describe().to_dict(),
|
|
"seca_summary": self.seca_df.describe().to_dict(),
|
|
"spirometry_summary": self.spirometry_df.describe().to_dict(),
|
|
}
|
|
|
|
context = {
|
|
"summary": summary,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_6_context(self):
|
|
# Example: Recommendations based on data for page 6
|
|
recommendations = [
|
|
"Increase cardiovascular training.",
|
|
"Incorporate strength training twice a week.",
|
|
"Monitor respiratory function regularly.",
|
|
]
|
|
|
|
context = {
|
|
"recommendations": recommendations,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_7_context(self):
|
|
# Example: Additional notes or references for page 7
|
|
notes = "This report is generated based on the provided data. Consult a healthcare professional for personalized advice."
|
|
|
|
context = {
|
|
"notes": notes,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_8_context(self):
|
|
# Example: Contact information and disclaimers for page 8
|
|
contact_info = {
|
|
"clinic_name": "Health Clinic",
|
|
"address": "123 Wellness St, Healthy City, HC 12345",
|
|
"phone": "(123) 456-7890",
|
|
"email": "contact@healthclinic.com"
|
|
}
|
|
|
|
context = {
|
|
"contact_info": contact_info,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_9_context(self):
|
|
# Example: Graphs and visualizations for page 9
|
|
graphs = [
|
|
"graph1.png",
|
|
"graph2.png",
|
|
"graph3.png"
|
|
]
|
|
|
|
context = {
|
|
"graphs": graphs,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_10_context(self):
|
|
# Example: Final remarks and next steps for page 10
|
|
final_remarks = "Thank you for using our health assessment services. We look forward to assisting you in your health journey."
|
|
|
|
context = {
|
|
"final_remarks": final_remarks,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_11_context(self):
|
|
# Example: Additional resources and references for page 11
|
|
resources = [
|
|
{"title": "Healthy Living Guide", "link": "http://example.com/healthy-living"},
|
|
{"title": "Exercise Tips", "link": "http://example.com/exercise-tips"},
|
|
{"title": "Nutrition Advice", "link": "http://example.com/nutrition-advice"}
|
|
]
|
|
|
|
context = {
|
|
"resources": resources,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_12_context(self):
|
|
# Example: Feedback and survey information for page 12
|
|
feedback_info = "We value your feedback. Please visit http://example.com/feedback to share your experience."
|
|
|
|
context = {
|
|
"feedback_info": feedback_info,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_13_context(self):
|
|
# Example: Acknowledgments and credits for page 13
|
|
acknowledgments = "This report was generated using data analysis techniques and the expertise of our medical team."
|
|
|
|
context = {
|
|
"acknowledgments": acknowledgments,
|
|
}
|
|
|
|
return context
|
|
|
|
def page_18_context(self):
|
|
# Example: Legal disclaimers and terms for page 18
|
|
legal_disclaimer = "This report is for informational purposes only and does not constitute medical advice."
|
|
|
|
context = {
|
|
"legal_disclaimer": legal_disclaimer,
|
|
}
|
|
|
|
return context |