Search in sources :

Example 1 with FhirContext

use of ca.uhn.fhir.context.FhirContext in project gpconnect-demonstrator by nhsconnect.

the class GpConnectServerCapabilityStatementProvider method getServerConformance.

@Override
public CapabilityStatement getServerConformance(HttpServletRequest theRequest) {
    final boolean FROM_JSON = true;
    CapabilityStatement capabilityStatement = null;
    if (!FROM_JSON) {
        // Get the automatically generated statement
        capabilityStatement = super.getServerConformance(theRequest);
        // added at 1.2.2 force overwrite the default entries which are not correct
        for (CapabilityStatement.CapabilityStatementRestComponent st : capabilityStatement.getRest()) {
            for (CapabilityStatement.CapabilityStatementRestOperationComponent operation : st.getOperation()) {
                String opPlusDollar = "$" + operation.getName();
                switch(opPlusDollar) {
                    case REGISTER_PATIENT_OPERATION_NAME:
                        operation.getDefinition().setReference(OD_GPC_REGISTER_PATIENT);
                        break;
                    case GET_STRUCTURED_RECORD_OPERATION_NAME:
                        operation.getDefinition().setReference(OD_GPC_GET_STRUCTURED_RECORD);
                        break;
                }
            }
        }
    } else {
        try {
            // 1.2.6 #316
            String interactionId = theRequest.getHeader(SSP_INTERACTIONID);
            String capabilityFile = null;
            switch(interactionId) {
                case REST_READ_STRUCTURED_METADATA:
                    capabilityFile = "structured_capability.json";
                    break;
                default:
                    capabilityFile = "capability.json";
            }
            // read a json capability file
            String capabilityJson = new String(Files.readAllBytes(Paths.get(FhirRequestGenericIntercepter.getConfigPath() + "/" + capabilityFile)));
            FhirContext ctx = FhirContext.forDstu3();
            capabilityStatement = (CapabilityStatement) ctx.newJsonParser().parseResource(capabilityJson);
        } catch (IOException ex) {
            return null;
        }
    }
    // And add additional required information
    capabilityStatement.setVersion(SystemVariable.VERSION);
    capabilityStatement.setDescription("This server implements the GP Connect API version " + SystemVariable.VERSION);
    capabilityStatement.setName("GP Connect");
    capabilityStatement.setCopyright("Copyright NHS Digital 2018");
    capabilityStatement.getSoftware().setReleaseDate(Date.valueOf(LocalDate.parse("2017-09-27")));
    return capabilityStatement;
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) IOException(java.io.IOException)

Example 2 with FhirContext

use of ca.uhn.fhir.context.FhirContext in project gpconnect-demonstrator by nhsconnect.

the class ValueSetValidator method findValueSet.

private ValueSet findValueSet(String systemUrl) {
    int valueSetNamePos = systemUrl.lastIndexOf("/") + 1;
    String valueSetFilename = String.format("%s.xml", systemUrl.substring(valueSetNamePos));
    ValueSet valSet = null;
    String xmlContent = null;
    if (fhirValueSetsCheckWebFirst == true) {
        xmlContent = readValueSetFromWeb(valueSetFilename);
    }
    if (xmlContent == null) {
        xmlContent = readValueSetFromDisk(valueSetFilename);
    }
    if (fhirValueSetsCheckWebFirst == false && xmlContent == null) {
        xmlContent = readValueSetFromWeb(valueSetFilename);
    }
    if (xmlContent != null) {
        try {
            FhirContext fhirCtx = FhirContext.forDstu3();
            IParser parser = fhirCtx.newXmlParser();
            valSet = parser.parseResource(ValueSet.class, xmlContent);
        } catch (DataFormatException ex) {
            LOG.error(String.format("Error parsing valueSetFilename: %s", valueSetFilename));
        }
    }
    if (valSet == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(String.format("Could not find or parse Value Set [SystemUrl: %s] at: %s. See system log for details.", systemUrl, valueSetFilename)), SystemCode.REFERENCE_NOT_FOUND, IssueType.NOTFOUND);
    }
    return valSet;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) FhirContext(ca.uhn.fhir.context.FhirContext) DataFormatException(ca.uhn.fhir.parser.DataFormatException) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) IParser(ca.uhn.fhir.parser.IParser)

Example 3 with FhirContext

use of ca.uhn.fhir.context.FhirContext in project gpconnect-demonstrator by nhsconnect.

the class FhirRestfulServlet method initialize.

