Created
February 28, 2019 14:51
-
-
Save kaweesi/763b80c9e1ea9b8b8d9edb5023ab6cba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select p.patient_id | |
from patient p inner join encounter e on e.patient_id=p.patient_id | |
where e.voided=0 and p.voided=0 and e.encounter_type in (5,7) and e.encounter_datetime<=:endDate and e.location_id = :location | |
union | |
select pg.patient_id | |
from patient p inner join patient_program pg on p.patient_id=pg.patient_id | |
where pg.voided=0 and p.voided=0 and program_id=1 and date_enrolled<=:endDate and location_id=:location | |
union | |
select pg.patient_id | |
from patient p | |
inner join patient_program pg on p.patient_id=pg.patient_id | |
inner join patient_state ps on pg.patient_program_id=ps.patient_program_id | |
where pg.voided=0 and ps.voided=0 and p.voided=0 and | |
pg.program_id=1 and ps.state=28 and ps.start_date=pg.date_enrolled and | |
ps.start_date<=:endDate and location_id=:location | |
union | |
select pg.patient_id | |
from patient p | |
inner join patient_program pg on p.patient_id=pg.patient_id | |
inner join patient_state ps on pg.patient_program_id=ps.patient_program_id | |
where pg.voided=0 and ps.voided=0 and p.voided=0 and | |
pg.program_id=2 and ps.state=29 and | |
ps.start_date<=:endDate and location_id=:location |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment