Phenotyping
fyron.phenotyping builds transparent rule-based clinical phenotypes from tabular FHIR-derived or registry-style data. Use it when diagnosis codes, procedure codes, lab thresholds, or medication exposure rows need to become patient-level cohort flags.
Phenotyping rules are explicit definitions, not validated clinical truth. Keep the rule inputs, code lists, thresholds, and evidence counts with the analysis so clinicians and reviewers can inspect what happened.
For broad ICD-10 disease groups, German OPS procedure categories, delimited code parsing, and date interval columns, see DataFrame Operations. Use fyron.phenotyping when the study needs explicit rule definitions with evidence counts and patient-level flags.
Imports
from fyron import phenotyping as fphFunction Reference
| Function | Required | Optional | Returns |
|---|---|---|---|
define_code_phenotype | table, code column, codes | patient/date/code-system columns, phenotype name | patient-level phenotype table |
define_lab_threshold_phenotype | table, value column, threshold | direction, patient/date columns, phenotype name | patient-level phenotype table |
define_medication_exposure | table, medication column, medications | patient/start/end columns, phenotype name | patient-level exposure table |
combine_phenotypes | phenotype tables | strategy="any" or "all" | combined patient-level table |
phenotype_summary | phenotype table, phenotype column | patient/group columns | prevalence summary table |
Code Phenotype
condition_flag = fph.define_code_phenotype(
conditions,
code_col="code",
codes=["I50", "I50.1"],
patient_col="patient_id",
date_col="recorded_date",
code_system_col="system",
code_systems=["ICD-10"],
phenotype_name="heart_failure",
)Outputs include patient_id, heart_failure, evidence_count, evidence_values, and optional first_date / last_date.
Lab Threshold Phenotype
anemia = fph.define_lab_threshold_phenotype(
observations,
value_col="hemoglobin",
threshold=12.0,
direction="<",
date_col="effective_datetime",
phenotype_name="anemia",
)Medication Exposure
exposure = fph.define_medication_exposure(
medications,
medication_col="medication_name",
medications=["cisplatin", "carboplatin"],
start_col="start_date",
end_col="end_date",
phenotype_name="platinum_exposure",
)Combine Rules
case_definition = fph.combine_phenotypes(
[condition_flag, anemia],
strategy="any",
phenotype_name="study_case",
)
summary = fph.phenotype_summary(
case_definition.merge(cohort[["patient_id", "sex"]], on="patient_id"),
phenotype_col="study_case",
group_col="sex",
)Common Pitfalls
- Store the exact code lists used for a study.
- Review date windows before interpreting first/last evidence dates.
- Treat medication names/codes as site-specific unless they come from normalized terminology.
- Validate rule outputs on a small manually reviewed sample before modeling.