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

(feat) Dynamic Offline Data for Forms | Offline Support for Concept Labels #710

Merged

Conversation

manuelroemer
Copy link
Member

Requirements

  • This PR has a title that briefly describes the work done, including the ticket number if there is a ticket.
  • My work conforms to the OpenMRS 3.0 Styleguide.
  • My work includes tests or is validated by existing tests.

Summary

This builds upon the changes in this PR. It migrates the patient chart towards the new dynamic data API. Notably, these areas have been updated:

  • Existing patient synchronization handlers using the previous API (from the legacy patient-list way).
  • Offline forms have been updated to leverage the dynamic data API for storing which forms are made available offline.

In addition, since it builds upon the new dynamic data API, I integrated offline support for the Ampath form concept labels which have been introduced in this commit a while ago. This should allow forms using concept labels to properly display offline.

⚠️ This will not build until the PR in esm-core is approved and on NPM. See the "Other" section in the esm-core PR for details about when the PRs should ideally be merged.

Related Issue

https://issues.openmrs.org/browse/O3-1110
https://issues.openmrs.org/browse/O3-1293

@manuelroemer manuelroemer requested a review from ibacher June 3, 2022 11:45
Comment on lines +96 to +100
const expectedUrls = await getCacheableFormUrls(identifier);
const absoluteExpectedUrls = expectedUrls.map((url) => window.origin + makeUrl(url));
const cache = await caches.open('omrs-spa-cache-v1');
const keys = (await cache.keys()).map((key) => key.url);
return absoluteExpectedUrls.every((url) => keys.includes(url));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am honestly torn about whether we should extract this logic here into a utility function in core. It is more or less the same code in every instance where it occurs (at the moment - it doesn't necessarily have to stay that way). I think it is duplicated around 5 times right now.
The reason for not doing it at the moment is that not moving it into core means that we don't have to commit to a new API that needs to be supported in the long run. Maybe it makes sense to wait and see how this develops and then, at some point, we can move it to core? Any thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my usually threshold for this is that if I've copied and pasted a snippet (or written something close enough) 3 times, its time to move it into a proper function. We can even do this without necessarily committing to an API by marking the function as @internal.

In any case, at some point, either the scheme contained in these lines is the de facto standard and having it implemented as a function means that its easier to make sure that others implement it correctly or we discover a need to change the scheme and its much easier if we only need to update it in one place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] 3 times, its time to move it into a proper function [...]

That sounds like a good approach. I think in this specific case, I'd like to delay it a little bit to move things forward, but I'll keep it on my todo list (and perhaps even think about a proper way to do this - functions for cache interaction would generally be a nice addition to core, maybe even without an @internal modifier).

@manuelroemer manuelroemer marked this pull request as ready for review June 20, 2022 14:10
Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, with suggestion to change one function name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants