Search in sources :

Example 51 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class ResourceParser method parseResource.

private ResourceDefn parseResource(String t) throws FHIRFormatError, FileNotFoundException, IOException {
    StructureDefinition sd = (StructureDefinition) parseXml("structuredefinition-" + t + ".xml");
    sdList.put(sd.getUrl(), sd);
    sd.setVersion(version);
    ResourceDefn r = new ResourceDefn();
    r.setName(sd.getName());
    r.setEnteredInErrorStatus(ToolingExtensions.readStringExtension(sd, BuildExtensions.EXT_ENTERED_IN_ERROR_STATUS));
    r.setStatus(StandardsStatus.fromCode(ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_STANDARDS_STATUS)));
    r.setAbstract(sd.getAbstract());
    r.setInterface(ToolingExtensions.readBoolExtension(sd, BuildExtensions.EXT_RESOURCE_INTERFACE));
    r.setWg(definitions.getWorkgroups().get(ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_WORKGROUP)));
    r.setFmmLevel(ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_FMM_LEVEL));
    r.setProposedOrder(ToolingExtensions.readStringExtension(sd, BuildExtensions.EXT_PROPOSED_ORDER));
    r.setSecurityCategorization(SecurityCategorization.fromCode(ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category")));
    r.setRequirements(sd.getPurpose());
    r.setDefinition(sd.getDescription());
    if (sd.hasExtension(BuildExtensions.EXT_TEMPLATE)) {
        String tname = BuildExtensions.readStringExtension(sd, BuildExtensions.EXT_TEMPLATE);
        ResourceDefn template = definitions.getResourceByName(tname);
        r.setTemplate(template.getRoot());
    }
    // private long timestamp; only set in regenerator...?
    // todo:
    // private List<InheritedMapping> inheritedMappings = new ArrayList<InheritedMapping>();
    // private ElementDefn template;
    // private Map<String, PointSpec> layout = new HashMap<String, PointSpec>();
    ProfileUtilities pu = new ProfileUtilities(context, null, null);
    r.setRoot(parseTypeDefinition(pu, sd.getDifferential().getElementFirstRep(), sd));
    r.getRoot().setFmmLevel(r.getFmmLevel());
    r.getRoot().setRequirements(r.getRequirements());
    if (r.isAbstract()) {
        r.getRoot().setAbstractType(true);
    }
    if (sd.hasBaseDefinition()) {
        r.getRoot().getTypes().add(new TypeRef(sd.getBaseDefinition().replace("http://hl7.org/fhir/StructureDefinition/", "")));
    }
    return r;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 52 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class ResourceParser method parsePacks.

private void parsePacks(ResourceDefn r, String n, String t) throws Exception {
    Set<String> codes = new HashSet<>();
    ListResource list = (ListResource) parseXml("list-" + t + "-packs.xml");
    for (ListResourceEntryComponent le : list.getEntry()) {
        String id = le.getItem().getReference().substring(le.getItem().getReference().indexOf("/") + 1);
        if (codes.contains(id)) {
            throw new FHIRException("Duplicate code " + id + " for resource " + n);
        }
        codes.add(id);
        ImplementationGuide ig = (ImplementationGuide) parseXml("implementationguide-" + id + ".xml");
        if (!id.startsWith(r.getName() + "-")) {
            throw new FHIRException("Illegal ig name " + id + " - should start with " + r.getName() + "-");
        }
        id = id.substring(t.length() + 1);
        r.getConformancePackages().add(convertPack(ig, id, r.getWg()));
    }
}
Also used : ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) ListResourceEntryComponent(org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent) ListResource(org.hl7.fhir.r5.model.ListResource) FHIRException(org.hl7.fhir.exceptions.FHIRException) HashSet(java.util.HashSet)

Example 53 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class ResourceParser method parseSearchParameter.

private void parseSearchParameter(ResourceDefn r, SearchParameter src) {
    if (!src.hasName()) {
        src.setName(src.getCode());
    }
    src.setVersion(version);
    SearchParameterDefn sp = new SearchParameterDefn(src.getCode(), src.getDescription(), type(src.getType()), src.getXpathUsage(), StandardsStatus.fromCode(BuildExtensions.readStringExtension(src, "http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status")));
    r.getSearchParams().put(sp.getCode(), sp);
    sp.setExpression(src.getExpression());
    sp.setXPath(src.getXpath());
    sp.setResource(src);
    String s = BuildExtensions.readStringExtension(src, BuildExtensions.EXT_PATH);
    if (!Utilities.noString(s)) {
        for (String p : s.split("\\,")) {
            String v = p.trim();
            if (!Utilities.noString(v)) {
                sp.getPaths().add(v);
            }
        }
    }
    for (SearchParameterComponentComponent comp : src.getComponent()) {
        sp.getComposites().add(new CompositeDefinition(comp.getDefinition(), comp.getExpression()));
    }
}
Also used : SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) CompositeDefinition(org.hl7.fhir.definitions.model.SearchParameterDefn.CompositeDefinition) SearchParameterComponentComponent(org.hl7.fhir.r5.model.SearchParameter.SearchParameterComponentComponent)

