use of org.hl7.fhir.dstu2016may.model.PrimitiveType in project kindling by HL7.
the class XSDBaseGenerator method genPrimitives.
private void genPrimitives() throws Exception {
for (DefinedCode cd : definitions.getPrimitives().values()) {
if (cd instanceof PrimitiveType) {
PrimitiveType pt = (PrimitiveType) cd;
// two very special cases due to schema weirdness
if (cd.getCode().equals("date")) {
write(" <xs:simpleType name=\"date-primitive\">\r\n");
write(" <xs:restriction>\r\n");
write(" <xs:simpleType>\r\n");
write(" <xs:union memberTypes=\"xs:gYear xs:gYearMonth xs:date\"/>\r\n");
write(" </xs:simpleType>\r\n");
write(" <xs:pattern value=\"([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1]))?)?\"/>\r\n");
write(" </xs:restriction>\r\n");
write(" </xs:simpleType>\r\n");
} else if (cd.getCode().equals("dateTime")) {
write(" <xs:simpleType name=\"dateTime-primitive\">\r\n");
write(" <xs:restriction>\r\n");
write(" <xs:simpleType>\r\n");
write(" <xs:union memberTypes=\"xs:gYear xs:gYearMonth xs:date xs:dateTime\"/>\r\n");
write(" </xs:simpleType>\r\n");
write(" <xs:pattern value=\"([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?\"/>\r\n");
write(" </xs:restriction>\r\n");
write(" </xs:simpleType>\r\n");
} else if (cd.getCode().equals("time")) {
write(" <xs:simpleType name=\"time-primitive\">\r\n");
write(" <xs:restriction base=\"xs:time\">\r\n");
write(" <xs:pattern value=\"([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?\"/>\r\n");
write(" </xs:restriction>\r\n");
write(" </xs:simpleType>\r\n");
} else {
write(" <xs:simpleType name=\"" + pt.getCode() + "-primitive\">\r\n");
if (pt.getSchemaType().contains(",")) {
write(" <xs:union memberTypes=\"" + pt.getSchemaType().replace(",", "") + "\"/>\r\n");
} else if (pt.getSchemaType().equals("string")) {
write(" <xs:restriction base=\"xs:" + pt.getSchemaType() + "\">\r\n");
write(" <xs:minLength value=\"1\"/>\r\n");
write(" </xs:restriction>\r\n");
} else if (!Utilities.noString(pt.getRegex())) {
write(" <xs:restriction base=\"xs:" + pt.getSchemaType() + "\">\r\n");
write(" <xs:pattern value=\"" + pt.getRegex() + "\"/>\r\n");
write(" </xs:restriction>\r\n");
} else {
write(" <xs:restriction base=\"xs:" + pt.getSchemaType() + "\"/>\r\n");
}
write(" </xs:simpleType>\r\n");
}
write(" <xs:complexType name=\"" + pt.getCode() + "\">\r\n");
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(pt.getDefinition()) + "</xs:documentation>\r\n");
if (!Utilities.noString(pt.getComment()))
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(pt.getComment()) + "</xs:documentation>\r\n");
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");
write(" <xs:extension base=\"Element\">\r\n");
write(" <xs:attribute name=\"value\" type=\"" + pt.getCode() + "-primitive\" use=\"optional\"/>\r\n");
write(" </xs:extension>\r\n");
write(" </xs:complexContent>\r\n");
write(" </xs:complexType>\r\n");
} else {
DefinedStringPattern sp = (DefinedStringPattern) cd;
write(" <xs:simpleType name=\"" + sp.getCode() + "-primitive\">\r\n");
if (sp.getSchema().endsWith("+")) {
write(" <xs:restriction base=\"" + sp.getSchema().substring(0, sp.getSchema().length() - 1) + "\">\r\n");
write(" <xs:pattern value=\"" + sp.getRegex() + "\"/>\r\n");
write(" <xs:minLength value=\"1\"/>\r\n");
if (sp.getCode().equals("id"))
write(" <xs:maxLength value=\"64\"/>\r\n");
write(" </xs:restriction>\r\n");
write(" </xs:simpleType>\r\n");
} else {
write(" <xs:restriction base=\"" + sp.getSchema() + "\">\r\n");
if (!sp.getSchema().contains("Integer")) {
write(" <xs:minLength value=\"1\"/>\r\n");
}
if (!Utilities.noString(sp.getRegex())) {
write(" <xs:pattern value=\"" + sp.getRegex() + "\"/>\r\n");
}
write(" </xs:restriction>\r\n");
write(" </xs:simpleType>\r\n");
}
write(" <xs:complexType name=\"" + sp.getCode() + "\">\r\n");
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(sp.getDefinition()) + "</xs:documentation>\r\n");
if (!Utilities.noString(sp.getComment()))
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(sp.getComment()) + "</xs:documentation>\r\n");
write(" <xs:documentation xml:lang=\"en\">If the element is present, it must have either a @value, an @id referenced from the Narrative, or extensions</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
write(" <xs:complexContent>\r\n");
write(" <xs:extension base=\"Element\">\r\n");
write(" <xs:attribute name=\"value\" type=\"" + sp.getCode() + "-primitive\"/>\r\n");
write(" </xs:extension>\r\n");
write(" </xs:complexContent>\r\n");
write(" </xs:complexType>\r\n");
}
}
}
use of org.hl7.fhir.dstu2016may.model.PrimitiveType in project kindling by HL7.
the class SvgGenerator method determineMetrics.
private Point determineMetrics(ElementDefn e, ClassItem source, String path, boolean isRoot, DefinedCode primitive) throws Exception {
String t = e.getName();
if (isRoot) {
t = t + " {" + e.typeCodeNoParams() + ")";
}
if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
t = t + " «Interface»";
}
double width = textWidth(t) * 1.8;
// double width = textWidth(e.getName()) * 1.8 + (isRoot ? textWidth(" (Resource)") : 0);
double height;
if (attributes) {
if (primitive != null) {
if (primitive instanceof PrimitiveType) {
height = HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT + GAP_HEIGHT * 2;
width = textWidth("value : " + getXsi(primitive) + " 0..1");
} else
height = HEADER_HEIGHT + GAP_HEIGHT * 2;
} else {
int i = 0;
for (ElementDefn c : e.getElements()) if (isAttribute(c)) {
String[] texts = textForAttribute(c);
i = i + texts.length;
double w = textWidth(texts[0]);
for (int j = 1; j < texts.length; j++) w = Math.max(w, textWidth(texts[j]));
if (w > width)
width = w;
}
height = HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT * i + GAP_HEIGHT * 2;
}
} else
height = HEADER_HEIGHT + GAP_HEIGHT * 2;
if (ini != null) {
String uml = ini.getStringProperty("directions", path);
if (!Utilities.noString(uml) && uml.contains(";")) {
String[] svg = uml.split("\\;");
e.setSvgLeft(Integer.parseInt(svg[0]));
e.setSvgTop(Integer.parseInt(svg[1]));
} else if (!Utilities.noString(uml) && uml.contains(",")) {
String[] svg = uml.split("\\,");
e.setSvgLeft(Integer.parseInt(svg[0]));
e.setSvgTop(Integer.parseInt(svg[1]));
} else {
e.setUmlDir(uml);
}
}
Point p = new Point(e.getSvgLeft(), e.getSvgTop(), PointKind.unknown);
if (p.y == ElementDefn.MAX_NEG || p.x == ElementDefn.MAX_NEG) {
if ("left".equals(e.getUmlDir())) {
p.x = source.left - 120 - width;
p.y = source.centerV() - height / 2;
p = findEmptyPlace(p, width, height, 0, 80);
} else if ("right".equals(e.getUmlDir())) {
p.x = source.right() + 120;
p.y = source.centerV() - height / 2;
p = findEmptyPlace(p, width, height, 0, 80);
} else if ("up".equals(e.getUmlDir())) {
p.x = source.centerH() - width / 2;
p.y = source.top - height - 80;
p = findEmptyPlace(p, width, height, 80, 0);
} else if ("down".equals(e.getUmlDir())) {
p.x = source.centerH() - width / 2;
p.y = source.bottom() + 80;
p = findEmptyPlace(p, width, height, +80, 0);
} else {
p.y = 0;
p.x = 0;
p = findEmptyPlace(p, width, height, 80, 0);
}
}
miny = Math.min(miny, p.y);
minx = Math.min(minx, p.x);
ClassItem item = new ClassItem(p.x, p.y, width, height, e.getPath());
classes.put(e, item);
double x = item.right() + MARGIN_X;
double y = item.bottom() + MARGIN_Y;
if (attributes) {
for (ElementDefn c : e.getElements()) {
if (!isAttribute(c) && (Utilities.noString(c.typeCode()) || !c.typeCode().startsWith("@"))) {
p = determineMetrics(c, item, path + "." + c.getName(), false, null);
x = Math.max(x, p.x + MARGIN_X);
y = Math.max(y, p.y + MARGIN_Y);
}
}
}
return new Point(x, y, PointKind.unknown);
}
use of org.hl7.fhir.dstu2016may.model.PrimitiveType in project kindling by HL7.
the class ProfileGenerator method genUml.
public void genUml(PrimitiveType type) {
UMLClass c = uml.getClassByNameCreate(type.getCode());
c.setDocumentation(type.getDefinition());
c.setSpecialises(uml.getClassByName("PrimitiveType"));
String t = type.getSchemaType();
if (!t.startsWith("xs:"))
t = "xs:" + t;
if (!uml.hasPrimitive(t)) {
UMLPrimitive p = new UMLPrimitive(t);
uml.getTypes().put(t, p);
}
c.getAttributes().add(new UMLAttribute("value", "0", "1", uml.getTypes().get(t)));
}
use of org.hl7.fhir.dstu2016may.model.PrimitiveType in project kindling by HL7.
the class SourceParser method processImport.
private void processImport(Sheet sheet, int row) throws Exception {
PrimitiveType prim = new PrimitiveType();
prim.setCode(sheet.getColumn(row, "Data Type"));
prim.setDefinition(sheet.getColumn(row, "Definition"));
prim.setComment(sheet.getColumn(row, "Comments"));
prim.setSchemaType(sheet.getColumn(row, "Schema"));
prim.setJsonType(sheet.getColumn(row, "Json"));
prim.setRegex(sheet.getColumn(row, "RegEx"));
prim.setV2(sheet.getColumn(row, "v2"));
prim.setV3(sheet.getColumn(row, "v3"));
TypeRef td = new TypeRef();
td.setName(prim.getCode());
definitions.getKnownTypes().add(td);
definitions.getPrimitives().put(prim.getCode(), prim);
}
use of org.hl7.fhir.dstu2016may.model.PrimitiveType in project org.hl7.fhir.core by hapifhir.
the class PrimitiveType method equalsDeep.
@Override
public boolean equalsDeep(Base obj) {
if (!super.equalsDeep(obj))
return false;
if (obj == null) {
return false;
}
if (!(obj.getClass() == getClass())) {
return false;
}
PrimitiveType<?> o = (PrimitiveType<?>) obj;
EqualsBuilder b = new EqualsBuilder();
b.append(getValue(), o.getValue());
return b.isEquals();
}
Aggregations