Class FhirUtil

java.lang.Object
com.ssgllc.fish.service.util.published.FhirUtil

@Component public class FhirUtil extends Object
Builds FHIR R4 responses in the scripts behind the FHIR API (/api/fhir/r4).
  • Constructor Details

    • FhirUtil

      public FhirUtil()
  • Method Details

    • searchset

      public static Map<String,Object> searchset(String baseUrl, String selfUrl, List<Map<String,Object>> resources)
      Wraps resources in a FHIR searchset Bundle. Each entry gets a fullUrl of [baseUrl]/[resourceType]/[id] when the resource has an id.
      Parameters:
      baseUrl - the FHIR base URL, available to the script as config.fhirBaseUrl
      selfUrl - the URL of this search, for the Bundle's self link; may be null
      resources - the matching resources, as maps
      Returns:
      the Bundle, as a map

      Groovy example:
      fhirUtil.searchset(config.fhirBaseUrl, config.fhirRequestUrl, [patientResource])

      Returns:
      ['resourceType': 'Bundle', 'type': 'searchset', 'total': 1, 'link': [['relation': 'self', 'url': '...']], 'entry': [['fullUrl': '.../Patient/123', 'resource': [...], 'search': ['mode': 'match']]]]
    • searchsetEntries

      public static Map<String,Object> searchsetEntries(String baseUrl, String selfUrl, List<Map<String,Object>> entries)
      Wraps resources in a FHIR searchset Bundle with search metadata per entry, e.g. a $match score or an include mode. An entry without search gets mode: match.
      Parameters:
      baseUrl - the FHIR base URL, available to the script as config.fhirBaseUrl
      selfUrl - the URL of this search, for the Bundle's self link; may be null
      entries - each a map with resource and optionally search
      Returns:
      the Bundle, as a map

      Groovy example:
      fhirUtil.searchsetEntries(config.fhirBaseUrl, null, [[resource: patient, search: [mode: 'match', score: 0.9]]])

      Returns:
      ['resourceType': 'Bundle', 'type': 'searchset', 'total': 1, 'entry': [['fullUrl': '.../Patient/123', 'resource': [...], 'search': ['mode': 'match', 'score': 0.9]]]]
    • operationOutcome

      public static Map<String,Object> operationOutcome(String severity, String code, String diagnostics)
      Builds a FHIR OperationOutcome with one issue.
      Parameters:
      severity - fatal, error, warning or information
      code - FHIR issue type code, e.g. "invalid", "not-found", "business-rule"
      diagnostics - message for the client
      Returns:
      the OperationOutcome, as a map

      Groovy example:
      fhirUtil.operationOutcome('warning', 'business-rule', 'Dose recorded with an expired lot')

      Returns:
      ['resourceType': 'OperationOutcome', 'issue': [['severity': 'warning', 'code': 'business-rule', 'diagnostics': '...']]]
    • error

      public static void error(int status, String code, String diagnostics)
      Ends the request with an error. The FHIR API returns it as an OperationOutcome with the given HTTP status.
      Parameters:
      status - HTTP status, e.g. 400, 404, 422
      code - FHIR issue type code, e.g. "invalid", "not-found", "processing"
      diagnostics - message for the client

      Groovy example:
      if (!config.fhirParams.birthdate) fhirUtil.error(400, 'required', 'birthdate is required')

      Returns:
      nothing; throws, and the client receives HTTP 400 with an OperationOutcome