use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class ResourceParser method parseResource.
private ResourceDefn parseResource(String t) throws FHIRFormatError, FileNotFoundException, IOException {
StructureDefinition sd = (StructureDefinition) parseXml("structuredefinition-" + t + ".xml");
sdList.put(sd.getUrl(), sd);
sd.setVersion(version);
ResourceDefn r = new ResourceDefn();
r.setName(sd.getName());
r.setEnteredInErrorStatus(ToolingExtensions.readStringExtension(sd, BuildExtensions.EXT_ENTERED_IN_ERROR_STATUS));
r.setStatus(StandardsStatus.fromCode(ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_STANDARDS_STATUS)));
r.setAbstract(sd.getAbstract());
r.setInterface(ToolingExtensions.readBoolExtension(sd, BuildExtensions.EXT_RESOURCE_INTERFACE));
r.setWg(definitions.getWorkgroups().get(ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_WORKGROUP)));
r.setFmmLevel(ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_FMM_LEVEL));
r.setProposedOrder(ToolingExtensions.readStringExtension(sd, BuildExtensions.EXT_PROPOSED_ORDER));
r.setSecurityCategorization(SecurityCategorization.fromCode(ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category")));
r.setRequirements(sd.getPurpose());
r.setDefinition(sd.getDescription());
if (sd.hasExtension(BuildExtensions.EXT_TEMPLATE)) {
String tname = BuildExtensions.readStringExtension(sd, BuildExtensions.EXT_TEMPLATE);
ResourceDefn template = definitions.getResourceByName(tname);
r.setTemplate(template.getRoot());
}
// private long timestamp; only set in regenerator...?
// todo:
// private List<InheritedMapping> inheritedMappings = new ArrayList<InheritedMapping>();
// private ElementDefn template;
// private Map<String, PointSpec> layout = new HashMap<String, PointSpec>();
ProfileUtilities pu = new ProfileUtilities(context, null, null);
r.setRoot(parseTypeDefinition(pu, sd.getDifferential().getElementFirstRep(), sd));
r.getRoot().setFmmLevel(r.getFmmLevel());
r.getRoot().setRequirements(r.getRequirements());
if (r.isAbstract()) {
r.getRoot().setAbstractType(true);
}
if (sd.hasBaseDefinition()) {
r.getRoot().getTypes().add(new TypeRef(sd.getBaseDefinition().replace("http://hl7.org/fhir/StructureDefinition/", "")));
}
return r;
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class ResourceParser method parseED.
private void parseED(ProfileUtilities pu, ElementDefn ed, ElementDefinition focus, StructureDefinition sd, String parentName) throws IOException {
ed.setMinCardinality(focus.getMin());
ed.setMaxCardinality("*".equals(focus.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(focus.getMax()));
ed.setIsModifier(focus.getIsModifier());
ed.setModifierReason(focus.getIsModifierReason());
ed.setMustSupport(focus.getMustSupport());
ed.setSummaryItem(focus.getIsSummary());
ed.setRegex(ToolingExtensions.readStringExtension(focus, ToolingExtensions.EXT_REGEX));
ed.setXmlAttribute(focus.hasRepresentation(PropertyRepresentation.XMLATTR));
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_DIR)) {
ed.setUmlDir(ToolingExtensions.readStringExtension(focus, BuildExtensions.EXT_UML_DIR));
}
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_BREAK)) {
ed.setUmlBreak(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_UML_BREAK));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_SVG)) {
String svg = BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_SVG);
if (svg.contains("w=")) {
ed.setSvgWidth(Integer.parseInt(svg.substring(svg.indexOf("w=") + 2)));
svg = svg.substring(0, svg.indexOf(";"));
}
ed.setSvgLeft(Integer.parseInt(svg.substring(0, svg.indexOf(","))));
ed.setSvgTop(Integer.parseInt(svg.substring(svg.indexOf(",") + 1)));
}
ed.setName(tail(focus.getPath()));
ed.setShortDefn(focus.getShort());
ed.setDefinition(focus.getDefinition());
ed.setRequirements(focus.getRequirements());
ed.setComments(focus.getComment());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_TODO)) {
ed.setTodo(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_TODO));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES)) {
ed.setCommitteeNotes(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_HINT)) {
ed.setDisplayHint(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_HINT));
}
if (focus.hasExtension(BuildExtensions.EXT_NO_BINDING)) {
ed.setNoBindingAllowed(focus.getExtensionString(BuildExtensions.EXT_NO_BINDING).equals("true"));
}
for (StringType t : focus.getAlias()) {
ed.getAliases().add(t.getValue());
}
if (focus.hasMaxLength()) {
ed.setMaxLength(Integer.toString(focus.getMaxLength()));
}
ed.setExample(focus.getExampleFirstRep().getValue());
ed.setMeaningWhenMissing(focus.getMeaningWhenMissing());
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_TRANSLATABLE)) {
ed.setTranslatable(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_TRANSLATABLE));
}
ed.setOrderMeaning(focus.getOrderMeaning());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)) {
ed.setStandardsStatus(StandardsStatus.fromCode(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION)) {
ed.setNormativeVersion(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION));
}
for (ElementDefinitionConstraintComponent cst : focus.getConstraint()) {
Invariant inv = new Invariant();
inv.setContext(focus.getPath());
inv.setEnglish(cst.getHuman());
if (cst.hasExtension(BuildExtensions.EXT_OCL)) {
inv.setOcl(cst.getExtensionString(BuildExtensions.EXT_OCL));
}
inv.setXpath(cst.getXpath());
inv.setId(cst.getKey());
if (cst.hasExtension(BuildExtensions.EXT_FIXED_NAME)) {
inv.setFixedName(cst.getExtensionString(BuildExtensions.EXT_FIXED_NAME));
}
inv.setSeverity(cst.getSeverity().toCode());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE)) {
inv.setSeverity("best-practice");
}
if (cst.hasExtension(BuildExtensions.EXT_TURTLE)) {
inv.setTurtle(cst.getExtensionString(BuildExtensions.EXT_TURTLE));
}
inv.setRequirements(cst.getRequirements());
inv.setExpression(cst.getExpression());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION)) {
inv.setExplanation(cst.getExtensionString(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION));
}
ed.getInvariants().put(inv.getId(), inv);
invariants.put(inv.getId(), inv);
}
for (IdType cnd : focus.getCondition()) {
Invariant inv = invariants.get(cnd.primitiveValue());
if (inv == null) {
System.out.println("Unable to find invariant " + cnd.primitiveValue());
} else {
ed.getStatedInvariants().add(inv);
}
}
for (ElementDefinitionMappingComponent map : focus.getMapping()) {
String uri = getMappingUri(sd, map.getIdentity());
if ("http://hl7.org/fhir/fivews".equals(uri)) {
ed.setW5(reverseW5(map.getMap()));
} else {
ed.getMappings().put(uri, map.getMap());
}
}
if (focus.hasContentReference()) {
ed.getTypes().add(new TypeRef("@" + focus.getContentReference().substring(1)));
} else {
for (TypeRefComponent tr : focus.getType()) {
if (!Utilities.existsInList(tr.getCode(), "Element", "BackboneElement")) {
TypeRef t = new TypeRef();
ed.getTypes().add(t);
if (tr.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")) {
t.setName(tr.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type"));
} else {
t.setName(tr.getCode());
}
if (ToolingExtensions.hasExtension(tr, BuildExtensions.EXT_HIERARCHY)) {
ed.setHierarchy(ToolingExtensions.readBoolExtension(tr, BuildExtensions.EXT_HIERARCHY));
}
for (CanonicalType u : tr.getProfile()) {
t.setProfile(u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
}
for (CanonicalType u : tr.getTargetProfile()) {
String s = u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", "");
if ("Resource".equals(s)) {
t.getParams().add("Any");
} else {
t.getParams().add(s);
}
}
if (t.getName().equals("Quantity") && "SimpleQuantity".equals(t.getProfile())) {
t.setName("SimpleQuantity");
t.setProfile(null);
}
if ("Resource".equals(t.getProfile())) {
t.setProfile("Any");
}
if (t.getParams().toString().equals("[ActivityDefinition, EventDefinition, EvidenceVariable, Measure, OperationDefinition, PlanDefinition, Questionnaire, SubscriptionTopic]")) {
t.getParams().clear();
t.getParams().add("Definition");
}
}
}
if (ed.getTypes().size() == STAR_TYPES_COUNT) {
ed.getTypes().clear();
ed.getTypes().add(new TypeRef("*"));
}
}
String name = parentName + Utilities.capitalize(ed.getName());
if (focus.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
ed.setStatedType(focus.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name"));
ed.setDeclaredTypeName(ed.getStatedType());
} else if (ed.getTypes().isEmpty() && !focus.hasContentReference()) {
ed.setDeclaredTypeName(name + "Component");
}
if (focus.hasBinding()) {
ed.setBinding(parseBinding(focus.getBinding()));
}
for (ElementDefinition child : pu.getChildList(sd, focus, true, false)) {
ElementDefn c = new ElementDefn();
ed.getElements().add(c);
parseED(pu, c, child, sd, name);
}
// todo:
// private ElementDefinition derivation;
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class SvgGenerator method drawClass.
private ClassItem drawClass(XMLWriter xml, ElementDefn e, boolean isRoot, ResourceDefn resource, boolean link, String path, DefinedCode primitive, StandardsStatus status) throws Exception {
ClassItem item = classes.get(e);
String tn = e.getName();
if (!definitions.hasPrimitiveType(tn) && !tn.equals("xhtml")) {
tn = Utilities.capitalize(tn);
}
ResourceDefn r = definitions.hasResource(tn) ? definitions.getResourceByName(tn) : null;
if (r == null) {
r = definitions.getBaseResources().get(tn);
}
xml.attribute("id", "n" + (++nc));
xml.enter("g");
xml.attribute("x", Double.toString(item.left));
xml.attribute("y", Double.toString(item.top));
xml.attribute("rx", "4");
xml.attribute("ry", "4");
xml.attribute("width", Double.toString(item.width));
xml.attribute("height", Double.toString(item.height));
xml.attribute("filter", "url(#shadow" + id + ")");
if (r != null) {
xml.attribute("style", "fill:" + r.getStatus().getColorSvg() + ";stroke:black;stroke-width:1");
status = r.getStatus();
} else if (e == null || e.getStandardsStatus() == null)
xml.attribute("style", "fill:" + (status == null ? "#ffffff" : status.getColorSvg()) + ";stroke:black;stroke-width:1");
else {
xml.attribute("style", "fill:" + e.getStandardsStatus().getColorSvg() + ";stroke:black;stroke-width:1");
status = e.getStandardsStatus();
}
if (!makeTargets)
xml.attribute("id", "n" + (++nc));
else
xml.attribute("id", item.getId());
xml.element("rect", null);
xml.attribute("x1", Double.toString(item.left));
xml.attribute("y1", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
xml.attribute("x2", Double.toString(item.left + item.width));
xml.attribute("y2", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
xml.attribute("style", "stroke:dimgrey;stroke-width:1");
xml.attribute("id", "n" + (++nc));
xml.element("line", null);
xml.attribute("x", Double.toString(item.left + item.width / 2));
xml.attribute("y", Double.toString(item.top + HEADER_HEIGHT));
xml.attribute("fill", "black");
if (isRoot)
xml.attribute("class", "diagram-class-title diagram-class-resource");
else
xml.attribute("class", "diagram-class-title");
if (link) {
xml.attribute("id", "n" + (++nc));
if (e.isAbstractType()) {
xml.attribute("style", "font-style: italic");
}
xml.enter("text");
xml.attribute("xlink:href", makeRel(definitions.getSrcFile(tn) + ".html#" + tn));
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.text(tn);
xml.exit("a");
if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
xml.text(" ");
xml.attribute("xlink:href", makeRel("uml.html#interface"));
xml.enter("a");
xml.text("«Interface»");
xml.exit("a");
}
xml.exit("text");
} else if (isRoot) {
xml.attribute("id", "n" + (++nc));
if (e.isAbstractType()) {
xml.attribute("style", "font-style: italic");
}
xml.enter("text");
xml.text(tn);
if (Utilities.noString(e.typeCode())) {
xml.text(" \u00ABResource\u00BB");
} else {
xml.attribute("class", "diagram-class-title-link");
xml.enter("tspan");
xml.text(" (");
if ("Logical".equals(e.typeCode()))
xml.attribute("xlink:href", prefix + definitions.getBaseLink());
else
xml.attribute("xlink:href", prefix + definitions.getSrcFile(e.typeCode()) + ".html#" + e.typeCode());
xml.attribute("class", "diagram-class-reference");
xml.attribute("id", "n" + (++nc));
xml.attribute("style", "font-style: italic");
if ("Logical".equals(e.typeCode())) {
xml.element("a", "Base");
} else {
xml.element("a", e.typeCode());
}
xml.text(")");
xml.exit("tspan");
}
if ("Logical".equals(e.typeCode())) {
xml.text(" ");
xml.attribute("xlink:href", makeRel("uml.html#pattern"));
xml.enter("a");
xml.text("«Pattern»");
xml.exit("a");
}
if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
xml.text(" ");
xml.attribute("xlink:href", makeRel("uml.html#interface"));
xml.enter("a");
xml.text("«Interface»");
xml.exit("a");
}
xml.exit("text");
} else if (e.hasStatedType()) {
xml.attribute("id", "n" + (++nc));
xml.element("text", e.getStatedType());
} else {
xml.attribute("id", "n" + (++nc));
xml.element("text", tn);
}
if (attributes) {
if (primitive != null) {
if (primitive instanceof PrimitiveType)
addValueAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT, getXsi(primitive).split("\\|"));
} else {
int i = 0;
for (ElementDefn c : e.getElements()) {
if (isAttribute(c)) {
i++;
addAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT * i, c, path, LINE_HEIGHT, item.width);
String[] texts = textForAttribute(c);
i = i + texts.length - 1;
}
}
}
}
xml.exit("g");
if (attributes) {
for (ElementDefn c : e.getElements()) {
if (!isAttribute(c)) {
if (Utilities.noString(c.typeCode()) || !c.typeCode().startsWith("@")) {
links.add(new Link(item, drawClass(xml, c, false, resource, false, path + "." + c.getName(), null, status), LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
} else {
ClassItem target = getItemForPath(resource, c.typeCode().substring(1));
links.add(new Link(item, target, LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
}
}
}
}
return item;
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class SvgGenerator method drawElement.
private ClassItem drawElement(XMLWriter xml, String[] classNames) throws Exception {
// classNames.length == 1 && classNames[0].equals("Base");
boolean onlyElement = false;
if (classNames != null) {
for (String cn : classNames) {
if (definitions.getPrimitives().containsKey(cn)) {
DefinedCode cd = definitions.getPrimitives().get(cn);
ElementDefn fake = fakes.get(cn);
if (cd instanceof DefinedStringPattern) {
links.add(new Link(classes.get(fakes.get(((DefinedStringPattern) cd).getBase())), drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
} else {
ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "PrimitiveType"));
if (parent == null) {
drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
} else {
links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
}
}
} else if ("xhtml".equals(cn)) {
DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
ElementDefn fake = fakes.get(cn);
ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "DataType"));
if (parent == null) {
drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
} else {
links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
}
} else if (definitions.getConstraints().containsKey(cn)) {
ProfiledType cd = definitions.getConstraints().get(cn);
ElementDefn fake = fakes.get(cn);
ClassItem parent = classes.get(definitions.getElementDefn(cd.getBaseType()));
links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, null, StandardsStatus.NORMATIVE), LinkType.CONSTRAINT, null, null, PointKind.unknown, null, null));
} else if (definitions.getPrimitives().containsKey(cn)) {
DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
ElementDefn fake = fakes.get(cn);
// links.add(new Link(item,
// , LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
} else if (!onlyElement) {
ElementDefn e = definitions.getElementDefn(cn);
ClassItem parent = Utilities.noString(e.typeCode()) ? null : classes.get(definitions.getElementDefn(e.typeCode()));
if (parent == null) {
drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus());
} else {
links.add(new Link(parent, drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus()), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
}
}
}
}
return null;
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class SvgGenerator method determineMetrics.
private Point determineMetrics(String[] classNames) throws Exception {
double width = textWidth("Element") * 1.8;
double height = HEADER_HEIGHT + GAP_HEIGHT * 2;
// if ("true".equals(ini.getStringProperty("diagram", "element-attributes"))) {
// height = height + LINE_HEIGHT + GAP_HEIGHT;
// width = textWidth("extension : Extension 0..*");
// }
Point p = new Point(0, 0, PointKind.unknown);
ClassItem item = new ClassItem(p.x, p.y, width, height, id);
classes.put(null, item);
double x = item.right() + MARGIN_X;
double y = item.bottom() + MARGIN_Y;
if (classNames != null) {
for (String cn : classNames) {
if (definitions.getPrimitives().containsKey(cn)) {
DefinedCode cd = definitions.getPrimitives().get(cn);
ElementDefn fake = new ElementDefn();
fake.setName(cn);
fakes.put(cn, fake);
if (cd instanceof DefinedStringPattern)
p = determineMetrics(fake, classes.get(fakes.get(((DefinedStringPattern) cd).getBase())), cn, false, cd);
else
p = determineMetrics(fake, item, cn, false, cd);
} else if ("xhtml".equals(cn)) {
ElementDefn fake = new ElementDefn();
fake.setName("xhtml");
fakes.put("xhtml", fake);
DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
p = determineMetrics(fake, item, cn, false, cd);
} else if (definitions.getConstraints().containsKey(cn)) {
ProfiledType cd = definitions.getConstraints().get(cn);
ElementDefn ed = definitions.getElementDefn(cd.getBaseType());
ClassItem parentClss = classes.get(ed);
ElementDefn fake = new ElementDefn();
fake.setName(cn);
fakes.put(cn, fake);
p = determineMetrics(fake, parentClss, cn, false, null);
} else {
ElementDefn c = definitions.getElementDefn(cn);
p = determineMetrics(c, item, 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);
}
Aggregations