Search in sources :

Example 1 with Argument

use of org.hl7.fhir.utilities.graphql.Argument in project quality-measure-and-cohort-service by Alvearie.

the class SparkCqlEvaluator method getFilteredRequests.

/**
 * @param requests     Request object to filter.
 * @param libraries    Map of library id to version used for filtering
 *                     down request based on library id. If this argument
 *                     is null or empty, then no library id filtering
 *                     is performed.
 * @param expressions  Used to optionally override which expressions will
 *                     run for each individual CqlEvaluationRequest. If this
 *                     argument is null or empty, no expressions are overwritten.
 *
 * @return CqlEvaluationRequests with the original requests optionally filtered
 *         based on the library ids the.
 *         Requests will optionally have their expressions overridden
 *         by args.expressions. if any are provided.
 *         Individual requests will also will also have any global
 *         parameters set on each individual CqlEvaluationRequest.
 */
protected CqlEvaluationRequests getFilteredRequests(CqlEvaluationRequests requests, Map<String, String> libraries, Collection<String> expressions) {
    if (requests != null) {
        List<CqlEvaluationRequest> evaluations = requests.getEvaluations();
        if (libraries != null && !libraries.isEmpty()) {
            evaluations = evaluations.stream().filter(r -> libraries.keySet().contains(r.getDescriptor().getLibraryId())).collect(Collectors.toList());
        }
        if (expressions != null && !expressions.isEmpty()) {
            evaluations.forEach(x -> x.setExpressions(x.getExpressions().stream().filter(e -> expressions.contains(e.getName())).collect(Collectors.toSet())));
        }
        if (requests.getGlobalParameters() != null) {
            for (CqlEvaluationRequest evaluation : evaluations) {
                for (Map.Entry<String, Parameter> globalParameter : requests.getGlobalParameters().entrySet()) {
                    Map<String, Parameter> parameters = evaluation.getParameters();
                    if (parameters == null) {
                        evaluation.setParameters(new HashMap<>());
                        parameters = evaluation.getParameters();
                    }
                    parameters.putIfAbsent(globalParameter.getKey(), globalParameter.getValue());
                }
            }
        }
        requests.setEvaluations(evaluations);
        jobSpecification.set(requests);
    }
    return requests;
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) Arrays(java.util.Arrays) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) FileSystem(org.apache.hadoop.fs.FileSystem) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) EncodedParametersCache(com.ibm.cohort.cql.spark.util.EncodedParametersCache) DataRowDataProvider(com.ibm.cohort.datarow.engine.DataRowDataProvider) Format(com.ibm.cohort.cql.library.Format) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) ColumnRuleCreator(com.ibm.cohort.cql.spark.aggregation.ColumnRuleCreator) ConfigurableOutputColumnNameEncoder(com.ibm.cohort.cql.spark.data.ConfigurableOutputColumnNameEncoder) DefaultDatasetRetriever(com.ibm.cohort.cql.spark.data.DefaultDatasetRetriever) SparkSchemaCreator(com.ibm.cohort.cql.spark.data.SparkSchemaCreator) ContextDefinition(com.ibm.cohort.cql.spark.aggregation.ContextDefinition) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) ModelUtils(com.ibm.cohort.cql.spark.optimizer.ModelUtils) ConstraintViolation(javax.validation.ConstraintViolation) StructType(org.apache.spark.sql.types.StructType) HadoopPathOutputMetadataWriter(com.ibm.cohort.cql.spark.metadata.HadoopPathOutputMetadataWriter) Collection(java.util.Collection) Set(java.util.Set) Validator(javax.validation.Validator) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) Reader(java.io.Reader) Tuple2(scala.Tuple2) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) ContextRetriever(com.ibm.cohort.cql.spark.aggregation.ContextRetriever) List(java.util.List) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) QName(javax.xml.namespace.QName) SparkOutputColumnEncoder(com.ibm.cohort.cql.spark.data.SparkOutputColumnEncoder) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) MapUtils(com.ibm.cohort.cql.util.MapUtils) ExternalFunctionProvider(org.opencds.cqf.cql.engine.data.ExternalFunctionProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Dataset(org.apache.spark.sql.Dataset) SerializableConfiguration(org.apache.spark.util.SerializableConfiguration) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) SparkDataRow(com.ibm.cohort.cql.spark.data.SparkDataRow) PriorityCqlLibraryProvider(com.ibm.cohort.cql.library.PriorityCqlLibraryProvider) R4FileSystemFhirTerminologyProvider(com.ibm.cohort.cql.terminology.R4FileSystemFhirTerminologyProvider) HashMap(java.util.HashMap) ValidatorFactory(javax.validation.ValidatorFactory) HadoopBasedCqlLibraryProvider(com.ibm.cohort.cql.library.HadoopBasedCqlLibraryProvider) SparkTypeConverter(com.ibm.cohort.cql.spark.data.SparkTypeConverter) Function(java.util.function.Function) ArrayList(java.util.ArrayList) CustomMetricSparkPlugin(com.ibm.cohort.cql.spark.metrics.CustomMetricSparkPlugin) CollectionUtils(org.apache.commons.collections.CollectionUtils) EvaluationError(com.ibm.cohort.cql.spark.errors.EvaluationError) DataRowRetrieveProvider(com.ibm.cohort.datarow.engine.DataRowRetrieveProvider) Validation(javax.validation.Validation) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) NoSuchElementException(java.util.NoSuchElementException) EvaluationSummary(com.ibm.cohort.cql.spark.metadata.EvaluationSummary) DataRow(com.ibm.cohort.datarow.model.DataRow) SparkSession(org.apache.spark.sql.SparkSession) PrintStream(java.io.PrintStream) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) SaveMode(org.apache.spark.sql.SaveMode) Logger(org.slf4j.Logger) CqlDebug(com.ibm.cohort.cql.evaluation.CqlDebug) Iterator(java.util.Iterator) RowFactory(org.apache.spark.sql.RowFactory) JCommander(com.beust.jcommander.JCommander) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Row(org.apache.spark.sql.Row) CollectionAccumulator(org.apache.spark.util.CollectionAccumulator) InputStreamReader(java.io.InputStreamReader) JavaPairRDD(org.apache.spark.api.java.JavaPairRDD) LongAccumulator(org.apache.spark.util.LongAccumulator) CqlExpressionConfiguration(com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration) AnyColumnFunctions(com.ibm.cohort.cql.functions.AnyColumnFunctions) MDC(org.slf4j.MDC) UnsupportedTerminologyProvider(com.ibm.cohort.cql.terminology.UnsupportedTerminologyProvider) CohortExternalFunctionProvider(com.ibm.cohort.cql.functions.CohortExternalFunctionProvider) ContextDefinitions(com.ibm.cohort.cql.spark.aggregation.ContextDefinitions) Collections(java.util.Collections) OutputMetadataWriter(com.ibm.cohort.cql.spark.metadata.OutputMetadataWriter) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Argument

