use of org.hl7.fhir.r4b.model.Reference in project kindling by HL7.
the class TurtleSpecGenerator method renderType.
private int renderType(int indent, int w, TypeRef t) throws IOException {
if (t.isXhtml())
write("fhir:value \"[escaped xhtml]\"^^xsd:string");
else if (t.getName().startsWith("@"))
write("<a href=\"#ttl-" + t.getName().substring(1) + "\"><span style=\"color: DarkViolet\">See " + t.getName().substring(1) + "</span></a>");
else if (definitions.getConstraints().containsKey(t.getName())) {
ProfiledType pt = definitions.getConstraints().get(t.getName());
write("<a href=\"" + (dtRoot + definitions.getSrcFile(pt.getBaseType()) + ".html#" + pt.getBaseType() + "\">" + pt.getBaseType()) + "</a>");
w = w + pt.getBaseType().length() + 2;
write("(<a style=\"color:navy\" href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>)");
} else
write("<a href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>");
if (t.hasParams()) {
write("(");
boolean firstp = true;
List<String> ap = new ArrayList<>();
for (String p : t.getParams()) {
if (definitions.hasLogicalModel(p))
ap.addAll(definitions.getLogicalModel(p).getImplementations());
else
ap.add(p);
}
Collections.sort(ap);
for (String p : ap) {
if (!firstp) {
write("|");
w++;
}
// again, p.length() could be wrong if this is an extension, but then it won't wrap
if (w + p.length() > 80) {
write("\r\n ");
for (int j = 0; j < indent; j++) write(" ");
w = indent + 2;
}
w = w + p.length();
// TODO: Display action and/or profile information
if (p.equals("Any")) {
write("<a href=\"" + prefix + "resourcelist.html" + "\">" + p + "</a>");
} else if (t.getName().equals("Reference") && t.getParams().size() == 1 && !Utilities.noString(t.getProfile()))
write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
else
write("<a href=\"" + (dtRoot + definitions.getSrcFile(p) + ".html#" + p) + "\">" + p + "</a>");
firstp = false;
}
write(")");
w++;
}
return w;
}
use of org.hl7.fhir.r4b.model.Reference in project kindling by HL7.
the class XmlSpecGenerator method writeTypeLinks.
private int writeTypeLinks(ElementDefn elem, int indent) throws Exception {
write(" <span style=\"color: darkgreen\">");
int i = 0;
// this is wrong if the type is an attribute, but the wrapping concern shouldn't apply in this case, so this is ok
int w = indent + 12 + elem.getName().length();
for (TypeRef t : elem.getTypes()) {
if (i > 0) {
write("|");
w++;
}
if (w + t.getName().length() > 80) {
write("\r\n ");
for (int j = 0; j < indent; j++) write(" ");
w = indent + 2;
}
// again, could be wrong if this is an extension, but then it won't wrap
w = w + t.getName().length();
if (t.isXhtml() || t.getName().equals("list"))
write(t.getName());
else if (t.getName().equals("Extension") && t.getParams().size() == 0 && !Utilities.noString(t.getProfile()))
write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
else if (definitions.getConstraints().containsKey(t.getName())) {
ProfiledType pt = definitions.getConstraints().get(t.getName());
write("<a href=\"" + (dtRoot + definitions.getSrcFile(pt.getBaseType()) + ".html#" + pt.getBaseType() + "\">" + pt.getBaseType()) + "</a>");
w = w + pt.getBaseType().length() + 2;
write("(<a style=\"color:navy\" href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>)");
} else
write("<a href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>");
if (t.hasParams()) {
write("(");
boolean firstp = true;
List<String> ap = new ArrayList<>();
for (String p : t.getParams()) {
if (definitions.hasLogicalModel(p))
ap.addAll(definitions.getLogicalModel(p).getImplementations());
else
ap.add(p);
}
Collections.sort(ap);
for (String p : ap) {
if (!firstp) {
write("|");
w++;
}
// again, p.length() could be wrong if this is an extension, but then it won't wrap
if (w + p.length() > 80) {
write("\r\n ");
for (int j = 0; j < indent; j++) write(" ");
w = indent + 2;
}
w = w + p.length();
// TODO: Display action and/or profile information
if (p.equals("Any")) {
write("<a href=\"" + prefix + "resourcelist.html" + "\">" + p + "</a>");
} else if (t.getName().equals("Reference") && t.getParams().size() == 1 && !Utilities.noString(t.getProfile()))
write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
else
write("<a href=\"" + (dtRoot + definitions.getSrcFile(p) + ".html#" + p) + "\">" + p + "</a>");
firstp = false;
}
write(")");
w++;
}
i++;
}
write("</span>");
return w;
}
use of org.hl7.fhir.r4b.model.Reference in project kindling by HL7.
the class XSDBaseGenerator method generateElement.
private void generateElement(ElementDefn root, ElementDefn e, String paramType, Map<String, String> rules) throws Exception {
List<TypeRef> types = e.getTypes();
if (types.size() > 1 || (types.size() == 1 && types.get(0).isWildcardType())) {
if (!e.getName().contains("[x]"))
throw new Exception("Element has multiple types as a choice doesn't have a [x] in the element name '" + e.getName() + "' in resource " + root.getName());
if ((types.size() == 1 && types.get(0).isWildcardType())) {
generateAny(root, e, e.getName().replace("[x]", ""), null);
} else {
String close = " minOccurs=\"0\">";
;
if (!forCodeGeneration) {
write(" <xs:choice minOccurs=\"" + checkRule(e.getMinCardinality().toString(), e.getName() + ".min", rules) + "\" maxOccurs=\"1\">\r\n");
if (e.hasDefinition()) {
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
}
close = "/>";
}
for (TypeRef t : types) {
String type = encodeType(e, t, true);
String name = e.getName().substring(0, e.getName().length() - 3) + nameForType(type);
write(" <xs:element name=\"" + name + "\" type=\"" + type + "\" ");
if (e.unbounded())
write(" maxOccurs=\"" + checkRule("unbounded", e.getName() + ".max", rules) + "\"" + close + "\r\n");
else
write(" maxOccurs=\"" + checkRule("1", e.getName() + ".max", rules) + "\"" + close + "\r\n");
if (forCodeGeneration) {
write(" <xs:annotation>\r\n");
if (e.hasDefinition()) {
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + " (choose any one of " + e.getName().replace("[x]", "") + "*, but only one)</xs:documentation>\r\n");
} else {
write(" <xs:documentation xml:lang=\"en\">(choose any one of " + e.getName().replace("[x]", "") + "*, but only one)</xs:documentation>\r\n");
}
write(" </xs:annotation>\r\n");
write(" </xs:element>\r\n");
}
}
if (!forCodeGeneration)
write(" </xs:choice>\r\n");
}
} else {
write(" ");
if ("extension".equals(e.getName()))
write("<xs:element name=\"" + e.getName() + "\" type=\"Extension\" ");
else if ("div".equals(e.getName()) && e.typeCode().equals("xhtml"))
write("<xs:element ref=\"xhtml:div\" ");
else if (e.usesCompositeType()) {
ElementDefn ref = root.getElementByName(definitions, e.typeCode().substring(1), true, false, null);
String rtn = this.types.get(ref);
if (rtn == null)
throw new Exception("logic error in schema generator (null composite reference in " + types.toString() + ")");
write("<xs:element name=\"" + e.getName() + "\" type=\"" + rtn + "\" ");
} else if (types.size() == 0 && e.getElements().size() > 0) {
String tn = root.getName() + "." + Utilities.capitalize(e.getName());
int i = 0;
while (typenames.contains(tn)) {
i++;
tn = root.getName() + "." + Utilities.capitalize(e.getName()) + Integer.toString(i);
}
write("<xs:element name=\"" + e.getName() + "\" type=\"" + tn + "\" ");
structures.put(tn, e);
this.types.put(e, tn);
typenames.add(tn);
} else if (types.size() == 1) {
if (types.get(0).isUnboundGenericParam() && paramType != null)
write("<xs:element name=\"" + e.getName() + "\" type=\"" + paramType + "\" ");
else if (!Utilities.noString(e.getRegex())) {
String tn = root.getName() + Utilities.capitalize(e.getName()) + "Type";
regexQueue.put(tn, e.getRegex());
write("<xs:element name=\"" + e.getName() + "\" type=\"" + tn + "\" ");
} else
write("<xs:element name=\"" + e.getName() + "\" type=\"" + encodeType(e, types.get(0), true) + "\" ");
} else
throw new Exception("how do we get here? " + e.getName() + " in " + root.getName() + " " + Integer.toString(types.size()));
write("minOccurs=\"" + checkRule(e.getMinCardinality().toString(), e.getName() + ".min", rules) + "\"");
if (e.unbounded())
write(" maxOccurs=\"" + checkRule("unbounded", e.getName() + ".max", rules) + "\"");
else
write(" maxOccurs=\"" + checkRule("1", e.getName() + ".max", rules) + "\"");
if (e.hasDefinition()) {
write(">\r\n");
write(" <xs:annotation>\r\n");
write(" <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + "</xs:documentation>\r\n");
write(" </xs:annotation>\r\n");
write(" </xs:element>\r\n");
} else {
write("/>\r\n");
}
}
}
use of org.hl7.fhir.r4b.model.Reference 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.r4b.model.Reference in project kindling by HL7.
the class ProfileGenerator method produceOpParam.
private void produceOpParam(String path, List<OperationDefinitionParameterComponent> opd, OperationParameter p, OperationParameterUse defUse) throws Exception {
OperationDefinitionParameterComponent pp = new OperationDefinitionParameterComponent();
pp.setName(p.getName());
if (path.contains("."))
pp.setUse(defUse);
else if (p.getUse().equals("in"))
pp.setUse(OperationParameterUse.IN);
else if (p.getUse().equals("out"))
pp.setUse(OperationParameterUse.OUT);
else
// but this is validated elsewhere
throw new Exception("Unable to determine parameter use: " + p.getUse() + " at " + path + "." + p.getName());
pp.setDocumentation(preProcessMarkdown(p.getDoc(), "Operation Parameter Doco"));
pp.setMin(p.getMin());
pp.setMax(p.getMax());
if (p.getBs() != null) {
if (p.getBs().hasMax())
throw new Error("Max binding not handled yet");
pp.setBinding(new OperationDefinitionParameterBindingComponent().setStrength(p.getBs().getStrength()).setValueSet(buildValueSetReference(p.getBs())));
if (!Utilities.noString(p.getBinding().getName())) {
pp.getBinding().addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName", new StringType(p.getBinding().getName()));
}
}
if (!Utilities.noString(p.getProfile())) {
pp.addTargetProfile(p.getProfile());
}
opd.add(pp);
if (p.getFhirType().equals("Tuple")) {
for (OperationParameter part : p.getParts()) {
produceOpParam(path + "." + p.getName(), pp.getPart(), part, pp.getUse());
}
} else {
List<TypeRef> trs = new TypeParser(version.toCode()).parse(p.getFhirType(), false, null, null, false);
if (trs.size() > 1) {
if (p.getSearchType() != null)
pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
pp.setType(Enumerations.FHIRAllTypes.fromCode("Element"));
for (TypeRef tr : trs) {
pp.addExtension(ToolingExtensions.EXT_ALLOWED_TYPE, new UriType(tr.getName()));
if (tr.getParams().size() > 0)
throw new Error("Multiple types for an operation parameter, where one is a reference, is not supported by the build tools");
}
} else {
TypeRef tr = trs.get(0);
if (definitions.getConstraints().containsKey(tr.getName())) {
ProfiledType pt = definitions.getConstraints().get(tr.getName());
pp.setType(Enumerations.FHIRAllTypes.fromCode(pt.getBaseType().equals("*") ? "Type" : pt.getBaseType()));
pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + pt.getName());
} else {
if (p.getSearchType() != null)
pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
pp.setType(Enumerations.FHIRAllTypes.fromCode(tr.getName().equals("*") ? "Type" : tr.getName()));
if (tr.getParams().size() == 1 && !tr.getParams().get(0).equals("Any"))
pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + tr.getParams().get(0));
}
}
}
}
Aggregations