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, |
| 7 | |
| 8 | select distinct d.doktor_id, c.ime, c.prezime, b.naziv as bolnica, o.naziv as oddel, b.grad, |
| 9 | case when pregledi_od_doktor.trimesecje = 1 then pregledi_od_doktor.pregledi else 0 end as quarter_1_pregledi, |
| 10 | case when pregledi_od_doktor.trimesecje = 2 then pregledi_od_doktor.pregledi else 0 end as quarter_2_pregledi, |
| 11 | case when pregledi_od_doktor.trimesecje = 3 then pregledi_od_doktor.pregledi else 0 end as quarter_3_pregledi, |
| 12 | case when pregledi_od_doktor.trimesecje = 4 then pregledi_od_doktor.pregledi else 0 end as quarter_4_pregledi, |
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, |
| 14 | case when upati_od_doktor.trimesecje = 1 then upati_od_doktor.upati else 0 end as quarter_1_upati_od_pregled, |
| 15 | case when upati_od_doktor.trimesecje = 2 then upati_od_doktor.upati else 0 end as quarter_2_upati_od_pregled, |
| 16 | case when upati_od_doktor.trimesecje = 3 then upati_od_doktor.upati else 0 end as quarter_3_upati_od_pregled, |
| 17 | case when upati_od_doktor.trimesecje = 4 then upati_od_doktor.upati else 0 end as quarter_4_upati_od_pregled, |
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 1, 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 ; |
| 19 | case when zakazani_termini_kaj_doktor.trimesecje = 1 then zakazani_termini_kaj_doktor.rezervacii else 0 end as quarter_1_zakazani_termini, |
| 20 | case when zakazani_termini_kaj_doktor.trimesecje = 2 then zakazani_termini_kaj_doktor.rezervacii else 0 end as quarter_2_zakazani_termini, |
| 21 | case when zakazani_termini_kaj_doktor.trimesecje = 3 then zakazani_termini_kaj_doktor.rezervacii else 0 end as quarter_3_zakazani_termini, |
| 22 | case when zakazani_termini_kaj_doktor.trimesecje = 4 then zakazani_termini_kaj_doktor.rezervacii else 0 end as quarter_4_zakazani_termini |
| 23 | from doktor d |
| 24 | left join pregled p on d.doktor_id = p.doktor_id |
| 25 | left join termin t on d.doktor_id = t.doktor_id |
| 26 | join covek c on d.doktor_id = c.covek_id |
| 27 | join oddel o on (d.oddel_id, d.bolnica_id) = (o.oddel_id, o.bolnica_id) |
| 28 | join bolnica b on o.bolnica_id = b.bolnica_id |
| 29 | left join ( |
| 30 | select extract (quarter from p2.vreme) as trimesecje, d3.doktor_id, count(p2.pregled_id) as pregledi |
| 31 | from doktor d3 |
| 32 | left join pregled p2 on d3.doktor_id = p2.doktor_id |
| 33 | where extract (year from p2.vreme) = extract (year from current_date) |
| 34 | group by 1, 2 |
| 35 | ) pregledi_od_doktor on d.doktor_id = pregledi_od_doktor.doktor_id |
| 36 | left join ( |
| 37 | select d3.doktor_id, extract (quarter from p2.vreme) as trimesecje, count(u.upat_id) as upati |
| 38 | from doktor d3 |
| 39 | left join pregled p2 on d3.doktor_id = p2.doktor_id |
| 40 | left join upat u on p2.pregled_id = u.pregled_id |
| 41 | where extract (year from p2.vreme) = extract (year from current_date) |
| 42 | group by 1, 2 |
| 43 | ) upati_od_doktor on d.doktor_id = upati_od_doktor.doktor_id |
| 44 | left join ( |
| 45 | select t3.doktor_id, extract (quarter from t3.vreme) as trimesecje, count(r.rezervacija_id) as rezervacii |
| 46 | from upat u |
| 47 | left join rezervacija r on u.upat_id = r.upat_id |
| 48 | left join termin t3 on (r.termin_id, r.doktor_id) = (t3.termin_id, t3.doktor_id) |
| 49 | where extract (year from t3.vreme) = extract (year from current_date) |
| 50 | group by 1, 2 |
| 51 | ) zakazani_termini_kaj_doktor on d.doktor_id = zakazani_termini_kaj_doktor.doktor_id ; |
| 52 | |