use of org.hl7.fhir.r4.model.UriType in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateExtensionTable.
public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, String imagePath, Set<String> outputTracker, RenderingContext rc) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics, true);
gen.setTranslator(getTranslator());
TableModel model = gen.initNormalTable(corePath, false, true, ed.getId() + (full ? "f" : "n"), true);
boolean deep = false;
String m = "";
boolean vdeep = false;
if (ed.getSnapshot().getElementFirstRep().getIsModifier())
m = "modifier_";
for (ElementDefinition eld : ed.getSnapshot().getElement()) {
deep = deep || eld.getPath().contains("Extension.extension.");
vdeep = vdeep || eld.getPath().contains("Extension.extension.extension.");
}
Row r = gen.new Row();
model.getRows().add(r);
String en;
if (!full)
en = ed.getName();
else if (ed.getSnapshot().getElement().get(0).getIsModifier())
en = "modifierExtension";
else
en = "extension";
r.getCells().add(gen.new Cell(null, defFile == null ? "" : defFile + "-definitions.html#extension." + ed.getName(), en, null, null));
r.getCells().add(gen.new Cell());
r.getCells().add(gen.new Cell(null, null, describeCardinality(ed.getSnapshot().getElement().get(0), null, new UnusedTracker()), null, null));
ElementDefinition ved = null;
if (full || vdeep) {
r.getCells().add(gen.new Cell("", "", "Extension", null, null));
r.setIcon(deep ? "icon_" + m + "extension_complex.png" : "icon_extension_simple.png", deep ? HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX : HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
List<ElementDefinition> children = getChildren(ed.getSnapshot().getElement(), ed.getSnapshot().getElement().get(0));
for (ElementDefinition child : children) if (!child.getPath().endsWith(".id")) {
List<StructureDefinition> sdl = new ArrayList<>();
sdl.add(ed);
genElement(defFile == null ? "" : defFile + "-definitions.html#extension.", gen, r.getSubRows(), child, ed.getSnapshot().getElement(), sdl, true, defFile, true, full, corePath, imagePath, true, false, false, false, null, false, rc);
}
} else if (deep) {
List<ElementDefinition> children = new ArrayList<ElementDefinition>();
for (ElementDefinition ted : ed.getSnapshot().getElement()) {
if (ted.getPath().equals("Extension.extension"))
children.add(ted);
}
r.getCells().add(gen.new Cell("", "", "Extension", null, null));
r.setIcon("icon_" + m + "extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX);
for (ElementDefinition c : children) {
ved = getValueFor(ed, c);
ElementDefinition ued = getUrlFor(ed, c);
if (ved != null && ued != null) {
Row r1 = gen.new Row();
r.getSubRows().add(r1);
r1.getCells().add(gen.new Cell(null, defFile == null ? "" : defFile + "-definitions.html#extension." + ed.getName(), ((UriType) ued.getFixed()).getValue(), null, null));
r1.getCells().add(gen.new Cell());
r1.getCells().add(gen.new Cell(null, null, describeCardinality(c, null, new UnusedTracker()), null, null));
genTypes(gen, r1, ved, defFile, ed, corePath, imagePath, false, false);
Cell cell = gen.new Cell();
cell.addMarkdown(c.getDefinition());
r1.getCells().add(cell);
r1.setIcon("icon_" + m + "extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
}
}
} else {
for (ElementDefinition ted : ed.getSnapshot().getElement()) {
if (ted.getPath().startsWith("Extension.value"))
ved = ted;
}
genTypes(gen, r, ved, defFile, ed, corePath, imagePath, false, false);
r.setIcon("icon_" + m + "extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
}
Cell c = gen.new Cell("", "", "URL = " + ed.getUrl(), null, null);
Piece cc = gen.new Piece(null, ed.getName() + ": ", null);
c.addPiece(gen.new Piece("br")).addPiece(cc);
c.addMarkdown(ed.getDescription());
if (!full && !(deep || vdeep) && ved != null && ved.hasBinding()) {
c.addPiece(gen.new Piece("br"));
BindingResolution br = pkp.resolveBinding(ed, ved.getBinding(), ved.getPath());
c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
if (ved.getBinding().hasStrength()) {
c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(null, " (", null)));
c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(corePath + "terminologies.html#" + ved.getBinding().getStrength().toCode(), egt(ved.getBinding().getStrengthElement()), ved.getBinding().getStrength().getDefinition())));
c.getPieces().add(gen.new Piece(null, ")", null));
}
if (ved.getBinding().hasDescription() && MarkDownProcessor.isSimpleMarkdown(ved.getBinding().getDescription())) {
c.getPieces().add(gen.new Piece(null, ": ", null));
c.addMarkdownNoPara(PublicationHacker.fixBindingDescriptions(context, ved.getBinding().getDescriptionElement()).asStringValue());
}
}
c.addPiece(gen.new Piece("br")).addPiece(gen.new Piece(null, describeExtensionContext(ed), null));
r.getCells().add(c);
try {
return gen.generate(model, corePath, 0, outputTracker);
} catch (org.hl7.fhir.exceptions.FHIRException e) {
throw new FHIRException(e.getMessage(), e);
}
}
use of org.hl7.fhir.r4.model.UriType in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateSlicer.
private Slicer generateSlicer(ElementDefinition child, ElementDefinitionSlicingComponent slicing, StructureDefinition structure) {
// given a child in a structure, it's sliced. figure out the slicing xpath
if (child.getPath().endsWith(".extension")) {
ElementDefinition ued = getUrlFor(structure, child);
if ((ued == null || !ued.hasFixed()) && !(child.hasType() && (child.getType().get(0).hasProfile())))
return new Slicer(false);
else {
Slicer s = new Slicer(true);
String url = (ued == null || !ued.hasFixed()) ? child.getType().get(0).getProfile().get(0).getValue() : ((UriType) ued.getFixed()).asStringValue();
s.name = " with URL = '" + url + "'";
s.criteria = "[@url = '" + url + "']";
return s;
}
} else
return new Slicer(false);
}
use of org.hl7.fhir.r4.model.UriType in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method validateOnServer.
protected ValidationResult validateOnServer(ValueSet vs, Parameters pin, ValidationOptions options) throws FHIRException {
boolean cache = false;
if (vs != null) {
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
codeSystemsUsed.add(inc.getSystem());
}
for (ConceptSetComponent inc : vs.getCompose().getExclude()) {
codeSystemsUsed.add(inc.getSystem());
}
}
if (vs != null) {
if (isTxCaching && cacheId != null && vs.getUrl() != null && cached.contains(vs.getUrl() + "|" + vs.getVersion())) {
pin.addParameter().setName("url").setValue(new UriType(vs.getUrl() + (vs.hasVersion() ? "|" + vs.getVersion() : "")));
} else if (options.getVsAsUrl()) {
pin.addParameter().setName("url").setValue(new StringType(vs.getUrl()));
} else {
pin.addParameter().setName("valueSet").setResource(vs);
if (vs.getUrl() != null) {
cached.add(vs.getUrl() + "|" + vs.getVersion());
}
}
cache = true;
addDependentResources(pin, vs);
}
if (cache) {
pin.addParameter().setName("cache-id").setValue(new StringType(cacheId));
}
for (ParametersParameterComponent pp : pin.getParameter()) {
if (pp.getName().equals("profile")) {
throw new Error(formatMessage(I18nConstants.CAN_ONLY_SPECIFY_PROFILE_IN_THE_CONTEXT));
}
}
if (expParameters == null) {
throw new Error(formatMessage(I18nConstants.NO_EXPANSIONPROFILE_PROVIDED));
}
pin.addParameter().setName("profile").setResource(expParameters);
if (txLog != null) {
txLog.clearLastId();
}
if (txClient == null) {
throw new FHIRException(formatMessage(I18nConstants.ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE));
}
Parameters pOut;
if (vs == null) {
pOut = txClient.validateCS(pin);
} else {
pOut = txClient.validateVS(pin);
}
return processValidationResult(pOut);
}
use of org.hl7.fhir.r4.model.UriType in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method checkTypeDerivation.
public void checkTypeDerivation(String purl, StructureDefinition srcSD, ElementDefinition base, ElementDefinition derived, TypeRefComponent ts) {
boolean ok = false;
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
String t = ts.getWorkingCode();
for (TypeRefComponent td : base.getType()) {
;
String tt = td.getWorkingCode();
b.append(tt);
if (td.hasCode() && (tt.equals(t))) {
ok = true;
}
if (!ok) {
StructureDefinition sdt = context.fetchTypeDefinition(tt);
if (sdt != null && (sdt.getAbstract() || sdt.getKind() == StructureDefinitionKind.LOGICAL)) {
StructureDefinition sdb = context.fetchTypeDefinition(t);
while (sdb != null && !ok) {
ok = sdb.getType().equals(sdt.getType());
sdb = context.fetchResource(StructureDefinition.class, sdb.getBaseDefinition());
}
}
}
// work around for old badly generated SDs
if (DONT_DO_THIS && Utilities.existsInList(tt, "Extension", "uri", "string", "Element")) {
ok = true;
}
if (DONT_DO_THIS && Utilities.existsInList(tt, "Resource", "DomainResource") && pkp.isResource(t)) {
ok = true;
}
if (ok && ts.hasTargetProfile()) {
// check that any derived target has a reference chain back to one of the base target profiles
for (UriType u : ts.getTargetProfile()) {
String url = u.getValue();
boolean tgtOk = !td.hasTargetProfile() || td.hasTargetProfile(url);
while (url != null && !tgtOk) {
StructureDefinition sd = context.fetchRawProfile(url);
if (sd == null) {
if (messages != null) {
messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.BUSINESSRULE, purl + "#" + derived.getPath(), "Cannot check whether the target profile " + url + " is valid constraint on the base because it is not known", IssueSeverity.WARNING));
}
url = null;
// suppress error message
tgtOk = true;
} else {
url = sd.getBaseDefinition();
tgtOk = td.hasTargetProfile(url);
}
}
if (!tgtOk) {
if (messages == null) {
throw new FHIRException(context.formatMessage(I18nConstants.ERROR_AT__THE_TARGET_PROFILE__IS_NOT__VALID_CONSTRAINT_ON_THE_BASE_, purl, derived.getPath(), url, td.getTargetProfile()));
} else {
messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.BUSINESSRULE, derived.getPath(), "The target profile " + u.getValue() + " is not a valid constraint on the base (" + td.getTargetProfile() + ") at " + derived.getPath(), IssueSeverity.ERROR));
}
}
}
}
}
if (!ok) {
throw new DefinitionException(context.formatMessage(I18nConstants.STRUCTUREDEFINITION__AT__ILLEGAL_CONSTRAINED_TYPE__FROM__IN_, purl, derived.getPath(), t, b.toString(), srcSD.getUrl()));
}
}
use of org.hl7.fhir.r4.model.UriType in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method makeExtensionForVersionedURL.
public static StructureDefinition makeExtensionForVersionedURL(IWorkerContext context, String url) {
String epath = url.substring(54);
if (!epath.contains("."))
return null;
String type = epath.substring(0, epath.indexOf("."));
StructureDefinition sd = context.fetchTypeDefinition(type);
if (sd == null)
return null;
ElementDefinition ed = null;
for (ElementDefinition t : sd.getSnapshot().getElement()) {
if (t.getPath().equals(epath)) {
ed = t;
break;
}
}
if (ed == null)
return null;
if ("Element".equals(ed.typeSummary()) || "BackboneElement".equals(ed.typeSummary())) {
return null;
} else {
StructureDefinition template = context.fetchResource(StructureDefinition.class, "http://fhir-registry.smarthealthit.org/StructureDefinition/capabilities");
StructureDefinition ext = template.copy();
ext.setUrl(url);
ext.setId("extension-" + epath);
ext.setName("Extension-" + epath);
ext.setTitle("Extension for r4 " + epath);
ext.setStatus(sd.getStatus());
ext.setDate(sd.getDate());
ext.getContact().clear();
ext.getContact().addAll(sd.getContact());
ext.setFhirVersion(sd.getFhirVersion());
ext.setDescription(ed.getDefinition());
ext.getContext().clear();
ext.addContext().setType(ExtensionContextType.ELEMENT).setExpression(epath.substring(0, epath.lastIndexOf(".")));
ext.getDifferential().getElement().clear();
ext.getSnapshot().getElement().get(3).setFixed(new UriType(url));
ext.getSnapshot().getElement().set(4, ed.copy());
ext.getSnapshot().getElement().get(4).setPath("Extension.value" + Utilities.capitalize(ed.typeSummary()));
return ext;
}
}
Aggregations