| 2 | |
| 3 | |
| 4 | == Број на извршени прегледи од секој доктор, број на издадени упати од секој доктор и број на закажани термини кај секој доктор, за секое тримесечје, за тековната година |
| 5 | |
| 6 | {{{#!sql |
| 7 | select d2.doktor_id, c.ime, c.prezime, b.naziv as bolnica, o.naziv as oddel, b.grad, |
| 8 | case when pregledi_quarter.trimesecje = 1 then pregledi_quarter.pregledi else 0 end as quarter_1_pregledi, |
| 9 | case when pregledi_quarter.trimesecje = 2 then pregledi_quarter.pregledi else 0 end as quarter_2_pregledi, |
| 10 | case when pregledi_quarter.trimesecje = 3 then pregledi_quarter.pregledi else 0 end as quarter_3_pregledi, |
| 11 | case when pregledi_quarter.trimesecje = 4 then pregledi_quarter.pregledi else 0 end as quarter_4_pregledi, |
| 12 | |
| 13 | case when zakazani_quarter.trimesecje = 1 then zakazani_quarter.zakazani_termini else 0 end as quarter_1_zakazani_termini, |
| 14 | case when zakazani_quarter.trimesecje = 2 then zakazani_quarter.zakazani_termini else 0 end as quarter_2_zakazani_termini, |
| 15 | case when zakazani_quarter.trimesecje = 3 then zakazani_quarter.zakazani_termini else 0 end as quarter_3_zakazani_termini, |
| 16 | case when zakazani_quarter.trimesecje = 4 then zakazani_quarter.zakazani_termini else 0 end as quarter_4_zakazani_termini, |
| 17 | |
| 18 | case when upati_quarter.trimesecje = 1 then upati_quarter.upati_od_pregled else 0 end as quarter_1_upati_od_pregled, |
| 19 | case when upati_quarter.trimesecje = 2 then upati_quarter.upati_od_pregled else 0 end as quarter_2_upati_od_pregled, |
| 20 | case when upati_quarter.trimesecje = 3 then upati_quarter.upati_od_pregled else 0 end as quarter_3_upati_od_pregled, |
| 21 | case when upati_quarter.trimesecje = 4 then upati_quarter.upati_od_pregled else 0 end as quarter_4_upati_od_pregled |
| 22 | from bolnica b |
| 23 | join oddel o on b.bolnica_id = o.bolnica_id |
| 24 | join doktor d2 on (o.oddel_id, o.bolnica_id) = (d2.oddel_id, d2.bolnica_id) |
| 25 | join covek c on d2.doktor_id = c.covek_id |
| 26 | left join ( |
| 27 | select extract (quarter from p.vreme) as trimesecje, count (p.pregled_id) as pregledi, |
| 28 | d.doktor_id , o.naziv as oddel, b.naziv as bolnica |
| 29 | from pregled p |
| 30 | join doktor d on p.doktor_id = d.doktor_id |
| 31 | join oddel o on (d.oddel_id, d.bolnica_id) = (o.oddel_id, o.bolnica_id) |
| 32 | join bolnica b on o.bolnica_id = b.bolnica_id |
| 33 | where extract (year from p.vreme) = extract (year from current_date) |
| 34 | group by trimesecje, 3, 4, 5 |
| 35 | ) pregledi_quarter on d2.doktor_id = pregledi_quarter.doktor_id |
| 36 | left join ( |
| 37 | select r.doktor_id, count(r.rezervacija_id) zakazani_termini, |
| 38 | extract (quarter from t.vreme) as trimesecje |
| 39 | from rezervacija r |
| 40 | join termin t on (r.termin_id, r.doktor_id) = (t.termin_id, t.doktor_id) |
| 41 | where extract (year from t.vreme) = extract (year from current_date) |
| 42 | group by 1, 3 |
| 43 | ) zakazani_quarter on d2.doktor_id = zakazani_quarter.doktor_id |
| 44 | left join ( |
| 45 | select p.doktor_id , count (u.upat_id) as upati_od_pregled, |
| 46 | extract (quarter from p.vreme) as trimesecje |
| 47 | from pregled p |
| 48 | join upat u on p.pregled_id = u.pregled_id |
| 49 | where extract (year from p.vreme) = extract (year from current_date) |
| 50 | group by 1, 3 |
| 51 | ) upati_quarter on d2.doktor_id = upati_quarter.doktor_id ; |
| 52 | }}} |
| 53 | |
| 54 | |