Search in sources :

Example 56 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileComparer method unionConstraints.

// we can't really know about constraints. We create warnings, and collate them
private List<ElementDefinitionConstraintComponent> unionConstraints(ProfileComparison comp, StructuralMatch<ElementDefinitionNode> res, String path, List<ElementDefinitionConstraintComponent> left, List<ElementDefinitionConstraintComponent> right) {
    List<ElementDefinitionConstraintComponent> result = new ArrayList<ElementDefinitionConstraintComponent>();
    for (ElementDefinitionConstraintComponent l : left) {
        boolean found = false;
        for (ElementDefinitionConstraintComponent r : right) if (Utilities.equals(r.getId(), l.getId()) || (Utilities.equals(r.getXpath(), l.getXpath()) && r.getSeverity() == l.getSeverity()))
            found = true;
        if (!found) {
            if (!Utilities.existsInList(l.getExpression(), "hasValue() or (children().count() > id.count())", "extension.exists() != value.exists()")) {
                vm(IssueSeverity.INFORMATION, "StructureDefinition " + comp.getLeft().getName() + " has a constraint that is removed in " + comp.getRight().getName() + " and it is uncertain whether they are compatible (" + l.getExpression() + ")", path, comp.getMessages(), res.getMessages());
            }
        }
        result.add(l);
    }
    for (ElementDefinitionConstraintComponent r : right) {
        boolean found = false;
        for (ElementDefinitionConstraintComponent l : left) if (Utilities.equals(r.getId(), l.getId()) || (Utilities.equals(r.getXpath(), l.getXpath()) && r.getSeverity() == l.getSeverity()))
            found = true;
        if (!found) {
            if (!Utilities.existsInList(r.getExpression(), "hasValue() or (children().count() > id.count())", "extension.exists() != value.exists()")) {
                vm(IssueSeverity.INFORMATION, "StructureDefinition " + comp.getRight().getName() + " has added constraint that is not found in " + comp.getLeft().getName() + " and it is uncertain whether they are compatible (" + r.getExpression() + ")", path, comp.getMessages(), res.getMessages());
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 57 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testSimple2.

// 
// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base. for a different resource with recursion
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
@Test
public void testSimple2() {
    StructureDefinition base = TestingUtilities.getSharedWorkerContext().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet").copy();
    StructureDefinition focus = base.copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setSnapshot(null);
    focus.setDifferential(null);
    List<ValidationMessage> messages = new ArrayList<>();
    new ProfileUtilities(TestingUtilities.getSharedWorkerContext(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test");
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        if (ok) {
            ElementDefinition b = base.getSnapshot().getElement().get(i);
            ElementDefinition f = focus.getSnapshot().getElement().get(i);
            for (ElementDefinitionConstraintComponent c : b.getConstraint()) {
                c.setSource(null);
            }
            for (ElementDefinitionConstraintComponent c : f.getConstraint()) {
                c.setSource(null);
            }
            if (!f.hasBase() || !b.getPath().equals(f.getPath()))
                ok = false;
            else {
                f.setBase(null);
                b.setBase(null);
                b.setRequirements(null);
                f.setRequirements(null);
                b.setComment(null);
                f.setComment(null);
                b.setDefinition(null);
                f.setDefinition(null);
                b.setContentReference(null);
                f.setContentReference(null);
                ok = Base.compareDeep(b, f, true);
            }
        }
    }
    Assertions.assertTrue(ok);
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 58 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testSimple.

// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
@Test
public void testSimple() throws FHIRException {
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = TestingUtilities.getSharedWorkerContext().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBaseDefinition(base.getUrl());
    focus.setType("Patient");
    focus.setDerivation(TypeDerivationRule.CONSTRAINT);
    List<ValidationMessage> messages = new ArrayList<>();
    new ProfileUtilities(TestingUtilities.getSharedWorkerContext(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org/test", "Simple Test");
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        ElementDefinition b = base.getSnapshot().getElement().get(i);
        ElementDefinition f = focus.getSnapshot().getElement().get(i);
        if (ok) {
            if (!f.hasBase())
                ok = false;
            else if (!b.getPath().equals(f.getPath()))
                ok = false;
            else {
                b.setBase(null);
                f.setBase(null);
                b.setRequirements(null);
                f.setRequirements(null);
                for (ElementDefinitionConstraintComponent c : b.getConstraint()) {
                    c.setSource(null);
                }
                for (ElementDefinitionConstraintComponent c : f.getConstraint()) {
                    c.setSource(null);
                }
                ok = Base.compareDeep(b, f, true);
            }
        }
    }
    Assertions.assertTrue(ok);
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 59 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testMinValueChange.

/**
 * Change min value
 */
@Test
void testMinValueChange() {
    // Given
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = TestingUtilities.getSharedWorkerContext().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Appointment").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBaseDefinition(base.getUrl());
    focus.setType(base.getType());
    focus.setDerivation(TypeDerivationRule.CONSTRAINT);
    ElementDefinition id = focus.getDifferential().addElement();
    id.setPath("Appointment.minutesDuration");
    id.setMinValue(new IntegerType(1));
    List<ValidationMessage> messages = new ArrayList<>();
    // When
    new ProfileUtilities(TestingUtilities.getSharedWorkerContext(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test");
    // Then
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        if (ok) {
            ElementDefinition b = base.getSnapshot().getElement().get(i);
            ElementDefinition f = focus.getSnapshot().getElement().get(i);
            b.setRequirements(null);
            f.setRequirements(null);
            for (ElementDefinitionConstraintComponent c : b.getConstraint()) {
                c.setSource(null);
            }
            for (ElementDefinitionConstraintComponent c : f.getConstraint()) {
                c.setSource(null);
            }
            if (!f.hasBase() || !b.getPath().equals(f.getPath())) {
                ok = false;
            } else {
                if (f.getPath().equals("Appointment.minutesDuration")) {
                    ok = f.getMinValue() instanceof IntegerType && ((IntegerType) f.getMinValue()).getValue() == 1;
                    if (ok) {
                        // Can't set minValue to null so change base minValue to IntegerType(1)
                        b.setMinValue(new IntegerType(1));
                    }
                }
                if (!Base.compareDeep(b, f, true)) {
                    ok = false;
                }
            }
        }
    }
    Assertions.assertTrue(ok);
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 60 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testMaxValueChange.

/**
 * Change max value
 */
@Test
void testMaxValueChange() {
    // Given
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = TestingUtilities.getSharedWorkerContext().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Appointment").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBaseDefinition(base.getUrl());
    focus.setType(base.getType());
    focus.setDerivation(TypeDerivationRule.CONSTRAINT);
    ElementDefinition id = focus.getDifferential().addElement();
    id.setPath("Appointment.minutesDuration");
    id.setMaxValue(new IntegerType(1));
    List<ValidationMessage> messages = new ArrayList<>();
    // When
    new ProfileUtilities(TestingUtilities.getSharedWorkerContext(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test");
    // Then
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        if (ok) {
            ElementDefinition b = base.getSnapshot().getElement().get(i);
            ElementDefinition f = focus.getSnapshot().getElement().get(i);
            b.setRequirements(null);
            f.setRequirements(null);
            for (ElementDefinitionConstraintComponent c : b.getConstraint()) {
                c.setSource(null);
            }
            for (ElementDefinitionConstraintComponent c : f.getConstraint()) {
                c.setSource(null);
            }
            if (!f.hasBase() || !b.getPath().equals(f.getPath())) {
                ok = false;
            } else {
                if (f.getPath().equals("Appointment.minutesDuration")) {
                    ok = f.getMaxValue() instanceof IntegerType && ((IntegerType) f.getMaxValue()).getValue() == 1;
                    if (ok) {
                        // Can't set maxValue to null so change base maxValue to IntegerType(1)
                        b.setMaxValue(new IntegerType(1));
                    }
                }
                if (!Base.compareDeep(b, f, true)) {
                    ok = false;
                }
            }
        }
    }
    Assertions.assertTrue(ok);
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Aggregations

ElementDefinitionConstraintComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)31 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)25 ArrayList (java.util.ArrayList)23 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)16 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)15 ElementDefinitionConstraintComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)10 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)9 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)9 Test (org.junit.jupiter.api.Test)8 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 ElementDefinitionConstraintComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent)7 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)7 Rule (org.hl7.fhir.utilities.xml.SchematronWriter.Rule)7 Section (org.hl7.fhir.utilities.xml.SchematronWriter.Section)7 IOException (java.io.IOException)6