Fetching complex obs's data via Angular/REST?

I am little confused about the REST resource for Complex Obs. I am referring to 2 source files in webservices rest.

  1. ObsResource1_8
  2. ObsComplexValueController1_8

In ObsResource1_8, why do we assume that the complex value will always be raw data (raw view)? Do we assume that the valueComplex always to be serialized content? What if it was a json block or a reference to a “location” or “address_entry” or “provider” etc? Also the value representation for “RAW VIEW” gives out very little information about the data to be fetched from /obs/{uuid}/value.

       "value": {
            "display": "raw file",
            "links": {
                "rel": "self",
                "uri": "http://localhost:8080/openmrs/ws/rest/v1/obs/e2821620-66ff-11e7-9951-0242ac110002/value"
            }
        }

IMHO, it ought to give out more info. maybe - display should be the string interpretation of the data, or indication of what type of value the /value will return.

       "value": {
            "display": "Location: General OPD",
            "links": {
                "rel": "self",
                "type": "application/json",
                "uri": "http://localhost:8080/openmrs/ws/rest/v1/obs/e2821620-66ff-11e7-9951-0242ac110002/value"
            }
        }

I would expect corresponding behavior from the “ObsComplexValueController”. The code gives impression [ObsComplexValueController.getFile()] that the expected content is a file. Depending on the “accept” header (led by the previous link type), the corresponding type should be serialized and sent and not just byte stream (file or image). e.g. for “application/json” serialize to a json response.

Thoughts? Of course the above arguments are not valid if you are saying that valueComplex to be always serialized content (and not meant for references to another resource or a complex representation through JSON).

So we do want to support passing not only raw data, but I haven’t had time to implement it. RAW_VIEW is supported by all handlers (although not enforced by API, see TRUNK-5020), thus it got prioritized. We have the following handlers in openmrs-core https://github.com/openmrs/openmrs-core/tree/master/api/src/main/java/org/openmrs/obs/handler so there’s nothing to support jsons or uris out of the box. The closest it gets is the text handler.

I’d suggest creating 2 issues for openmrs-core to add json and uri handlers. It would be handy not to have to post jsons or uirs as base64 so I’d add a line checking if the value is base64 encoded or not somewhere around here.

Our obs handlers are created to support multiple views. We could add an info about the default mime-type returned when there’s no view parameter specified or even provide separate links for each supported view and the returned mime-type. Note that mime-type was added to ComplexData in openmrs-api 1.11+.

ComplexData has the title field, which is a string representation of the data. We could easily use that for the display property.

The issue with accessing ComplexData is that it may be inefficient as some custom handlers may access or even process the data when creating the object.