use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class CodeSystemRenderer method generateCodeSystemContent.
private boolean generateCodeSystemContent(XhtmlNode x, CodeSystem cs, boolean hasExtensions, List<UsedConceptMap> maps) throws FHIRFormatError, DefinitionException, IOException {
XhtmlNode p = x.para();
if (cs.getContent() == CodeSystemContentMode.COMPLETE)
p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), "This code system %s defines the following codes", cs.getUrl()) + ":");
else if (cs.getContent() == CodeSystemContentMode.EXAMPLE)
p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), "This code system %s defines some example codes", cs.getUrl()) + ":");
else if (cs.getContent() == CodeSystemContentMode.FRAGMENT)
p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), "This code system %s defines many codes, of which the following are a subset", cs.getUrl()) + ":");
else if (cs.getContent() == CodeSystemContentMode.NOTPRESENT) {
p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), "This code system %s defines many codes, but they are not represented here", cs.getUrl()));
return false;
}
XhtmlNode t = x.table("codes");
boolean definitions = false;
boolean commentS = false;
boolean deprecated = false;
boolean display = false;
boolean hierarchy = false;
boolean version = false;
boolean ignoreStatus = false;
boolean isSupplement = cs.getContent() == CodeSystemContentMode.SUPPLEMENT;
List<PropertyComponent> properties = new ArrayList<>();
for (PropertyComponent cp : cs.getProperty()) {
if (showPropertyInTable(cp)) {
boolean exists = false;
for (ConceptDefinitionComponent c : cs.getConcept()) {
exists = exists || conceptsHaveProperty(c, cp);
}
if (exists) {
properties.add(cp);
if ("status".equals(cp.getCode())) {
ignoreStatus = true;
}
}
}
}
for (ConceptDefinitionComponent c : cs.getConcept()) {
commentS = commentS || conceptsHaveComments(c);
deprecated = deprecated || conceptsHaveDeprecated(cs, c, ignoreStatus);
display = display || conceptsHaveDisplay(c);
version = version || conceptsHaveVersion(c);
hierarchy = hierarchy || c.hasConcept();
definitions = definitions || conceptsHaveDefinition(c);
}
CodeSystemNavigator csNav = new CodeSystemNavigator(cs);
hierarchy = hierarchy || csNav.isRestructure();
List<String> langs = new ArrayList<>();
addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, definitions, commentS, version, deprecated, properties, null, false), maps);
for (ConceptDefinitionComponent c : csNav.getConcepts(null)) {
hasExtensions = addDefineRowToTable(t, c, 0, hierarchy, display, definitions, commentS, version, deprecated, maps, cs.getUrl(), cs, properties, csNav, langs, isSupplement) || hasExtensions;
}
if (langs.size() > 0) {
Collections.sort(langs);
x.para().b().tx("Additional Language Displays");
t = x.table("codes");
XhtmlNode tr = t.tr();
tr.td().b().tx("Code");
for (String lang : langs) tr.td().b().addText(describeLang(lang));
for (ConceptDefinitionComponent c : cs.getConcept()) {
addLanguageRow(c, t, langs);
}
}
return hasExtensions;
}
use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class CompartmentDefinitionRenderer method render.
public boolean render(XhtmlNode x, CompartmentDefinition cpd) throws FHIRFormatError, DefinitionException, IOException {
StringBuilder in = new StringBuilder();
StringBuilder out = new StringBuilder();
for (CompartmentDefinitionResourceComponent cc : cpd.getResource()) {
CommaSeparatedStringBuilder rules = new CommaSeparatedStringBuilder();
if (!cc.hasParam()) {
out.append(" <li><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></li>\r\n");
} else if (!rules.equals("{def}")) {
for (StringType p : cc.getParam()) rules.append(p.asStringValue());
in.append(" <tr><td><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></td><td>").append(rules.toString()).append("</td></tr>\r\n");
}
}
XhtmlNode xn;
xn = new XhtmlParser().parseFragment("<div><p>\r\nThe following resources may be in this compartment:\r\n</p>\r\n" + "<table class=\"grid\">\r\n" + " <tr><td><b>Resource</b></td><td><b>Inclusion Criteria</b></td></tr>\r\n" + in.toString() + "</table>\r\n" + "<p>\r\nA resource is in this compartment if the nominated search parameter (or chain) refers to the patient resource that defines the compartment.\r\n</p>\r\n" + "<p>\r\n\r\n</p>\r\n" + "<p>\r\nThe following resources are never in this compartment:\r\n</p>\r\n" + "<ul>\r\n" + out.toString() + "</ul></div>\r\n");
x.getChildNodes().addAll(xn.getChildNodes());
return true;
}
use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method render.
@Override
public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException {
if (context.isAddGeneratedNarrativeHeader()) {
x.para().b().tx("Generated Narrative");
}
if (context.isTechnicalMode()) {
renderResourceHeader(r, x);
}
try {
StructureDefinition sd = r.getDefinition();
if (sd == null) {
throw new FHIRException("Cannot find definition for " + r.fhirType());
} else {
ElementDefinition ed = sd.getSnapshot().getElement().get(0);
containedIds.clear();
hasExtensions = false;
generateByProfile(r, sd, r.root(), sd.getSnapshot().getElement(), ed, context.getProfileUtilities().getChildList(sd, ed), x, r.fhirType(), context.isTechnicalMode(), 0);
}
} catch (Exception e) {
System.out.println("Error Generating Narrative for " + r.fhirType() + "/" + r.getId() + ": " + e.getMessage());
e.printStackTrace();
x.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
}
return hasExtensions;
}
use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method splitExtensions.
private List<PropertyWrapper> splitExtensions(StructureDefinition profile, List<PropertyWrapper> children) throws UnsupportedEncodingException, IOException, FHIRException {
List<PropertyWrapper> results = new ArrayList<PropertyWrapper>();
Map<String, PropertyWrapper> map = new HashMap<String, PropertyWrapper>();
for (PropertyWrapper p : children) if (p.getName().equals("extension") || p.getName().equals("modifierExtension")) {
// we're going to split these up, and create a property for each url
if (p.hasValues()) {
for (BaseWrapper v : p.getValues()) {
Extension ex = (Extension) v.getBase();
String url = ex.getUrl();
StructureDefinition ed = getContext().getWorker().fetchResource(StructureDefinition.class, url);
if (ed == null) {
if (xverManager == null) {
xverManager = new XVerExtensionManager(context.getWorker());
}
if (xverManager.matchingUrl(url) && xverManager.status(url) == XVerExtensionStatus.Valid) {
ed = xverManager.makeDefinition(url);
getContext().getWorker().generateSnapshot(ed);
getContext().getWorker().cacheResource(ed);
}
}
if (p.getName().equals("modifierExtension") && ed == null) {
throw new DefinitionException("Unknown modifier extension " + url);
}
PropertyWrapper pe = map.get(p.getName() + "[" + url + "]");
if (pe == null) {
if (ed == null) {
if (url.startsWith("http://hl7.org/fhir") && !url.startsWith("http://hl7.org/fhir/us")) {
throw new DefinitionException("unknown extension " + url);
}
// System.out.println("unknown extension "+url);
pe = new PropertyWrapperDirect(this.context, new Property(p.getName() + "[" + url + "]", p.getTypeCode(), p.getDefinition(), p.getMinCardinality(), p.getMaxCardinality(), ex), null);
} else {
ElementDefinition def = ed.getSnapshot().getElement().get(0);
pe = new PropertyWrapperDirect(this.context, new Property(p.getName() + "[" + url + "]", "Extension", def.getDefinition(), def.getMin(), def.getMax().equals("*") ? Integer.MAX_VALUE : Integer.parseInt(def.getMax()), ex), ed.getSnapshot().getElementFirstRep());
((PropertyWrapperDirect) pe).getWrapped().setStructure(ed);
}
results.add(pe);
} else
pe.getValues().add(v);
}
}
} else
results.add(p);
return results;
}
use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method getChildrenForPath.
private List<ElementDefinition> getChildrenForPath(List<ElementDefinition> elements, String path) throws DefinitionException {
// do we need to do a name reference substitution?
for (ElementDefinition e : elements) {
if (e.getPath().equals(path) && e.hasContentReference()) {
String ref = e.getContentReference();
ElementDefinition t = null;
// now, resolve the name
for (ElementDefinition e1 : elements) {
if (ref.equals("#" + e1.getId()))
t = e1;
}
if (t == null)
throw new DefinitionException("Unable to resolve content reference " + ref + " trying to resolve " + path);
path = t.getPath();
break;
}
}
List<ElementDefinition> results = new ArrayList<ElementDefinition>();
for (ElementDefinition e : elements) {
if (e.getPath().startsWith(path + ".") && !e.getPath().substring(path.length() + 1).contains("."))
results.add(e);
}
return results;
}
Aggregations