hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.05k stars 1.34k forks source link

Search Accross Multiple Resources #685

Open parisni opened 7 years ago

parisni commented 7 years ago

Hi,

Accordingly to API FHIR specifications it is also possible to search across multiple resource types:

GET [base]?_type=Condition,Observation&[parameters]{&_format=[mime-type]}

While it is possible in HAPI FHIR to search for multiple linked resources: curl -H "Accept: application/json" http://fhirtest.uhn.ca/baseDstu3/Encounter?_include=Encounter:part-of

I am not able to get for example both two kinds same time:


curl  -H "Accept: application/json" http://fhirtest.uhn.ca/baseDstu3/?_type=Condition,Observation

{
  "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>This is the base URL of FHIR server. Unable to handle this request, as it does not contain a resource type or operation name.</pre></td>\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
  },
  "issue": [
    {
      "severity": "error",
      "code": "processing",
      "diagnostics": "This is the base URL of FHIR server. Unable to handle this request, as it does not contain a resource type or operation name."
    }
  ]
}

I am missing something ?

Thanks

jamesagnew commented 7 years ago

This is not currently implemented. We can use this ticket to track this request for sure.

parisni commented 7 years ago

Hey @jamesagnew

I would be glad to develop this feature. Before I look at the source code, can you please tell me how difficult this should be? (easy, medium, hardcore) An also some guidance for me, or any developer who d'like to do this.

Thanks

jamesagnew commented 7 years ago

Hi @parisni ,

This would definitely be one of the more difficult things to accomplish unfortunately.

Most of the changes would be in the class called SearchBuilder in the JPA project. If you are comfortable with the way JPA's CriteriaBuilder works, this wouldn't be so bad, but JPA's searching is one of the more complicated parts of the library for sure (mostly because FHIR's search isn't exactly trivial :) )

There would be changes required to the core server framework too in order to allow such a search to propagate to the JPA layer but that's much easier.

I might suggest taking a look at how existing searches work. This unit test would be a good place to start: https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java

If that makes sense, modifying the SearchBuilder to allow for multi-type searches would be the next step. I could probably help you to get a unit test going for this at least..

metapink commented 5 years ago

@jamesagnew did you get any unit tests "goin" for this? I'd love to take a look

If that makes sense, modifying the SearchBuilder to allow for multi-type searches would be the next step. I could probably help you to get a unit test going for this at least..

utkinnina commented 5 years ago

Hello @jamesagnew, do you have any new about the issue? when it will be implemented?

EvDuijnhoven commented 5 years ago

Hello @jamesagnew, Is there any plan in the near future to implement this feature?