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

Timestamps shown in the Patient List do not match those in the database/API #418

Closed
ndobb opened this issue Jun 4, 2021 · 0 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ndobb
Copy link
Member

ndobb commented Jun 4, 2021

The Patient List shows many dates, such as those associated with clinic visits, lab result times, or whatever admins have configured Leaf to query and show.

However, the values shown to the user currently do not match those in the clinical database or Leaf API (unless you live in the UK, and unrelated to de-identification & date-shifting).

Why is this? The reason is that JavaScript internally tracks dates as UTC ticks, and assumes any input timestamp strings are in Greenwich Mean time, and "helpfully" adds the user's timezone hour difference to the resulting value. If the values stored in the clinical database are not UTC, then this hour-shifting is erroneous.

For example:

new Date("2021-05-28T14:00:00Z")
// Date Fri May 28 2021 07:00:00 GMT-0700 (Pacific Daylight Time)

Note that 2pm has become 7am.

The current JSON string (via the Leaf API) to Date conversion happens in the Patient List webworker.

To get around this (and avoid pulling in 3rd party libraries such as Moment in web workers), a function such as:

// Adapted from https://stackoverflow.com/a/36768608
const parseTimestamp = (timestampStr) => {
  const _date = new Date(timestampStr);
  return new Date(_date.getTime() + (_date.getTimezoneOffset() * 60 * 1000));
};

Should be sufficient for a fix. Let's switch to using this.

parseTimestamp("2021-05-28T14:00:00Z")
// Date Fri May 28 2021 14:00:00 GMT-0700 (Pacific Daylight Time)
@ndobb ndobb added the bug Something isn't working label Jun 4, 2021
@ndobb ndobb self-assigned this Jun 4, 2021
@ndobb ndobb added this to the 3.9.1 milestone Jun 11, 2021
@ndobb ndobb closed this as completed Oct 19, 2021
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

No branches or pull requests

1 participant