1
|
|
|
class Patient: |
2
|
|
|
""" |
3
|
|
|
Klasse voor patiëntenn. |
4
|
|
|
""" |
5
|
|
|
|
6
|
1 |
|
# ------------------------------------------------------------------------------------------------------------------ |
7
|
|
|
def __init__(self, geboorte_datum: str, geslacht_code: str): |
8
|
|
|
""" |
9
|
|
|
Object constructor. |
10
|
|
|
|
11
|
|
|
:param str geboorte_datum: De geboortedatum van de patiënt. |
12
|
1 |
|
:param str geslacht_code: Het geslacht van de patiënt. |
13
|
|
|
""" |
14
|
|
|
self.__geboorte_datum: str = geboorte_datum |
15
|
|
|
""" |
16
|
|
|
De geboortedatum van de patiënt. |
17
|
|
|
""" |
18
|
|
|
|
19
|
1 |
|
self.__geslacht_code: str = Patient.normaliseer_geslacht_code(geslacht_code) |
20
|
1 |
|
""" |
21
|
|
|
Het geslacht van de patiënt. |
22
|
|
|
""" |
23
|
1 |
|
|
24
|
1 |
|
# ------------------------------------------------------------------------------------------------------------------ |
25
|
|
|
@property |
26
|
|
|
def geslacht_code(self) -> str: |
27
|
|
|
""" |
28
|
|
|
Geeft het geslacht van deze patiënt. |
29
|
|
|
|
30
|
1 |
|
:rtype: str |
31
|
|
|
""" |
32
|
|
|
return self.__geslacht_code |
33
|
1 |
|
|
34
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
35
|
|
|
def leeftijd(self, datum: str) -> int: |
36
|
|
|
""" |
37
|
|
|
Geeft de leeftijd van deze patient op een peildatum. |
38
|
|
|
|
39
|
|
|
:param str datum: De peildatum. |
40
|
|
|
|
41
|
1 |
|
:rtype: int |
42
|
|
|
""" |
43
|
|
|
if not datum: |
44
|
1 |
|
raise RuntimeError("Datum is niet gespecificeerd.") |
45
|
|
|
|
46
|
|
|
if not self.__geboorte_datum: |
47
|
1 |
|
raise RuntimeError("Geboortedatum is niet gespecificeerd.") |
48
|
|
|
|
49
|
|
|
if datum < self.__geboorte_datum: |
50
|
|
|
raise RuntimeError("Leeftijd van patient gevraagd op datum (%s) voor geboortedatum (%s)." % |
51
|
1 |
|
(datum, self.__geboorte_datum)) |
52
|
1 |
|
|
53
|
1 |
|
age = int(datum[0:4]) - int(self.__geboorte_datum[0:4]) |
54
|
|
|
if datum[-5:] < self.__geboorte_datum[-5:]: |
55
|
1 |
|
age -= 1 |
56
|
|
|
|
57
|
|
|
return age |
58
|
1 |
|
|
59
|
1 |
|
# ------------------------------------------------------------------------------------------------------------------ |
60
|
|
|
@staticmethod |
61
|
|
|
def normaliseer_geslacht_code(geslacht_code: str) -> str: |
62
|
|
|
""" |
63
|
|
|
Normaliseert een geslachtscode naar 1 (man), 2 (vrouw) of 9 (anders). |
64
|
|
|
|
65
|
|
|
:param str geslacht_code: De geslachtscode. |
66
|
|
|
|
67
|
1 |
|
:rtype: str |
68
|
1 |
|
""" |
69
|
|
|
if geslacht_code.upper() in ('1', 'M'): |
70
|
1 |
|
return '1' |
71
|
1 |
|
|
72
|
|
|
if geslacht_code.upper() in ('2', 'V', 'F'): |
73
|
|
|
return '2' |
74
|
|
|
|
75
|
|
|
return '9' |
76
|
|
|
|
77
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
78
|
|
|
|