Spaces:
Running
Running
| """Duplicate therapy checks.""" | |
| from __future__ import annotations | |
| from app.common.types import Medication | |
| from app.knowledge.drug_catalog import DRUG_CLASSES | |
| def has_duplicate_therapy( | |
| meds: list[Medication], | |
| target_drug: str | None, | |
| replacement_drug: str | None, | |
| ) -> bool: | |
| classes = [DRUG_CLASSES.get(m.drug) for m in meds if DRUG_CLASSES.get(m.drug)] | |
| if replacement_drug and DRUG_CLASSES.get(replacement_drug): | |
| classes.append(DRUG_CLASSES[replacement_drug]) | |
| if target_drug and replacement_drug: | |
| # replacement within class is expected; duplicate only when 3+ active in same class. | |
| return any(classes.count(c) >= 3 for c in set(classes)) | |
| return any(classes.count(c) >= 3 for c in set(classes)) | |