Search in sources :

Example 76 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testCardinalityChange.

/**
 * Change one cardinality.
 */
@Test
void testCardinalityChange() {
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBaseDefinition(base.getUrl());
    focus.setType(base.getType());
    focus.setDerivation(TypeDerivationRule.CONSTRAINT);
    ElementDefinition id = focus.getDifferential().addElement();
    id.setPath("Patient.identifier");
    id.setMin(1);
    List<ValidationMessage> messages = new ArrayList<>();
    new ProfileUtilities(TestingUtilities.context(), 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);
            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("Patient.identifier")) {
                    ok = f.getMin() == 1;
                    if (ok) {
                        f.setMin(0);
                    }
                }
                if (!Base.compareDeep(b, f, true)) {
                    ok = Base.compareDeep(b, f, true);
                }
            }
        }
    }
    Assertions.assertTrue(ok);
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 77 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities 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.context().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.context(), 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.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 78 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities 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.context().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.context(), 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.r4b.model.IntegerType) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 79 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities 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.context().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.context(), 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.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 80 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.

the class SnapShotGenerationTests method testSort.

private void testSort(TestDetails test, SnapShotGenerationTestsContext context) throws DefinitionException, FHIRException, IOException {
    StructureDefinition base = getSD(test.getSource().getBaseDefinition(), context);
    test.setOutput(test.getSource().copy());
    ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, null);
    pu.setIds(test.getSource(), false);
    List<String> errors = new ArrayList<String>();
    pu.sortDifferential(base, test.getOutput(), test.getOutput().getUrl(), errors, false);
    if (!errors.isEmpty())
        throw new FHIRException(errors.get(0));
    IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(TestingUtilities.tempFile("snapshot", test.getId() + "-expected.xml")));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("snapshot", test.getId() + "-actual.xml")), test.getOutput());
    Assertions.assertTrue(test.expected.equalsDeep(test.output), "Output does not match expected");
}
Also used : XmlParser(org.hl7.fhir.r4b.formats.XmlParser) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

ArrayList (java.util.ArrayList)74 FHIRException (org.hl7.fhir.exceptions.FHIRException)59 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)52 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)48 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)38 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)21 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)20 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)16 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)16 FileOutputStream (java.io.FileOutputStream)15 ProfileUtilities (org.hl7.fhir.r4b.conformance.ProfileUtilities)14 IOException (java.io.IOException)13 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)13 ProfileUtilities (org.hl7.fhir.dstu2.utils.ProfileUtilities)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 ProfileUtilities (org.hl7.fhir.r4.conformance.ProfileUtilities)12 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)12 Test (org.junit.jupiter.api.Test)12 FileNotFoundException (java.io.FileNotFoundException)11