Search in sources :

Example 36 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.

the class ValueSetComparer method compareDefinitions.

private void compareDefinitions(ConceptSetComponent left, ConceptSetComponent right, StructuralMatch<Element> combined, ConceptSetComponent union, ConceptSetComponent intersection) {
    // system must match, but the rest might not. we're going to do the full comparison whatever, so the outcome looks consistent to the user
    List<CanonicalType> matchVSR = new ArrayList<>();
    for (CanonicalType l : left.getValueSet()) {
        CanonicalType r = findInList(right.getValueSet(), l, left.getValueSet());
        if (r == null) {
            union.getValueSet().add(l);
            combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed ValueSet", "ValueSet.compose.include.valueSet")));
        } else {
            matchVSR.add(r);
            if (l.getValue().equals(r.getValue())) {
                union.getValueSet().add(l);
                intersection.getValueSet().add(l);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, null);
                combined.getChildren().add(sm);
            } else {
                union.getValueSet().add(l);
                union.getValueSet().add(r);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Values are different", "ValueSet.compose.include.valueSet"));
                combined.getChildren().add(sm);
            }
        }
    }
    for (CanonicalType r : right.getValueSet()) {
        if (!matchVSR.contains(r)) {
            union.getValueSet().add(r);
            combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Add ValueSet", "ValueSet.compose.include.valueSet"), r));
        }
    }
    List<ConceptReferenceComponent> matchCR = new ArrayList<>();
    for (ConceptReferenceComponent l : left.getConcept()) {
        ConceptReferenceComponent r = findInList(right.getConcept(), l, left.getConcept());
        if (r == null) {
            union.getConcept().add(l);
            combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed this Concept", "ValueSet.compose.include.concept")));
        } else {
            matchCR.add(r);
            if (l.getCode().equals(r.getCode())) {
                ConceptReferenceComponent cu = new ConceptReferenceComponent();
                ConceptReferenceComponent ci = new ConceptReferenceComponent();
                union.getConcept().add(cu);
                intersection.getConcept().add(ci);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
                combined.getChildren().add(sm);
                compareConcepts(l, r, sm, cu, ci);
            } else {
                union.getConcept().add(l);
                union.getConcept().add(r);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Concepts are different", "ValueSet.compose.include.concept"));
                combined.getChildren().add(sm);
                compareConcepts(l, r, sm, null, null);
            }
        }
    }
    for (ConceptReferenceComponent r : right.getConcept()) {
        if (!matchCR.contains(r)) {
            union.getConcept().add(r);
            combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added this Concept", "ValueSet.compose.include.concept"), r));
        }
    }
    List<ConceptSetFilterComponent> matchFR = new ArrayList<>();
    for (ConceptSetFilterComponent l : left.getFilter()) {
        ConceptSetFilterComponent r = findInList(right.getFilter(), l, left.getFilter());
        if (r == null) {
            union.getFilter().add(l);
            combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed this item", "ValueSet.compose.include.filter")));
        } else {
            matchFR.add(r);
            if (l.getProperty().equals(r.getProperty()) && l.getOp().equals(r.getOp())) {
                ConceptSetFilterComponent cu = new ConceptSetFilterComponent();
                ConceptSetFilterComponent ci = new ConceptSetFilterComponent();
                union.getFilter().add(cu);
                intersection.getFilter().add(ci);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
                combined.getChildren().add(sm);
                compareFilters(l, r, sm, cu, ci);
            } else {
                union.getFilter().add(l);
                union.getFilter().add(r);
                StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Codes are different", "ValueSet.compose.include.filter"));
                combined.getChildren().add(sm);
                compareFilters(l, r, sm, null, null);
            }
        }
    }
    for (ConceptSetFilterComponent r : right.getFilter()) {
        if (!matchFR.contains(r)) {
            union.getFilter().add(r);
            combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added this item", "ValueSet.compose.include.filter"), r));
        }
    }
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) Element(org.hl7.fhir.r5.model.Element) ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 37 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.

the class CanonicalResourceComparer method compareCanonicalList.

protected void compareCanonicalList(String name, List<CanonicalType> left, List<CanonicalType> right, Map<String, StructuralMatch<String>> comp, IssueSeverity level, CanonicalResourceComparison<? extends CanonicalResource> res, List<CanonicalType> union, List<CanonicalType> intersection) {
    List<CanonicalType> matchR = new ArrayList<>();
    StructuralMatch<String> combined = new StructuralMatch<String>();
    for (CanonicalType l : left) {
        CanonicalType r = findCanonicalInList(right, l);
        if (r == null) {
            union.add(l);
            combined.getChildren().add(new StructuralMatch<String>(l.getValue(), vm(IssueSeverity.INFORMATION, "Removed the item '" + l.getValue() + "'", fhirType() + "." + name, res.getMessages())));
        } else {
            matchR.add(r);
            union.add(r);
            intersection.add(r);
            StructuralMatch<String> sm = new StructuralMatch<String>(l.getValue(), r.getValue());
            combined.getChildren().add(sm);
        }
    }
    for (CanonicalType r : right) {
        if (!matchR.contains(r)) {
            union.add(r);
            combined.getChildren().add(new StructuralMatch<String>(vm(IssueSeverity.INFORMATION, "Added the item '" + r.getValue() + "'", fhirType() + "." + name, res.getMessages()), r.getValue()));
        }
    }
    comp.put(name, combined);
}
Also used : ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r5.model.CanonicalType)

