Search code examples
hl7-fhirhapi-fhir

Usage of search parameter "_profile" in HAPI FHIR


In the FHIR REST API, there are some standard parameters for all resources that can be used in the 'search' endpoints.

I need to use the '_profile' parameter on a search operation: https://www.hl7.org/fhir/search.html#profile

The HAPI FHIR documentation on implementing search operations (https://hapifhir.io/hapi-fhir/docs/server_plain/rest_operations_search.html) has a lot of examples, none mention the parameters that apply to all the resources, like '_profile'.

I also checked their test server online (http://hapi.fhir.org/resource?serverId=home_r4&pretty=true&resource=Observation) and I can't find a way to specify the '_profile' there, to see how it works.

At the code level, what I'm trying to do is this:

@Search
public List<Observation> getObservationsByProfile(??? profile)
{
  ...
  if (profile == '...')
  {
    ...
  }
  else
  {
    ...
  }
  ...
}

I don't know how to specify the annotations and type of the parameter so it binds to the value provided in the '_profile' param un the requested URL.

Is there any sample code or documentation I can refere to? Thanks.


Solution

  • The way to make the search work with the "_profile" parameters is this:

    @Search
    public List<Observation> getObservationsByProfile(@OptionalParam(name="_profile) UriParam profile)
    {
      ...
      if (profile == '...')
      {
        ...
      }
      else
      {
        ...
      }
      ...
    }
    

    Even though the _xxx parameters apply to all the FHIR resources, the HAPI FHIR documentation doesn't include an example on how to use those in the search. Hope this helps as reference for others.