use of org.hl7.fhir.r4.model.Reference in project kindling by HL7.
the class Publisher method genExampleUsage.
private String genExampleUsage(Example e, String prefix) {
if (e.getInbounds().isEmpty())
return "";
else {
StringBuilder b = new StringBuilder();
b.append("<p>\r\nOther examples that reference this example:</p>\r\n");
List<String> names = new ArrayList<String>();
for (Example x : e.getInbounds()) names.add(x.getResourceName() + ":" + x.getId());
Collections.sort(names);
for (String n : names) {
Example x = null;
for (Example y : e.getInbounds()) if (n.equals(y.getResourceName() + ":" + y.getId()))
x = y;
b.append("<li><a href=\"");
b.append(prefix);
if (x.getIg() != null) {
ImplementationGuideDefn ig = page.getDefinitions().getIgs().get(x.getIg());
if (ig != null && !ig.isCore()) {
b.append(ig.getCode());
b.append("/");
}
}
b.append(x.getTitle() + ".html");
b.append("\">");
b.append(x.getResourceName() + "/" + x.getName());
b.append("</a></li>\r\n");
}
b.append("</ul>\r\n");
return b.toString();
}
}
use of org.hl7.fhir.r4.model.Reference in project kindling by HL7.
the class Publisher method checkExampleLinks.
private void checkExampleLinks(List<ValidationMessage> errors, ResourceDefn r) throws Exception {
for (Example e : r.getExamples()) {
try {
if (e.getXml() != null) {
List<ExampleReference> refs = new ArrayList<ExampleReference>();
listLinks(e.getXml().getDocumentElement(), refs);
for (ExampleReference ref : refs) {
if (!ref.isExempt() && !resolveLink(ref, e)) {
String path = ref.getPath().replace("/f:", ".").substring(1) + " (example " + e.getTitle() + ")";
if (ref.hasType() && page.getDefinitions().hasResource(ref.getType())) {
errors.add(new ValidationMessage(Source.ExampleValidator, IssueType.BUSINESSRULE, -1, -1, path, "Unable to resolve example reference to " + ref.getRef() + " in " + e.getTitle() + " (Possible Ids: " + listTargetIds(ref.getType()) + ")", "Unable to resolve example reference to " + ref.getRef() + " in <a href=\"" + e.getTitle() + ".html" + "\">" + e.getTitle() + "</a> (Possible Ids: " + listTargetIds(ref.getType()) + ")", IssueSeverity.INFORMATION));
} else {
String regex = "((http|https)://([A-Za-z0-9\\\\\\/\\.\\:\\%\\$])*)?(" + page.pipeResources() + ")\\/" + FormatUtilities.ID_REGEX + "(\\/_history\\/" + FormatUtilities.ID_REGEX + ")?";
if (ref.getRef().matches(regex)) {
errors.add(new ValidationMessage(Source.ExampleValidator, IssueType.BUSINESSRULE, -1, -1, path, "Unable to resolve example reference " + ref.getRef() + " in " + e.getTitle(), "Unable to resolve example reference " + ref.getRef() + " in <a href=\"" + e.getTitle() + ".html" + "\">" + e.getTitle() + "</a>", IssueSeverity.INFORMATION));
} else {
errors.add(new ValidationMessage(Source.ExampleValidator, IssueType.BUSINESSRULE, -1, -1, path, "Unable to resolve invalid example reference " + ref.getRef() + " in " + e.getTitle(), "Unable to resolve invalid example reference " + ref.getRef() + " in <a href=\"" + e.getTitle() + ".html" + "\">" + e.getTitle() + "</a>", IssueSeverity.WARNING));
}
}
// System.out.println("unresolved reference "+ref.getRef()+" at "+path);
}
}
}
} catch (Exception ex) {
throw new Exception("Error checking example " + e.getTitle() + ":" + ex.getMessage(), ex);
}
}
}
use of org.hl7.fhir.r4.model.Reference in project kindling by HL7.
the class PageProcessor method genDTCodes.
private String genDTCodes() {
StringBuilder html = new StringBuilder();
List<String> names = new ArrayList<String>();
names.addAll(definitions.getTypes().keySet());
names.addAll(definitions.getInfrastructure().keySet());
Collections.sort(names);
for (String n : names) {
if (!definitions.dataTypeIsSharedInfo(n)) {
ElementDefn c = definitions.getTypes().get(n);
if (c == null)
c = definitions.getInfrastructure().get(n);
if (c.getName().equals("Extension"))
html.append(" <tr><td><a href=\"extensibility.html\">" + c.getName() + "</a></td><td>" + Utilities.escapeXml(c.getDefinition()) + "</td></tr>");
else if (c.getName().equals("Narrative"))
html.append(" <tr><td><a href=\"narrative.html#" + c.getName() + "\">" + c.getName() + "</a></td><td>" + Utilities.escapeXml(c.getDefinition()) + "</td></tr>");
else if (c.getName().equals("Reference"))
html.append(" <tr><td><a href=\"references.html#" + c.getName() + "\">" + c.getName() + "</a></td><td>" + Utilities.escapeXml(c.getDefinition()) + "</td></tr>");
else if (c.getName().equals("canonical"))
html.append(" <tr><td><a href=\"references.html#" + c.getName() + "\">" + c.getName() + "</a></td><td>" + Utilities.escapeXml(c.getDefinition()) + "</td></tr>");
else
html.append(" <tr><td><a href=\"datatypes.html#" + c.getName() + "\">" + c.getName() + "</a></td><td>" + Utilities.escapeXml(c.getDefinition()) + "</td></tr>");
}
}
return html.toString();
}
use of org.hl7.fhir.r4.model.Reference in project kindling by HL7.
the class BookMaker method fixReferences.
private void fixReferences(XhtmlNode parent, XhtmlNode node, String name) throws Exception {
List<XhtmlNode> wantDelete = new ArrayList<XhtmlNode>();
for (XhtmlNode child : node.getChildNodes()) {
if (child.getNodeType() == NodeType.Element) {
if ("index-only-no-book".equals(child.getAttribute("class")))
wantDelete.add(child);
else
fixReferences(node, child, name);
}
}
for (XhtmlNode c : wantDelete) node.getChildNodes().remove(c);
if (node.getName().equals("a")) {
if (node.getAttributes().containsKey("name")) {
String lname = node.getAttributes().get("name");
node.getAttributes().put("name", name + "." + lname);
// System.out.println("found anchor "+name+"."+lname);
} else if (node.getAttribute("href") != null || node.getAttributes().get("xlink:href") != null) {
String s = node.getAttributes().get("href");
if (s == null || s.length() == 0)
s = node.getAttributes().get("xlink:href");
if (s == null || s.length() == 0)
throw new Error("empty \"href\" element in \"a\" tag around " + parent.allText());
if (s.startsWith("#")) {
s = "#" + name + "." + s.substring(1);
} else if (s.startsWith("http:") || s.startsWith("https:") || s.startsWith("ftp:") || s.startsWith("mailto:")) {
// s = s;
} else {
int i = s.indexOf('.');
if (i == -1)
throw new Error("unable to understand ref: '" + s + "' on '" + node.allText() + "'");
if (s.contains("#")) {
int j = s.indexOf('#');
s = "#" + s.substring(0, i) + "." + s.substring(j + 1);
} else if (s.endsWith(".html")) {
s = "#" + s.substring(0, i);
} else {
if (!s.endsWith(".zip") && !s.endsWith(".xsd") && !s.endsWith(".xml") && !s.endsWith(".json") && !s.endsWith(".png") && !s.endsWith(".xml") && !s.endsWith(".eap") && !s.endsWith(".xmi")) {
System.out.println("odd ref: " + s + " in " + node.allText());
// s = s;
} else {
// actually, what we want to do is do what?
// System.out.println("ref to remove: "+s+" in "+node.allText());
// Utilities.copyFile(new File(page.getFolders().dstDir+s), new File(targetBin+File.separatorChar+s));
// s = "http://hl7.org/documentcenter/public/standards/FHIR"+DSTU_PATH_PORTION+"/v"+page.getVersion()+"/"+s;
}
}
}
node.getAttributes().put("href", s);
if (s.startsWith("http") && parent != null && !node.allText().equals(s)) {
node.addText(" (" + s + ") ");
}
// System.out.println("reference to "+s);
}
}
}
use of org.hl7.fhir.r4.model.Reference in project kindling by HL7.
the class TypeParser method convert.
public List<TypeRefComponent> convert(IWorkerContext context, String path, List<TypeRef> types, boolean resource, ElementDefinition ed) throws Exception {
List<TypeRefComponent> list = new ArrayList<TypeRefComponent>();
for (TypeRef t : types) {
// Expand any Resource(A|B|C) references
if (t.hasParams() && !("Reference".equals(t.getName()) || "canonical".equals(t.getName()))) {
throw new Exception("Only resource references can specify parameters. Path " + path);
}
if (t.getParams().size() > 0) {
if (t.getProfile() != null && t.getParams().size() != 1) {
throw new Exception("Cannot declare profile on a resource reference declaring multiple resource types. Path " + path);
}
if (t.getProfile() != null) {
TypeRefComponent childType = getTypeComponent(list, t.getName());
if (t.getVersioning() != null)
childType.setVersioning(t.getVersioning());
if (t.getName().equals("Reference") || t.getName().equals("canonical"))
childType.addTargetProfile(t.getProfile());
else
childType.addProfile(t.getProfile());
} else
for (String param : t.getParams()) {
TypeRefComponent childType = getTypeComponent(list, t.getName());
if (t.getVersioning() != null)
childType.setVersioning(t.getVersioning());
String p = "Any".equals(param) ? "Resource" : param;
if (t.getName().equals("Reference") || t.getName().equals("canonical"))
childType.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
else
childType.addProfile("http://hl7.org/fhir/StructureDefinition/" + p);
}
} else if (t.isWildcardType()) {
// this list is filled out manually because it may be running before the types referred to have been loaded
for (String n : TypesUtilities.wildcardTypes(version)) {
TypeRefComponent tc = new TypeRefComponent().setCode(n);
if (t.getVersioning() != null)
tc.setVersioning(t.getVersioning());
list.add(tc);
}
} else if (Utilities.noString(t.getName()) && t.getProfile() != null) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, t.getProfile());
TypeRefComponent tc = getTypeComponent(list, sd != null ? sd.getType() : t.getName());
if (t.getVersioning() != null)
tc.setVersioning(t.getVersioning());
if (t.getName().equals("Reference"))
tc.addTargetProfile(t.getProfile());
else
tc.addProfile(t.getProfile());
} else if (t.getName().startsWith("=")) {
if (resource)
list.add(new TypeRefComponent().setCode("BackboneElement"));
else
list.add(new TypeRefComponent().setCode("Element"));
ToolingExtensions.addStringExtension(ed, "http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name", t.getName().substring(1));
} else {
StructureDefinition sd = context.fetchTypeDefinition(t.getName());
if (sd == null)
throw new Exception("Unknown type '" + t.getName() + "'");
TypeRefComponent tc = getTypeComponent(list, sd.getType());
if (t.getVersioning() != null)
tc.setVersioning(t.getVersioning());
if (t.getName().equals("Reference")) {
if (t.hasProfile())
tc.addTargetProfile(t.getProfile());
} else if (t.hasProfile())
tc.addProfile(t.getProfile());
}
}
// no duplicates
for (TypeRefComponent tr1 : list) {
for (TypeRefComponent tr2 : list) {
if (tr1 != tr2) {
if (tr1.getWorkingCode().equals(tr2.getWorkingCode()))
throw new Exception("duplicate code " + tr1.getWorkingCode());
}
}
}
return list;
}
Aggregations