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

Resource Creation using POST http verb (SingleResourcePost) #2464

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

santosh-pingle
Copy link
Collaborator

@santosh-pingle santosh-pingle commented Mar 6, 2024

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #2440

Description
The resource is created locally, and the HTTP POST verb is used to synchronize the resource with the FHIR server. In return, the server sends a response containing the resource with the newly assigned resource ID. Subsequently, the local database is updated with the provided resource.

Upload strategy : SingleResourcePost
Update the resource with the received resourceId in the local database
Update the resource with the received meta data in the local database
Update the resource with the received resource json string in the local database

Update the resource with the received reference id in the local database.

Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?

Type
Choose one: (Bug fix | Feature | Documentation | Testing | Code health | Builds | Releases | Other)

Screenshots (if applicable)

Checklist

  • I have read and acknowledged the Code of conduct.
  • I have read the Contributing page.
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project.
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally.
  • I have built and run the demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

@santosh-pingle santosh-pingle marked this pull request as ready for review March 19, 2024 05:03
@santosh-pingle santosh-pingle requested a review from a team as a code owner March 19, 2024 05:03
@santosh-pingle santosh-pingle changed the title In progress : Resource Creation using POST http verb Resource Creation using POST http verb Mar 19, 2024
@santosh-pingle santosh-pingle changed the title Resource Creation using POST http verb Resource Creation using POST http verb (SingleResourcePost) Mar 19, 2024
@dubdabasoduba
Copy link
Collaborator

dubdabasoduba commented Apr 4, 2024

@santosh-pingle How is this going to work? Are we making it the default behaviour for all CREATEs.

Right now if you POST to a HAPI server, the server assigns the resource its own id.

e.g posting the following resource

{
  "resourceType": "List",
  "id": "af17fe86-561a-44b0-84d3-5e75c753f6f8",
  "meta": {
    "versionId"  : "1"                            ,
    "lastUpdated": "2024-03-13T15:41:42.808+00:00",
    "source"     : "#fd2dc30247cf61b8"
  },
  "identifier": [
    {"use": "official", "value": "f39c5f68-ab0f-4ae5-a9e2-47b0beb73d8e"}
  ],
  "status": "current",
  "code": {
    "coding": [
      {
        "system" : "http://smartregister.org/",
        "code"   : "22138876"                 ,
        "display": "Supply Inventory List"
      }
    ],
    "text": "Supply Inventory List"
  }
}

will result in

{
  "resourceType": "List",
  "id": "1759",
  "meta": {
    "versionId"  : "1"                            ,
    "lastUpdated": "2024-04-04T09:09:05.431+00:00",
    "source"     : "#fd2dc30247cf61b8"
  },
  "identifier": [
    {"use": "official", "value": "f39c5f68-ab0f-4ae5-a9e2-47b0beb73d8e"}
  ],
  "status": "current",
  "code": {
    "coding": [
      {
        "system" : "http://smartregister.org/",
        "code"   : "22138876"                 ,
        "display": "Supply Inventory List"
      }
    ],
    "text": "Supply Inventory List"
  }
}

The above behaviour is going to distort the resource references for any resources created on the mobile application

cc: @ellykits @qiarie @ndegwamartin

@dubdabasoduba
Copy link
Collaborator

@santosh-pingle How is this going to work? Are we making it the default behaviour for all CREATEs.

Right now if you POST to a HAPI server, the server assigns the resource its own id.

e.g posting the following resource

{
  "resourceType": "List",
  "id": "af17fe86-561a-44b0-84d3-5e75c753f6f8",
  "meta": {
    "versionId"  : "1"                            ,
    "lastUpdated": "2024-03-13T15:41:42.808+00:00",
    "source"     : "#fd2dc30247cf61b8"
  },
  "identifier": [
    {"use": "official", "value": "f39c5f68-ab0f-4ae5-a9e2-47b0beb73d8e"}
  ],
  "status": "current",
  "code": {
    "coding": [
      {
        "system" : "http://smartregister.org/",
        "code"   : "22138876"                 ,
        "display": "Supply Inventory List"
      }
    ],
    "text": "Supply Inventory List"
  }
}

will result in

