Search in sources :

Example 46 with StructureDefinition

use of org.hl7.fhir.r4b.model.StructureDefinition in project kindling by HL7.

the class CDAGenerator method addInfrastructureRootAttributes.

private void addInfrastructureRootAttributes(List<ElementDefinition> list, String path) {
    StructureDefinition any = getDataType("http://hl7.org/fhir/cda/StructureDefinition/ANY");
    addAbstractClassAttributes(list, path, any);
    StructureDefinition ir = getDataType("http://hl7.org/fhir/cda/StructureDefinition/InfrastructureRoot");
    addAbstractClassAttributes(list, path, ir);
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition)

Example 47 with StructureDefinition

use of org.hl7.fhir.r4b.model.StructureDefinition in project kindling by HL7.

the class CDAGenerator method processDataTypes.

private void processDataTypes(String filename) throws FileNotFoundException, ParserConfigurationException, SAXException, IOException, FHIRFormatError, DefinitionException {
    System.out.println("Process Data Types");
    Document dtMif = XMLUtil.parseFileToDom(filename);
    List<Element> dts = new ArrayList<Element>();
    XMLUtil.getNamedChildren(dtMif.getDocumentElement(), "mif:datatype", dts);
    for (Element dt : dts) {
        String n = dt.getAttribute("name");
        types.put(n, dt);
        if (n.equals("IVL")) {
            processDataType(dt, n + "_TS", "TS");
            processDataType(dt, n + "_PQ", "PQ");
            processDataType(dt, n + "_INT", "INT");
        } else if (n.equals("PIVL")) {
            processDataType(dt, n + "_TS", null);
        } else if (n.equals("EIVL")) {
            processDataType(dt, n + "_TS", null);
        } else if (n.equals("RTO")) {
            processDataType(dt, n + "_PQ_PQ", "PQ");
        } else if (!"Binding".equals(dt.getAttribute("datatypeKind")))
            processDataType(dt, n, null);
    }
    buildSXPR();
    buildInfrastructureRoot();
    for (StructureDefinition sd : structures) {
        // if (!sd.getAbstract())
        generateSnapShot(sd);
    }
    System.out.println(" ... done");
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document)

Example 48 with StructureDefinition

use of org.hl7.fhir.r4b.model.StructureDefinition in project kindling by HL7.

the class LogicalModelProcessor method genLogicalModelTable.

private String genLogicalModelTable(StructureDefinition sd, String prefix) throws Exception {
    ProfileUtilities pu = new ProfileUtilities(page.getWorkerContext(), null, this);
    XhtmlNode x = pu.generateTable(sd.getId() + "-definitions.html", sd, sd.hasSnapshot() ? false : true, page.getFolders().dstDir, false, sd.getId(), true, prefix, prefix, true, false, null, true, false);
    return new XhtmlComposer(XhtmlComposer.HTML).compose(x);
}
Also used : ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 49 with StructureDefinition

use of org.hl7.fhir.r4b.model.StructureDefinition in project kindling by HL7.

the class TypeParser method convert.

public List<TypeRefComponent> convert(IWorkerContext context, String path, List<TypeRef> types, boolean resource, ElementDefinition ed) throws Exception {
    List<TypeRefComponent> list = new ArrayList<TypeRefComponent>();
    for (TypeRef t : types) {
        // Expand any Resource(A|B|C) references
        if (t.hasParams() && !("Reference".equals(t.getName()) || "canonical".equals(t.getName()))) {
            throw new Exception("Only resource references can specify parameters.  Path " + path);
        }
        if (t.getParams().size() > 0) {
            if (t.getProfile() != null && t.getParams().size() != 1) {
                throw new Exception("Cannot declare profile on a resource reference declaring multiple resource types.  Path " + path);
            }
            if (t.getProfile() != null) {
                TypeRefComponent childType = getTypeComponent(list, t.getName());
                if (t.getVersioning() != null)
                    childType.setVersioning(t.getVersioning());
                if (t.getName().equals("Reference") || t.getName().equals("canonical"))
                    childType.addTargetProfile(t.getProfile());
                else
                    childType.addProfile(t.getProfile());
            } else
                for (String param : t.getParams()) {
                    TypeRefComponent childType = getTypeComponent(list, t.getName());
                    if (t.getVersioning() != null)
                        childType.setVersioning(t.getVersioning());
                    String p = "Any".equals(param) ? "Resource" : param;
                    if (t.getName().equals("Reference") || t.getName().equals("canonical"))
                        childType.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
                    else
                        childType.addProfile("http://hl7.org/fhir/StructureDefinition/" + p);
                }
        } else if (t.isWildcardType()) {
            // this list is filled out manually because it may be running before the types referred to have been loaded
            for (String n : TypesUtilities.wildcardTypes(version)) {
                TypeRefComponent tc = new TypeRefComponent().setCode(n);
                if (t.getVersioning() != null)
                    tc.setVersioning(t.getVersioning());
                list.add(tc);
            }
        } else if (Utilities.noString(t.getName()) && t.getProfile() != null) {
            StructureDefinition sd = context.fetchResource(StructureDefinition.class, t.getProfile());
            TypeRefComponent tc = getTypeComponent(list, sd != null ? sd.getType() : t.getName());
            if (t.getVersioning() != null)
                tc.setVersioning(t.getVersioning());
            if (t.getName().equals("Reference"))
                tc.addTargetProfile(t.getProfile());
            else
                tc.addProfile(t.getProfile());
        } else if (t.getName().startsWith("=")) {
            if (resource)
                list.add(new TypeRefComponent().setCode("BackboneElement"));
            else
                list.add(new TypeRefComponent().setCode("Element"));
            ToolingExtensions.addStringExtension(ed, "http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name", t.getName().substring(1));
        } else {
            StructureDefinition sd = context.fetchTypeDefinition(t.getName());
            if (sd == null)
                throw new Exception("Unknown type '" + t.getName() + "'");
            TypeRefComponent tc = getTypeComponent(list, sd.getType());
            if (t.getVersioning() != null)
                tc.setVersioning(t.getVersioning());
            if (t.getName().equals("Reference")) {
                if (t.hasProfile())
                    tc.addTargetProfile(t.getProfile());
            } else if (t.hasProfile())
                tc.addProfile(t.getProfile());
        }
    }
    // no duplicates
    for (TypeRefComponent tr1 : list) {
        for (TypeRefComponent tr2 : list) {
            if (tr1 != tr2) {
                if (tr1.getWorkingCode().equals(tr2.getWorkingCode()))
                    throw new Exception("duplicate code " + tr1.getWorkingCode());
            }
        }
    }
    return list;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList)

Example 50 with StructureDefinition

use of org.hl7.fhir.r4b.model.StructureDefinition 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)

Aggregations

ArrayList (java.util.ArrayList)307 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)241 FHIRException (org.hl7.fhir.exceptions.FHIRException)226 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)158 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)144 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)105 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)98 IOException (java.io.IOException)91 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)91 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)87 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)83 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)70 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)69 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)67 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)58 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)56 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)50 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)49 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)46 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)46