setting encounter id in fhir Observation

Application Name: Platform Version Number: 2.1.3

Question: I’m adding observations using FHIR but “encounter” is not accepted as a valid parameter and using “extension” doesn’t actually set the encounter (the option seems to be silently ignored) Is there currently a way to set the encounter uuid when posting an observation or could I help add this feature? Thanks for any pointers!

here is a link to the test:

I’m not sure at what point the REST request gets intercepted or where the JSON array is parsed.

Do you have a unit test to reproduce the problem?

No, but I’d like to learn how to write one. Is there an example unit test for posting json to the fhir interface?

Can you share what you are exactly posting to get the reported problem?

NETWORK TRACE OF POST:

######## T 127.0.0.1:57740 -> 127.0.0.1:8080 [AP] POST /openmrs/ws/fhir/Observation HTTP/1.1. Host: localhost:8080. User-Agent: python-requests/2.18.4. Accept-Encoding: gzip, deflate. Accept: /. Connection: keep-alive. Content-Length: 437. Content-Type: application/json. Authorization: Basic

T 127.0.0.1:57740 -> 127.0.0.1:8080 [AP] {“resourceType”: “Observation”, “code”: {“coding”: [{“system”: “http://openmrs.org”, “code”: “0ec749af-b61e-421c-a932-8754d4a7ea21”}]}, “subject”: {“id”: “f3b69296-58bb-4770-937c-6320a360981f”}, “effectiveDateTime”: “2000-01-05T04:40:00”, “issued”: “2000-01-05T04:40:00”, “valueQuantity”: {“value”: 6.3, “unit”: “K/uL”, “system”: “http://unitsofmeasure.org”}, “encounter”: {“reference”: “Encounter/11c1b0ab-d213-43b1-9ea2-6c0f58e2e459”}}

T 127.0.0.1:8080 -> 127.0.0.1:57740 [AP] HTTP/1.1 201 Created. Server: Apache-Coyote/1.1. Set-Cookie: JSESSIONID=BA8AE9453939570EEADB1C91AA9B96D5; Path=/openmrs/; HttpOnly. X-Powered-By: HAPI FHIR 3.3.0 REST Server (FHIR Server; FHIR 3.0.1/DSTU3). Location: http://localhost:8080/openmrs/ws/fhir/Observation/e9dca778-9699-4c97-a56c-3887fe5aaded. Content-Encoding: gzip. Content-Type: application/fhir+json;charset=UTF-8. Transfer-Encoding: chunked. Date: Mon, 09 Jul 2018 15:23:28 GMT. …

RESULTING OBS RECORD (has no encounter) { “resourceType”: “Observation”, “id”: “e9dca778-9699-4c97-a56c-3887fe5aaded”, “status”: “final”, “code”: { “coding”: [ { “system”: “http://openmrs.org”, “code”: “0ec749af-b61e-421c-a932-8754d4a7ea21”, “display”: “White Blood Cells” } ] }, “subject”: { “id”: “f3b69296-58bb-4770-937c-6320a360981f”, “reference”: “Patient/f3b69296-58bb-4770-937c-6320a360981f”, “identifier”: { “id”: “f3b69296-58bb-4770-937c-6320a360981f” }, “display”: “James Pond(Identifier:270-9)” }, “effectiveDateTime”: “2000-01-05T04:40:00-05:00”, “issued”: “2000-01-05T04:40:00.000-05:00”, “valueQuantity”: { “value”: 6.3, “unit”: “K/uL”, “system”: “http://unitsofmeasure.org”, “code”: “K/uL” }, “referenceRange”: [ { “low”: { “value”: 0.0, “unit”: “K/uL”, “system”: “http://unitsofmeasure.org”, “code”: “]” }, “high”: { “value”: 846.7, “unit”: “K/uL”, “system”: “http://unitsofmeasure.org”, “code”: “K/uL” } } ] }

while posting, i see this in openmrs logs: WARN - LenientErrorHandler.unknownElement(150) |2018-07-09 11:23:28,692| Unknown element ‘encounter’ found while parsing

It looks like this should be set using the “context” param but that doesn’t work either: https://www.hl7.org/fhir/observation.html

where is the fhir message decoded? It looks like there are two methods defined; generateOpenMRSObsWithEncounter and generateOpenMRSObs

is it a matter of parsing the json to see if that context is set then using the appropriate method?

I forked the module and made changes to get it to work with this:

        "context": {
        "reference": "Encounter/" + encounter_uuid,
    }

Cool. Do you wanna create a ticket and raise a pull request? :slight_smile:

Happy to!