use of org.hl7.fhir.r4.model.ValueSet in project cqf-ruler by DBCG.
the class JpaTerminologyProvider method expand.
@Override
public Iterable<Code> expand(ValueSetInfo valueSet) throws ResourceNotFoundException {
// This could possibly be refactored into a single call to the underlying HAPI
// Terminology service. Need to think through that..,
IBaseResource vs;
if (hasUrlId(valueSet)) {
if (hasVersion(valueSet) || hasVersionedCodeSystem(valueSet)) {
throw new UnsupportedOperationException(String.format("Could not expand value set %s; version and code system bindings are not supported at this time.", valueSet.getId()));
}
IBundleProvider bundleProvider = search(getClass("ValueSet"), Searches.byUrl(valueSet.getId()), myRequestDetails);
List<IBaseResource> valueSets = bundleProvider.getAllResources();
if (valueSets.isEmpty()) {
throw new IllegalArgumentException(String.format("Could not resolve value set %s.", valueSet.getId()));
} else if (valueSets.size() == 1) {
vs = valueSets.get(0);
} else {
throw new IllegalArgumentException("Found more than 1 ValueSet with url: " + valueSet.getId());
}
} else {
vs = read(Ids.newId(this.myTerminologySvc.getFhirContext(), "ValueSet", valueSet.getId()), myRequestDetails);
if (vs == null) {
throw new IllegalArgumentException(String.format("Could not resolve value set %s.", valueSet.getId()));
}
}
// relies heavily on reflection.
switch(vs.getStructureFhirVersionEnum()) {
case DSTU3:
return getCodes((org.hl7.fhir.dstu3.model.ValueSet) vs);
case R4:
return getCodes((org.hl7.fhir.r4.model.ValueSet) vs);
case R5:
return getCodes((org.hl7.fhir.r5.model.ValueSet) vs);
default:
throw new IllegalArgumentException(String.format("expand does not support FHIR version %s", vs.getStructureFhirVersionEnum().getFhirVersionString()));
}
}
use of org.hl7.fhir.r4.model.ValueSet 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 org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestStatusHandlerTest method testEnhancedHealthCheckFailedNoInput.
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class, DefaultFhirClientBuilder.class })
@Test
public /**
* Test a failure when invalid input provided
*/
void testEnhancedHealthCheckFailedNoInput() throws Exception {
prepMocks(false);
PowerMockito.mockStatic(ServiceBaseUtility.class);
PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, CohortEngineRestStatusHandler.GET_HEALTH_CHECK_ENCHANCED)).thenReturn(null);
CapabilityStatement metadata = getCapabilityStatement();
mockFhirResourceRetrieval("/metadata?_format=json", metadata);
// return null to cause exception
mockFhirResourceRetrieval("/Patient?_format=json", null);
mockFhirResourceRetrieval("/ValueSet?_format=json", null);
Response response = cerSH.getHealthCheckEnhanced(VERSION, null);
assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
}
use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestStatusHandlerTest method testEnhancedHealthCheckFailed.
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class, DefaultFhirClientBuilder.class })
@Test
public /**
* Test the service returns a failure when trying to connect to data and terminology servers
*/
void testEnhancedHealthCheckFailed() throws Exception {
prepMocks(false);
PowerMockito.mockStatic(ServiceBaseUtility.class);
PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, CohortEngineRestStatusHandler.GET_HEALTH_CHECK_ENCHANCED)).thenReturn(null);
CapabilityStatement metadata = getCapabilityStatement();
mockFhirResourceRetrieval("/metadata?_format=json", metadata);
// return null to cause exception
mockFhirResourceRetrieval("/Patient?_format=json", null);
mockFhirResourceRetrieval("/ValueSet?_format=json", null);
Response response = cerSH.getHealthCheckEnhanced(VERSION, getEnhancedHealthCheckInputConfigFileBody(true));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getDataServerConnectionResults().getConnectionResults(), FhirConnectionStatus.failure);
assertEquals(((EnhancedHealthCheckResults) response.getEntity()).getTerminologyServerConnectionResults().getConnectionResults(), FhirConnectionStatus.failure);
}
use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.
the class RestFhirRetrieveProviderTest method makeValueSet.
protected ValueSet makeValueSet(String name, String system, String... codes) {
ValueSet vs = new ValueSet();
vs.setId(name);
vs.setName(name);
vs.setUrl("http://somewhere.com/fhir/ValueSet/" + name);
vs.setVersion("1.0.0");
for (String code : codes) {
vs.getExpansion().addContains().setSystem(system).setCode(code);
}
return vs;
}
Aggregations