Create Complex Obs with REST API

(Sajan George) #1

Version - OpenMRS 2.0.5 Rest Services version-2.23 I am trying to upload an image to a complex observation.I created a concept with complex type and imagehandler.When I try to use online , the image is getting uploaded and I can also download the image with the uri present in the response. When I try with REST api however it does not work.No error occurs , but no uri with value is getting generated.Could you let me know what is the correct payload that I should be passing . Is the feature available for 2.0.5 ?.The below is the sample json I was trying with.

{ “uuid”:“1639045f-35a7-4dc6-8608-ff6070fa53bc”, “encounterDatetime”: “2019-02-06T12:44:34.662+0530”, “patient”: “ffc30b9b-0de9-4c10-95e5-227043c8b45b”, “encounterType”: “8d5b27bc-c2cc-11de-8d13-0010c6dffd0f”, “visit”: “5b72525f-f553-4557-b7b1-06801ab2aad9”, “obs”: [ { “concept”: “8f0a07f6-2d51-4ea9-abb2-02779f2d78f5”, “value”: Base 64 encoded value of file as string } ], “encounterProviders”: [ { “encounterRole”: “73bbb069-9781-4afc-a9d1-54b6b2270e04”, “provider”: “163b48e5-26fb-40c1-8d94-a6c873dd2869” } ], “location”: “b56d5d16-bf89-4ac0-918d-e830fbfba290” }

How do I pass the filename also?.I tried putting filename field in the obs json , but it was throwing an error.So it’s going in as RAW.

(tendo kiiza Martyn) #2

@sajankos What do you have on your log ?

(Moses Mutesasira) #3

No i haven’t seen a functionality of passing the file-name directly to the URL of the obs resource. You can do the following.

the value parameter takes in a converted value of the file e.g

    InputStream in = getClass().getClassLoader().getResourceAsStream("customTestDataset.xml");
    		ByteArrayOutputStream out = new ByteArrayOutputStream();
    		IOUtils.copy(in, out);
String value = DatatypeConverter.printBase64Binary(out.toByteArray());

or you’ll just attach the actual file to the request like the way PostMan can do it ssss