use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method processLinkTarget.

private void processLinkTarget(String focusPath, Resource focus, GraphDefinitionLinkComponent link, int depth) {
    check(link.getTarget().size() == 1, "If there is no path, there must be one and only one target at " + focusPath);
    check(link.getTarget().get(0).hasType(), "If there is no path, there must be type on the target at " + focusPath);
    check(link.getTarget().get(0).getParams().contains("{ref}"), "If there is no path, the target must have parameters that include a parameter using {ref} at " + focusPath);
    String path = focusPath + " -> " + link.getTarget().get(0).getType() + "?" + link.getTarget().get(0).getParams();
    List<IBaseResource> list = new ArrayList<>();
    List<Argument> params = new ArrayList<>();
    parseParams(params, link.getTarget().get(0).getParams(), focus);
    services.listResources(appInfo, link.getTarget().get(0).getType(), params, list);
    check(!validating || (list.size() >= (link.hasMin() ? link.getMin() : 0)), "Link at path " + path + " requires at least " + link.getMin() + " matches, but only found " + list.size());
    check(!validating || (list.size() <= (link.hasMax() && !link.getMax().equals("*") ? Integer.parseInt(link.getMax()) : Integer.MAX_VALUE)), "Link at path " + path + " requires at most " + link.getMax() + " matches, but found " + list.size());
    for (IBaseResource res : list) {
        Resource r = (Resource) res;
        if (!isInBundle(r)) {
            addToBundle(r);
            // Grahame Grieve 17-06-2020: this seems wrong to me - why restart?
            for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
                processLink(start.fhirType(), start, l, depth + 1);
            }
        }
    }
}
Also used : GraphDefinitionLinkComponent(org.hl7.fhir.r4b.model.GraphDefinition.GraphDefinitionLinkComponent) Argument(org.hl7.fhir.utilities.graphql.Argument) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.r4b.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 3 with Argument

