Download tests/test_db.py from Fuzure/sheami: direct link, hf CLI and curl.
- Browser
- Download file 2.28 kB
-
https://huggingface.co/spaces/Fuzure/sheami/resolve/main/tests/test_db.py
- Command line
-
hf download hf://spaces/Fuzure/sheami/tests/test_db.py
-
curl -L -o test_db.py https://huggingface.co/spaces/Fuzure/sheami/resolve/main/tests/test_db.py
2.28 kB
| # --------------------------- | |
| # Example usage | |
| # --------------------------- | |
| import json | |
| import os | |
| from dotenv import load_dotenv | |
| from modules.db import SheamiDB | |
| if __name__ == "__main__": | |
| load_dotenv(override=True) | |
| db = SheamiDB(os.getenv("DB_URI")) | |
| # Suppose logged-in user email is known | |
| user = db.get_user_by_email("doctor1@sheami.com") | |
| if user: | |
| user_id = str(user["_id"]) | |
| data = db.get_user_full_data(user_id) | |
| print("data = ",json.dumps(data,indent=1)) | |
| # Now `data` looks like: | |
| # { | |
| # "user": {...}, | |
| # "patients": [ | |
| # { | |
| # "patient": {...}, | |
| # "reports": [...], | |
| # "trends": [...], | |
| # "final_reports": [...] | |
| # }, ... | |
| # ] | |
| # } | |
| print(data) | |
| else: | |
| # Add user | |
| user_id = db.add_user("doctor1@sheami.com", "Dr. Smith") | |
| # Add patient | |
| patient_id = db.add_patient(user_id, "John Doe", "1980-05-20", "male") | |
| # Add report | |
| parsed_data = { | |
| "tests": [ | |
| {"name": "Hemoglobin", "value": 13.5, "unit": "g/dL", "reference_range": "13.0-17.0"}, | |
| {"name": "Cholesterol", "value": 210, "unit": "mg/dL", "reference_range": "<200"} | |
| ] | |
| } | |
| report_id = db.add_report(patient_id, "bloodwork_july.pdf", parsed_data) | |
| # Add trend | |
| db.add_or_update_trend(patient_id, "Hemoglobin", [ | |
| {"date": "2025-05-01", "value": 13.2}, | |
| {"date": "2025-07-01", "value": 13.5}, | |
| {"date": "2025-08-19", "value": 13.8} | |
| ]) | |
| # Add final report | |
| final_report_id = db.add_final_report( | |
| patient_id, | |
| "Hemoglobin stable, cholesterol slightly high.", | |
| ["Maintain healthy diet", "Check cholesterol in 3 months"], | |
| [ | |
| {"test_name": "Hemoglobin", "latest_value": 13.8, "direction": "stable"}, | |
| {"test_name": "Cholesterol", "latest_value": 210, "direction": "increasing"} | |
| ] | |
| ) | |
| print("User ID:", user_id) | |
| print("Patient ID:", patient_id) | |
| print("Report ID:", report_id) | |
| print("Final Report ID:", final_report_id) | |