5. QUERIES I CREATED TO TEST THE DATABASE
What accounts have unpaid balances?
(SELECT bill.bill_no, bill_amount - (SELECT SUM(payment_amount)
FROM payment WHERE payment.bill_no = bill.bill_no)
FROM bill WHERE bill_amount - (SELECT SUM(payment_amount)
FROM payment WHERE payment.bill_no = bill.bill_no) > 0)
UNION
(SELECT bill.bill_no, bill_amount FROM bill WHERE (SELECT COUNT(*)
FROM payment WHERE payment.bill_no = bill.bill_no) = 0);
Results
bill_no | ?column?
---------+----------
106 | 35.00
115 | 50.00
118 | 100.00
107 | 75.00
109 | 150.00
108 | 150.00
114 | 50.00
117 | 50.00
103 | 50.00
111 | 30.00
110 | 75.00
113 | 50.00
104 | 25.00
116 | 50.00
6. Which diagnosis codes have been billed most within the past
year?
SELECT is_made_during.dx_code, diag_desc
FROM is_made_during, diagnosis
WHERE is_made_during.dx_code = diagnosis.dx_code
GROUP BY is_made_during.dx_code, diagnosis.diag_desc
HAVING COUNT(*) =
(SELECT MAX(num) FROM
(SELECT COUNT(*) AS num FROM is_made_during GROUP BY
dx_code) AS mycount);
dx_code | diag_desc
---------+------------------------------
V70.0 | routine general medical exam
7. Which procedure codes were billed most within the past year?
SELECT is_performed_during.px_code, procedure.proc_desc
FROM is_performed_during, procedure
WHERE is_performed_during.px_code = procedure.px_code
GROUP BY is_performed_during.px_code,
procedure.proc_desc
HAVING COUNT(*) =
(SELECT MAX(num) FROM
(SELECT COUNT(*) AS num FROM is_performed_during GROUP
BY px_code) AS mycount);
Results
px_code | proc_desc
---------+-----------------------------------
G0463 | visit for assessment & management
8. What encounters took place on a certain date?
SELECT pt_id, visit_date
FROM encounter
WHERE visit_date = '2014-10-01';
Results:
pt_id | visit_date
-------+------------
6 | 2014-10-01
7 | 2014-10-01
9. Which insurance companies have made the most payments within
the past year?
SELECT makes_a.insurance_id, insurance.ins_name
FROM makes_a, insurance
WHERE makes_a.insurance_id = insurance.insurance_id
GROUP BY makes_a.insurance_id, insurance.ins_name
HAVING COUNT(*) =
(SELECT MAX(num) FROM
(SELECT COUNT(*) AS num FROM makes_a
GROUP BY insurance_id) AS mycount);
Results
insurance_id | ins_name
-------------- ----------
1 | Aetna
10. How many visits has a certain patient had within the past
year?
SELECT COUNT(visit_date)
FROM encounter
WHERE pt_id = '1';
Results
count
-------
3
Hinweis der Redaktion
THE ENTITY RELATIONSHIP DIAGRAM
The reporting of diagnosis codes is important for statistical healthcare reporting agencies that gather information about diagnoses is demographical areas. This is how they are able to report where epidemics are happening, such as when there was an avian flu outbreak in the midwest several years back.
The reporting of procedure codes is important to facilities such as hospitals. They may want to see what types of procedures are being performed, such as nose jobs for example, in that case they may want to bring in more plastic surgeons.
Insurance Company query, providers may want to know which insurance companies are making payments, or not because they may want to reconsider their contract with these insurance companies or may want to contact Provider Relations to discuss why their claims are not being paid.
Example of a Medical Billing Database on the front-end from a users point of view.