Search in sources :

Example 56 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class FhirTestBase method getFhirServerConfig.

protected FhirServerConfig getFhirServerConfig() {
    FhirServerConfig fhirConfig = new FhirServerConfig();
    fhirConfig.setEndpoint("http://localhost:" + HTTP_PORT);
    fhirConfig.setLogInfo(Arrays.asList(LogInfo.REQUEST_SUMMARY));
    return fhirConfig;
}
Also used : FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig)

Example 57 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class MeasureImporter method runWithArgs.

/**
 * Execute measure import process with given arguments. Console logging is
 * redirected to the provided stream.
 *
 * @param args Program arguments
 * @param out  Sink for console output
 * @return number of errors encountered during processing
 * @throws Exception on any error.
 */
public static int runWithArgs(String[] args, PrintStream out) throws Exception {
    int resultCode = 0;
    Arguments arguments = new Arguments();
    Console console = new DefaultConsole(out);
    JCommander jc = JCommander.newBuilder().programName("measure-importer").console(console).addObject(arguments).build();
    jc.parse(args);
    if (arguments.isDisplayHelp) {
        jc.usage();
        resultCode = 1;
    } else {
        FhirContext fhirContext = FhirContext.forR4();
        ObjectMapper om = new ObjectMapper();
        FhirServerConfig config = om.readValue(arguments.measureServerConfigFile, FhirServerConfig.class);
        IGenericClient client = FhirClientBuilderFactory.newInstance().newFhirClientBuilder(fhirContext).createFhirClient(config);
        MeasureImporter importer = new MeasureImporter(client);
        resultCode = importer.importFiles(arguments.artifactPaths, arguments.outputPath);
        if (resultCode == 0) {
            out.println("Process completed with no errors.");
        } else {
            out.println(String.format("Process completed with errors. Failed to process %d artifacts.", resultCode));
        }
    }
    return resultCode;
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) DefaultConsole(com.beust.jcommander.internal.DefaultConsole) JCommander(com.beust.jcommander.JCommander) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Console(com.beust.jcommander.internal.Console) DefaultConsole(com.beust.jcommander.internal.DefaultConsole) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 58 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class ValueSetImporter method runWithArgs.

