Search in sources :

Example 56 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project cqf-ruler by DBCG.

the class DataRequirements method getModuleDefinitionLibraryDstu3.

public static org.hl7.fhir.dstu3.model.Library getModuleDefinitionLibraryDstu3(LibraryManager libraryManager, TranslatedLibrary translatedLibrary, CqlTranslatorOptions options) {
    org.hl7.fhir.r5.model.Library libraryR5 = getModuleDefinitionLibraryR5(libraryManager, translatedLibrary, options);
    BaseAdvisor_30_50 baseAdvisor_30_50 = new BaseAdvisor_30_50();
    VersionConvertor_30_50 versionConvertor_30_50 = new VersionConvertor_30_50(baseAdvisor_30_50);
    org.hl7.fhir.dstu3.model.Library libraryDstu3 = null;
    libraryDstu3 = (org.hl7.fhir.dstu3.model.Library) versionConvertor_30_50.convertResource(libraryR5);
    // There is no DSTU3 extension to support FHIRQueryPattern representation on a DataRequirement
    return libraryDstu3;
}
Also used : BaseAdvisor_30_50(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_50) VersionConvertor_30_50(org.hl7.fhir.convertors.conv30_50.VersionConvertor_30_50)

Example 57 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model 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 58 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model 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 59 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model 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 60 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model 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)

Aggregations

Test (org.junit.jupiter.api.Test)435 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)334 Test (org.junit.Test)289 ArrayList (java.util.ArrayList)112 FHIRException (org.hl7.fhir.exceptions.FHIRException)111 IOException (java.io.IOException)84 List (java.util.List)73 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)70 Date (java.util.Date)68 FileOutputStream (java.io.FileOutputStream)66 File (java.io.File)61 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)61 CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 InputStream (java.io.InputStream)55 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)51 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 Bundle (org.hl7.fhir.dstu3.model.Bundle)49 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)48 Collectors (java.util.stream.Collectors)48 Arrays (java.util.Arrays)46