use of org.hl7.fhir.r4b.model.TypeDetails in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method getChildTypesByName.
private void getChildTypesByName(String type, String name, TypeDetails result) throws PathEngineException, DefinitionException {
if (Utilities.noString(type))
throw new PathEngineException("No type provided in BuildToolPathEvaluator.getChildTypesByName");
if (type.equals("xhtml"))
return;
String url = null;
if (type.contains(".")) {
url = "http://hl7.org/fhir/StructureDefinition/" + type.substring(0, type.indexOf("."));
} else {
url = "http://hl7.org/fhir/StructureDefinition/" + type;
}
String tail = "";
StructureDefinition sd = worker.fetchResource(StructureDefinition.class, url);
if (sd == null)
// this really is an error, because we can only get to here if the internal infrastrucgture is wrong
throw new DefinitionException("Unknown type " + type);
List<StructureDefinition> sdl = new ArrayList<StructureDefinition>();
ElementDefinitionMatch m = null;
if (type.contains("."))
m = getElementDefinition(sd, type, false);
if (m != null && hasDataType(m.definition)) {
if (m.fixedType != null) {
StructureDefinition dt = worker.fetchTypeDefinition(m.fixedType);
if (dt == null)
throw new DefinitionException("unknown data type " + m.fixedType);
sdl.add(dt);
} else
for (TypeRefComponent t : m.definition.getType()) {
StructureDefinition dt = worker.fetchTypeDefinition(t.getCode());
if (dt == null)
throw new DefinitionException("unknown data type " + t.getCode());
sdl.add(dt);
}
} else {
sdl.add(sd);
if (type.contains("."))
tail = type.substring(type.indexOf("."));
}
for (StructureDefinition sdi : sdl) {
String path = sdi.getSnapshot().getElement().get(0).getPath() + tail + ".";
if (name.equals("**")) {
assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
if (ed.getPath().startsWith(path))
for (TypeRefComponent t : ed.getType()) {
if (t.hasCode() && t.getCodeElement().hasValue()) {
String tn = null;
if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
tn = ed.getPath();
else
tn = t.getCode();
if (t.getCode().equals("Resource")) {
for (String rn : worker.getResourceNames()) {
if (!result.hasType(worker, rn)) {
result.addType(rn);
getChildTypesByName(rn, "**", result);
}
}
} else if (!result.hasType(worker, tn)) {
result.addType(tn);
getChildTypesByName(tn, "**", result);
}
}
}
}
} else if (name.equals("*")) {
assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
if (ed.getPath().startsWith(path) && !ed.getPath().substring(path.length()).contains("."))
for (TypeRefComponent t : ed.getType()) {
if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
result.addType(ed.getPath());
else if (t.getCode().equals("Resource"))
result.addTypes(worker.getResourceNames());
else
result.addType(t.getCode());
}
}
} else {
path = sdi.getSnapshot().getElement().get(0).getPath() + tail + "." + name;
ElementDefinitionMatch ed = getElementDefinition(sdi, path, false);
if (ed != null) {
if (!Utilities.noString(ed.getFixedType()))
result.addType(ed.getFixedType());
else
for (TypeRefComponent t : ed.getDefinition().getType()) {
if (Utilities.noString(t.getCode()))
// throw new PathEngineException("Illegal reference to primitive value attribute @ "+path);
break;
if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
result.addType(path);
else if (t.getCode().equals("Resource"))
result.addTypes(worker.getResourceNames());
else
result.addType(t.getCode());
}
}
}
}
}
use of org.hl7.fhir.r4b.model.TypeDetails in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method executeType.
private TypeDetails executeType(ExecutionTypeContext context, TypeDetails focus, ExpressionNode exp, boolean atEntry) throws PathEngineException, DefinitionException {
// System.out.println("Evaluate {'"+exp.toString()+"'} on "+focus.toString());
TypeDetails result = new TypeDetails(null);
switch(exp.getKind()) {
case Name:
if (atEntry && exp.getName().equals("$this"))
result.update(context.getThisItem());
else {
for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry));
}
if (result.hasNoTypes())
throw new PathEngineException("The name " + exp.getName() + " is not valid for any of the possible types: " + focus.describe());
}
break;
case Function:
result.update(evaluateFunctionType(context, focus, exp));
break;
case Constant:
result.addType(readConstantType(context, exp.getConstant()));
break;
case Group:
result.update(executeType(context, focus, exp.getGroup(), atEntry));
}
exp.setTypes(result);
if (exp.getInner() != null) {
result = executeType(context, result, exp.getInner(), false);
}
if (exp.isProximal() && exp.getOperation() != null) {
ExpressionNode next = exp.getOpNext();
ExpressionNode last = exp;
while (next != null) {
TypeDetails work;
if (last.getOperation() == Operation.Is || last.getOperation() == Operation.As)
work = executeTypeName(context, focus, next, atEntry);
else
work = executeType(context, focus, next, atEntry);
result = operateTypes(result, last.getOperation(), work);
last = next;
next = next.getOpNext();
}
exp.setOpTypes(result);
}
return result;
}
use of org.hl7.fhir.r4b.model.TypeDetails in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method checkParamTypes.
private void checkParamTypes(String funcName, List<TypeDetails> paramTypes, TypeDetails... typeSet) throws PathEngineException {
int i = 0;
for (TypeDetails pt : typeSet) {
if (i == paramTypes.size())
return;
TypeDetails actual = paramTypes.get(i);
i++;
for (String a : actual.getTypes()) {
if (!pt.hasType(a))
throw new PathEngineException("The parameter type '" + a + "' is not legal for " + funcName + " parameter " + Integer.toString(i) + ". expecting " + pt.toString());
}
}
}
use of org.hl7.fhir.r4b.model.TypeDetails in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method executeType.
private TypeDetails executeType(ExecutionTypeContext context, TypeDetails focus, ExpressionNode exp, boolean atEntry) throws PathEngineException, DefinitionException {
TypeDetails result = new TypeDetails(null);
switch(exp.getKind()) {
case Name:
if (atEntry && exp.getName().equals("$this"))
result.update(context.getContext());
else {
for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry));
}
if (result.hasNoTypes())
throw new PathEngineException("The name " + exp.getName() + " is not valid for any of the possible types: " + focus.describe());
}
break;
case Function:
result.update(evaluateFunctionType(context, focus, exp));
break;
case Constant:
result.addType(readConstantType(context, exp.getConstant()));
break;
case Group:
result.update(executeType(context, focus, exp.getGroup(), atEntry));
}
exp.setTypes(result);
if (exp.getInner() != null) {
result = executeType(context, result, exp.getInner(), false);
}
if (exp.isProximal() && exp.getOperation() != null) {
ExpressionNode next = exp.getOpNext();
ExpressionNode last = exp;
while (next != null) {
TypeDetails work;
if (last.getOperation() == Operation.Is || last.getOperation() == Operation.As)
work = executeTypeName(context, focus, next, atEntry);
else
work = executeType(context, focus, next, atEntry);
result = operateTypes(result, last.getOperation(), work);
last = next;
next = next.getOpNext();
}
exp.setOpTypes(result);
}
return result;
}
use of org.hl7.fhir.r4b.model.TypeDetails in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseTransform.
private TypeDetails analyseTransform(TransformContext context, StructureMap map, StructureMapGroupRuleTargetComponent tgt, VariableForProfiling var, VariablesForProfiling vars) throws FHIRException {
switch(tgt.getTransform()) {
case CREATE:
String p = getParamString(vars, tgt.getParameter().get(0));
return new TypeDetails(CollectionStatus.SINGLETON, p);
case COPY:
return getParam(vars, tgt.getParameter().get(0));
case EVALUATE:
ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
if (expr == null) {
expr = fpe.parse(getParamString(vars, tgt.getParameter().get(tgt.getParameter().size() - 1)));
tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
}
return fpe.check(vars, null, expr);
// // throw new Error("Transform "+tgt.getTransform().toCode()+" not supported yet");
case TRANSLATE:
return new TypeDetails(CollectionStatus.SINGLETON, "CodeableConcept");
case CC:
ProfiledType res = new ProfiledType("CodeableConcept");
if (tgt.getParameter().size() >= 2 && isParamId(vars, tgt.getParameter().get(1))) {
TypeDetails td = vars.get(null, getParamId(vars, tgt.getParameter().get(1))).property.types;
if (td != null && td.hasBinding())
// todo: do we need to check that there's no implicit translation her? I don't think we do...
res.addBinding(td.getBinding());
}
return new TypeDetails(CollectionStatus.SINGLETON, res);
case C:
return new TypeDetails(CollectionStatus.SINGLETON, "Coding");
case QTY:
return new TypeDetails(CollectionStatus.SINGLETON, "Quantity");
case REFERENCE:
VariableForProfiling vrs = vars.get(VariableMode.OUTPUT, getParamId(vars, tgt.getParameterFirstRep()));
if (vrs == null)
throw new FHIRException("Unable to resolve variable \"" + getParamId(vars, tgt.getParameterFirstRep()) + "\"");
String profile = vrs.property.getProfileProperty().getStructure().getUrl();
TypeDetails td = new TypeDetails(CollectionStatus.SINGLETON);
td.addType("Reference", profile);
return td;
// // throw new FHIRException("Transform engine cannot point at an element of type "+b.fhirType());
default:
throw new Error("Transform Unknown or not handled yet: " + tgt.getTransform().toCode());
}
}
Aggregations