void runWithArgs(String[] args, PrintStream out) throws IOException {
    ValueSetImporterArguments arguments = new ValueSetImporterArguments();
    Console console = new DefaultConsole(out);
    JCommander jc = JCommander.newBuilder().programName("value-set-importer").console(console).addObject(arguments).build();
    jc.parse(args);
    if (arguments.isDisplayHelp) {
        jc.usage();
    } else {
        arguments.validate();
        FhirContext fhirContext = FhirContext.forR4();
        // only connect to fhir server if we are not writing it to file system
        IGenericClient client = null;
        ObjectMapper om = new ObjectMapper();
        if (arguments.fileOutputLocation == OutputLocations.NONE) {
            FhirServerConfig config = om.readValue(arguments.measureServerConfigFile, FhirServerConfig.class);
            client = FhirClientBuilderFactory.newInstance().newFhirClientBuilder(fhirContext).createFhirClient(config);
        }
        Map<String, String> codeSystemMappings = null;
        if (arguments.filename != null) {
            codeSystemMappings = ValueSetUtil.getMapFromInputStream(new FileInputStream(new File(arguments.filename)));
        }
        for (String arg : arguments.spreadsheets) {
            try (InputStream is = new FileInputStream(arg)) {
                ValueSetArtifact artifact = ValueSetUtil.createArtifact(is, codeSystemMappings);
                // only import the value set to fhir server if we are not writing the value set to file system
                if (arguments.fileOutputLocation == OutputLocations.NONE) {
                    String retVal = ValueSetUtil.importArtifact(client, artifact, arguments.overrideValueSets);
                    if (retVal == null) {
                        logger.error("Value set already exists! Please provide the override option if you would like to override this value set.");
                    }
                } else {
                    // write value set to file system
                    ValueSet vs = artifact.getFhirResource();
                    // If the valueset id contains urn:oid, remove it to make a valid filename
                    String valueSetId = vs.getId().startsWith("urn:oid:") ? vs.getId().replace("urn:oid:", "") : vs.getId();
                    String vsFileName = valueSetId + "." + arguments.filesystemOutputFormat.toString().toLowerCase();
                    if (arguments.fileOutputLocation == OutputLocations.BOTH || arguments.fileOutputLocation == OutputLocations.S3) {
                        S3Configuration S3Config = om.readValue(arguments.S3JsonConfigs, S3Configuration.class);
                        AmazonS3 S3Client = createClient(S3Config.getAccess_key_id(), S3Config.getSecret_access_key(), S3Config.getEndpoint(), S3Config.getLocation());
                        putToS3(arguments, fhirContext, vs, vsFileName, S3Client);
                    }
                    if (arguments.fileOutputLocation == OutputLocations.BOTH || arguments.fileOutputLocation == OutputLocations.LOCAL) {
                        try (BufferedWriter writer = new BufferedWriter(new FileWriter(arguments.fileSystemOutputPath + System.getProperty("file.separator") + vsFileName))) {
                            // create the output dir if it doesn't exist
                            File outputDir = new File(arguments.fileSystemOutputPath);
                            if (!outputDir.exists()) {
                                outputDir.mkdir();
                            }
                            // write to xml or json format
                            if (arguments.filesystemOutputFormat == FileFormat.JSON) {
                                fhirContext.newJsonParser().encodeResourceToWriter(vs, writer);
                            } else if (arguments.filesystemOutputFormat == FileFormat.XML) {
                                fhirContext.newXmlParser().encodeResourceToWriter(vs, writer);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) FhirContext(ca.uhn.fhir.context.FhirContext) DefaultConsole(com.beust.jcommander.internal.DefaultConsole) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) ValueSetArtifact(com.ibm.cohort.valueset.ValueSetArtifact) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) S3Configuration(com.ibm.cohort.tooling.s3.S3Configuration) JCommander(com.beust.jcommander.JCommander) Console(com.beust.jcommander.internal.Console) DefaultConsole(com.beust.jcommander.internal.DefaultConsole) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) File(java.io.File) ValueSet(org.hl7.fhir.r4.model.ValueSet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 59 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class MeasureImporterTest method testImportBundleClientConnectFailure.

@Test(expected = ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException.class)
public void testImportBundleClientConnectFailure() throws Exception {
    FhirServerConfig fhirConfig = new FhirServerConfig();
    fhirConfig.setEndpoint("http://i.am.not.here");
    runTest(fhirConfig, "src/test/resources/simple_age_measure_v2_2_2.zip", -1);
}
Also used : FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Test(org.junit.Test)

Example 60 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class MeasureImporterTest method roundTripTest.

protected String roundTripTest(String inputPath, String expectedRequest, String expectedResponse, int statusCode, int numExpectedErrors) throws Exception {
    String consoleOutput;
    FhirServerConfig fhirConfig = getFhirServerConfig();
    fhirConfig.setLogInfo(Arrays.asList(LogInfo.REQUEST_SUMMARY));
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    stubFor(post(urlEqualTo("/?_format=json")).willReturn(aResponse().withStatus(statusCode).withHeader("Content-Type", "application/json").withBody(expectedResponse)));
    consoleOutput = runTest(fhirConfig, inputPath, numExpectedErrors);
    verify(1, postRequestedFor(urlEqualTo("/?_format=json")).withRequestBody(equalTo(expectedRequest)));
    return consoleOutput;
}
Also used : FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig)

Aggregations

FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)63 Test (org.junit.Test)52 Patient (org.hl7.fhir.r4.model.Patient)39 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)36 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 HashMap (java.util.HashMap)21 File (java.io.File)18 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)15 Response (javax.ws.rs.core.Response)15 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)14 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)14 FileWriter (java.io.FileWriter)14 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)13 PrintStream (java.io.PrintStream)13 Writer (java.io.Writer)13 ByteArrayInputStream (java.io.ByteArrayInputStream)11 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)10 IMultipartBody (com.ibm.websphere.jaxrs20.multipart.IMultipartBody)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 IParser (ca.uhn.fhir.parser.IParser)9