Search in sources :

Example 11 with StandardsStatus

use of org.hl7.fhir.utilities.StandardsStatus 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 12 with StandardsStatus

use of org.hl7.fhir.utilities.StandardsStatus in project kindling by HL7.

the class ProfileGenerator method makeSearchParam.

public SearchParameter makeSearchParam(StructureDefinition p, String id, String rn, SearchParameterDefn spd, ResourceDefn rd) throws Exception {
    boolean shared;
    boolean created = true;
    SearchParameter sp;
    if (definitions.getCommonSearchParameters().containsKey(rn + "::" + spd.getCode())) {
        shared = true;
        CommonSearchParameter csp = definitions.getCommonSearchParameters().get(rn + "::" + spd.getCode());
        if (csp.getDefinition() == null) {
            sp = new SearchParameter();
            csp.setDefinition(sp);
            sp.setId(csp.getId());
        } else {
            created = false;
            sp = csp.getDefinition();
        }
    } else {
        shared = false;
        sp = new SearchParameter();
        sp.setId(id.replace("[", "").replace("]", ""));
    }
    spd.setCommonId(sp.getId());
    if (created) {
        sp.setUrl("http://hl7.org/fhir/SearchParameter/" + sp.getId());
        sp.setVersion(version.toCode());
        if (context.getSearchParameter(sp.getUrl()) != null)
            throw new Exception("Duplicated Search Parameter " + sp.getUrl());
        context.cacheResource(sp);
        spd.setResource(sp);
        definitions.addNs(sp.getUrl(), "Search Parameter: " + sp.getName(), rn.toLowerCase() + ".html#search");
        sp.setStatus(spd.getStandardsStatus() == StandardsStatus.NORMATIVE ? PublicationStatus.fromCode("active") : PublicationStatus.fromCode("draft"));
        StandardsStatus sst = ToolingExtensions.getStandardsStatus(sp);
        if (sst == null || (spd.getStandardsStatus() == null && spd.getStandardsStatus().isLowerThan(sst)))
            ToolingExtensions.setStandardsStatus(sp, spd.getStandardsStatus(), spd.getNormativeVersion());
        sp.setExperimental(p.getExperimental());
        sp.setName(spd.getCode());
        sp.setCode(spd.getCode());
        sp.setDate(genDate.getTime());
        sp.setPublisher(p.getPublisher());
        for (ContactDetail tc : p.getContact()) {
            ContactDetail t = sp.addContact();
            if (tc.hasNameElement())
                t.setNameElement(tc.getNameElement().copy());
            for (ContactPoint ts : tc.getTelecom()) t.getTelecom().add(ts.copy());
        }
        if (!definitions.hasResource(p.getType()) && !p.getType().equals("Resource") && !p.getType().equals("DomainResource"))
            throw new Exception("unknown resource type " + p.getType());
        sp.setType(getSearchParamType(spd.getType()));
        if (sp.getType() == SearchParamType.REFERENCE && spd.isHierarchy()) {
            sp.addModifier(SearchParameter.SearchModifierCode.BELOW);
            sp.addModifier(SearchParameter.SearchModifierCode.ABOVE);
        }
        if (shared) {
            sp.setDescription("Multiple Resources: \r\n\r\n* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
        } else
            sp.setDescription(preProcessMarkdown(spd.getDescription(), "Search Description"));
        if (!Utilities.noString(spd.getExpression()))
            sp.setExpression(spd.getExpression());
        // addModifiers(sp);
        addComparators(sp);
        String xpath = Utilities.noString(spd.getXPath()) ? new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn) : spd.getXPath();
        if (xpath != null) {
            if (xpath.contains("[x]"))
                xpath = convertToXpath(xpath);
            sp.setXpath(xpath);
            sp.setXpathUsage(spd.getxPathUsage());
        }
        if (sp.getType() == SearchParamType.COMPOSITE) {
            for (CompositeDefinition cs : spd.getComposites()) {
                SearchParameterDefn cspd = findSearchParameter(rd, cs.getDefinition());
                if (cspd != null)
                    sp.addComponent().setExpression(cs.getExpression()).setDefinition(cspd.getUrl());
                else
                    sp.addComponent().setExpression(cs.getExpression()).setDefinition("http://hl7.org/fhir/SearchParameter/" + rn + "-" + cs.getDefinition());
            }
            sp.setMultipleOr(false);
        }
        sp.addBase(p.getType());
    } else {
        if (sp.getType() != getSearchParamType(spd.getType()))
            throw new FHIRException("Type mismatch on common parameter: expected " + sp.getType().toCode() + " but found " + getSearchParamType(spd.getType()).toCode());
        if (!sp.getDescription().contains("[" + rn + "](" + rn.toLowerCase() + ".html)"))
            sp.setDescription(sp.getDescription() + "* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
        // ext.addExtension("description", new MarkdownType(spd.getDescription()));
        if (!Utilities.noString(spd.getExpression()) && !sp.getExpression().contains(spd.getExpression()))
            sp.setExpression(sp.getExpression() + " | " + spd.getExpression());
        String xpath = new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn);
        if (xpath != null) {
            if (xpath.contains("[x]"))
                xpath = convertToXpath(xpath);
            if (sp.getXpath() != null && !sp.getXpath().contains(xpath))
                sp.setXpath(sp.getXpath() + " | " + xpath);
            if (sp.getXpathUsage() != spd.getxPathUsage())
                throw new FHIRException("Usage mismatch on common parameter: expected " + sp.getXpathUsage().toCode() + " but found " + spd.getxPathUsage().toCode());
        }
        boolean found = false;
        for (CodeType ct : sp.getBase()) found = found || p.getType().equals(ct.asStringValue());
        if (!found)
            sp.addBase(p.getType());
    }
    spd.setUrl(sp.getUrl());
    for (String target : spd.getWorkingTargets()) {
        if ("Any".equals(target) == true) {
            for (String resourceName : definitions.sortedResourceNames()) {
                boolean found = false;
                for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(resourceName);
                if (!found)
                    sp.addTarget(resourceName);
            }
        } else {
            boolean found = false;
            for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(target);
            if (!found)
                sp.addTarget(target);
        }
    }
    return sp;
}
Also used : SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) CompositeDefinition(org.hl7.fhir.definitions.model.SearchParameterDefn.CompositeDefinition) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) CodeType(org.hl7.fhir.r5.model.CodeType) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus)

