Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want the payer code, payer name, payer category code, example inpatient visit, inpatient count, facility name, and facility code. Right now my code only

I want the payer code, payer name, payer category code, example inpatient visit, inpatient count, facility name, and facility code. Right now my code only outputs the following: payer code, payer name, payer category code, example inpatient visit. Please provide a SQL query that it will include inpatient count, facility name, and facility code in the output as well.
SELECT DISTINCT
code,
name,
payer_category_code,
'https://'||(select value
from configuration_option
where config_key = 'customerId'
)
||'.test'||visits.visit_id||'123' example_inpatient_visit
FROM payer p
LEFT JOIN (SELECT
split_part(payers,',',1) payer
,max(visit_id) visit_id
FROM visit
WHERE (pre_disch_admit_status =1 OR admit_status =1)
AND admit_date > NOW()- INTERVAL '30 Days'
AND facility is not null
AND loc_poc is not null
GROUP BY 1
)visits ON visits.payer = p.code
UNION
SELECT DISTINCT
vp.plan_id
, vp.company_name
, 'NOT MAPPED'
,'https://'||(select value
from configuration_option
where config_key = 'customerId'
)
||'.test'||visits.visit_id||'123' example_inpatient_visit
FROM visit_payer vp
LEFT JOIN payer p ON p.code = vp.plan_id
LEFT JOIN (SELECT
split_part(payers,',',1) payer
,max(visit_id) visit_id
FROM visit
WHERE (pre_disch_admit_status =1 OR admit_status =1)
AND admit_date > NOW()- INTERVAL '30 Days'
AND facility is not null
AND loc_poc is not null
GROUP BY 1
)visits ON visits.payer = vp.plan_id
WHERE p.code IS NULL
AND vp.creation_date >= NOW()- INTERVAL '30 days'
ORDER BY 1,2,3;
NOTE: You can get the inpatientcount
FROM general_adt
WHERE admit_date > NOW()- INTERVAL '30 Days'
AND patient_class IN ('I','INPATIENT','Inpatient','IN')
GROUP BY 1,2;
Here is some information about my tables; The payer table has the following: code, name, payer_category_code. The visit table has the following: visit_id, account_no, admit_status, loc_poc. The visit_payer table has the following: plan_id, visit_id. The configuration_option table has the following: config_key. The facility table has the following: code, name. The location table has the following: facility_code, code, name. The general_adt table has the following: account_no, patient_id, visit_no. Please let me know if you have any questions!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

how would you have done things differently?

Answered: 1 week ago

Question

What were the reasons for your conversion or resistance?

Answered: 1 week ago

Question

How was their resistance overcome?

Answered: 1 week ago