google / android-fhir

The Android FHIR SDK is a set of Kotlin libraries for building offline-capable, mobile-first healthcare applications using the HL7® FHIR® standard on Android.
https://google.github.io/android-fhir/
Apache License 2.0
476 stars 253 forks source link

New API to support saving local only resources #2123

Open ndegwamartin opened 1 year ago

ndegwamartin commented 1 year ago

Is your feature request related to a problem? Please describe. Sometimes we need to persist resources on the device's database without creating local changes to be synced to the server. Such resources may be downloaded from the server or perhaps generated by the client itself.

Currently the only way to persist a resource is to use the FhirEngine.create API method which flags the resources for sync.

Describe the solution you'd like This could be solved by exposing the Database.insertRemote API via the FhirEngine API by adding the following interface and implementation.

//FhirEngine.kt
suspend fun createRemote(vararg resource: Resource)
//FhirEngineImpl.kt
  override suspend fun createRemote(vararg resource: Resource){
    return database.insertRemote(*resource)
  }

Describe alternatives you've considered An alternative approach could be to enhance the current FhirEngine.create API and pass a flag to determine whether it should be marked for sync or is a local only resource.

//FhirEngine.kt
suspend fun create(val isLocalOnlyChange:Boolean = false, vararg resource: Resource): List<String>

Might be better to name the flag something like isSyncable or syncUp and set its default to true to avoid any confusion with the existing concept of local changes.

Additional context N/A

Would you like to work on the issue? Yes

ndegwamartin commented 11 months ago

Appears in Kotlin an overriding function is not allowed to specify default values for its parameters. I will therefore make a PR with the original solution and we can iterate on that if need be.

jingtang10 commented 6 months ago

what does it mean for a non-local only resource to depend on a local only resource? this shouldn't really work as we'd be potentially breaking data integrity on the server if the non-local only resource is uploaded to the server. to what extent is this a problem in our case and how should we handle it?

jingtang10 commented 6 months ago

ping @ndegwamartin

aditya-07 commented 3 weeks ago

@ndegwamartin Is this change still required or we can close it?