Example 13 with StandardsStatus

use of org.hl7.fhir.utilities.StandardsStatus in project kindling by HL7.

the class ResourceDependencyGenerator method addBindingToAnalysis.

private void addBindingToAnalysis(HierarchicalTableGenerator gen, Row row, Cell dc, boolean req, StandardsStatus elementStatus, BindingSpecification binding) throws FHIRException {
    String tgtFMM = null;
    StandardsStatus tgtSS = null;
    ValueSet vs = binding.getValueSet();
    if (vs != null) {
        tgtFMM = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_FMM_LEVEL);
        tgtSS = ToolingExtensions.getStandardsStatus(vs);
    } else if (Utilities.existsInList(binding.getReference(), "http://www.rfc-editor.org/bcp/bcp13.txt")) {
        tgtFMM = "5";
        tgtSS = StandardsStatus.EXTERNAL;
    }
    if (elementStatus == null)
        elementStatus = sstatus;
    if (tgtFMM == null)
        addError(gen, row, dc, "Binding Error: Unable to resolve vs '" + binding.getReference() + "' to check dependencies", null);
    else {
        boolean ok = elementStatus.canDependOn(tgtSS);
        if (ok)
            ok = fmm.compareTo(tgtFMM) <= 0;
        if (ok)
            // addInfo(gen, row, dc, "Binding OK (ValueSet = FMM"+tgtFMM+"-"+tgtSS.toDisplay()+" vs. Element = FMM"+fmm+"-"+elementStatus.toDisplay()+")", null);
            ;
        else
            addError(gen, row, dc, "Binding Error: (ValueSet = FMM" + tgtFMM + "-" + tgtSS.toDisplay() + " vs. Element = FMM" + fmm + "-" + elementStatus.toDisplay() + ")", vs.getUserString("path"));
    }
}
Also used : StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 14 with StandardsStatus

use of org.hl7.fhir.utilities.StandardsStatus in project org.hl7.fhir.core by hapifhir.

the class CodeSystemUtilities method markStatus.

