Search in sources :

Example 1 with CapabilityStatement

use of org.hl7.fhir.dstu3.model.CapabilityStatement 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)

Aggregations

FhirContext (ca.uhn.fhir.context.FhirContext)1 IOException (java.io.IOException)1 CapabilityStatement (org.hl7.fhir.dstu3.model.CapabilityStatement)1