Search in sources :

Example 76 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeDeviceComponent.

protected void composeDeviceComponent(Complex parent, String parentType, String name, DeviceComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "DeviceComponent", name, element, index);
    if (element.hasIdentifier())
        composeIdentifier(t, "DeviceComponent", "identifier", element.getIdentifier(), -1);
    if (element.hasType())
        composeCodeableConcept(t, "DeviceComponent", "type", element.getType(), -1);
    if (element.hasLastSystemChangeElement())
        composeInstant(t, "DeviceComponent", "lastSystemChange", element.getLastSystemChangeElement(), -1);
    if (element.hasSource())
        composeReference(t, "DeviceComponent", "source", element.getSource(), -1);
    if (element.hasParent())
        composeReference(t, "DeviceComponent", "parent", element.getParent(), -1);
    for (int i = 0; i < element.getOperationalStatus().size(); i++) composeCodeableConcept(t, "DeviceComponent", "operationalStatus", element.getOperationalStatus().get(i), i);
    if (element.hasParameterGroup())
        composeCodeableConcept(t, "DeviceComponent", "parameterGroup", element.getParameterGroup(), -1);
    if (element.hasMeasurementPrincipleElement())
        composeEnum(t, "DeviceComponent", "measurementPrinciple", element.getMeasurementPrincipleElement(), -1);
    for (int i = 0; i < element.getProductionSpecification().size(); i++) composeDeviceComponentDeviceComponentProductionSpecificationComponent(t, "DeviceComponent", "productionSpecification", element.getProductionSpecification().get(i), i);
    if (element.hasLanguageCode())
        composeCodeableConcept(t, "DeviceComponent", "languageCode", element.getLanguageCode(), -1);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 77 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.

the class DocumentManifest method setProperty.

@Override
public void setProperty(String name, Base value) throws FHIRException {
    if (name.equals("masterIdentifier"))
        // Identifier
        this.masterIdentifier = castToIdentifier(value);
    else if (name.equals("identifier"))
        this.getIdentifier().add(castToIdentifier(value));
    else if (name.equals("subject"))
        // Reference
        this.subject = castToReference(value);
    else if (name.equals("recipient"))
        this.getRecipient().add(castToReference(value));
    else if (name.equals("type"))
        // CodeableConcept
        this.type = castToCodeableConcept(value);
    else if (name.equals("author"))
        this.getAuthor().add(castToReference(value));
    else if (name.equals("created"))
        // DateTimeType
        this.created = castToDateTime(value);
    else if (name.equals("source"))
        // UriType
        this.source = castToUri(value);
    else if (name.equals("status"))
        // Enumeration<DocumentReferenceStatus>
        this.status = new DocumentReferenceStatusEnumFactory().fromType(value);
    else if (name.equals("description"))
        // StringType
        this.description = castToString(value);
    else if (name.equals("content"))
        this.getContent().add((DocumentManifestContentComponent) value);
    else if (name.equals("related"))
        this.getRelated().add((DocumentManifestRelatedComponent) value);
    else
        super.setProperty(name, value);
}
Also used : DocumentReferenceStatusEnumFactory(org.hl7.fhir.dstu2.model.Enumerations.DocumentReferenceStatusEnumFactory)

Example 78 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method getProfile.

// private static String listStructures(StructureDefinition p) {
// StringBuilder b = new StringBuilder();
// boolean first = true;
// for (ProfileStructureComponent s : p.getStructure()) {
// if (first)
// first = false;
// else
// b.append(", ");
// if (pkp != null && pkp.hasLinkFor(s.getType()))
// b.append("<a href=\""+pkp.getLinkFor(s.getType())+"\">"+s.getType()+"</a>");
// else
// b.append(s.getType());
// }
// return b.toString();
// }
public StructureDefinition getProfile(StructureDefinition source, String url) {
    StructureDefinition profile;
    String code;
    if (url.startsWith("#")) {
        profile = source;
        code = url.substring(1);
    } else {
        String[] parts = url.split("\\#");
        profile = context.fetchResource(StructureDefinition.class, parts[0]);
        code = parts.length == 1 ? null : parts[1];
    }
    if (profile == null)
        return null;
    if (code == null)
        return profile;
    for (Resource r : profile.getContained()) {
        if (r instanceof StructureDefinition && r.getId().equals(code))
            return (StructureDefinition) r;
    }
    return null;
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) Resource(org.hl7.fhir.dstu2.model.Resource)

Example 79 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method updateFromDefinition.

