use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.
the class PageProcessor method ttlForDt.
private String ttlForDt(String dt, String pn) throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
TurtleSpecGenerator gen = new TurtleSpecGenerator(b, pn == null ? null : pn.substring(0, pn.indexOf(".")) + "-definitions.html", null, this, "", version.toCode());
TypeParser tp = new TypeParser(version.toCode());
TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
ElementDefn e = definitions.getElementDefn(t.getName());
if (e == null) {
gen.close();
throw new Exception("unable to find definition for " + dt);
} else {
gen.generate(e, false);
gen.close();
}
String val = new String(b.toByteArray()) + "\r\n";
return val;
}
use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.
the class PageProcessor method jsonForDt.
private String jsonForDt(String dt, String pn) throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
JsonSpecGenerator gen = new JsonSpecGenerator(b, pn == null ? null : pn.substring(0, pn.indexOf(".")) + "-definitions.html", null, this, "", version.toCode());
TypeParser tp = new TypeParser(version.toCode());
TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
ElementDefn e = definitions.getElementDefn(t.getName());
if (e == null) {
gen.close();
throw new Exception("unable to find definition for " + dt);
} else {
gen.generate(e, false, false);
gen.close();
}
String val = new String(b.toByteArray()) + "\r\n";
return val;
}
use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.
the class PageProcessor method buildCircularReferenceList.
private void buildCircularReferenceList(StringBuilder b, String s, ElementDefn t, ResourceDefn rd, Boolean hierarchy) {
if (t.getHierarchy() == hierarchy)
for (TypeRef tr : t.getTypes()) {
if (tr.getName().equals("Reference") || tr.getName().equals("canonical"))
for (String p : tr.getParams()) {
if (s.equals(p)) {
b.append("<li><a href=\"" + s.toLowerCase() + "-definitions.html#" + t.getPath() + "\">");
b.append(t.getPath());
b.append("</a>");
boolean first = true;
for (String spn : sorted(rd.getSearchParams().keySet())) {
SearchParameterDefn sp = rd.getSearchParams().get(spn);
if (pointsAtElement(sp, t)) {
if (first) {
b.append(" (");
first = false;
} else
b.append(",");
b.append(sp.getCode());
}
}
if (!first)
b.append(")");
b.append("</li>");
}
}
}
for (ElementDefn e : t.getElements()) buildCircularReferenceList(b, s, e, rd, hierarchy);
}
use of org.hl7.fhir.definitions.model.TypeRef 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.TypeRef in project kindling by HL7.
the class OldSpreadsheetParser method parseExtensionElement.
private void parseExtensionElement(Sheet sheet, int row, Definitions definitions, ElementDefn exe, boolean nested) throws Exception {
// things that go on Extension
String[] card = sheet.getColumn(row, "Card.").split("\\.\\.");
if (card.length != 2 || !Utilities.isInteger(card[0]) || (!"*".equals(card[1]) && !Utilities.isInteger(card[1])))
throw new Exception("Unable to parse Cardinality " + sheet.getColumn(row, "Card.") + " in " + getLocation(row));
exe.setMinCardinality(Integer.parseInt(card[0]));
exe.setMaxCardinality("*".equals(card[1]) ? Integer.MAX_VALUE : Integer.parseInt(card[1]));
exe.setDefinition(Utilities.appendPeriod(processDefinition(sheet.getColumn(row, "Definition"))));
exe.setRequirements(Utilities.appendPeriod(sheet.getColumn(row, "Requirements")));
exe.setComments(Utilities.appendPeriod(sheet.getColumn(row, "Comments")));
doAliases(sheet, row, exe);
for (String n : mappings.keySet()) {
exe.addMapping(n, sheet.getColumn(row, mappings.get(n).getColumnName()).trim());
}
exe.setTodo(Utilities.appendPeriod(sheet.getColumn(row, "To Do")));
exe.setCommitteeNotes(Utilities.appendPeriod(sheet.getColumn(row, "Committee Notes")));
exe.setShortDefn(sheet.getColumn(row, "Short Name"));
exe.setIsModifier(parseBoolean(sheet.getColumn(row, "Is Modifier"), row, null));
if (exe.isModifier()) {
String reason = sheet.getColumn(row, "Modifier Reason");
if (Utilities.noString(reason)) {
System.out.println("Missing IsModifierReason on extension @ " + getLocation(row));
reason = "Not known why this is labelled a modifier";
}
exe.setModifierReason(reason);
}
if (nested && exe.isModifier())
throw new Exception("Cannot create a nested extension that is a modifier @" + getLocation(row));
exe.getTypes().add(new TypeRef().setName("Extension"));
// things that go on Extension.value
if (!Utilities.noString(sheet.getColumn(row, "Type"))) {
ElementDefn exv = new ElementDefn();
exv.setName("value[x]");
exv.getTypes().addAll(new TypeParser(version.toCode()).parse(sheet.getColumn(row, "Type"), true, profileExtensionBase, context, false, sheet.title));
/* if (!exv.getName().equals("value[x]")) {
ElementDefn exd = new ElementDefn();
exd.setName("value[x]");
exd.setMaxCardinality(1);
exd.getTypes().add(new TypeRef(exv.getTypes().get(0).getName()));
List<String> discriminator = new ArrayList<String>();
discriminator.add("@type");
exd.setDiscriminator(discriminator);
exe.getElements().add(exd);
exv.setProfileName("value");
}*/
exe.getElements().add(exv);
String bindingName = sheet.getColumn(row, "Binding");
if (!Utilities.noString(bindingName)) {
BindingSpecification binding = bindings.get(bindingName);
if (binding == null && definitions != null)
binding = definitions.getCommonBindings().get(bindingName);
if (binding == null) {
if (bindingName.startsWith("!"))
exv.setNoBindingAllowed(true);
else
throw new Exception("Binding name " + bindingName + " could not be resolved in local spreadsheet");
}
exv.setBinding(binding);
if (binding != null && !binding.getUseContexts().contains(name))
binding.getUseContexts().add(name);
}
// exv.setBinding();
exv.setMaxLength(sheet.getColumn(row, "Max Length"));
exv.setExample(processValue(sheet, row, "Example", sheet.getColumn(row, "Example"), exv));
}
}
Aggregations