Class FhirUtil
java.lang.Object
com.ssgllc.fish.service.util.published.FhirUtil
Builds FHIR R4 responses in the scripts behind the FHIR API (
/api/fhir/r4).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidEnds the request with an error.operationOutcome(String severity, String code, String diagnostics) Builds a FHIR OperationOutcome with one issue.Wraps resources in a FHIR searchset Bundle.Wraps resources in a FHIR searchset Bundle with search metadata per entry, e.g. a$matchscore or anincludemode.
-
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 afullUrlof[baseUrl]/[resourceType]/[id]when the resource has an id.- Parameters:
baseUrl- the FHIR base URL, available to the script asconfig.fhirBaseUrlselfUrl- the URL of this search, for the Bundle's self link; may be nullresources- 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$matchscore or anincludemode. An entry withoutsearchgetsmode: match.- Parameters:
baseUrl- the FHIR base URL, available to the script asconfig.fhirBaseUrlselfUrl- the URL of this search, for the Bundle's self link; may be nullentries- each a map withresourceand optionallysearch- 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
Builds a FHIR OperationOutcome with one issue.- Parameters:
severity- fatal, error, warning or informationcode- 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
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, 422code- 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
-