Class SearchParameterUtil

java.lang.Object
ca.uhn.fhir.util.SearchParameterUtil

public class SearchParameterUtil extends Object
  • Constructor Details

  • Method Details

    • getBaseAsStrings

      public static List<String> getBaseAsStrings(FhirContext theContext, IBaseResource theResource)
    • getOnlyPatientSearchParamForResourceType

      public static Optional<RuntimeSearchParam> getOnlyPatientSearchParamForResourceType(FhirContext theFhirContext, String theResourceType)
      Given the resource type, fetch its patient-based search parameter name 1. Attempt to find one called 'patient' 2. If that fails, find one called 'subject' 3. If that fails, find one by Patient Compartment. 3.1 If that returns exactly 1 result then return it 3.2 If that doesn't return exactly 1 result and is R4, fall to 3.3, otherwise, 3.5 3.3 If that returns >1 result, throw an error 3.4 If that returns 1 result, return it 3.5 Find the search parameters by patient compartment using the R4 FHIR path, and return it if there is 1 result, otherwise, fall to 3.3
    • getPatientSearchParamsForResourceType

      public static Set<String> getPatientSearchParamsForResourceType(FhirContext theFhirContext, String theResourceType)
      Given the resource type, fetch all its patient-based search parameter name that's available
    • getOnlyPatientCompartmentRuntimeSearchParam

      public static RuntimeSearchParam getOnlyPatientCompartmentRuntimeSearchParam(FhirContext theFhirContext, String theResourceType)
      Search the resource definition for a compartment named 'patient' and return its related Search Parameter.
    • getOnlyPatientCompartmentRuntimeSearchParam

    • getOnlyPatientCompartmentRuntimeSearchParam

    • getAllPatientCompartmentRuntimeSearchParamsForResourceType

    • getAllPatientCompartmenRuntimeSearchParams

    • getAllResourceTypesThatAreInPatientCompartment

    • isResourceTypeInPatientCompartment

      public static boolean isResourceTypeInPatientCompartment(FhirContext theFhirContext, String theResourceType)
      Return true if any search parameter in the resource can point at a patient, false otherwise
    • getCode

      @Nullable public static String getCode(FhirContext theContext, IBaseResource theResource)
    • getURL

      @Nullable public static String getURL(FhirContext theContext, IBaseResource theResource)
    • getExpression

      @Nullable public static String getExpression(FhirContext theFhirContext, IBaseResource theResource)
    • stripModifier

      public static String stripModifier(String theSearchParam)
    • splitSearchParameterExpressions

      public static String[] splitSearchParameterExpressions(String thePaths)
      Many SearchParameters combine a series of potential expressions into a single concatenated expression. For example, in FHIR R5 the "encounter" search parameter has an expression like: AuditEvent.encounter | CarePlan.encounter | ChargeItem.encounter | ....... This method takes such a FHIRPath expression and splits it into a series of separate expressions. To achieve this, we iteratively splits a string on any or or | that is not contained inside a set of parentheses. e.g.

      "Patient.select(a or b)" --> ["Patient.select(a or b)"] "Patient.select(a or b) or Patient.select(c or d )" --> ["Patient.select(a or b)", "Patient.select(c or d)"] "Patient.select(a|b) or Patient.select(c or d )" --> ["Patient.select(a|b)", "Patient.select(c or d)"] "Patient.select(b) | Patient.select(c)" --> ["Patient.select(b)", "Patient.select(c)"]

      Parameters:
      thePaths - The FHIRPath expression to split
      Returns:
      The split strings
    • referencePathCouldPotentiallyReferenceCanonicalElement

      public static boolean referencePathCouldPotentiallyReferenceCanonicalElement(FhirContext theContext, String theResourceType, String thePath, boolean theReverse)
      Given a FHIRPath expression which presumably addresses a FHIR reference or canonical reference element (i.e. a FHIRPath expression used in a "reference" SearchParameter), tries to determine whether the path could potentially resolve to a canonical reference.

      Just because a SearchParameter is a Reference SP, doesn't necessarily mean that it can reference a canonical. So first we try to rule out the SP based on the path it contains. This matters because a SearchParameter of type Reference can point to a canonical element (in which case we need to _include any canonical targets). Or it can point to a Reference element (in which case we only need to _include actual references by ID).

      This isn't perfect because there's really no definitive and comprehensive way of determining the datatype that a SearchParameter or a FHIRPath point to. But we do our best if the path is simple enough to just manually check the type it points to, or if it ends in an explicit type declaration.

      Because it is not possible to deterministically determine the datatype for a FHIRPath expression in all cases, this method is cautious: it will return true if it isn't sure.

      Returns:
      Returns true if the path could return a canonical or CanonicalReference, or returns false if the path could only return a Reference.