Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions database/3_view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,34 @@ LEFT JOIN public.doctor d ON a.doctor_id = d.doctor_id
LEFT JOIN public.staff s ON d.doctor_id = s.staff_id AND s.role = 'doctor'
ORDER BY i.date DESC, i.invoice_id DESC;
-- View for appointment details with patient, treatment, doctor info
CREATE OR REPLACE VIEW appointment_details_view AS
SELECT
CREATE VIEW appointment_details_view AS
SELECT
a.appointment_id,
a.patient_id,
p.name AS patient_name,
at.treatment_code,
t.name AS treatment_name,
a.doctor_id,
s.name AS doctor_name,
a.date,
a.action_time,
a.status,
a.is_emergency,
a.branch_id,
b.name AS branch_name
FROM public.appointment a
LEFT JOIN public.patient p ON a.patient_id = p.patient_id
LEFT JOIN public.appointment_treatment at ON a.appointment_id = at.appointment_id
LEFT JOIN public.treatment_catalogue t ON at.treatment_code = t.treatment_code
LEFT JOIN public.doctor d ON a.doctor_id = d.doctor_id
LEFT JOIN public.staff s ON d.doctor_id = s.staff_id AND s.role = 'doctor'
LEFT JOIN public.branch b ON a.branch_id = b.branch_id;
a.total_cost,
p.patient_id,
p.name AS patient_name,
d.doctor_id,
d.name AS doctor_name,
b.branch_id,
b.name AS branch_name,
tc.treatment_code,
tc.name AS treatment_name
FROM
appointment a
LEFT JOIN
patient p ON a.patient_id = p.patient_id
LEFT JOIN
doctor d ON a.doctor_id = d.doctor_id
LEFT JOIN
branch b ON a.branch_id = b.branch_id
LEFT JOIN
appointment_treatment at ON a.appointment_id = at.appointment_id
LEFT JOIN
treatment_catalogue tc ON at.treatment_code = tc.treatment_code;

-- Create a view for doctor revenue that automatically updates when new payments are added
CREATE OR REPLACE VIEW doctor_revenue_view AS
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"chart.js": "^4.5.0",
"next": "15.5.3",
"next-auth": "^4.24.11",
"node": "^25.0.0",
"pg": "^8.16.3",
"react": "19.1.0",
"react-chartjs-2": "^5.3.0",
Expand Down
Loading