Smile CDR v2024.08.PRE
On this page:

12.4.1HL7v2 Endpoint Examples

 

This page contains example interceptors that can be registered against a HL7v2 Endpoint module, including:

12.4.2Example: Starter Server interceptor for all HL7v2 pointcuts

 

The following example shows an interceptor that can be used as a starter Server interceptor, implementing a hook method for each available pointcut for a HL7v2 endpoint.

/*-
 * #%L
 * Smile CDR - CDR
 * %%
 * Copyright (C) 2016 - 2024 Smile CDR, Inc.
 * %%
 * All rights reserved.
 * #L%
 */

package com.smilecdr.demo.fhirstorage;

import ca.cdr.api.fhir.interceptor.CdrHook;
import ca.cdr.api.fhir.interceptor.CdrPointcut;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.Interceptor;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.interceptor.model.ReadPartitionIdRequestDetails;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.interceptor.model.TransactionWriteOperationsDetails;
import ca.uhn.fhir.jpa.api.model.DeleteConflictList;
import ca.uhn.fhir.jpa.api.model.ResourceVersionConflictResolutionStrategy;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.InterceptorInvocationTimingEnum;
import ca.uhn.fhir.rest.api.server.IPreResourceAccessDetails;
import ca.uhn.fhir.rest.api.server.IPreResourceShowDetails;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.bulk.BulkExportJobParameters;
import ca.uhn.fhir.rest.api.server.storage.DeferredInterceptorBroadcasts;
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.rest.server.util.ICachedSearchDetails;
import ca.uhn.fhir.util.StopWatch;
import ca.uhn.hl7v2.model.Message;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

@SuppressWarnings({"unused", "EmptyTryBlock"})
@Interceptor
public class Hl7v2InterceptorTemplate {

	private static final Logger ourLog = LoggerFactory.getLogger(Hl7v2InterceptorTemplate.class);

