Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom procedures method that joins on d_procedures #6

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading