Search in sources :

Example 16 with ElementDefn

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();
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType) MappingsGenerator(org.hl7.fhir.definitions.generators.specification.MappingsGenerator)

Example 17 with ElementDefn

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;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 18 with ElementDefn

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

Example 19 with ElementDefn

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;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) FHIRPathUsage(org.hl7.fhir.definitions.validation.FHIRPathUsage) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 20 with ElementDefn

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

Aggregations

ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)100 TypeRef (org.hl7.fhir.definitions.model.TypeRef)35 ArrayList (java.util.ArrayList)28 FHIRException (org.hl7.fhir.exceptions.FHIRException)28 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)21 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)19 Invariant (org.hl7.fhir.definitions.model.Invariant)16 IOException (java.io.IOException)14 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)11 FileNotFoundException (java.io.FileNotFoundException)10 URISyntaxException (java.net.URISyntaxException)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)9 TransformerException (javax.xml.transform.TransformerException)8 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7 UcumException (org.fhir.ucum.UcumException)7 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7