FHIR Chat · value · implementers

Stream: implementers

Topic: value


view this post on Zulip Alvaro Riquelme Godoy (Nov 01 2016 at 00:43):

Hi everyone! I'm currently playing with Observation.class and i try to get ValueQuantity to receive value parameters at number or string, but i can't. I'm working in JAVA with Eclipse software.
I tried to perform observation.getValue().toString() and i got rare numbers and letters (ie: ca.uhn.fhir.model.dstu2.composite.QuantityDt@144ada6e)
Thanks!

view this post on Zulip Rowan Foster (Nov 01 2016 at 00:55):

You need to check what type of value is contained in the Observation and use the appropriate getter (or check the type returned by getValue())

if(observation.hasValueQuantity()) {
   QuantityDt quantity = observation.getValueQuantity();
   // TODO do stuff with quantity
} else if(observation.hasValueStringType()) {
   //...

view this post on Zulip Alvaro Riquelme Godoy (Nov 01 2016 at 01:46):

We tried using this, but the three methods mentioned are not recognized by our environment. We're working with a bundle of the resource, if it's any help.
We alse checked the observation.class file, and we didn't find this methods either.
Thank you for the help!

view this post on Zulip Rowan Foster (Nov 01 2016 at 02:17):

What version of HAPI are you using?

You could just check the type as I mentioned eg

Type value = observation.getValue();
if(value instanceof QuantityDt) {
    QuantityDt valueAsQuantity = (QuantityDt)value;
    // TODO do stuff with valueAsQuantity
}

view this post on Zulip Marcela Aguirre Jerez (Nov 02 2016 at 19:18):

Hi, I'm working with Alvaro, we're using HAPI dstu2 1.4. And we checked the type of observation.getValue() is IDatatype. So we couldn't run the codes that you've sent. Thanks again for the help. If you think that it has to do with the HAPI version, which one do you suggest?

view this post on Zulip James Agnew (Nov 05 2016 at 02:50):

Hi Marcela,

The code above that Rowan posted should work, although it has one minor correction:

IDatatype value = observation.getValue();
if(value instanceof QuantityDt) {
    QuantityDt valueAsQuantity = (QuantityDt)value;
    // TODO do stuff with valueAsQuantity
}

Basically the field Observation.value has multiple allowed types per the FHIR spec, so you need to test which one is actually there via instanceof.

view this post on Zulip James Agnew (Nov 05 2016 at 02:51):

Meant to tag you @Marcela Aguirre Jerez

view this post on Zulip Marcela Aguirre Jerez (Nov 05 2016 at 15:40):

Thank you @James Agnew !!


Last updated: Apr 12 2022 at 19:14 UTC