ycq091044 / SafeDrug

IJCAI2021: Code for SafeDrug, MIMIC data processing, Medical code mapping
67 stars 16 forks source link

Question about the visit order for a single patient #5

Closed Gkunnan97 closed 2 years ago

Gkunnan97 commented 2 years ago

Hello, I have a question about the data processing procedure written in 'data/processing.py' : for a single patient, how to keep the visit sequence is ordered by the visit time? Because downstream task(medication prediction for the patient's t-th visit) and the longitudinal patient representation module, I think time-ordered visit sequence is necessary. And it should be ordered by the 'ADMITTIME' in admissions table of the mimic-iii dataset. Maybe I don't understand the code and the mimic-iii dataset enough. Thanks in advance.

ycq091044 commented 2 years ago

Thanks for asking this question. The patient-level visits are in order!

Please check our processing.py. During preprocessing, the very high-level logic is to merge the diagnosis table, procedure table, and medication table on the patient ID and visit ID. In the MIMIC dataset, the patient ID is "SUBJECT_ID" and the visit ID is "HADM_ID". Please refer to https://mimic.mit.edu/docs/iii/tables/

In line 22, line 73, and line 91, we sort the medication, diagnosis, and procedure tables, separately, by subject and visit order, and then merge them together. Thus, the patient-level visits are guaranteed to be in order.

Gkunnan97 commented 2 years ago

Thanks for your reply. But I am still confused with the sort operation. Because, for a single patient, the order of 'HADM_ID' is not consistent with the visit order. For the patient whose 'SUBJECT_ID' is 17: grep ',17,' ADMISSIONS.csv will get:

'HADM_ID' (column 3) and 'ADMITTIME' (column 4) are in reverse order. Howerver, when 'SUBJECT_ID' is 21, grep ',21,' ADMISSIONS.csv will get:

the order of 'HADM_ID' is the same with 'ADMITIME'

So, I thick that it may not be possible to maintain the visit order only by the sort operation with 'HADM_ID'. Thanks in advance.