use of org.hl7.fhir.r4b.model.TypeDetails in project org.hl7.fhir.core by hapifhir.
the class Property method getChildProperties.
protected List<Property> getChildProperties(TypeDetails type) throws DefinitionException {
ElementDefinition ed = definition;
StructureDefinition sd = structure;
List<ElementDefinition> children = profileUtilities.getChildMap(sd, ed);
if (children.isEmpty()) {
// ok, find the right definitions
String t = null;
if (ed.getType().size() == 1)
t = ed.getType().get(0).getCode();
else if (ed.getType().size() == 0)
throw new Error("types == 0, and no children found");
else {
t = ed.getType().get(0).getCode();
boolean all = true;
for (TypeRefComponent tr : ed.getType()) {
if (!tr.getCode().equals(t)) {
all = false;
break;
}
}
if (!all) {
// ok, it's polymorphic
t = type.getType();
}
}
if (!"xhtml".equals(t)) {
sd = context.fetchResource(StructureDefinition.class, t);
if (sd == null)
throw new DefinitionException("Unable to find class '" + t + "' for name '" + ed.getPath() + "' on property " + definition.getPath());
children = profileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));
}
}
List<Property> properties = new ArrayList<Property>();
for (ElementDefinition child : children) {
properties.add(new Property(context, child, sd, this.profileUtilities));
}
return properties;
}
use of org.hl7.fhir.r4b.model.TypeDetails in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method checkParamTypes.
private void checkParamTypes(ExpressionNode expr, 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(worker, a)) {
throw makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, funcName, i, a, 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(String type, ExpressionNode exp, boolean atEntry) throws PathEngineException, DefinitionException {
if (atEntry && Character.isUpperCase(exp.getName().charAt(0)) && hashTail(type).equals(exp.getName())) {
// special case for start up
return new TypeDetails(CollectionStatus.SINGLETON, type);
}
TypeDetails result = new TypeDetails(null);
getChildTypesByName(type, exp.getName(), result, exp);
return result;
}
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, ExpressionNode expr) throws PathEngineException, DefinitionException {
if (Utilities.noString(type)) {
throw makeException(expr, I18nConstants.FHIRPATH_NO_TYPE, "", "getChildTypesByName");
}
if (type.equals("http://hl7.org/fhir/StructureDefinition/xhtml")) {
return;
}
if (type.startsWith(Constants.NS_SYSTEM_TYPE)) {
return;
}
if (type.equals(TypeDetails.FP_SimpleTypeInfo)) {
getSimpleTypeChildTypesByName(name, result);
} else if (type.equals(TypeDetails.FP_ClassInfo)) {
getClassInfoChildTypesByName(name, result);
} else {
String url = null;
if (type.contains("#")) {
url = type.substring(0, type.indexOf("#"));
} else {
url = type;
}
String tail = "";
StructureDefinition sd = worker.fetchResource(StructureDefinition.class, url);
if (sd == null) {
throw makeException(expr, I18nConstants.FHIRPATH_NO_TYPE, url, "getChildTypesByName");
}
List<StructureDefinition> sdl = new ArrayList<StructureDefinition>();
ElementDefinitionMatch m = null;
if (type.contains("#"))
m = getElementDefinition(sd, type.substring(type.indexOf("#") + 1), false, expr);
if (m != null && hasDataType(m.definition)) {
if (m.fixedType != null) {
StructureDefinition dt = worker.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(m.fixedType, worker.getOverrideVersionNs()));
if (dt == null) {
throw makeException(expr, I18nConstants.FHIRPATH_NO_TYPE, ProfileUtilities.sdNs(m.fixedType, worker.getOverrideVersionNs()), "getChildTypesByName");
}
sdl.add(dt);
} else
for (TypeRefComponent t : m.definition.getType()) {
StructureDefinition dt = worker.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(t.getCode(), worker.getOverrideVersionNs()));
if (dt == null) {
throw makeException(expr, I18nConstants.FHIRPATH_NO_TYPE, ProfileUtilities.sdNs(t.getCode(), worker.getOverrideVersionNs()), "getChildTypesByName");
}
sdl.add(dt);
}
} else {
sdl.add(sd);
if (type.contains("#")) {
tail = type.substring(type.indexOf("#") + 1);
tail = tail.substring(tail.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 = sdi.getType() + "#" + ed.getPath();
} else {
tn = t.getCode();
}
if (t.getCode().equals("Resource")) {
for (String rn : worker.getResourceNames()) {
if (!result.hasType(worker, rn)) {
getChildTypesByName(result.addType(rn), "**", result, expr);
}
}
} else if (!result.hasType(worker, tn)) {
getChildTypesByName(result.addType(tn), "**", result, expr);
}
}
}
}
} 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 (Utilities.noString(t.getCode())) {
// Element.id or Extension.url
result.addType("System.string");
} else if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement")) {
result.addType(sdi.getType() + "#" + 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, isAllowPolymorphicNames(), expr);
if (ed != null) {
if (!Utilities.noString(ed.getFixedType()))
result.addType(ed.getFixedType());
else {
for (TypeRefComponent t : ed.getDefinition().getType()) {
if (Utilities.noString(t.getCode())) {
if (Utilities.existsInList(ed.getDefinition().getId(), "Element.id", "Extension.url") || Utilities.existsInList(ed.getDefinition().getBase().getPath(), "Resource.id", "Element.id", "Extension.url")) {
result.addType(TypeDetails.FP_NS, "string");
}
// throw new PathEngineException("Illegal reference to primitive value attribute @ "+path);
break;
}
ProfiledType pt = null;
if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement")) {
pt = new ProfiledType(sdi.getUrl() + "#" + path);
} else if (t.getCode().equals("Resource")) {
result.addTypes(worker.getResourceNames());
} else {
pt = new ProfiledType(t.getCode());
}
if (pt != null) {
if (t.hasProfile()) {
pt.addProfiles(t.getProfile());
}
if (ed.getDefinition().hasBinding()) {
pt.addBinding(ed.getDefinition().getBinding());
}
result.addType(pt);
}
}
}
}
}
}
}
}
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.getThisItem());
} else if (atEntry && exp.getName().equals("$total")) {
result.update(anything(CollectionStatus.UNORDERED));
} else if (atEntry && exp.getName().equals("$index")) {
result.addType(TypeDetails.FP_Integer);
} else if (atEntry && focus == null) {
result.update(executeContextType(context, exp.getName(), exp));
} else {
for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry));
}
if (result.hasNoTypes()) {
throw makeException(exp, I18nConstants.FHIRPATH_UNKNOWN_NAME, exp.getName(), focus.describe());
}
}
break;
case Function:
result.update(evaluateFunctionType(context, focus, exp));
break;
case Unary:
result.addType(TypeDetails.FP_Integer);
result.addType(TypeDetails.FP_Decimal);
result.addType(TypeDetails.FP_Quantity);
break;
case Constant:
result.update(resolveConstantType(context, exp.getConstant(), exp));
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);
last = next;
next = next.getOpNext();
}
exp.setOpTypes(result);
}
return result;
}
Aggregations