Skip to content

Commit

Permalink
Add custom procedures method that joins on d_procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
amrit110 committed Nov 30, 2023
1 parent 813bdee commit 85110da
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 145 deletions.
31 changes: 30 additions & 1 deletion cycquery/mimiciv.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def patients(

return QueryInterface(self.db, table)

def diagnoses(
def diagnoses_icd(
self,
) -> QueryInterface:
"""Query MIMIC diagnosis data.
Expand Down Expand Up @@ -116,6 +116,35 @@ def diagnoses(

return QueryInterface(self.db, table)

def procedures_icd(
self,
) -> QueryInterface:
"""Query MIMIC diagnosis data.
Parameters
----------
join
Join arguments.
ops
Additional operations to apply to the query.
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 85110da

Please sign in to comment.