use of org.hl7.fhir.definitions.model.Invariant 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.definitions.model.Invariant in project kindling by HL7.
the class OldSpreadsheetParser method copyInvariants.
private void copyInvariants(ResourceDefn resource) {
if (!resource.isInterface()) {
String abb = ini.getStringProperty("tla", resource.getName());
if (abb == null)
abb = ini.getStringProperty("tla", resource.getName().toLowerCase());
ResourceDefn t2 = definitions.getBaseResources().get(template.getRoot().typeCode());
if (t2 != null && t2.isInterface()) {
String t2Title = Utilities.unCamelCase(t2.getName());
for (String n : t2.getRoot().getInvariants().keySet()) {
Invariant inv = t2.getRoot().getInvariants().get(n);
resource.getRoot().getInvariants().put(n.replace("inv", abb), new Invariant(inv, t2.getName(), resource.getName(), t2Title, abb));
}
}
for (String n : template.getRoot().getInvariants().keySet()) {
Invariant inv = template.getRoot().getInvariants().get(n);
resource.getRoot().getInvariants().put(n.replace("inv", abb), new Invariant(inv, template.getName(), resource.getName(), templateTitle, abb));
}
}
}
use of org.hl7.fhir.definitions.model.Invariant in project kindling by HL7.
the class OldSpreadsheetParser method readInvariants.
private Map<String, Invariant> readInvariants(Sheet sheet, String id, String sheetName) throws Exception {
Map<String, Invariant> result = new HashMap<String, Invariant>();
for (int row = 0; row < sheet.rows.size(); row++) {
Invariant inv = new Invariant();
String s = sheet.getColumn(row, "Id");
if (!s.startsWith("!")) {
inv.setId(s.contains("-") ? s : getAbbreviationFor(id) + "-" + s);
inv.setRequirements(sheet.getColumn(row, "Requirements"));
inv.setContext(sheet.getColumn(row, "Context"));
inv.setEnglish(sheet.getColumn(row, "English"));
inv.setXpath(sheet.getColumn(row, "XPath"));
inv.setExpression(sheet.getColumn(row, "Expression"));
inv.setExplanation(sheet.getColumn(row, "Explanation"));
if (Utilities.noString(inv.getExpression()))
throw new Exception("missing expression " + getLocation(row));
inv.setSeverity(sheet.getColumn(row, "Severity"));
inv.setTurtle(sheet.getColumn(row, "RDF"));
inv.setOcl(sheet.getColumn(row, "OCL"));
if (s.equals("") || result.containsKey(s))
throw new Exception("duplicate or missing invariant id " + getLocation(row));
result.put(s, inv);
}
}
return result;
}
use of org.hl7.fhir.definitions.model.Invariant 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();
}
use of org.hl7.fhir.definitions.model.Invariant 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