Package com.ibm.fhir.server.util
Class FHIRRestHelper
- java.lang.Object
-
- com.ibm.fhir.server.util.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.ibm.fhir.server.spi.operation.FHIRResourceHelpers
FHIRResourceHelpers.Interaction
-
-
Field Summary
Fields Modifier and Type Field Description static DateTimeFormatterPARSER_FORMATTER-
Fields inherited from interface com.ibm.fhir.server.spi.operation.FHIRResourceHelpers
DO_VALIDATION, IF_NOT_MATCH_NULL, SKIPPABLE_UPDATE
-
-
Constructor Summary
Constructors Constructor Description FHIRRestHelper(FHIRPersistence persistence)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Object>buildPersistenceEventProperties(String type, String id, String version, FHIRSearchContext searchContext)Builds a collection of properties that will be passed to the persistence interceptors.(package private) BundlecreateSearchResponseBundle(List<Resource> resources, FHIRSearchContext searchContext, String type)Creates a bundle that will hold results for a search operation.BundledoBundle(Bundle inputBundle, boolean skippableUpdates)Processes a bundled request (batch or transaction type).FHIRRestOperationResponsedoCreate(String type, Resource resource, String ifNoneExist, boolean doValidation)Performs the heavy lifting associated with a 'create' interaction.FHIRRestOperationResponsedoCreateMeta(FHIRPersistenceEvent event, List<OperationOutcome.Issue> warnings, String type, Resource resource, String ifNoneExist)1st phase of CREATE.FHIRRestOperationResponsedoCreatePersist(FHIRPersistenceEvent event, List<OperationOutcome.Issue> warnings, Resource resource)3rd phase of resource create.FHIRRestOperationResponsedoDelete(String type, String id, String searchQueryString)Performs a 'delete' operation on the specified resource.ResourceEraseRecorddoErase(FHIROperationContext operationContext, EraseDTO eraseDto)Invoke the FHIR Persistence erase operation for a specific instance of the erase.BundledoHistory(String type, String id, javax.ws.rs.core.MultivaluedMap<String,String> queryParameters, String requestUri)Performs the work of retrieving versions of a Resource.BundledoHistory(javax.ws.rs.core.MultivaluedMap<String,String> queryParameters, String requestUri)Implement the system level history operation to obtain a list of changes to resourcesResourcedoInvoke(FHIROperationContext operationContext, String resourceTypeName, String logicalId, String versionId, Resource resource, javax.ws.rs.core.MultivaluedMap<String,String> queryParameters)Helper method which invokes a custom operation.FHIRRestOperationResponsedoPatch(String type, String id, FHIRPatch patch, String ifMatchValue, String searchQueryString, boolean skippableUpdate)Performs a patch operation (a new version of the Resource will be stored).FHIRRestOperationResponsedoPatchOrUpdatePersist(FHIRPersistenceEvent event, String type, String id, boolean isPatch, Resource newResource, Resource prevResource, List<OperationOutcome.Issue> warnings, boolean isDeleted, Integer ifNoneMatch)Persist the newResource value for patch or update interactionsSingleResourceResult<? extends Resource>doRead(String type, String id, boolean throwExcOnNull, boolean includeDeleted, Resource contextResource)Performs a 'read' operation to retrieve a Resource.SingleResourceResult<? extends Resource>doRead(String type, String id, boolean throwExcOnNull, boolean includeDeleted, Resource contextResource, javax.ws.rs.core.MultivaluedMap<String,String> queryParameters)Performs a 'read' operation to retrieve a Resource with select query parameters.intdoReindex(FHIROperationContext operationContext, OperationOutcome.Builder operationOutcomeResult, Instant tstamp, List<Long> indexIds, String resourceLogicalId)Invoke the FHIR persistence reindex operation for either a specified list of indexIds, or a randomly chosen resource, last reindexed before the given timestamp.intdoReindexList(OperationOutcome.Builder operationOutcomeResult, Instant tstamp, List<Long> indexIds)encapsulates the logic to process a list with graduated backoff through the full list of indexIdsintdoReindexSingle(OperationOutcome.Builder operationOutcomeResult, Instant tstamp, String resourceLogicalId)do a single reindex on a specific resourceLogicalIdList<Long>doRetrieveIndex(FHIROperationContext operationContext, String resourceTypeName, int count, Instant notModifiedAfter, Long afterIndexId)Invoke the FHIR persistence retrieve index operation to retrieve a list of indexIds available for reindexing.BundledoSearch(String type, String compartment, String compartmentId, javax.ws.rs.core.MultivaluedMap<String,String> queryParameters, String requestUri, Resource contextResource)Performs heavy lifting associated with a 'search' operation.BundledoSearch(String type, String compartment, String compartmentId, javax.ws.rs.core.MultivaluedMap<String,String> queryParameters, String requestUri, Resource contextResource, boolean checkInteractionAllowed)Performs heavy lifting associated with a 'search' operation.FHIRRestOperationResponsedoUpdate(String type, String id, Resource newResource, String ifMatchValue, String searchQueryString, boolean skippableUpdate, boolean doValidation, Integer ifNoneMatch)Performs an update operation (a new version of the Resource will be stored).FHIRRestOperationResponsedoUpdateMeta(FHIRPersistenceEvent event, String type, String id, FHIRPatch patch, Resource newResource, String ifMatchValue, String searchQueryString, boolean skippableUpdate, boolean doValidation, List<OperationOutcome.Issue> warnings)1st phase of update interaction.ResourcedoVRead(String type, String id, String versionId, javax.ws.rs.core.MultivaluedMap<String,String> queryParameters)Performs a 'vread' operation by retrieving the specified version of a Resource.StringgenerateResourceId()Generate a new resource id.protected InstantgetCurrentInstant()Get the current time which can be used for the lastUpdated fieldFHIRPersistenceTransactiongetTransaction()Future<PayloadKey>storePayload(Resource resource, String logicalId, int newVersionNumber)If the underlying persistence layer supports offloading payload storage, initiate the request here.voidupdateOperationContext(FHIROperationContext operationContext, String method)common update to the operationContextvoidvalidateInteraction(FHIRResourceHelpers.Interaction interaction, String resourceType)Validate an interaction for a specified resource type.List<OperationOutcome.Issue>validateResource(Resource resource)Validate a resource.-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.ibm.fhir.server.spi.operation.FHIRResourceHelpers
doCreate, doUpdate, doVRead
-
-
-
-
Field Detail
-
PARSER_FORMATTER
public static final DateTimeFormatter PARSER_FORMATTER
-
-
Constructor Detail
-
FHIRRestHelper
public FHIRRestHelper(FHIRPersistence persistence)
-
-
Method Detail
-
doCreate
public FHIRRestOperationResponse doCreate(String type, Resource resource, String ifNoneExist, boolean doValidation) throws Exception
Description copied from interface:FHIRResourceHelpersPerforms the heavy lifting associated with a 'create' interaction.- Specified by:
doCreatein interfaceFHIRResourceHelpers- Parameters:
type- the resource type specified as part of the request URLresource- the Resource to be stored.ifNoneExist- whether to create the resource if none existsdoValidation- 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
-
doCreateMeta
public FHIRRestOperationResponse doCreateMeta(FHIRPersistenceEvent event, List<OperationOutcome.Issue> warnings, String type, Resource resource, String ifNoneExist) throws Exception
Description copied from interface:FHIRResourceHelpers1st phase of CREATE. Perform the search for conditional create (ifNoneExist) interactions. Any validation (if required) should be performed before this call.- Specified by:
doCreateMetain interfaceFHIRResourceHelpers- Returns:
- Throws:
Exception
-
doCreatePersist
public FHIRRestOperationResponse doCreatePersist(FHIRPersistenceEvent event, List<OperationOutcome.Issue> warnings, Resource resource) throws Exception
Description copied from interface:FHIRResourceHelpers3rd phase of resource create. Persist the resource using the configured persistence layer. Does not modify the resource.- Specified by:
doCreatePersistin interfaceFHIRResourceHelpers- Returns:
- Throws:
Exception
-
doPatch
public FHIRRestOperationResponse doPatch(String type, String id, FHIRPatch patch, String ifMatchValue, String searchQueryString, boolean skippableUpdate) throws Exception
Description copied from interface:FHIRResourceHelpersPerforms a patch operation (a new version of the Resource will be stored).- Specified by:
doPatchin interfaceFHIRResourceHelpers- Parameters:
type- the type of the resource to be updatedid- the id of the Resource being updatedpatch- the patch to applyifMatchValue- an optional "If-Match" header value to request a version-aware updatesearchQueryString- an optional search query string to request a conditional updateskippableUpdate- 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:FHIRResourceHelpersPerforms an update operation (a new version of the Resource will be stored).- Specified by:
doUpdatein interfaceFHIRResourceHelpers- Parameters:
type- the type of the resource to be updatedid- the id of the Resource being updatednewResource- the new resource to be storedifMatchValue- an optional "If-Match" header value to request a version-aware updatesearchQueryString- an optional search query string to request a conditional updateskippableUpdate- 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 updatedoValidation- if true, validate the resource; if false, assume the resource has already been validatedifNoneMatch- conditional create-on-update- Returns:
- a FHIRRestOperationResponse that contains the results of the operation
- Throws:
Exception
-
doUpdateMeta
public FHIRRestOperationResponse doUpdateMeta(FHIRPersistenceEvent event, String type, String id, FHIRPatch patch, Resource newResource, String ifMatchValue, String searchQueryString, boolean skippableUpdate, boolean doValidation, List<OperationOutcome.Issue> warnings) throws Exception
Description copied from interface:FHIRResourceHelpers1st phase of update interaction.- Specified by:
doUpdateMetain interfaceFHIRResourceHelpers- Returns:
- Throws:
Exception
-
doPatchOrUpdatePersist
public FHIRRestOperationResponse doPatchOrUpdatePersist(FHIRPersistenceEvent event, String type, String id, boolean isPatch, Resource newResource, Resource prevResource, List<OperationOutcome.Issue> warnings, boolean isDeleted, Integer ifNoneMatch) throws Exception
Description copied from interface:FHIRResourceHelpersPersist the newResource value for patch or update interactions- Specified by:
doPatchOrUpdatePersistin interfaceFHIRResourceHelpers- Returns:
- Throws:
Exception
-
doDelete
public FHIRRestOperationResponse doDelete(String type, String id, String searchQueryString) throws Exception
Description copied from interface:FHIRResourceHelpersPerforms a 'delete' operation on the specified resource.- Specified by:
doDeletein interfaceFHIRResourceHelpers- Parameters:
type- the resource type associated with the Resource to be deletedid- the id of the Resource to be deletedsearchQueryString- a search query associated with a conditional delete request (mutually exclusive with id)- 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:FHIRResourceHelpersPerforms a 'read' operation to retrieve a Resource.- Specified by:
doReadin interfaceFHIRResourceHelpers- Parameters:
type- the resource type associated with the Resource to be retrievedid- the id of the Resource to be retrievedthrowExcOnNull- whether to throw an exception on nullincludeDeleted- allow the read, even if the resource has been deletedcontextResource- 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:FHIRResourceHelpersPerforms a 'read' operation to retrieve a Resource with select query parameters.- Specified by:
doReadin interfaceFHIRResourceHelpers- Parameters:
type- the resource type associated with the Resource to be retrievedid- the id of the Resource to be retrievedthrowExcOnNull- whether to throw an exception on nullincludeDeleted- allow the read, even if the resource has been deletedcontextResource- the resourcequeryParameters- 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:FHIRResourceHelpersPerforms a 'vread' operation by retrieving the specified version of a Resource.- Specified by:
doVReadin interfaceFHIRResourceHelpers- Parameters:
type- the resource type associated with the Resource to be retrievedid- the id of the Resource to be retrievedversionId- the version id of the Resource to be retrievedqueryParameters- 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:
doHistoryin interfaceFHIRResourceHelpers- Parameters:
type- the resource type associated with the Resource to be retrievedid- the id of the Resource to be retrievedqueryParameters- a Map containing the query parameters from the request URLrequestUri- the URI from the requestrequestProperties- 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:FHIRResourceHelpersPerforms heavy lifting associated with a 'search' operation.- Specified by:
doSearchin interfaceFHIRResourceHelpers- Parameters:
type- the resource type associated with the searchcompartment- the compartment type to search in, or null if not a compartment searchcompartmentId- the specific compartment to search in, or null if not a compartment searchqueryParameters- a Map containing the query parameters from the request URLrequestUri- the request URIcontextResource- 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:FHIRResourceHelpersPerforms heavy lifting associated with a 'search' operation.- Specified by:
doSearchin interfaceFHIRResourceHelpers- Parameters:
type- the resource type associated with the searchcompartment- the compartment type to search in, or null if not a compartment searchcompartmentId- the specific compartment to search in, or null if not a compartment searchqueryParameters- a Map containing the query parameters from the request URLrequestUri- the request URIcontextResource- the resource contextcheckInteractionAllowed- 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:
doInvokein interfaceFHIRResourceHelpers- Parameters:
operationContext- the FHIROperationContext associated with the requestresourceTypeName- the resource type associated with the requestlogicalId- the resource logical id associated with the requestversionId- the resource version id associated with the requestresource- the input resource associated with the custom operation to be invokedqueryParameters- 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:FHIRResourceHelpersProcesses a bundled request (batch or transaction type).- Specified by:
doBundlein interfaceFHIRResourceHelpers- Parameters:
inputBundle- the request BundleskippableUpdates- 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
-
getTransaction
public FHIRPersistenceTransaction getTransaction() throws Exception
- Specified by:
getTransactionin interfaceFHIRResourceHelpers- Throws:
Exception
-
updateOperationContext
public void updateOperationContext(FHIROperationContext operationContext, String method)
common update to the operationContext- Parameters:
operationContext-method-
-
createSearchResponseBundle
Bundle createSearchResponseBundle(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 bundlesearchContext- the FHIRSearchContext object associated with the searchtype- the name of the resource type being searched- Returns:
- the bundle
- Throws:
Exception
-
buildPersistenceEventProperties
public Map<String,Object> buildPersistenceEventProperties(String type, String id, String version, FHIRSearchContext searchContext) throws FHIRPersistenceException
Description copied from interface:FHIRResourceHelpersBuilds a collection of properties that will be passed to the persistence interceptors.- Specified by:
buildPersistenceEventPropertiesin interfaceFHIRResourceHelpers- Parameters:
type- the resource typeid- the resource logical IDversion- the resource versionsearchContext- the request search context- Returns:
- a map of persistence event properties
- Throws:
FHIRPersistenceException
-
doReindex
public int doReindex(FHIROperationContext operationContext, OperationOutcome.Builder operationOutcomeResult, Instant tstamp, List<Long> indexIds, String resourceLogicalId) throws Exception
Description copied from interface:FHIRResourceHelpersInvoke 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:
doReindexin interfaceFHIRResourceHelpers- Parameters:
operationContext- the operation contextoperationOutcomeResult- accumulate issues in thisOperationOutcome.Buildertstamp- only reindex resources with a reindex_tstamp less than thisindexIds- list of index IDs of resources to reindex, or nullresourceLogicalId- 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
-
validateResource
public List<OperationOutcome.Issue> validateResource(Resource resource) throws FHIROperationException
Description copied from interface:FHIRResourceHelpersValidate a resource. First validate profile assertions for the resource if configured to do so, then validate the resource itself.- Specified by:
validateResourcein interfaceFHIRResourceHelpers- Parameters:
resource- the resource to be validated- Returns:
- A list of validation errors and warnings
- Throws:
FHIROperationException
-
validateInteraction
public void validateInteraction(FHIRResourceHelpers.Interaction interaction, String resourceType) throws FHIROperationException
Description copied from interface:FHIRResourceHelpersValidate an interaction for a specified resource type.- Specified by:
validateInteractionin interfaceFHIRResourceHelpers- Parameters:
interaction- the interaction to be performedresourceType- the resource type against which the interaction is to be performed- Throws:
FHIROperationException
-
doHistory
public Bundle doHistory(javax.ws.rs.core.MultivaluedMap<String,String> queryParameters, String requestUri) throws Exception
Description copied from interface:FHIRResourceHelpersImplement the system level history operation to obtain a list of changes to resources- Specified by:
doHistoryin interfaceFHIRResourceHelpers- Parameters:
queryParameters- a Map containing the query parameters from the request URLrequestUri- the request URI- Returns:
- a Bundle containing the history of the specified Resource
- Throws:
Exception
-
doErase
public ResourceEraseRecord doErase(FHIROperationContext operationContext, EraseDTO eraseDto) throws FHIROperationException
Description copied from interface:FHIRResourceHelpersInvoke the FHIR Persistence erase operation for a specific instance of the erase.- Specified by:
doErasein interfaceFHIRResourceHelpers- Returns:
- Throws:
FHIROperationException
-
doRetrieveIndex
public List<Long> doRetrieveIndex(FHIROperationContext operationContext, String resourceTypeName, int count, Instant notModifiedAfter, Long afterIndexId) throws Exception
Description copied from interface:FHIRResourceHelpersInvoke the FHIR persistence retrieve index operation to retrieve a list of indexIds available for reindexing.- Specified by:
doRetrieveIndexin interfaceFHIRResourceHelpers- Parameters:
operationContext- the operation contextresourceTypeName- the resource type of index IDs to return, or nullcount- the maximum nuber of index IDs to retrievenotModifiedAfter- only retrieve index IDs for resources not last updated after the specified timestampafterIndexId- 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:FHIRResourceHelpersGenerate 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:
generateResourceIdin interfaceFHIRResourceHelpers- 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:FHIRResourceHelpersIf the underlying persistence layer supports offloading payload storage, initiate the request here.- Specified by:
storePayloadin interfaceFHIRResourceHelpers- Parameters:
resource- the resource to store (with correct Meta fields)logicalId- the logical id of the resourcenewVersionNumber- the version number to use- Returns:
- a Future response to the payload store operation, or null if it is not supported
- Throws:
Exception
-
-