ideafast / middleware-services

Python API containing endpoints for smartphone hub applications and transfer to data portal
0 stars 0 forks source link

UCAM: ensure `patient_by_wear_period` considers same day checkin and out #84

Open davidverweij opened 3 years ago

davidverweij commented 3 years ago

In the (very unlikely, but realistic) scenario that a device is being worn by two different patients on the same day, our pipeline will not associate the data to the correct patient. This is due to our use of normalise_day in combination with UCAM only containing the granularity of days and not hours. Relatedly, NCL reported that in UCAM they couldn't check in a device for a patient if it was only checked out that day.

The core issue is in the granularity of check in and out times (now only days) in UCAM, though once this is improved, our pipeline might still miss this edge case.

To illustrate, if a user worn a Dreem device at night, but only after 00:00, data will be:

last user:  from last week - to today
next user: from today - next week
data: from today - today

Due to normalise day, the recording from today - today will satisfy being within both end and start days of both patients, and data actually belonging to the second patient is lost.

At this time, this isn't of too importance; but a good edge case to catch in high-turnaround environments (and this case has been reported in NCL)

jawrainey commented 3 years ago

The core issue is in the granularity of check in and out times (now only days) in UCAM, though once this is improved, our pipeline might still miss this edge case.

This is true if we continue to use normalise_day. Previously, complete datetimes were compared within the inventory but introduced some problems as devices may be checked out before patients actually have them or multiple patients use the device in one day (e.g., on testing accounts). If UCAM provide hours/minutes (ISO 8601 formatted) the comparsion with normalise_day could be removed and it'll work as-is.

Having said that, I suspect that asking staff to input hours/minutes is not ideal given they enter data into UCAM days after a patient is onboarded. Perhaps this is something that UCAM could do behind the scenes, e.g., if a device was returned on Day X and checked out on Day X, then the former could be 10:00 and the latter 12:00. That way we could tell the difference without having to ask clinicans to input such datetimes. What's your thoughts @davidverweij and sounds like something to raise with UCAM.