use of org.hl7.fhir.r5.model.BackboneElement in project kindling by HL7.
the class PageProcessor method produceStructureDefinitionExamples.
private String produceStructureDefinitionExamples(ResourceDefn resource) throws Exception {
StringBuilder s = new StringBuilder();
s.append("<div id=\"tabs\">\r\n");
s.append("<ul>\r\n");
s.append(" <li><a href=\"#tabs-1\">Base Types</a></li>\r\n");
s.append(" <li><a href=\"#tabs-2\">Resources</a></li>\r\n");
s.append(" <li><a href=\"#tabs-3\">Constraints</a></li>\r\n");
s.append(" <li><a href=\"#tabs-4\">Extensions</a></li>\r\n");
s.append(" <li><a href=\"#tabs-5\">Examples</a></li>\r\n");
s.append("</ul>\r\n");
s.append("<div id=\"tabs-1\">\r\n");
// base types
s.append("<table class=\"list\">\r\n");
genStructureExampleCategory(s, "Abstract Types", "3");
genStructureExample(s, definitions.getElementLink(), "element.profile", "element", "Element");
genStructureExample(s, definitions.getBackboneLink(), "backboneelement.profile", "backboneelement", "BackBoneElement");
genStructureExample(s, "resource.html", "resource.profile", "resource", "Resource");
genStructureExample(s, "domainresource.html", "domainresource.profile", "domainresource", "DomainResource");
genStructureExampleCategory(s, "Primitive Types", "3");
List<String> names = new ArrayList<String>();
names.addAll(definitions.getPrimitives().keySet());
Collections.sort(names);
for (String n : names) {
DefinedCode dc = definitions.getPrimitives().get(n);
genStructureExample(s, "datatypes.html#" + dc.getCode(), dc.getCode().toLowerCase() + ".profile", dc.getCode().toLowerCase(), dc.getCode());
}
genStructureExampleCategory(s, "Data Types", "3");
names.clear();
names.addAll(definitions.getTypes().keySet());
names.addAll(definitions.getInfrastructure().keySet());
Collections.sort(names);
for (String n : names) {
org.hl7.fhir.definitions.model.TypeDefn t = definitions.getTypes().get(n);
if (t == null)
t = definitions.getInfrastructure().get(n);
genStructureExample(s, getLinkFor("", t.getName()), t.getName().toLowerCase() + ".profile", t.getName().toLowerCase(), t.getName());
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("<div id=\"tabs-2\">\r\n");
s.append("<table class=\"list\">\r\n");
genStructureExampleCategory(s, "Resources", "3");
for (String n : definitions.sortedResourceNames()) {
ResourceDefn r = definitions.getResources().get(n);
genStructureExample(s, r.getName().toLowerCase() + ".html", r.getName().toLowerCase() + ".profile", r.getName().toLowerCase(), r.getName());
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("<div id=\"tabs-3\">\r\n");
s.append("<table class=\"list\">\r\n");
Map<String, ConstraintStructure> constraints = new HashMap<String, ConstraintStructure>();
for (Profile pp : definitions.getPackList()) {
for (ConstraintStructure p : pp.getProfiles()) constraints.put(p.getId(), p);
}
for (String rn : definitions.sortedResourceNames()) for (Profile ap : definitions.getResourceByName(rn).getConformancePackages()) for (ConstraintStructure p : ap.getProfiles()) constraints.put(p.getId(), p);
names.clear();
names.addAll(constraints.keySet());
Collections.sort(names);
for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
boolean started = false;
for (String n : names) {
ConstraintStructure p = constraints.get(n);
if (ig == p.getUsage()) {
if (!started) {
started = true;
genStructureExampleCategory(s, ig.getName(), "3");
}
String prefix = ig.isCore() ? "" : ig.getCode() + "/";
genStructureExample(s, prefix + p.getId().toLowerCase() + ".html", prefix + p.getId().toLowerCase() + ".profile", p.getId().toLowerCase(), p.getTitle());
}
}
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("<div id=\"tabs-4\">\r\n");
s.append("<table class=\"list\">\r\n");
names.clear();
for (StructureDefinition sd : workerContext.getExtensionDefinitions()) names.add(sd.getUrl());
Collections.sort(names);
for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
boolean started = false;
for (String n : names) {
StructureDefinition ed = workerContext.fetchResource(StructureDefinition.class, n);
if (ig.getCode().equals(ToolResourceUtilities.getUsage(ed))) {
if (!started) {
started = true;
genStructureExampleCategory(s, ig.getName(), "3");
}
String prefix = ig.isCore() ? "" : ig.getCode() + "/";
genStructureExample(s, prefix + "extension-" + ed.getId().toLowerCase() + ".html", prefix + "extension-" + ed.getId().toLowerCase(), ed.getId().toLowerCase(), ed.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/") ? ed.getUrl().substring(40) : ed.getUrl(), ed.getName());
}
}
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("<div id=\"tabs-5\">\r\n");
s.append("<table class=\"list\">\r\n");
for (Example e : resource.getExamples()) {
if (e.isRegistered() && Utilities.noString(e.getIg()))
produceExampleListEntry(s, e, null, null);
}
for (Profile p : resource.getConformancePackages()) {
for (Example e : p.getExamples()) {
produceExampleListEntry(s, e, p, null);
}
}
for (Profile p : definitions.getPackList()) {
ImplementationGuideDefn ig = definitions.getIgs().get(p.getCategory());
for (Example e : p.getExamples()) {
String rn = e.getResourceName();
if (Utilities.noString(rn))
rn = e.getXml().getDocumentElement().getNodeName();
if (rn.equals(resource.getName()))
produceExampleListEntry(s, e, p, ig);
}
}
for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
if (ig.getIg() != null) {
for (ImplementationGuideDefinitionResourceComponent res : ig.getIg().getDefinition().getResource()) {
Example e = (Example) res.getUserData(ToolResourceUtilities.NAME_RES_EXAMPLE);
if (res.hasExample() && e != null && e.getResourceName().equals(resource.getName()))
produceExampleListEntry(s, res, ig);
}
}
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("</div>\r\n");
s.append("\r\n");
s.append("<script src=\"external/jquery/jquery.js\"> </script>\r\n");
s.append("<script src=\"jquery-ui.min.js\"> </script>\r\n");
s.append("<script>\r\n");
s.append("try {\r\n");
s.append(" var currentTabIndex = sessionStorage.getItem('fhir-sdelist-tab-index');\r\n");
s.append("}\r\n");
s.append("catch(exception){\r\n");
s.append("}\r\n");
s.append("\r\n");
s.append("if (!currentTabIndex)\r\n");
s.append(" currentTabIndex = '0';\r\n");
s.append(" \r\n");
s.append("$( '#tabs' ).tabs({\r\n");
s.append(" active: currentTabIndex,\r\n");
s.append(" activate: function( event, ui ) {\r\n");
s.append(" var active = $('.selector').tabs('option', 'active');\r\n");
s.append(" currentTabIndex = ui.newTab.index();\r\n");
s.append(" document.activeElement.blur();\r\n");
s.append(" try {\r\n");
s.append(" sessionStorage.setItem('fhir-sdelist-tab-index', currentTabIndex);\r\n");
s.append(" }\r\n");
s.append(" catch(exception){\r\n");
s.append(" }\r\n");
s.append(" }\r\n");
s.append(" });\r\n");
s.append("</script>\r\n");
s.append("\r\n");
return s.toString();
}
use of org.hl7.fhir.r5.model.BackboneElement in project kindling by HL7.
the class PageProcessor method belHeader.
private String belHeader(String mode) {
StringBuilder b = new StringBuilder();
b.append("<ul class=\"nav nav-tabs\">");
b.append(makeHeaderTab("Element", "backboneelement.html", mode == null || "base".equals(mode)));
b.append(makeHeaderTab("Detailed Descriptions", "backboneelement-definitions.html", mode == null || "definitions".equals(mode)));
b.append("</ul>\r\n");
return b.toString();
}
use of org.hl7.fhir.r5.model.BackboneElement 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;
}
use of org.hl7.fhir.r5.model.BackboneElement in project kindling by HL7.
the class SpreadSheetReloader method parseType.
private void parseType(ElementDefinition ed, String value, String hierarchy) throws Exception {
ed.getType().clear();
ed.setContentReferenceElement(null);
if (ed.getPath().equals("Resource.id")) {
ed.addType().setCode("http://hl7.org/fhirpath/System.String").addExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type", new UriType("id"));
} else {
if (Utilities.noString(value)) {
if (ed.getPath().contains(".")) {
ed.addType().setCode("BackboneElement");
}
} else if (value.startsWith("#")) {
ed.setContentReference(value);
} else {
List<TypeRef> tl = new TypeParser(version).parse(value, false, null, context, false);
for (TypeRef tr : tl) {
TypeRefComponent t = ed.addType().setCode(tr.getName());
if ("SimpleQuantity".equals(t.getCode())) {
t.setCode("Quantity");
t.addProfile("http://hl7.org/fhir/StructureDefinition/SimpleQuantity");
}
for (String p : tr.getParams()) {
if (p.equals("Definition")) {
t.addExtension(BuildExtensions.EXT_PATTERN, new CanonicalType("http://hl7.org/fhir/StructureDefinition/Definition"));
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/ActivityDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EventDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EvidenceVariable");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Measure");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/OperationDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/PlanDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Questionnaire");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/SubscriptionTopic");
} else {
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
}
}
if (Utilities.existsInList(tr.getName(), "canonical", "Reference") && !Utilities.noString(hierarchy)) {
t.addExtension(BuildExtensions.EXT_HIERARCHY, new BooleanType(Utilities.existsInList(hierarchy, "true", "True", "TRUE", "1", "y", "Y")));
}
}
}
}
}
use of org.hl7.fhir.r5.model.BackboneElement in project kindling by HL7.
the class ResourceParser method parseED.
private void parseED(ProfileUtilities pu, ElementDefn ed, ElementDefinition focus, StructureDefinition sd, String parentName) throws IOException {
ed.setMinCardinality(focus.getMin());
ed.setMaxCardinality("*".equals(focus.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(focus.getMax()));
ed.setIsModifier(focus.getIsModifier());
ed.setModifierReason(focus.getIsModifierReason());
ed.setMustSupport(focus.getMustSupport());
ed.setSummaryItem(focus.getIsSummary());
ed.setRegex(ToolingExtensions.readStringExtension(focus, ToolingExtensions.EXT_REGEX));
ed.setXmlAttribute(focus.hasRepresentation(PropertyRepresentation.XMLATTR));
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_DIR)) {
ed.setUmlDir(ToolingExtensions.readStringExtension(focus, BuildExtensions.EXT_UML_DIR));
}
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_BREAK)) {
ed.setUmlBreak(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_UML_BREAK));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_SVG)) {
String svg = BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_SVG);
if (svg.contains("w=")) {
ed.setSvgWidth(Integer.parseInt(svg.substring(svg.indexOf("w=") + 2)));
svg = svg.substring(0, svg.indexOf(";"));
}
ed.setSvgLeft(Integer.parseInt(svg.substring(0, svg.indexOf(","))));
ed.setSvgTop(Integer.parseInt(svg.substring(svg.indexOf(",") + 1)));
}
ed.setName(tail(focus.getPath()));
ed.setShortDefn(focus.getShort());
ed.setDefinition(focus.getDefinition());
ed.setRequirements(focus.getRequirements());
ed.setComments(focus.getComment());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_TODO)) {
ed.setTodo(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_TODO));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES)) {
ed.setCommitteeNotes(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_HINT)) {
ed.setDisplayHint(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_HINT));
}
if (focus.hasExtension(BuildExtensions.EXT_NO_BINDING)) {
ed.setNoBindingAllowed(focus.getExtensionString(BuildExtensions.EXT_NO_BINDING).equals("true"));
}
for (StringType t : focus.getAlias()) {
ed.getAliases().add(t.getValue());
}
if (focus.hasMaxLength()) {
ed.setMaxLength(Integer.toString(focus.getMaxLength()));
}
ed.setExample(focus.getExampleFirstRep().getValue());
ed.setMeaningWhenMissing(focus.getMeaningWhenMissing());
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_TRANSLATABLE)) {
ed.setTranslatable(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_TRANSLATABLE));
}
ed.setOrderMeaning(focus.getOrderMeaning());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)) {
ed.setStandardsStatus(StandardsStatus.fromCode(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION)) {
ed.setNormativeVersion(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION));
}
for (ElementDefinitionConstraintComponent cst : focus.getConstraint()) {
Invariant inv = new Invariant();
inv.setContext(focus.getPath());
inv.setEnglish(cst.getHuman());
if (cst.hasExtension(BuildExtensions.EXT_OCL)) {
inv.setOcl(cst.getExtensionString(BuildExtensions.EXT_OCL));
}
inv.setXpath(cst.getXpath());
inv.setId(cst.getKey());
if (cst.hasExtension(BuildExtensions.EXT_FIXED_NAME)) {
inv.setFixedName(cst.getExtensionString(BuildExtensions.EXT_FIXED_NAME));
}
inv.setSeverity(cst.getSeverity().toCode());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE)) {
inv.setSeverity("best-practice");
}
if (cst.hasExtension(BuildExtensions.EXT_TURTLE)) {
inv.setTurtle(cst.getExtensionString(BuildExtensions.EXT_TURTLE));
}
inv.setRequirements(cst.getRequirements());
inv.setExpression(cst.getExpression());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION)) {
inv.setExplanation(cst.getExtensionString(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION));
}
ed.getInvariants().put(inv.getId(), inv);
invariants.put(inv.getId(), inv);
}
for (IdType cnd : focus.getCondition()) {
Invariant inv = invariants.get(cnd.primitiveValue());
if (inv == null) {
System.out.println("Unable to find invariant " + cnd.primitiveValue());
} else {
ed.getStatedInvariants().add(inv);
}
}
for (ElementDefinitionMappingComponent map : focus.getMapping()) {
String uri = getMappingUri(sd, map.getIdentity());
if ("http://hl7.org/fhir/fivews".equals(uri)) {
ed.setW5(reverseW5(map.getMap()));
} else {
ed.getMappings().put(uri, map.getMap());
}
}
if (focus.hasContentReference()) {
ed.getTypes().add(new TypeRef("@" + focus.getContentReference().substring(1)));
} else {
for (TypeRefComponent tr : focus.getType()) {
if (!Utilities.existsInList(tr.getCode(), "Element", "BackboneElement")) {
TypeRef t = new TypeRef();
ed.getTypes().add(t);
if (tr.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")) {
t.setName(tr.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type"));
} else {
t.setName(tr.getCode());
}
if (ToolingExtensions.hasExtension(tr, BuildExtensions.EXT_HIERARCHY)) {
ed.setHierarchy(ToolingExtensions.readBoolExtension(tr, BuildExtensions.EXT_HIERARCHY));
}
for (CanonicalType u : tr.getProfile()) {
t.setProfile(u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
}
for (CanonicalType u : tr.getTargetProfile()) {
String s = u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", "");
if ("Resource".equals(s)) {
t.getParams().add("Any");
} else {
t.getParams().add(s);
}
}
if (t.getName().equals("Quantity") && "SimpleQuantity".equals(t.getProfile())) {
t.setName("SimpleQuantity");
t.setProfile(null);
}
if ("Resource".equals(t.getProfile())) {
t.setProfile("Any");
}
if (t.getParams().toString().equals("[ActivityDefinition, EventDefinition, EvidenceVariable, Measure, OperationDefinition, PlanDefinition, Questionnaire, SubscriptionTopic]")) {
t.getParams().clear();
t.getParams().add("Definition");
}
}
}
if (ed.getTypes().size() == STAR_TYPES_COUNT) {
ed.getTypes().clear();
ed.getTypes().add(new TypeRef("*"));
}
}
String name = parentName + Utilities.capitalize(ed.getName());
if (focus.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
ed.setStatedType(focus.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name"));
ed.setDeclaredTypeName(ed.getStatedType());
} else if (ed.getTypes().isEmpty() && !focus.hasContentReference()) {
ed.setDeclaredTypeName(name + "Component");
}
if (focus.hasBinding()) {
ed.setBinding(parseBinding(focus.getBinding()));
}
for (ElementDefinition child : pu.getChildList(sd, focus, true, false)) {
ElementDefn c = new ElementDefn();
ed.getElements().add(c);
parseED(pu, c, child, sd, name);
}
// todo:
// private ElementDefinition derivation;
}
Aggregations