Skip to content

Commit

Permalink
Merge pull request #6 from VectorInstitute/add_procedures_method_mimiciv
Browse files Browse the repository at this point in the history
Add custom procedures method that joins on d_procedures
  • Loading branch information
amrit110 authored Nov 30, 2023
2 parents 813bdee + d65e53b commit 15f0b34
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 154 deletions.
31 changes: 23 additions & 8 deletions cycquery/mimiciv.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,11 @@ def patients(

return QueryInterface(self.db, table)

def diagnoses(
def diagnoses_icd(
self,
) -> QueryInterface:
"""Query MIMIC diagnosis data.
Parameters
----------
join
Join arguments.
ops
Additional operations to apply to the query.
Returns
-------
cycquery.interface.QueryInterface
Expand All @@ -116,6 +109,28 @@ def diagnoses(

return QueryInterface(self.db, table)

def procedures_icd(
self,
) -> QueryInterface:
"""Query MIMIC procedures data.
Returns
-------
cycquery.interface.QueryInterface
Constructed query, wrapped in an interface object.
"""
table = self.get_table("mimiciv_hosp", "procedures_icd")

# Join with procedures dimension table.
table = qo.Join(
join_table=self.get_table("mimiciv_hosp", "d_icd_procedures"),
on=["icd_code", "icd_version"],
on_to_type=["str", "int"],
)(table)

return QueryInterface(self.db, table)

def labevents(
self,
) -> QueryInterface:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/mimiciv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
" qo.ConditionInYears(\"admittime\", \"2015\"),\n",
")\n",
"patient_admissions = patient_admissions.ops(ops)\n",
"diagnoses = querier.diagnoses()\n",
"diagnoses = querier.diagnoses_icd()\n",
"diagnoses_ops = qo.Sequential(\n",
" qo.ConditionEquals(\"icd_version\", 10),\n",
" qo.ConditionSubstring(\"long_title\", \"schizophrenia\"),\n",
Expand Down Expand Up @@ -143,7 +143,7 @@
" qo.ConditionInYears(\"admittime\", \"2015\"),\n",
")\n",
"patient_admissions = patient_admissions.ops(ops)\n",
"diagnoses = querier.diagnoses()\n",
"diagnoses = querier.diagnoses_icd()\n",
"diagnoses_ops = qo.Sequential(\n",
" qo.ConditionEquals(\"icd_version\", 9),\n",
" qo.ConditionRegexMatch(\"long_title\", r\"(?=.*schizophrenia)(?=.*chronic)\"),\n",
Expand Down
Loading

0 comments on commit 15f0b34

Please sign in to comment.