0

I'm using HAPI-FHIR library and I'm trying to introduce a new search parameter to resource provider for example :

@Read
  public Patient getResourceById(@IdParam IdDt id,
                             @RequiredParam(name="session") String session){}

But I have an exception

"ca.uhn.fhir.rest.server.ConfigurationException: Method[public ca.uhn.fhir.model.dstu.resource.Patient PatientResourceProvider.getResourceById(ca.uhn.fhir.model.primitive.IdDt,java.lang.String)] is not allowed to have a parameter annotated with @ca.uhn.fhir.rest.annotation.RequiredParam(compositeTypes=[], chainBlacklist=[], targetTypes=[], chainWhitelist=[*], name=session)"

Any suggestions how to do it?

carpinchosaurio
  • 1,175
  • 21
  • 44

1 Answers1

0

The problem here is that this method is annotated with @Read, so it's a "read"/"vread" and not a "search". To create a search method which accepts that one parameter, copy your existing method, remove the first parameter, and change @Read to @Search.

Note that you may also want to return List instead of just Patient since a search can return multiple results.

James Agnew
  • 701
  • 4
  • 3
  • Thank You for your response. The problem is that I have to introduce a new parameter to each method. I need "session" in all methods Read, Search, Update, Create,.. . I need this "session" object to call my services. Any ideas how to introduce a new require param to the each method? – Petro Mykhailyshyn Oct 10 '14 at 07:12
  • Or another suitable option for me is to have access to HttpServletRequest in the resource provider methods. – Petro Mykhailyshyn Oct 10 '14 at 10:05
  • You can actually add a parameter of type HttpServletRequest (and/or HttpServeltResponse) to any of the HAPI ResourceProvider methods and HAPI will automatically inject that object into the method parameters before executing your method. That'll give you access to the underlying session if you need it. – James Agnew Oct 10 '14 at 15:08
  • Incidentally, here's an example of exactly that: http://jamesagnew.github.io/hapi-fhir/doc_rest_server.html#Accessing_the_underlying_Servlet_RequestResponse – James Agnew Oct 10 '14 at 15:09