fix bugs in type handling
This commit is contained in:
parent
363045c1c8
commit
bb4379f5dd
|
@ -2245,16 +2245,21 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
Set<StructureDefinition> types = new HashSet<>();
|
||||
types.addAll(fetchTypeDefinitions(typeName));
|
||||
types.removeIf(sd -> sd.getDerivation() == TypeDerivationRule.CONSTRAINT);
|
||||
if (types.size() == 1) {
|
||||
if (types.size() == 0) {
|
||||
return null; // throw new FHIRException("Unresolved type "+typeName+" (0)");
|
||||
} else if (types.size() == 1) {
|
||||
return types.iterator().next();
|
||||
} else if (types.size() > 1) {
|
||||
throw new FHIRException("Ambiguous type "+typeName);
|
||||
} else {
|
||||
return fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/"+typeName);
|
||||
} else {
|
||||
types.removeIf(sd -> !sd.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/"));
|
||||
if (types.size() != 1) {
|
||||
throw new FHIRException("Ambiguous type "+typeName+" ("+types.toString()+") (contact Grahame Grieve for investigation)");
|
||||
} else {
|
||||
return types.iterator().next();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<StructureDefinition> fetchTypeDefinitions(String typeName) {
|
||||
List<StructureDefinition> res = new ArrayList<>();
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.hl7.fhir.r5.model.NamingSystem;
|
|||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.utilities.OIDUtils;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.utilities.i18n.I18nConstants;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
|
||||
|
@ -156,8 +157,10 @@ public class ContextUtilities implements ProfileKnowledgeProvider {
|
|||
public Set<String> getTypeNameSet() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
for (StructureDefinition sd : context.fetchResourcesByType(StructureDefinition.class)) {
|
||||
if (sd.getKind() != StructureDefinitionKind.LOGICAL && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION)
|
||||
if (sd.getKind() != StructureDefinitionKind.LOGICAL && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION &&
|
||||
VersionUtilities.versionsCompatible(context.getVersion(), sd.getFhirVersion().toCode())) {
|
||||
result.add(sd.getName());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue