Stream: implementers
Topic: Working FHIR resources Offline
Mounika (May 07 2021 at 07:45):
Hi all,
We are trying to create application work offline mode using FHIR server. When no network available we are creating FHIR resource using UUID (randomly generated unique identifier) and saving locally. And work around that resource using that resources another resources references.
We have few queries around that how to save all resources when network or server available. How to check any duplicate related to uploaded data from offline.
Example: Creating Patient. Resource - offline with UUID.
Creating Allergy Intolerance resource of created offline patient as subject and saving offline.
Creating Condition resource of created offline patient as subject and saving offline.
How to save all resources and validate duplicates while saving to FHIR server best way to avoid duplicates and complexity.
Rik Smithies (May 07 2021 at 09:04):
Another way to think of this is as if perhaps you have local data that is that is not in FHIR. At some stage you take this existing local data and upload it to FHIR. How would you handle that? How would that be different to the situation you describe? Any two sets of data may have the same real world data (e.g. the same allergy twice). That is not really a FHIR issue. The exact same FHIR resources are not going to exist, presumably, if your user just created them. You would just need to do some sort of reconciliation step, probably with user assistance, to show what is on the server and what is being uploaded and say “this allergy exists on the server, do you still want to upload this new one, or do you want to merge them etc”.
Craig McClendon (May 07 2021 at 21:23):
This is not an easy problem in the general sense.
You have either a Bundle or set of resources you created offline. Some or all of them may exist already on the server.
One way to handle it would be:
1) take the set of offline resources and walk all the References between them to create a dependency graph (directed graph).
Hint: The HAPI library has a Terser object which can help with this.
2) sort the graph
At this point you know the dependency order -i.e. the order you need to resolve the resources against the server so you can update the references properly.
3) Iterate the graph and resolve each resource. This involves searching to see if it exists, and POSTing it if not.
In both cases you then need to then update the dependent resources with the newly resolved id in their references.
Step 3 is hard because you have to define what defines the uniqueness of a resource. It it an Identifier, a combination of attributes, etc.
As Rik pointed out, you may also have to account for the resources being updated by multiple sources and whether you need to merge changes vs a straight PUT to replace an existing resource.
Last updated: Apr 12 2022 at 19:14 UTC