Search in sources :

Example 26 with Invariant

use of org.hl7.fhir.definitions.model.Invariant in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method describeExtensionContext.

public static String describeExtensionContext(StructureDefinition ext) {
    StringBuilder b = new StringBuilder();
    b.append("Use on ");
    for (int i = 0; i < ext.getContext().size(); i++) {
        StructureDefinitionContextComponent ec = ext.getContext().get(i);
        if (i > 0)
            b.append(i < ext.getContext().size() - 1 ? ", " : " or ");
        b.append(ec.getType().getDisplay());
        b.append(" ");
        b.append(ec.getExpression());
    }
    if (ext.hasContextInvariant()) {
        b.append(", with <a href=\"structuredefinition-definitions.html#StructureDefinition.contextInvariant\">Context Invariant</a> = ");
        boolean first = true;
        for (StringType s : ext.getContextInvariant()) {
            if (first)
                first = false;
            else
                b.append(", ");
            b.append("<code>" + s.getValue() + "</code>");
        }
    }
    return b.toString();
}
Also used : StructureDefinitionContextComponent(org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) StringType(org.hl7.fhir.r4b.model.StringType)

Example 27 with Invariant

use of org.hl7.fhir.definitions.model.Invariant in project org.hl7.fhir.core by hapifhir.

the class ProfileValidator method validate.

public List<ValidationMessage> validate(StructureDefinition profile, boolean forBuild) {
    List<ValidationMessage> errors = new ArrayList<ValidationMessage>();
    // must have a FHIR version- GF#3160
    warning(errors, IssueType.BUSINESSRULE, profile.getUrl(), profile.hasFhirVersion(), "Profiles SHOULD state the FHIR Version on which they are based");
    warning(errors, IssueType.BUSINESSRULE, profile.getUrl(), profile.hasVersion(), "Profiles SHOULD state their own version");
    // extensions must be defined
    for (ElementDefinition ec : profile.getDifferential().getElement()) checkExtensions(profile, errors, "differential", ec);
    rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "missing Snapshot at " + profile.getName() + "." + profile.getName());
    for (ElementDefinition ec : profile.getSnapshot().getElement()) checkExtensions(profile, errors, "snapshot", ec);
    if (rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "A snapshot is required")) {
        Hashtable<String, ElementDefinition> snapshotElements = new Hashtable<String, ElementDefinition>();
        for (ElementDefinition ed : profile.getSnapshot().getElement()) {
            snapshotElements.put(ed.getId(), ed);
            checkExtensions(profile, errors, "snapshot", ed);
            for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) {
                if (forBuild) {
                    if (!inExemptList(inv.getKey())) {
                        if (rule(errors, IssueType.BUSINESSRULE, profile.getId() + "::" + ed.getPath() + "::" + inv.getKey(), inv.hasExpression(), "The invariant has no FHIR Path expression (" + inv.getXpath() + ")")) {
                            try {
                                // , inv.hasXpath() && inv.getXpath().startsWith("@value")
                                new FHIRPathEngine(context).check(null, profile.getType(), ed.getPath(), inv.getExpression());
                            } catch (Exception e) {
                            // rule(errors, IssueType.STRUCTURE, profile.getId()+"::"+ed.getPath()+"::"+inv.getId(), exprExt != null, e.getMessage());
                            }
                        }
                    }
                }
            }
        }
        if (snapshotElements != null) {
            for (ElementDefinition diffElement : profile.getDifferential().getElement()) {
                if (diffElement == null)
                    throw new Error("Diff Element is null - this is not an expected thing");
                ElementDefinition snapElement = snapshotElements.get(diffElement.getId());
                if (snapElement != null) {
                    // Happens with profiles in the main build - should be able to fix once snapshot generation is fixed - Lloyd
                    warning(errors, IssueType.BUSINESSRULE, diffElement.getId(), !checkMustSupport || snapElement.hasMustSupport(), "Elements included in the differential should declare mustSupport");
                    if (checkAggregation) {
                        for (TypeRefComponent type : snapElement.getType()) {
                            if ("http://hl7.org/fhir/Reference".equals(type.getWorkingCode()) || "http://hl7.org/fhir/canonical".equals(type.getWorkingCode())) {
                                warning(errors, IssueType.BUSINESSRULE, diffElement.getId(), type.hasAggregation(), "Elements with type Reference or canonical should declare aggregation");
                            }
                        }
                    }
                }
            }
        }
    }
    return errors;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 28 with Invariant

use of org.hl7.fhir.definitions.model.Invariant in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method describeExtensionContext.

public static String describeExtensionContext(StructureDefinition ext) {
    StringBuilder b = new StringBuilder();
    b.append("Use on ");
    for (int i = 0; i < ext.getContext().size(); i++) {
        StructureDefinitionContextComponent ec = ext.getContext().get(i);
        if (i > 0)
            b.append(i < ext.getContext().size() - 1 ? ", " : " or ");
        b.append(ec.getType().getDisplay());
        b.append(" ");
        b.append(ec.getExpression());
    }
    if (ext.hasContextInvariant()) {
        b.append(", with <a href=\"structuredefinition-definitions.html#StructureDefinition.contextInvariant\">Context Invariant</a> = ");
        boolean first = true;
        for (StringType s : ext.getContextInvariant()) {
            if (first)
                first = false;
            else
                b.append(", ");
            b.append("<code>" + s.getValue() + "</code>");
        }
    }
    return b.toString();
}
Also used : StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) StringType(org.hl7.fhir.r5.model.StringType)

Aggregations

Invariant (org.hl7.fhir.definitions.model.Invariant)21 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)11 FHIRException (org.hl7.fhir.exceptions.FHIRException)10 ArrayList (java.util.ArrayList)8 TypeRef (org.hl7.fhir.definitions.model.TypeRef)6 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)6 ElementDefinitionConstraintComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)5 Sheet (org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)5 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)4 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)4 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)3 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)3 StringType (org.hl7.fhir.r5.model.StringType)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 IParser (ca.uhn.fhir.parser.IParser)2 SingleValidationMessage (ca.uhn.fhir.validation.SingleValidationMessage)2 ValidationResult (ca.uhn.fhir.validation.ValidationResult)2 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)2 TypeDefn (org.hl7.fhir.definitions.model.TypeDefn)2 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)2