medilang-tech / app /utils /helpers.py
Dama03's picture
first push of the AI
411a994
from cachetools import TTLCache
from typing import Any, Optional
cache = TTLCache(maxsize=512, ttl=60 * 10)
def cache_get(key: str) -> Any | None:
return cache.get(key)
def cache_set(key: str, value: Any) -> None:
cache[key] = value
def medical_disclaimer(language: str) -> str:
if language.lower().startswith("fr"):
return (
"Avertissement: Je ne suis pas un médecin. Les conseils fournis par l'IA peuvent contenir des erreurs. "
"En cas de symptômes graves, consultez un professionnel de santé ou appelez les services d'urgence."
)
return (
"Disclaimer: I am not a medical professional. AI advice can be inaccurate. "
"For serious symptoms, consult a healthcare professional or emergency services."
)
def emergency_triage(text: str) -> bool:
signals = ["chest pain", "poitrine", "hemorrag", "fainting", "inconscient", "stroke", "AVC", "difficulty breathing", "respire"]
lower = text.lower()
return any(s in lower for s in signals)
def normalize_gender(value: str) -> Optional[str]:
if value is None:
return None
v = value.strip().lower()
mapping = {
"m": "male", "male": "male", "man": "male", "masculin": "male", "homme": "male",
"f": "female", "female": "female", "woman": "female", "feminin": "female", "femme": "female"
}
return mapping.get(v, None)
def clean_diagnosis(value: str) -> Optional[str]:
if not value:
return None
v = value.strip().nlower() if hasattr(value, 'nlower') else value.strip().lower()
return v