private void updateFromDefinition(ElementDefinition dest, ElementDefinition source, String pn, boolean trimDifferential, String purl) throws DefinitionException, FHIRException {
    // we start with a clone of the base profile ('dest') and we copy from the profile ('source')
    // over the top for anything the source has
    ElementDefinition base = dest;
    ElementDefinition derived = source;
    derived.setUserData(DERIVATION_POINTER, base);
    if (derived != null) {
        boolean isExtension = checkExtensionDoco(base);
        if (derived.hasShortElement()) {
            if (!Base.compareDeep(derived.getShortElement(), base.getShortElement(), false))
                base.setShortElement(derived.getShortElement().copy());
            else if (trimDifferential)
                derived.setShortElement(null);
            else if (derived.hasShortElement())
                derived.getShortElement().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasDefinitionElement()) {
            if (derived.getDefinition().startsWith("..."))
                base.setDefinition(base.getDefinition() + "\r\n" + derived.getDefinition().substring(3));
            else if (!Base.compareDeep(derived.getDefinitionElement(), base.getDefinitionElement(), false))
                base.setDefinitionElement(derived.getDefinitionElement().copy());
            else if (trimDifferential)
                derived.setDefinitionElement(null);
            else if (derived.hasDefinitionElement())
                derived.getDefinitionElement().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasCommentsElement()) {
            if (derived.getComments().startsWith("..."))
                base.setComments(base.getComments() + "\r\n" + derived.getComments().substring(3));
            else if (!Base.compareDeep(derived.getCommentsElement(), base.getCommentsElement(), false))
                base.setCommentsElement(derived.getCommentsElement().copy());
            else if (trimDifferential)
                base.setCommentsElement(derived.getCommentsElement().copy());
            else if (derived.hasCommentsElement())
                derived.getCommentsElement().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasLabelElement()) {
            if (derived.getLabel().startsWith("..."))
                base.setLabel(base.getLabel() + "\r\n" + derived.getLabel().substring(3));
            else if (!Base.compareDeep(derived.getLabelElement(), base.getLabelElement(), false))
                base.setLabelElement(derived.getLabelElement().copy());
            else if (trimDifferential)
                base.setLabelElement(derived.getLabelElement().copy());
            else if (derived.hasLabelElement())
                derived.getLabelElement().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasRequirementsElement()) {
            if (derived.getRequirements().startsWith("..."))
                base.setRequirements(base.getRequirements() + "\r\n" + derived.getRequirements().substring(3));
            else if (!Base.compareDeep(derived.getRequirementsElement(), base.getRequirementsElement(), false))
                base.setRequirementsElement(derived.getRequirementsElement().copy());
            else if (trimDifferential)
                base.setRequirementsElement(derived.getRequirementsElement().copy());
            else if (derived.hasRequirementsElement())
                derived.getRequirementsElement().setUserData(DERIVATION_EQUALS, true);
        }
        // sdf-9
        if (derived.hasRequirements() && !base.getPath().contains("."))
            derived.setRequirements(null);
        if (base.hasRequirements() && !base.getPath().contains("."))
            base.setRequirements(null);
        if (derived.hasAlias()) {
            if (!Base.compareDeep(derived.getAlias(), base.getAlias(), false))
                for (StringType s : derived.getAlias()) {
                    if (!base.hasAlias(s.getValue()))
                        base.getAlias().add(s.copy());
                }
            else if (trimDifferential)
                derived.getAlias().clear();
            else
                for (StringType t : derived.getAlias()) t.setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasMinElement()) {
            if (!Base.compareDeep(derived.getMinElement(), base.getMinElement(), false)) {
                if (derived.getMin() < base.getMin())
                    messages.add(new ValidationMessage(Source.ProfileValidator, IssueType.BUSINESSRULE, pn + "." + derived.getPath(), "Derived min  (" + Integer.toString(derived.getMin()) + ") cannot be less than base min (" + Integer.toString(base.getMin()) + ")", IssueSeverity.ERROR));
                base.setMinElement(derived.getMinElement().copy());
            } else if (trimDifferential)
                derived.setMinElement(null);
            else
                derived.getMinElement().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasMaxElement()) {
            if (!Base.compareDeep(derived.getMaxElement(), base.getMaxElement(), false)) {
                if (isLargerMax(derived.getMax(), base.getMax()))
                    messages.add(new ValidationMessage(Source.ProfileValidator, IssueType.BUSINESSRULE, pn + "." + derived.getPath(), "Derived max (" + derived.getMax() + ") cannot be greater than base max (" + base.getMax() + ")", IssueSeverity.ERROR));
                base.setMaxElement(derived.getMaxElement().copy());
            } else if (trimDifferential)
                derived.setMaxElement(null);
            else
                derived.getMaxElement().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasFixed()) {
            if (!Base.compareDeep(derived.getFixed(), base.getFixed(), true)) {
                base.setFixed(derived.getFixed().copy());
            } else if (trimDifferential)
                derived.setFixed(null);
            else
                derived.getFixed().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasPattern()) {
            if (!Base.compareDeep(derived.getPattern(), base.getPattern(), false)) {
                base.setPattern(derived.getPattern().copy());
            } else if (trimDifferential)
                derived.setPattern(null);
            else
                derived.getPattern().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasExample()) {
            if (!Base.compareDeep(derived.getExample(), base.getExample(), false))
                base.setExample(derived.getExample().copy());
            else if (trimDifferential)
                derived.setExample(null);
            else
                derived.getExample().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasMaxLengthElement()) {
            if (!Base.compareDeep(derived.getMaxLengthElement(), base.getMaxLengthElement(), false))
                base.setMaxLengthElement(derived.getMaxLengthElement().copy());
            else if (trimDifferential)
                derived.setMaxLengthElement(null);
            else
                derived.getMaxLengthElement().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasMaxValue()) {
            if (!Base.compareDeep(derived.getMaxValue(), base.getMaxValue(), false))
                base.setMaxValue(derived.getMaxValue().copy());
            else if (trimDifferential)
                derived.setMaxValue(null);
            else
                derived.getMaxValue().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasMinValue()) {
            if (!Base.compareDeep(derived.getMinValue(), base.getMinValue(), false))
                base.setMinValue(derived.getMinValue().copy());
            else if (trimDifferential)
                derived.setMinValue(null);
            else
                derived.getMinValue().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasMustSupportElement()) {
            if (!Base.compareDeep(derived.getMustSupportElement(), base.getMustSupportElement(), false))
                base.setMustSupportElement(derived.getMustSupportElement().copy());
            else if (trimDifferential)
                derived.setMustSupportElement(null);
            else
                derived.getMustSupportElement().setUserData(DERIVATION_EQUALS, true);
        }
        // but extensions can change isModifier
        if (isExtension) {
            if (!Base.compareDeep(derived.getIsModifierElement(), base.getIsModifierElement(), false))
                base.setIsModifierElement(derived.getIsModifierElement().copy());
            else if (trimDifferential)
                derived.setIsModifierElement(null);
            else
                derived.getIsModifierElement().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasBinding()) {
            if (!Base.compareDeep(derived.getBinding(), base.getBinding(), false)) {
                if (base.hasBinding() && base.getBinding().getStrength() == BindingStrength.REQUIRED && derived.getBinding().getStrength() != BindingStrength.REQUIRED)
                    messages.add(new ValidationMessage(Source.ProfileValidator, IssueType.BUSINESSRULE, pn + "." + derived.getPath(), "illegal attempt to change a binding from " + base.getBinding().getStrength().toCode() + " to " + derived.getBinding().getStrength().toCode(), IssueSeverity.ERROR));
                else // throw new DefinitionException("StructureDefinition "+pn+" at "+derived.getPath()+": illegal attempt to change a binding from "+base.getBinding().getStrength().toCode()+" to "+derived.getBinding().getStrength().toCode());
                if (base.hasBinding() && derived.hasBinding() && base.getBinding().getStrength() == BindingStrength.REQUIRED) {
                    ValueSetExpansionOutcome expBase = context.expandVS(context.fetchResource(ValueSet.class, base.getBinding().getValueSetReference().getReference()), true);
                    ValueSetExpansionOutcome expDerived = context.expandVS(context.fetchResource(ValueSet.class, derived.getBinding().getValueSetReference().getReference()), true);
                    if (expBase.getValueset() == null)
                        messages.add(new ValidationMessage(Source.ProfileValidator, IssueType.BUSINESSRULE, pn + "." + base.getPath(), "Binding " + base.getBinding().getValueSetReference().getReference() + " could not be expanded", IssueSeverity.WARNING));
                    else if (expDerived.getValueset() == null)
                        messages.add(new ValidationMessage(Source.ProfileValidator, IssueType.BUSINESSRULE, pn + "." + derived.getPath(), "Binding " + derived.getBinding().getValueSetReference().getReference() + " could not be expanded", IssueSeverity.WARNING));
                    else if (!isSubset(expBase.getValueset(), expDerived.getValueset()))
                        messages.add(new ValidationMessage(Source.ProfileValidator, IssueType.BUSINESSRULE, pn + "." + derived.getPath(), "Binding " + derived.getBinding().getValueSetReference().getReference() + " is not a subset of binding " + base.getBinding().getValueSetReference().getReference(), IssueSeverity.ERROR));
                }
                base.setBinding(derived.getBinding().copy());
            } else if (trimDifferential)
                derived.setBinding(null);
            else
                derived.getBinding().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasIsSummaryElement()) {
            if (!Base.compareDeep(derived.getIsSummaryElement(), base.getIsSummaryElement(), false))
                base.setIsSummaryElement(derived.getIsSummaryElement().copy());
            else if (trimDifferential)
                derived.setIsSummaryElement(null);
            else
                derived.getIsSummaryElement().setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasType()) {
            if (!Base.compareDeep(derived.getType(), base.getType(), false)) {
                if (base.hasType()) {
                    for (TypeRefComponent ts : derived.getType()) {
                        boolean ok = false;
                        CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
                        for (TypeRefComponent td : base.getType()) {
                            b.append(td.getCode());
                            if (td.hasCode() && (td.getCode().equals(ts.getCode()) || td.getCode().equals("Extension") || td.getCode().equals("Element") || td.getCode().equals("*") || ((td.getCode().equals("Resource") || (td.getCode().equals("DomainResource")) && pkp.isResource(ts.getCode())))))
                                ok = true;
                        }
                        if (!ok)
                            throw new DefinitionException("StructureDefinition " + pn + " at " + derived.getPath() + ": illegal constrained type " + ts.getCode() + " from " + b.toString());
                    }
                }
                base.getType().clear();
                for (TypeRefComponent t : derived.getType()) {
                    TypeRefComponent tt = t.copy();
                    // tt.setUserData(DERIVATION_EQUALS, true);
                    base.getType().add(tt);
                }
            } else if (trimDifferential)
                derived.getType().clear();
            else
                for (TypeRefComponent t : derived.getType()) t.setUserData(DERIVATION_EQUALS, true);
        }
        if (derived.hasMapping()) {
            // todo: mappings are not cumulative - one replaces another
            if (!Base.compareDeep(derived.getMapping(), base.getMapping(), false)) {
                for (ElementDefinitionMappingComponent s : derived.getMapping()) {
                    boolean found = false;
                    for (ElementDefinitionMappingComponent d : base.getMapping()) {
                        found = found || (d.getIdentity().equals(s.getIdentity()) && d.getMap().equals(s.getMap()));
                    }
                    if (!found)
                        base.getMapping().add(s);
                }
            } else if (trimDifferential)
                derived.getMapping().clear();
            else
                for (ElementDefinitionMappingComponent t : derived.getMapping()) t.setUserData(DERIVATION_EQUALS, true);
        }
        // todo: constraints are cumulative. there is no replacing
        for (ElementDefinitionConstraintComponent s : base.getConstraint()) s.setUserData(IS_DERIVED, true);
        if (derived.hasConstraint()) {
            for (ElementDefinitionConstraintComponent s : derived.getConstraint()) {
                base.getConstraint().add(s.copy());
            }
        }
    }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) StringType(org.hl7.fhir.dstu2.model.StringType) TypeRefComponent(org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent) ValueSetExpansionOutcome(org.hl7.fhir.dstu2.terminologies.ValueSetExpander.ValueSetExpansionOutcome) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinitionMappingComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionMappingComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 80 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.

