1
|
|
|
import csv |
2
|
|
|
from typing import Optional, Dict, List |
3
|
|
|
|
4
|
1 |
|
from kerapu import clean_code, clean_date, clean_str, LEN_SPECIALISME_CODE |
5
|
1 |
|
|
6
|
|
|
|
7
|
1 |
|
class Specialisme: |
8
|
|
|
""" |
9
|
|
|
Klasse voor specialismen. |
10
|
1 |
|
""" |
11
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
12
|
|
|
_specialisme_tabel: Dict[str, List[Dict[str, str]]] = {} |
13
|
|
|
""" |
14
|
|
|
De specialismen referentietabel. |
15
|
1 |
|
""" |
16
|
|
|
|
17
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
18
|
|
|
def __init__(self, specialisme_code: str) -> None: |
19
|
|
|
""" |
20
|
|
|
Object constructor. |
21
|
|
|
|
22
|
|
|
:param str specialisme_code: De code van het specialisme. |
23
|
1 |
|
""" |
24
|
|
|
self.__specialisme_code: str = clean_code(specialisme_code, LEN_SPECIALISME_CODE) |
25
|
|
|
""" |
26
|
|
|
De code van het uitvoerend specialisme. |
27
|
|
|
""" |
28
|
|
|
|
29
|
1 |
|
# ------------------------------------------------------------------------------------------------------------------ |
30
|
1 |
|
@staticmethod |
31
|
|
|
def __lees_specialisme_tabel(folder: str) -> None: |
32
|
|
|
""" |
33
|
|
|
Leest de specialisme referentietabel (opgeslagen in CSV). |
34
|
|
|
|
35
|
|
|
:param str folder: De folder met alle goupertabellen. |
36
|
|
|
""" |
37
|
1 |
|
with open(folder + '/Specialismen.csv', 'r', encoding='utf-8') as csv_file: |
38
|
1 |
|
reader = csv.reader(csv_file) |
39
|
|
|
regel_nummer = 0 |
40
|
|
|
for regel in reader: |
41
|
|
|
regel_nummer += 1 |
42
|
|
|
|
43
|
|
|
# Sla de eerste regel met koppen over. |
44
|
1 |
|
if regel_nummer == 1: |
45
|
1 |
|
continue |
46
|
1 |
|
|
47
|
1 |
|
specialisme_code = clean_code(regel[0], LEN_SPECIALISME_CODE) |
48
|
1 |
|
specialisme_cluster1 = clean_str(regel[4]) |
49
|
|
|
specialisme_cluster2 = clean_str(regel[5]) |
50
|
|
|
begin_datum = clean_date(regel[7]) |
51
|
1 |
|
eind_datum = clean_date(regel[8]) |
52
|
1 |
|
|
53
|
|
|
rij = {'specialisme_code': specialisme_code, |
54
|
1 |
|
'specialisme_cluster1': specialisme_cluster1, |
55
|
1 |
|
'specialisme_cluster2': specialisme_cluster2, |
56
|
1 |
|
'begin_datum': begin_datum, |
57
|
1 |
|
'eind_datum': eind_datum} |
58
|
1 |
|
|
59
|
|
|
if specialisme_code not in Specialisme._specialisme_tabel: |
60
|
1 |
|
Specialisme._specialisme_tabel[specialisme_code] = [] |
61
|
|
|
|
62
|
|
|
Specialisme._specialisme_tabel[specialisme_code].append(rij) |
63
|
|
|
|
64
|
|
|
print("Aantal specialismen: %d" % (regel_nummer - 1)) |
65
|
|
|
|
66
|
1 |
|
# ------------------------------------------------------------------------------------------------------------------ |
67
|
1 |
|
@staticmethod |
68
|
|
|
def init_static(folder: str) -> None: |
69
|
1 |
|
""" |
70
|
|
|
Initialiseert alle statistische data. |
71
|
1 |
|
|
72
|
|
|
:param str folder: De folder met alle goupertabellen. |
73
|
|
|
""" |
74
|
1 |
|
Specialisme.__lees_specialisme_tabel(folder) |
75
|
1 |
|
|
76
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
77
|
|
|
def __get_specialisme_referentie(self, datum: str) -> Optional[Dict]: |
78
|
|
|
""" |
79
|
|
|
Zoekt de referentie data voor deze specialisme in de specialismen referentietabel. |
80
|
|
|
|
81
|
1 |
|
:param str datum: De begindatum van het subtraject. |
82
|
|
|
|
83
|
|
|
:rtype: dict[str,str] |
84
|
1 |
|
""" |
85
|
|
|
if self.__specialisme_code in self._specialisme_tabel: |
86
|
|
|
for referentie in self._specialisme_tabel[self.__specialisme_code]: |
87
|
|
|
if referentie['begin_datum'] <= datum <= referentie['eind_datum']: |
88
|
|
|
# Een geldige referentie rij gevonden. |
89
|
|
|
return referentie |
90
|
|
|
|
91
|
|
|
# Er is geen geldige referentie rij gevonden. |
92
|
1 |
|
return None |
93
|
1 |
|
|
94
|
1 |
|
else: |
95
|
|
|
return None |
96
|
1 |
|
|
97
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
98
|
|
|
def specialisme_aantal(self, specialisme_code: str, datum: str) -> int: |
99
|
|
|
""" |
100
|
|
|
Geeft het aantal malen (d.w.z. 0 of 1) dat dit specialisme voldoet aan een attributecode op een gegeven datum |
101
|
|
|
. |
102
|
|
|
:param str specialisme_code: De attribuutcode waaraan voldaan moet worden. |
103
|
|
|
:param str datum: De datum. |
104
|
|
|
|
105
|
1 |
|
:rtype: int |
106
|
|
|
""" |
107
|
|
|
referentie = self.__get_specialisme_referentie(datum) |
108
|
|
|
|
109
|
|
|
if not referentie: |
110
|
|
|
# Het specialisme komt niet voor in de referentie tabel. Geef 0 terug. |
111
|
|
|
return 0 |
112
|
|
|
|
113
|
|
|
if referentie['specialisme_code'] == clean_code(specialisme_code, LEN_SPECIALISME_CODE): |
114
|
1 |
|
return 1 |
115
|
|
|
|
116
|
1 |
|
return 0 |
117
|
|
|
|
118
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
119
|
|
|
def specialisme_cluster_aantal(self, cluster_code: str, cluster_nummer: int, datum: str) -> int: |
120
|
1 |
|
""" |
121
|
1 |
|
Geeft het aantal malen (d.w.z. 0 of 1) dat dit specialisme voldoet aan een clustercode op een gegeven datum. |
122
|
|
|
|
123
|
1 |
|
:param str cluster_code: De clustercode waaraan voldaan moet worden. |
124
|
|
|
:param int cluster_nummer: Het clusternummer. |
125
|
|
|
:param str datum: De datum. |
126
|
1 |
|
|
127
|
|
|
:rtype: int |
128
|
|
|
""" |
129
|
|
|
referentie = self.__get_specialisme_referentie(datum) |
130
|
|
|
|
131
|
|
|
if not referentie: |
132
|
|
|
# Het specialisme komt niet voor in de referentie tabel. Geef 0 terug. |
133
|
|
|
return 0 |
134
|
|
|
|
135
|
|
|
if cluster_nummer == 0: |
136
|
1 |
|
return 1 |
137
|
|
|
|
138
|
1 |
|
if 1 <= cluster_nummer <= 2: |
139
|
|
|
if referentie['specialisme_cluster%d' % cluster_nummer] == cluster_code: |
140
|
|
|
# Dit specialisme komt voor in het gevraagde cluster. |
141
|
|
|
return 1 |
142
|
1 |
|
|
143
|
|
|
return 0 |
144
|
|
|
|
145
|
1 |
|
raise RuntimeError("Onbekend clusternummer %d." % cluster_nummer) |
146
|
1 |
|
|
147
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
148
|
|
|
|