use of org.hl7.fhir.utilities.validation.ValidationMessage in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method testSlicingExtensionComplex.
/**
* we're going to slice Patient.extension and refer to extension by profile. one of the extensions is complex, and we're going to walk into
* it and make it must support
*
* implicit: whether to rely on implicit extension slicing
*/
private void testSlicingExtensionComplex(boolean implicit) throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBase(base.getUrl());
// set the slice up
ElementDefinition id;
if (!implicit) {
id = focus.getDifferential().addElement();
id.setPath("Patient.extension");
id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator("url");
}
// first slice - a simple one to get us going:
id = focus.getDifferential().addElement();
id.setPath("Patient.extension");
id.setName("simple");
id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/patient-birthTime");
// second slice - the complex one
// we walk into this and fix properties on the inner extensions
id = focus.getDifferential().addElement();
id.setPath("Patient.extension");
id.setName("complex");
id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality");
if (!implicit) {
id = focus.getDifferential().addElement();
id.setPath("Patient.extension.extension");
id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator("url");
}
id = focus.getDifferential().addElement();
id.setPath("Patient.extension.extension");
id.setName("code");
id.setMustSupport(true);
id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality#code");
id = focus.getDifferential().addElement();
id.setPath("Patient.extension.extension");
id.setName("period");
id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality#period");
// prohibit this one....
id.setMax("0");
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
// ok, there's going to 1 (simple) + complex: 1 + id + extnesion.slice + extension.code + (4 inside from that) + extension.period + (4 inside from that) + value + url = 16
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 16;
// custom checks
ok = ok && rule(focus.getSnapshot().getElement().get(7).getPath().equals("Patient.extension"), "element 7 (base) path");
ok = ok && rule(focus.getSnapshot().getElement().get(7).hasSlicing(), "element 7 slicing");
ok = ok && rule(focus.getSnapshot().getElement().get(8).getPath().equals("Patient.extension"), "element 8 (1st slice) path");
ok = ok && rule(focus.getSnapshot().getElement().get(8).getName().equals("simple"), "element 8 (1st slice) name");
ok = ok && rule(focus.getSnapshot().getElement().get(8).getType().get(0).getProfile().get(0).getValue().equals("http://hl7.org/fhir/StructureDefinition/patient-birthTime"), "element 9 (2nd slice) profile name");
ok = ok && rule(focus.getSnapshot().getElement().get(9).getPath().equals("Patient.extension"), "element 9 (2nd slice) path");
ok = ok && rule(focus.getSnapshot().getElement().get(9).getName().equals("complex"), "element 8 (1st slice) name");
ok = ok && rule(focus.getSnapshot().getElement().get(9).getType().get(0).getProfile().get(0).getValue().equals("http://hl7.org/fhir/StructureDefinition/patient-nationality"), "element 9 (2nd slice) profile name");
ok = ok && rule(focus.getSnapshot().getElement().get(10).getPath().equals("Patient.extension.id"), "element 10 (2nd slice).id path");
ok = ok && rule(focus.getSnapshot().getElement().get(11).getPath().equals("Patient.extension.extension"), "element 11 (2nd slice).extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(12).getPath().equals("Patient.extension.extension"), "element 12 (2nd slice).extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(12).getMustSupport(), "element 12 (2nd slice).extension must support");
ok = ok && rule(focus.getSnapshot().getElement().get(13).getPath().equals("Patient.extension.extension.id"), "element 13 (2nd slice).extension.id path");
ok = ok && rule(focus.getSnapshot().getElement().get(14).getPath().equals("Patient.extension.extension.extension"), "element 14 (2nd slice).extension.extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(15).getPath().equals("Patient.extension.extension.url"), "element 15 (2nd slice).extension.url path");
ok = ok && rule(focus.getSnapshot().getElement().get(16).getPath().equals("Patient.extension.extension.valueCodeableConcept"), "element 16 (2nd slice).extension.valueCodeableConcept path");
ok = ok && rule(focus.getSnapshot().getElement().get(17).getPath().equals("Patient.extension.extension"), "element 17 (2nd slice).extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(17).getMax().equals("0"), "element 17 (2nd slice).extension cardinality");
ok = ok && rule(focus.getSnapshot().getElement().get(18).getPath().equals("Patient.extension.extension.id"), "element 18 (2nd slice).extension.id path");
ok = ok && rule(focus.getSnapshot().getElement().get(19).getPath().equals("Patient.extension.extension.extension"), "element 19 (2nd slice).extension.extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(20).getPath().equals("Patient.extension.extension.url"), "element 20 (2nd slice).extension.url path");
ok = ok && rule(focus.getSnapshot().getElement().get(21).getPath().equals("Patient.extension.extension.valuePeriod"), "element 21 (2nd slice).extension.valuePeriod path");
ok = ok && rule(focus.getSnapshot().getElement().get(22).getPath().equals("Patient.extension.url"), "element 22 (2nd slice).url path");
ok = ok && rule(focus.getSnapshot().getElement().get(23).getPath().equals("Patient.extension.value[x]"), "element 23 (2nd slice).url path");
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 <= 7 ? i : i + 16);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
if (f.getPath().equals("Patient.extension")) {
ok = f.hasSlicing();
if (ok)
f.setSlicing(null);
}
if (// no compare that because the definitions get overwritten
!f.getPath().equals("Patient.extension"))
ok = Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation slicing extensions complex (" + (implicit ? "implicit" : "not implicit") + ") failed");
} else
System.out.println("Snap shot generation slicing extensions complex (" + (implicit ? "implicit" : "not implicit") + ") passed");
}
use of org.hl7.fhir.utilities.validation.ValidationMessage 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
*/
private void testSimple2() throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBase(base.getUrl());
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "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);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
ok = Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation simple test failed");
} else
System.out.println("Snap shot generation simple test passed");
}
use of org.hl7.fhir.utilities.validation.ValidationMessage 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 {
source.setUserData(GENERATED_IN_SNAPSHOT, true);
// 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);
// Before applying changes, apply them to what's in the profile
// TODO: follow Chris's rules
StructureDefinition profile = source.getType().size() == 1 && source.getTypeFirstRep().hasProfile() ? context.fetchResource(StructureDefinition.class, source.getTypeFirstRep().getProfile()) : null;
if (profile != null) {
ElementDefinition e = profile.getSnapshot().getElement().get(0);
base.setDefinition(e.getDefinition());
base.setShort(e.getShort());
if (e.hasCommentElement())
base.setCommentElement(e.getCommentElement());
if (e.hasRequirementsElement())
base.setRequirementsElement(e.getRequirementsElement());
base.getAlias().clear();
base.getAlias().addAll(e.getAlias());
base.getMapping().clear();
base.getMapping().addAll(e.getMapping());
}
if (derived != null) {
boolean isExtension = checkExtensionDoco(base);
if (derived.hasSliceName()) {
base.setSliceName(derived.getSliceName());
}
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.hasCommentElement()) {
if (derived.getComment().startsWith("..."))
base.setComment(base.getComment() + "\r\n" + derived.getComment().substring(3));
else if (derived.hasCommentElement() != base.hasCommentElement() || !Base.compareDeep(derived.getCommentElement(), base.getCommentElement(), false))
base.setCommentElement(derived.getCommentElement().copy());
else if (trimDifferential)
base.setCommentElement(derived.getCommentElement().copy());
else if (derived.hasCommentElement())
derived.getCommentElement().setUserData(DERIVATION_EQUALS, true);
}
if (derived.hasLabelElement()) {
if (derived.getLabel().startsWith("..."))
base.setLabel(base.getLabel() + "\r\n" + derived.getLabel().substring(3));
else if (!base.hasLabelElement() || !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.hasRequirementsElement() || !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, ValidationMessage.IssueType.BUSINESSRULE, pn + "." + source.getPath(), "Derived min (" + Integer.toString(derived.getMin()) + ") cannot be less than base min (" + Integer.toString(base.getMin()) + ")", ValidationMessage.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, ValidationMessage.IssueType.BUSINESSRULE, pn + "." + source.getPath(), "Derived max (" + derived.getMax() + ") cannot be greater than base max (" + base.getMax() + ")", ValidationMessage.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);
}
for (ElementDefinitionExampleComponent ex : derived.getExample()) {
boolean found = false;
for (ElementDefinitionExampleComponent exS : base.getExample()) if (Base.compareDeep(ex, exS, false))
found = true;
if (!found)
base.addExample(ex.copy());
else if (trimDifferential)
derived.getExample().remove(ex);
else
ex.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.hasMustSupportElement() && 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 (derived.hasIsModifierElement() && !(base.hasIsModifierElement() && Base.compareDeep(derived.getIsModifierElement(), base.getIsModifierElement(), false)))
base.setIsModifierElement(derived.getIsModifierElement().copy());
else if (trimDifferential)
derived.setIsModifierElement(null);
else if (derived.hasIsModifierElement())
derived.getIsModifierElement().setUserData(DERIVATION_EQUALS, true);
}
if (derived.hasBinding()) {
if (!base.hasBinding() || !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, ValidationMessage.IssueType.BUSINESSRULE, pn + "." + derived.getPath(), "illegal attempt to change the binding on " + derived.getPath() + " from " + base.getBinding().getStrength().toCode() + " to " + derived.getBinding().getStrength().toCode(), ValidationMessage.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 && base.getBinding().hasValueSetReference() && derived.getBinding().hasValueSetReference()) {
ValueSetExpansionOutcome expBase = context.expandVS(context.fetchResource(ValueSet.class, base.getBinding().getValueSetReference().getReference()), true, false);
ValueSetExpansionOutcome expDerived = context.expandVS(context.fetchResource(ValueSet.class, derived.getBinding().getValueSetReference().getReference()), true, false);
if (expBase.getValueset() == null)
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.BUSINESSRULE, pn + "." + base.getPath(), "Binding " + base.getBinding().getValueSetReference().getReference() + " could not be expanded", ValidationMessage.IssueSeverity.WARNING));
else if (expDerived.getValueset() == null)
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.BUSINESSRULE, pn + "." + derived.getPath(), "Binding " + derived.getBinding().getValueSetReference().getReference() + " could not be expanded", ValidationMessage.IssueSeverity.WARNING));
else if (!isSubset(expBase.getValueset(), expDerived.getValueset()))
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.BUSINESSRULE, pn + "." + derived.getPath(), "Binding " + derived.getBinding().getValueSetReference().getReference() + " is not a subset of binding " + base.getBinding().getValueSetReference().getReference(), ValidationMessage.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)) {
if (base.hasIsSummary())
throw new Error("Error in profile " + pn + " at " + derived.getPath() + ": Base isSummary = " + base.getIsSummaryElement().asStringValue() + ", derived isSummary = " + derived.getIsSummaryElement().asStringValue());
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 (!s.hasSource())
s.setSource(base.getId());
}
if (derived.hasConstraint()) {
for (ElementDefinitionConstraintComponent s : derived.getConstraint()) {
ElementDefinitionConstraintComponent inv = s.copy();
base.getConstraint().add(inv);
}
}
// now, check that we still have a bindable type; if not, delete the binding - see task 8477
if (dest.hasBinding() && !hasBindableType(dest))
dest.setBinding(null);
// finally, we copy any extensions from source to dest
for (Extension ex : base.getExtension()) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, ex.getUrl());
if (sd == null || sd.getSnapshot() == null || sd.getSnapshot().getElementFirstRep().getMax().equals("1"))
ToolingExtensions.removeExtension(dest, ex.getUrl());
dest.addExtension(ex);
}
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method seeProfile.
public void seeProfile(String url, StructureDefinition p) throws FHIRException {
if (Utilities.noString(url))
url = p.getUrl();
if (!p.hasSnapshot() && p.getKind() != StructureDefinitionKind.LOGICAL) {
if (!p.hasBaseDefinition())
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") has no base and no snapshot");
StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBaseDefinition());
if (sd == null)
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") base " + p.getBaseDefinition() + " could not be resolved");
List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
List<String> errors = new ArrayList<String>();
ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
pu.sortDifferential(sd, p, url, errors);
for (String err : errors) msgs.add(new ValidationMessage(Source.ProfileValidator, IssueType.EXCEPTION, p.getUserString("path"), "Error sorting Differential: " + err, ValidationMessage.IssueSeverity.ERROR));
pu.generateSnapshot(sd, p, p.getUrl(), p.getName());
for (ValidationMessage msg : msgs) {
if (msg.getLevel() == ValidationMessage.IssueSeverity.ERROR || msg.getLevel() == ValidationMessage.IssueSeverity.FATAL)
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot: " + msg.getMessage());
}
if (!p.hasSnapshot())
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot");
pu = null;
}
if (structures.containsKey(p.getUrl()) && !allowLoadingDuplicates)
throw new DefinitionException("Duplicate structures " + p.getUrl());
structures.put(p.getId(), p);
structures.put(p.getUrl(), p);
if (!p.getUrl().equals(url))
structures.put(url, p);
}
use of org.hl7.fhir.utilities.validation.ValidationMessage in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method compareChildren.
private boolean compareChildren(ElementDefinition ed, ProfileComparison outcome, String path, DefinitionNavigator left, DefinitionNavigator right) throws DefinitionException, IOException, FHIRFormatError {
List<DefinitionNavigator> lc = left.children();
List<DefinitionNavigator> rc = right.children();
// walk into it
if (lc.isEmpty() && !rc.isEmpty() && right.current().getType().size() == 1 && left.hasTypeChildren(right.current().getType().get(0)))
lc = left.childrenFromType(right.current().getType().get(0));
if (rc.isEmpty() && !lc.isEmpty() && left.current().getType().size() == 1 && right.hasTypeChildren(left.current().getType().get(0)))
rc = right.childrenFromType(left.current().getType().get(0));
if (lc.size() != rc.size()) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Different number of children at " + path + " (" + Integer.toString(lc.size()) + "/" + Integer.toString(rc.size()) + ")", ValidationMessage.IssueSeverity.ERROR));
status(ed, ProfileUtilities.STATUS_ERROR);
return false;
} else {
for (int i = 0; i < lc.size(); i++) {
DefinitionNavigator l = lc.get(i);
DefinitionNavigator r = rc.get(i);
String cpath = comparePaths(l.path(), r.path(), path, l.nameTail(), r.nameTail());
if (cpath != null) {
if (!compareElements(outcome, cpath, l, r))
return false;
} else {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Different path at " + path + "[" + Integer.toString(i) + "] (" + l.path() + "/" + r.path() + ")", ValidationMessage.IssueSeverity.ERROR));
status(ed, ProfileUtilities.STATUS_ERROR);
return false;
}
}
}
return true;
}
Aggregations