File size: 1,519 Bytes
411a994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import pandas as pd
from app.services.cameroon_data import CameroonMedicalData


def test_service_handles_missing_csv(tmp_path):
    svc = CameroonMedicalData(csv_path=str(tmp_path / "missing.csv"))
    svc.clean()
    assert svc.stats_overview()["total_rows"] == 0


def test_basic_stats(tmp_path):
    # Build a tiny CSV
    df = pd.DataFrame([
        {"summary_id": "1", "patient_id": "p1", "patient_age": 25, "patient_gender": "M", "diagnosis": "Paludisme",
         "body_temp_c": 38.5, "blood_pressure_systolic": 120, "heart_rate": 90, "summary_text": "Fievre et frissons",
         "date_recorded": "2024-01-10"},
        {"summary_id": "2", "patient_id": "p2", "patient_age": 7, "patient_gender": "F", "diagnosis": "Typhoide",
         "body_temp_c": 39.2, "blood_pressure_systolic": 110, "heart_rate": 95, "summary_text": "Fièvre, maux de ventre",
         "date_recorded": "2024-02-15"}
    ])
    csv_path = tmp_path / "clinical_summaries.csv"
    df.to_csv(csv_path, index=False)

    svc = CameroonMedicalData(csv_path=str(csv_path))
    svc.clean()
    ov = svc.stats_overview()
    assert ov["total_rows"] == 2
    assert "paludisme" in ov["top_diagnoses"] or "typhoide" in ov["top_diagnoses"]

    disease = svc.stats_disease("paludisme")
    assert disease["disease"] == "paludisme"

    seasonal = svc.seasonal_patterns()
    assert isinstance(seasonal, dict)

    age_gender = svc.age_gender_distribution()
    assert "age_buckets" in age_gender and "gender_distribution" in age_gender