You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: etl/StandardizedClinicalDataTables/MEASUREMENT/etl.sql
-125
Original file line number
Diff line number
Diff line change
@@ -734,74 +734,6 @@ OR -- middle
734
734
(is_last IS FALSE AND is_first IS FALSE ANDrow_to_insert.measurement_datetime>visit_detail_assign.visit_start_datetimeANDrow_to_insert.measurement_datetime<=visit_detail_assign.visit_end_datetime)
735
735
);
736
736
737
-
-- Derived values from labeevent
738
-
739
-
with
740
-
"patients"AS (SELECT mimic_id AS person_id, subject_id FROM patients),
741
-
"admissions"AS (SELECT mimic_id AS visit_occurrence_id, hadm_id FROM admissions),
742
-
"gcpt_lab_unit_to_concept"AS (SELECT unit as unit_source_value, concept_id as unit_concept_id FROM gcpt_lab_unit_to_concept),
743
-
"gcpt_derived_to_concept"as (select measurement_source_value, itemid, mimic_id as measurement_source_concept_id, concept_id as measurement_concept_id from gcpt_derived_to_concept),
744
-
"row_to_insert"as (
745
-
SELECT
746
-
nextval('mimic_id_seq') as measurement_id
747
-
, person_id
748
-
, coalesce(measurement_concept_id, 0) as measurement_concept_id -- mapped
749
-
, charttime::dateas measurement_date
750
-
, charttime::timestampas measurement_datetime
751
-
, 45754907as measurement_type_concept_id --derived value
752
-
, 4172703as operator_concept_id -- =
753
-
, valuenum as value_as_number
754
-
, CASE WHEN flag ='abnormal' THEN 45878745--abnormal
755
-
ELSE NULL END as value_as_concept_id -- this shouldn't actually be here, no way to put this information into range too
(is_first IS TRUE AND is_last IS FALSE ANDrow_to_insert.measurement_datetime<=visit_detail_assign.visit_end_datetime)
800
-
OR-- last
801
-
(is_last IS TRUE AND is_first IS FALSE ANDrow_to_insert.measurement_datetime>visit_detail_assign.visit_start_datetime)
802
-
OR-- middle
803
-
(is_last IS FALSE AND is_first IS FALSE ANDrow_to_insert.measurement_datetime>visit_detail_assign.visit_start_datetimeANDrow_to_insert.measurement_datetime<=visit_detail_assign.visit_end_datetime)
804
-
);
805
737
806
738
-- weight from inputevent_mv
807
739
@@ -872,60 +804,3 @@ OR -- middle
872
804
)
873
805
;
874
806
875
-
-- Derived values from noteevents
876
-
877
-
with
878
-
"patients"AS (SELECT mimic_id AS person_id, subject_id FROM patients),
879
-
"admissions"AS (SELECT mimic_id AS visit_occurrence_id, hadm_id FROM admissions),
880
-
"gcpt_derived_to_concept"as (select measurement_source_value, itemid, mimic_id as measurement_source_concept_id, concept_id as measurement_concept_id from gcpt_derived_to_concept),
881
-
"row_to_insert"as (
882
-
SELECT
883
-
nextval('mimic_id_seq') as measurement_id
884
-
, person_id
885
-
, coalesce(measurement_concept_id, 0) as measurement_concept_id -- mapped
886
-
, charttime::dateas measurement_date
887
-
, charttime::timestampas measurement_datetime
888
-
, 45754907as measurement_type_concept_id --derived value
889
-
, CASE WHEN exact_value IS NOT NULL THEN 4172703--=
890
-
WHEN inf_egal_value IS NOT NULL THEN 4171756--<
891
-
WHEN sup_egal_value IS NOT NULL THEN 4172704 END -->
892
-
as operator_concept_id
893
-
, coalesce(exact_value, inf_egal_value, sup_egal_value) as value_as_number
"patients"AS (SELECT mimic_id AS person_id, subject_id FROM patients),
5
+
"admissions"AS (SELECT mimic_id AS visit_occurrence_id, hadm_id FROM admissions),
6
+
"gcpt_lab_unit_to_concept"AS (SELECT unit as unit_source_value, concept_id as unit_concept_id FROM gcpt_lab_unit_to_concept),
7
+
"gcpt_derived_to_concept"as (select measurement_source_value, itemid, mimic_id as measurement_source_concept_id, concept_id as measurement_concept_id from gcpt_derived_to_concept),
8
+
"row_to_insert"as (
9
+
SELECT
10
+
nextval('mimic_id_seq') as measurement_id
11
+
, person_id
12
+
, coalesce(measurement_concept_id, 0) as measurement_concept_id -- mapped
13
+
, charttime::dateas measurement_date
14
+
, charttime::timestampas measurement_datetime
15
+
, 45754907as measurement_type_concept_id --derived value
16
+
, 4172703as operator_concept_id -- =
17
+
, valuenum as value_as_number
18
+
, CASE WHEN flag ='abnormal' THEN 45878745--abnormal
19
+
ELSE NULL END as value_as_concept_id -- this shouldn't actually be here, no way to put this information into range too
(is_first IS TRUE AND is_last IS FALSE ANDrow_to_insert.measurement_datetime<=visit_detail_assign.visit_end_datetime)
64
+
OR-- last
65
+
(is_last IS TRUE AND is_first IS FALSE ANDrow_to_insert.measurement_datetime>visit_detail_assign.visit_start_datetime)
66
+
OR-- middle
67
+
(is_last IS FALSE AND is_first IS FALSE ANDrow_to_insert.measurement_datetime>visit_detail_assign.visit_start_datetimeANDrow_to_insert.measurement_datetime<=visit_detail_assign.visit_end_datetime)
68
+
);
69
+
70
+
-- Derived values from noteevents
71
+
72
+
with
73
+
"patients"AS (SELECT mimic_id AS person_id, subject_id FROM patients),
74
+
"admissions"AS (SELECT mimic_id AS visit_occurrence_id, hadm_id FROM admissions),
75
+
"gcpt_derived_to_concept"as (select measurement_source_value, itemid, mimic_id as measurement_source_concept_id, concept_id as measurement_concept_id from gcpt_derived_to_concept),
76
+
"row_to_insert"as (
77
+
SELECT
78
+
nextval('mimic_id_seq') as measurement_id
79
+
, person_id
80
+
, coalesce(measurement_concept_id, 0) as measurement_concept_id -- mapped
81
+
, charttime::dateas measurement_date
82
+
, charttime::timestampas measurement_datetime
83
+
, 45754907as measurement_type_concept_id --derived value
84
+
, CASE WHEN exact_value IS NOT NULL THEN 4172703--=
85
+
WHEN inf_egal_value IS NOT NULL THEN 4171756--<
86
+
WHEN sup_egal_value IS NOT NULL THEN 4172704 END -->
87
+
as operator_concept_id
88
+
, coalesce(exact_value, inf_egal_value, sup_egal_value) as value_as_number
0 commit comments