use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class PageProcessor method genDataTypeMappings.
private String genDataTypeMappings(String name) throws Exception {
if (name.equals("primitives")) {
StringBuilder b = new StringBuilder();
b.append("<table class=\"grid\">\r\n");
b.append("<tr>");
b.append("<td><b>Data Type</b></td>");
b.append("<td><b>V2</b></td>");
b.append("<td><b>RIM</b></td>");
b.append("</tr>");
List<String> names = new ArrayList<String>();
names.addAll(definitions.getPrimitives().keySet());
Collections.sort(names);
for (String n : names) {
DefinedCode dc = definitions.getPrimitives().get(n);
if (dc instanceof PrimitiveType) {
PrimitiveType pt = (PrimitiveType) dc;
b.append("<tr>");
b.append("<td>").append(n).append("</td>");
b.append("<td>").append(pt.getV2()).append("</td>");
b.append("<td>").append(pt.getV3()).append("</td>");
b.append("</tr>");
}
}
b.append("</table>\r\n");
return b.toString();
} else {
List<ElementDefn> list = new ArrayList<ElementDefn>();
// list.addAll(definitions.getStructures().values());
// list.addAll(definitions.getTypes().values());
// list.addAll(definitions.getInfrastructure().values());
list.add(definitions.getElementDefn(name));
MappingsGenerator maps = new MappingsGenerator(definitions);
maps.generate(list);
return maps.getMappings();
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class OldSpreadsheetParser method parseProfileSheet.
private ConstraintStructure parseProfileSheet(Definitions definitions, Profile ap, String n, List<String> namedSheets, boolean published, String usage, List<ValidationMessage> issues, WorkGroup wg, String fmm) throws Exception {
Sheet sheet;
ResourceDefn resource = new ResourceDefn();
sheet = loadSheet(n + "-Inv");
Map<String, Invariant> invariants = null;
if (sheet != null) {
invariants = readInvariants(sheet, n, n + "-Inv");
} else {
invariants = new HashMap<String, Invariant>();
}
sheet = loadSheet(n);
if (sheet == null)
throw new Exception("The StructureDefinition referred to a tab by the name of '" + n + "', but no tab by the name could be found");
for (int row = 0; row < sheet.rows.size(); row++) {
ElementDefn e = processLine(resource, sheet, row, invariants, true, ap, row == 0);
if (e != null)
for (TypeRef t : e.getTypes()) {
if (t.getProfile() != null && !t.getName().equals("Extension") && t.getProfile().startsWith("#")) {
if (!namedSheets.contains(t.getProfile().substring(1)))
namedSheets.add(t.getProfile().substring(1));
}
}
}
sheet = loadSheet(n + "-Extensions");
if (sheet != null) {
int row = 0;
while (row < sheet.rows.size()) {
if (sheet.getColumn(row, "Code").startsWith("!"))
row++;
else
row = processExtension(resource.getRoot().getElementByName(definitions, "extensions", true, false), sheet, row, definitions, ap.metadata("extension.uri"), ap, issues, invariants, wg);
}
}
sheet = loadSheet(n + "-Search");
if (sheet != null) {
readSearchParams(resource, sheet, true);
}
if (invariants != null) {
for (Invariant inv : invariants.values()) {
if (Utilities.noString(inv.getContext()))
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " has no context");
else {
ElementDefn ed = findContext(resource.getRoot(), inv.getContext(), "Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " Context");
// TODO: Need to resolve context based on element name, not just path
if (ed.getName().endsWith("[x]") && !inv.getContext().endsWith("[x]"))
inv.setFixedName(inv.getContext().substring(inv.getContext().lastIndexOf(".") + 1));
ed.getInvariants().put(inv.getId(), inv);
if (Utilities.noString(inv.getXpath())) {
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") has no XPath statement");
} else if (inv.getXpath().contains("\""))
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") contains a \" character");
// if (Utilities.noString(inv.getExpression()))
// throw new Exception("Type "+resource.getRoot().getName()+" Invariant "+inv.getId()+" ("+inv.getEnglish()+") has no Expression statement (in FHIRPath format)");
}
}
}
resource.getRoot().setProfileName(n);
if (n.toLowerCase().equals(ap.getId()))
throw new Exception("Duplicate Profile Name: Package id " + ap.getId() + " and profile id " + n.toLowerCase() + " are the same");
if (profileIds.containsKey(n.toLowerCase()))
throw new Exception("Duplicate Profile Name: " + n.toLowerCase() + " in " + ap.getId() + ", already registered in " + profileIds.get(n.toLowerCase()).getOwner());
ConstraintStructure p = new ConstraintStructure(n.toLowerCase(), resource.getRoot().getProfileName(), resource, ig != null ? ig : definitions.getUsageIG(usage, "Parsing " + name), wg, fmm, Utilities.existsInList(ap.metadata("Experimental"), "y", "Y", "true", "TRUE", "1"));
p.setOwner(ap.getId());
profileIds.put(n.toLowerCase(), p);
return p;
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class OldSpreadsheetParser method resolveElementReferences.
private void resolveElementReferences(ResourceDefn parent, ElementDefn root) throws Exception {
for (TypeRef ref : root.getTypes()) {
if (ref.isElementReference()) {
ElementDefn referredElement = parent.getRoot().getElementByName(definitions, ref.getName().substring(1), true, false, null);
if (referredElement == null)
throw new Exception("Element reference " + ref.getName() + " cannot be found in type " + parent.getName());
if (referredElement.getDeclaredTypeName() == null)
throw new Exception("Element reference " + ref.getName() + " in " + parent.getName() + " refers to an anonymous group of elements. Please specify names with the '=<name>' construct in the typename column.");
ref.setResolvedTypeName(referredElement.getDeclaredTypeName());
}
}
for (ElementDefn element : root.getElements()) {
resolveElementReferences(parent, element);
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class OldSpreadsheetParser method parseCommonTypeColumns.
private ResourceDefn parseCommonTypeColumns(boolean isResource, boolean isTemplate) throws Exception {
ResourceDefn resource = new ResourceDefn();
resource.setInterface(isTemplate);
Sheet sheet = loadSheet("Bindings");
if (sheet != null)
readBindings(sheet);
sheet = loadSheet("Invariants");
Map<String, Invariant> invariants = null;
if (sheet != null)
invariants = readInvariants(sheet, title, "Invariants");
sheet = loadSheet("Data Elements");
if (sheet == null)
throw new Exception("No Sheet found for Data Elements");
for (int row = 0; row < sheet.rows.size(); row++) {
processLine(resource, sheet, row, invariants, false, null, row == 0);
}
// default...
StandardsStatus ss = StandardsStatus.TRIAL_USE;
String s = ini.getStringProperty("normative", resource.getName());
if (!Utilities.noString(s))
ss = StandardsStatus.NORMATIVE;
resource.setStatus(ss);
resource.setRequirements(resource.getRoot().getRequirements());
resource.addHints(checkIgnoredColumns(sheet));
if (template != null) {
resource.setTemplate(template.getRoot());
copySearchParameters(resource);
copyInvariants(resource);
template = null;
}
parseMetadata(resource);
if (invariants != null) {
for (Invariant inv : invariants.values()) {
if (Utilities.noString(inv.getContext()))
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " has no context");
else {
ElementDefn ed = findContext(resource.getRoot(), inv.getContext(), "Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " Context");
if (ed.getName().endsWith("[x]") && !inv.getContext().endsWith("[x]"))
inv.setFixedName(inv.getContext().substring(inv.getContext().lastIndexOf(".") + 1));
ed.getInvariants().put(inv.getId(), inv);
if (Utilities.noString(inv.getXpath())) {
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") has no XPath statement");
} else if (inv.getXpath().contains("\""))
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") contains a \" character");
if (Utilities.noString(inv.getExpression())) {
// This has been disabled for now, per Lloyd McKenzie's request via Skype - jamesagnew
// throw new Exception("Type "+resource.getRoot().getName()+" Invariant "+inv.getId()+" ("+inv.getEnglish()+") has no Expression statement (in FHIRPath format)");
} else {
fpUsages.add(new FHIRPathUsage(inv.getContext(), isResource ? resource.getName() : "DomainResource", inv.getContext(), null, inv.getExpression(), inv.getXpath()));
}
}
}
}
// EK: Future types. But those won't get there.
if (bindings != null)
resource.getRoot().getNestedBindings().putAll(bindings);
scanNestedTypes(resource, resource.getRoot(), resource.getName());
resolveElementReferences(resource, resource.getRoot());
resource.getRoot().setAbstractType(isAbstract);
return resource;
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class OldSpreadsheetParser method scanNestedTypes.
private void scanNestedTypes(ResourceDefn parent, ElementDefn root, String parentName) throws Exception {
for (ElementDefn element : root.getElements()) {
if (element.hasNestedElements()) {
String nestedTypeName;
ElementDefn newCompositeType = new ElementDefn();
// generated name for this nested type
if (element.typeCode().startsWith("=")) {
if (isProfile)
throw new Exception("Cannot use '=' types in profiles on " + parentName);
element.setStatedType(element.typeCode().substring(1));
nestedTypeName = element.typeCode().substring(1);
} else {
nestedTypeName = parentName + Utilities.capitalize(element.getName());
}
newCompositeType.setAnonymousTypedGroup(true);
// Add Component to the actually generated name to avoid
// confusing between the element name and the element's type
newCompositeType.setName(nestedTypeName + "Component");
newCompositeType.setDefinition("A nested type in " + parent.getName() + ": " + element.getDefinition());
newCompositeType.getElements().addAll(element.getElements());
if (parent.getRoot().getNestedTypes().containsKey(nestedTypeName))
throw new Exception("Nested type " + nestedTypeName + " already exist in resource " + parent.getName());
parent.getRoot().getNestedTypes().put(nestedTypeName, newCompositeType);
// Clear out the name of the local type, so old code
// will not see a change.
element.getTypes().clear();
element.setDeclaredTypeName(newCompositeType.getName());
scanNestedTypes(parent, element, nestedTypeName);
}
}
}
Aggregations