public static void markStatus(CodeSystem cs, String wg, StandardsStatus status, String pckage, String fmm, String normativeVersion) throws FHIRException {
    if (wg != null) {
        if (!ToolingExtensions.hasExtension(cs, ToolingExtensions.EXT_WORKGROUP) || (Utilities.existsInList(ToolingExtensions.readStringExtension(cs, ToolingExtensions.EXT_WORKGROUP), "fhir", "vocab") && !Utilities.existsInList(wg, "fhir", "vocab"))) {
            ToolingExtensions.setCodeExtension(cs, ToolingExtensions.EXT_WORKGROUP, wg);
        }
    }
    if (status != null) {
        StandardsStatus ss = ToolingExtensions.getStandardsStatus(cs);
        if (ss == null || ss.isLowerThan(status))
            ToolingExtensions.setStandardsStatus(cs, status, normativeVersion);
        if (pckage != null) {
            if (!cs.hasUserData("ballot.package"))
                cs.setUserData("ballot.package", pckage);
            else if (!pckage.equals(cs.getUserString("ballot.package")))
                if (!"infrastructure".equals(cs.getUserString("ballot.package")))
                    System.out.println("Code System " + cs.getUrl() + ": ownership clash " + pckage + " vs " + cs.getUserString("ballot.package"));
        }
        if (status == StandardsStatus.NORMATIVE) {
            cs.setExperimental(false);
            cs.setStatus(PublicationStatus.ACTIVE);
        }
    }
    if (fmm != null) {
        String sfmm = ToolingExtensions.readStringExtension(cs, ToolingExtensions.EXT_FMM_LEVEL);
        if (Utilities.noString(sfmm) || Integer.parseInt(sfmm) < Integer.parseInt(fmm)) {
            ToolingExtensions.setIntegerExtension(cs, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(fmm));
        }
        if (Integer.parseInt(fmm) <= 1) {
            cs.setExperimental(true);
        }
    }
}
Also used : StandardsStatus(org.hl7.fhir.utilities.StandardsStatus)

Example 15 with StandardsStatus

use of org.hl7.fhir.utilities.StandardsStatus in project org.hl7.fhir.core by hapifhir.

the class ValueSetUtilities method markStatus.

public static void markStatus(ValueSet vs, String wg, StandardsStatus status, String pckage, String fmm, IWorkerContext context, String normativeVersion) throws FHIRException {
    if (vs.hasUserData("external.url"))
        return;
    if (wg != null) {
        if (!ToolingExtensions.hasExtension(vs, ToolingExtensions.EXT_WORKGROUP) || (!Utilities.existsInList(ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP), "fhir", "vocab") && Utilities.existsInList(wg, "fhir", "vocab"))) {
            ToolingExtensions.setCodeExtension(vs, ToolingExtensions.EXT_WORKGROUP, wg);
        }
    }
    if (status != null) {
        StandardsStatus ss = ToolingExtensions.getStandardsStatus(vs);
        if (ss == null || ss.isLowerThan(status))
            ToolingExtensions.setStandardsStatus(vs, status, normativeVersion);
        if (pckage != null) {
            if (!vs.hasUserData("ballot.package"))
                vs.setUserData("ballot.package", pckage);
            else if (!pckage.equals(vs.getUserString("ballot.package")))
                if (!"infrastructure".equals(vs.getUserString("ballot.package")))
                    System.out.println("Value Set " + vs.getUrl() + ": ownership clash " + pckage + " vs " + vs.getUserString("ballot.package"));
        }
        if (status == StandardsStatus.NORMATIVE) {
            vs.setExperimental(false);
            vs.setStatus(PublicationStatus.ACTIVE);
        }
    }
    if (fmm != null) {
        String sfmm = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_FMM_LEVEL);
        if (Utilities.noString(sfmm) || Integer.parseInt(sfmm) < Integer.parseInt(fmm)) {
            ToolingExtensions.setIntegerExtension(vs, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(fmm));
        }
        if (Integer.parseInt(fmm) <= 1) {
            vs.setExperimental(true);
        }
    }
    if (vs.hasUserData("cs"))
        CodeSystemUtilities.markStatus((CodeSystem) vs.getUserData("cs"), wg, status, pckage, fmm, normativeVersion);
    else if (status == StandardsStatus.NORMATIVE && context != null) {
        for (ConceptSetComponent csc : vs.getCompose().getInclude()) {
            if (csc.hasSystem()) {
                CodeSystem cs = context.fetchCodeSystem(csc.getSystem());
                if (cs != null) {
                    CodeSystemUtilities.markStatus(cs, wg, status, pckage, fmm, normativeVersion);
                }
            }
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem)

Aggregations

StandardsStatus (org.hl7.fhir.utilities.StandardsStatus)20 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ArrayList (java.util.ArrayList)7 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)7 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 URISyntaxException (java.net.URISyntaxException)6 File (java.io.File)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)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 CSFile (org.hl7.fhir.utilities.CSFile)5 IniFile (org.hl7.fhir.utilities.IniFile)5 TextFile (org.hl7.fhir.utilities.TextFile)5 SvgGenerator (org.hl7.fhir.definitions.generators.specification.SvgGenerator)4