drug_exposure_end_date
CDS Drug Exposure
Source column ExposureEndDate
. Converts text to dates.
ExposureEndDate
End date of the episode, if exists, else the spell discharge date, if exists, else the message date. CDS ACTIVITY DATE, END DATE (EPISODE), DISCHARGE DATE (HOSPITAL PROVIDER SPELL)
select
distinct
l1.RecordConnectionIdentifier,
l1.NHSNumber as nhs_number,
drugs.Code as DrugSourceValue,
coalesce(l5.EpisodeStartDate, l5.StartDateHospitalProviderSpell, l1.CDSActivityDate) as ExposureStartDate,
coalesce(l5.EpisodeEndDate, l5.DischargeDateHospitalProviderSpell, l1.CDSActivityDate) as ExposureEndDate,
case
when l5.EpisodeEndDate is null and l5.DischargeDateHospitalProviderSpell is null then 32220
else 32818
end as DrugTypeConceptId
from [omop_staging].[cds_line01] l1
inner join [omop_staging].[cds_high_cost_drugs] drugs
on l1.MessageId = drugs.MessageId
inner join [omop_staging].[cds_line04] l4
on l4.MessageId = l1.MessageId
left join [omop_staging].[cds_line05] l5
on l5.MessageId = l1.MessageId