use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class XSDGenerator method generateType.
private void generateType(ElementDefn root, String name, ElementDefn struc, boolean isResource) throws IOException, Exception {
write(" <xs:complexType name=\"" + name + "\">\r\n");
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(root.getDefinition()) + "</xs:documentation>\r\n");
if (isResource)
write(" <xs:documentation xml:lang=\"en\">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
write(" <xs:complexContent>\r\n");
if (isResource)
write(" <xs:extension base=\"" + root.typeCode() + "\">\r\n");
else
write(" <xs:extension base=\"BackboneElement\">\r\n");
write(" <xs:sequence>\r\n");
for (ElementDefn e : struc.getElements()) {
if (e.getName().equals("[type]"))
generateAny(root, e);
else
generateElement(root, e);
}
write(" </xs:sequence>\r\n");
write(" </xs:extension>\r\n");
write(" </xs:complexContent>\r\n");
write(" </xs:complexType>\r\n");
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class JsonLDGenerator method scanTypes.
//
// private CharSequence nameForType(String type) {
// if (definitions.getConstraints().containsKey(type))
// return definitions.getConstraints().get(type).getBaseType();
// else
// return Utilities.capitalize(type);
// }
private void scanTypes(ElementDefn root, ElementDefn focus) {
for (ElementDefn e : focus.getElements()) {
if (e.getTypes().size() == 0 && e.getElements().size() > 0) {
String tn = e.getPath();
structures.add(e);
typenames.add(tn);
types.put(e, tn);
scanTypes(root, e);
}
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class XSDBaseGenerator method genInfrastructure.
private void genInfrastructure(ElementDefn elem) throws Exception {
enums.clear();
enumDefs.clear();
String name = elem.getName();
write(" <xs:complexType name=\"" + name + "\">\r\n");
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(elem.getDefinition()) + "</xs:documentation>\r\n");
write(" <xs:documentation xml:lang=\"en\">If the element is present, it must have a value for at least one of the defined elements, an @id referenced from the Narrative, or extensions</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
if (!elem.getName().equals("Base")) {
write(" <xs:complexContent>\r\n");
write(" <xs:extension base=\"" + getParentType(elem) + "\">\r\n");
}
write(" <xs:sequence>\r\n");
for (ElementDefn e : elem.getElements()) {
if (!e.isXmlAttribute()) {
if (e.getName().equals("[type]"))
generateAny(elem, e, null, null);
else
generateElement(elem, e, null, null);
}
}
write(" </xs:sequence>\r\n");
for (ElementDefn e : elem.getElements()) {
if (e.isXmlAttribute()) {
generateAttribute(elem, e, null);
}
}
if (!elem.getName().equals("Base")) {
write(" </xs:extension>\r\n");
write(" </xs:complexContent>\r\n");
}
write(" </xs:complexType>\r\n");
while (!structures.isEmpty()) {
String s = structures.keySet().iterator().next();
generateType(elem, s, structures.get(s));
structures.remove(s);
}
for (BindingSpecification en : enums) {
generateEnum(en);
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class XVerPathsGenerator method process.
private void process(ElementDefn ed, String path) {
ElementInfo ei = new ElementInfo();
ei.path = path;
r5List.add(ei);
ElementInfo r4 = r4List.get(path);
if (ed.getTypes().size() > 0) {
// leaf
for (TypeRef tr : ed.getTypes()) {
if (r4 == null || !r4.types.contains(tr.summary())) {
ei.types.add(tr.summary());
}
}
} else {
for (ElementDefn child : ed.getElements()) {
if (r4 == null || !r4.elements.contains(child.getName())) {
ei.elements.add(child.getName());
}
process(child, path + "." + child.getName());
}
}
}
use of org.hl7.fhir.definitions.model.ElementDefn 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);
}
Aggregations