use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class ProfileGenerator method buildDefinitionFromElement.
private void buildDefinitionFromElement(String path, ElementDefinition ce, ElementDefn e, Profile ap, StructureDefinition p, String inheritedType, boolean isInterface) throws Exception {
if (!Utilities.noString(e.getComments()))
ce.setComment(preProcessMarkdown(e.getComments(), "Element Comments"));
if (!Utilities.noString(e.getShortDefn()))
ce.setShort(e.getShortDefn());
if (!Utilities.noString(e.getDefinition())) {
ce.setDefinition(preProcessMarkdown(e.getDefinition(), "Element Definition"));
if (!Utilities.noString(e.getShortDefn()))
ce.setShort(e.getShortDefn());
}
if (path.contains(".") && !Utilities.noString(e.getRequirements()))
ce.setRequirements(preProcessMarkdown(e.getRequirements(), "Element Requirements"));
if (e.hasMustSupport())
ce.setMustSupport(e.isMustSupport());
if (!Utilities.noString(e.getMaxLength()))
ce.setMaxLength(Integer.parseInt(e.getMaxLength()));
// no purpose here
if (e.getMinCardinality() != null)
ce.setMin(e.getMinCardinality());
if (e.getMaxCardinality() != null)
ce.setMax(e.getMaxCardinality() == Integer.MAX_VALUE ? "*" : e.getMaxCardinality().toString());
// we don't know mustSupport here
if (e.hasModifier())
ce.setIsModifier(e.isModifier());
if (ce.getIsModifier())
ce.setIsModifierReason(e.getModifierReason());
// ce.setConformance(getType(e.getConformance()));
for (Invariant id : e.getStatedInvariants()) {
ce.addCondition(id.getId());
}
ce.setFixed(e.getFixed());
ce.setPattern(e.getPattern());
// ce.setDefaultValue(e.getDefaultValue());
ce.setMeaningWhenMissing(e.getMeaningWhenMissing());
if (e.getExample() != null)
ce.addExample().setLabel("General").setValue(e.getExample());
for (Integer i : e.getOtherExamples().keySet()) {
Extension ex = ce.addExtension();
ex.setUrl("http://hl7.org/fhir/StructureDefinition/structuredefinition-example");
ex.addExtension().setUrl("index").setValue(new StringType(i.toString()));
ex.addExtension().setUrl("exValue").setValue(e.getOtherExamples().get(i));
}
for (String s : e.getAliases()) ce.addAlias(s);
if (e.hasSummaryItem() && ce.getPath().contains("."))
ce.setIsSummaryElement(Factory.newBoolean(e.isSummary()));
for (String n : definitions.getMapTypes().keySet()) {
addMapping(p, ce, n, e.getMapping(n), null);
}
if (ap != null) {
for (String n : ap.getMappingSpaces().keySet()) {
addMapping(p, ce, n, e.getMapping(n), ap);
}
}
ToolingExtensions.addDisplayHint(ce, e.getDisplayHint());
if (!isInterface) {
convertConstraints(e, ce, inheritedType == null ? p.getUrl() : "http://hl7.org/fhir/StructureDefinition/" + inheritedType);
}
// we don't have anything to say about constraints on resources
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class ProfileGenerator method isImplicitTypeConstraint.
private String isImplicitTypeConstraint(String path) throws Exception {
if (!path.contains("."))
return null;
String t = path.substring(0, path.indexOf("."));
ElementDefn tt = definitions.getElementDefn(t);
return isImplicitTypeConstraint(tt.getName(), tt, path);
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class ProfileGenerator method addElementConstraint.
/*
* // resource
// domain resource
for (ElementDefn child : definitions.getBaseResources().get("DomainResource").getRoot().getElements())
defineElement(null, p, p.getSnapshot(), child, r.getRoot().getName()+"."+child.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.Resource);
*/
/*
private String registerMapping(ConformancePackage ap, StructureDefinition p, String m) {
for (StructureDefinitionMappingComponent map : p.getMapping()) {
if (map.getUri().equals(m))
return map.getIdentity();
}
StructureDefinitionMappingComponent map = new StructureDefinitionMappingComponent();
MappingSpace space = definitions.getMapTypes().get(m);
if (space != null)
map.setIdentity(space.getId());
else
map.setIdentity("m" + Integer.toString(p.getMapping().size()+1));
map.setUri(m);
String name = ap.metadata(m+"-name");
if (Utilities.noString(name) && space != null)
name = space.getTitle();
if (!Utilities.noString(name))
map.setName(name);
String comments = ap.metadata(m+"-comments");
if (Utilities.noString(comments) && space != null)
comments = space.getPreamble();
if (!Utilities.noString(comments))
map.setComments(comments);
return map.getIdentity();
}
*/
private ElementDefinition addElementConstraint(StructureDefinition sd, ElementDefinition ed) {
if (!ed.getPath().contains(".") && sd.getKind() == StructureDefinitionKind.RESOURCE)
return ed;
if (hasSystemType(ed))
return ed;
if (isResource(ed))
return ed;
if (hasConstraint(ed, "ele-1"))
return ed;
ElementDefinitionConstraintComponent inv = ed.addConstraint();
inv.setKey("ele-1");
inv.setSeverity(ConstraintSeverity.ERROR);
inv.setHuman("All FHIR elements must have a @value or children");
inv.setExpression("hasValue() or (children().count() > id.count())");
inv.setXpath("@value|f:*|h:div");
inv.setSource("http://hl7.org/fhir/StructureDefinition/Element");
return ed;
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class DictHTMLGenerator method describeType.
private String describeType(ElementDefn e) throws Exception {
StringBuilder b = new StringBuilder();
boolean first = true;
if (e.typeCode().startsWith("@")) {
b.append("<a href=\"#" + e.typeCode().substring(1) + "\">See " + e.typeCode().substring(1) + "</a>");
} else {
for (TypeRef t : e.getTypes()) {
if (!first)
b.append("|");
String tn = t.getName();
if (tn.equals("Type"))
tn = "Element";
if (tn.equals("*"))
b.append("<a href=\"" + prefix + "datatypes.html#open\">*</a>");
else
b.append("<a href=\"" + prefix + typeLink(tn) + "\">" + tn + "</a>");
if (t.hasParams()) {
b.append("(");
boolean firstp = true;
for (String p : t.getParams()) {
if (!firstp)
b.append(" | ");
firstp = false;
if (definitions.hasLogicalModel(p)) {
b.append("<a href=\"" + prefix + typeLink(p) + "\">" + p + "</a>[");
boolean firstpn = true;
for (String pn : definitions.getLogicalModel(p).getImplementations()) {
if (!firstpn)
b.append(", ");
firstpn = false;
b.append("<a href=\"" + prefix + typeLink(pn) + "\">" + pn + "</a>");
}
b.append("]");
} else {
b.append("<a href=\"" + prefix + typeLink(p) + "\">" + p + "</a>");
}
}
b.append(")");
}
first = false;
}
}
return b.toString();
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class DictHTMLGenerator method generate.
public void generate(ElementDefn root) throws Exception {
write("<table class=\"dict\">\r\n");
writeEntry(root.getName(), "0..*", describeType(root), null, root, root.getName(), true);
for (ElementDefn e : root.getElements()) {
generateElement(root.getName(), e, root.getName(), false);
}
write("</table>\r\n");
write("\r\n");
flush();
close();
}
Aggregations