SQL: Average Well Visit Payment by Ins Carrier (Without Vaccines)

About

This report lists the average payment for well visit by insurance carrier based on the date range you specify.

A sample image of this SQL report run in the Database Viewer is shown below:

Caveats

  • Insurance carrier is the PRIMARY insurance
  • "Well visit" is every CPT code that occurred for the same patient/DOS when a well code (9939x, 9938x) was used except for the vaccine and vaccine administration.
  • The date range you specify are DATES OF SERVICE, not payment dates.  
  • Enter dates old enough for the date range. If you pick recent dates of service (like yesterday), those claims won't be paid yet. Therefore, you would receive a bunch of zero payments averaged into the result.  
  • Payments include both the insurance side and patient side for ALL CPT codes (except the vaccines) associated with that visit.

Code

To highlight and copy the code below to your clipboard, simply click the Copy button.

select count(patno) as patients, ins_carrier_code, round(avg(paid),2) as avg_paid from
(

select patno, date1, ins_carrier_code, sum(total_pmt) as paid from
(

select b.patno, b.date1, b.cptcode, b.trnsxno, ins_carrier_code,  p+c as total_pmt from
(
select a.patno, a.date1, at2.cptcode, at2.trnsxno, ins_carrier_code from
(
select patno, date1, cptcode, ins_carrier_code from archive_transactions where cptcode in ('99391','99392','99393','99394','99395','99381','99382','99383','99384','99385') and date1 between :start_date and :end_date and archive_flag = 1
)
a left outer join
(select patno, date1, cptcode, trnsxno from archive_transactions where date1 between :start_date and :end_date and archive_flag = 1
and cptcode not in ('90460','90461','90471','90472','90473','90474')
and cptcode not between '90600' and '90799'
and cptcode not in ('1','2','3','4')
) at2 on a.patno = at2.patno and a.date1= at2.date1
) 
b left outer join
(select txnopaid, sum(payment) as p, sum(copayrecd) as c from archive_transactions where date1 >= :start_date and txnopaid >0 group by txnopaid) at3 on at3.txnopaid = b.trnsxno
) t2 group by patno, date1, ins_carrier_code
) t3 group by ins_carrier_code