use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method parseParams.

private void parseParams(List<Argument> params, String value, Resource res) {
    boolean refed = false;
    Map<String, List<String>> p = splitQuery(value);
    for (String n : p.keySet()) {
        for (String v : p.get(n)) {
            if (v.equals("{ref}")) {
                refed = true;
                v = res.fhirType() + '/' + res.getId();
            }
            params.add(new Argument(n, new StringValue(v)));
        }
    }
    check(refed, "no use of {ref} found");
}
Also used : Argument(org.hl7.fhir.utilities.graphql.Argument) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) StringValue(org.hl7.fhir.utilities.graphql.StringValue)

Example 4 with Argument

use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method processReference.

private void processReference(Resource context, Base source, Field field, ObjectValue target, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
    if (!(source instanceof Reference))
        throw new EGraphQLException("Not done yet");
    if (services == null)
        throw new EGraphQLException("Resource Referencing services not provided");
    Reference ref = (Reference) source;
    ReferenceResolution res = services.lookup(appInfo, context, ref);
    if (res != null) {
        if (targetTypeOk(field.getArguments(), res.getTarget())) {
            Argument arg = target.addField(field.getAlias() + suffix, listStatus(field, inheritedList));
            ObjectValue obj = new ObjectValue();
            arg.addValue(obj);
            processObject((Resource) res.getTargetContext(), (Base) res.getTarget(), obj, field.getSelectionSet(), inheritedList, suffix);
        }
    } else if (!hasArgument(field.getArguments(), "optional", "true"))
        throw new EGraphQLException("Unable to resolve reference to " + ref.getReference());
}
Also used : ReferenceResolution(org.hl7.fhir.utilities.graphql.IGraphQLStorageServices.ReferenceResolution)

Example 5 with Argument

use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method processSearchSingle.

private void processSearchSingle(ObjectValue target, Field field, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
    if (services == null)
        throw new EGraphQLException("Resource Referencing services not provided");
    String id = "";
    for (Argument arg : field.getArguments()) if ((arg.getName().equals("id")))
        id = getSingleValue(arg);
    else
        throw new EGraphQLException("Unknown/invalid parameter " + arg.getName());
    if (Utilities.noString(id))
        throw new EGraphQLException("No id found");
    Resource res = (Resource) services.lookup(appInfo, field.getName(), id);
    if (res == null)
        throw new EGraphQLException("Resource " + field.getName() + "/" + id + " not found");
    Argument arg = target.addField(field.getAlias() + suffix, listStatus(field, false));
    ObjectValue obj = new ObjectValue();
    arg.addValue(obj);
    processObject(res, res, obj, field.getSelectionSet(), inheritedList, suffix);
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Aggregations

Argument (org.hl7.fhir.utilities.graphql.Argument)24 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)22 ArrayList (java.util.ArrayList)21 EGraphQLException (org.hl7.fhir.utilities.graphql.EGraphQLException)20 ObjectValue (org.hl7.fhir.utilities.graphql.ObjectValue)20 StringValue (org.hl7.fhir.utilities.graphql.StringValue)16 FHIRException (org.hl7.fhir.exceptions.FHIRException)8 ReferenceResolution (org.hl7.fhir.utilities.graphql.IGraphQLStorageServices.ReferenceResolution)8 IOException (java.io.IOException)7 List (java.util.List)6 Resource (org.hl7.fhir.r4b.model.Resource)6 NameValue (org.hl7.fhir.utilities.graphql.NameValue)6 NumberValue (org.hl7.fhir.utilities.graphql.NumberValue)6 DomainResource (org.hl7.fhir.r4b.model.DomainResource)5 Nonnull (javax.annotation.Nonnull)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 Row (org.apache.spark.sql.Row)4 SAXException (org.xml.sax.SAXException)4 FhirPath (au.csiro.pathling.fhirpath.FhirPath)3 NonLiteralPath (au.csiro.pathling.fhirpath.NonLiteralPath)3