Search in sources :

Example 1 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project kindling by HL7.

the class Publisher method checkElement.

private void checkElement(StructureDefinition sd, ElementDefinition ed, boolean inDiff) {
    check(ed.hasPath(), sd, "Element has no path");
    Set<String> codes = new HashSet<String>();
    for (TypeRefComponent tr : ed.getType()) {
        String tc = tr.getWorkingCode();
        if (codes.contains(tc))
            check(false, sd, ed.getPath() + ": type '" + tc + "' is duplicated");
        if ((!inDiff || tr.hasCode()) && tc != null)
            if (ed.getPath().contains("."))
                check(page.getDefinitions().hasBaseType(tc) || tc.equals("Resource"), sd, ed.getPath() + ": type '" + tc + "' is not valid (a)");
            else if (sd.hasBaseDefinition()) {
                if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT)
                    check(page.getDefinitions().hasConcreteResource(tc) || page.getDefinitions().hasBaseType(tc), sd, ed.getPath() + ": type '" + tc + "' is not valid (b)");
                else
                    check(page.getDefinitions().hasAbstractResource(tc) || tc.equals("Element"), sd, ed.getPath() + ": type '" + tc + "' is not valid (c)");
            }
        if (tr.hasProfile()) {
            check(tr.getProfile().size() == 1, sd, ed.getPath() + ": multiple profiles found: " + tr.getProfile());
            String pt = tr.getProfile().get(0).getValue();
            if (pt.contains("#")) {
                String[] parts = pt.split("\\#");
                StructureDefinition exd = page.getWorkerContext().fetchResource(StructureDefinition.class, parts[0]);
                if (exd == null)
                    check(false, sd, ed.getPath() + ": profile '" + pt + "' is not valid (definition not found)");
                else {
                    ElementDefinition ex = null;
                    for (ElementDefinition et : exd.getSnapshot().getElement()) if (et.hasFixed() && et.getFixed() instanceof UriType && ((UriType) et.getFixed()).asStringValue().equals(parts[1]))
                        ex = et;
                    check(ex != null, sd, ed.getPath() + ": profile '" + pt + "' is not valid (inner path not found)");
                }
            } else
                check((page.getWorkerContext().hasResource(StructureDefinition.class, pt)) || isStringPattern(tail(pt)), sd, ed.getPath() + ": profile '" + pt + "' is not valid (d)");
        }
        if (tr.hasTargetProfile()) {
            String pt = tr.getTargetProfile().get(0).getValue();
            if (pt.contains("#")) {
                String[] parts = pt.split("\\#");
                StructureDefinition exd = page.getWorkerContext().fetchResource(StructureDefinition.class, parts[0]);
                if (exd == null)
                    check(false, sd, ed.getPath() + ": target profile '" + pt + "' is not valid (definition not found)");
                else {
                    ElementDefinition ex = null;
                    for (ElementDefinition et : exd.getSnapshot().getElement()) if (et.hasFixed() && et.getFixed() instanceof UriType && ((UriType) et.getFixed()).asStringValue().equals(parts[1]))
                        ex = et;
                    check(ex != null, sd, ed.getPath() + ": target profile '" + pt + "' is not valid (inner path not found)");
                }
            } else
                check((page.getWorkerContext().hasResource(StructureDefinition.class, pt)) || isStringPattern(tail(pt)), sd, ed.getPath() + ": target profile '" + pt + "' is not valid (d)");
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) HashSet(java.util.HashSet) UriType(org.hl7.fhir.r5.model.UriType)

Example 2 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project kindling by HL7.

the class PageProcessor method parseConceptMapMapping.

private ConceptMap parseConceptMapMapping(ElementDefn logical, ElementDefinition resource, String src) throws FHIRException {
    if (!src.startsWith("{map:"))
        return null;
    ConceptMap map = new ConceptMap();
    map.setId(logical.getPath() + "2" + resource.getPath());
    map.setUrl("http://hl7.org/fhir/ConceptMap/" + map.getId());
    map.setVersion(version.toCode());
    ConceptMapGroupComponent grp = map.addGroup();
    String[] statements = src.substring(0, src.length() - 1).substring(5).split("\\;");
    if (statements.length == 0)
        throw new FHIRException("Unable to parse map details '" + src + "'");
    for (String s : statements) {
        String[] p = s.split("\\=");
        if (p.length < 2)
            throw new FHIRException("Unable to parse map details '" + src + "'");
        if (":default".equals(p[0].trim())) {
            grp.getUnmapped().setMode(ConceptMapGroupUnmappedMode.FIXED);
            grp.getUnmapped().setCode(p[1].trim());
        } else {
            grp.addElement().setCode(p[0].trim()).addTarget().setRelationship(ConceptMapRelationship.EQUIVALENT).setCode(p[1].trim());
        }
    }
    return map;
}
Also used : ConceptMap(org.hl7.fhir.r5.model.ConceptMap) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)

