use of org.hl7.fhir.r4.model.Enumerations.FHIRDefinedType 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"));
}
}
}
Aggregations