use of org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent in project kindling by HL7.
the class DictHTMLGenerator method describeTypes.
private String describeTypes(List<TypeRefComponent> types) throws Exception {
if (types.isEmpty())
return "";
StringBuilder b = new StringBuilder();
if (types.size() == 1)
describeType(b, types.get(0));
else {
boolean first = true;
b.append("Choice of: ");
for (TypeRefComponent t : types) {
if (first)
first = false;
else
b.append(", ");
describeType(b, t);
}
}
return b.toString();
}
use of org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent in project org.hl7.fhir.core by hapifhir.
the class SpecDifferenceEvaluator method analyseTypes.
private void analyseTypes(JsonObject element, ElementDefinition rev, ElementDefinition orig) {
JsonArray oa = new JsonArray();
JsonArray ra = new JsonArray();
if (rev.getType().size() == 1 && orig.getType().size() == 1) {
String r = describeType(rev.getType().get(0));
if (Utilities.noString(r) && Utilities.existsInList(rev.getId(), "Element.id", "Extension.url"))
r = "string";
String o = describeType(orig.getType().get(0));
if (Utilities.noString(o) && Utilities.existsInList(orig.getId(), "Element.id", "Extension.url"))
o = "string";
if (!o.equals(r)) {
oa.add(new JsonPrimitive(o));
ra.add(new JsonPrimitive(r));
}
} else {
for (TypeRefComponent tr : orig.getType()) {
if (!hasType(rev.getType(), tr))
oa.add(new JsonPrimitive(describeType(tr)));
}
for (TypeRefComponent tr : rev.getType()) {
if (!hasType(orig.getType(), tr) && !isAbstractType(tr.getWorkingCode()))
ra.add(new JsonPrimitive(describeType(tr)));
}
for (TypeRefComponent tr : rev.getType()) {
TypeRefComponent tm = getType(rev.getType(), tr);
if (tm != null) {
compareParameters(element, tr, tm);
}
}
}
if (oa.size() > 0)
element.add("removed-types", oa);
if (ra.size() > 0)
element.add("added-types", ra);
}
use of org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent in project org.hl7.fhir.core by hapifhir.
the class SpecDifferenceEvaluator method hasType.
private boolean hasType(List<TypeRefComponent> types, TypeRefComponent tr) {
for (TypeRefComponent t : types) {
if (t.getWorkingCode().equals(tr.getWorkingCode())) {
if ((!t.hasProfile() && !tr.hasProfile())) {
return true;
}
boolean found = true;
for (CanonicalType t1 : tr.getProfile()) {
boolean ok = false;
for (CanonicalType t2 : t.getProfile()) {
ok = ok || t2.getValue().equals(t1.getValue());
}
found = found && ok;
}
return found;
}
}
return false;
}
use of org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent in project org.hl7.fhir.core by hapifhir.
the class DefinitionNavigator method loadTypedChildren.
private void loadTypedChildren(TypeRefComponent type) throws DefinitionException {
typeOfChildren = null;
StructureDefinition sd = context.fetchResource(StructureDefinition.class, type.hasProfile() ? type.getProfile().get(0).getValue() : type.getCode());
if (sd != null) {
DefinitionNavigator dn = new DefinitionNavigator(context, sd, 0, path, names, sd.getConstrainedType());
typeChildren = dn.children();
} else
throw new DefinitionException("Unable to find definition for " + type.getCode() + (type.hasProfile() ? "(" + type.getProfile() + ")" : ""));
typeOfChildren = type;
}
use of org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent 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());
}
}
}
}
}
Aggregations