use of org.hl7.fhir.definitions.parsers.TypeParser 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