FHIR module - POST Observation body

I am trying to make an observation post request using the fhir module. I am using fhir version 0.9 and it is installed properly (as it allows me to make get requests). Therefore I think I am doing something wrong in my body request which looks like this:

{
    "resourceType":"Observation",
    "code":{
        "coding":[
            {
                "system":"http://loinc.org",
                "code":"53665-6",
                "display":"SYSTOLIC BLOOD PRESSURE"
            }
        ]
    },
    "valueQuantity":{
        "value":123.0,
        "units":"mmHg",
        "system":"http://unitsofmeasure.org",
        "code":"mmHg"
    },
    "appliesDateTime":"2016-08-14T09:41:52",
    "issued":"2016-08-14T09:41:52.000",
    "status":"final",
    "reliability":"ok",
    "subject":{
        "reference":"Patient/a740ec1e-5e3b-11e6-883f-000d3a23bb00"
    },
    "referenceRange":[
        {
            "high":{
                "value":0.0,
                "units":"mmHg",
                "system":"http://unitsofmeasure.org",
                "code":"mmHg"
            }
        }
    ]
}

I’m always getting error 400 so it must be something wrong with the request body I’m making but can’t figure out what the problem is, Any help would be greatly appreciated!

@yumed can you try use the current snapshot version of the module and see if you get the same problem?

@surangak can you add me as one of the maintainer for this module such that i can upload the latest in modulus?

1 Like

@dkayiwa sorry but what do you mean by the current snapshot version? Isn’t 0.9 the only available version of the module?

I mean the one you get after cloning and compiling https://github.com/openmrs/openmrs-module-fhir Latest released version should be 1.5 It is already bundled with the latest platform 2.0 release https://sourceforge.net/projects/openmrs/files/releases/OpenMRS_Platform_2.0.0/

1 Like

@dkayiwa thank you for your reply! I tried cloning and compiling the version from github and didn’t work so I changed my platform version to the latest 2.0.0, installed the legacy UI to test the FHIR module using the rest client interface and now i get error 422. The only thing that I changed in my post request body is the patient uuid

Try this server and tell me what happens: http://int02.openmrs.org/openmrs/module/fhir/client.form

2 Likes

Also if it isn’t work, please check your backend logs for any error as well. Share your backend logs as well.

1 Like

I solved my problem. I was getting No matching concept found for the given codings. in my log because i wasn’t actually linking my observation to any openmrs concept. This is the JSON I send now and it works.

 {
    "resourceType":"Observation",
    "code":{
        "coding":[
            {
                "system":"http://openmrs.org",
                "code":"85062ed4-6223-11e6-a4f9-000d3a23bb00",
                "display":"PULSE"
            },
            {
                "system":"http://loinc.org",
                "code":"8889-8",
                "display":"Heart Rate"
            }
        ]
    },
    "valueQuantity":{
        "value":87,
        "units":"bpm",
        "system":"http://unitsofmeasure.org",
        "code":"bpm"
    },
    "appliesDateTime":"2016-08-14T09:41:52",
    "issued":"2016-08-14T09:41:52.000",
    "status":"final",
    "reliability":"ok",
    "subject":{
        "reference":"Patient/85511527-6223-11e6-a4f9-000d3a23bb00"
    },
    "referenceRange":[
        {
            "high":{
                "value":120,
                "units":"bpm",
                "system":"http://unitsofmeasure.org",
                "code":"bpm"
            }
        }
    ]
}

But is there a way to make a FHIR request without having to give the uuid of the concept? It’s inconvenient since the request is going to be made by a mobile application that doesn’t know the uuids of the concepts.

Thank you all for your help! I really appreciate it!

1 Like

I would not recommend you to use anything other than the concept uuid. This is what is recommended going forwards. My advice is that when the mobile client is fetching concepts, make it also include the concept uuids.

2 Likes

Sorry for the trouble but I have another question. How can I store a value that is not numerical? For example if I want to make an observation for the patient’s skin type? Sending it as

  "valueQuantity":{
        "value":"type IV"
    }

wouldn’t work as openmrs would wait for a numerical value. This is what my log shows:

ERROR - ExceptionHandlingInterceptor.createOperationOutcome(141) |2016-08-16 09:08:43,098| Failure during REST processing: java.lang.NumberFormatException java.lang.NumberFormatException at java.math.BigDecimal.(Unknown Source) at java.math.BigDecimal.(Unknown Source) at java.math.BigDecimal.(Unknown Source) at ca.uhn.fhir.model.primitive.DecimalDt.parse(DecimalDt.java:108) at ca.uhn.fhir.model.primitive.DecimalDt.parse(DecimalDt.java:33) at ca.uhn.fhir.model.api.BasePrimitive.setValueAsString(BasePrimitive.java:112) at ca.uhn.fhir.parser.ParserState$PrimitiveState.attributeValue(ParserState.java:2257) at ca.uhn.fhir.parser.ParserState.attributeValue(ParserState.java:105) at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1220) at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1157) at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1210) at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1157) at ca.uhn.fhir.parser.JsonParser.doParseResource(JsonParser.java:214) at ca.uhn.fhir.parser.BaseParser.parseResource(BaseParser.java:484) at ca.uhn.fhir.rest.param.ResourceParameter.loadResourceFromRequest(ResourceParameter.java:190) at ca.uhn.fhir.rest.param.ResourceParameter.parseResourceFromRequest(ResourceParameter.java:222) at ca.uhn.fhir.rest.param.ResourceParameter.translateQueryParametersIntoServerArgument(ResourceParameter.java:116)

What is the concept data type? Why don’t you use valueString?

2 Likes

The concept data type was numerical (my mistake), I created a new concept with text data type and tried posting a request but now I’m getting:

Caused by: java.lang.RuntimeException: concept is null for obs id is null
	at org.openmrs.Obs.setValueAsString(Obs.java:1095)
	at org.openmrs.module.fhir.api.util.FHIRObsUtil.generateOpenMRSObs(FHIRObsUtil.java:337)
	at org.openmrs.module.fhir.api.impl.ObsServiceImpl.createFHIRObservation(ObsServiceImpl.java:236)
	at sun.reflect.GeneratedMethodAccessor373.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)

and the JSON I’m sending is:

{
    "resourceType":"Observation",
    "code":{
        "coding":[
            {
                "system":"http://openmrs.org",
                "code":"3d8cffcd-59a8-422d-b6f5-b4f18a0b2863",
                "display":"Skin Type"
            },
            {
                "system":"http://loinc.org",
                "code":"8889-8",
                "display":"Skin Type"
            }
        ]
    },
    "valueString":{
        "value":"type IV"
    },
    "appliesDateTime":"2016-08-14T09:41:52",
    "issued":"2016-08-14T09:41:52.000",
    "status":"final",
    "reliability":"ok",
    "subject":{
        "reference":"Patient/85511527-6223-11e6-a4f9-000d3a23bb00"
    }
}

Verify that you are sending a uuid of an existing concept.

Yes, the concept exists

Can you reproduce it here? http://int-refapp.openmrs.org/ Remember to include the exact post data you are using.

@yumed this can happen if the provided concept can’t be found. Please double check your request and the concept source.