the class FHIRToolingClient method expandValueset.

public ValueSet expandValueset(ValueSet source, Parameters expParams, Map<String, String> params) {
    List<Header> headers = null;
    Parameters p = expParams == null ? new Parameters() : expParams.copy();
    p.addParameter().setName("valueSet").setResource(source);
    for (String n : params.keySet()) p.addParameter().setName(n).setValue(new StringType(params.get(n)));
    ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", params), utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, 4);
    // gone
    result.addErrorStatus(410);
    // unknown
    result.addErrorStatus(404);
    result.addErrorStatus(405);
    // Unprocessable Entity
    result.addErrorStatus(422);
    result.addSuccessStatus(200);
    result.addSuccessStatus(201);
    if (result.isUnsuccessfulRequest()) {
        throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
    }
    return (ValueSet) result.getPayload();
}
Also used : Parameters(org.hl7.fhir.dstu2.model.Parameters) Header(org.apache.http.Header) StringType(org.hl7.fhir.dstu2.model.StringType) Resource(org.hl7.fhir.dstu2.model.Resource) ValueSet(org.hl7.fhir.dstu2.model.ValueSet)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)125 FileInputStream (java.io.FileInputStream)59 FileOutputStream (java.io.FileOutputStream)55 IOException (java.io.IOException)55 ArrayList (java.util.ArrayList)48 File (java.io.File)45 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)45 TextFile (org.hl7.fhir.utilities.TextFile)41 CSFile (org.hl7.fhir.utilities.CSFile)35 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)35 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)30 XmlParser (org.hl7.fhir.r5.formats.XmlParser)28 Date (java.util.Date)27 HashMap (java.util.HashMap)26 Reference (org.hl7.fhir.r4.model.Reference)26 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)24 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)24 Coding (org.hl7.fhir.r4.model.Coding)24 JsonObject (com.google.gson.JsonObject)22 NotImplementedException (org.apache.commons.lang3.NotImplementedException)22