Skip to content

Commit

Permalink
adding the counts
Browse files Browse the repository at this point in the history
  • Loading branch information
quan14 committed Jan 27, 2025
1 parent b165f3a commit 827aed8
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions analysis/dataset_definition_dx_to_med_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
medications,
)

from codelists import adhd_codelist, methylphenidate_codelist
from codelists import (
adhd_codelist,
adhdrem_codelist,
methylphenidate_codelist
)

def last_matching_event(events, codelist, where=True):
"""Select the last matching SNOMED CT event from specified codelist
Expand All @@ -27,7 +31,7 @@ def last_matching_event(events, codelist, where=True):
)

dataset = create_dataset()
dataset.configure_dummy_data(population_size=10)
dataset.configure_dummy_data(population_size=5)

# Date range
start_date = "2016-04-01"
Expand All @@ -38,7 +42,7 @@ def last_matching_event(events, codelist, where=True):
start_date, end_date
).exists_for_patient()
dataset.sex = patients.sex
dataset.age = patients.age_on(start_date)
dataset.age = patients.age_on(end_date)

# Setting up the dates
selected_events = clinical_events.where(
Expand All @@ -57,6 +61,17 @@ def last_matching_event(events, codelist, where=True):
# Picking the last date for dia and first date for med
dataset.adhd_cod_date = last_matching_event(selected_events, adhd_codelist).date

dataset.has_adhdrem_cod_date = last_matching_event(selected_events, adhdrem_codelist).date

#Number of counts for ADHD diagonsis and readmission
dataset.count_adhd_diagnoses = selected_events.where(
clinical_events.snomedct_code.is_in(adhd_codelist)
).count_for_patient()

dataset.count_adhd_resolved = selected_events.where(
clinical_events.snomedct_code.is_in(adhd_codelist)
).count_for_patient()

dataset.mph_med_date = selected_medications.where(True)\
.where(selected_medications.dmd_code.is_in(methylphenidate_codelist))\
.sort_by(selected_medications.date)\
Expand All @@ -73,5 +88,6 @@ def last_matching_event(events, codelist, where=True):
& patients.is_alive_on(start_date)
& dataset.adhd_cod_date.is_not_null()
& dataset.mph_med_date.is_not_null()
& (dataset.has_adhdrem_cod_date <= dataset.adhd_cod_date)
& (dataset.adhd_cod_date <= dataset.mph_med_date)
)

0 comments on commit 827aed8

Please sign in to comment.