use of org.hl7.fhir.r4.model.StructureDefinition.ExtensionContextType 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;
}
Aggregations