Dear Altruist,
We were trying to write an OpenFN job to upsert an encounter in OpenMRS. However, it seems that it is always creating new resources (encounters) instead of updating existing ones. Though the console log shows it has indeed found the resources and successfully updated them,
ADA Preparing composed upsert on encounter
ADA GET /ws/rest/v1/encounter?patient=f1add10d-6851-43b1-b7d9-7236a06b478f&encounterType=7e10b3cb-e42f-11e5-8c3e-08002715d519&fromdate=2025-06-12T11%3A06%3A28.234&todate=2025-06-12T11%3A11%3A13.962&limit=1 - 200 in 198ms
ADA encounter found: updating existing resource
ADA Preparing to update encounter
ADA POST /ws/rest/v1/encounter - 201 in 146ms
ADA Successfully updated encounter
Have you encountered a similar issue before? Would you please suggest what we might be missing? The following are our environment and version details.
We are using the openFN lightning v2,
VER Versions:
▸ node.js 22.16.0
▸ worker 1.13.6
▸ @openfn/language-common 2.4.0
▸ @openfn/language-openmrs 5.0.2
Thank you @joe for your quick checking, there is also another kind of problem with this version that may be relevant, this case’s upsert did not find the encounter and wanted to create a new encounter URL for the POST, but that also seems generate incorrect POST URL.
It seems it drops the resource name at the end of POST URL,
e.g. POST to https://:our-host:/openmrs/ws/rest/v1
Preparing composed upsert on encounter
ADA GET /ws/rest/v1/encounter?patient=6074816c-ade7-41bd-abf9-17205e9c2fff&encounterType=7e10b3cb-e42f-11e5-8c3e-08002715d519&fromdate=2025-06-12T11%3A06%3A28.234&todate=2025-06-12T11%3A11%3A13.962&limit=1 - 200 in 709ms
ADA encounter not found: creating new resource
ADA Preparing to create
R/T 3-createOpenMRSEncounter aborted with error (3.514s)
R/T Error reported by "each()" operation line 2:
R/T Error: POST to https://<our-host>/openmrs/ws/rest/v1 returned 405: Method Not Allowed
@openfn/language-common/dist/util.cjs:149:19)
@openfn/language-common/dist/util.cjs:235:3)
@openfn/language-openmrs_5.0.2/dist/index.cjs:90:22)
@openfn/language-openmrs_5.0.2/dist/index.cjs:290:22
R/T Additional error details:
R/T {
"body": {
"error": {
"code": "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver:677",
"message": "[Request method 'POST' not supported]"
}
},
Hope this might also be helpful for you while checking.
@sohel I think I have a fix to your first issue. Are you comfortable using the openfn CLI? Are you able to run some local testing on the unreleased adaptor? I can help you but don’t worry if this sounds too difficult We can just release the adaptor to the app and see if it works
Regarding your second issue I can see the problem. That also looks like a adaptor bug. It might be a little harder, I’m going to give it some thought.
Sure @joe, Thank you very much that pretty fast with fixation, I am not super used to with CLI yet :-), but let me know how I may help with local testing ?
Thank you @joe for the quick help, yes, we are waiting for the patch release.
Sorry, we are not using SAS; we are checking with the local instance.
Yes, it seems local testing involves a handful number of steps , better for us to skip for now as you are doing this already.
Thank you, @joe, for your quick fix. The new version we tested from the CLI is spotless and working as expected. New Resource:
Preparing composed upsert on encounter
GET /ws/rest/v1/encounter?patient=f1add10d-6851-43b1-b7d9-7236a06b478f&encounterType=7e10b3cb-e42f-11e5-8c3e-08002715d519&fromdate=2025-06-08T11%3A06%3A28.234&todate=2025-06-08T11%3A11%3A13.962&limit=1 - 200 in 279ms
encounter not found: creating new resource
Preparing to create encounter
POST /ws/rest/v1/encounter - 201 in 286ms
Successfully created encounter
Update Resource:
Preparing composed upsert on encounter
GET /ws/rest/v1/encounter?patient=f1add10d-6851-43b1-b7d9-7236a06b478f&encounterType=7e10b3cb-e42f-11e5-8c3e-08002715d519&fromdate=2025-06-12T11%3A06%3A28.234&todate=2025-06-12T11%3A11%3A13.962&limit=1 - 200 in 233ms
encounter/4ff392d6-cd50-4841-8cb2-86396c90f1c7 found: updating existing resource
Preparing to update encounter/4ff392d6-cd50-4841-8cb2-86396c90f1c7
POST /ws/rest/v1/encounter/4ff392d6-cd50-4841-8cb2-86396c90f1c7 - 200 in 238ms
Successfully updated encounter/4ff392d6-cd50-4841-8cb2-86396c90f1c7
To get this new adapter version available in our local instance, do we need to reinstall the whole setup, or will any configuration update work?
Thank you all for fixing the resource URL in openmrs@5.0.3. We are now using that version and it seems now updating the correct resources as it finds during the time of upsert. But still another issue, we noticed that inside the encounter it is creating the new observations instead of updating the existing observations. Though it is showing updating the existing resources in log,
Preparing composed upsert on encounter
ADA GET /ws/rest/v1/encounter?patient=f1add10d-6851-43b1-b7d9-7236a06b478f&encounterType=7e10b3cb-e42f-11e5-8c3e-08002715d519&fromdate=2025-06-12T11%3A06%3A28.234&todate=2025-06-12T11%3A11%3A13.962&limit=1 - 200 in 99ms
ADA encounter/b52cf352-9540-43be-9340-0da05f22709a found: updating existing resource
ADA Preparing to update encounter/b52cf352-9540-43be-9340-0da05f22709a
ADA POST /ws/rest/v1/encounter/b52cf352-9540-43be-9340-0da05f22709a - 200 in 233ms
ADA Successfully updated encounter/b52cf352-9540-43be-9340-0da05f22709a
Do you have the similar issue or suggestions why this might be?
We believe that if you repost the existing payload, it will add these as a new observation within the existing encounter in OpenMRS. May be to update observations in an existing encounter, need to update the encounter payload with the observation’s existing UUID and with its new value before repost.
Hi @sohel - yes I believe that’s how the OpenMRS REST API behaves as observations are considered a top-level resource (and not a subresource of encounters).
When you create or update an encounter, per the api docs it looks like you can include an obs array of new observations in the same payload
To update existing observations, you’ll need the observation records’ uuid to do so, and there even looks like there is a dedicated api endpoint (see api docs) for updating these resources
//example openfn job code to update an existing observation
update('obs/727124cd-191e-4073-a619-d3169c228374', {
'value': 71
})