Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

[Bug] search parameter "_include" doesn't include fields with type "Reference<any>" #449

Closed
lquanx opened this issue Sep 20, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@lquanx
Copy link

lquanx commented Sep 20, 2021

Describe the bug
"_include" parameter works for most fields. However, It seems it doesn't include referenced Resource for Reference type field.

To Reproduce
Steps to reproduce the behavior:
1.POST /Patient
{ "resourceType": "Patient", "gender": "male" }
2.POST /Communication
{ "resourceType": "Communication", "status":"completed", "about": [ { "reference": "Patient/dfa6216e-10bf-4551-b19d-c9c3fd7d8952" } ] }
3.GET /Communication?&_include=*

Expected behavior
The response includes Patient resource

Versions (please complete the following information):

  • v2.2.0-smart
@lquanx lquanx added the bug Something isn't working label Sep 20, 2021
@ssvegaraju
Copy link
Contributor

Hi @Lin-002, I've successfully reproduced this behavior, and will add this to our team's backlog. Thanks for raising this issue; I will comment here when there is an update!

@lquanx
Copy link
Author

lquanx commented Sep 20, 2021

Thanks very much !

@carvantes
Copy link
Contributor

Hi @Lin-002 ,

From what I can tell, this is not actually a bug. The thing is that on the FHIR spec, the Communication.about field is not searchable.

_include does not look at ALL the references in the resource, it only looks at the searchable references(the ones that have a SearchParameter with type reference). For Communication the available reference search params are: based-on, encounter, instantiates-canonical, part-of, patient, recipient, sender, subject.
https://www.hl7.org/fhir/communication.html#search

However, it is possible to extend the functionality of FHIR works via Implementation Guides to add a SearchParameter on the Communication.about field. Please refer to: https://github.com/awslabs/fhir-works-on-aws-deployment/blob/mainline/USING_IMPLEMENTATION_GUIDES.md.

@lquanx
Copy link
Author

lquanx commented Sep 20, 2021

awesome. Thanks a lot @carvantes

@lquanx
Copy link
Author

lquanx commented Sep 21, 2021

I created a SearchParameter for "about" field, and followed instruction https://github.com/awslabs/fhir-works-on-aws-deployment/blob/mainline/USING_IMPLEMENTATION_GUIDES.md.

But, It still doesn't include "about" field. Could you help me out ?
Here is the SearchParameter definition

{
  "resourceType": "SearchParameter",
  "id": "CommunicationAboutSearchParameter",
  "url": "http://fhir.company.com/SearchParameter/Communication/about",
  "description": "This SearchParameter enables query of Communication by its about field.",
  "name": "CommunicationAboutSearchParameter",
  "status": "active",
  "type": "reference",
  "base": [
    "Communication"
  ],
  "code": "about",
  "expression": "Communication.about",
  "modifier": [
    "contains"
  ]
}

@lquanx
Copy link
Author

lquanx commented Sep 21, 2021

I have successfully added custom SearchParameter for field "about". In order to do add SearchParameter, I had to provide "expression" and "xpath" both as well as ".index.json" file.

I can search Communication Resource by "about", but I cannot include "about", "subject", "recipient" fields. Previously it can include "subject" and "recipient". But now I cannot include any of them. If I use wildcard "*", then I got HTTP 500 error.

{
    "resourceType": "OperationOutcome",
    "text": {
        "status": "generated",
        "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">error</td><td>[]</td><td><pre>Internal server error</pre></td></tr></table></div>"
    },
    "issue": [
        {
            "severity": "error",
            "code": "exception",
            "diagnostics": "Internal server error"
        }
    ]
}

@ssvegaraju
Copy link
Contributor

Hi, which Implementation Guide package is this using? And is the modified Search Parameter similar to the one posted above?

@ssvegaraju ssvegaraju reopened this Sep 21, 2021
@carvantes
Copy link
Contributor

Hi @Lin-002 ,

The error occur because your search parameter is missing the target field. search parameters of type reference must have a target value.

The following will work:

{
  "resourceType": "SearchParameter",
  "id": "CommunicationAboutSearchParameter",
  "url": "http://fhir.company.com/SearchParameter/Communication/about",
  "description": "This SearchParameter enables query of Communication by its about field.",
  "name": "CommunicationAboutSearchParameter",
  "status": "active",
  "type": "reference",
  "base": [
    "Communication"
  ],
  "code": "about",
  "expression": "Communication.about",
  "xpath": "f:Communication/f:about",
  "target": [
    "Patient",
    "Group" // etc.
  ],
  "modifier": [
    "contains"
  ]
}

Note that there's no shorthand to indicate that it targets "any" resource type. Such search params must list ALL resource types in the target array.


I have successfully added custom SearchParameter for field "about". In order to do add SearchParameter, I had to provide "expression" and "xpath" both as well as ".index.json" file.

The IG support was designed primarily to consume published IGs, so it's true that making minor changes (such as adding a single search param) can be a bit cumbersome since you need to essentially create a mini IG package. This is an interesting use case and your feedback is much appreciated!

We'll update the IG compiler to validate that reference search params have a target. @ssvegaraju, could you make this change?

@lquanx
Copy link
Author

lquanx commented Sep 22, 2021

@carvantes Thanks a lot. After adding target, "_include" parameter works like a charm !

@ssvegaraju
Copy link
Contributor

Sure, I will update the IG compiler to make sure that reference search params have the target defined, and will link that change here when done!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants