As we're looking at the closest values, we need to decide whether or not we can look at the future.
It could be considered "outcome leakage" or a violation of causality principles, but the timestamps may not be 100% accurate. On the other hand, some values don't change that much and looking at future values would retrieve the same exact values as if we did 3h before. Most of the times, if lab measurements are ordered, that's because the physician already suspects something's up.
We have to decide where are these assumptions correct or not. For example, vital signs are quite ubiquitous and we should look at past values only; on the other hand, lab values are not so common and more stable throughout time.
As we're looking at the closest values, we need to decide whether or not we can look at the future.
It could be considered "outcome leakage" or a violation of causality principles, but the timestamps may not be 100% accurate. On the other hand, some values don't change that much and looking at future values would retrieve the same exact values as if we did 3h before. Most of the times, if lab measurements are ordered, that's because the physician already suspects something's up.
We have to decide where are these assumptions correct or not. For example, vital signs are quite ubiquitous and we should look at past values only; on the other hand, lab values are not so common and more stable throughout time.