Search in sources :

Example 16 with Library

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

the class CollectDataProviderIT method testCollectData.

@Test
public void testCollectData() {
    // Create test Measure
    String cql = CqlBuilder.newCqlLibrary("4.0.1").addExpression("Initial Population", "exists([Observation])").build();
    Library lib = Libraries.library(cql);
    Measure m = MeasureBuilder.newCohortMeasure(lib).build();
    this.update(lib);
    this.update(m);
    // Create test data
    Patient john = Patients.john_doe();
    this.create(john);
    Observation obs = newResource(Observation.class).setSubject(new Reference(john));
    this.create(obs);
    Encounter enc = newResource(Encounter.class).setSubject(new Reference(john));
    this.create(enc);
    // Submit it
    Parameters results = collectDataProvider.collectData(new SystemRequestDetails(), m.getIdElement(), "2019-01-01", "2019-12-31", Ids.simple(john), null, null);
    List<ParametersParameterComponent> resources = org.opencds.cqf.ruler.utility.r4.Parameters.getPartsByName(results, "resource");
    assertEquals(1, resources.size());
    assertEquals("Observation", resources.get(0).getResource().fhirType());
    List<ParametersParameterComponent> reports = org.opencds.cqf.ruler.utility.r4.Parameters.getPartsByName(results, "measureReport");
    assertEquals(1, reports.size());
    assertEquals("MeasureReport", reports.get(0).getResource().fhirType());
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) Reference(org.hl7.fhir.r4.model.Reference) Measure(org.hl7.fhir.r4.model.Measure) Observation(org.hl7.fhir.r4.model.Observation) Patient(org.hl7.fhir.r4.model.Patient) Encounter(org.hl7.fhir.r4.model.Encounter) Library(org.hl7.fhir.r4.model.Library) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) Test(org.junit.jupiter.api.Test) DaoIntegrationTest(org.opencds.cqf.ruler.test.DaoIntegrationTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with Library

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

the class DataOperationProviderIT method testR4MeasureDataRequirementsOperation.

@Test
public void testR4MeasureDataRequirementsOperation() throws IOException {
    String bundleAsText = stringFromResource("Exm104FhirR4MeasureBundle.json");
    Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText);
    getClient().transaction().withBundle(bundle).execute();
    Parameters params = new Parameters();
    params.addParameter().setName("startPeriod").setValue(new StringType("2019-01-01"));
    params.addParameter().setName("endPeriod").setValue(new StringType("2020-01-01"));
    Library returnLibrary = getClient().operation().onInstance(new IdType("Measure", "measure-EXM104-8.2.000")).named("$data-requirements").withParameters(params).returnResourceType(Library.class).execute();
    assertNotNull(returnLibrary);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) Library(org.hl7.fhir.r4.model.Library) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 18 with Library

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

the class DataOperationProviderIT method testR4LibraryDataRequirementsOperation.

@Test
public void testR4LibraryDataRequirementsOperation() throws IOException {
    String bundleAsText = stringFromResource("DataReqLibraryTransactionBundle.json");
    Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText);
    getClient().transaction().withBundle(bundle).execute();
    Parameters params = new Parameters();
    params.addParameter().setName("target").setValue(new StringType("dummy"));
    Library returnLibrary = getClient().operation().onInstance(new IdType("Library", "LibraryEvaluationTest")).named("$data-requirements").withParameters(params).returnResourceType(Library.class).execute();
    assertNotNull(returnLibrary);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) Library(org.hl7.fhir.r4.model.Library) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 19 with Library

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

the class DataOperationsProvider method createLibraryManager.

private LibraryManager createLibraryManager(Library library, RequestDetails theRequestDetails) {
    JpaLibraryContentProvider jpaLibraryContentProvider = jpaLibraryContentProviderFactory.create(theRequestDetails);
    Bundle libraryBundle = new Bundle();
    List<Library> listLib = fetchDependencyLibraries(library, theRequestDetails);
    listLib.add(library);
    listLib.forEach(lib -> {
        Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent();
        component.setResource(lib);
        libraryBundle.addEntry(component);
    });
    LibraryContentProvider bundleLibraryProvider = new BundleFhirLibraryContentProvider(this.getFhirContext(), libraryBundle, adapterFactory, libraryVersionSelector);
    List<LibraryContentProvider> sourceProviders = new ArrayList<>(Arrays.asList(bundleLibraryProvider, jpaLibraryContentProvider));
    return libraryManagerFactory.create(sourceProviders);
}
Also used : BundleFhirLibraryContentProvider(org.opencds.cqf.cql.evaluator.cql2elm.content.fhir.BundleFhirLibraryContentProvider) LibraryContentProvider(org.opencds.cqf.cql.evaluator.cql2elm.content.LibraryContentProvider) JpaLibraryContentProvider(org.opencds.cqf.ruler.cql.JpaLibraryContentProvider) BundleFhirLibraryContentProvider(org.opencds.cqf.cql.evaluator.cql2elm.content.fhir.BundleFhirLibraryContentProvider) Bundle(org.hl7.fhir.r4.model.Bundle) JpaLibraryContentProvider(org.opencds.cqf.ruler.cql.JpaLibraryContentProvider) ArrayList(java.util.ArrayList) Library(org.hl7.fhir.r4.model.Library)

Example 20 with Library

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

the class DataOperationsProvider method visitLibrary.

private void visitLibrary(Library library, List<Library> queue, Map<String, Library> resources, RequestDetails theRequestDetails) {
    for (RelatedArtifact relatedArtifact : library.getRelatedArtifact()) {
        if (relatedArtifact.getType().equals(RelatedArtifact.RelatedArtifactType.DEPENDSON) && relatedArtifact.hasResource()) {
            // FHIR R4+, resource is defined as a canonical
            String resourceString = relatedArtifact.getResource();
            CanonicalParts parts = Canonicals.getParts(resourceString);
            if (parts.resourceType().equals("Library")) {
                Library lib = search(Library.class, Searches.byCanonical(resourceString), theRequestDetails).firstOrNull();
                if (lib != null) {
                    resources.putIfAbsent(lib.getId(), lib);
                    queue.add(lib);
                }
            }
        }
    }
}
Also used : Library(org.hl7.fhir.r4.model.Library) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) CanonicalParts(org.opencds.cqf.ruler.utility.CanonicalParts)

Aggregations

Library (org.hl7.fhir.r4.model.Library)130 Test (org.junit.Test)85 Measure (org.hl7.fhir.r4.model.Measure)60 Patient (org.hl7.fhir.r4.model.Patient)41 HashMap (java.util.HashMap)36 Test (org.junit.jupiter.api.Test)34 ArrayList (java.util.ArrayList)32 Library (org.hl7.fhir.dstu3.model.Library)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)21 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)21 StringType (org.hl7.fhir.r4.model.StringType)21 IOException (java.io.IOException)20 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)20 FhirContext (ca.uhn.fhir.context.FhirContext)19 IParser (ca.uhn.fhir.parser.IParser)19 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)19 Bundle (org.hl7.fhir.r4.model.Bundle)19 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)18