Changes between Initial Version and Version 1 of UseCase13


Ignore:
Timestamp:
06/14/26 20:55:58 (5 days ago)
Author:
236021
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UseCase13

    v1 v1  
     1= UseCase13 - Create / Update Billing Record =
     2
     3== Initiating Actor - `System Administrator / Billing Admin ` ==
     4
     5== Description ==
     6The system automatically creates and updates billing records when lab tests or procedures are requested. Billing admins can view pending records, inspect itemized costs, and update payment status when payment is received.
     7
     8== Scenario ==
     9
     101. Doctor requests a lab test and the system calculates the total cost for tests requested on that date.
     11
     12{{{
     13#!sql
     14SELECT SUM(lt.cost) AS total_cost
     15FROM performed_lab_tests plt
     16JOIN lab_tests lt ON plt.test_id = lt.test_id
     17WHERE plt.patient_id = (
     18SELECT patient_id
     19FROM users
     20WHERE username = 'maja.veljanova')
     21  AND plt.test_date = '2026-06-05';
     22}}}
     23
     242. System creates a billing record for the patient on that date.
     25
     26{{{
     27#!sql
     28INSERT INTO billing (total_cost, payment_status, record_id, admin_id)
     29VALUES (
     30  75.00,
     31  'PENDING',
     32  (SELECT record_id FROM medical_records WHERE patient_id = (
     33SELECT patient_id
     34FROM users
     35WHERE username = 'maja.veljanova')),
     36  (
     37SELECT admin_id
     38FROM admin LIMIT 1)
     39)
     40RETURNING bill_id;
     41}}}
     42
     433. System links the performed lab test to the billing record.
     44
     45{{{
     46#!sql
     47INSERT INTO billing_lab_tests (bill_id, test_id)
     48VALUES (
     49  (SELECT MAX(bill_id) FROM billing),
     50  (SELECT test_id FROM lab_tests WHERE test_name = 'Complete Blood Count')
     51);
     52}}}
     53
     544. System links the performed procedure to the billing record.
     55
     56{{{
     57#!sql
     58INSERT INTO billing_procedures (bill_id, procedure_id)
     59VALUES (
     60  (SELECT MAX(bill_id) FROM billing),
     61  (SELECT procedure_id FROM procedures WHERE procedure_type = 'ECG')
     62);
     63}}}
     64
     655. Billing admin logs in and retrieves all pending billing records.
     66
     67{{{
     68#!sql
     69SELECT
     70  b.bill_id,
     71  u_p.first_name AS patient_first_name,
     72  u_p.last_name AS patient_last_name,
     73  b.total_cost,
     74  b.payment_status
     75FROM billing b
     76JOIN medical_records mr ON b.record_id = mr.record_id
     77JOIN patients p ON mr.patient_id = p.patient_id
     78JOIN users u_p ON p.patient_id = u_p.patient_id
     79WHERE b.payment_status = 'PENDING'
     80ORDER BY b.bill_id;
     81}}}
     82
     836. Admin views the detailed billing record with itemized costs.
     84
     85{{{
     86#!sql
     87SELECT
     88  b.bill_id,
     89  b.total_cost,
     90  b.payment_status,
     91  u_p.first_name AS patient_first_name,
     92  u_p.last_name AS patient_last_name,
     93  p.embg,
     94  lt.test_name,
     95  lt.cost AS test_cost,
     96  pr.procedure_type,
     97  pr.cost AS procedure_cost
     98FROM billing b
     99JOIN medical_records mr ON b.record_id = mr.record_id
     100JOIN patients p ON mr.patient_id = p.patient_id
     101JOIN users u_p ON p.patient_id = u_p.patient_id
     102LEFT JOIN billing_lab_tests blt ON b.bill_id = blt.bill_id
     103LEFT JOIN lab_tests lt ON blt.test_id = lt.test_id
     104LEFT JOIN billing_procedures bp ON b.bill_id = bp.bill_id
     105LEFT JOIN procedures pr ON bp.procedure_id = pr.procedure_id
     106WHERE b.bill_id = (SELECT MAX(bill_id) FROM billing);
     107}}}
     108
     1097. Admin marks the billing record as paid once payment is received.
     110
     111{{{
     112#!sql
     113UPDATE billing
     114SET payment_status = 'PAID',
     115    payment_date = '2026-06-09'
     116WHERE bill_id = (SELECT MAX(bill_id) FROM billing WHERE payment_status = 'PENDING');
     117}}}