use of org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkTargetComponent in project org.hl7.fhir.core by hapifhir.
the class GraphDefinitionEngine method processLinkPath.
private void processLinkPath(String focusPath, Resource focus, GraphDefinitionLinkComponent link, int depth) {
String path = focusPath + " -> " + link.getPath();
check(link.hasPath(), "Path is needed at " + path);
check(!link.hasSliceName(), "SliceName is not yet supported at " + path);
ExpressionNode node;
if (link.getPathElement().hasUserData(TAG_NAME)) {
node = (ExpressionNode) link.getPathElement().getUserData(TAG_NAME);
} else {
node = engine.parse(link.getPath());
link.getPathElement().setUserData(TAG_NAME, node);
}
List<Base> matches = engine.evaluate(null, focus, focus, focus, node);
check(!validating || matches.size() >= (link.hasMin() ? link.getMin() : 0), "Link at path " + path + " requires at least " + link.getMin() + " matches, but only found " + matches.size());
check(!validating || matches.size() <= (link.hasMax() ? Integer.parseInt(link.getMax()) : Integer.MAX_VALUE), "Link at path " + path + " requires at most " + link.getMax() + " matches, but found " + matches.size());
for (Base sel : matches) {
// todo: should a URL be ok?
check(sel.fhirType().equals("Reference"), "Selected node from an expression must be a Reference");
ReferenceResolution res = services.lookup(appInfo, focus, (Reference) sel);
if (res != null) {
// todo
check(res.getTargetContext() != focus, "how to handle contained resources is not yet resolved");
for (GraphDefinitionLinkTargetComponent tl : link.getTarget()) {
if (tl.getType().equals(res.getTarget().fhirType())) {
Resource r = (Resource) res.getTarget();
if (!isInBundle(r)) {
addToBundle(r);
for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
processLink(focus.fhirType(), r, l, depth + 1);
}
}
}
}
}
}
}
use of org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkTargetComponent in project org.hl7.fhir.core by hapifhir.
the class GraphDefinitionEngine method processLinkPath.
private void processLinkPath(String focusPath, Resource focus, GraphDefinitionLinkComponent link, int depth) {
String path = focusPath + " -> " + link.getPath();
check(link.hasPath(), "Path is needed at " + path);
check(!link.hasSliceName(), "SliceName is not yet supported at " + path);
ExpressionNode node;
if (link.getPathElement().hasUserData(TAG_NAME)) {
node = (ExpressionNode) link.getPathElement().getUserData(TAG_NAME);
} else {
node = engine.parse(link.getPath());
link.getPathElement().setUserData(TAG_NAME, node);
}
List<Base> matches = engine.evaluate(null, focus, focus, focus, node);
check(!validating || matches.size() >= (link.hasMin() ? link.getMin() : 0), "Link at path " + path + " requires at least " + link.getMin() + " matches, but only found " + matches.size());
check(!validating || matches.size() <= (link.hasMax() ? Integer.parseInt(link.getMax()) : Integer.MAX_VALUE), "Link at path " + path + " requires at most " + link.getMax() + " matches, but found " + matches.size());
for (Base sel : matches) {
// todo: should a URL be ok?
check(sel.fhirType().equals("Reference"), "Selected node from an expression must be a Reference");
ReferenceResolution res = services.lookup(appInfo, focus, (Reference) sel);
if (res != null) {
// todo
check(res.getTargetContext() != focus, "how to handle contained resources is not yet resolved");
for (GraphDefinitionLinkTargetComponent tl : link.getTarget()) {
if (tl.getType().equals(res.getTarget().fhirType())) {
Resource r = (Resource) res.getTarget();
if (!isInBundle(r)) {
addToBundle(r);
for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
processLink(focus.fhirType(), r, l, depth + 1);
}
}
}
}
}
}
}
Aggregations