Hi all.
I have just started to work with Hapi FHIR.
We are trying to build a POC with Hapi FHIR and Spring Boot. We have read that the Fhir context is designed to be created once and reused.
In our FhirRestfulServer class we are setting the FhirContext.forR4(), but we want to reuse this context in a service class to call Fhir Client. How can we reuse this context set in a @Service class?
@WebServlet(urlPatterns = { "/fhir/*" }, displayName = "FHIR Server")
public class FhirRestfulServer extends RestfulServer
{
private final ApplicationContext applicationContext;
FhirRestfulServer(ApplicationContext context)
{
this.applicationContext = context;
}
@Override
protected void initialize() throws ServletException
{
super.initialize();
//create a context for the appropriate version
setFhirContext(FhirContext.forR4());
setDefaultPrettyPrint(true);
//Register Resource Providers
setResourceProviders(Arrays.asList(
applicationContext.getBean(CommunicationProvider.class),
applicationContext.getBean(DeviceProvider.class),
applicationContext.getBean(DeviceMetricProvider.class),
applicationContext.getBean(SpecimenProvider.class)));
// Now register the interceptor
OpenApiInterceptor openApiInterceptor = new OpenApiInterceptor();
registerInterceptor(openApiInterceptor);
}
}
Thanks in advance