fix bugs in type handling

This commit is contained in:
Grahame Grieve 2023-07-22 21:01:08 +10:00
parent 363045c1c8
commit bb4379f5dd
2 changed files with 15 additions and 7 deletions

View File

@ -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<>();

View File

@ -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;
}