{
  "resourceType": "List",
  "id": "1759",
  "meta": {
    "versionId"  : "1"                            ,
    "lastUpdated": "2024-04-04T09:09:05.431+00:00",
    "source"     : "#fd2dc30247cf61b8"
  },
  "identifier": [
    {"use": "official", "value": "f39c5f68-ab0f-4ae5-a9e2-47b0beb73d8e"}
  ],
  "status": "current",
  "code": {
    "coding": [
      {
        "system" : "http://smartregister.org/",
        "code"   : "22138876"                 ,
        "display": "Supply Inventory List"
      }
    ],
    "text": "Supply Inventory List"
  }
}

The above behaviour is going to distort the resource references for any resources created on the mobile application

cc: @ellykits @qiarie @ndegwamartin

This was clarified on the SDK dev call. I think this is a good addition

@santosh-pingle
Copy link
Collaborator Author

@santosh-pingle How is this going to work? Are we making it the default behaviour for all CREATEs.

Right now if you POST to a HAPI server, the server assigns the resource its own id.

e.g posting the following resource

{
  "resourceType": "List",
  "id": "af17fe86-561a-44b0-84d3-5e75c753f6f8",
  "meta": {
    "versionId"  : "1"                            ,
    "lastUpdated": "2024-03-13T15:41:42.808+00:00",
    "source"     : "#fd2dc30247cf61b8"
  },
  "identifier": [
    {"use": "official", "value": "f39c5f68-ab0f-4ae5-a9e2-47b0beb73d8e"}
  ],
  "status": "current",
  "code": {
    "coding": [
      {
        "system" : "http://smartregister.org/",
        "code"   : "22138876"                 ,
        "display": "Supply Inventory List"
      }
    ],
    "text": "Supply Inventory List"
  }
}

will result in

{
  "resourceType": "List",
  "id": "1759",
  "meta": {
    "versionId"  : "1"                            ,
    "lastUpdated": "2024-04-04T09:09:05.431+00:00",
    "source"     : "#fd2dc30247cf61b8"
  },
  "identifier": [
    {"use": "official", "value": "f39c5f68-ab0f-4ae5-a9e2-47b0beb73d8e"}
  ],
  "status": "current",
  "code": {
    "coding": [
      {
        "system" : "http://smartregister.org/",
        "code"   : "22138876"                 ,
        "display": "Supply Inventory List"
      }
    ],
    "text": "Supply Inventory List"
  }
}

The above behaviour is going to distort the resource references for any resources created on the mobile application

cc: @ellykits @qiarie @ndegwamartin

We have kept existing DefaultConsolidator as it is.

* @param preSyncResourceId The [Resource.id] of the resource before synchronization.
* @param postSyncResource The [Resource] after synchronization.
*/
suspend fun updateResourcesAndLocalChangesPostSync(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this API different from updateResourceAndReferences we already have in Database ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was something that was not updated or included in the old API. Let me check what was not included.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Essentially, the old API was not updating metadata such as version ID, last updated time, and the new resource ID in the payload of the resource, and meta data externally also.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we modify the existing API to update metadata instead of creating a new API ?
Or in case if this is not possible then rename the APIs to distinguish them properly ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am thinking of renaming api.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also the kdoc for both

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed version id issue in existing api.

Copy link
Collaborator

@MJ1998 MJ1998 May 21, 2024

Choose a reason for hiding this comment

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

Existing api you mean updateResourceAndReferences which is already there in DatabaseImpl ?
I don't see any changes in that.

Like we discussed in eng meeting, updating this API is better than creating a new API updateResourcesAndLocalChangesPostSync .

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you please confirm if you have the latest code changes? For me it looks like you are referring outdated code which is no more present in the pr.
updateResourcesAndLocalChangesPostSync is no longer valid, and the Database file does not contain any changes in the PR.

Actual fix is here
engine/src/main/java/com/google/android/fhir/db/impl/dao/ResourceDao.kt

@MJ1998
Copy link
Collaborator

MJ1998 commented May 2, 2024

Checkout this PR which added bunch of stuffs for POST upload strategy.

@santosh-pingle
Copy link
Collaborator Author

Checkout this PR which added bunch of stuffs for POST upload strategy.

Yes, I am using the core logic as it is. Only delta changes are added on top of it to achieve the end-to-end use case for resource consolidation.

@santosh-pingle santosh-pingle requested a review from MJ1998 May 8, 2024 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: PR under Review
Development

Successfully merging this pull request may close these issues.

Allow Resource Creation using POST http verb.
5 participants