Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUMC] Error in difftimes for second ICU stays #20

Open
prockenschaub opened this issue Oct 4, 2022 · 2 comments
Open

[AUMC] Error in difftimes for second ICU stays #20

prockenschaub opened this issue Oct 4, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@prockenschaub
Copy link
Collaborator

AUMCdb, like eICU, does not provide dates but instead reports times since admission. For this reason, both databases are loaded in ricu via that load_eiau function.

Problem

The calculation of times -- while similar -- is not equal between eICU and AUMCdb. While in eICU times denote the number of minutes from unit admit time, in AUMCdb they represent milliseconds since the first ICU admission. That is, while eICU provides the time since current admission, AUMCdb gives the time since the first admission. load_eiau however treats them both the same, which leads to incorrect times for AUMCdb

Example

library(ricu)

# Two admissions for one patient. Note that the first admittedat is always 0, 
# whereas the second is relative to the first
aumc$admissions[aumc$admissions$patientid == 38, c("admissionid", "admittedat", "dischargedat")]
#>    admissionid admittedat dischargedat
#> 1:          40          0     56820000
#> 2:          41  164280000    325620000

# For heart rates during the first admission, everything works correctly
aumc$numericitems[aumc$numericitems$admissionid == 40 & aumc$numericitems$itemid == 6640, c("admissionid", "measuredat", "value")][1]
#>    admissionid measuredat value
#> 1:          40     300000    86
load_concepts("hr", "aumc", patient_ids = 40, interval = mins(1L))[1]
#>   admissionid measuredat    hr
#>         <int> <drtn>     <dbl>
#> 1          40 5 mins        86
ricu:::ms_as_mins(300000 - 0) # <-- correct
#> Time difference of 5 mins

# For heart rates during the second admission, ricu calculates difftimes since *first* admission 
aumc$numericitems[aumc$numericitems$admissionid == 41 & aumc$numericitems$itemid == 6640, c("admissionid", "measuredat", "value")][1]
#>    admissionid measuredat value
#> 1:          41  167280000   118
load_concepts("hr", "aumc", patient_ids = 41, interval = mins(1L))[1]
#>   admissionid measuredat    hr
#>         <int> <drtn>     <dbl>
#> 1          41 2788 mins    118
ricu:::ms_as_mins(167280000 - 0) # <-- incorrect
#> Time difference of 2788 mins
ricu:::ms_as_mins(167280000 - 164280000) # <-- should be this
#> Time difference of 50 mins

Note that the output above has been been shortened a little for readability.

@prockenschaub prockenschaub linked a pull request Oct 11, 2023 that will close this issue
@dplecko
Copy link
Member

dplecko commented Dec 29, 2023

Very good catch, thanks @prockenschaub. The PR currently seems to have a lot going on, unrelated to this issue (if I am not mistaken).

Could you open a simple pull request building off the current main which bumped ricu to 0.6.0? It would simplify things considerably for me. Thanks for the help!

@prockenschaub
Copy link
Collaborator Author

Sorry for the delay! Finally got to look at this and I've provided a cleaned PR here #51

@prockenschaub prockenschaub added the bug Something isn't working label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants