Search in sources :

Example 66 with ValueSet

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()));
    }
}
Also used : IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 67 with ValueSet

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();
    }
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) PrintStream(java.io.PrintStream) Reference(org.hl7.fhir.r4.model.Reference) FileWriter(java.io.FileWriter) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Coding(org.hl7.fhir.r4.model.Coding) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Writer(java.io.Writer) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 68 with ValueSet

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());
}
Also used : Response(javax.ws.rs.core.Response) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 69 with ValueSet

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);
}
Also used : Response(javax.ws.rs.core.Response) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) EnhancedHealthCheckResults(com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckResults) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 70 with ValueSet

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;
}
Also used : ValueSet(org.hl7.fhir.r4.model.ValueSet)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)159 ValueSet (org.hl7.fhir.r4.model.ValueSet)116 Test (org.junit.jupiter.api.Test)115 ArrayList (java.util.ArrayList)101 FHIRException (org.hl7.fhir.exceptions.FHIRException)100 IOException (java.io.IOException)97 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)59 ValueSet (org.hl7.fhir.r4b.model.ValueSet)59 FileNotFoundException (java.io.FileNotFoundException)58 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)56 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)46 HashMap (java.util.HashMap)45 Test (org.junit.Test)45 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)43 File (java.io.File)36 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)29 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)29 FileInputStream (java.io.FileInputStream)27