use of org.hl7.fhir.r4b.model.Extension in project kindling by HL7.
the class XmlSpecGenerator method generateInner.
private void generateInner(StructureDefinition sd) throws IOException, Exception {
ElementDefinition root = sd.getSnapshot().getElement().get(0);
write("<!-- " + Utilities.escapeXml(sd.getName()) + " -->");
write("<span style=\"float: right\"><a title=\"Documentation for this format\" href=\"" + prefix + "xml.html\"><img src=\"" + prefix + "help.png\" alt=\"doco\"/></a></span>\r\n");
String rn = sd.getSnapshot().getElement().get(0).getPath();
write("\r\n<");
if (defPage == null)
write("<span title=\"" + Utilities.escapeXml(root.getDefinition()) + "\"><b>");
else
write("<a href=\"" + (defPage + "#" + root.getSliceName()) + "\" title=\"" + Utilities.escapeXml(root.getDefinition()) + "\" class=\"dict\"><b>");
write(rn);
if ((defPage == null))
write("</b></span>");
else
write("</b></a>");
write(" xmlns=\"http://hl7.org/fhir\"\r\n>\r\n");
List<ElementDefinition> children = getChildren(sd.getSnapshot().getElement(), sd.getSnapshot().getElement().get(0));
boolean complex = isComplex(children);
if (!complex)
write(" <!-- from Element: <a href=\"" + prefix + "extensibility.html\">extension</a> -->\r\n");
for (ElementDefinition child : children) generateCoreElem(sd.getSnapshot().getElement(), child, 1, rn, false, complex);
write("</");
write(rn);
write(">\r\n");
}
use of org.hl7.fhir.r4b.model.Extension in project kindling by HL7.
the class XSDBaseGenerator method generateElement.
private void generateElement(ElementDefn root, ElementDefn e, String paramType, Map<String, String> rules) throws Exception {
List<TypeRef> types = e.getTypes();
if (types.size() > 1 || (types.size() == 1 && types.get(0).isWildcardType())) {
if (!e.getName().contains("[x]"))
throw new Exception("Element has multiple types as a choice doesn't have a [x] in the element name '" + e.getName() + "' in resource " + root.getName());
if ((types.size() == 1 && types.get(0).isWildcardType())) {
generateAny(root, e, e.getName().replace("[x]", ""), null);
} else {
String close = " minOccurs=\"0\">";
;
if (!forCodeGeneration) {
write(" <xs:choice minOccurs=\"" + checkRule(e.getMinCardinality().toString(), e.getName() + ".min", rules) + "\" maxOccurs=\"1\">\r\n");
if (e.hasDefinition()) {
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
}
close = "/>";
}
for (TypeRef t : types) {
String type = encodeType(e, t, true);
String name = e.getName().substring(0, e.getName().length() - 3) + nameForType(type);
write(" <xs:element name=\"" + name + "\" type=\"" + type + "\" ");
if (e.unbounded())
write(" maxOccurs=\"" + checkRule("unbounded", e.getName() + ".max", rules) + "\"" + close + "\r\n");
else
write(" maxOccurs=\"" + checkRule("1", e.getName() + ".max", rules) + "\"" + close + "\r\n");
if (forCodeGeneration) {
write(" <xs:annotation>\r\n");
if (e.hasDefinition()) {
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + " (choose any one of " + e.getName().replace("[x]", "") + "*, but only one)</xs:documentation>\r\n");
} else {
write(" <xs:documentation xml:lang=\"en\">(choose any one of " + e.getName().replace("[x]", "") + "*, but only one)</xs:documentation>\r\n");
}
write(" </xs:annotation>\r\n");
write(" </xs:element>\r\n");
}
}
if (!forCodeGeneration)
write(" </xs:choice>\r\n");
}
} else {
write(" ");
if ("extension".equals(e.getName()))
write("<xs:element name=\"" + e.getName() + "\" type=\"Extension\" ");
else if ("div".equals(e.getName()) && e.typeCode().equals("xhtml"))
write("<xs:element ref=\"xhtml:div\" ");
else if (e.usesCompositeType()) {
ElementDefn ref = root.getElementByName(definitions, e.typeCode().substring(1), true, false, null);
String rtn = this.types.get(ref);
if (rtn == null)
throw new Exception("logic error in schema generator (null composite reference in " + types.toString() + ")");
write("<xs:element name=\"" + e.getName() + "\" type=\"" + rtn + "\" ");
} else if (types.size() == 0 && e.getElements().size() > 0) {
String tn = root.getName() + "." + Utilities.capitalize(e.getName());
int i = 0;
while (typenames.contains(tn)) {
i++;
tn = root.getName() + "." + Utilities.capitalize(e.getName()) + Integer.toString(i);
}
write("<xs:element name=\"" + e.getName() + "\" type=\"" + tn + "\" ");
structures.put(tn, e);
this.types.put(e, tn);
typenames.add(tn);
} else if (types.size() == 1) {
if (types.get(0).isUnboundGenericParam() && paramType != null)
write("<xs:element name=\"" + e.getName() + "\" type=\"" + paramType + "\" ");
else if (!Utilities.noString(e.getRegex())) {
String tn = root.getName() + Utilities.capitalize(e.getName()) + "Type";
regexQueue.put(tn, e.getRegex());
write("<xs:element name=\"" + e.getName() + "\" type=\"" + tn + "\" ");
} else
write("<xs:element name=\"" + e.getName() + "\" type=\"" + encodeType(e, types.get(0), true) + "\" ");
} else
throw new Exception("how do we get here? " + e.getName() + " in " + root.getName() + " " + Integer.toString(types.size()));
write("minOccurs=\"" + checkRule(e.getMinCardinality().toString(), e.getName() + ".min", rules) + "\"");
if (e.unbounded())
write(" maxOccurs=\"" + checkRule("unbounded", e.getName() + ".max", rules) + "\"");
else
write(" maxOccurs=\"" + checkRule("1", e.getName() + ".max", rules) + "\"");
if (e.hasDefinition()) {
write(">\r\n");
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
write(" </xs:element>\r\n");
} else {
write("/>\r\n");
}
}
}
use of org.hl7.fhir.r4b.model.Extension in project kindling by HL7.
the class XVerPathsGenerator method execute.
public void execute() throws IOException {
// load the R4 content; can't be an extension if it already matches R4
loadR4();
// iterate all the elements, building a list
for (String s : sorted(definitions.getTypes().keySet())) {
ElementDefn ed = definitions.getTypes().get(s);
process(ed);
}
for (String s : sorted(definitions.getBaseResources().keySet())) {
ResourceDefn ed = definitions.getBaseResources().get(s);
process(ed.getRoot());
}
for (String s : sorted(definitions.getResources().keySet())) {
ResourceDefn ed = definitions.getResources().get(s);
process(ed.getRoot());
}
StringBuilder r5 = new StringBuilder();
r5.append("{\r\n");
int i = 0;
for (ElementInfo ei : r5List) {
r5.append(" \"" + ei.path + "\": { ");
if (ei.types.size() > 0) {
r5.append("\"types\": [");
boolean first = true;
for (String s : ei.types) {
if (first)
first = false;
else
r5.append(", ");
r5.append("\"" + s + "\"");
}
r5.append("]");
} else if (ei.elements.size() > 0) {
r5.append("\"elements\": [");
boolean first = true;
for (String s : ei.elements) {
if (first)
first = false;
else
r5.append(", ");
r5.append("\"" + s + "\"");
}
r5.append("]");
}
i++;
if (i == r5List.size()) {
r5.append(" }\r\n");
} else {
r5.append(" },\r\n");
}
}
r5.append("}\r\n");
TextFile.stringToFile(r5.toString(), dest);
}
use of org.hl7.fhir.r4b.model.Extension in project kindling by HL7.
the class JsonSpecGenerator method generateCoreElem.
@SuppressWarnings("rawtypes")
private void generateCoreElem(List<ElementDefinition> elements, ElementDefinition elem, int indent, String pathName, boolean asValue, TypeRefComponent type, boolean last, boolean complex) throws Exception {
if (elem.getPath().endsWith(".id"))
return;
if (!complex && elem.getPath().endsWith(".extension"))
return;
if (elem.getMax().equals("0"))
return;
String indentS = "";
for (int i = 0; i < indent; i++) {
indentS += " ";
}
write(indentS);
List<ElementDefinition> children = getChildren(elements, elem);
String name = tail(elem.getPath());
String en = asValue ? "value[x]" : name;
String tc = type.getWorkingCode();
if (en.contains("[x]"))
en = en.replace("[x]", upFirst(tc));
boolean unbounded = elem.hasMax() && elem.getMax().equals("*");
// 1. name
write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(getEnhancedDefinition(elem)) + "\" class=\"dict\"><span style=\"text-decoration: underline\">" + en + "</span></a>\" : ");
// 2. value
boolean delayedCloseArray = false;
if (unbounded)
write("[");
if (type == null) {
// inline definition
assert (children.size() > 0);
write("{");
delayedCloseArray = true;
} else if (definitions.getPrimitives().containsKey(tc)) {
if (!(tc.equals("integer") || tc.equals("boolean") || tc.equals("decimal")))
write("\"");
if (elem.hasFixed())
write(Utilities.escapeJson(((PrimitiveType) elem.getFixed()).asStringValue()));
else
write("<<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(tc) + ".html#" + tc) + "\">" + tc + "</a></span>>");
if (!(tc.equals("integer") || tc.equals("boolean") || tc.equals("decimal")))
write("\"");
} else {
write("{ ");
write("<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(tc) + ".html#" + tc) + "\">" + tc + "</a></span>");
if (type.hasProfile()) {
if (type.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
String t = type.getProfile().get(0).getValue().substring(40);
if (definitions.hasType(t))
write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(t) + ".html#" + t) + "\">" + t + "</a></span>)");
else if (definitions.hasResource(t))
write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + dtRoot + t.toLowerCase() + ".html\">" + t + "</a></span>)");
else
write("(" + t + ")");
} else
write("(" + type.getProfile() + ")");
}
if (type.hasTargetProfile()) {
if (type.getTargetProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
String t = type.getTargetProfile().get(0).getValue().substring(40);
if (definitions.hasType(t))
write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(t) + ".html#" + t) + "\">" + t + "</a></span>)");
else if (definitions.hasResource(t))
write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + dtRoot + t.toLowerCase() + ".html\">" + t + "</a></span>)");
else
write("(" + t + ")");
} else
write("(" + type.getTargetProfile() + ")");
}
write(" }");
}
if (!delayedCloseArray) {
if (unbounded)
write("]");
if (!last)
write(",");
}
write(" <span style=\"color: Gray\">//</span>");
// 3. optionality
writeCardinality(elem);
// 4. doco
if (!elem.hasFixed()) {
if (elem.hasBinding() && elem.getBinding().hasValueSet()) {
ValueSet vs = resolveValueSet(elem.getBinding().getValueSet());
if (vs != null)
write("<span style=\"color: navy; opacity: 0.8\"><a href=\"" + (Utilities.isAbsoluteUrl(vs.getUserString("path")) ? "" : prefix) + vs.getUserData("path") + "\" style=\"color: navy\">" + Utilities.escapeXml(elem.getShort()) + "</a></span>");
else
write("<span style=\"color: navy; opacity: 0.8\"><a href=\"" + elem.getBinding().getValueSet() + ".html\" style=\"color: navy\">" + Utilities.escapeXml(elem.getShort()) + "</a></span>");
} else
write("<span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(elem.getShort()) + "</span>");
}
write("\r\n");
if (delayedCloseArray) {
int c = 0;
for (ElementDefinition child : children) {
if (child.getType().size() == 1)
generateCoreElem(elements, child, indent + 1, pathName + "." + name, false, child.getType().get(0), ++c == children.size(), false);
else {
write("<span style=\"color: Gray\">// value[x]: <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(child.getShort()) + "</span>. One of these " + Integer.toString(child.getType().size()) + ":</span>\r\n");
for (TypeRefComponent t : child.getType()) generateCoreElem(elements, child, indent + 1, pathName + "." + name, false, t, ++c == children.size(), false);
}
}
write("}]");
if (!last)
write(",");
}
}
use of org.hl7.fhir.r4b.model.Extension in project kindling by HL7.
the class JsonSpecGenerator method generateCoreElemSliced.
private void generateCoreElemSliced(List<ElementDefinition> elements, ElementDefinition elem, List<ElementDefinition> children, int indent, String pathName, boolean asValue, TypeRefComponent type, boolean last, boolean complex) throws Exception {
String name = tail(elem.getPath());
String en = asValue ? "value[x]" : name;
if (en.contains("[x]"))
en = en.replace("[x]", upFirst(type.getWorkingCode()));
boolean unbounded = elem.hasMax() && elem.getMax().equals("*");
String indentS = "";
for (int i = 0; i < indent; i++) {
indentS += " ";
}
write(indentS);
List<ElementDefinition> slices = getSlices(elem, children);
boolean hasContent = slices.size() > 0;
write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(getEnhancedDefinition(elem)) + "\" class=\"dict\"><span style=\"text-decoration: underline\">" + en + "</span></a>\" : ");
write("[ // <span style=\"color: navy\">" + describeSlicing(elem.getSlicing()) + "</span> " + (hasContent ? "" : "]"));
// write(" <span style=\"color: Gray\">//</span>");
// writeCardinality(elem);
write("\r\n");
int c = 0;
for (ElementDefinition slice : slices) {
write(indentS + " ");
write("{ // <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(slice.getShort()) + "</span>");
write(" <span style=\"color: Gray\">//</span>");
writeCardinality(slice);
write("\r\n");
List<ElementDefinition> extchildren = getChildren(elements, slice);
boolean extcomplex = isComplex(extchildren) && complex;
if (!extcomplex) {
write(indentS + " ");
write(" // from Element: <a href=\"" + prefix + "extensibility.html\">extension</a>\r\n");
}
int cc = 0;
int l = lastChild(extchildren);
for (ElementDefinition child : extchildren) if (child.hasSlicing())
generateCoreElemSliced(elements, child, children, indent + 2, pathName + "." + en, false, child.getType().get(0), ++cc == l, extcomplex);
else if (wasSliced(child, children))
// nothing
;
else if (child.getType().size() == 1)
generateCoreElem(elements, child, indent + 2, pathName + "." + en, false, child.getType().get(0), ++cc == l, extcomplex);
else {
write("<span style=\"color: Gray\">// value[x]: <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(child.getShort()) + "</span>. One of these " + Integer.toString(child.getType().size()) + ":</span>\r\n");
for (TypeRefComponent t : child.getType()) generateCoreElem(elements, child, indent + 2, pathName + "." + en, false, t, ++cc == l, false);
}
c++;
write(indentS);
if (c == slices.size())
write(" }\r\n");
else
write(" },\r\n");
}
if (hasContent) {
write(indentS);
if (last)
write("]\r\n");
else
write("],\r\n");
}
}
Aggregations