Search in sources :

Example 66 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.

the class GitHubFileStore method getCqlRule.

public CqlRule getCqlRule(String topic, String fhirVersion) {
    logger.info("GitHubFileStore::getCqlRule(): " + topic + "/" + fhirVersion);
    // load CQL files needed for the CRD Rule
    HashMap<String, byte[]> cqlFiles = new HashMap<>();
    String rulePath = config.getGitHubConfig().getRulePath();
    String examplesPath = config.getGitHubConfig().getExamplesPath();
    String mainCqlLibraryName = topic + "Rule";
    String mainCqlFile = findGitHubFile(topic, fhirVersion, mainCqlLibraryName, FileStore.CQL_EXTENSION);
    if (mainCqlFile == null) {
        logger.warn("GitHubFileStore::getCqlRule(): failed to find main CQL file");
    } else {
        String mainCqlFilePath = rulePath + topic + "/" + fhirVersion + "/files/" + mainCqlFile;
        try {
            InputStream inputStream = connection.getFile(mainCqlFilePath);
            if (inputStream == null) {
                // look for the main cql file in the examples path as well
                mainCqlFilePath = examplesPath + topic + "/" + fhirVersion + "/files/" + mainCqlFile;
                inputStream = connection.getFile(mainCqlFilePath);
            }
            cqlFiles.put(mainCqlFile, IOUtils.toByteArray(inputStream));
            logger.info("GitHubFileStore::getCqlRule(): added mainCqlFile: " + mainCqlFile);
        } catch (IOException e) {
            logger.warn("GitHubFileStore::getCqlRule(): failed to open main cql file: " + e.getMessage());
        }
    }
    String helperCqlFile = findGitHubFile(FileStore.SHARED_TOPIC, fhirVersion, FileStore.FHIR_HELPERS_FILENAME, FileStore.CQL_EXTENSION);
    if (helperCqlFile == null) {
        logger.warn("GitHubFileStore::getCqlRule(): failed to find FHIR helper CQL file");
    } else {
        String helperCqlFilePath = rulePath + "Shared/" + fhirVersion + "/files/" + helperCqlFile;
        try {
            InputStream inputStream = connection.getFile(helperCqlFilePath);
            if (inputStream == null) {
                // look for the helper cql file in the examples path as well
                helperCqlFilePath = examplesPath + "Shared/" + fhirVersion + "/files/" + helperCqlFile;
                inputStream = connection.getFile(helperCqlFilePath);
            }
            cqlFiles.put(helperCqlFile, IOUtils.toByteArray(inputStream));
            logger.info("GitHubFileStore::getCqlRule(): added helperCqlFile: " + helperCqlFile);
        } catch (IOException e) {
            logger.warn("GitHubFileStore::getCqlRule(): failed to open file FHIR helper cql file: " + e.getMessage());
        }
    }
    return new CqlRule(mainCqlLibraryName, cqlFiles, fhirVersion);
}
Also used : CqlRule(org.hl7.davinci.endpoint.cql.CqlRule) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 67 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.

the class Metadata method buildCapabilityStatement.

/**
 * Builds the CapabilityStatement describing the Coverage Requirements Discovery Reference
 * Implementation.
 *
 * @return CapabilityStatement - the CapabilityStatement.
 */
