use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class ExampleAdorner method getState.
@Override
public XhtmlGeneratorAdornerState getState(XhtmlGenerator ref, XhtmlGeneratorAdornerState state, Element node) throws Exception {
if (state == null) {
if (node == null)
return new ExampleAdornerState(State.Unknown, "", null, "", "");
else if (definitions.hasResource(node.getLocalName()))
return new ExampleAdornerState(State.Element, node.getLocalName(), definitions.getResourceByName(node.getLocalName()).getRoot(), "", "");
else
return new ExampleAdornerState(State.Unknown, "", null, "", "");
} else {
ExampleAdornerState s = (ExampleAdornerState) state;
if (s.getState() == State.Element) {
if (s.definition == null) {
System.out.println("??");
}
if (// account for extra element
s.definition != null && "Resource".equals(s.definition.typeCode()) && (s.getPath().endsWith(".entry.resource") || s.getPath().endsWith(".contained")) && definitions.isResource(node.getNodeName()))
return new ExampleAdornerState(State.Element, s.getPath(), definitions.getResourceByName(node.getNodeName()).getRoot(), "", "");
String p = s.getPath() + "." + node.getNodeName();
ElementDefn e = s.getDefinition().getElementByName(node.getLocalName(), true, definitions, "adorn example", false);
if (e == null && definitions.hasElementDefn(s.getDefinition().typeCodeNoParams())) {
// well, we see if it's inherited...
ElementDefn t = definitions.getElementDefn(s.getDefinition().typeCodeNoParams());
while (t != null && e == null) {
e = t.getElementByName(node.getLocalName(), true, definitions, "adorn example", false);
if (e != null)
p = t.getName() + "." + e.getName();
else if (definitions.hasElementDefn(t.typeCodeNoParams()))
t = definitions.getElementDefn(t.typeCodeNoParams());
else
t = null;
}
} else if (e != null)
p = s.getPath() + "." + e.getName();
if (e == null)
return new ExampleAdornerState(State.Unknown, s.getPath(), null, "", "");
if (!e.isBaseResourceElement() && e.typeCode().contains("Reference") && !e.typeCode().contains("CodeableReference"))
return new ExampleAdornerState(State.Reference, p, e, "", "");
else if (!e.isBaseResourceElement() && e.typeCode().contains("canonical"))
return new ExampleAdornerState(State.Reference, p, e, "", "");
else if (!e.isBaseResourceElement() && e.typeCode().equals("uri"))
return new ExampleAdornerState(State.Reference, p, e, "", "");
else
return new ExampleAdornerState(State.Element, p, e, "", "");
} else if (s.getState() == State.Reference) {
if (node.getLocalName().equals("reference")) {
String type = extractType(node.getAttribute("value"));
String id = extractId(node.getAttribute("value"), type);
if (id == null)
return new ExampleAdornerState(State.Element, s.getPath() + ".reference", null, "", "");
ResourceDefn r = definitions.getResourceByName(type);
if (r == null)
throw new Exception("unable to find type " + type);
for (Example e : r.getExamples()) {
if (id.equals(e.getId()))
if (Utilities.noString(e.getIg())) {
return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + e.getTitle() + ".xml.html\">", "</a>");
} else {
ImplementationGuideDefn ig = definitions.getIgs().get(e.getIg());
return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + ig.getPrefix() + e.getTitle() + ".xml.html\">", "</a>");
}
if (e.getXml() != null && e.getXml().getDocumentElement().getLocalName().equals("feed")) {
List<Element> entries = new ArrayList<Element>();
XMLUtil.getNamedChildren(e.getXml().getDocumentElement(), "entry", entries);
String url = "http://hl7.org/fhir/" + type + "/" + id;
for (Element c : entries) {
String t = XMLUtil.getNamedChild(c, "id").getAttribute("value");
if (url.equals(t))
return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + e.getTitle() + ".xml.html#" + id + "\">", "</a>");
}
}
}
return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<font color=\"red\">", "</font>");
} else
return new ExampleAdornerState(State.Reference, s.getPath(), s.getDefinition(), "", "");
} else
// else
return new ExampleAdornerState(State.Unknown, s.getPath(), null, "", "");
}
}
use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class PageProcessor method produceProfiles.
private String produceProfiles(ResourceDefn resource) {
int count = 0;
Map<String, CSPair> map = new HashMap<String, CSPair>();
for (Profile ap : resource.getConformancePackages()) {
for (ConstraintStructure cs : ap.getProfiles()) {
if (coversResource(cs, resource.getName()))
map.put(cs.getTitle(), new CSPair(ap, cs));
}
}
for (Profile ap : definitions.getPackList()) {
for (ConstraintStructure cs : ap.getProfiles()) {
if (coversResource(cs, resource.getName()))
map.put(cs.getTitle(), new CSPair(ap, cs));
}
}
StringBuilder b = new StringBuilder();
for (String s : sorted(map.keySet())) {
CSPair cs = map.get(s);
ImplementationGuideDefn ig = definitions.getIgs().get(cs.p.getCategory());
if (ig == null) {
throw new FHIRException("The profile " + cs.cs.getId() + " is not registered in an IG");
}
count++;
b.append(" <tr>\r\n");
String ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.cs.getId() + ".html";
b.append(" <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.cs.getTitle())).append("</a></td>\r\n");
b.append(" <td>").append(Utilities.escapeXml(cs.p.getDescription())).append("</td>\r\n");
ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.p.getId().toLowerCase() + ".html";
b.append(" <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.p.getTitle())).append("</a></td>\r\n");
b.append(" </tr>\r\n");
}
if (count == 0)
return "<p>No Profiles defined for this resource</p>";
return "<table class=\"list\">\r\n" + " <tr><td><b>Profile</b></td><td><b>Description</b></td><td><b>Context</b></td></tr>\r\n" + b.toString() + "</table>\r\n";
}
use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class PageProcessor method genChoiceElementsJson.
public String genChoiceElementsJson() throws Exception {
StringBuilder b = new StringBuilder();
for (String s : sorted(definitions.getTypes().keySet())) {
ElementDefn t = definitions.getTypes().get(s);
buildChoiceElementList(b, s, t);
}
for (String s : sorted(definitions.getResources().keySet())) {
ResourceDefn t = definitions.getResources().get(s);
buildChoiceElementList(b, s, t.getRoot());
}
return "{\r\n \"elements\" : {\r\n" + b.toString() + "\r\n }\r\n}\r\n";
}
use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class PageProcessor method genLogicalAnalysis.
private String genLogicalAnalysis(ResourceDefn logical, String genlevel) throws FHIRException, IOException {
IniFile ini = new IniFile(Utilities.path(getFolders().srcDir, logical.getName(), logical.getName() + "-tasks.ini"));
String url = logical.getMappingUrl();
Map<ElementDefn, StringBuilder> bm = new HashMap<>();
List<ElementDefn> elements = new ArrayList<ElementDefn>();
listAllElements(elements, logical.getRoot().getName(), logical.getRoot());
for (ElementDefn e : elements) {
StringBuilder b2 = new StringBuilder();
bm.put(e, b2);
}
boolean any = false;
for (String s : sorted(definitions.getResources().keySet())) {
ResourceDefn rd = definitions.getResourceByName(s);
StructureDefinition sd = rd.getProfile();
String code = null;
for (StructureDefinitionMappingComponent m : sd.getMapping()) {
if (m.getUri().equals(url))
code = m.getIdentity();
}
if (code != null) {
if (hasLogicalMapping(sd, logical, code)) {
any = true;
for (ElementDefn e : elements) {
StringBuilder b2 = bm.get(e);
populateLogicalMappingColumn(null, logical.getRoot().getName(), rd.getName().toLowerCase() + "-definitions.html#", e, sd, rd.getName(), code, url, b2, ini, e.getPath());
}
}
}
}
if (any) {
StringBuilder bx = new StringBuilder();
bx.append("<a name=\"mappings\"></a><h3>Mappings</h3>\r\n");
bx.append("<table class=\"grid\">\r\n");
for (ElementDefn e : elements) {
if (logical.getRoot().getElements().contains(e)) {
bx.append("<tr><td colspan=\"6\"><b><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">" + e.getPath() + "</a></b></td></tr>\r\n");
} else {
bx.append("<tr><td colspan=\"6\"><b><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">." + e.getPath() + "</a></b></td></tr>\r\n");
}
bx.append("<tr><td colspan=\"6\">" + e.getPath() + " : " + e.typeCode() + " [" + e.describeCardinality() + "]</td></tr>\r\n");
bx.append("<tr><td>Resource</td><td>Matches</td><td>Issues</td><td>Tasks</td><td>Status</td><td>Notes</td></tr>\r\n");
bx.append(bm.get(e).toString());
}
bx.append("</table>\r\n");
return bx.toString();
} else
return "";
}
use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class PageProcessor method genScList.
private String genScList(String path) throws Exception {
ResourceDefn r = definitions.getResourceByName(path.substring(0, path.indexOf(".")));
if (r == null)
throw new Exception("Unable to process sclist (1): " + path);
ElementDefn e = r.getRoot().getElementByName(definitions, path.substring(path.indexOf(".") + 1), true, false);
if (e == null)
throw new Exception("Unable to process sclist (2): " + path);
if (e.typeCode().equals("boolean"))
return "true | false";
else {
StringBuilder b = new StringBuilder();
boolean first = true;
for (ConceptSetComponent inc : e.getBinding().getValueSet().getCompose().getInclude()) {
CodeSystem cs = definitions.getCodeSystems().get(inc.getSystem());
if (cs != null) {
for (ConceptDefinitionComponent cc : cs.getConcept()) {
if (first)
first = false;
else
b.append(" | ");
b.append("<span title=\"" + cc.getDisplay() + ": " + Utilities.escapeXml(cc.getDefinition()) + "\">" + cc.getCode() + "</span>");
}
}
}
return b.toString();
}
}
Aggregations