Example 38 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.

the class CapabilityStatementComparer method compareProfiles.

private void compareProfiles(String path, StructuralMatch<Element> combined, CanonicalType left, CanonicalType right, CapabilityStatementComparison res, CapabilityStatementRestResourceComponent union, CapabilityStatementRestResourceComponent intersection) {
    if (!left.hasValue() && !right.hasValue()) {
    // nothing in this case
    } else if (!left.hasValue()) {
        // the intersection is anything in right. The union is everything (or nothing, in this case)
        intersection.setProfileElement(right.copy());
        combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.WARNING, "Added this profile", path), right).setName("profile"));
    } else if (!right.hasValue()) {
        // the intersection is anything in right. The union is everything (or nothing, in this case)
        intersection.setProfileElement(left.copy());
        combined.getChildren().add(new StructuralMatch<Element>(left, vmI(IssueSeverity.WARNING, "Removed this profile", path)).setName("profile"));
    } else {
        // profiles on both sides...
        StructureDefinition sdLeft = session.getContextLeft().fetchResource(StructureDefinition.class, left.getValue());
        StructureDefinition sdRight = session.getContextRight().fetchResource(StructureDefinition.class, right.getValue());
        if (sdLeft == null && sdRight == null) {
            combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.ERROR, "Cannot compare profiles because neither is known", path)).setName("profile"));
        } else if (sdLeft == null) {
            combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.ERROR, "Cannot compare profiles because '" + left.getValue() + "' is not known", path)).setName("profile"));
        } else if (sdRight == null) {
            combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.ERROR, "Cannot compare profiles because '" + right.getValue() + "' is not known", path)).setName("profile"));
        } else if (sdLeft.getUrl().equals(sdRight.getUrl())) {
            intersection.setProfileElement(left.copy());
            union.setProfileElement(left.copy());
            combined.getChildren().add(new StructuralMatch<Element>(left, right).setName("profile"));
        } else if (profileInherits(sdLeft, sdRight, session.getContextLeft())) {
            // if left inherits from right:
            intersection.setProfileElement(left.copy());
            union.setProfileElement(right.copy());
            combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.WARNING, "Changed this profile to a broader profile", path)).setName("profile"));
        } else if (profileInherits(sdRight, sdLeft, session.getContextRight())) {
            intersection.setProfileElement(right.copy());
            union.setProfileElement(left.copy());
            combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.WARNING, "Changed this profile to a narrower one", path)).setName("profile"));
        } else {
            combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.WARNING, "Different", path)).setName("profile"));
            throw new Error("Not done yet");
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) BackboneElement(org.hl7.fhir.r5.model.BackboneElement) Element(org.hl7.fhir.r5.model.Element)

Example 39 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method processCanonicalReference.

private void processCanonicalReference(Resource context, Base source, Field field, ObjectValue target, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
    if (!(source instanceof CanonicalType))
        throw new EGraphQLException("Not done yet");
    if (services == null)
        throw new EGraphQLException("Resource Referencing services not provided");
    Reference ref = new Reference(source.primitiveValue());
    ReferenceResolution res = services.lookup(appInfo, context, ref);
    if (res != null) {
        if (targetTypeOk(field.getArguments(), res.getTarget())) {
            Argument arg = target.addField(field.getAlias() + suffix, listStatus(field, inheritedList));
            ObjectValue obj = new ObjectValue();
            arg.addValue(obj);
            processObject((Resource) res.getTargetContext(), (Base) res.getTarget(), obj, field.getSelectionSet(), inheritedList, suffix);
        }
    } else if (!hasArgument(field.getArguments(), "optional", "true"))
        throw new EGraphQLException("Unable to resolve reference to " + ref.getReference());
}
Also used : ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) Argument(org.hl7.fhir.utilities.graphql.Argument) ReferenceResolution(org.hl7.fhir.utilities.graphql.IGraphQLStorageServices.ReferenceResolution) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 40 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method addReferenceQuestions.

// Special Types ---------------------------------------------------------------
private void addReferenceQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, List<CanonicalType> profileURL, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
    // var
    // rn : String;
    // i : integer;
    // q : TFhirQuestionnaireGroupQuestion;
    ToolingExtensions.addFhirType(group, "Reference");
    QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.REFERENCE, null, path, "value", group.getText(), answerGroups);
    group.setText(null);
    CommaSeparatedStringBuilder rn = new CommaSeparatedStringBuilder();
    for (UriType u : profileURL) if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/"))
        rn.append(u.getValue().substring(40));
    if (rn.length() == 0)
        ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
    else {
        ToolingExtensions.addAllowedResource(q, rn.toString());
        ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
    }
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) ag.setText(null);
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) QuestionnaireResponse(org.hl7.fhir.r5.model.QuestionnaireResponse) UriType(org.hl7.fhir.r5.model.UriType)

Aggregations

CanonicalType (org.hl7.fhir.r4.model.CanonicalType)45 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)37 ArrayList (java.util.ArrayList)27 CanonicalType (org.hl7.fhir.r4b.model.CanonicalType)19 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)12 Test (org.junit.jupiter.api.Test)12 List (java.util.List)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Extension (org.hl7.fhir.r4.model.Extension)7 Library (org.hl7.fhir.r4.model.Library)7 StringType (org.hl7.fhir.r4.model.StringType)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 Bundle (org.hl7.fhir.r4.model.Bundle)5 IdType (org.hl7.fhir.r4.model.IdType)5