Openmrs Rest API Send Observation not working.

Tags: #<Tag:0x00007f8283440040> #<Tag:0x00007f828344bf58>

I want to send Form data using the rest API.

Here is my JSON:

https://pastebin.com/YnMMN0AX

And endpoint is “openmrs/ws/rest/v1/obs/” But it gives me error.
https://pastebin.com/BbMtWpYn So, What should I have to do ?

To make the thread easier to read, can you paste the stack trace at pastebin.com and then edit your post to include a link to it?

1 Like

The property is supposed to be encounterDatetime not encounterDate

@shahnewaz, the obs resource is for manipulating one single observation at a time. The JSON that you’re posting should actually go to the encounter resource, which will create an encounter that contains multiple observations.

I see a bunch of other errors in the JSON (e.g. there is no “obsName” property, and you probably mean this to be “concept”), so you will have to do more debugging.

I hope this is enough to get you started in the right direction.

@darius Can you please help me to design this JSON structure. Here is the current structure: https://pastebin.com/m7AdsmJ6

Actually I’ve to insert data into this from using API.

Take a look at these tests that create an encounter with obs: https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/EncounterController1_9Test.java

1 Like

Some of the property names are wrong, should be location and not encounterLocation, and then provider or encounterProviders and not encounterProvider depending on if you are running platform 1.8 and below or 1.9 and later. Please always refer to docs in the application for the correct property names and structure of your json, you can find the docs through the application by navigating to the main Admin page in the legacy UI, under Rest Web Services section, click on API Documentation and find the encounter and observation resources.

Can please make me json structure for image

I’ll be really grateful to you

Thanks, S

Did you take a look at the link that i sent above? It has good examples.

yes I did. But I’m not familiar with Java. I want to do it with php. I also tried as per your link instruction. Unfortunately failed. :frowning:

As per your above link jSON structure like this:

{
"location" : "25b463cb-35d5-41e0-b25b-7c0c0492ef31",
"encounterType": "fef74a7d-706b-461e-a00f-dc907d05f6f2",
"encounterDatetime" : "2011-01-15",
"patient": "61f194c6-36fd-41b4-800d-cb01df3cbf88",
"provider": "457eeb5f-1e7b-4672-b414-16b9e16b7aa4",
    "obs" :[
						{

							  "concept" : "bae8ffd2-ee79-494c-abc7-2f2a174f802a",
							  "value" : "111"
						},

						{

							  "concept" : "c201b543-00a3-4f45-b4ee-684e7fe56782",
							  "value" : "Test"
						},
						{

							  "concept" : "b37b9390-f14f-41da-893f-604def748fea",
							  "concept" : "30"
						},
						{

							  "concept" : "c28ac81f-eaf2-45ec-b9a2-5ded562d8a91",
							  "value" : "test."
						}

					]
}

but it gives error.: https://pastebin.com/DrufZq04

Replace “provider” with “encounterProviders” which is a list of {provider, encounterRole} as you can see here: https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/EncounterController1_9Test.java#L393-L404

I did it but still error. Here is the JSON:

{
"location" : "25b463cb-35d5-41e0-b25b-7c0c0492ef31",
"encounterType": "fef74a7d-706b-461e-a00f-dc907d05f6f2",
"encounterDatetime" : "2019-01-15",
"patient": "61f194c6-36fd-41b4-800d-cb01df3cbf88",
"encounterProviders":  [ 
							{
								"provider":"457eeb5f-1e7b-4672-b414-16b9e16b7aa4",
								"encounterRole": "835ec152-cb27-498a-910c-252cdff6c251"
							}
						],
"obs" :[
						{

							  "concept" : "bae8ffd2-ee79-494c-abc7-2f2a174f802a",
							  "value" : "111"
						},

						{

							  "concept" : "c201b543-00a3-4f45-b4ee-684e7fe56782",
							  "value" : "Test"
						},
						{

							  "concept" : "b37b9390-f14f-41da-893f-604def748fea",
							  "value" : "70"
						},
						{

							  "concept" : "c28ac81f-eaf2-45ec-b9a2-5ded562d8a91",
							  "value" : "test."
						}

					]
}

and error: https://pastebin.com/X0u8zNGd

Which url are you posting to? And which OpenMRS platform version are you running?

Sorry for late reply. I was in vacation.

Posted url : “http://domain.com:8080/openmrs/ws/rest/v1/obs/”; version: 2.0.6

And which version of the rest webservices module are you using?

openmrs 2.0.6

Did you understand my question? :slight_smile:

I’m out of city right now. I’ve to rejoin home to give this answer. Our previous version was 1.9.2 .Now we are upgrading 2.0.6. I’m not sure REST api version. I think its 1.9.2 version’s default rest api version.

Make sure you are running the latest version of the rest module, you can get it at https://addons.openmrs.org/show/org.openmrs.module.webservices-rest