Checks
Classes¶
Checks(base, check_unique_in_for_everybody=True, check_unique_out_or_death_for_everybody=True, reorder=True, check_no_in_after_treatment=True, check_no_out_before_treatment=True, check_no_duplicated_rows=True, check_mutiple_delivrance_on_same_date=True)
¶
Initialize the class that runs checks on the initial dataset.
Note: It orders the dataset by ID_PATIENT then TIMESTAMP, placing 'in' events first and 'out'/'death' events last.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base
|
DataFrame — one row per event for a patient; columns: 'ID_PATIENT', 'EVT', 'TIMESTAMP' |
required | |
check_unique_in_for_everybody
|
bool
|
run check method |
True
|
check_unique_out_or_death_for_everybody
|
bool
|
run check method |
True
|
reorder
|
bool
|
reorder dataset according to |
True
|
check_no_in_after_treatment
|
bool
|
run check method |
True
|
check_no_out_before_treatment
|
bool
|
run check method |
True
|
check_no_duplicated_rows
|
bool
|
run check method |
True
|
check_mutiple_delivrance_on_same_date
|
bool
|
run check method |
True
|
Returns:
Type | Description |
---|---|
None
|
None (raises an error if any check fails) |
Source code in opentak/utils_events/checks.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
Functions¶
check_in_for_everybody()
¶
Verify that every patient has exactly one 'in' event.
Raises:
Type | Description |
---|---|
ValueError
|
if a patient is missing an 'in' or has more than one |
Source code in opentak/utils_events/checks.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
check_out_for_everybody()
¶
Verify that every patient has exactly one 'out' or one 'death' event.
Raises:
Type | Description |
---|---|
ValueError
|
if a patient is missing an 'out' or 'death' event or has more than one |
Source code in opentak/utils_events/checks.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
ordonne()
¶
Place 'in' events first and 'out'/'death' events last, then stably sort by ID_PATIENT then TIMESTAMP (mergesort).
Returns:
Type | Description |
---|---|
DataFrame
|
Sorted eventlog |
Source code in opentak/utils_events/checks.py
128 129 130 131 132 133 134 135 136 137 138 |
|
check_no_in_after_treatment()
¶
Ensure each patient's 'in' occurs before their first treatment event.
If violations are found: logs the patient IDs and the first four related rows, then raises ValueError.
Raises:
Type | Description |
---|---|
ValueError
|
if an 'in' appears after the first treatment |
Source code in opentak/utils_events/checks.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
check_no_out_before_treatment()
¶
Ensure each patient's 'out' occurs after their last treatment event.
If violations are found: logs the patient IDs and the last four related rows, then raises ValueError.
Raises:
Type | Description |
---|---|
ValueError
|
if an 'out' appears before the last treatment |
Source code in opentak/utils_events/checks.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
check_no_duplicated_rows()
¶
Ensure the dataset has no duplicated rows.
Raises:
Type | Description |
---|---|
ValueError
|
if duplicate rows are found |
Source code in opentak/utils_events/checks.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
check_mutiple_delivrance_on_same_date()
¶
Check whether any patients have multiple deliveries of different medications on the same day.
Returns:
Type | Description |
---|---|
bool
|
bool — True if multiple deliveries exist, False otherwise |
Raises:
Type | Description |
---|---|
ValueError
|
if three or more deliveries occur the same day (excluding 'in' and 'out') |
Source code in opentak/utils_events/checks.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|