Lines 100.00% 81 / 81
Functions and Methods 100.00% 3 / 3
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ExchangeWaitingdepartment 100.00% 81 / 81 100.00% 3 / 3 10 100.00% 1 / 1
 readEntity 100.00% 46 / 46 100.00% 1 / 1 4
 readSubjectList 100.00% 12 / 12 100.00% 1 / 1 2
 readPeriodList 100.00% 23 / 23 100.00% 1 / 1 4
1<?php
2
3namespace BO\Zmsbackend\Exchange\Service;
4
5use BO\Zmsentities\Exchange;
6
7class ExchangeWaitingdepartment extends \BO\Zmsbackend\Base implements \BO\Zmsbackend\Interfaces\ExchangeSubject
8{
9    /**
10     * @return Exchange
11     */
12    #[\Override]
13    public function readEntity(
14        string|int $subjectid,
15        \DateTimeInterface $datestart,
16        \DateTimeInterface $dateend,
17        string $period = 'day'
18    ) {
19        $department = (new \BO\Zmsbackend\Department\Service\Department())->readEntity($subjectid);
20        $organisation = (new \BO\Zmsbackend\Organisation\Service\Organisation())->readByDepartmentId($subjectid);
21        $entity = new Exchange();
22        $entity['title'] = "Wartestatistik $organisation->name -> $department->name";
23        $entity->setPeriod($datestart, $dateend, $period);
24        $entity->addDictionaryEntry('subjectid', 'string', 'ID of a department', 'department.id');
25        $entity->addDictionaryEntry('date', 'string', 'date of report entry');
26        $entity->addDictionaryEntry('hour', 'string', 'hour of report entry');
27        $entity->addDictionaryEntry('waitingcount', 'number', 'amount of waiting spontaneous clients');
28        $entity->addDictionaryEntry('waitingtime', 'number', 'real waitingtime for spontaneous clients');
29        $entity->addDictionaryEntry('waytime', 'number', 'real waytime for spontaneous clients');
30        $entity->addDictionaryEntry('waitingcalculated', 'number', 'calculated waitingtime for spontaneous clients');
31        $entity->addDictionaryEntry('waitingcount_termin', 'number', 'amount of waiting clients with termin');
32        $entity->addDictionaryEntry('waitingtime_termin', 'number', 'real waitingtime with termin');
33        $entity->addDictionaryEntry('waytime_termin', 'number', 'real waytime with appointment');
34        $entity->addDictionaryEntry('waitingcalculated_termin', 'number', 'calculated waitingtime with termin');
35        $entity->addDictionaryEntry('waycount_termin', 'number', 'clients included in appointment way time');
36        $subjectIdList = explode(',', $subjectid);
37        foreach ($subjectIdList as $subjectid) {
38            $raw = $this
39                ->getReader()
40                ->fetchAll(
41                    constant("\BO\Zmsbackend\Exchange\Repository\ExchangeWaitingdepartment::QUERY_READ_" . strtoupper($period)),
42                    [
43                        'departmentid' => $subjectid,
44                        'datestart' => $datestart->format('Y-m-d'),
45                        'dateend' => $dateend->format('Y-m-d'),
46                    ]
47                );
48
49            foreach ($raw as $entry) {
50                foreach (range(0, 23) as $hour) {
51                    $entity->addDataSet([
52                        $subjectid,
53                        $entry['datum'],
54                        $hour,
55                        $entry[sprintf('hour_%02d_waiting_count_spontaneous', $hour)],
56                        $entry[sprintf('hour_%02d_waiting_time_spontaneous', $hour)],
57                        $entry[sprintf('hour_%02d_way_time_spontaneous', $hour)],
58                        $entry[sprintf('hour_%02d_estimated_waiting_time_spontaneous', $hour)],
59                        $entry[sprintf('hour_%02d_waiting_count_appointment', $hour)],
60                        $entry[sprintf('hour_%02d_waiting_time_appointment', $hour)],
61                        $entry[sprintf('hour_%02d_way_time_appointment', $hour)],
62                        $entry[sprintf('hour_%02d_estimated_waiting_time_appointment', $hour)],
63                        $entry[sprintf('hour_%02d_way_count_appointment', $hour)],
64                    ]);
65                }
66            }
67        }
68        return $entity;
69    }
70
71    /**
72     * @return Exchange
73     */
74    #[\Override]
75    public function readSubjectList()
76    {
77        $raw = $this->getReader()->fetchAll(\BO\Zmsbackend\Exchange\Repository\ExchangeWaitingdepartment::QUERY_SUBJECTS, []);
78        $entity = new Exchange();
79        $entity['title'] = "Wartestatistik";
80        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable());
81        $entity->addDictionaryEntry('subject', 'string', 'Behörde ID', 'department.id');
82        $entity->addDictionaryEntry('periodstart', 'string', 'Datum von');
83        $entity->addDictionaryEntry('periodend', 'string', 'Datum bis');
84        $entity->addDictionaryEntry('organisationname', 'string', 'Name der Organisation');
85        $entity->addDictionaryEntry('description', 'string', 'Name der Behörde');
86        foreach ($raw as $entry) {
87            $entity->addDataSet(array_values($entry));
88        }
89        return $entity;
90    }
91
92    /**
93     * @return Exchange
94     */
95    #[\Override]
96    public function readPeriodList(string|int $subjectid, string $period = 'day')
97    {
98        $department = (new \BO\Zmsbackend\Department\Service\Department())->readEntity($subjectid);
99        $organisation = (new \BO\Zmsbackend\Organisation\Service\Organisation())->readByDepartmentId($subjectid);
100        $entity = new Exchange();
101        $entity['title'] = "Wartestatistik $organisation->name -> $department->name";
102        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable(), $period);
103        $entity->addDictionaryEntry('period');
104
105        $montsList = $this->getReader()->fetchAll(
106            constant("\BO\Zmsbackend\Exchange\Repository\ExchangeWaitingdepartment::QUERY_PERIODLIST_MONTH"),
107            [
108                'departmentid' => $subjectid,
109            ]
110        );
111        $raw = [];
112        foreach ($montsList as $month) {
113            $date = new \DateTimeImmutable($month['date']);
114            $raw[$date->format('Y')][] = $month['date'];
115            rsort($raw[$date->format('Y')]);
116        }
117        krsort($raw);
118
119        foreach ($raw as $year => $months) {
120            $entity->addDataSet([$year]);
121            foreach ($months as $month) {
122                $entity->addDataSet([$month]);
123            }
124        }
125        return $entity;
126    }
127}