Use the profile of the datatype if available, intead of the default hl7.org url

This commit is contained in:
Sebastien Riviere 2017-01-19 14:55:42 +01:00
parent cac44c736c
commit 13646168f0
2 changed files with 27 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package org.hl7.fhir.dstu3.elementmodel;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.dstu3.conformance.ProfileUtilities;
import org.hl7.fhir.dstu3.context.IWorkerContext;
import org.hl7.fhir.dstu3.formats.FormatUtilities;
@ -240,7 +241,13 @@ public class Property {
}
}
if (!"xhtml".equals(t)) {
sd = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/"+t);
final String url;
if (StringUtils.isNotBlank(ed.getType().get(0).getProfile())) {
url = ed.getType().get(0).getProfile();
} else {
url = "http://hl7.org/fhir/StructureDefinition/" + t;
}
sd = context.fetchResource(StructureDefinition.class, url);
if (sd == null)
throw new DefinitionException("Unable to find class '"+t+"' for name '"+elementName+"' on property "+definition.getPath());
children = ProfileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));

View File

@ -993,8 +993,15 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
return null;
}
private StructureDefinition getProfileForType(String type) throws Exception {
return context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + type);
private StructureDefinition getProfileForType(ElementDefinition ed, String type) throws Exception {
//return context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + type);
final String url;
if (!"Reference".equals(type) && ed.getType().get(0).hasProfile()) {
url = ed.getType().get(0).getProfile().get(0).getValue();
} else {
url = "http://hl7.org/fhir/StructureDefinition/" + type;
}
return context.fetchResource(StructureDefinition.class, url);
}
private Element getValueForDiscriminator(WrapperElement element, String discriminator, ElementDefinition criteria) {
@ -1182,8 +1189,14 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
return context.fetchResource(StructureDefinition.class, pr);
}
private ElementDefinition resolveType(String type) throws EOperationOutcome, Exception {
String url = "http://hl7.org/fhir/StructureDefinition/" + type;
private ElementDefinition resolveType(ElementDefinition ed, String type) throws EOperationOutcome, Exception {
final String url;
if (ed.getType().get(0).hasProfile()) {
url = ed.getType().get(0).getProfile().get(0).getValue();
} else {
url = "http://hl7.org/fhir/StructureDefinition/" + type;
}
StructureDefinition sd = context.fetchResource(StructureDefinition.class, url);
if (sd == null || !sd.hasSnapshot())
return null;
@ -1803,7 +1816,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
type = null;
}
}
NodeStack localStack = stack.push(ei.element, ei.count, ei.definition, type == null ? typeDefn : resolveType(type));
NodeStack localStack = stack.push(ei.element, ei.count, ei.definition, type == null ? typeDefn : resolveType(ei.definition, type));
String localStackLiterapPath = localStack.getLiteralPath();
String eiPath = ei.path;
assert(eiPath.equals(localStackLiterapPath)) : "ei.path: " + ei.path + " - localStack.getLiterapPath: " + localStackLiterapPath;
@ -1828,7 +1841,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
validateContains(errors, ei.path, ei.definition, definition, ei.element, localStack, !isBundleEntry(ei.path) && !isParametersEntry(ei.path)); // if
// (str.matches(".*([.,/])work\\1$"))
else {
StructureDefinition p = getProfileForType(type);
StructureDefinition p = getProfileForType(ei.definition, type);
if (rule(errors, IssueType.STRUCTURE, ei.line(), ei.col(), ei.path, p != null, "Unknown type " + type)) {
validateElement(errors, p, p.getSnapshot().getElement().get(0), profile, ei.definition, ei.element, type, localStack);
}