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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations