Utils
Classes¶
Functions¶
get_evt_log_with_frosenset_evt(log, list_ignored_evt=None)
¶
Transform the log to group concomitant events and keep only those.
This prepares the data for analysis by identifying events occurring at the
same time for the same patient and replacing their set of events with a
frozenset
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log
|
DataFrame
|
DataFrame with columns "ID_PATIENT", "EVT" and "TIMESTAMP" |
required |
list_ignored_evt
|
list[str] | None
|
events that should never be considered concomitant (e.g., 'in', 'out', 'death') |
None
|
Returns:
Type | Description |
---|---|
Series
|
Series of only concomitant events (same patient and timestamp) where values are the |
Source code in opentak/utils_events/utils.py
9 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 |
|
regroup_evt(log, list_ignored_evt=None, list_fzset_to_be_regrouped=None, sep=' + ')
¶
Group concomitant events into a single event label like "A + B".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log
|
DataFrame
|
DataFrame with columns "ID_PATIENT", "EVT" and "TIMESTAMP" |
required |
list_ignored_evt
|
list[str] | None
|
events that should never be considered concomitant (e.g., 'in', 'out', 'death') |
None
|
list_fzset_to_be_regrouped
|
list | None
|
list of frozensets describing which combinations to group (e.g., [frozenset({"A", "B"}), frozenset({"B", "D"})]). If None, all concomitant events are grouped. |
None
|
sep
|
str
|
separator used when concatenating events (e.g., sep=" + " turns events "A" and "B" into the single event label "A + B") |
' + '
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame where targeted concomitant events belonging to list_fzset_to_be_regrouped are grouped into a single event label |
Source code in opentak/utils_events/utils.py
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 71 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 97 98 99 |
|
order_in_first_out_last(log)
¶
Reorder log according to ID_PATIENT and TIMESTAMP, with in first and out last when several EVT.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log
|
DataFrame
|
df to be reordored |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
log reordored |
Source code in opentak/utils_events/utils.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
deal_with_double_delivrance(base, reset_index=True)
¶
Swap the order of rows in an event log for specific double-delivery cases.
When a patient has a treatment subsequence like A-B-A with B and A given at
the same TIMESTAMP
, the B-A pair at that timestamp is swapped to A-B.
Likewise for A-B-A where A-B are given at the same timestamp: the pair is
reordered to A-A then B at the next timestamp, to match the treatment logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base
|
event log with columns ID_PATIENT, TIMESTAMP and EVT |
required | |
reset_index
|
reset the index before returning (rows may be permuted) !!! note |ID_PATIENT|TIMESTAMP|EVT| | :--: | :--: | :--: | |...|...|...| |10|x|A| |10|y|B| |10|y|A| |...|...|...| with x < y, becomes |ID_PATIENT|TIMESTAMP|EVT| | :--: | :--: | :--: | |...|...|...| |10|x|A| |10|y|A| |10|y|B| |...|...|...| and |ID_PATIENT|TIMESTAMP|EVT| | :--: | :--: | :--: | |...|...|...| |10|x|A| |10|x|B| |10|y|A| |...|...|...| with x < y, becomes |ID_PATIENT|TIMESTAMP|EVT| | :--: | :--: | :--: | |...|...|...| |10|x|A| |10|x|A| |10|y|B| |...|...|...| |
True
|
Returns:
Type | Description |
---|---|
DataFrame
|
event log where rows were reordered to reflect the patient's treatment logic |
Source code in opentak/utils_events/utils.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
add_evt_duration(base, check=True)
¶
Add a column with the delay until the next event (treatment duration).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base
|
DataFrame
|
DataFrame — one row per event for a patient; columns: 'ID_PATIENT', 'EVT', 'TIMESTAMP' |
required |
check
|
set to False to skip validations (e.g., if there is neither 'in' nor 'out') |
True
|
Returns:
Type | Description |
---|---|
DataFrame
|
copy of the input with an additional |
Source code in opentak/utils_events/utils.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|