GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

kerapu.lbz.ZorgType   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 65
dl 0
loc 160
ccs 44
cts 55
cp 0.8
rs 10
c 0
b 0
f 0
wmc 19

6 Methods

Rating   Name   Duplication   Size   Complexity  
A ZorgType.zorg_type_cluster_aantal() 0 27 5
B ZorgType.__lees_zorg_type_tabel() 0 41 5
A ZorgType.__get_zorg_type_referentie() 0 20 4
A ZorgType.zorg_type_attribute_aantal() 0 20 3
A ZorgType.__init__() 0 14 1
A ZorgType.init_static() 0 8 1
1
import csv
2
from typing import Optional, Dict, List, Tuple
3
4 1
from kerapu import clean_code, LEN_SPECIALISME_CODE, LEN_ZORG_TYPE_CODE, clean_str, clean_date
5 1
6
7 1
class ZorgType:
8
    """
9
    Klasse voor zorgtypen.
10 1
    """
11
    # ------------------------------------------------------------------------------------------------------------------
12
    __zorg_type_tabel: Dict[Tuple[str, str], List[Dict[str, str]]] = {}
13
    """
14
    De zorgtypen referentietabel.
15 1
    """
16
17
    # ------------------------------------------------------------------------------------------------------------------
18
    def __init__(self, specialisme_code: str, zorg_type_code: str):
19
        """
20
        Object constructor.
21
22
        :param str specialisme_code: De code van het uitvoerend specialisme.
23 1
        :param str zorg_type_code: De code van deze zorgtype.
24
        """
25
        self.__specialisme_code: str = clean_code(specialisme_code, LEN_SPECIALISME_CODE)
26
        """
27
        De code van het uitvoerend specialisme.
28
        """
29
30 1
        self.__zorg_type_code: str = clean_code(zorg_type_code, LEN_ZORG_TYPE_CODE)
31
        """
32
        De code van deze zorgtype.
33
        """
34
35
    # ------------------------------------------------------------------------------------------------------------------
36
    @staticmethod
37 1
    def init_static(folder: str) -> None:
38 1
        """
39
        Initialiseert alle statistische data.
40
41
        :param str folder: De folder met alle goupertabellen.
42
        """
43
        ZorgType.__lees_zorg_type_tabel(folder)
44
45 1
    # ------------------------------------------------------------------------------------------------------------------
46 1
    def __get_zorg_type_referentie(self, datum: str) -> Optional[dict]:
47
        """
48
        Zoekt de referentie data voor deze zorg_type in de zorgtype referentietabel.
49
50
        :param datum: De begindatum van het subtraject.
51
52 1
        :rtype: dict[str,str]
53
        """
54
55 1
        if (self.__specialisme_code, self.__zorg_type_code) in self.__zorg_type_tabel:
56
            for referentie in self.__zorg_type_tabel[(self.__specialisme_code, self.__zorg_type_code)]:
57
                if referentie['begin_datum'] <= datum <= referentie['eind_datum']:
58
                    # Een geldige referentie rij gevonden.
59
                    return referentie
60
61
            # Er is geen geldige referentie rij gevonden.
62
            return None
63
64 1
        else:
65 1
            return None
66 1
67
    # ------------------------------------------------------------------------------------------------------------------
68 1
    def zorg_type_attribute_aantal(self, zorg_type_attribute_code: str, datum: str) -> int:
69
        """
70
        Geeft het aantal malen (d.w.z. 0 of 1) data deze diagnose voldoet aan een (specialismecode, zorgtypecode)
71
        combinatie op een peildatum.
72
73
        :param str zorg_type_attribute_code: De attribuutcode voor (specialismecode, diagnosecode) combinatie.
74 1
        :param str datum: De peildatum.
75
76
        :rtype: int
77 1
        """
78
        referentie = self.__get_zorg_type_referentie(datum)
79
80
        if not referentie:
81
            # De diagnose komt niet voor in de referentie tabel. Geef 0 terug.
82
            return 0
83
84
        if referentie['zorg_type_attribuut_code'] == zorg_type_attribute_code:
85
            return 1
86
87 1
        return 0
88
89 1
    # ------------------------------------------------------------------------------------------------------------------
90
    def zorg_type_cluster_aantal(self, cluster_code: str, cluster_nummer: int, datum: str) -> int:
91 1
        """
92
        Geeft het aantal malen (d.w.z. 0 of 1) dat deze zorgtype voorkomt in een zorgtypecluster op een peildatum.
93 1
94 1
        :param str cluster_code: De zorgtypeclustercode.
95
        :param int cluster_nummer: Het clusternummer (0..2).
96 1
        :param str datum: De peildatum.
97
98
        :rtype: int
99 1
        """
100
        referentie = self.__get_zorg_type_referentie(datum)
101
102
        if not referentie:
103
            # Deze zorgtype komt niet voor in de referentie tabel. Geef 0 terug.
104
            return 0
105
106
        if cluster_nummer == 0:
107
            return 1
108
109
        if 1 <= cluster_nummer <= 2:
110
            if referentie['zorg_type_cluster%d' % cluster_nummer] == cluster_code:
111
                # Deze zorgtype komt voor in het zorgtype cluster.
112
                return 1
113
114
            return 0
115
116
        raise RuntimeError("Onbekend clusternummer %d." % cluster_nummer)
117
118
    # ------------------------------------------------------------------------------------------------------------------
119
    @staticmethod
120
    def __lees_zorg_type_tabel(folder: str) -> None:
121
        """
122
        Leest de zorg_type referentietabel (opgeslagen in CSV).
123
124
        :param str folder: De folder met alle goupertabellen.
125
        """
126
        with open(folder + '/ZorgTypen.csv', 'r', encoding='utf-8') as csv_file:
127
            reader = csv.reader(csv_file)
128 1
            regel_nummer = 0
129 1
            for regel in reader:
130
                regel_nummer += 1
131
132
                # Sla de eerste regel met koppen over.
133
                if regel_nummer == 1:
134
                    continue
135 1
136 1
                specialisme_code = clean_code(regel[0], LEN_SPECIALISME_CODE)
137 1
                zorg_type_code = clean_code(regel[1], LEN_ZORG_TYPE_CODE)
138 1
                zorg_type_attribuut_code = clean_str(regel[3])
139 1
                zorg_type_cluster01 = clean_str(regel[4])
140
                zorg_type_cluster02 = clean_str(regel[5])
141
                begin_datum = clean_date(regel[6])
142 1
                eind_datum = clean_date(regel[7])
143 1
144
                sleutel = (specialisme_code, zorg_type_code)
145 1
146 1
                rij = {'specialisme_code':         specialisme_code,
147 1
                       'zorg_type_code':           zorg_type_code,
148 1
                       'zorg_type_attribuut_code': zorg_type_attribuut_code,
149 1
                       'zorg_type_cluster1':       zorg_type_cluster01,
150 1
                       'zorg_type_cluster2':       zorg_type_cluster02,
151 1
                       'begin_datum':              begin_datum,
152
                       'eind_datum':               eind_datum}
153 1
154
                if sleutel not in ZorgType.__zorg_type_tabel:
155 1
                    ZorgType.__zorg_type_tabel[sleutel] = []
156
157
                ZorgType.__zorg_type_tabel[sleutel].append(rij)
158
159
        print("Aantal zorgtypen: %d" % (regel_nummer - 1))
160
161
# ----------------------------------------------------------------------------------------------------------------------
162