allow interceptors to be registered via properties

This commit is contained in:
Craig McClendon
2022-12-20 20:07:18 -06:00
parent 19c68e7cfc
commit ba58a71624
9 changed files with 234 additions and 7 deletions

View File

@@ -0,0 +1,18 @@
package some.custom.pkg1;
import org.springframework.stereotype.Component;
@Component
public class CustomBean {
private String initFlag;
public CustomBean() {
initFlag = "I am alive";
}
public String getInitFlag() {
return initFlag;
}
}

View File

@@ -0,0 +1,31 @@
package some.custom.pkg1;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.StringType;
import org.springframework.stereotype.Component;
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.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
@Interceptor
@Component
public class CustomInterceptorBean {
@Hook(Pointcut.SERVER_INCOMING_REQUEST_PRE_HANDLED)
void preHandleResource(ServletRequestDetails servletRequestDetails, RestOperationTypeEnum opType) {
IBaseResource resource = servletRequestDetails.getResource();
// add an extension before saving the resource to mark it
if (opType == RestOperationTypeEnum.CREATE && resource instanceof Patient) {
Patient pat = (Patient) resource;
Extension ext = pat.addExtension();
ext.setUrl("http://some.custom.pkg1/CustomInterceptorBean");
ext.setValue(new StringType("CustomInterceptorBean wuz here"));
}
}
}

View File

@@ -0,0 +1,26 @@
package some.custom.pkg1;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.StringType;
import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
public class CustomInterceptorPojo {
@Hook(Pointcut.SERVER_INCOMING_REQUEST_PRE_HANDLED)
void preHandleResource(ServletRequestDetails servletRequestDetails, RestOperationTypeEnum opType) {
IBaseResource resource = servletRequestDetails.getResource();
// add an extension before saving the resource to mark it
if (opType == RestOperationTypeEnum.CREATE && resource instanceof Patient) {
Patient pat = (Patient) resource;
Extension ext = pat.addExtension();
ext.setUrl("http://some.custom.pkg1/CustomInterceptorPojo");
ext.setValue(new StringType("CustomInterceptorPojo wuz here"));
}
}
}