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;
}
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);
}
}
}
}
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");
}
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());
}
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);
}
Aggregations