0

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.

Pablo Pazos
  • 3,080
  • 29
  • 42
  • Note, you can use built in constants as well : https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-base/ca/uhn/fhir/rest/api/Constants.html specifically : https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-base/ca/uhn/fhir/rest/api/Constants.html#PARAM_PROFILE – granadaCoder Oct 30 '20 at 19:45

1 Answers1

1

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.

Pablo Pazos
  • 3,080
  • 29
  • 42
  • Thanks for answer. After I found this answer, I found a hapi-constant for "_profile" too. See : https://stackoverflow.com/questions/63797010/hapi-fhir-constants-for-common-parameters-defined-for-all-resources/63797498#63797498 – granadaCoder Sep 08 '20 at 18:35
  • @granadaCoder the constant is just the parameter name, the issue was really on how to receive the value correctly. – Pablo Pazos Sep 08 '20 at 22:53
  • Yes, and your "UriParam" is what I was looking for, the most important part...and why I upvoted your answer. I was just adding that .. there is a constant for that specific magic string...to avoid creating "copies" of the magic string values...in this case : "_profile". – granadaCoder Sep 09 '20 at 14:30