| 56 | == Број на пациенти кои биле на преглед во даден оддел и број на упати кои биле издадени за во оддел после извршен преглед, за секое тримесечје, за тековната година |
| 57 | |
| 58 | {{{#!sql |
| 59 | select distinct o.naziv as oddel, b.naziv as bolnica, |
| 60 | case when pregled_quarter.trimesecje = 1 then pacienti_quarter.pacienti else 0 end as quarter_1_pacienti, |
| 61 | case when pregled_quarter.trimesecje = 2 then pacienti_quarter.pacienti else 0 end as quarter_2_pacienti, |
| 62 | case when pregled_quarter.trimesecje = 3 then pacienti_quarter.pacienti else 0 end as quarter_3_pacienti, |
| 63 | case when pregled_quarter.trimesecje = 4 then pacienti_quarter.pacienti else 0 end as quarter_4_pacienti, |
| 64 | |
| 65 | case when pregled_quarter.trimesecje = 1 then upati_quarter.upati else 0 end as quarter_1_upati, |
| 66 | case when pregled_quarter.trimesecje = 2 then upati_quarter.upati else 0 end as quarter_2_upati, |
| 67 | case when pregled_quarter.trimesecje = 3 then upati_quarter.upati else 0 end as quarter_3_upati, |
| 68 | case when pregled_quarter.trimesecje = 4 then upati_quarter.upati else 0 end as quarter_4_upati |
| 69 | from oddel o |
| 70 | join bolnica b on o.bolnica_id = b.bolnica_id |
| 71 | join ( |
| 72 | select o.oddel_id, o.bolnica_id, extract (quarter from p.vreme) as trimesecje |
| 73 | from pregled p |
| 74 | join doktor d on p.doktor_id = d.doktor_id |
| 75 | join oddel o on (d.oddel_id, d.bolnica_id) = (o.oddel_id, o.bolnica_id) |
| 76 | ) pregled_quarter on (o.oddel_id, o.bolnica_id) = (pregled_quarter.oddel_id, pregled_quarter.bolnica_id) |
| 77 | left join ( |
| 78 | select o.oddel_id, o.bolnica_id, count (p.covek_pacient_id) as pacienti |
| 79 | from pregled p |
| 80 | join doktor d on p.doktor_id = d.doktor_id |
| 81 | join oddel o on (d.oddel_id, d.bolnica_id) = (o.oddel_id, o.bolnica_id) |
| 82 | join bolnica b on o.bolnica_id = b.bolnica_id |
| 83 | where extract (year from p.vreme) = extract (year from current_date) |
| 84 | group by 1, 2 |
| 85 | ) pacienti_quarter on (o.oddel_id, o.bolnica_id) = (pacienti_quarter.oddel_id, pacienti_quarter.bolnica_id) |
| 86 | left join ( |
| 87 | select u.oddel_id, u.bolnica_id, count(u.upat_id) as upati |
| 88 | from upat u |
| 89 | join pregled p on u.pregled_id = p.pregled_id |
| 90 | where extract (year from p.vreme) = extract (year from current_date) |
| 91 | group by 1, 2 |
| 92 | ) upati_quarter on (o.oddel_id, o.bolnica_id) = (upati_quarter.oddel_id, upati_quarter.bolnica_id) |
| 93 | }}} |
| 94 | |
| 95 | |
| 96 | |