Example 54 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class SvgGenerator method drawClass.

private ClassItem drawClass(XMLWriter xml, ElementDefn e, boolean isRoot, ResourceDefn resource, boolean link, String path, DefinedCode primitive, StandardsStatus status) throws Exception {
    ClassItem item = classes.get(e);
    String tn = e.getName();
    if (!definitions.hasPrimitiveType(tn) && !tn.equals("xhtml")) {
        tn = Utilities.capitalize(tn);
    }
    ResourceDefn r = definitions.hasResource(tn) ? definitions.getResourceByName(tn) : null;
    if (r == null) {
        r = definitions.getBaseResources().get(tn);
    }
    xml.attribute("id", "n" + (++nc));
    xml.enter("g");
    xml.attribute("x", Double.toString(item.left));
    xml.attribute("y", Double.toString(item.top));
    xml.attribute("rx", "4");
    xml.attribute("ry", "4");
    xml.attribute("width", Double.toString(item.width));
    xml.attribute("height", Double.toString(item.height));
    xml.attribute("filter", "url(#shadow" + id + ")");
    if (r != null) {
        xml.attribute("style", "fill:" + r.getStatus().getColorSvg() + ";stroke:black;stroke-width:1");
        status = r.getStatus();
    } else if (e == null || e.getStandardsStatus() == null)
        xml.attribute("style", "fill:" + (status == null ? "#ffffff" : status.getColorSvg()) + ";stroke:black;stroke-width:1");
    else {
        xml.attribute("style", "fill:" + e.getStandardsStatus().getColorSvg() + ";stroke:black;stroke-width:1");
        status = e.getStandardsStatus();
    }
    if (!makeTargets)
        xml.attribute("id", "n" + (++nc));
    else
        xml.attribute("id", item.getId());
    xml.element("rect", null);
    xml.attribute("x1", Double.toString(item.left));
    xml.attribute("y1", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
    xml.attribute("x2", Double.toString(item.left + item.width));
    xml.attribute("y2", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
    xml.attribute("style", "stroke:dimgrey;stroke-width:1");
    xml.attribute("id", "n" + (++nc));
    xml.element("line", null);
    xml.attribute("x", Double.toString(item.left + item.width / 2));
    xml.attribute("y", Double.toString(item.top + HEADER_HEIGHT));
    xml.attribute("fill", "black");
    if (isRoot)
        xml.attribute("class", "diagram-class-title  diagram-class-resource");
    else
        xml.attribute("class", "diagram-class-title");
    if (link) {
        xml.attribute("id", "n" + (++nc));
        if (e.isAbstractType()) {
            xml.attribute("style", "font-style: italic");
        }
        xml.enter("text");
        xml.attribute("xlink:href", makeRel(definitions.getSrcFile(tn) + ".html#" + tn));
        xml.attribute("id", "n" + (++nc));
        xml.enter("a");
        xml.text(tn);
        xml.exit("a");
        if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#interface"));
            xml.enter("a");
            xml.text("«Interface»");
            xml.exit("a");
        }
        xml.exit("text");
    } else if (isRoot) {
        xml.attribute("id", "n" + (++nc));
        if (e.isAbstractType()) {
            xml.attribute("style", "font-style: italic");
        }
        xml.enter("text");
        xml.text(tn);
        if (Utilities.noString(e.typeCode())) {
            xml.text(" \u00ABResource\u00BB");
        } else {
            xml.attribute("class", "diagram-class-title-link");
            xml.enter("tspan");
            xml.text(" (");
            if ("Logical".equals(e.typeCode()))
                xml.attribute("xlink:href", prefix + definitions.getBaseLink());
            else
                xml.attribute("xlink:href", prefix + definitions.getSrcFile(e.typeCode()) + ".html#" + e.typeCode());
            xml.attribute("class", "diagram-class-reference");
            xml.attribute("id", "n" + (++nc));
            xml.attribute("style", "font-style: italic");
            if ("Logical".equals(e.typeCode())) {
                xml.element("a", "Base");
            } else {
                xml.element("a", e.typeCode());
            }
            xml.text(")");
            xml.exit("tspan");
        }
        if ("Logical".equals(e.typeCode())) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#pattern"));
            xml.enter("a");
            xml.text("«Pattern»");
            xml.exit("a");
        }
        if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#interface"));
            xml.enter("a");
            xml.text("«Interface»");
            xml.exit("a");
        }
        xml.exit("text");
    } else if (e.hasStatedType()) {
        xml.attribute("id", "n" + (++nc));
        xml.element("text", e.getStatedType());
    } else {
        xml.attribute("id", "n" + (++nc));
        xml.element("text", tn);
    }
    if (attributes) {
        if (primitive != null) {
            if (primitive instanceof PrimitiveType)
                addValueAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT, getXsi(primitive).split("\\|"));
        } else {
            int i = 0;
            for (ElementDefn c : e.getElements()) {
                if (isAttribute(c)) {
                    i++;
                    addAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT * i, c, path, LINE_HEIGHT, item.width);
                    String[] texts = textForAttribute(c);
                    i = i + texts.length - 1;
                }
            }
        }
    }
    xml.exit("g");
    if (attributes) {
        for (ElementDefn c : e.getElements()) {
            if (!isAttribute(c)) {
                if (Utilities.noString(c.typeCode()) || !c.typeCode().startsWith("@")) {
                    links.add(new Link(item, drawClass(xml, c, false, resource, false, path + "." + c.getName(), null, status), LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
                } else {
                    ClassItem target = getItemForPath(resource, c.typeCode().substring(1));
                    links.add(new Link(item, target, LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
                }
            }
        }
    }
    return item;
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 55 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class Regenerator method generateSearchParameter.

private CanonicalResource generateSearchParameter(String root, ResourceDefn r, Profile p, SearchParameter sp) throws IOException {
    File fn = new File(Utilities.path(root, sp.fhirType().toLowerCase() + "-profile-" + sp.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sp);
    fn.setLastModified(r.getTimestamp());
    return sp;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)75 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)42 ArrayList (java.util.ArrayList)38 FHIRException (org.hl7.fhir.exceptions.FHIRException)36 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)31 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)28 File (java.io.File)26 FileOutputStream (java.io.FileOutputStream)25 CSFile (org.hl7.fhir.utilities.CSFile)24 XmlParser (org.hl7.fhir.r5.formats.XmlParser)22 FileNotFoundException (java.io.FileNotFoundException)20 IOException (java.io.IOException)20 Example (org.hl7.fhir.definitions.model.Example)20 Profile (org.hl7.fhir.definitions.model.Profile)20 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)18 IniFile (org.hl7.fhir.utilities.IniFile)18 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)16 TransformerException (javax.xml.transform.TransformerException)15 TextFile (org.hl7.fhir.utilities.TextFile)15 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)14