FHIR Chat · HAPI FHIR - Pass List<Observation> to create method · hapi

Stream: hapi

Topic: HAPI FHIR - Pass List<Observation> to create method


view this post on Zulip Valeriy Shtanko (Jan 31 2019 at 15:42):

Hi!
I am new with HAPI FHIR and asking for help with my task.

I want to pass a list of Observation to the method in my Observation resource provider.
When I try to do

@Create
public MethodOutcome createObservationResult(@ResourceParam List<Observation> results) {
...
}

I face a multiple issues such as incorrect resource type, wrong json.
Could you advise me a correct approach for that task?

view this post on Zulip Lars Rückert (Feb 01 2019 at 08:30):

Hi Valeriy.

I think for the @Create method of the Observation provider he expects the @ResourceParam to be a plain Observation, not a list of observations. Not sure if that can be changed, but what you could do is either use a transaction bundle to post multiple observations at once, or you implement a custom operation on your provider, which can then probably can take a list of observations.

Hope this helps somewhat.
Best regards,
Lars

view this post on Zulip Valeriy Shtanko (Feb 01 2019 at 10:52):

Hi Lars,
Thank you for your answer.

I have googled for information about HAPI custom operation, but didn't find useful information(only about standard REST operations).
May be you can point me on place in HAPI documentation or another place about custom operation in HAPI?
Thanks.

view this post on Zulip Lars Rückert (Feb 01 2019 at 11:28):

I think custom operation is a wrong term. I think you can find the basic information in the RestfulOperation Docu:
http://hapifhir.io/doc_rest_operations.html#_toc_extended_operations

view this post on Zulip Patrick Werner (Feb 01 2019 at 12:24):

the best way to learn how to implement custom operations in hapi is to look at existing operations. I implemented $document recently and had a look on Patient$everything and other implemented operations to get a feeling for it.

view this post on Zulip Valeriy Shtanko (Feb 01 2019 at 12:47):

Thank you for the link, it helps a lot.

But as I can see in documentation for extended operations "FHIR allows operation parameters to be of a Search parameter type (e.g. token) instead of a FHIR datatype (e.g. Coding)."

Looks like I am not able to pass List<Observation> to extended operation
:-(

view this post on Zulip Lars Rückert (Feb 01 2019 at 12:50):

You can give a resource though, so you could just send a Bundle of Observations. Then your operation can work through the bundle entries, just like it would work through a list.

view this post on Zulip Valeriy Shtanko (Feb 01 2019 at 13:21):

Is this correct bundle to send?

{
"resourceType": "Bundle",
"id": "cf288d1c-6828-4a63-a3c1-3d503a1e7759",
"meta": {
"lastUpdated": "2019-01-31T14:53:33.392+02:00"
},
"type": "message",
"total": 3,
"link": [
{
"relation": "self",
"url": "http://localhost:8089/fhir/Observation"
}
],
"entry": [
{
"fullUrl": "http://localhost:8089/fhir/Observation/333",
"resource": {
"resourceType": "Observation",
"id": "333",
"basedOn": [
{
"reference": "referral-id"
}
],
"performer": [
{
"reference": "referral-id"
}
],
"component": [
{
"code": {
"coding": [
{
"code": "name-of-analysis"
}
]
},
"valueString": "aaa"
},
{
"code": {
"coding": [
{
"code": "result-of-analysis"
}
]
},
"valueString": "bbb"
},
{
"code": {
"coding": [
{
"code": "unit-of-measurement"
}
]
},
"valueString": "ccc"
},
{
"code": {
"coding": [
{
"code": "reference-interval"
}
]
},
"valueString": "ddd"
}
]
}
},
{
"fullUrl": "http://localhost:8089/fhir/Observation/333",
"resource": {
"resourceType": "Observation",
"id": "333",
"basedOn": [
{
"reference": "referral-id"
}
],
"performer": [
{
"reference": "referral-id"
}
],
"component": [
{
"code": {
"coding": [
{
"code": "name-of-analysis"
}
]
},
"valueString": "aaa"
},
{
"code": {
"coding": [
{
"code": "result-of-analysis"
}
]
},
"valueString": "bbb"
},
{
"code": {
"coding": [
{
"code": "unit-of-measurement"
}
]
},
"valueString": "ccc"
},
{
"code": {
"coding": [
{
"code": "reference-interval"
}
]
},
"valueString": "ddd"
}
]
}
},
{
"fullUrl": "http://localhost:8089/fhir/Observation/333",
"resource": {
"resourceType": "Observation",
"id": "333",
"basedOn": [
{
"reference": "referral-id"
}
],
"performer": [
{
"reference": "referral-id"
}
],
"component": [
{
"code": {
"coding": [
{
"code": "name-of-analysis"
}
]
},
"valueString": "aaa"
},
{
"code": {
"coding": [
{
"code": "result-of-analysis"
}
]
},
"valueString": "bbb"
},
{
"code": {
"coding": [
{
"code": "unit-of-measurement"
}
]
},
"valueString": "ccc"
},
{
"code": {
"coding": [
{
"code": "reference-interval"
}
]
},
"valueString": "ddd"
}
]
}
}
]
}

view this post on Zulip Patrick Werner (Feb 01 2019 at 13:27):

Your reference to referral-id is not valid, should be Referralrequest/referral-id or an absolute URL. You can validate your Bundle yourself against public FHIR servers using the $validate operation, there are more errors in this bundle.

view this post on Zulip Patrick Werner (Feb 01 2019 at 13:29):

You also chose Message as Bundle Type, which would need a MessageHeader as the First Resource of the bundle. I would go for batch if you want to send this to your custom Operation

view this post on Zulip Patrick Werner (Feb 01 2019 at 13:48):

just read your question in the implementers stream, your custom operation has to be on the Bundle Endpoint, not on Observation.

view this post on Zulip Valeriy Shtanko (Feb 01 2019 at 13:48):

Thank you a lot!!!
I am fixing my bundle json.

I implement the follows operation method inside Observation provider (<base>/Observation)

@Operation(name="$OP_SAVE_OBSERVATION_RESULTS")
public MethodOutcome saveObservationResult(
        @OperationParam(name="Observation.class") List&lt;Observation&gt; theObservation)

{
return new MethodOutcome();
}

When I send my bundle json inside method I have a list with one Observation which has all values null.

Is it because of incorrect json or I am doing something wrong?

view this post on Zulip Valeriy Shtanko (Feb 01 2019 at 16:56):

Very strange situation.
I don't understand what happened, but now expected list of observations always comes as null.
:-(

view this post on Zulip Valeriy Shtanko (Feb 04 2019 at 10:48):

Guys, I am lost.
Is it possible at all to implement and use the follows method to pass list of Observations into Observation resource provider :

@Operation(name="$saveObservationResults")
public MethodOutcome saveObservationResults(
        @OperationParam(name="Observation.class") List&lt;Observation&gt; observations) { ... }

I send to that method bundle of Observations generated by FHIR sample server but whithout success.
Whatever I send I always get null as input.


Last updated: Apr 12 2022 at 19:14 UTC