| patient_id | condition_id | performed_at | code_system | code_code | code_display |
|---|---|---|---|---|---|
| Patient/8adbf3e4-47ff-561e-b1b6-746ee32e056d | Procedure/71664e0b-2062-5998-b88e-4b60f961aae8 | 2150-06-03T00:00:00-04:00 | http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-procedure-icd9 | 5124 | Laparoscopic partial cholecystectomy |
| Patient/568cb149-804c-59e8-bdf5-816e8151cd22 | Procedure/69621df5-b36b-5959-a3df-d3081045754b | 2196-06-14T00:00:00-04:00 | http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-procedure-icd9 | 5123 | Laparoscopic cholecystectomy |
Last active
September 7, 2025 00:19
-
-
Save johngrimes/2b230c4a3a04c3075d5890ce2fd5b9eb to your computer and use it in GitHub Desktop.
MIMIC-IV example - patients with laparascopic cholecystectomy procedure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pathling import PathlingContext | |
| import re | |
| pc = PathlingContext.create() | |
| data = pc.read.ndjson( | |
| "/tmp/mimic-iv-clinical-database-demo-on-fhir-2.1.0/fhir", | |
| file_name_mapper=lambda file_name: re.findall( | |
| r"Mimic(\w+?)(?:ED|ICU|" | |
| r"Chartevents|Datetimeevents|Labevents|MicroOrg|MicroSusc|MicroTest|" | |
| r"Outputevents|Lab|Mix|VitalSigns|VitalSignsED)?$", | |
| file_name, | |
| ), | |
| ) | |
| patient = data.view( | |
| "Patient", | |
| select=[ | |
| { | |
| "column": [ | |
| { | |
| "name": "patient_id", | |
| "path": "getResourceKey()", | |
| "description": "Unique identifier for the patient", | |
| } | |
| ] | |
| } | |
| ], | |
| ) | |
| laparoscopic_cholecystectomy = data.view( | |
| "Procedure", | |
| select=[ | |
| { | |
| "column": [ | |
| { | |
| "name": "condition_id", | |
| "path": "getResourceKey()", | |
| "description": "Unique identifier for the procedure", | |
| }, | |
| { | |
| "name": "patient_id", | |
| "path": "subject.getReferenceKey()", | |
| "description": "Reference to the patient who underwent the procedure", | |
| }, | |
| { | |
| "name": "performed_at", | |
| "path": "performed.ofType(dateTime)", | |
| "description": "Date and time when the procedure was performed", | |
| }, | |
| ] | |
| }, | |
| { | |
| "forEach": "code.coding", | |
| "column": [ | |
| { | |
| "name": "code_system", | |
| "path": "system", | |
| "description": "The code system that defines the procedure code", | |
| }, | |
| { | |
| "name": "code_code", | |
| "path": "code", | |
| "description": "The procedure code value", | |
| }, | |
| { | |
| "name": "code_display", | |
| "path": "display", | |
| "description": "Human-readable description of the procedure", | |
| }, | |
| ], | |
| }, | |
| ], | |
| where=[ | |
| { | |
| "path": "code.coding.where(system = 'http://mimic.mit.edu/fhir/mimic/CodeSystem/mimic-procedure-icd9').exists(code = '5123' or code = '5124')", | |
| "description": "Filter for laparoscopic cholecystectomy procedures (ICD-9 codes 51.23 and 51.24)", | |
| } | |
| ], | |
| ) | |
| result = patient.join(laparoscopic_cholecystectomy, on="patient_id") | |
| result.show(truncate=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment