fix validator bug (issue 47)

This commit is contained in:
Grahame Grieve 2019-06-19 09:07:29 +10:00
parent 70ce1ded74
commit 3b76303d83
12 changed files with 432 additions and 254 deletions

View File

@ -1,7 +1,7 @@
package org.hl7.fhir.convertors.conv40_50;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.SearchParameter.SearchModifierCodeEnumFactory;
import org.hl7.fhir.convertors.VersionConvertor_40_50;
@ -222,7 +222,7 @@ public class SearchParameter extends VersionConvertor_40_50 {
public static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode> convertSearchModifierCode(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode> src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode> tgt = new org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode>();
org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode> tgt = new org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode>(new org.hl7.fhir.r5.model.SearchParameter.SearchModifierCodeEnumFactory());
copyEnumeration(src, tgt);
switch (src.getValue()) {
case MISSING: tgt.setValue(org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode.MISSING);
@ -245,7 +245,7 @@ public class SearchParameter extends VersionConvertor_40_50 {
public static org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode> convertSearchModifierCode(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.SearchParameter.SearchModifierCode> src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode> tgt = new org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode>();
org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode> tgt = new org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode>(new org.hl7.fhir.r4.model.SearchParameter.SearchModifierCodeEnumFactory());
copyEnumeration(src, tgt);
switch (src.getValue()) {
case MISSING: tgt.setValue( org.hl7.fhir.r4.model.SearchParameter.SearchModifierCode.MISSING);

View File

@ -374,8 +374,10 @@ public class ExpressionNode {
b.append(" '");
b.append(Utilities.escapeJson(q.getUnit()));
b.append("'");
} else
} else if (constant.primitiveValue() != null)
b.append(Utilities.escapeJson(constant.primitiveValue()));
else
b.append(Utilities.escapeJson(constant.toString()));
break;
case Group:
b.append("(");

View File

@ -114,6 +114,11 @@ public class FHIRPathEngine {
public String getValue() {
return value;
}
@Override
public String primitiveValue() {
return value;
}
}
private class ClassTypeInfo extends Base {

View File

@ -3734,15 +3734,7 @@ private boolean isAnswerRequirementFulfilled(QuestionnaireItemComponent qItem, L
// System.out.println(" "+stack.getLiteralPath()+" "+Long.toString((System.nanoTime() - time) / 1000000));
// time = System.nanoTime();
if (resource.getName().equals("contained")) {
NodeStack ancestor = stack;
while (!ancestor.element.isResource() || ancestor.element.getName().equals("contained"))
ancestor = ancestor.parent;
checkInvariants(hostContext, errors, stack.getLiteralPath(), profile, definition, null, null, ancestor.element, element);
} else
checkInvariants(hostContext, errors, stack.getLiteralPath(), profile, definition, null, null, resource, element);
if (definition.getFixed()!=null)
checkFixedValue(errors, stack.getLiteralPath(), element, definition.getFixed(), definition.getSliceName(), null);
checkInvariants(hostContext, errors, profile, definition, resource, element, stack);
// get the list of direct defined children, including slices
@ -3750,7 +3742,6 @@ private boolean isAnswerRequirementFulfilled(QuestionnaireItemComponent qItem, L
if (childDefinitions.isEmpty()) {
if (actualType == null)
return; // there'll be an error elsewhere in this case, and we're going to stop.
StructureDefinition dt = this.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + actualType);
if (dt == null)
throw new DefinitionException("Unable to resolve actual type " + actualType);
@ -3758,12 +3749,259 @@ private boolean isAnswerRequirementFulfilled(QuestionnaireItemComponent qItem, L
childDefinitions = ProfileUtilities.getChildMap(dt, dt.getSnapshot().getElement().get(0));
}
// 1. List the children, and remember their exact path (convenience)
List<ElementInfo> children = new ArrayList<InstanceValidator.ElementInfo>();
ChildIterator iter = new ChildIterator(stack.getLiteralPath(), element);
while (iter.next())
children.add(new ElementInfo(iter.name(), iter.element(), iter.path(), iter.count()));
List<ElementInfo> children = listChildren(element, stack);
List<String> problematicPaths = assignChildren(hostContext, errors, profile, resource, stack, childDefinitions, children);
checkCardinalities(errors, profile, element, stack, childDefinitions, children, problematicPaths);
// 4. check order if any slices are ordered. (todo)
// 5. inspect each child for validity
for (ElementInfo ei : children) {
checkChild(hostContext, errors, profile, definition, resource, element, actualType, stack, inCodeableConcept, checkDisplayInContext, ei);
}
}
public void checkChild(ValidatorHostContext hostContext, List<ValidationMessage> errors, StructureDefinition profile, ElementDefinition definition,
Element resource, Element element, String actualType, NodeStack stack, boolean inCodeableConcept, boolean checkDisplayInContext, ElementInfo ei)
throws FHIRException, IOException, DefinitionException {
List<String> profiles = new ArrayList<String>();
if (ei.definition != null) {
String type = null;
ElementDefinition typeDefn = null;
String usesMustSupport = profile.getUserString("usesMustSupport");
if (usesMustSupport == null) {
usesMustSupport = "N";
for (ElementDefinition pe: profile.getSnapshot().getElement()) {
if (pe.getMustSupport()) {
usesMustSupport = "Y";
break;
}
}
profile.setUserData("usesMustSupport", usesMustSupport);
}
if (usesMustSupport.equals("Y")) {
String elementSupported = ei.element.getUserString("elementSupported");
if (elementSupported==null || ei.definition.getMustSupport())
if (ei.definition.getMustSupport())
ei.element.setUserData("elementSupported", "Y");
else
ei.element.setUserData("elementSupported", "N");
}
if (ei.definition.getType().size() == 1 && !"*".equals(ei.definition.getType().get(0).getCode()) && !"Element".equals(ei.definition.getType().get(0).getCode())
&& !"BackboneElement".equals(ei.definition.getType().get(0).getCode())) {
type = ei.definition.getType().get(0).getCode();
// Excluding reference is a kludge to get around versioning issues
if (ei.definition.getType().get(0).hasProfile())
profiles.add(ei.definition.getType().get(0).getProfile().get(0).getValue());
} else if (ei.definition.getType().size() == 1 && "*".equals(ei.definition.getType().get(0).getCode())) {
String prefix = tail(ei.definition.getPath());
assert prefix.endsWith("[x]");
type = ei.name.substring(prefix.length() - 3);
if (isPrimitiveType(type))
type = Utilities.uncapitalize(type);
// Excluding reference is a kludge to get around versioning issues
if (ei.definition.getType().get(0).hasProfile() && !type.equals("Reference"))
profiles.add(ei.definition.getType().get(0).getProfile().get(0).getValue());
} else if (ei.definition.getType().size() > 1) {
String prefix = tail(ei.definition.getPath());
assert typesAreAllReference(ei.definition.getType()) || ei.definition.hasRepresentation(PropertyRepresentation.TYPEATTR) || prefix.endsWith("[x]") : prefix;
if (ei.definition.hasRepresentation(PropertyRepresentation.TYPEATTR))
type = ei.element.getType();
else {
prefix = prefix.substring(0, prefix.length() - 3);
for (TypeRefComponent t : ei.definition.getType())
if ((prefix + Utilities.capitalize(t.getCode())).equals(ei.name)) {
type = t.getCode();
// Excluding reference is a kludge to get around versioning issues
if (t.hasProfile() && !type.equals("Reference"))
profiles.add(t.getProfile().get(0).getValue());
}
}
if (type == null) {
TypeRefComponent trc = ei.definition.getType().get(0);
if (trc.getCode().equals("Reference"))
type = "Reference";
else
rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), stack.getLiteralPath(), false,
"The type of element " + ei.name + " is not known, which is illegal. Valid types at this point are " + describeTypes(ei.definition.getType()));
}
} else if (ei.definition.getContentReference() != null) {
typeDefn = resolveNameReference(profile.getSnapshot(), ei.definition.getContentReference());
} else if (ei.definition.getType().size() == 1 && ("Element".equals(ei.definition.getType().get(0).getCode()) || "BackboneElement".equals(ei.definition.getType().get(0).getCode()))) {
if (ei.definition.getType().get(0).hasProfile()) {
CanonicalType pu = ei.definition.getType().get(0).getProfile().get(0);
if (pu.hasExtension(ToolingExtensions.EXT_PROFILE_ELEMENT))
profiles.add(pu.getValue()+"#"+pu.getExtensionString(ToolingExtensions.EXT_PROFILE_ELEMENT));
else
profiles.add(pu.getValue());
}
}
if (type != null) {
if (type.startsWith("@")) {
ei.definition = findElement(profile, type.substring(1));
type = null;
}
}
NodeStack localStack = stack.push(ei.element, ei.count, ei.definition, type == null ? typeDefn : resolveType(type, ei.definition.getType()));
String localStackLiterapPath = localStack.getLiteralPath();
String eiPath = ei.path;
assert(eiPath.equals(localStackLiterapPath)) : "ei.path: " + ei.path + " - localStack.getLiteralPath: " + localStackLiterapPath;
boolean thisIsCodeableConcept = false;
boolean checkDisplay = true;
ei.element.markValidation(profile, ei.definition);
if (type != null) {
if (isPrimitiveType(type)) {
checkPrimitive(hostContext, errors, ei.path, type, ei.definition, ei.element, profile, stack);
} else {
if (ei.definition.hasFixed()) {
checkFixedValue(errors,ei.path, ei.element, ei.definition.getFixed(), ei.definition.getSliceName(), null);
}
if (ei.definition.hasPattern()) {
checkFixedValue(errors,ei.path, ei.element, ei.definition.getPattern(), ei.definition.getSliceName(), null, true);
}
}
if (type.equals("Identifier")) {
checkIdentifier(errors, ei.path, ei.element, ei.definition);
} else if (type.equals("Coding")) {
checkCoding(errors, ei.path, ei.element, profile, ei.definition, inCodeableConcept, checkDisplayInContext, stack);
} else if (type.equals("CodeableConcept")) {
checkDisplay = checkCodeableConcept(errors, ei.path, ei.element, profile, ei.definition, stack);
thisIsCodeableConcept = true;
} else if (type.equals("Reference")) {
checkReference(hostContext, errors, ei.path, ei.element, profile, ei.definition, actualType, localStack);
// We only check extensions if we're not in a complex extension or if the element we're dealing with is not defined as part of that complex extension
} else if (type.equals("Extension") && ei.element.getChildValue("url") != null && ei.element.getChildValue("url").contains("/")) {
checkExtension(hostContext, errors, ei.path, resource, ei.element, ei.definition, profile, localStack);
} else if (type.equals("Resource")) {
validateContains(hostContext, errors, ei.path, ei.definition, definition, resource, ei.element, localStack, idStatusForEntry(element, ei)); // if
// (str.matches(".*([.,/])work\\1$"))
}
} else {
if (rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), stack.getLiteralPath(), ei.definition != null, "Unrecognised Content " + ei.name))
validateElement(hostContext, errors, profile, ei.definition, null, null, resource, ei.element, type, localStack, false, true);
}
StructureDefinition p = null;
boolean elementValidated = false;
String tail = null;
if (profiles.isEmpty()) {
if (type != null) {
p = getProfileForType(type, ei.definition.getType());
// If dealing with a primitive type, then we need to check the current child against
// the invariants (constraints) on the current element, because otherwise it only gets
// checked against the primary type's invariants: LLoyd
//if (p.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
// checkInvariants(hostContext, errors, ei.path, profile, ei.definition, null, null, resource, ei.element);
//}
rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, p != null, "Unknown type " + type);
}
} else if (profiles.size()==1) {
String url = profiles.get(0);
if (url.contains("#")) {
tail = url.substring(url.indexOf("#")+1);
url = url.substring(0, url.indexOf("#"));
}
p = this.context.fetchResource(StructureDefinition.class, url);
rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, p != null, "Unknown profile " + profiles.get(0));
} else {
elementValidated = true;
HashMap<String, List<ValidationMessage>> goodProfiles = new HashMap<String, List<ValidationMessage>>();
List<List<ValidationMessage>> badProfiles = new ArrayList<List<ValidationMessage>>();
for (String typeProfile : profiles) {
String url = typeProfile;
tail = null;
if (url.contains("#")) {
tail = url.substring(url.indexOf("#")+1);
url = url.substring(0, url.indexOf("#"));
}
p = this.context.fetchResource(StructureDefinition.class, typeProfile);
if (rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, p != null, "Unknown profile " + typeProfile)) {
List<ValidationMessage> profileErrors = new ArrayList<ValidationMessage>();
validateElement(hostContext, profileErrors, p, getElementByTail(p, tail), profile, ei.definition, resource, ei.element, type, localStack, thisIsCodeableConcept, checkDisplay);
if (hasErrors(profileErrors))
badProfiles.add(profileErrors);
else
goodProfiles.put(typeProfile, profileErrors);
}
if (goodProfiles.size()==1) {
errors.addAll(goodProfiles.values().iterator().next());
} else if (goodProfiles.size()==0) {
rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, false, "Unable to find matching profile among choices: " + StringUtils.join("; ", profiles));
for (List<ValidationMessage> messages : badProfiles) {
errors.addAll(messages);
}
} else {
warning(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, false, "Found multiple matching profiles among choices: " + StringUtils.join("; ", goodProfiles.keySet()));
for (List<ValidationMessage> messages : goodProfiles.values()) {
errors.addAll(messages);
}
}
}
}
if (p!=null) {
if (!elementValidated) {
if (ei.element.getSpecial() == SpecialElement.BUNDLE_ENTRY || ei.element.getSpecial() == SpecialElement.BUNDLE_OUTCOME || ei.element.getSpecial() == SpecialElement.PARAMETER )
validateElement(hostContext, errors, p, getElementByTail(p, tail), profile, ei.definition, ei.element, ei.element, type, localStack, thisIsCodeableConcept, checkDisplay);
else
validateElement(hostContext, errors, p, getElementByTail(p, tail), profile, ei.definition, resource, ei.element, type, localStack, thisIsCodeableConcept, checkDisplay);
}
int index = profile.getSnapshot().getElement().indexOf(ei.definition);
if (index < profile.getSnapshot().getElement().size() - 1) {
String nextPath = profile.getSnapshot().getElement().get(index+1).getPath();
if (!nextPath.equals(ei.definition.getPath()) && nextPath.startsWith(ei.definition.getPath()))
validateElement(hostContext, errors, profile, ei.definition, null, null, resource, ei.element, type, localStack, thisIsCodeableConcept, checkDisplay);
}
}
}
}
public void checkCardinalities(List<ValidationMessage> errors, StructureDefinition profile, Element element, NodeStack stack,
List<ElementDefinition> childDefinitions, List<ElementInfo> children, List<String> problematicPaths) throws DefinitionException {
// 3. report any definitions that have a cardinality problem
for (ElementDefinition ed : childDefinitions) {
if (ed.getRepresentation().isEmpty()) { // ignore xml attributes
int count = 0;
List<ElementDefinition> slices = null;
if (ed.hasSlicing())
slices = ProfileUtilities.getSliceList(profile, ed);
for (ElementInfo ei : children)
if (ei.definition == ed)
count++;
else if (slices!=null) {
for (ElementDefinition sed : slices) {
if (ei.definition == sed) {
count++;
break;
}
}
}
String location = "Profile " + profile.getUrl() + ", Element '" + stack.getLiteralPath() + "." + tail(ed.getPath()) + (ed.hasSliceName()? "[" + ed.getSliceName() + (ed.hasLabel() ? " ("+ed.getLabel()+")" : "")+"]": "") + "'";
if (ed.getMin() > 0) {
if (problematicPaths.contains(ed.getPath()))
hint(errors, IssueType.NOTSUPPORTED, element.line(), element.col(), stack.getLiteralPath(), count >= ed.getMin(), location + "': Unable to check minimum required (" + Integer.toString(ed.getMin()) + ") due to lack of slicing validation");
else
rule(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), count >= ed.getMin(), location + ": minimum required = " + Integer.toString(ed.getMin()) + ", but only found " + Integer.toString(count));
}
if (ed.hasMax() && !ed.getMax().equals("*")) {
if (problematicPaths.contains(ed.getPath()))
hint(errors, IssueType.NOTSUPPORTED, element.line(), element.col(), stack.getLiteralPath(), count <= Integer.parseInt(ed.getMax()), location + ": Unable to check max allowed (" + ed.getMax() + ") due to lack of slicing validation");
else
rule(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), count <= Integer.parseInt(ed.getMax()), location + ": max allowed = " + ed.getMax() + ", but found " + Integer.toString(count));
}
}
}
}
public List<String> assignChildren(ValidatorHostContext hostContext, List<ValidationMessage> errors, StructureDefinition profile, Element resource,
NodeStack stack, List<ElementDefinition> childDefinitions, List<ElementInfo> children) throws DefinitionException, IOException {
// 2. assign children to a definition
// for each definition, for each child, check whether it belongs in the slice
ElementDefinition slicer = null;
@ -3847,239 +4085,29 @@ private boolean isAnswerRequirementFulfilled(QuestionnaireItemComponent qItem, L
else
lastSlice = -1;
}
return problematicPaths;
}
// 3. report any definitions that have a cardinality problem
for (ElementDefinition ed : childDefinitions) {
if (ed.getRepresentation().isEmpty()) { // ignore xml attributes
int count = 0;
List<ElementDefinition> slices = null;
if (ed.hasSlicing())
slices = ProfileUtilities.getSliceList(profile, ed);
for (ElementInfo ei : children)
if (ei.definition == ed)
count++;
else if (slices!=null) {
for (ElementDefinition sed : slices) {
if (ei.definition == sed) {
count++;
break;
}
}
}
String location = "Profile " + profile.getUrl() + ", Element '" + stack.getLiteralPath() + "." + tail(ed.getPath()) + (ed.hasSliceName()? "[" + ed.getSliceName() + (ed.hasLabel() ? " ("+ed.getLabel()+")" : "")+"]": "") + "'";
if (ed.getMin() > 0) {
if (problematicPaths.contains(ed.getPath()))
hint(errors, IssueType.NOTSUPPORTED, element.line(), element.col(), stack.getLiteralPath(), count >= ed.getMin(), location + "': Unable to check minimum required (" + Integer.toString(ed.getMin()) + ") due to lack of slicing validation");
else
rule(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), count >= ed.getMin(), location + ": minimum required = " + Integer.toString(ed.getMin()) + ", but only found " + Integer.toString(count));
}
if (ed.hasMax() && !ed.getMax().equals("*")) {
if (problematicPaths.contains(ed.getPath()))
hint(errors, IssueType.NOTSUPPORTED, element.line(), element.col(), stack.getLiteralPath(), count <= Integer.parseInt(ed.getMax()), location + ": Unable to check max allowed (" + ed.getMax() + ") due to lack of slicing validation");
else
rule(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), count <= Integer.parseInt(ed.getMax()), location + ": max allowed = " + ed.getMax() + ", but found " + Integer.toString(count));
}
}
}
// 4. check order if any slices are ordered. (todo)
public List<ElementInfo> listChildren(Element element, NodeStack stack) {
// 1. List the children, and remember their exact path (convenience)
List<ElementInfo> children = new ArrayList<InstanceValidator.ElementInfo>();
ChildIterator iter = new ChildIterator(stack.getLiteralPath(), element);
while (iter.next())
children.add(new ElementInfo(iter.name(), iter.element(), iter.path(), iter.count()));
return children;
}
// 5. inspect each child for validity
for (ElementInfo ei : children) {
List<String> profiles = new ArrayList<String>();
if (ei.definition != null) {
String type = null;
ElementDefinition typeDefn = null;
String usesMustSupport = profile.getUserString("usesMustSupport");
if (usesMustSupport == null) {
usesMustSupport = "N";
for (ElementDefinition pe: profile.getSnapshot().getElement()) {
if (pe.getMustSupport()) {
usesMustSupport = "Y";
break;
}
}
profile.setUserData("usesMustSupport", usesMustSupport);
}
if (usesMustSupport.equals("Y")) {
String elementSupported = ei.element.getUserString("elementSupported");
if (elementSupported==null || ei.definition.getMustSupport())
if (ei.definition.getMustSupport())
ei.element.setUserData("elementSupported", "Y");
else
ei.element.setUserData("elementSupported", "N");
}
if (ei.definition.getType().size() == 1 && !"*".equals(ei.definition.getType().get(0).getCode()) && !"Element".equals(ei.definition.getType().get(0).getCode())
&& !"BackboneElement".equals(ei.definition.getType().get(0).getCode())) {
type = ei.definition.getType().get(0).getCode();
// Excluding reference is a kludge to get around versioning issues
if (ei.definition.getType().get(0).hasProfile())
profiles.add(ei.definition.getType().get(0).getProfile().get(0).getValue());
} else if (ei.definition.getType().size() == 1 && "*".equals(ei.definition.getType().get(0).getCode())) {
String prefix = tail(ei.definition.getPath());
assert prefix.endsWith("[x]");
type = ei.name.substring(prefix.length() - 3);
if (isPrimitiveType(type))
type = Utilities.uncapitalize(type);
// Excluding reference is a kludge to get around versioning issues
if (ei.definition.getType().get(0).hasProfile() && !type.equals("Reference"))
profiles.add(ei.definition.getType().get(0).getProfile().get(0).getValue());
} else if (ei.definition.getType().size() > 1) {
String prefix = tail(ei.definition.getPath());
assert typesAreAllReference(ei.definition.getType()) || ei.definition.hasRepresentation(PropertyRepresentation.TYPEATTR) || prefix.endsWith("[x]") : prefix;
if (ei.definition.hasRepresentation(PropertyRepresentation.TYPEATTR))
type = ei.element.getType();
else {
prefix = prefix.substring(0, prefix.length() - 3);
for (TypeRefComponent t : ei.definition.getType())
if ((prefix + Utilities.capitalize(t.getCode())).equals(ei.name)) {
type = t.getCode();
// Excluding reference is a kludge to get around versioning issues
if (t.hasProfile() && !type.equals("Reference"))
profiles.add(t.getProfile().get(0).getValue());
}
}
if (type == null) {
TypeRefComponent trc = ei.definition.getType().get(0);
if (trc.getCode().equals("Reference"))
type = "Reference";
else
rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), stack.getLiteralPath(), false,
"The type of element " + ei.name + " is not known, which is illegal. Valid types at this point are " + describeTypes(ei.definition.getType()));
}
} else if (ei.definition.getContentReference() != null) {
typeDefn = resolveNameReference(profile.getSnapshot(), ei.definition.getContentReference());
} else if (ei.definition.getType().size() == 1 && ("Element".equals(ei.definition.getType().get(0).getCode()) || "BackboneElement".equals(ei.definition.getType().get(0).getCode()))) {
if (ei.definition.getType().get(0).hasProfile()) {
CanonicalType pu = ei.definition.getType().get(0).getProfile().get(0);
if (pu.hasExtension(ToolingExtensions.EXT_PROFILE_ELEMENT))
profiles.add(pu.getValue()+"#"+pu.getExtensionString(ToolingExtensions.EXT_PROFILE_ELEMENT));
else
profiles.add(pu.getValue());
}
}
if (type != null) {
if (type.startsWith("@")) {
ei.definition = findElement(profile, type.substring(1));
type = null;
}
}
NodeStack localStack = stack.push(ei.element, ei.count, ei.definition, type == null ? typeDefn : resolveType(type, ei.definition.getType()));
String localStackLiterapPath = localStack.getLiteralPath();
String eiPath = ei.path;
assert(eiPath.equals(localStackLiterapPath)) : "ei.path: " + ei.path + " - localStack.getLiteralPath: " + localStackLiterapPath;
boolean thisIsCodeableConcept = false;
boolean checkDisplay = true;
ei.element.markValidation(profile, ei.definition);
if (type != null) {
if (isPrimitiveType(type)) {
checkPrimitive(hostContext, errors, ei.path, type, ei.definition, ei.element, profile, stack);
} else {
if (ei.definition.hasFixed()) {
checkFixedValue(errors,ei.path, ei.element, ei.definition.getFixed(), ei.definition.getSliceName(), null);
}
if (ei.definition.hasPattern()) {
checkFixedValue(errors,ei.path, ei.element, ei.definition.getPattern(), ei.definition.getSliceName(), null, true);
}
}
if (type.equals("Identifier")) {
checkIdentifier(errors, ei.path, ei.element, ei.definition);
} else if (type.equals("Coding")) {
checkCoding(errors, ei.path, ei.element, profile, ei.definition, inCodeableConcept, checkDisplayInContext, stack);
} else if (type.equals("CodeableConcept")) {
checkDisplay = checkCodeableConcept(errors, ei.path, ei.element, profile, ei.definition, stack);
thisIsCodeableConcept = true;
} else if (type.equals("Reference")) {
checkReference(hostContext, errors, ei.path, ei.element, profile, ei.definition, actualType, localStack);
// We only check extensions if we're not in a complex extension or if the element we're dealing with is not defined as part of that complex extension
} else if (type.equals("Extension") && ei.element.getChildValue("url") != null && ei.element.getChildValue("url").contains("/")) {
checkExtension(hostContext, errors, ei.path, resource, ei.element, ei.definition, profile, localStack);
} else if (type.equals("Resource")) {
validateContains(hostContext, errors, ei.path, ei.definition, definition, resource, ei.element, localStack, idStatusForEntry(element, ei)); // if
// (str.matches(".*([.,/])work\\1$"))
}
} else {
if (rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), stack.getLiteralPath(), ei.definition != null, "Unrecognised Content " + ei.name))
validateElement(hostContext, errors, profile, ei.definition, null, null, resource, ei.element, type, localStack, false, true);
}
StructureDefinition p = null;
boolean elementValidated = false;
String tail = null;
if (profiles.isEmpty()) {
if (type != null) {
p = getProfileForType(type, ei.definition.getType());
// If dealing with a primitive type, then we need to check the current child against
// the invariants (constraints) on the current element, because otherwise it only gets
// checked against the primary type's invariants: LLoyd
//if (p.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
// checkInvariants(hostContext, errors, ei.path, profile, ei.definition, null, null, resource, ei.element);
//}
rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, p != null, "Unknown type " + type);
}
} else if (profiles.size()==1) {
String url = profiles.get(0);
if (url.contains("#")) {
tail = url.substring(url.indexOf("#")+1);
url = url.substring(0, url.indexOf("#"));
}
p = this.context.fetchResource(StructureDefinition.class, url);
rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, p != null, "Unknown profile " + profiles.get(0));
} else {
elementValidated = true;
HashMap<String, List<ValidationMessage>> goodProfiles = new HashMap<String, List<ValidationMessage>>();
List<List<ValidationMessage>> badProfiles = new ArrayList<List<ValidationMessage>>();
for (String typeProfile : profiles) {
String url = typeProfile;
tail = null;
if (url.contains("#")) {
tail = url.substring(url.indexOf("#")+1);
url = url.substring(0, url.indexOf("#"));
}
p = this.context.fetchResource(StructureDefinition.class, typeProfile);
if (rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, p != null, "Unknown profile " + typeProfile)) {
List<ValidationMessage> profileErrors = new ArrayList<ValidationMessage>();
validateElement(hostContext, profileErrors, p, getElementByTail(p, tail), profile, ei.definition, resource, ei.element, type, localStack, thisIsCodeableConcept, checkDisplay);
if (hasErrors(profileErrors))
badProfiles.add(profileErrors);
else
goodProfiles.put(typeProfile, profileErrors);
}
if (goodProfiles.size()==1) {
errors.addAll(goodProfiles.values().iterator().next());
} else if (goodProfiles.size()==0) {
rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, false, "Unable to find matching profile among choices: " + StringUtils.join("; ", profiles));
for (List<ValidationMessage> messages : badProfiles) {
errors.addAll(messages);
}
} else {
warning(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, false, "Found multiple matching profiles among choices: " + StringUtils.join("; ", goodProfiles.keySet()));
for (List<ValidationMessage> messages : goodProfiles.values()) {
errors.addAll(messages);
}
}
}
}
if (p!=null) {
if (!elementValidated) {
validateElement(hostContext, errors, p, getElementByTail(p, tail), profile, ei.definition, resource, ei.element, type, localStack, thisIsCodeableConcept, checkDisplay);
}
int index = profile.getSnapshot().getElement().indexOf(ei.definition);
if (index < profile.getSnapshot().getElement().size() - 1) {
String nextPath = profile.getSnapshot().getElement().get(index+1).getPath();
if (!nextPath.equals(ei.definition.getPath()) && nextPath.startsWith(ei.definition.getPath()))
validateElement(hostContext, errors, profile, ei.definition, null, null, resource, ei.element, type, localStack, thisIsCodeableConcept, checkDisplay);
}
}
}
}
public void checkInvariants(ValidatorHostContext hostContext, List<ValidationMessage> errors, StructureDefinition profile, ElementDefinition definition,
Element resource, Element element, NodeStack stack) throws FHIRException {
if (resource.getName().equals("contained")) {
NodeStack ancestor = stack;
while (!ancestor.element.isResource() || ancestor.element.getName().equals("contained"))
ancestor = ancestor.parent;
checkInvariants(hostContext, errors, stack.getLiteralPath(), profile, definition, null, null, ancestor.element, element);
} else
checkInvariants(hostContext, errors, stack.getLiteralPath(), profile, definition, null, null, resource, element);
if (definition.getFixed()!=null)
checkFixedValue(errors, stack.getLiteralPath(), element, definition.getFixed(), definition.getSliceName(), null);
}
public boolean matchSlice(ValidatorHostContext hostContext, List<ValidationMessage> errors, StructureDefinition profile, NodeStack stack,

View File

@ -94,8 +94,8 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour
this.content = content;
}
// private static final String DEF_TX = "http://tx.fhir.org";
private static final String DEF_TX = "http://local.fhir.org:960";
private static final String DEF_TX = "http://tx.fhir.org";
// private static final String DEF_TX = "http://local.fhir.org:960";
private static ValidationEngine ve;
@SuppressWarnings("deprecation")

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bundle xmlns="http://hl7.org/fhir">
<type value="collection"/>
<entry>
<resource>
<Binary>
<id value="1"/>
<contentType value="text/plain"/>
<data value="VGVzdA=="/>
</Binary>
</resource>
</entry>
</Bundle>

