Search in sources :

Example 21 with Library

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

the class DataOperationsProvider method dataRequirements.

@Operation(name = "$data-requirements", idempotent = true, type = Measure.class)
public Library dataRequirements(@IdParam IdType theId, @OperationParam(name = "startPeriod") String startPeriod, @OperationParam(name = "endPeriod") String endPeriod, RequestDetails theRequestDetails) throws InternalErrorException, FHIRException {
    Measure measure = read(theId, theRequestDetails);
    Library library = getLibraryFromMeasure(measure, theRequestDetails);
    if (library == null) {
        throw new RuntimeException("Could not load measure library.");
    }
    // TODO: Pass startPeriod and endPeriod as parameters to the data requirements operation
    return processDataRequirements(measure, library, theRequestDetails);
}
Also used : Measure(org.hl7.fhir.dstu3.model.Measure) Library(org.hl7.fhir.dstu3.model.Library) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 22 with Library

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

the class DataOperationsProvider method getLibraryFromMeasure.

public Library getLibraryFromMeasure(Measure measure, RequestDetails theRequestDetails) {
    Iterator<Reference> var6 = measure.getLibrary().iterator();
    String libraryIdOrCanonical = null;
    // use the first library
    while (var6.hasNext() && libraryIdOrCanonical == null) {
        Reference ref = var6.next();
        if (ref != null) {
            libraryIdOrCanonical = ref.getReference();
        }
    }
    Library library = read(new IdType(libraryIdOrCanonical), theRequestDetails);
    if (library == null) {
        library = search(Library.class, Searches.byCanonical(libraryIdOrCanonical), theRequestDetails).firstOrNull();
    }
    return library;
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) Library(org.hl7.fhir.dstu3.model.Library) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 23 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 = Lists.newArrayList(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.dstu3.model.Bundle) JpaLibraryContentProvider(org.opencds.cqf.ruler.cql.JpaLibraryContentProvider) Library(org.hl7.fhir.dstu3.model.Library)

Example 24 with Library

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

the class DataOperationsProvider method fetchDependencyLibraries.

private List<Library> fetchDependencyLibraries(Library library, RequestDetails theRequestDetails) {
    Map<String, Library> resources = new HashMap<>();
    List<Library> queue = new ArrayList<>();
    queue.add(library);
    while (!queue.isEmpty()) {
        Library current = queue.get(0);
        queue.remove(0);
        visitLibrary(current, queue, resources, theRequestDetails);
    }
    return new ArrayList<>(resources.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Library(org.hl7.fhir.dstu3.model.Library)

Example 25 with Library

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

the class Session method resolveCdsHooksPlanDefinition.

// For library use
public CarePlan resolveCdsHooksPlanDefinition(RequestDetails theRequest, Context context, PlanDefinition planDefinition, String patientId) {
    CarePlanBuilder carePlanBuilder = new CarePlanBuilder();
    RequestGroupBuilder requestGroupBuilder = new RequestGroupBuilder().buildStatus().buildIntent();
    // links
    if (planDefinition.hasRelatedArtifact()) {
        List<Extension> extensions = new ArrayList<>();
        for (RelatedArtifact relatedArtifact : planDefinition.getRelatedArtifact()) {
            AttachmentBuilder attachmentBuilder = new AttachmentBuilder();
            ExtensionBuilder extensionBuilder = new ExtensionBuilder();
            if (relatedArtifact.hasDisplay()) {
                // label
                attachmentBuilder.buildTitle(relatedArtifact.getDisplay());
            }
            if (relatedArtifact.hasUrl()) {
                // url
                attachmentBuilder.buildUrl(relatedArtifact.getUrl());
            }
            if (relatedArtifact.hasExtension()) {
                // type
                attachmentBuilder.buildExtension(relatedArtifact.getExtension());
            }
            extensionBuilder.buildUrl("http://example.org");
            extensionBuilder.buildValue(attachmentBuilder.build());
            extensions.add(extensionBuilder.build());
        }
        requestGroupBuilder.buildExtension(extensions);
    }
    resolveActions(theRequest, planDefinition, planDefinition.getAction(), context, patientId, requestGroupBuilder, new ArrayList<>());
    CarePlanActivityBuilder carePlanActivityBuilder = new CarePlanActivityBuilder();
    carePlanActivityBuilder.buildReferenceTarget(requestGroupBuilder.build());
    carePlanBuilder.buildActivity(carePlanActivityBuilder.build());
    return carePlanBuilder.build();
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) AttachmentBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.AttachmentBuilder) CarePlanBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.CarePlanBuilder) RequestGroupBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.RequestGroupBuilder) ArrayList(java.util.ArrayList) ExtensionBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.ExtensionBuilder) RelatedArtifact(org.hl7.fhir.dstu3.model.RelatedArtifact) CarePlanActivityBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.CarePlanActivityBuilder)

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