use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngine method processValues.
private void processValues(Resource context, Selection sel, Property prop, ObjectValue target, List<Base> values, boolean extensionMode, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
boolean il = false;
Argument arg = null;
ExpressionNode expression = null;
if (sel.getField().hasDirective("slice")) {
Directive dir = sel.getField().directive("slice");
String s = ((StringValue) dir.getArguments().get(0).getValues().get(0)).getValue();
if (s.equals("$index"))
expression = magicExpression;
else
expression = fpe.parse(s);
}
if (// special: instruction to drop this node...
sel.getField().hasDirective("flatten"))
il = prop.isList() && !sel.getField().hasDirective("first");
else if (sel.getField().hasDirective("first")) {
if (expression != null)
throw new FHIRException("You cannot mix @slice and @first");
arg = target.addField(sel.getField().getAlias() + suffix, listStatus(sel.getField(), inheritedList));
} else if (expression == null)
arg = target.addField(sel.getField().getAlias() + suffix, listStatus(sel.getField(), prop.isList() || inheritedList));
int index = 0;
for (Base value : values) {
String ss = "";
if (expression != null) {
if (expression == magicExpression)
ss = suffix + '.' + Integer.toString(index);
else
ss = suffix + '.' + fpe.evaluateToString(null, null, null, value, expression);
if (!sel.getField().hasDirective("flatten"))
arg = target.addField(sel.getField().getAlias() + suffix, listStatus(sel.getField(), prop.isList() || inheritedList));
}
if (value.isPrimitive() && !extensionMode) {
if (!sel.getField().getSelectionSet().isEmpty())
throw new EGraphQLException("Encountered a selection set on a scalar field type");
processPrimitive(arg, value);
} else {
if (sel.getField().getSelectionSet().isEmpty())
throw new EGraphQLException("No Fields selected on a complex object");
if (arg == null)
processObject(context, value, target, sel.getField().getSelectionSet(), il, ss);
else {
ObjectValue n = new ObjectValue();
arg.addValue(n);
processObject(context, value, n, sel.getField().getSelectionSet(), il, ss);
}
}
if (sel.getField().hasDirective("first"))
return;
index++;
}
}
use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngine method processCanonicalReference.
private void processCanonicalReference(Resource context, Base source, Field field, ObjectValue target, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
if (!(source instanceof CanonicalType))
throw new EGraphQLException("Not done yet");
if (services == null)
throw new EGraphQLException("Resource Referencing services not provided");
Reference ref = new Reference(source.primitiveValue());
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 processPrimitive.
private void processPrimitive(Argument arg, Base value) {
String s = value.fhirType();
if (s.equals("integer") || s.equals("decimal") || s.equals("unsignedInt") || s.equals("positiveInt"))
arg.addValue(new NumberValue(value.primitiveValue()));
else if (s.equals("boolean"))
arg.addValue(new NameValue(value.primitiveValue()));
else
arg.addValue(new StringValue(value.primitiveValue()));
}
use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngine method processSearchSimple.
private void processSearchSimple(ObjectValue target, Field field, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
if (services == null)
throw new EGraphQLException("Resource Referencing services not provided");
List<IBaseResource> list = new ArrayList<>();
services.listResources(appInfo, field.getName().substring(0, field.getName().length() - 4), field.getArguments(), list);
Argument 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);
}
}
}
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());
}
Aggregations