use of org.hl7.fhir.definitions.model.DefinedCode in project kindling by HL7.
the class ValueSetGenerator method genResourceTypes.
private void genResourceTypes(ValueSet vs) {
if (!vs.hasCompose())
vs.setCompose(new ValueSetComposeComponent());
vs.getCompose().addInclude().setSystem("http://hl7.org/fhir/resource-types");
vs.setUserData("filename", "valueset-" + vs.getId());
if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType("fhir"));
} else {
String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
if (!ec.equals("fhir"))
System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 7: is " + ec + ", want to set to " + "fhir");
}
vs.setUserData("path", "valueset-" + vs.getId() + ".html");
CodeSystem cs = new CodeSystem();
CodeSystemConvertor.populate(cs, vs);
cs.setUrl("http://hl7.org/fhir/resource-types");
cs.setVersion(version);
cs.setCaseSensitive(true);
cs.setContent(CodeSystemContentMode.COMPLETE);
definitions.getCodeSystems().see(cs, packageInfo);
List<String> codes = new ArrayList<String>();
codes.addAll(definitions.getBaseResources().keySet());
codes.addAll(definitions.getKnownResources().keySet());
Collections.sort(codes);
for (String s : codes) {
DefinedCode rd = definitions.getKnownResources().get(s);
ConceptDefinitionComponent c = cs.addConcept();
Map<String, String> t;
if (rd == null) {
t = translator.translations(s);
c.setCode(s);
c.setDisplay(definitions.getBaseResources().get(s).getName());
c.setDefinition((definitions.getBaseResources().get(s).isAbstract() ? "--- Abstract Type! ---" : "") + definitions.getBaseResources().get(s).getDefinition());
} else {
t = translator.translations(rd.getCode());
c.setCode(rd.getCode());
c.setDisplay(rd.getCode());
c.setDefinition(rd.getDefinition());
}
if (t != null) {
for (String l : t.keySet()) c.addDesignation().setLanguage(l).setValue(t.get(l)).getUse().setSystem("http://terminology.hl7.org/CodeSystem/designation-usage").setCode("display");
}
}
markSpecialStatus(vs, cs, true);
}
use of org.hl7.fhir.definitions.model.DefinedCode 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.DefinedCode 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.DefinedCode 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);
}
use of org.hl7.fhir.definitions.model.DefinedCode 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