View File

@ -0,0 +1,22 @@
<Parameters xmlns="http://hl7.org/fhir">
<meta>
<profile value="http://example.org/fhir/StructureDefinition/param-profile"/>
</meta>
<parameter>
<name value="bundleparam"/>
<resource>
<Bundle>
<type value="collection"/>
<entry>
<resource>
<Binary>
<id value="1"/>
<contentType value="text/plain"/>
<data value="VGVzdA=="/>
</Binary>
</resource>
</entry>
</Bundle>
</resource>
</parameter>
</Parameters>

View File

@ -0,0 +1,15 @@
<Parameters xmlns="http://hl7.org/fhir">
<meta>
<profile value="http://example.org/fhir/StructureDefinition/param-profile"/>
</meta>
<parameter>
<name value="binaryparam"/>
<resource>
<Binary>
<id value="1"/>
<contentType value="text/plain"/>
<data value="VGVzdA=="/>
</Binary>
</resource>
</parameter>
</Parameters>

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<StructureDefinition xmlns="http://hl7.org/fhir">
<url value="http://example.org/fhir/StructureDefinition/param-profile"/>
<name value="ParamProfile"/>
<status value="draft"/>
<fhirVersion value="4.0.0"/>
<kind value="resource"/>
<abstract value="false"/>
<type value="Parameters"/>
<baseDefinition value="http://hl7.org/fhir/StructureDefinition/Parameters"/>
<derivation value="constraint"/>
<differential>
<element id="Parameters.parameter">
<path value="Parameters.parameter"/>
<slicing>
<discriminator>
<type value="value"/>
<path value="name"/>
</discriminator>
<rules value="open"/>
</slicing>
</element>
<element id="Parameters.parameter:p1">
<path value="Parameters.parameter"/>
<sliceName value="p1"/>
<min value="0"/>
<max value="1"/>
</element>
<element id="Parameters.parameter:p1.name">
<path value="Parameters.parameter.name"/>
<fixedString value="binaryparam"/>
</element>
<element id="Parameters.parameter:p1.resource">
<path value="Parameters.parameter.resource"/>
<type>
<code value="Resource"/>
<profile value="http://example.org/fhir/StructureDefinition/text-binary"/>
</type>
</element>
<element id="Parameters.parameter:p2">
<path value="Parameters.parameter"/>
<sliceName value="p2"/>
<min value="0"/>
<max value="1"/>
</element>
<element id="Parameters.parameter:p2.name">
<path value="Parameters.parameter.name"/>
<fixedString value="bundleparam"/>
</element>
<element id="Parameters.parameter:p2.resource">
<path value="Parameters.parameter.resource"/>
<type>
<code value="Resource"/>
<profile value="http://hl7.org/fhir/StructureDefinition/Bundle"/>
</type>
</element>
</differential>
</StructureDefinition>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<StructureDefinition xmlns="http://hl7.org/fhir">
<id value="text-binary"/>
<url value="http://example.org/fhir/StructureDefinition/text-binary"/>
<name value="TextBinary"/>
<status value="draft"/>
<description value="Text represented as a FHIR Binary resource"/>
<fhirVersion value="4.0.0"/>
<kind value="resource"/>
<abstract value="false"/>
<type value="Binary"/>
<baseDefinition value="http://hl7.org/fhir/StructureDefinition/Binary"/>
<derivation value="constraint"/>
<differential>
<element id="Binary">
<path value="Binary"/>
</element>
<element id="Binary.contentType">
<path value="Binary.contentType"/>
<short value="MimeType for a test"/>
<fixedCode value="text/plain"/>
</element>
</differential>
</StructureDefinition>

