datamarathon / AHHF-team

1 stars 0 forks source link

SQL data selection #1

Open MarcusVollmer opened 10 years ago

MarcusVollmer commented 10 years ago

SELECT ad."SUBJECT_ID" AS SUBJ_ID, ha."HADM_ID" HADM_ID, ha."ADMIT_DT" ADMIT_DT, cs."CARDIAC_ARRHYTHMIAS" cardiac_arrhythmias, cs."CONGESTIVE_HEART_FAILURE" CONGESTIVE_HEART_FAILURE, ad."CUID" cuid

FROM "MIMIC2V26"."additives" ad, "MIMIC2V26"."comorbidity_scores" cs, "MIMIC2V26"."admissions" ha

WHERE cs."CONGESTIVE_HEART_FAILURE" > 0 --and ad."CUID" = 1 -- Care unit id == CCU and ad."SUBJECT_ID"=cs."SUBJECT_ID" and ad."SUBJECT_ID"=ha."SUBJECT_ID"

ORDER BY ad."SUBJECT_ID"

MarcusVollmer commented 10 years ago

I have access to the MIMIC2 database and installed the virtual box. I started a new query with PostGreSQL. Here is an image from the graphical query builder:

gqb_1

The corresponding SQL code is:

COPY( SELECT demographic_detail.subject_id, demographic_detail.hadm_id, demographic_detail.marital_status_itemid, demographic_detail.marital_status_descr, demographic_detail.ethnicity_itemid, demographic_detail.ethnicity_descr, demographic_detail.overall_payor_group_itemid, demographic_detail.overall_payor_group_descr, demographic_detail.religion_itemid, demographic_detail.religion_descr, demographic_detail.admission_type_itemid, demographic_detail.admission_type_descr, demographic_detail.admission_source_itemid, demographic_detail.admission_source_descr, censusevents.careunit, censusevents.destcareunit, censusevents.census_id, censusevents.los, censusevents.dischstatus, censusevents.outtime, censusevents.intime, censusevents.icustay_id, admissions.admit_dt, admissions.disch_dt, icustayevents.intime, icustayevents.outtime, icustayevents.los, icustayevents.first_careunit, icustayevents.last_careunit FROM mimic2v26.demographic_detail, mimic2v26.comorbidity_scores, mimic2v26.censusevents, mimic2v26.admissions, mimic2v26.icustayevents WHERE comorbidity_scores.subject_id = demographic_detail.subject_id AND comorbidity_scores.hadm_id = demographic_detail.hadm_id AND censusevents.subject_id = demographic_detail.subject_id AND admissions.hadm_id = demographic_detail.hadm_id AND admissions.subject_id = demographic_detail.subject_id AND icustayevents.icustay_id = censusevents.icustay_id AND icustayevents.subject_id = censusevents.subject_id AND comorbidity_scores.congestive_heart_failure > 0 AND (censusevents.careunit = 1 OR censusevents.destcareunit = 1 OR icustayevents.first_careunit = 1 OR icustayevents.last_careunit = 1) ) TO '/home/mimic2/VM/10212014_stays.csv' DELIMITER ',' CSV HEADER;

At the critical care marathon the selection was made using the CUID of the "medication" table. I used "icustayevents" and "censusevents", in which care unit transfers were saved as well as the first and last care unit. Searching for subject_IDs with congestive heart failure and treated on CCU during some hospital stay will give us now 2003 different patients.

silviu0 commented 10 years ago

Marcus, this is excellent! We should extract the vitals and lab values of these patients at admission and discharge.