Search in sources :

Example 11 with TypeParser

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));
    }
}
Also used : TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

TypeRef (org.hl7.fhir.definitions.model.TypeRef)10 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 URISyntaxException (java.net.URISyntaxException)6 File (java.io.File)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 TransformerException (javax.xml.transform.TransformerException)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 UcumException (org.fhir.ucum.UcumException)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)5 ITypeParser (org.hl7.fhir.r5.renderers.utils.RenderingContext.ITypeParser)5 CSFile (org.hl7.fhir.utilities.CSFile)5 IniFile (org.hl7.fhir.utilities.IniFile)5 TextFile (org.hl7.fhir.utilities.TextFile)5 FileOutputStream (java.io.FileOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2