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.
Completed
Push — master ( be813a...3d8811 )
by P.R.
06:43 queued 46s
created

kerapu.lbz.Diagnose.Diagnose.__init__()   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 3
dl 0
loc 16
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
"""
2
Kerapu
3
"""
4 1
import csv
5 1
from typing import Optional
6
7 1
from kerapu import clean_code, clean_date, clean_str, LEN_DIAGNOSE_CODE, LEN_SPECIALISME_CODE
8
9
10 1
class Diagnose:
11
    """
12
    Klasse voor diagnosen.
13
    """
14
    # ------------------------------------------------------------------------------------------------------------------
15 1
    __diagnose_tabel = {}
16
    """
17
    De diagnosen referentietabel.
18
19
    :type: dict[(str,str),list[dict[str,str]]]
20
    """
21
22
    # ------------------------------------------------------------------------------------------------------------------
23 1
    def __init__(self, specialisme_code: str, diagnose_code: str):
24
        """
25
        Object constructor.
26
27
        :param str specialisme_code: De code van het uitvoerend specialisme.
28
        :param str diagnose_code: De code van deze diagnose.
29
        """
30 1
        self.__specialisme_code = clean_code(specialisme_code, LEN_SPECIALISME_CODE)
31
        """
32
        De code van het uitvoerend specialisme.
33
34
        :type: str
35
        """
36
37 1
        self.__diagnose_code = clean_code(diagnose_code, LEN_DIAGNOSE_CODE)
38 1
        """
39
        De code van deze diagnose.
40
41
        :type: str
42
        """
43
44
    # ------------------------------------------------------------------------------------------------------------------
45 1
    @staticmethod
46 1
    def __lees_diagnose_tabel(folder: str):
47
        """
48
        Leest de diagnose referentietabel (opgeslagen in CSV).
49
50
        :param str folder: De folder met alle goupertabellen.
51
        """
52 1
        with open(folder + '/Diagnosen.csv', encoding='utf-8') as csv_file:
53 1
            reader = csv.reader(csv_file, )
54 1
            regel_nummer = 0
55 1
            for regel in reader:
56 1
                regel_nummer += 1
57
58
                # Sla de eerste regel met koppen over.
59 1
                if regel_nummer == 1:
60 1
                    continue
61
62 1
                specialisme_code = clean_code(regel[0], LEN_SPECIALISME_CODE)
63 1
                diagnose_code = clean_code(regel[1], LEN_DIAGNOSE_CODE)
64 1
                diagnose_attribute_code = clean_str(regel[3])
65 1
                diagnose_cluster01 = clean_str(regel[5])
66 1
                diagnose_cluster02 = clean_str(regel[6])
67 1
                diagnose_cluster03 = clean_str(regel[7])
68 1
                diagnose_cluster04 = clean_str(regel[8])
69 1
                diagnose_cluster05 = clean_str(regel[9])
70 1
                diagnose_cluster06 = clean_str(regel[10])
71 1
                begin_datum = clean_date(regel[11])
72 1
                eind_datum = clean_date(regel[12])
73
74 1
                sleutel = (specialisme_code, diagnose_code)
75
76 1
                rij = {'specialisme_code':        specialisme_code,
77
                       'diagnose_code':           diagnose_code,
78
                       'diagnose_attribute_code': diagnose_attribute_code,
79
                       'diagnose_cluster1':       diagnose_cluster01,
80
                       'diagnose_cluster2':       diagnose_cluster02,
81
                       'diagnose_cluster3':       diagnose_cluster03,
82
                       'diagnose_cluster4':       diagnose_cluster04,
83
                       'diagnose_cluster5':       diagnose_cluster05,
84
                       'diagnose_cluster6':       diagnose_cluster06,
85
                       'begin_datum':             begin_datum,
86
                       'eind_datum':              eind_datum}
87
88 1
                if sleutel not in Diagnose.__diagnose_tabel:
89 1
                    Diagnose.__diagnose_tabel[sleutel] = []
90
91 1
                Diagnose.__diagnose_tabel[sleutel].append(rij)
92
93 1
        print("Aantal diagnosen: %d" % (regel_nummer - 1))
94
95
    # ------------------------------------------------------------------------------------------------------------------
96 1
    @staticmethod
97 1
    def init_static(folder: str):
98
        """
99
        Initialiseert alle statistische data.
100
101
        :param str folder: De folder met alle goupertabellen.
102
        """
103 1
        Diagnose.__lees_diagnose_tabel(folder)
104
105
    # ------------------------------------------------------------------------------------------------------------------
106 1
    def __diagnose_referentie(self, datum: str) -> Optional[dict]:
107
        """
108
        Zoekt de referentie data voor deze diagnose in de diagnosen referentietabel.
109
110
        :param str datum: De begindatum van het subtraject.
111
        :rtype: dict[str,str]
112
        """
113 1
        if (self.__specialisme_code, self.__diagnose_code) in self.__diagnose_tabel:
114 1
            for referentie in self.__diagnose_tabel[(self.__specialisme_code, self.__diagnose_code)]:
115 1
                if referentie['begin_datum'] <= datum <= referentie['eind_datum']:
116
                    # Een geldige referentie rij gevonden.
117 1
                    return referentie
118
119
            # Er is geen geldige referentie rij gevonden.
120
            return None
121
122
        else:
123 1
            return None
124
125
    # ------------------------------------------------------------------------------------------------------------------
126 1
    def diagnose_attribute_aantal(self, diagnose_attribute_code: str, datum: str) -> int:
127
        """
128
        Geeft het aantal malen (d.w.z. 0 of 1) data deze diagnose voldoet aan een (specialismecode, diagnosecode)
129
        op een peildatum.
130
131
        :param str diagnose_attribute_code: De attribuutcode voor de (specialismecode, diagnosecode) combinatie.
132
        :param str datum: De peildatum.
133
134
        :rtype: int
135
        """
136 1
        referentie = self.__diagnose_referentie(datum)
137
138 1
        if not referentie:
139
            # De diagnose komt niet voor in de referentie tabel. Geef 0 terug.
140 1
            return 0
141
142 1
        if referentie['diagnose_attribute_code'] == diagnose_attribute_code:
143 1
            return 1
144
145 1
        return 0
146
147
    # ------------------------------------------------------------------------------------------------------------------
148 1
    def diagnose_cluster_aantal(self, cluster_code: str, cluster_nummer: int, datum: str) -> int:
149
        """
150
        Geeft het aantal malen (d.w.z. 0 of 1) data deze diagnose voorkomt in een diagnosecodecluster op een peildatum.
151
152
        :param str cluster_code: De diagnoseclustercode.
153
        :param int cluster_nummer: De clusternummer (0..6).
154
        :param str datum: De peildatum.
155
156
        :rtype: int
157
        """
158 1
        referentie = self.__diagnose_referentie(datum)
159
160 1
        if not referentie:
161
            # De diagnose komt niet voor in de referentie tabel. Geef 0 terug.
162 1
            return 0
163
164 1
        if cluster_nummer == 0:
165
            return 1
166
167 1
        if 1 <= cluster_nummer <= 6:
168 1
            if referentie['diagnose_cluster%d' % cluster_nummer] == cluster_code:
169
                # Deze diagnose komt voor in het gevraagde cluster.
170 1
                return 1
171
172 1
            return 0
173
174
        raise RuntimeError("Onbekend clusternummer %d." % cluster_nummer)
175
176
# ----------------------------------------------------------------------------------------------------------------------
177