use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class XSDGenerator method generateElement.
private void generateElement(ElementDefn root, ElementDefn e) throws Exception {
write(" ");
if (e.getTypes().size() > 1 || (e.getTypes().size() == 1 && e.getTypes().get(0).isWildcardType())) {
if (!e.getName().contains("[x]"))
throw new Exception("Element " + e.getName() + " in " + root.getName() + " has multiple types as a choice doesn't have a [x] in the element name");
String close = " minOccurs=\"0\">";
if (!forCodeGeneration) {
write("<xs:choice minOccurs=\"" + e.getMinCardinality().toString() + "\" maxOccurs=\"" + (e.unbounded() ? "unbounded" : "1") + "\" ");
write(">\r\n");
if (e.hasDefinition()) {
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(e.getDefinition()) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
}
close = "/>";
}
if (e.getTypes().size() == 1)
generateAny(root, e, e.getName().replace("[x]", ""), close);
else
for (TypeRef t : e.getTypes()) {
String tn = encodeType(e, t, true);
String n = e.getName().replace("[x]", nameForType(tn));
if (t.getName().equals("Reference"))
n = e.getName().replace("[x]", "Reference");
write(" <xs:element name=\"" + n + "\" type=\"" + encodeType(e, t, true) + "\"" + close + "\r\n");
if (forCodeGeneration) {
write(" <xs:annotation>\r\n");
if (e.hasDefinition()) {
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(e.getDefinition()) + " (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 {
String tn = null;
if ("extension".equals(e.getName()))
write("<xs:element name=\"" + e.getName() + "\" type=\"Extension\" ");
else if (e.usesCompositeType()) /* && types.containsKey(root.getElementByName(e.typeCode().substring(1)))*/
{
ElementDefn ref = root.getElementByName(definitions, e.typeCode().substring(1), true, false, null);
String rtn = 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 (e.getTypes().size() == 0 && e.getElements().size() > 0) {
write("<xs:element name=\"" + e.getName() + "\" type=\"" + types.get(e) + "\" ");
} else if (e.getTypes().size() == 1) {
write("<xs:element name=\"" + e.getName() + "\" ");
tn = encodeType(e, e.getTypes().get(0), true);
if (tn.equals("Narrative") && e.getName().equals("text") && root.getElements().contains(e))
write("type=\"" + tn + "\" ");
} else
throw new Exception("how do we get here? " + e.getName() + " in " + root.getName() + " " + Integer.toString(e.getTypes().size()));
write("minOccurs=\"" + e.getMinCardinality().toString() + "\"");
if (e.unbounded())
write(" maxOccurs=\"unbounded\"");
else
write(" maxOccurs=\"1\"");
if (tn != null && !(tn.equals("Narrative") && e.getName().equals("text") && root.getElements().contains(e))) {
write(" type=\"" + tn + "\"");
}
write(">\r\n");
if (e.hasDefinition()) {
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(e.getDefinition()) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
}
write(" </xs:element>\r\n");
if (tn != null && !(tn.equals("Narrative") && e.getName().equals("text") && root.getElements().contains(e))) {
if (tn.equals("FHIRDefinedType"))
enums.put("FHIRDefinedType", definitions.getValuesets().get("http://hl7.org/fhir/ValueSet/defined-types"));
else if (tn.equals("FHIRAllTypes"))
enums.put("FHIRAllTypes", definitions.getValuesets().get("http://hl7.org/fhir/ValueSet/all-types"));
}
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class XSDGenerator method generateAny.
private void generateAny(ElementDefn root, ElementDefn e) throws Exception {
String close = " minOccurs=\"0\">";
if (!forCodeGeneration) {
write(" <xs:choice minOccurs=\"" + e.getMinCardinality().toString() + "\" maxOccurs=\"1\">\r\n");
if (e.hasDefinition()) {
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(e.getDefinition()) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
}
close = "/>";
}
for (TypeRef t : datatypes) {
if (t.isResourceReference()) {
write(" <xs:element name=\"Resource\" type=\"Reference\"" + close + "\r\n");
} else {
write(" <xs:element name=\"" + t.getName() + "\" type=\"" + t.getName() + "\"" + close + "\r\n");
}
if (forCodeGeneration) {
write(" <xs:annotation>\r\n");
if (e.hasDefinition()) {
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(e.getDefinition()) + " (choose any one of the elements, but only one)</xs:documentation>\r\n");
} else {
write(" <xs:documentation xml:lang=\"en\">(choose any one of the elements, but only one)</xs:documentation>\r\n");
}
write(" </xs:annotation>\r\n");
write(" </xs:element>\r\n");
}
}
if (!forCodeGeneration)
write(" </xs:choice>\r\n");
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class JsonSpecGenerator method generateInner.
private void generateInner(ElementDefn root, boolean resource, boolean isAbstract) throws IOException, Exception {
String rn;
if (root.getTypes().size() > 0 && (root.getTypes().get(0).getName().equals("Type") || root.getName().equals("Extension") || (root.getTypes().get(0).getName().equals("Structure")) && root.getName().equals("Element") || root.getName().equals("BackboneElement") || root.getName().equals("Meta")))
rn = null;
else if (isAbstract)
rn = "[name]";
else
rn = root.getName();
write("{<span style=\"float: right\"><a title=\"Documentation for this format\" href=\"" + prefix + "json.html\"><img src=\"" + prefix + "help.png\" alt=\"doco\"/></a></span>\r\n");
if (definitions.hasResource(root.getName()) || Utilities.existsInList(root.getName(), "Parameters")) {
write(" \"resourceType\" : \"");
if (defPage == null)
write("<span title=\"" + Utilities.escapeXml(root.getDefinition()) + "\"><b>");
else
write("<a href=\"" + (defPage + "#" + root.getName()) + "\" title=\"" + Utilities.escapeXml(root.getDefinition()) + "\" class=\"dict\"><b>");
write(rn);
if ((defPage == null))
write("</b></span>\",\r\n");
else
write("</b></a>\",\r\n");
}
if ((root.getName().equals(rn) || "[name]".equals(rn)) && resource) {
if (!Utilities.noString(root.typeCode())) {
write(" // from <a href=\"" + prefix + "resource.html\">Resource</a>: <a href=\"" + prefix + "resource.html#id\">id</a>, <a href=\"" + prefix + "resource.html#meta\">meta</a>, <a href=\"" + prefix + "resource.html#implicitRules\">implicitRules</a>, and <a href=\"" + prefix + "resource.html#language\">language</a>\r\n");
if (root.typeCode().equals("DomainResource"))
write(" // from <a href=\"" + prefix + "domainresource.html\">DomainResource</a>: <a href=\"" + prefix + "narrative.html#Narrative\">text</a>, <a href=\"" + prefix + "references.html#contained\">contained</a>, <a href=\"" + prefix + "extensibility.html\">extension</a>, and <a href=\"" + prefix + "extensibility.html#modifierExtension\">modifierExtension</a>\r\n");
}
} else if (!resource) {
if (root.typeCode().equals("BackboneElement"))
write(" // from BackboneElement: <a href=\"" + prefix + "extensibility.html\">extension</a>, <a href=\"" + prefix + "extensibility.html\">modifierExtension</a>\r\n");
else
write(" // from Element: <a href=\"" + prefix + "extensibility.html\">extension</a>\r\n");
}
// if (root.getName().equals("Extension")) {
// ElementDefn urld = root.getElements().get(0);
// write(" \"<span title=\"" + Utilities.escapeXml(urld.getDefinition()) + "\"><a href=\"" + (defPage + "#Extension.url") + "\" title=\"" + Utilities.escapeXml(urld.getDefinition()) + "\" class=\"dict\">");
// write("<url></a></span>");
// write("\" : { // <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(root.getElements().get(0).getShortDefn()) + "</span>\r\n");
// generateCoreElem(root.getElements().get(1), 2, rn, root.getName(), false, true);
// write(" }\r\n");
// } else {
int c = 0;
for (ElementDefn elem : root.getElements()) {
generateCoreElem(elem, 1, rn, root.getName(), root.getName().equals(rn) && resource, ++c == root.getElements().size());
// }
}
write("}\r\n");
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class JsonSpecGenerator method writeTypeLinks.
/*
private String docPrefix(int widthSoFar, int indent, ElementDefinition elem) {
if (widthSoFar + (elem.getShort() == null ? 0 : elem.getShort().length())+8+elem.getPath().length() > 105) {
String ret = "\r\n ";
for (int i = 0; i < indent+2; i++)
ret = ret + " ";
return ret;
}
else
return "";
}
*/
private int writeTypeLinks(ElementDefn elem, int indent, TypeRef t) throws Exception {
write(" <span style=\"color: darkgreen\">");
int i = 0;
// this is wrong if the type is an attribute, but the wrapping concern shouldn't apply in this case, so this is ok
int w = indent + 12 + elem.getName().length();
// for (TypeRef t : elem.getTypes()) {
if (i > 0) {
write("|");
w++;
}
if (w + t.getName().length() > 80) {
throw new Error("this sholdn't happen");
// write("\r\n ");
// for (int j = 0; j < indent; j++)
// write(" ");
// w = indent+2;
}
// again, could be wrong if this is an extension, but then it won't wrap
w = w + t.getName().length();
if (t.isXhtml() || t.getName().equals("list"))
write(t.getName());
else if (t.getName().equals("Extension") && t.getParams().size() == 0 && !Utilities.noString(t.getProfile()))
write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
else if (definitions.getConstraints().containsKey(t.getName())) {
ProfiledType pt = definitions.getConstraints().get(t.getName());
write("<a href=\"" + prefix + (dtRoot + definitions.getSrcFile(pt.getBaseType()) + ".html#" + pt.getBaseType() + "\">" + pt.getBaseType()) + "</a>");
w = w + pt.getBaseType().length() + 2;
write("(<a style=\"color:navy\" href=\"" + prefix + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>)");
} else
write("<a href=\"" + prefix + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>");
if (t.hasParams()) {
write("(");
boolean firstp = true;
List<String> ap = new ArrayList<>();
for (String p : t.getParams()) {
if (definitions.hasLogicalModel(p))
ap.addAll(definitions.getLogicalModel(p).getImplementations());
else
ap.add(p);
}
Collections.sort(ap);
for (String p : ap) {
if (!firstp) {
write("|");
w++;
}
// again, p.length() could be wrong if this is an extension, but then it won't wrap
if (w + p.length() > 80) {
write("\r\n ");
for (int j = 0; j < indent; j++) write(" ");
w = indent + 2;
}
w = w + p.length();
// TODO: Display action and/or profile information
if (p.equals("Any")) {
write("<a href=\"" + prefix + "resourcelist.html" + "\">" + p + "</a>");
} else if (isReference(t.getName()) && t.getParams().size() == 1 && !Utilities.noString(t.getProfile()))
write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
else
write("<a href=\"" + prefix + (dtRoot + definitions.getSrcFile(p) + ".html#" + p) + "\">" + p + "</a>");
firstp = false;
}
write(")");
w++;
}
i++;
// }
write("</span>");
return w;
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class MappingsGenerator method genElement.
private void genElement(StringBuilder s, int indent, ElementDefn elem, String m, int children, boolean isRoot, boolean sparse) {
if ((children == ROOT_ONLY || children == ALL)) {
if (isRoot || !sparse || hasMapping(elem, m)) {
s.append(" <tr><td>");
if (indent == 0) {
s.append("<a name=\"" + elem.getName() + "\"> </a>");
s.append("<a name=\"" + elem.getName().toLowerCase() + "\"> </a>");
}
for (int i = 0; i < indent; i++) {
s.append(" ");
s.append(" ");
s.append(" ");
s.append(" ");
}
if (indent == 0)
s.append("<b>" + elem.getName() + "</b>");
else
s.append(elem.getName());
s.append("</td><td>" + Utilities.escapeXml(elem.getMappings().get(m)).replace("\n", "<br/>\n") + "</td></tr>\r\n");
}
}
if (!isRoot || !"N/A".equalsIgnoreCase(elem.getMappings().get(m))) {
if (children == CHILDREN_ONLY || children == ALL) {
for (ElementDefn child : elem.getElements()) {
genElement(s, indent + 1, child, m, ALL, false, sparse);
}
}
}
}
Aggregations