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;
}
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;
}
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);
}
}
}
}
}
}
}
}
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);
}
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;
}
Aggregations