private CapabilityStatement buildCapabilityStatement(String baseUrl) {
    CapabilityStatement metadata = new CapabilityStatement();
    metadata.setTitle("Da Vinci Coverage Requirements Discovery (CRD) Reference Implementation");
    metadata.setStatus(PublicationStatus.DRAFT);
    metadata.setExperimental(true);
    Calendar calendar = Calendar.getInstance();
    calendar.set(2019, 4, 28, 0, 0, 0);
    metadata.setDate(calendar.getTime());
    metadata.setPublisher("Da Vinci");
    metadata.setKind(CapabilityStatementKind.INSTANCE);
    CapabilityStatementSoftwareComponent software = new CapabilityStatementSoftwareComponent();
    software.setName("https://github.com/HL7-DaVinci/CRD");
    metadata.setSoftware(software);
    CapabilityStatementImplementationComponent implementation = new CapabilityStatementImplementationComponent();
    implementation.setDescription(metadata.getTitle());
    implementation.setUrl(baseUrl + "metadata");
    metadata.setImplementation(implementation);
    metadata.setFhirVersion(FHIRVersion._4_0_1);
    metadata.addFormat("json");
    metadata.addExtension("http://hl7.org/fhir/StructureDefinition/capabilitystatement-websocket", new StringType("/fhir/r4"));
    metadata.addImplementationGuide("https://build.fhir.org/ig/HL7/davinci-crd/index.html");
    CapabilityStatementRestComponent rest = new CapabilityStatementRestComponent();
    rest.setMode(RestfulCapabilityMode.SERVER);
    CapabilityStatementRestSecurityComponent security = new CapabilityStatementRestSecurityComponent();
    security.setCors(true);
    rest.setSecurity(security);
    // Library Resource
    CapabilityStatementRestResourceComponent library = new CapabilityStatementRestResourceComponent();
    library.setType("Library");
    library.addInteraction().setCode(TypeRestfulInteraction.READ);
    library.addInteraction().setCode(TypeRestfulInteraction.SEARCHTYPE);
    library.addInteraction().setCode(TypeRestfulInteraction.CREATE);
    rest.addResource(library);
    // Questionnaire Resource
    CapabilityStatementRestResourceComponent questionnaire = new CapabilityStatementRestResourceComponent();
    questionnaire.setType("Questionnaire");
    questionnaire.addInteraction().setCode(TypeRestfulInteraction.READ);
    questionnaire.addInteraction().setCode(TypeRestfulInteraction.SEARCHTYPE);
    questionnaire.addInteraction().setCode(TypeRestfulInteraction.CREATE);
    CapabilityStatementRestResourceOperationComponent questionnairePackageOperation = new CapabilityStatementRestResourceOperationComponent();
    questionnairePackageOperation.setName("questionnaire-package");
    questionnairePackageOperation.setDefinition("http://hl7.org/fhir/us/davinci-dtr/OperationDefinition/Questionnaire-package");
    questionnairePackageOperation.setDocumentation("Retrieve the Questionnaire(s), Libraries, and Valuesets for a given order and coverage. This operation is to support HL7 DaVinci DTR.");
    questionnaire.addOperation(questionnairePackageOperation);
    rest.addResource(questionnaire);
    // QuestionnaireResponse Resource
    CapabilityStatementRestResourceComponent questionnaireResponse = new CapabilityStatementRestResourceComponent();
    questionnaireResponse.setType("QuestionnaireResponse");
    questionnaireResponse.addInteraction().setCode(TypeRestfulInteraction.READ);
    questionnaireResponse.addInteraction().setCode(TypeRestfulInteraction.SEARCHTYPE);
    questionnaireResponse.addInteraction().setCode(TypeRestfulInteraction.CREATE);
    rest.addResource(questionnaireResponse);
    // ValueSet Resource
    CapabilityStatementRestResourceComponent valueset = new CapabilityStatementRestResourceComponent();
    valueset.setType("ValueSet");
    valueset.addInteraction().setCode(TypeRestfulInteraction.READ);
    valueset.addInteraction().setCode(TypeRestfulInteraction.SEARCHTYPE);
    valueset.addInteraction().setCode(TypeRestfulInteraction.CREATE);
    // ValueSet $expand Operator
    CapabilityStatementRestResourceOperationComponent expandOperator = new CapabilityStatementRestResourceOperationComponent();
    expandOperator.setName("expand");
    expandOperator.setDefinition("http://hl7.org/fhir/OperationDefinition/ValueSet-expand");
    expandOperator.setDocumentation("Only works at the ValueSet type level with a 'url' query parameter. Will only return expansions that are pre-cached on this server.");
    valueset.addOperation(expandOperator);
    rest.addResource(valueset);
    metadata.addRest(rest);
    return metadata;
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) CapabilityStatementImplementationComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementImplementationComponent) CapabilityStatementRestSecurityComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestSecurityComponent) Calendar(java.util.Calendar) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) CapabilityStatementSoftwareComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementSoftwareComponent) CapabilityStatementRestComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestComponent) CapabilityStatementRestResourceComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceComponent) CapabilityStatementRestResourceOperationComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceOperationComponent)

Aggregations

ArrayList (java.util.ArrayList)10 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)9 JsonObject (com.google.gson.JsonObject)8 Date (java.util.Date)8 IOException (java.io.IOException)7 FhirContext (ca.uhn.fhir.context.FhirContext)6 JsonArray (com.google.gson.JsonArray)6 HashMap (java.util.HashMap)5 FhirVersionEnum (ca.uhn.fhir.context.FhirVersionEnum)4 IParser (ca.uhn.fhir.parser.IParser)4 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 JsonPrimitive (com.google.gson.JsonPrimitive)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 CascadingDeleteInterceptor (ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor)2