@Override
protected void initialize() throws ServletException {
    FhirContext ctx = FhirContext.forDstu3();
    ctx.setParserErrorHandler(new StrictErrorHandler());
    // version required on capability statement operation definition
    // see https://hapifhir.io/doc_resource_references.html
    ctx.getParserOptions().setStripVersionsFromReferences(false);
    // This explicit call does not work
    // /ctx.getParserOptions().setDontStripVersionsFromReferencesAtPaths("CapabilityStatement");
    setFhirContext(ctx);
    setETagSupport(ETagSupportEnum.ENABLED);
    setServerAddressStrategy(new HardcodedServerAddressStrategy(serverBaseUrl));
    setResourceProviders(Arrays.asList(applicationContext.getBean(PatientResourceProvider.class), applicationContext.getBean(OrganizationResourceProvider.class), applicationContext.getBean(PractitionerResourceProvider.class), // applicationContext.getBean(MedicationResourceProvider.class), // #183
    applicationContext.getBean(LocationResourceProvider.class), applicationContext.getBean(AppointmentResourceProvider.class), // applicationContext.getBean(ScheduleResourceProvider.class), // #183
    applicationContext.getBean(SlotResourceProvider.class)));
    CorsConfiguration config = new CorsConfiguration();
    config.setMaxAge(10L);
    config.addAllowedOrigin("*");
    config.setAllowCredentials(Boolean.TRUE);
    config.setExposedHeaders(Arrays.asList(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
    config.setAllowedMethods(Arrays.asList(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name(), HttpMethod.DELETE.name()));
    config.setAllowedHeaders(Arrays.asList(HttpHeaders.ACCEPT, HttpHeaders.ACCEPT_ENCODING, HttpHeaders.ACCEPT_LANGUAGE, HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, HttpHeaders.AUTHORIZATION, HttpHeaders.CACHE_CONTROL, HttpHeaders.CONNECTION, HttpHeaders.CONTENT_LENGTH, SystemHeader.PREFER, HttpHeaders.CONTENT_TYPE, HttpHeaders.COOKIE, HttpHeaders.HOST, HttpHeaders.ORIGIN, HttpHeaders.PRAGMA, HttpHeaders.REFERER, SystemHeader.SSP_FROM, SystemHeader.SSP_INTERACTIONID, SystemHeader.SSP_TO, SystemHeader.SSP_TRACEID, HttpHeaders.USER_AGENT, SystemHeader.X_REQUESTED_WITH));
    registerInterceptor(new CorsInterceptor(config));
    registerInterceptor(applicationContext.getBean(FhirRequestAuthInterceptor.class));
    registerInterceptor(applicationContext.getBean(FhirRequestGenericIntercepter.class));
    registerInterceptor(applicationContext.getBean(PatientJwtValidator.class));
    // #215 don't populate Bundle.entry.fullurl
    registerInterceptor(new PostProcessor());
    GpConnectServerCapabilityStatementProvider capStatementProvider = new GpConnectServerCapabilityStatementProvider(this);
    super.setServerConformanceProvider(capStatementProvider);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) StrictErrorHandler(ca.uhn.fhir.parser.StrictErrorHandler) CorsConfiguration(org.springframework.web.cors.CorsConfiguration) FhirRequestGenericIntercepter(uk.gov.hscic.common.filters.FhirRequestGenericIntercepter) FhirRequestAuthInterceptor(uk.gov.hscic.common.filters.FhirRequestAuthInterceptor) GpConnectServerCapabilityStatementProvider(uk.gov.hscic.metadata.GpConnectServerCapabilityStatementProvider) PatientJwtValidator(uk.gov.hscic.common.filters.PatientJwtValidator) CorsInterceptor(ca.uhn.fhir.rest.server.interceptor.CorsInterceptor) HardcodedServerAddressStrategy(ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy)

Aggregations

FhirContext (ca.uhn.fhir.context.FhirContext)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)1 IParser (ca.uhn.fhir.parser.IParser)1 StrictErrorHandler (ca.uhn.fhir.parser.StrictErrorHandler)1 HardcodedServerAddressStrategy (ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy)1 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)1 CorsInterceptor (ca.uhn.fhir.rest.server.interceptor.CorsInterceptor)1 IOException (java.io.IOException)1 CapabilityStatement (org.hl7.fhir.dstu3.model.CapabilityStatement)1 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)1 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)1 FhirRequestAuthInterceptor (uk.gov.hscic.common.filters.FhirRequestAuthInterceptor)1 FhirRequestGenericIntercepter (uk.gov.hscic.common.filters.FhirRequestGenericIntercepter)1 PatientJwtValidator (uk.gov.hscic.common.filters.PatientJwtValidator)1 GpConnectServerCapabilityStatementProvider (uk.gov.hscic.metadata.GpConnectServerCapabilityStatementProvider)1