use of org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent 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);
}
}
}
}
Aggregations