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.

Diagnose.__lees_diagnose_tabel()   B
last analyzed

Complexity

Conditions 5

Size

Total Lines 49
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 5

Importance

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