Example 3 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project kindling by HL7.

the class Publisher method processProfile.

private void processProfile(Profile ap, ConstraintStructure profile, String filename, ResourceDefn baseResource) throws Exception {
    // create StructureDefinition structures if needed (create differential definitions from spreadsheets)
    if (profile.getResource() == null) {
        StructureDefinition p = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(ap, profile, profile.getDefn(), profile.getId(), profile.getUsage(), page.getValidationErrors(), baseResource);
        p.setUserData("pack", ap);
        profile.setResource(p);
        if (profile.getResourceInfo() != null) {
            profile.getResourceInfo().setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, p);
        }
        if (page.getProfiles().has(p.getUrl()))
            throw new Exception("Duplicate Profile URL " + p.getUrl());
        page.getProfiles().see(p, page.packageInfo());
    } else {
        profile.getResource().setUserData("pack", ap);
        sortProfile(profile.getResource());
        for (ElementDefinition ed : profile.getResource().getDifferential().getElement()) if (!ed.hasId())
            throw new Exception("Missing ID");
        // special case: if the profile itself doesn't claim a date, it's date is the date of this publication
        if (!profile.getResource().hasDate())
            profile.getResource().setDate(page.getGenDate().getTime());
        if (profile.getResource().hasBaseDefinition() && !profile.getResource().hasSnapshot()) {
            // cause it probably doesn't, coming from the profile directly
            StructureDefinition base = getSnapShotForProfile(profile.getResource().getBaseDefinition());
            new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).generateSnapshot(base, profile.getResource(), profile.getResource().getBaseDefinition().split("#")[0], "http://hl7.org/fhir", profile.getResource().getName());
        }
        if (page.getProfiles().has(profile.getResource().getUrl()))
            throw new Exception("Duplicate Profile URL " + profile.getResource().getUrl());
        System.out.println("register " + profile.getResource().getUrl());
        page.getProfiles().see(profile.getResource(), page.packageInfo());
    }
    if (!Utilities.noString(filename))
        profile.getResource().setUserData("filename", filename + ".html");
    if (Utilities.noString(profile.getResource().getUserString("path"))) {
        String path = "";
        ImplementationGuideDefn ig = page.getDefinitions().getUsageIG(ap.getCategory(), "processProfile");
        if (ig != null && !ig.isCore())
            path = ig.getCode() + File.separator;
        profile.getResource().setUserData("path", path + filename + ".html");
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project kindling by HL7.

the class Publisher method minifyProfile.

private void minifyProfile(StructureDefinition p) {
    p.getContact().clear();
    p.setDescriptionElement(null);
    p.getKeyword().clear();
    p.setPurposeElement(null);
    p.getMapping().clear();
    p.setDifferential(null);
    for (ElementDefinition ed : p.getSnapshot().getElement()) {
        ed.setShortElement(null);
        ed.setDefinitionElement(null);
        ed.setCommentElement(null);
        ed.setRequirementsElement(null);
        ed.getAlias().clear();
        ed.setMeaningWhenMissingElement(null);
        ed.getMapping().clear();
    }
}
Also used : ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 5 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project kindling by HL7.

the class PageProcessor method displayExtensionCardinality.

private String displayExtensionCardinality(StructureDefinition ed) {
    ElementDefinition e = ed.getSnapshot().getElementFirstRep();
    String m = "";
    if (ed.getSnapshot().getElementFirstRep().getIsModifier())
        m = " <b title=\"This is a modifier extension\">M</b>";
    return Integer.toString(e.getMin()) + ".." + e.getMax() + m;
}
Also used : ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Aggregations

ArrayList (java.util.ArrayList)226 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)199 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)120 FHIRException (org.hl7.fhir.exceptions.FHIRException)116 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)92 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)91 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)85 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)82 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)68 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)60 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)57 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)51 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)50 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)46 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)44 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)42 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 List (java.util.List)37