use of org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent in project org.hl7.fhir.core by hapifhir.
the class StructureDefinitionSpreadsheetGenerator method addStructureDefinitionMetadata.
private void addStructureDefinitionMetadata(Sheet sheet, StructureDefinition sd) {
for (Coding k : sd.getKeyword()) {
addMetadataRow(sheet, "Keyword", dr.display(k));
}
addMetadataRow(sheet, "FHIR Version", sd.getFhirVersionElement().asStringValue());
addMetadataRow(sheet, "Kind", sd.getKindElement().asStringValue());
addMetadataRow(sheet, "Type", sd.getType());
addMetadataRow(sheet, "Base Definition", sd.getBaseDefinition());
addMetadataRow(sheet, "Abstract", sd.getAbstractElement().asStringValue());
addMetadataRow(sheet, "Derivation", sd.getDerivationElement().asStringValue());
for (StructureDefinitionContextComponent k : sd.getContext()) {
addMetadataRow(sheet, "Context", k.getTypeElement().asStringValue() + ":" + k.getExpression());
}
for (StringType k : sd.getContextInvariant()) {
addMetadataRow(sheet, "Context Inv.", k.getValue());
}
}
use of org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent in project kindling by HL7.
the class PageProcessor method populateLogicalMappingColumn.
private void populateLogicalMappingColumn(StringBuilder b, String n, String page, ElementDefn e, StructureDefinition sd, String rn, String code, String url, StringBuilder b2, IniFile ini, String iniPath) throws FHIRException {
LogicalModelSupportInformation info = new LogicalModelSupportInformation();
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
for (ElementDefinitionMappingComponent m : ed.getMapping()) {
if (m.getIdentity().equals(code)) {
String s = m.getMap();
for (String p : s.split("\\,")) {
String f = p.contains("{") ? p.substring(0, p.indexOf("{")).trim() : p;
String cm = p.contains("{") ? p.substring(p.indexOf("{")) : null;
if (cm != null) {
cm = cm.trim();
}
if (f.equals(e.getPath())) {
checkMapping(info, e, ed, b2 == null, cm);
}
}
}
}
}
for (StructureDefinition ext : workerContext.getExtensionDefinitions()) {
boolean ok = false;
for (StructureDefinitionContextComponent ec : ext.getContext()) {
if (ec.getType() == ExtensionContextType.ELEMENT) {
if (rn.equals(ec.getExpression()))
ok = true;
}
if (ok) {
String map = getWorkflowMapping(ext, url);
if (map != null) {
for (String p : map.split("\\,")) {
String f = p.contains("{") ? p.substring(0, p.indexOf("{")) : p;
if (f.equals(e.getPath())) {
checkExtMapping(info, e, ext);
}
}
}
}
}
}
// color:
// one color when supported and aligned
// one color when not aligned
// one coor when color extension
// blank for no mapping
String color;
if (info.typeMismatch == TypeMappingStatus.ERROR || info.cardinalityProblem)
color = LOGICAL_MAPPING_MISMATCH_COLOR;
else if (info.nameChanged || info.typeMismatch == TypeMappingStatus.NEEDS_MAPPING)
color = LOGICAL_MAPPING_NAMECHANGE_COLOR;
else if (info.extension)
color = LOGICAL_MAPPING_EXTENSION_COLOR;
else if (info.elementcount > 0)
color = LOGICAL_MAPPING_MAPPED_COLOR;
else
color = LOGICAL_MAPPING_NOTMAPPED_COLOR;
if (b != null) {
StringBuilder ns = new StringBuilder();
for (String s : info.notes) {
if (ns.length() > 0)
ns.append("; ");
ns.append(s);
}
b.append(" <td style=\"background-color: " + color + "\" title=\"" + ns.toString() + "\">");
if (info.elementcount > 0)
b.append(info.elementcount);
else if (info.extension)
b.append("E");
b.append(" ");
if (info.nameChanged)
b.append("N");
if (info.typeMismatch == TypeMappingStatus.ERROR)
b.append("T");
if (info.cardinalityProblem)
b.append("C");
b.append("</td>\r\n");
}
StringBuilder ns = new StringBuilder();
for (String s : info.notes) {
ns.append(s);
}
String tasks = ini == null ? null : ini.getStringProperty(iniPath, sd.getName() + ".tasks");
String status = ini == null ? null : ini.getStringProperty(iniPath, sd.getName() + ".status");
String notes = ini == null ? null : ini.getStringProperty(iniPath, sd.getName() + ".notes");
if (b2 != null && !(Utilities.noString(ns.toString()) && Utilities.noString(tasks))) {
b2.append("<tr style=\"background-color: " + color + "\"><td><b><a href=\"" + sd.getName().toLowerCase() + ".html\">" + sd.getName() + "</a></b></td><td><ul>" + ns.toString() + "</ul>");
if (info.extension)
b2.append(" (as an extension)");
b2.append("</td><td>");
if (info.nameChanged || info.typeMismatch != TypeMappingStatus.OK || info.cardinalityProblem) {
boolean first = true;
if (info.nameChanged) {
b2.append("Names are different. ");
first = false;
}
if (info.typeMismatch != TypeMappingStatus.OK) {
if (!first)
b2.append("<br/>");
b2.append("Type Mismatch. ");
first = false;
}
if (info.cardinalityProblem) {
if (!first)
b2.append("<br/>");
b2.append("Cardinality Problem. ");
}
}
b2.append("</td><td>");
boolean first = true;
if (!Utilities.noString(tasks)) {
for (String id : tasks.split("\\;")) {
if (!first)
b2.append(" | ");
b2.append("<a href=\"https://gforge.hl7.org/gf/project/fhir/tracker/?action=TrackerItemEdit&tracker_item_id=" + id.trim() + "\">GF#" + id.trim() + "</a>");
first = false;
}
b2.append("</td><td>");
}
if (!Utilities.noString(status))
b2.append(Utilities.escapeXml(status));
b2.append("</td><td>");
if (!Utilities.noString(notes))
b2.append(Utilities.escapeXml(notes));
b2.append("</td></tr>\r\n");
}
}
use of org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent in project kindling by HL7.
the class OldSpreadsheetParser method processExtension.
private int processExtension(ElementDefn extensions, Sheet sheet, int row, Definitions definitions, String uri, Profile ap, List<ValidationMessage> issues, Map<String, Invariant> invariants, WorkGroup wg) throws Exception {
// first, we build the extension definition
StructureDefinition ex = new StructureDefinition();
ex.setUserData(ToolResourceUtilities.NAME_RES_IG, ig == null ? "core" : ig.getCode());
ex.setUserData("profile", ap);
ex.setKind(StructureDefinitionKind.COMPLEXTYPE);
ex.setType("Extension");
ex.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Extension");
ex.setDerivation(TypeDerivationRule.CONSTRAINT);
ex.setAbstract(false);
ex.setFhirVersion(version);
ex.setVersion(version.toCode());
if (wg != null)
ToolingExtensions.setCodeExtension(ex, ToolingExtensions.EXT_WORKGROUP, wg.getCode());
String fmm = sheet.getColumn(row, "FMM");
if (Utilities.noString(fmm))
// default fmm value for extensions
fmm = "1";
ToolingExtensions.addIntegerExtension(ex, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(fmm));
if (ap.hasMetadata("fmm-level"))
ToolingExtensions.addIntegerExtension(ex, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(ap.getFmmLevel()));
if (ap.hasMetadata("workgroup"))
ToolingExtensions.setCodeExtension(ex, ToolingExtensions.EXT_WORKGROUP, ap.getWg());
ToolResourceUtilities.updateUsage(ex, ap.getCategory());
String name = sheet.getColumn(row, "Code");
String context = null;
if (Utilities.noString(name))
throw new Exception("No code found on Extension at " + getLocation(row));
if (name.contains("."))
throw new Exception("Extension Definition Error: Extension names cannot contain '.': " + name + " at " + getLocation(row));
ex.setUrl(uri + name);
ex.setId(tail(ex.getUrl()));
ex.setUserData("path", "extension-" + ex.getId().toLowerCase() + ".html");
ap.getExtensions().add(ex);
if (context == null) {
ExtensionContextType ct = readContextType(sheet.getColumn(row, "Context Type"), row);
if (sheet.hasColumn("Context Invariant"))
for (String s : sheet.getColumn(row, "Context Invariant").split("~")) ex.addContextInvariant(s);
String cc = checkContextMacro(sheet.getColumn(row, "Context"));
if (!Utilities.noString(cc))
for (String c : cc.split("\\;")) {
StructureDefinitionContextComponent ec = ex.addContext();
ec.setExpression(c.trim());
ec.setType(ct);
if (definitions != null) {
definitions.checkContextValid(ec, this.name, this.context);
}
}
}
ex.setTitle(sheet.getColumn(row, "Display"));
ElementDefn exe = new ElementDefn();
exe.setName(sheet.getColumn(row, "Code"));
ElementDefn exu = new ElementDefn();
exu.setName("url");
exu.setXmlAttribute(true);
exe.getElements().add(exu);
exu.setFixed(new UriType(ex.getUrl()));
exu.getTypes().add(new TypeRef().setName("uri"));
if (invariants != null) {
for (Invariant inv : invariants.values()) {
if (inv.getContext().equals(name))
exe.getInvariants().put(inv.getId(), inv);
}
}
parseExtensionElement(sheet, row, definitions, exe, false);
String sl = exe.getShortDefn();
ex.setName(sheet.getColumn(row, "Name"));
if (!ex.hasName())
ex.setName(exe.getName());
if (!ex.hasName())
ex.setName(ex.getTitle());
if (!ex.hasName() && !Utilities.noString(sl))
ex.setName(sl);
if (!ex.hasName())
throw new Exception("Extension " + ex.getUrl() + " missing name at " + getLocation(row));
ex.setDescription(preProcessMarkdown(exe.getDefinition(), "Extension Definition"));
ex.setPublisher(ap.metadata("author.name"));
if (ap.hasMetadata("author.reference"))
ex.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, ap.metadata("author.reference")));
// <code> opt Zero+ Coding assist with indexing and finding</code>
if (ap.hasMetadata("date"))
ex.setDateElement(Factory.newDateTime(ap.metadata("date").substring(0, 10)));
else
ex.setDate(genDate.getTime());
if (ap.hasMetadata("status"))
ex.setStatus(PublicationStatus.fromCode(ap.metadata("status")));
row++;
if (ig == null || ig.isCore()) {
if (!ex.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/") && !ex.getUrl().startsWith("http://fhir-registry.smarthealthit.org/StructureDefinition/"))
throw new Exception("extension " + ex.getUrl() + " is not valid in the publication tooling");
} else {
if (!ex.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "-"))
throw new Exception("extension " + ex.getUrl() + " is not valid for the IG " + ig.getCode() + " in the publication tooling");
}
while (row < sheet.getRows().size() && sheet.getColumn(row, "Code").startsWith(name + ".")) {
String n = sheet.getColumn(row, "Code");
ElementDefn p = findContext(exe, n.substring(0, n.lastIndexOf(".")), "Extension Definition " + name);
ElementDefn child = new ElementDefn();
p.getElements().add(child);
child.setName(n.substring(n.lastIndexOf(".") + 1));
child.setProfileName(child.getName());
parseExtensionElement(sheet, row, definitions, child, true);
if (invariants != null) {
for (Invariant inv : invariants.values()) {
if (inv.getContext().equals(n))
child.getInvariants().put(inv.getId(), inv);
}
}
row++;
}
ProfileGenerator gen = new ProfileGenerator(definitions, null, pkp, null, version, null, fpUsages, null, null, rc);
ProfileUtilities utils = new ProfileUtilities(this.context, issues, pkp);
gen.convertElements(exe, ex, null);
ex.getDifferential().getElementFirstRep().getType().clear();
utils.setIds(ex, false);
StructureDefinition base = definitions != null ? definitions.getSnapShotForType("Extension") : this.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Extension");
List<String> errors = new ArrayList<String>();
utils.sortDifferential(base, ex, "extension " + ex.getUrl(), errors, false);
assert (errors.size() == 0);
utils.generateSnapshot(base, ex, ex.getUrl(), "http://hl7.org/fhir", ex.getName());
utils.setIds(ex, true);
new ExtensionDefinitionValidator(context).validate(ex);
this.context.cacheResource(ex);
return row;
}
use of org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent in project kindling by HL7.
the class SourceParser method parseConformanceDocument.
private void parseConformanceDocument(Profile pack, String n, File file, String usage, WorkGroup wg) throws Exception {
try {
Resource rf = new XmlParser().parse(new CSFileInputStream(file));
if (!(rf instanceof Bundle))
throw new Exception("Error parsing Profile: neither a spreadsheet nor a bundle");
Bundle b = (Bundle) rf;
if (b.getType() != BundleType.DOCUMENT)
throw new Exception("Error parsing profile: neither a spreadsheet nor a bundle that is a document");
for (BundleEntryComponent ae : ((Bundle) rf).getEntry()) {
if (ae.getResource() instanceof Composition)
pack.loadFromComposition((Composition) ae.getResource(), file.getAbsolutePath());
else if (ae.getResource() instanceof StructureDefinition && !((StructureDefinition) ae.getResource()).getType().equals("Extension")) {
StructureDefinition ed = (StructureDefinition) ae.getResource();
for (StructureDefinitionContextComponent s : ed.getContext()) definitions.checkContextValid(s, file.getName(), this.context);
ToolResourceUtilities.updateUsage(ed, pack.getCategory());
pack.getProfiles().add(new ConstraintStructure(ed, definitions.getUsageIG(usage, "Parsing " + file.getAbsolutePath()), wg == null ? wg(ed) : wg, fmm(ed), ed.getExperimental()));
} else if (ae.getResource() instanceof StructureDefinition) {
StructureDefinition ed = (StructureDefinition) ae.getResource();
if (Utilities.noString(ed.getBaseDefinition()))
ed.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Extension");
ed.setDerivation(TypeDerivationRule.CONSTRAINT);
if (ToolingExtensions.readStringExtension(ed, ToolingExtensions.EXT_WORKGROUP) == null)
ToolingExtensions.setCodeExtension(ed, ToolingExtensions.EXT_WORKGROUP, wg.getCode());
if (!ed.hasUrl())
if (ae.hasFullUrl())
ed.setUrl(ae.getFullUrl());
else
ed.setUrl("http://hl7.org/fhir/StructureDefinition/" + ed.getId());
context.cacheResource(ed);
pack.getExtensions().add(ed);
}
}
} catch (Exception e) {
throw new Exception("Error Parsing profile: '" + n + "': " + e.getMessage(), e);
}
}
use of org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method describeExtensionContext.
public static String describeExtensionContext(StructureDefinition ext) {
StringBuilder b = new StringBuilder();
b.append("Use on ");
for (int i = 0; i < ext.getContext().size(); i++) {
StructureDefinitionContextComponent ec = ext.getContext().get(i);
if (i > 0)
b.append(i < ext.getContext().size() - 1 ? ", " : " or ");
b.append(ec.getType().getDisplay());
b.append(" ");
b.append(ec.getExpression());
}
if (ext.hasContextInvariant()) {
b.append(", with <a href=\"structuredefinition-definitions.html#StructureDefinition.contextInvariant\">Context Invariant</a> = ");
boolean first = true;
for (StringType s : ext.getContextInvariant()) {
if (first)
first = false;
else
b.append(", ");
b.append("<code>" + s.getValue() + "</code>");
}
}
return b.toString();
}
Aggregations