use of org.hl7.fhir.r5.model.PrimitiveType 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.r5.model.PrimitiveType in project kindling by HL7.
the class ProfileGenerator method genUml.
private void genUml(TypeDefn t) {
if (!uml.hasClass(t.getName())) {
UMLClass c = new UMLClass(t.getName(), UMLClassType.Class);
uml.getTypes().put(t.getName(), c);
}
UMLClass c = uml.getClassByName(t.getName());
c.setDocumentation(t.getDefinition());
if (!t.getTypes().isEmpty()) {
c.setSpecialises(uml.getClassByName(t.typeCodeNoParams()));
}
if (!c.hasAttributes()) {
for (ElementDefn e : t.getElements()) {
UMLAttribute a = null;
if (t.getTypes().isEmpty()) {
a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate("Base"));
} else if (t.getTypes().size() == 1 && !isReference(t.getTypes().get(0).getName())) {
a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate(e.typeCode()));
} else {
String tn = t.getTypes().get(0).getName();
boolean allSame = true;
for (int i = 1; i < t.getTypes().size(); i++) {
allSame = tn.equals(t.getTypes().get(i).getName());
}
if (allSame && isReference(tn)) {
a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate(tn));
for (TypeRef tr : t.getTypes()) {
for (String p : tr.getParams()) {
a.getTargets().add(p);
}
}
} else {
boolean allPrimitive = true;
for (TypeRef tr : t.getTypes()) {
if (!definitions.hasPrimitiveType(tr.getName())) {
allPrimitive = false;
}
}
if (allPrimitive) {
a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate("PrimitiveType"));
} else {
a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate("DataType"));
}
for (TypeRef tr : t.getTypes()) {
a.getTypes().add(tr.getName());
for (String p : tr.getParams()) {
a.getTargets().add(p);
}
}
}
}
c.getAttributes().add(a);
}
}
}
use of org.hl7.fhir.r5.model.PrimitiveType in project kindling by HL7.
the class ProfileGenerator method addSpecificDetails.
private void addSpecificDetails(PrimitiveType type, ElementDefinition ed) throws FHIRFormatError {
if (type.getCode().equals("integer")) {
ed.setMinValue(new IntegerType(-2147483648));
ed.setMaxValue(new IntegerType(2147483647));
}
if (type.getCode().equals("integer64")) {
ed.setMinValue(new Integer64Type(-9223372036854775808L));
ed.setMaxValue(new Integer64Type(9223372036854775807L));
}
if (type.getCode().equals("string")) {
ed.setMaxLength(1024 * 1024);
}
}
use of org.hl7.fhir.r5.model.PrimitiveType in project kindling by HL7.
the class DictHTMLGenerator method encodeValue.
private String encodeValue(DataType value) throws Exception {
if (value == null || value.isEmpty())
return null;
if (value instanceof PrimitiveType)
return Utilities.escapeXml(((PrimitiveType) value).asStringValue());
ByteArrayOutputStream bs = new ByteArrayOutputStream();
XmlParser parser = new XmlParser();
parser.setOutputStyle(OutputStyle.PRETTY);
parser.compose(bs, null, value);
String[] lines = bs.toString().split("\\r?\\n");
StringBuilder b = new StringBuilder();
for (String s : lines) {
if (!Utilities.noString(s) && !s.startsWith("<?")) {
// eliminate the xml header
b.append(Utilities.escapeXml(s).replace(" ", " ") + "<br/>");
}
}
return b.toString();
}
use of org.hl7.fhir.r5.model.PrimitiveType in project kindling by HL7.
the class FhirTurtleGenerator method genPrimitiveType.
/* ==============================================
Generators for various FHIR types
* ============================================== */
/**
* PrimitiveType Generator
*
* @param pt FHIR Primitive Type (e.g. int, string, dateTime)
*/
// Note: For unknown reasons, getPrimitives returns DefinedCodes, not PrimitiveTypes...
private void genPrimitiveType(DefinedCode pt) {
String ptName = pt.getCode();
FHIRResource ptRes = fact.fhir_class(ptName, "Primitive").addDefinition(pt.getDefinition());
Resource rdfType = RDFTypeMap.xsd_type_for(ptName, owlTarget);
if (rdfType != null)
ptRes.restriction(fact.fhir_cardinality_restriction(value, fact.fhir_datatype(rdfType).resource, 1, 1));
}
Aggregations