Search in sources :

Example 41 with org.hl7.fhir.r5.utils.validation.constants

use of org.hl7.fhir.r5.utils.validation.constants 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 42 with org.hl7.fhir.r5.utils.validation.constants

use of org.hl7.fhir.r5.utils.validation.constants in project quality-measure-and-cohort-service by Alvearie.

the class CQLToFHIRMeasureReportHelperTest method testRatio.

@Test
public void testRatio() {
    String unit = "ml";
    BigDecimal amount1 = new BigDecimal("4.0");
    Quantity quantity1 = new Quantity().withUnit(unit).withValue(amount1);
    BigDecimal amount2 = new BigDecimal("7.0");
    Quantity quantity2 = new Quantity().withUnit(unit).withValue(amount2);
    Ratio ratio = new Ratio().setNumerator(quantity1).setDenominator(quantity2);
    IBaseDatatype fhirTypeValue = CQLToFHIRMeasureReportHelper.getFhirTypeValue(ratio);
    assertTrue(fhirTypeValue instanceof org.hl7.fhir.r4.model.Ratio);
    org.hl7.fhir.r4.model.Ratio castResult = (org.hl7.fhir.r4.model.Ratio) fhirTypeValue;
    verifyBaseTypeAsQuantity(castResult.getNumerator(), amount1, unit);
    verifyBaseTypeAsQuantity(castResult.getDenominator(), amount2, unit);
}
Also used : IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) Quantity(org.opencds.cqf.cql.engine.runtime.Quantity) Ratio(org.opencds.cqf.cql.engine.runtime.Ratio) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 43 with org.hl7.fhir.r5.utils.validation.constants

use of org.hl7.fhir.r5.utils.validation.constants in project quality-measure-and-cohort-service by Alvearie.

the class MeasureHelperTest method testResolveByIdentifier_getLatestMeasure.

@Test
public void testResolveByIdentifier_getLatestMeasure() throws Exception {
    String identifierSystem = "system1";
    String identifierValue = "val1";
    Measure measure1 = getCohortMeasure("Test", getLibrary("123", DEFAULT_VERSION, "cql/basic/Test-1.0.0.xml"), "Female");
    Measure measure2 = getCohortMeasure("Test", getLibrary("123", DEFAULT_VERSION, "cql/basic/Test-1.0.0.xml"), "Female");
    Measure measure3 = getCohortMeasure("Test", getLibrary("123", DEFAULT_VERSION, "cql/basic/Test-1.0.0.xml"), "Female");
    measure1.setVersion("1.0.0");
    measure2.setVersion("2.0.0");
    org.hl7.fhir.r4.model.Identifier identifier = new IdentifierBuilder().buildValue(identifierValue).buildSystem(identifierSystem).build();
    measure1.setIdentifier(Collections.singletonList(identifier));
    measure2.setIdentifier(Collections.singletonList(identifier));
    measure3.setIdentifier(Collections.singletonList(identifier));
    MappingBuilder builder = get(urlPathEqualTo("/Measure")).withQueryParam("identifier", new EqualToPattern(identifierSystem + '|' + identifierValue)).withQueryParam("_format", new EqualToPattern("json"));
    mockFhirResourceRetrieval(builder, getBundle(measure1, measure2, measure3));
    Measure actual = MeasureHelper.loadMeasure(new Identifier(identifierSystem, identifierValue), null, resolver);
    assertNotNull(actual);
    assertEquals("Test", actual.getName());
    assertEquals("2.0.0", actual.getVersion());
}
Also used : MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) IdentifierBuilder(com.ibm.cohort.engine.r4.builder.IdentifierBuilder) Measure(org.hl7.fhir.r4.model.Measure) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Test(org.junit.Test)

Example 44 with org.hl7.fhir.r5.utils.validation.constants

use of org.hl7.fhir.r5.utils.validation.constants in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverterTest method testRange__shouldReturnIntervalParameterOfQuantityParameter.

@Test
public void testRange__shouldReturnIntervalParameterOfQuantityParameter() {
    ParameterDefinition parameterDefinition = getBaseParameterDefinition("Range");
    String lowString = "1.5";
    String highString = "2.5";
    BigDecimal lowValue = new BigDecimal(lowString);
    BigDecimal highValue = new BigDecimal(highString);
    String unit = "ml";
    Range fhirValue = new Range().setLow(new org.hl7.fhir.r4.model.Quantity().setValue(lowValue).setUnit(unit)).setHigh(new org.hl7.fhir.r4.model.Quantity().setValue(highValue).setUnit(unit));
    parameterDefinition.addExtension(CDMConstants.PARAMETER_DEFAULT_URL, fhirValue);
    IntervalParameter expectedParameter = new IntervalParameter(new QuantityParameter().setUnit(unit).setAmount(lowString), true, new QuantityParameter().setUnit(unit).setAmount(highString), true);
    assertEquals(expectedParameter, R4ParameterDefinitionWithDefaultToCohortParameterConverter.toCohortParameter(parameterDefinition));
}
Also used : QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) Range(org.hl7.fhir.r4.model.Range) BigDecimal(java.math.BigDecimal) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Test(org.junit.Test)

Example 45 with org.hl7.fhir.r5.utils.validation.constants

use of org.hl7.fhir.r5.utils.validation.constants in project openmrs-module-fhir2 by openmrs.

the class ConditionSearchQueryTest method searchForObsConditions_shouldReturnConditionByPatientIdentifier.

@Test
public void searchForObsConditions_shouldReturnConditionByPatientIdentifier() {
    ReferenceParam patientReference = new ReferenceParam(Patient.SP_IDENTIFIER, PATIENT_IDENTIFIER);
    ReferenceAndListParam patientList = new ReferenceAndListParam();
    patientList.addAnd(new ReferenceOrListParam().addOr(patientReference));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientList);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertEquals(resultList.size(), 2);
    assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReference(), endsWith(PATIENT_UUID));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Test (org.junit.jupiter.api.Test)427 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)334 Test (org.junit.Test)241 FHIRException (org.hl7.fhir.exceptions.FHIRException)104 ArrayList (java.util.ArrayList)101 IOException (java.io.IOException)78 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)70 Date (java.util.Date)65 List (java.util.List)64 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)61 FileOutputStream (java.io.FileOutputStream)59 CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 File (java.io.File)57 InputStream (java.io.InputStream)51 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)48 Bundle (org.hl7.fhir.dstu3.model.Bundle)48 MethodSource (org.junit.jupiter.params.provider.MethodSource)46 Arrays (java.util.Arrays)45 Collectors (java.util.stream.Collectors)45