	@CdrHook(CdrPointcut.HL7V2IN_PRE_HL7V2_TO_FHIR_MAPPING_PROCESSING)
	public Boolean serverPreHl7v2ToFhirMapping(Message theMessage){

		ourLog.info("Interceptor HL7V2IN_PRE_HL7V2_TO_FHIR_MAPPING_PROCESSING - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		}
		finally {
			ourLog.info("Interceptor HL7V2IN_PRE_HL7V2_TO_FHIR_MAPPING_PROCESSING - ended, execution took {}", stopWatch);
		}

		// return true if this message should keep on being processed.
		// return false to stop all further processing.
		return true;
	}


	@Hook(Pointcut.STORAGE_PRESEARCH_REGISTERED)
	public void storagePreSearchRegistered(
		ICachedSearchDetails theCachedSearchDetails,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		SearchParameterMap theSearchParameterMap) {

		ourLog.info("Interceptor STORAGE_PRESEARCH_REGISTERED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRESEARCH_REGISTERED - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRECHECK_FOR_CACHED_SEARCH)
	public boolean storagePreCheckForCachedSearch(
		SearchParameterMap theSearchParameterMap,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails) {

		ourLog.info("Interceptor STORAGE_PRECHECK_FOR_CACHED_SEARCH - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRECHECK_FOR_CACHED_SEARCH - ended, execution took {}", stopWatch);
		}
		return true;
	}

	@Hook(Pointcut.STORAGE_PREACCESS_RESOURCES)
	public void storagePreAccessResources(
		IPreResourceAccessDetails thePreResourceAccessDetails,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails) {

		ourLog.info("Interceptor STORAGE_PREACCESS_RESOURCES - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PREACCESS_RESOURCES - ended, execution took {}", stopWatch);
		}
	}


	@Hook(Pointcut.STORAGE_PRESHOW_RESOURCES)
	public void storagePreShowResources(
		IPreResourceShowDetails thePreResourceShowDetails,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails) {

		ourLog.info("Interceptor STORAGE_PRESHOW_RESOURCES - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRESHOW_RESOURCES - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRESTORAGE_RESOURCE_CREATED)
	public void storagePreStorageResourceCreated(
		IBaseResource theBaseResource,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		TransactionDetails theTransactionDetails,
		RequestPartitionId theRequestPartitionId) {

		ourLog.info("Interceptor STORAGE_PRESTORAGE_RESOURCE_CREATED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRESTORAGE_RESOURCE_CREATED - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRESTORAGE_RESOURCE_UPDATED)
	public void storagePreStorageResourceUpdated(
		IBaseResource theBaseResource,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		TransactionDetails theTransactionDetails) {

		ourLog.info("Interceptor STORAGE_PRESTORAGE_RESOURCE_UPDATED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRESTORAGE_RESOURCE_UPDATED - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRESTORAGE_RESOURCE_DELETED)
	public void storagePreStorageResourceDeleted(
		IBaseResource theBaseResource,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		TransactionDetails theTransactionDetails) {

		ourLog.info("Interceptor STORAGE_PRESTORAGE_RESOURCE_DELETED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRESTORAGE_RESOURCE_DELETED - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRECOMMIT_RESOURCE_CREATED)
	public void storagePreCommitResourceCreated(
		IBaseResource theBaseResource,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		TransactionDetails theTransactionDetails,
		InterceptorInvocationTimingEnum theInterceptorInvocationTimingEnum) {

		ourLog.info("Interceptor STORAGE_PRECOMMIT_RESOURCE_CREATED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRECOMMIT_RESOURCE_CREATED - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRECOMMIT_RESOURCE_UPDATED)
	public void storagePreCommitResourceUpdated(
		IBaseResource thePreviousContentBaseResource,
		IBaseResource theProposedBaseResource,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		TransactionDetails theTransactionDetails,
		InterceptorInvocationTimingEnum theInterceptorInvocationTimingEnum) {

		ourLog.info("Interceptor STORAGE_PRECOMMIT_RESOURCE_UPDATED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRECOMMIT_RESOURCE_UPDATED - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRECOMMIT_RESOURCE_DELETED)
	public void storagePreCommitResourceDeleted(
		IBaseResource theBaseResource,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		TransactionDetails theTransactionDetails,
		InterceptorInvocationTimingEnum theInterceptorInvocationTimingEnum) {

		ourLog.info("Interceptor STORAGE_PRECOMMIT_RESOURCE_DELETED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRECOMMIT_RESOURCE_DELETED - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRESTORAGE_EXPUNGE_RESOURCE)
	public void storagePreStorageExpungeResource(
		AtomicInteger theAtomicInteger,
		IIdType theIdType,
		IBaseResource theBaseResource,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails) {

		ourLog.info("Interceptor STORAGE_PRESTORAGE_EXPUNGE_RESOURCE - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRESTORAGE_EXPUNGE_RESOURCE - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRESTORAGE_EXPUNGE_EVERYTHING)
	public void storagePartitionSelected(
		AtomicInteger theAtomicInteger,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails) {

		ourLog.info("Interceptor STORAGE_PRESTORAGE_EXPUNGE_EVERYTHING - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRESTORAGE_EXPUNGE_EVERYTHING - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRE_DELETE_EXPUNGE_PID_LIST)
	public void storagePreDeleteExpungePidList(
		String theResourceType,
		List<Long> theResourcePidList,
		AtomicLong theAtomicLong,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails) {

		ourLog.info("Interceptor STORAGE_PRE_DELETE_EXPUNGE_PID_LIST - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRE_DELETE_EXPUNGE_PID_LIST - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRE_DELETE_EXPUNGE)
	public void storagePreDeleteExpunge(
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		String theUrl) {

		ourLog.info("Interceptor STORAGE_PRE_DELETE_EXPUNGE - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRE_DELETE_EXPUNGE - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_CASCADE_DELETE)
	public void storageCascadeDelete(
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		DeleteConflictList theDeleteConflictList,
		IBaseResource theBaseResource) {

		ourLog.info("Interceptor STORAGE_CASCADE_DELETE - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_CASCADE_DELETE - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PARTITION_IDENTIFY_CREATE)
	public RequestPartitionId storagePartitionIdentifyCreate(
		IBaseResource theBaseResource,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails) {

		ourLog.info("Interceptor STORAGE_PARTITION_IDENTIFY_CREATE - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PARTITION_IDENTIFY_CREATE - ended, execution took {}", stopWatch);
		}
		return null;
	}

	@Hook(Pointcut.STORAGE_PARTITION_IDENTIFY_READ)
	public RequestPartitionId storagePartitionIdentifyRead(
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		ReadPartitionIdRequestDetails theReadPartitionIdRequestDetails) {

		ourLog.info("Interceptor STORAGE_PARTITION_IDENTIFY_READ - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PARTITION_IDENTIFY_READ - ended, execution took {}", stopWatch);
		}
		return null;
	}

	@Hook(Pointcut.STORAGE_PARTITION_SELECTED)
	public void storagePartitionSelected(
		RequestPartitionId theRequestPartitionId,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		RuntimeResourceDefinition theRuntimeResourceDefinition) {

		ourLog.info("Interceptor STORAGE_PARTITION_SELECTED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PARTITION_SELECTED - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_TRANSACTION_PROCESSED)
	public void storageTransactionProcessed(
		IBaseBundle theBaseBundle,
		DeferredInterceptorBroadcasts theDeferredInterceptorBroadcasts,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails,
		TransactionDetails theTransactionDetails) {

		ourLog.info("Interceptor STORAGE_TRANSACTION_PROCESSED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_TRANSACTION_PROCESSED - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_INITIATE_BULK_EXPORT)
	public void storageInitiateBulkExport(
		BulkExportJobParameters theBulkDataExportOptions,
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails) {

		ourLog.info("Interceptor STORAGE_INITIATE_BULK_EXPORT - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_INITIATE_BULK_EXPORT - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_PRESTORAGE_CLIENT_ASSIGNED_ID)
	public void storagePreStorageClientAssignedId(
		IBaseResource theBaseResource,
		RequestDetails theRequestDetails) {

		ourLog.info("Interceptor STORAGE_PRESTORAGE_CLIENT_ASSIGNED_ID - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_PRESTORAGE_CLIENT_ASSIGNED_ID - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_TRANSACTION_WRITE_OPERATIONS_PRE)
	public void storageTransactionWriteOperationsPre(
		TransactionWriteOperationsDetails theTransactionWriteOperationsDetails,
		TransactionDetails theTransactionDetails) {

		ourLog.info("Interceptor STORAGE_TRANSACTION_WRITE_OPERATIONS_PRE - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_TRANSACTION_WRITE_OPERATIONS_PRE - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_TRANSACTION_WRITE_OPERATIONS_POST)
	public void storageTransactionWriteOperationsPost(
		TransactionWriteOperationsDetails theTransactionWriteOperationsDetails,
		TransactionDetails theTransactionDetails) {

		ourLog.info("Interceptor STORAGE_TRANSACTION_WRITE_OPERATIONS_POST - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_TRANSACTION_WRITE_OPERATIONS_POST - ended, execution took {}", stopWatch);
		}
	}

	@Hook(Pointcut.STORAGE_VERSION_CONFLICT)
	public ResourceVersionConflictResolutionStrategy storageVersionConflict(
		RequestDetails theRequestDetails,
		ServletRequestDetails theServletRequestDetails) {

		ourLog.info("Interceptor STORAGE_VERSION_CONFLICT - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor STORAGE_VERSION_CONFLICT - ended, execution took {}", stopWatch);
		}
		return null;
	}

	@Hook(Pointcut.INTERCEPTOR_REGISTERED)
	public void interceptorRegistered() {

		ourLog.info("Interceptor INTERCEPTOR_REGISTERED - started");
		StopWatch stopWatch = new StopWatch();
		try {
			// your implementation goes here
		} finally {
			ourLog.info("Interceptor INTERCEPTOR_REGISTERED - ended, execution took {}", stopWatch);
		}
	}
}