use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testMainMultipleResultTypes.
@Test
public void testMainMultipleResultTypes() throws Exception {
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
patient.setMaritalStatus(new CodeableConcept(new Coding("http://hl7.org/fhir/ValueSet/marital-status", "M", "Married")));
mockFhirResourceRetrieval(patient);
Condition condition = new Condition();
condition.setSubject(new Reference(patient.getId()));
condition.setCode(new CodeableConcept(new Coding("http://snomed.com/snomed/2020", "1234", "Dummy")));
mockFhirResourceRetrieval("/Condition?code%3Ain=http%3A%2F%2Fsome.io%2Fcondition&subject=Patient%2F" + patient.getId() + "&_count=500&_format=json", condition);
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-f", "src/test/resources/cql/result-types", "-l", "test_result_types", "-c", patient.getId(), "--enable-terminology-optimization", "--search-page-size", "500" });
} finally {
System.setOut(originalOut);
}
String output = new String(baos.toByteArray());
assertTrue(output.contains("Collection: 1"));
assertTrue(output.contains("Patient/123"));
assertTrue(output.contains("false"));
assertTrue(output.contains("DateType[1978-05-06]"));
assertTrue(output.contains("Enumeration[female]"));
String[] lines = output.split("\r?\n");
assertEquals(output, 9, lines.length);
System.out.println(output);
} finally {
tmpFile.delete();
}
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testMainNonPatientContext.
@Test
public void testMainNonPatientContext() throws Exception {
Encounter encounter = new Encounter();
encounter.setId("123");
encounter.setStatus(Encounter.EncounterStatus.FINISHED);
Encounter otherEncounter = new Encounter();
otherEncounter.setId("234");
otherEncounter.setStatus(Encounter.EncounterStatus.FINISHED);
FhirServerConfig fhirConfig = getFhirServerConfig();
String resourcePath = "/Encounter?_count=1000&_format=json";
mockFhirResourceRetrieval(resourcePath, getFhirParser(), makeBundle(encounter, otherEncounter));
setupTestFor(encounter, fhirConfig, "cql.encounter-context");
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-t", tmpFile.getAbsolutePath(), "-f", "src/test/resources/cql/encounter-context", "-l", "EncounterContext", "-v", "1.0.0", "-e", "ValidEncounterCount", "-n", "Encounter" });
} finally {
System.setOut(originalOut);
}
String output = baos.toString();
assertTrue(output.contains("Expression: \"ValidEncounterCount\", Result: 2"));
verify(1, getRequestedFor(urlEqualTo(resourcePath)));
} finally {
tmpFile.delete();
}
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testCQLTranslationCustomIGWithTargetUrl.
@Test
public void testCQLTranslationCustomIGWithTargetUrl() throws Exception {
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
patient.addExtension(new Extension("http://fakeIg.com/fake-extension", new StringType("fakeValue")));
mockFhirResourceRetrieval(patient);
Library root = getLibrary("test", DEFAULT_RESOURCE_VERSION, "cql/ig-test/Test-1.0.0.cql");
Library helpers = getLibrary("FHIRHelpers", "4.0.0", "cql/fhir-helpers/FHIRHelpers.cql", "text/cql", "cql/fhir-helpers/FHIRHelpers.xml", "application/elm+json");
RelatedArtifact related = new RelatedArtifact();
related.setType(RelatedArtifactType.DEPENDSON);
related.setResource("/Library/" + helpers.getId());
root.addRelatedArtifact(related);
mockFhirResourceRetrieval(root);
mockFhirSingletonBundleRetrieval(helpers);
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-f", root.getId(), "-l", root.getName(), "-v", root.getVersion(), "-c", patient.getId(), "-s", "CQL", "-i", "src/test/resources/modelinfo/ig-with-target-modelinfo-0.0.1.xml" });
} finally {
System.setOut(originalOut);
}
String output = new String(baos.toByteArray());
System.out.println(output);
verify(1, getRequestedFor(urlEqualTo("/Patient/" + patient.getId() + "?_format=json")));
verify(1, getRequestedFor(urlEqualTo("/Library/" + root.getId() + "?_format=json")));
verify(1, getRequestedFor(urlEqualTo("/Library?url=%2FLibrary%2F" + helpers.getId() + "&_format=json")));
} finally {
tmpFile.delete();
}
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testMainZippedLibrariesMultiFolderWithExtraEntries.
@Test
public void testMainZippedLibrariesMultiFolderWithExtraEntries() throws Exception {
FhirServerConfig fhirConfig = getFhirServerConfig();
IParser encoder = getFhirParser();
mockFhirResourceRetrieval("/metadata?_format=json", encoder, getCapabilityStatement(), fhirConfig);
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
mockFhirResourceRetrieval(patient);
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-t", tmpFile.getAbsolutePath(), "-f", "src/test/resources/cql/zip-with-folders/cohorts.zip", "-l", "Breast-Cancer", "-v", "Screening", "-e", "Female", "-e", "Ages 40 to 75", "-e", "MeetsInclusionCriteria", "-c", "123", "-s", "CQL" });
} finally {
System.setOut(originalOut);
}
String output = new String(baos.toByteArray());
String[] lines = output.split("\r?\n");
assertEquals(output, 6, lines.length);
System.out.println(output);
verify(1, getRequestedFor(urlEqualTo("/Patient/123?_format=json")));
} finally {
tmpFile.delete();
}
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class FhirClientTimeoutTest method testDefaultFhirClientBuilder_requestTimesOut.
@Test(expected = FhirClientConnectionException.class)
public void testDefaultFhirClientBuilder_requestTimesOut() {
FhirServerConfig fhirServerConfig = getFhirServerConfig();
fhirServerConfig.setSocketTimeout(CONFIG_TIMEOUT_MILLIS);
DefaultFhirClientBuilder builder = new DefaultFhirClientBuilder(fhirContext);
IGenericClient client = builder.createFhirClient(fhirServerConfig);
client.read().resource(Patient.class).withId(PATIENT_ID).execute();
}
Aggregations