clean up bug checking data types in ContextUtilities

This commit is contained in:
Grahame Grieve 2022-10-25 14:58:00 +11:00
parent f1c56ca0d6
commit c13f24ef4c
5 changed files with 30 additions and 5 deletions

View File

@ -439,6 +439,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public String url; public String url;
} }
boolean isDatatype(String typeSimple); boolean isDatatype(String typeSimple);
boolean isPrimitiveType(String typeSimple);
boolean isResource(String typeSimple); boolean isResource(String typeSimple);
boolean hasLinkFor(String typeSimple); boolean hasLinkFor(String typeSimple);
String getLinkFor(String corePath, String typeSimple); String getLinkFor(String corePath, String typeSimple);
@ -3291,10 +3292,10 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
} }
if (dest.hasFixed()) { if (dest.hasFixed()) {
checkTypeOk(dest, dest.getFixed().fhirType(), srcSD); checkTypeOk(dest, dest.getFixed().fhirType(), srcSD, "fixed");
} }
if (dest.hasPattern()) { if (dest.hasPattern()) {
checkTypeOk(dest, dest.getPattern().fhirType(), srcSD); checkTypeOk(dest, dest.getPattern().fhirType(), srcSD, "pattern");
} }
} }
@ -3359,7 +3360,7 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
public void checkTypeOk(ElementDefinition dest, String ft, StructureDefinition sd) { public void checkTypeOk(ElementDefinition dest, String ft, StructureDefinition sd, String fieldName) {
boolean ok = false; boolean ok = false;
Set<String> types = new HashSet<>(); Set<String> types = new HashSet<>();
if (dest.getPath().contains(".")) { if (dest.getPath().contains(".")) {
@ -3375,7 +3376,7 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
if (!ok) { if (!ok) {
messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.CONFLICT, dest.getId(), "The fixed value has type '"+ft+"' which is not valid (valid "+Utilities.pluralize("type", dest.getType().size())+": "+types.toString()+")", IssueSeverity.ERROR)); messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.CONFLICT, dest.getId(), "The "+fieldName+" value has type '"+ft+"' which is not valid (valid "+Utilities.pluralize("type", dest.getType().size())+": "+types.toString()+")", IssueSeverity.ERROR));
} }
} }

View File

@ -282,11 +282,17 @@ public class ContextUtilities implements ProfileKnowledgeProvider {
} }
@Override @Override
public boolean isDatatype(String type) { public boolean isPrimitiveType(String type) {
StructureDefinition sd = context.fetchTypeDefinition(type); StructureDefinition sd = context.fetchTypeDefinition(type);
return sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE; return sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE;
} }
@Override
public boolean isDatatype(String type) {
StructureDefinition sd = context.fetchTypeDefinition(type);
return sd != null && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE || sd.getKind() == StructureDefinitionKind.COMPLEXTYPE) && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION;
}
@Override @Override
public boolean isResource(String t) { public boolean isResource(String t) {
StructureDefinition sd; StructureDefinition sd;

View File

@ -59,6 +59,10 @@ public class NarrativeGenerationTests {
public boolean isDatatype(String typeSimple) { public boolean isDatatype(String typeSimple) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override
public boolean isPrimitiveType(String typeSimple) {
throw new NotImplementedException();
}
@Override @Override
public boolean isResource(String typeSimple) { public boolean isResource(String typeSimple) {

View File

@ -215,6 +215,13 @@ public class SnapShotGenerationTests {
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE || sd.getKind() == StructureDefinitionKind.COMPLEXTYPE); return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE || sd.getKind() == StructureDefinitionKind.COMPLEXTYPE);
} }
@Override
public boolean isPrimitiveType(String name) {
StructureDefinition sd = TestingUtilities.getSharedWorkerContext().fetchTypeDefinition(name);
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE);
}
@Override @Override
public boolean isResource(String typeSimple) { public boolean isResource(String typeSimple) {
StructureDefinition sd = TestingUtilities.getSharedWorkerContext().fetchTypeDefinition(typeSimple); StructureDefinition sd = TestingUtilities.getSharedWorkerContext().fetchTypeDefinition(typeSimple);

View File

@ -207,6 +207,13 @@ public class SnapShotGenerationXTests {
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE || sd.getKind() == StructureDefinitionKind.COMPLEXTYPE); return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE || sd.getKind() == StructureDefinitionKind.COMPLEXTYPE);
} }
@Override
public boolean isPrimitiveType(String name) {
StructureDefinition sd = TestingUtilities.getSharedWorkerContext().fetchTypeDefinition(name);
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE);
}
@Override @Override
public boolean isResource(String typeSimple) { public boolean isResource(String typeSimple) {
StructureDefinition sd = UtilitiesXTests.context(version).fetchTypeDefinition(typeSimple); StructureDefinition sd = UtilitiesXTests.context(version).fetchTypeDefinition(typeSimple);