Search in sources :

Example 1 with FHIRMedicationProvider

use of org.snomed.snowstorm.fhir.services.FHIRMedicationProvider in project snowstorm by IHTSDO.

the class HapiRestfulServlet method initialize.

/**
 * The initialize method is automatically called when the servlet is starting up, so it can be used to configure the
 * servlet to define resource providers, or set up configuration, interceptors, etc.
 */
@Override
protected void initialize() throws ServletException {
    final WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    setDefaultResponseEncoding(EncodingEnum.JSON);
    final FhirContext ctxt = FhirContext.forR4();
    final LenientErrorHandler delegateHandler = new LenientErrorHandler();
    ctxt.setParserErrorHandler(new StrictErrorHandler() {

        @Override
        public void unknownAttribute(IParseLocation theLocation, String theAttributeName) {
            delegateHandler.unknownAttribute(theLocation, theAttributeName);
        }

        @Override
        public void unknownElement(IParseLocation theLocation, String theElementName) {
            delegateHandler.unknownElement(theLocation, theElementName);
        }

        @Override
        public void unknownReference(IParseLocation theLocation, String theReference) {
            delegateHandler.unknownReference(theLocation, theReference);
        }
    });
    setFhirContext(ctxt);
    /*
		 * The servlet defines any number of resource providers, and configures itself to use them by calling
		 * setResourceProviders()
		 */
    List<IResourceProvider> resourceProviders = new ArrayList<>();
    FHIRCodeSystemProvider csp = applicationContext.getBean(FHIRCodeSystemProvider.class);
    FHIRValueSetProvider vsp = applicationContext.getBean(FHIRValueSetProvider.class);
    FHIRConceptMapProvider cmp = applicationContext.getBean(FHIRConceptMapProvider.class);
    FHIRMedicationProvider mp = applicationContext.getBean(FHIRMedicationProvider.class);
    FHIRStructureDefinitionProvider sd = applicationContext.getBean(FHIRStructureDefinitionProvider.class);
    resourceProviders.add(csp);
    resourceProviders.add(vsp);
    resourceProviders.add(cmp);
    resourceProviders.add(mp);
    resourceProviders.add(sd);
    setResourceProviders(resourceProviders);
    FHIRTerminologyCapabilitiesProvider tcp = applicationContext.getBean(FHIRTerminologyCapabilitiesProvider.class);
    setServerConformanceProvider(tcp);
    // Now register interceptors
    RootInterceptor interceptor = new RootInterceptor();
    registerInterceptor(interceptor);
    logger.info("FHIR Resource providers and interceptors registered");
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) ArrayList(java.util.ArrayList) FHIRCodeSystemProvider(org.snomed.snowstorm.fhir.services.FHIRCodeSystemProvider) FHIRMedicationProvider(org.snomed.snowstorm.fhir.services.FHIRMedicationProvider) LenientErrorHandler(ca.uhn.fhir.parser.LenientErrorHandler) WebApplicationContext(org.springframework.web.context.WebApplicationContext) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) FHIRValueSetProvider(org.snomed.snowstorm.fhir.services.FHIRValueSetProvider) FHIRStructureDefinitionProvider(org.snomed.snowstorm.fhir.services.FHIRStructureDefinitionProvider) StrictErrorHandler(ca.uhn.fhir.parser.StrictErrorHandler) FHIRTerminologyCapabilitiesProvider(org.snomed.snowstorm.fhir.services.FHIRTerminologyCapabilitiesProvider) FHIRConceptMapProvider(org.snomed.snowstorm.fhir.services.FHIRConceptMapProvider)

Aggregations

FhirContext (ca.uhn.fhir.context.FhirContext)1 LenientErrorHandler (ca.uhn.fhir.parser.LenientErrorHandler)1 StrictErrorHandler (ca.uhn.fhir.parser.StrictErrorHandler)1 IResourceProvider (ca.uhn.fhir.rest.server.IResourceProvider)1 ArrayList (java.util.ArrayList)1 FHIRCodeSystemProvider (org.snomed.snowstorm.fhir.services.FHIRCodeSystemProvider)1 FHIRConceptMapProvider (org.snomed.snowstorm.fhir.services.FHIRConceptMapProvider)1 FHIRMedicationProvider (org.snomed.snowstorm.fhir.services.FHIRMedicationProvider)1 FHIRStructureDefinitionProvider (org.snomed.snowstorm.fhir.services.FHIRStructureDefinitionProvider)1 FHIRTerminologyCapabilitiesProvider (org.snomed.snowstorm.fhir.services.FHIRTerminologyCapabilitiesProvider)1 FHIRValueSetProvider (org.snomed.snowstorm.fhir.services.FHIRValueSetProvider)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1