use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngine method resolveValues.
private List<Value> resolveValues(Argument arg, int max, String vars) throws EGraphQLException {
List<Value> result = new ArrayList<Value>();
for (Value v : arg.getValues()) {
if (!(v instanceof VariableValue))
result.add(v);
else {
if (vars.contains(":" + v.toString() + ":"))
throw new EGraphQLException("Recursive reference to variable " + v.toString());
Argument a = workingVariables.get(v.toString());
if (a == null)
throw new EGraphQLException("No value found for variable \"" + v.toString() + "\" in \"" + arg.getName() + "\"");
List<Value> vl = resolveValues(a, -1, vars + ":" + v.toString() + ":");
result.addAll(vl);
}
}
if ((max != -1 && result.size() > max))
throw new EGraphQLException("Only " + Integer.toString(max) + " values are allowed for \"" + arg.getName() + "\", but " + Integer.toString(result.size()) + " enoucntered");
return result;
}
use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngine method filterResources.
private List<Resource> filterResources(Argument fhirpath, List<IBaseResource> list) throws EGraphQLException, FHIRException {
List<Resource> result = new ArrayList<Resource>();
if (list.size() > 0) {
if ((fhirpath == null))
for (IBaseResource v : list) result.add((Resource) v);
else {
FHIRPathEngine fpe = new FHIRPathEngine(context);
ExpressionNode node = fpe.parse(getSingleValue(fhirpath));
for (IBaseResource v : list) if (fpe.evaluateToBoolean(null, (Resource) v, (Base) v, node))
result.add((Resource) v);
}
}
return result;
}
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 processReverseReferenceList.
private void processReverseReferenceList(Resource source, Field field, ObjectValue target, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
if (services == null)
throw new EGraphQLException("Resource Referencing services not provided");
List<IBaseResource> list = new ArrayList<>();
List<Argument> params = new ArrayList<>();
Argument parg = null;
for (Argument a : field.getArguments()) if (!(a.getName().equals("_reference")))
params.add(a);
else if ((parg == null))
parg = a;
else
throw new EGraphQLException("Duplicate parameter _reference");
if (parg == null)
throw new EGraphQLException("Missing parameter _reference");
Argument arg = new Argument();
params.add(arg);
arg.setName(getSingleValue(parg));
arg.addValue(new StringValue(source.fhirType() + "/" + source.getIdPart()));
services.listResources(appInfo, field.getName().substring(0, field.getName().length() - 4), params, list);
arg = null;
ObjectValue obj = null;
List<Resource> vl = filterResources(field.argument("fhirpath"), list);
if (!vl.isEmpty()) {
arg = target.addField(field.getAlias() + suffix, listStatus(field, true));
for (Resource v : vl) {
obj = new ObjectValue();
arg.addValue(obj);
processObject(v, v, obj, field.getSelectionSet(), inheritedList, suffix);
}
}
}
Aggregations