View File

@ -176,7 +176,8 @@
}
},
"medication-atc.json": {
"errorCount": 0,
"errorCount": 1,
"errors-for-debugging" : ["ERROR: Medication.extension[2].valueCodeableConcept.coding: The code \"N02AA\" is not valid in the system http://www.whocc.no/atc; The code provided (http://www.whocc.no/atc#N02AA) is not valid in the value set All codes known to the system"],
"allowed-extension-domain": "https://api-v8-r4.hspconsortium.org/DrugFormulary0/open"
},
"bp.json": {
@ -781,6 +782,14 @@
"loinc-lang-nl-3.xml" : {
"errorCount": 0,
"warningCount": 0
},
"azatadha/example-params-1.xml" : {
"errorCount": 0,
"warningCount": 1,
"profile": {
"source": "azatadha/param-profile.xml",
"errorCount": 0
}
}
}
}

View File

@ -14,8 +14,8 @@ pause
call mvn versions:set -DnewVersion=%newver%-SNAPSHOT
call git commit -a -m "Release new version"
call git push origin master
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.java" --includeSubDirectories --find "%oldver%-SNAPSHOT" --replace "%newver%-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.xml" --find "%oldver%-SNAPSHOT" --replace "%newver%-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\fhir-ig-publisher" --fileMask "*.xml" --find "%oldver%-SNAPSHOT" --replace "%newver%-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\latest-ig-publisher" --fileMask "*.html" --find "%oldver%" --replace "%newver%"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\latest-ig-publisher" --fileMask "*.json" --find "%oldver%" --replace "%newver%"
call mvn deploy