google / android-fhir

The Android FHIR SDK is a set of Kotlin libraries for building offline-capable, mobile-first healthcare applications using the HL7® FHIR® standard on Android.
https://google.github.io/android-fhir/
Apache License 2.0
495 stars 296 forks source link

Add support for nested filtering using combinations of AND and OR operations #2710

Open allan-on opened 3 weeks ago

allan-on commented 3 weeks ago

Is your feature request related to a problem? Please describe. Currently, it isn't possible to perform complex search operations where you can filter resources by combining AND and OR operations.

Describe the solution you'd like The SDK search functionality should be extended to support complex search filter operations such as searching for active patients whose name contains the search term OR identifier is equal to the search term/value.

fhirEngine.search<Patient> {
     filter(Patient.Active, {
       value = "true"
       modifier = StringFilterModifier.MATCHES_EXACTLY
     })

     operation(Operation.OR) {
         filter(Patient.GIVEN, {
           value = "Jay"
           modifier = StringFilterModifier.CONTAINS
         })

         operation(Operation.AND) {
             filter(Patient.IDENTIFIER, {
               value = "Jay"
               modifier = StringFilterModifier.CONTAINS
             })

             filter(Patient.IDENTIFIER, {
               value = "Official"
               modifier = StringFilterModifier.CONTAINS
             })
         }

    }

        operation = AND
}

The preferred implementation is to use the operation = AND|OR added to each filter. Each filter can have sub-filters, with a function to group filters together.

search{
  filter{
    filter(name, value)
    filter(name, value)
    operation = OR
  }
  filter(name, value)
  operation = AND
}

Describe alternatives you've considered

  1. Using a custom search param that will extract all the required items, i.e. Patient.name, Patient.identifier into the StringIndexEntity table.

Additional context Add any other context or screenshots about the feature request here.

Would you like to work on the issue? Please state if this issue should be assigned to you or who you think could help to solve this issue.

allan-on commented 3 weeks ago

Doing a similar search using Search filters on a HAPI Server is supported, and the expression would be, for example:

 https://my-fhir-server.org/fhir/Patient?_filter=active eq false and (identifier eq 90007 and name eq Bari)
dubdabasoduba commented 3 weeks ago

@jingtang10