Skip to content

Instantly share code, notes, and snippets.

@kujhawk94
Created October 23, 2013 15:30
Show Gist options
  • Save kujhawk94/7120913 to your computer and use it in GitHub Desktop.
Save kujhawk94/7120913 to your computer and use it in GitHub Desktop.
e-mds query to find the insurance associated with a specified patient id
SELECT
pat.patient_ID AS PID,
i.insurance_sequence as RN,
ic.InsuranceCompany_ID AS ID,
o.organization_name AS Ins_name,
ic.entity_ID
FROM
TopsData.dbo.enty_patient pat
LEFT JOIN TopsData.dbo.insr_insurance i on
(
pat.entity_id = i.entity_id and
(Insurance_DateTerminated > getdate() or Insurance_DateTerminated is null) and
i.insurance_recordstate <> 1
)
LEFT JOIN TopsData.dbo.insr_insurancegroup ig on
(
ig.insurancegroup_id = i.insurancegroup_id and
ig.insurancegroup_recordstate <> 1
)
LEFT JOIN TopsData.dbo.enty_InsuranceCompany ic on
(
ig.InsuranceCompany_ID = ic.InsuranceCompany_ID and
ic.InsuranceCompany_RecordState <> 1
)
LEFT JOIN TopsData.dbo.enty_organization o on
(
ic.entity_id = o.entity_id and
o.organization_recordstate <> 1
)
WHERE
( i.Insurance_ID is not null )
and ( (i.Insurance_DateEffective is null) or ( i.Insurance_DateEffective <= getdate() ) )
and ( (i.Insurance_DateTerminated is null) or (i.Insurance_DateTerminated >= getdate() ) )
and pat.patient_ID = 'ZZZZZ00001' -- Replace this ID with the id you are looking for.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment