Another Solid Checkpoint
This commit is contained in:
@@ -524,9 +524,36 @@ class ReportGeneratorService:
|
||||
}
|
||||
rmr_metrics = temp_context_gen.calculate_rmr_and_fuel_source()
|
||||
|
||||
# Generate metabolism chart
|
||||
# Convert height to cm if available
|
||||
height_cm = None
|
||||
height_str = patient_info.get("height", "")
|
||||
if height_str:
|
||||
try:
|
||||
# Try to parse height string (e.g., "5'4"", "165cm", "165")
|
||||
import re
|
||||
# Check if it's in feet'inches" format
|
||||
feet_inches_match = re.match(r"(\d+)'(\d+)\"", height_str)
|
||||
if feet_inches_match:
|
||||
feet = int(feet_inches_match.group(1))
|
||||
inches = int(feet_inches_match.group(2))
|
||||
height_cm = (feet * 12 + inches) * 2.54
|
||||
# Check if it ends with cm
|
||||
elif "cm" in height_str.lower():
|
||||
height_cm = float(re.sub(r"[^\d.]", "", height_str))
|
||||
# Otherwise try to parse as number (assume cm)
|
||||
else:
|
||||
height_cm = float(re.sub(r"[^\d.]", "", height_str))
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
|
||||
# Generate metabolism chart with ratio calculation if we have all parameters
|
||||
metabolism_chart_b64 = self.graph_generator.generate_metabolism_chart(
|
||||
rmr_metrics["rmr_kcal"], save_as_base64=True
|
||||
rmr_metrics["rmr_kcal"],
|
||||
weight_kg=weight_kg,
|
||||
height_cm=height_cm,
|
||||
age_years=patient_info.get("age", None),
|
||||
sex=gender,
|
||||
save_as_base64=True,
|
||||
)
|
||||
graphs_dict["metabolism_chart"] = metabolism_chart_b64
|
||||
|
||||
|
||||
Reference in New Issue
Block a user