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
ANDd.drug_concept_id!=0---Our unmapped drug_concept_id's are set to 0, so we don't want different drugs wrapped up in the same era
207
221
ANDcoalesce(d.days_supply,0) >=0---We have cases where days_supply is negative, and this can set the end_date before the start_date, which we don't want. So we're just looking over those rows. This is a data-quality issue.
208
222
)
223
+
select
224
+
*
225
+
into #ctePreDrugTarget
226
+
from ctePreDrugTarget
209
227
210
-
, cteSubExposureEndDates (person_id, ingredient_concept_id, end_date) AS--- A preliminary sorting that groups all of the overlapping exposures into one exposure so that we don't double-count non-gap-days
228
+
CREATENONCLUSTEREDINDEX IDX_ctePreDrugTarget
229
+
ON [#ctePreDrugTarget] ([person_id],[ingredient_concept_id],[drug_exposure_start_date])
230
+
INCLUDE ([drug_exposure_id])
231
+
232
+
;with cteSubExposureEndDates (person_id, ingredient_concept_id, end_date) AS--- A preliminary sorting that groups all of the overlapping exposures into one exposure so that we don't double-count non-gap-days
211
233
(
212
234
SELECT person_id, ingredient_concept_id, event_date AS end_date
, cteSubExposures(row_number, person_id, drug_concept_id, drug_sub_exposure_start_date, drug_sub_exposure_end_date, drug_exposure_count) AS
279
+
;with cteSubExposures(row_number, person_id, drug_concept_id, drug_sub_exposure_start_date, drug_sub_exposure_end_date, drug_exposure_count) AS
257
280
(
258
281
SELECTROW_NUMBER() OVER (PARTITIONBY person_id, drug_concept_id, drug_sub_exposure_end_date ORDER BY person_id)
259
282
, person_id, drug_concept_id, MIN(drug_exposure_start_date) AS drug_sub_exposure_start_date, drug_sub_exposure_end_date, COUNT(*) AS drug_exposure_count
260
-
FROM cteDrugExposureEnds
283
+
FROM#cteDrugExposureEnds
261
284
GROUP BY person_id, drug_concept_id, drug_sub_exposure_end_date
0 commit comments