use of org.hl7.fhir.r4.model.Extension in project kindling by HL7.
the class JsonSpecGenerator method generateCoreElemDetails.
private void generateCoreElemDetails(ElementDefn elem, int indent, String rootName, String pathName, boolean backbone, boolean last, int width, String en, TypeRef type, boolean doco) throws Exception {
if (elem.getName().equals("extension")) {
write(" (<a href=\"" + prefix + "extensibility.html\">Extensions</a> - see <a href=\"" + prefix + "json.html#extensions\">JSON page</a>)\r\n");
return;
}
if (elem.getName().equals("modifierExtension")) {
write(" (<a href=\"" + prefix + "extensibility.html#modifier\">Modifier Extensions</a> - see <a href=\"" + prefix + "json.html#modifier\">JSON page</a>)\r\n");
return;
}
// 1. name
for (int i = 0; i < indent; i++) {
write(" ");
}
if (defPage == null) {
if (elem.isModifier() || elem.isMustSupport())
write("\"<span style=\"text-decoration: underline\" title=\"" + Utilities.escapeXml(elem.getEnhancedDefinition()) + "\">");
else
write("\"<span title=\"" + Utilities.escapeXml(elem.getDefinition()) + "\">");
} else if (elem.isModifier() || elem.getMustSupport())
write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(elem.getEnhancedDefinition()) + "\" class=\"dict\"><span style=\"text-decoration: underline\">");
else
write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(elem.getDefinition()) + "\" class=\"dict\">");
if (defPage == null) {
write(en + "</span>");
} else if (elem.isModifier() || elem.getMustSupport())
write(en + "</span></a>");
else
write(en + "</a>");
write("\" : ");
// 2. value
boolean delayedCloseArray = false;
boolean sharedDT = definitions.dataTypeIsSharedInfo(elem.typeCode());
if (elem.getMaxCardinality() != null && elem.getMaxCardinality() > 1)
write("[");
if (elem.usesCompositeType()) {
write("{ <span style=\"color: darkgreen\">");
write("Content as for " + elem.typeCode().substring(1) + "</span> }");
} else if (type == null) {
// inline definition
assert (elem.getElements().size() > 0);
write("{");
delayedCloseArray = true;
} else if (type.isXhtml()) {
// element contains xhtml
write("\"(Escaped XHTML)\"");
} else if (definitions.getPrimitives().containsKey(type.getName()) && !type.hasParams()) {
if (!(type.getName().equals("integer") || type.getName().equals("boolean") || type.getName().equals("decimal")))
write("\"");
write("<<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(type.getName()) + ".html#" + type.getName()) + "\">" + type.getName() + "</a></span>>");
if (!(type.getName().equals("integer") || type.getName().equals("boolean") || type.getName().equals("decimal")))
write("\"");
} else {
write("{");
width = writeTypeLinks(elem, indent, type);
write(" }");
}
if (!delayedCloseArray && (elem.getMaxCardinality() != null && elem.getMaxCardinality() > 1))
write("]");
if (!last && !delayedCloseArray)
write(",");
if (!elem.hasFixed() && doco) {
write(" <span style=\"color: Gray\">//</span>");
// 3. optionality
writeCardinality(elem);
// 4. doco
write(" ");
if (elem.getName().equals("extension")) {
write(" <a href=\"" + prefix + "extensibility.html\"><span style=\"color: navy; opacity: 0.8\">See Extensions</span></a>");
} else if ("See Extensions".equals(elem.getShortDefn())) {
write(" <a href=\"" + prefix + "extensibility.html\"><span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(elem.getShortDefn()) + "</span></a>");
} else {
String ref = getBindingLink(elem);
write("<span style=\"color: navy; opacity: 0.8\"><a href=\"" + (Utilities.isAbsoluteUrl(ref) ? "" : prefix) + ref + "\" style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(elem.getShortDefn()) + "</a></span>");
}
}
if (elem.getMaxCardinality() != null && elem.getMaxCardinality() == 0)
write("</span>");
if (elem.getElements().size() > 0) {
write("\r\n");
int c = 0;
for (ElementDefn child : elem.getElements()) {
generateCoreElem(child, indent + 1, rootName, pathName + "." + en, backbone, ++c == elem.getElements().size());
}
for (int i = 0; i < indent; i++) {
write(" ");
}
}
if (elem.getElements().size() > 0) {
write("}");
if (delayedCloseArray && elem.getMaxCardinality() != null && elem.getMaxCardinality() > 1)
write("]");
if (!last && delayedCloseArray)
write(",");
}
write("\r\n");
}
use of org.hl7.fhir.r4.model.Extension in project kindling by HL7.
the class ProfileGenerator method convertElements.
public void convertElements(ElementDefn src, StructureDefinition ed, String path) throws Exception {
ElementDefinition dst = new ElementDefinition();
if (!ed.hasDifferential())
ed.setDifferential(new StructureDefinitionDifferentialComponent());
ed.getDifferential().getElement().add(dst);
String thisPath = path == null ? "Extension" : path;
dst.setId(thisPath);
dst.setPath(thisPath);
if (!Utilities.noString(src.getProfileName()))
dst.setSliceName(src.getProfileName());
dst.setShort(src.getShortDefn());
dst.setDefinition(preProcessMarkdown(src.getDefinition(), "Element Definition"));
dst.setComment(preProcessMarkdown(src.getComments(), "Element Comments"));
if (src.getMaxCardinality() != null) {
if (src.getMaxCardinality() == Integer.MAX_VALUE)
dst.setMax("*");
else
dst.setMax(src.getMaxCardinality().toString());
}
if (src.getMinCardinality() != null)
dst.setMin(src.getMinCardinality());
if (src.getFixed() != null)
dst.setFixed(src.getFixed());
if (src.hasMustSupport())
dst.setMustSupport(src.isMustSupport());
if (src.hasModifier())
dst.setIsModifier(src.isModifier());
if (dst.getIsModifier())
dst.setIsModifierReason(src.getModifierReason());
if (src.hasSummaryItem() && dst.getPath().contains("."))
dst.setIsSummaryElement(Factory.newBoolean(src.isSummary()));
for (Invariant id : src.getStatedInvariants()) dst.addCondition(id.getId());
// dDst.
for (TypeRef t : src.getTypes()) {
if (t.hasParams()) {
for (String tp : t.getParams()) {
if (definitions.hasLogicalModel(tp)) {
for (String tpn : definitions.getLogicalModel(tp).getImplementations()) {
ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
String pr = "http://hl7.org/fhir/StructureDefinition/" + tpn;
type.addTargetProfile(pr);
}
} else {
ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
String pr = t.hasProfile() ? t.getProfile() : // this should only happen if t.getParams().size() == 1
"http://hl7.org/fhir/StructureDefinition/" + (tp.equals("Any") ? "Resource" : tp);
if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("canonical") || type.getWorkingCode().equals("CodeableReference"))
type.addTargetProfile(pr);
else
type.addProfile(pr);
}
}
} else if (t.isWildcardType()) {
for (String n : TypesUtilities.wildcardTypes(version.toString())) dst.getType(n);
} else {
if (definitions != null && definitions.getConstraints().containsKey(t.getName())) {
ProfiledType ct = definitions.getConstraints().get(t.getName());
ElementDefinition.TypeRefComponent type = dst.getType(ct.getBaseType());
type.addProfile("http://hl7.org/fhir/StructureDefinition/" + ct.getName());
} else if ("Extension.url".equals(path)) {
// juat don't populate it
// ElementDefinition.TypeRefComponent tt = dst.addType();
// tt.setCodeElement(new UriType());
// tt.getFormatCommentsPre().add("Note: special primitive values do not have an assigned type. e.g. this is compiler magic. XML, JSON and RDF types provided by extension");
// ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_JSON_TYPE, "string");
// ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_XML_TYPE, "xs:anyURI");
// ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_RDF_TYPE, "xs:anyURI");
} else {
ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
if (t.hasProfile())
if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("CodeableReference"))
type.addTargetProfile(t.getProfile());
else
type.addProfile(t.getProfile());
}
}
}
if (definitions != null) {
// igtodo - catch this
for (String mu : definitions.getMapTypes().keySet()) {
if (src.hasMapping(mu)) {
addMapping(ed, dst, mu, src.getMapping(mu), null);
}
}
}
for (String in : src.getInvariants().keySet()) {
ElementDefinitionConstraintComponent con = new ElementDefinitionConstraintComponent();
Invariant inv = src.getInvariants().get(in);
con.setKey(inv.getId());
if (!con.hasKey()) {
extensionCounter++;
con.setKey("exd-" + Integer.toString(extensionCounter));
}
con.setRequirements(inv.getRequirements());
if (Utilities.noString(inv.getSeverity()))
con.setSeverity(ConstraintSeverity.ERROR);
else
con.setSeverity(ConstraintSeverity.fromCode(inv.getSeverity()));
con.setHuman(inv.getEnglish());
con.setXpath(inv.getXpath());
if (!"n/a".equals(inv.getExpression()))
con.setExpression(inv.getExpression());
dst.getConstraint().add(con);
}
if (src.hasBinding())
dst.setBinding(generateBinding(src.getBinding()));
if (src.getElements().isEmpty()) {
if (path == null)
throw new Exception("?error parsing extension");
} else {
ElementDefn url = src.getElements().get(0);
if (!url.getName().equals("url"))
throw new Exception("first child of extension should be 'url', not " + url.getName() + " for structure definition " + ed.getUrl());
convertElements(url, ed, thisPath + ".url");
// this pair might leave elements out of order, but we're going to sort them later
if (!hasValue(src)) {
ElementDefn value = new ElementDefn();
value.setName("value[x]");
value.setMinCardinality(0);
value.setMaxCardinality(0);
convertElements(value, ed, thisPath + ".value[x]");
} else {
ElementDefn ext = new ElementDefn();
// can't have an extension if you have a value
ext.setName("extension");
ext.setMaxCardinality(0);
convertElements(ext, ed, thisPath + ".extension");
}
if (src.getElements().size() == 2 && src.getElements().get(0).getName().equals("url") && src.getElements().get(1).getName().equals("value[x]")) {
ElementDefn value = src.getElements().get(1);
value.setMinCardinality(1);
convertElements(value, ed, thisPath + ".value[x]");
} else {
for (ElementDefn child : src.getElements()) {
if (child != url) {
if (child.getName().startsWith("value") && !child.getName().startsWith("valueSet"))
convertElements(child, ed, thisPath + "." + child.getName());
else {
if (child.getElements().size() == 0 || !child.getElements().get(0).getName().equals("url")) {
ElementDefn childUrl = new ElementDefn();
childUrl.setName("url");
childUrl.setXmlAttribute(true);
childUrl.getTypes().add(new TypeRef("uri"));
childUrl.setFixed(new UriType(child.getName()));
child.getElements().add(0, childUrl);
}
if (!hasValue(child)) {
ElementDefn value = new ElementDefn();
value.setName("value[x]");
value.setMinCardinality(0);
value.setMaxCardinality(0);
child.getElements().add(value);
}
convertElements(child, ed, thisPath + ".extension");
}
}
}
}
}
}
use of org.hl7.fhir.r4.model.Extension 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.r4.model.Extension in project kindling by HL7.
the class ProfileGenerator method generate.
public StructureDefinition generate(DefinedStringPattern type) throws Exception {
genUml(type);
StructureDefinition p = new StructureDefinition();
p.setId(type.getCode());
p.setUrl("http://hl7.org/fhir/StructureDefinition/" + type.getCode());
p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + type.getBase());
p.setType(type.getCode());
p.setDerivation(TypeDerivationRule.SPECIALIZATION);
p.setKind(StructureDefinitionKind.PRIMITIVETYPE);
p.setAbstract(false);
p.setUserData("filename", type.getCode().toLowerCase());
p.setUserData("path", "datatypes.html#" + type.getCode());
p.setFhirVersion(version);
p.setVersion(version.toCode());
ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
ToolResourceUtilities.updateUsage(p, "core");
p.setName(type.getCode());
p.setPublisher("HL7 FHIR Standard");
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
p.setDescription("Base StructureDefinition for " + type.getCode() + " type: " + type.getDefinition());
p.setDate(genDate.getTime());
p.setStatus(PublicationStatus.fromCode("active"));
Set<String> containedSlices = new HashSet<String>();
// first, the differential
p.setDifferential(new StructureDefinitionDifferentialComponent());
ElementDefinition ec1 = new ElementDefinition();
p.getDifferential().getElement().add(ec1);
ec1.setId(type.getCode());
ec1.setPath(type.getCode());
ec1.setShort("Primitive Type " + type.getCode());
ec1.setDefinition(type.getDefinition());
ec1.setComment(type.getComment());
ec1.setMin(0);
ec1.setMax("*");
ElementDefinition ec2 = new ElementDefinition();
p.getDifferential().getElement().add(ec2);
ec2.setId(type.getCode() + ".value");
ec2.setPath(type.getCode() + ".value");
ec2.addRepresentation(PropertyRepresentation.XMLATTR);
ec2.setShort("Primitive value for " + type.getCode());
ec2.setDefinition("Primitive value for " + type.getCode());
ec2.setMin(0);
ec2.setMax("1");
TypeRefComponent t = ec2.addType();
t.setCodeElement(new UriType());
t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (g)");
t.setCode(Constants.NS_SYSTEM_TYPE + type.getFHIRPathType());
ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, type.getCode());
if (!Utilities.noString(type.getRegex())) {
ToolingExtensions.addStringExtension(t, ToolingExtensions.EXT_REGEX, type.getRegex());
}
reset();
// now. the snapshot
p.setSnapshot(new StructureDefinitionSnapshotComponent());
ElementDefinition ecA = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
p.getSnapshot().getElement().add(ecA);
ecA.setId(type.getCode());
ecA.setPath(type.getCode());
ecA.setShort("Primitive Type " + type.getCode());
ecA.setDefinition(type.getDefinition());
ecA.setComment(type.getComment());
ecA.setMin(0);
ecA.setMax("*");
ecA.makeBase(type.getCode(), 0, "*");
addElementConstraints("Element", ecA);
ElementDefinition ecid = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
p.getSnapshot().getElement().add(ecid);
ecid.setId(type.getCode() + ".id");
ecid.setPath(type.getCode() + ".id");
ecid.addRepresentation(PropertyRepresentation.XMLATTR);
ecid.setDefinition("unique id for the element within a resource (for internal references)");
ecid.setMin(0);
ecid.setMax("1");
ecid.setShort("xml:id (or equivalent in JSON)");
TypeRefComponent tr = ecid.addType();
tr.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (h)");
tr.setCode(Constants.NS_SYSTEM_TYPE + "String");
ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "string");
ecid.makeBase("Element.id", 0, "1");
makeExtensionSlice("extension", p, p.getSnapshot(), null, type.getCode());
ElementDefinition ecB = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
p.getSnapshot().getElement().add(ecB);
ecB.setPath(type.getCode() + ".value");
ecB.setId(type.getCode() + ".value");
ecB.addRepresentation(PropertyRepresentation.XMLATTR);
ecB.setDefinition("Primitive value for " + type.getCode());
ecB.setShort("Primitive value for " + type.getCode());
ecB.setMin(0);
ecB.setMax("1");
ecB.makeBase(type.getBase() + ".value", 0, "1");
t = ecB.addType();
t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (i)");
t.setCode(Constants.NS_SYSTEM_TYPE + "String");
ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
if (!Utilities.noString(type.getRegex()))
ToolingExtensions.addStringExtension(t, ToolingExtensions.EXT_REGEX, type.getRegex());
// generateElementDefinition(ecB, ecA);
containedSlices.clear();
addElementConstraintToSnapshot(p);
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.addText("to do");
p.setText(new Narrative());
p.getText().setStatus(NarrativeStatus.GENERATED);
p.getText().setDiv(div);
checkHasTypes(p);
return p;
}
use of org.hl7.fhir.r4.model.Extension in project kindling by HL7.
the class ProfileGenerator method addExtensionConstraint.
private ElementDefinition addExtensionConstraint(StructureDefinition sd, ElementDefinition ed) {
if (!typeIsExtension(ed))
return ed;
if (hasConstraint(ed, "ext-1"))
return ed;
ElementDefinitionConstraintComponent inv = ed.addConstraint();
inv.setKey("ext-1");
inv.setSeverity(ConstraintSeverity.ERROR);
inv.setHuman("Must have either extensions or value[x], not both");
inv.setExpression("extension.exists() != value.exists()");
inv.setXpath("exists(f:extension)!=exists(f:*[starts-with(local-name(.), \"value\")])");
inv.setSource("http://hl7.org/fhir/StructureDefinition/Extension");
return ed;
}
Aggregations