Skip to content

Instantly share code, notes, and snippets.

@docsteveharris
Last active November 25, 2019 14:48
Show Gist options
  • Save docsteveharris/d0a4909e5186f6dbf098c86a08345293 to your computer and use it in GitHub Desktop.
Save docsteveharris/d0a4909e5186f6dbf098c86a08345293 to your computer and use it in GitHub Desktop.
Returns open visit_occurences (without and visit_end_datetime) for T03 #emap #uclh
--SELECT * FROM omop_live.care_site WHERE care_site_name LIKE 'T03%' order by care_site_name;
--JOIN done manually because otherwise runs really slowly
SELECT
vd.person_id,
vd.visit_detail_id,
vd.visit_occurrence_id,
-- cs.care_site_id,
-- cs.care_site_name,
vd.visit_start_datetime,
vd.visit_end_datetime,
vd.care_site_id,
GREATEST(vd.visit_start_datetime, vd.visit_end_datetime) visit_last_update
FROM omop_live.visit_detail as vd
-- LEFT JOIN omop_live.care_site as cs
-- ON vd.care_site_id = vd.care_site_id
WHERE vd.visit_end_datetime ISNULL
AND
vd.care_site_id IN (
289048375
,286779401
,286578016
,287018166
,286756747
,286616494
,286735943
,286606043
,286607864
,286387095
,286414100
,286602366
,286420073
,286596953
,286404254
,286441911
,286419486
,286438461
,286459032
,286537491
,286460240
,286380854
,286499847
,286434532
,286390642
,286434146
,286589967
,286601872
,286472148
,286706005
,286589952
,286735946
,286518748
,286739282
,286463743
,286396967
,286377109
)
ORDER BY visit_last_update desc ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment