Class FHIRRestHelper

  • All Implemented Interfaces:
    FHIRResourceHelpers

    public class FHIRRestHelper
    extends Object
    implements FHIRResourceHelpers
    Helper methods for performing the "heavy lifting" with respect to implementing FHIR interactions.
    • Constructor Detail

    • Method Detail

      • doCreate

        public FHIRRestOperationResponse doCreate​(String type,
                                                  Resource resource,
                                                  String ifNoneExist,
                                                  boolean doValidation)
                                           throws Exception
        Description copied from interface: FHIRResourceHelpers
        Performs the heavy lifting associated with a 'create' interaction.
        Specified by:
        doCreate in interface FHIRResourceHelpers
        Parameters:
        type - the resource type specified as part of the request URL
        resource - the Resource to be stored.
        ifNoneExist - whether to create the resource if none exists
        doValidation - if true, validate the resource; if false, assume the resource has already been validated
        Returns:
        a FHIRRestOperationResponse object containing the results of the operation
        Throws:
        Exception
      • doPatch

        public FHIRRestOperationResponse doPatch​(String type,
                                                 String id,
                                                 FHIRPatch patch,
                                                 String ifMatchValue,
                                                 String searchQueryString,
                                                 boolean skippableUpdate)
                                          throws Exception
        Description copied from interface: FHIRResourceHelpers
        Performs a patch operation (a new version of the Resource will be stored).
        Specified by:
        doPatch in interface FHIRResourceHelpers
        Parameters:
        type - the type of the resource to be updated
        id - the id of the Resource being updated
        patch - the patch to apply
        ifMatchValue - an optional "If-Match" header value to request a version-aware update
        searchQueryString - an optional search query string to request a conditional update
        skippableUpdate - if true, and the result of the patch matches the existing resource on the server, then skip the update; if false, then always attempt the update
        Returns:
        a FHIRRestOperationResponse that contains the results of the operation
        Throws:
        Exception
      • doUpdate

        public FHIRRestOperationResponse doUpdate​(String type,
                                                  String id,
                                                  Resource newResource,
                                                  String ifMatchValue,
                                                  String searchQueryString,
                                                  boolean skippableUpdate,
                                                  boolean doValidation,
                                                  Integer ifNoneMatch)
                                           throws Exception
        Description copied from interface: FHIRResourceHelpers
        Performs an update operation (a new version of the Resource will be stored).
        Specified by:
        doUpdate in interface FHIRResourceHelpers
        Parameters:
        type - the type of the resource to be updated
        id - the id of the Resource being updated
        newResource - the new resource to be stored
        ifMatchValue - an optional "If-Match" header value to request a version-aware update
        searchQueryString - an optional search query string to request a conditional update
        skippableUpdate - if true, and the resource content in the update matches the existing resource on the server, then skip the update; if false, then always attempt the update
        doValidation - if true, validate the resource; if false, assume the resource has already been validated
        ifNoneMatch - conditional create-on-update
        Returns:
        a FHIRRestOperationResponse that contains the results of the operation
        Throws:
        Exception
      • doDelete

        public FHIRRestOperationResponse doDelete​(String type,
                                                  String id,
                                                  String searchQueryString)
                                           throws Exception
        Performs a 'delete' operation on the specified resource.
        Specified by:
        doDelete in interface FHIRResourceHelpers
        Parameters:
        type - the resource type associated with the Resource to be deleted
        id - the id of the Resource to be deleted
        requestProperties - additional request properties which supplement the HTTP headers associated with this request
        Returns:
        a FHIRRestOperationResponse that contains the results of the operation
        Throws:
        Exception
      • doRead

        public SingleResourceResult<? extends Resource> doRead​(String type,
                                                               String id,
                                                               boolean throwExcOnNull,
                                                               boolean includeDeleted,
                                                               Resource contextResource)
                                                        throws Exception
        Description copied from interface: FHIRResourceHelpers
        Performs a 'read' operation to retrieve a Resource.
        Specified by:
        doRead in interface FHIRResourceHelpers
        Parameters:
        type - the resource type associated with the Resource to be retrieved
        id - the id of the Resource to be retrieved
        throwExcOnNull - whether to throw an exception on null
        includeDeleted - allow the read, even if the resource has been deleted
        contextResource - the resource
        Returns:
        a SingleResourceResult wrapping the resource and including its deletion status
        Throws:
        Exception
      • doRead

        public SingleResourceResult<? extends Resource> doRead​(String type,
                                                               String id,
                                                               boolean throwExcOnNull,
                                                               boolean includeDeleted,
                                                               Resource contextResource,
                                                               javax.ws.rs.core.MultivaluedMap<String,​String> queryParameters)
                                                        throws Exception
        Description copied from interface: FHIRResourceHelpers
        Performs a 'read' operation to retrieve a Resource with select query parameters.
        Specified by:
        doRead in interface FHIRResourceHelpers
        Parameters:
        type - the resource type associated with the Resource to be retrieved
        id - the id of the Resource to be retrieved
        throwExcOnNull - whether to throw an exception on null
        includeDeleted - allow the read, even if the resource has been deleted
        contextResource - the resource
        queryParameters - for supporting _elements and _summary for resource read
        Returns:
        a SingleResourceResult wrapping the resource and including its deletion status
        Throws:
        Exception
      • doVRead

        public Resource doVRead​(String type,
                                String id,
                                String versionId,
                                javax.ws.rs.core.MultivaluedMap<String,​String> queryParameters)
                         throws Exception
        Description copied from interface: FHIRResourceHelpers
        Performs a 'vread' operation by retrieving the specified version of a Resource.
        Specified by:
        doVRead in interface FHIRResourceHelpers
        Parameters:
        type - the resource type associated with the Resource to be retrieved
        id - the id of the Resource to be retrieved
        versionId - the version id of the Resource to be retrieved
        queryParameters - for supporting _elements and _summary for resource vread
        Returns:
        the Resource
        Throws:
        Exception
      • doHistory

        public Bundle doHistory​(String type,
                                String id,
                                javax.ws.rs.core.MultivaluedMap<String,​String> queryParameters,
                                String requestUri)
                         throws Exception
        Performs the work of retrieving versions of a Resource.
        Specified by:
        doHistory in interface FHIRResourceHelpers
        Parameters:
        type - the resource type associated with the Resource to be retrieved
        id - the id of the Resource to be retrieved
        queryParameters - a Map containing the query parameters from the request URL
        requestUri - the URI from the request
        requestProperties - additional request properties which supplement the HTTP headers associated with this request
        Returns:
        a Bundle containing the history of the specified Resource
        Throws:
        Exception
      • doSearch

        public Bundle doSearch​(String type,
                               String compartment,
                               String compartmentId,
                               javax.ws.rs.core.MultivaluedMap<String,​String> queryParameters,
                               String requestUri,
                               Resource contextResource)
                        throws Exception
        Description copied from interface: FHIRResourceHelpers
        Performs heavy lifting associated with a 'search' operation.
        Specified by:
        doSearch in interface FHIRResourceHelpers
        Parameters:
        type - the resource type associated with the search
        compartment - the compartment type to search in, or null if not a compartment search
        compartmentId - the specific compartment to search in, or null if not a compartment search
        queryParameters - a Map containing the query parameters from the request URL
        requestUri - the request URI
        contextResource - the resource context
        Returns:
        a Bundle containing the search result set
        Throws:
        Exception
      • doSearch

        public Bundle doSearch​(String type,
                               String compartment,
                               String compartmentId,
                               javax.ws.rs.core.MultivaluedMap<String,​String> queryParameters,
                               String requestUri,
                               Resource contextResource,
                               boolean checkInteractionAllowed)
                        throws Exception
        Description copied from interface: FHIRResourceHelpers
        Performs heavy lifting associated with a 'search' operation.
        Specified by:
        doSearch in interface FHIRResourceHelpers
        Parameters:
        type - the resource type associated with the search
        compartment - the compartment type to search in, or null if not a compartment search
        compartmentId - the specific compartment to search in, or null if not a compartment search
        queryParameters - a Map containing the query parameters from the request URL
        requestUri - the request URI
        contextResource - the resource context
        checkInteractionAllowed - if true, check that the search interaction is permitted
        Returns:
        a Bundle containing the search result set
        Throws:
        Exception
      • doInvoke

        public Resource doInvoke​(FHIROperationContext operationContext,
                                 String resourceTypeName,
                                 String logicalId,
                                 String versionId,
                                 Resource resource,
                                 javax.ws.rs.core.MultivaluedMap<String,​String> queryParameters)
                          throws Exception
        Helper method which invokes a custom operation.
        Specified by:
        doInvoke in interface FHIRResourceHelpers
        Parameters:
        operationContext - the FHIROperationContext associated with the request
        resourceTypeName - the resource type associated with the request
        logicalId - the resource logical id associated with the request
        versionId - the resource version id associated with the request
        resource - the input resource associated with the custom operation to be invoked
        queryParameters - query parameters may be passed instead of a Parameters resource for certain custom operations invoked via GET
        Returns:
        a Resource that represents the response to the custom operation
        Throws:
        Exception
      • doBundle

        public Bundle doBundle​(Bundle inputBundle,
                               boolean skippableUpdates)
                        throws Exception
        Description copied from interface: FHIRResourceHelpers
        Processes a bundled request (batch or transaction type).
        Specified by:
        doBundle in interface FHIRResourceHelpers
        Parameters:
        inputBundle - the request Bundle
        skippableUpdates - if true, and the bundle contains an update for which the resource content in the update matches the existing resource on the server, then skip the update; if false, then always attempt the updates specified in the bundle
        Returns:
        the response Bundle
        Throws:
        Exception
      • updateOperationContext

        public void updateOperationContext​(FHIROperationContext operationContext,
                                           String method)
        common update to the operationContext
        Parameters:
        operationContext -
        method -
      • createSearchBundle

        Bundle createSearchBundle​(List<Resource> resources,
                                  FHIRSearchContext searchContext,
                                  String type)
                           throws Exception
        Creates a bundle that will hold results for a search operation.
        Parameters:
        resources - the list of resources to include in the bundle
        searchContext - the FHIRSearchContext object associated with the search
        type - the name of the resource type being searched
        Returns:
        the bundle
        Throws:
        Exception
      • doReindex

        public int doReindex​(FHIROperationContext operationContext,
                             OperationOutcome.Builder operationOutcomeResult,
                             Instant tstamp,
                             List<Long> indexIds,
                             String resourceLogicalId)
                      throws Exception
        Description copied from interface: FHIRResourceHelpers
        Invoke the FHIR persistence reindex operation for either a specified list of indexIds, or a randomly chosen resource, last reindexed before the given timestamp.
        Specified by:
        doReindex in interface FHIRResourceHelpers
        Parameters:
        operationContext - the operation context
        operationOutcomeResult - accumulate issues in this OperationOutcome.Builder
        tstamp - only reindex resources with a reindex_tstamp less than this
        indexIds - list of index IDs of resources to reindex, or null
        resourceLogicalId - resourceType (e.g. "Patient"), or resourceType/logicalId a specific resource (e.g. "Patient/abc123"), to reindex, or null; this parameter is ignored if the indexIds parameter value is non-null
        Returns:
        count of the number of resources reindexed by this call
        Throws:
        Exception
      • doReindexList

        public int doReindexList​(OperationOutcome.Builder operationOutcomeResult,
                                 Instant tstamp,
                                 List<Long> indexIds)
                          throws Exception
        encapsulates the logic to process a list with graduated backoff through the full list of indexIds
        Parameters:
        operationOutcomeResult -
        tstamp -
        indexIds -
        Returns:
        Throws:
        Exception
      • doReindexSingle

        public int doReindexSingle​(OperationOutcome.Builder operationOutcomeResult,
                                   Instant tstamp,
                                   String resourceLogicalId)
                            throws Exception
        do a single reindex on a specific resourceLogicalId
        Parameters:
        operationOutcomeResult -
        tstamp -
        resourceLogicalId -
        Returns:
        Throws:
        Exception
      • doHistory

        public Bundle doHistory​(javax.ws.rs.core.MultivaluedMap<String,​String> queryParameters,
                                String requestUri)
                         throws Exception
        Description copied from interface: FHIRResourceHelpers
        Implement the system level history operation to obtain a list of changes to resources
        Specified by:
        doHistory in interface FHIRResourceHelpers
        Parameters:
        queryParameters - a Map containing the query parameters from the request URL
        requestUri - the request URI
        Returns:
        a Bundle containing the history of the specified Resource
        Throws:
        Exception
      • doRetrieveIndex

        public List<Long> doRetrieveIndex​(FHIROperationContext operationContext,
                                          String resourceTypeName,
                                          int count,
                                          Instant notModifiedAfter,
                                          Long afterIndexId)
                                   throws Exception
        Description copied from interface: FHIRResourceHelpers
        Invoke the FHIR persistence retrieve index operation to retrieve a list of indexIds available for reindexing.
        Specified by:
        doRetrieveIndex in interface FHIRResourceHelpers
        Parameters:
        operationContext - the operation context
        resourceTypeName - the resource type of index IDs to return, or null
        count - the maximum nuber of index IDs to retrieve
        notModifiedAfter - only retrieve index IDs for resources not last updated after the specified timestamp
        afterIndexId - retrieve index IDs starting after this specified ID, or null to start with first ID
        Returns:
        list of index IDs available for reindexing
        Throws:
        Exception
      • generateResourceId

        public String generateResourceId()
        Description copied from interface: FHIRResourceHelpers
        Generate a new resource id. This is typically delegated to the persistence layer, which may want to create FHIR-compliant ids optimized for a certain type of storage.
        Specified by:
        generateResourceId in interface FHIRResourceHelpers
        Returns:
      • getCurrentInstant

        protected Instant getCurrentInstant()
        Get the current time which can be used for the lastUpdated field
        Returns:
        current time in UTC
      • storePayload

        public Future<PayloadKey> storePayload​(Resource resource,
                                               String logicalId,
                                               int newVersionNumber)
                                        throws Exception
        Description copied from interface: FHIRResourceHelpers
        If the underlying persistence layer supports offloading payload storage, initiate the request here.
        Specified by:
        storePayload in interface FHIRResourceHelpers
        Parameters:
        resource - the resource to store (with correct Meta fields)
        logicalId - the logical id of the resource
        newVersionNumber - the version number to use
        Returns:
        a Future response to the payload store operation, or null if it is not supported
        Throws:
        Exception