Merge pull request #215 from hapifhir/gg-work

R2B fixes
This commit is contained in:
Grahame Grieve 2020-06-03 21:40:28 +10:00 committed by GitHub
commit 903eabdfc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 95 additions and 43 deletions

View File

@ -1482,6 +1482,8 @@ public class VersionConvertor_14_50 {
tgt.setBase(convertElementDefinitionBaseComponent(src.getBase())); tgt.setBase(convertElementDefinitionBaseComponent(src.getBase()));
if (src.hasContentReference()) if (src.hasContentReference())
tgt.setContentReferenceElement(convertUri(src.getContentReferenceElement())); tgt.setContentReferenceElement(convertUri(src.getContentReferenceElement()));
// work around for problem in R2B definitions:
if (!src.hasContentReference()) {
for (org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent t : src.getType()) convertTypeRefComponent(t, tgt.getType()); for (org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent t : src.getType()) convertTypeRefComponent(t, tgt.getType());
if (src.hasDefaultValue()) if (src.hasDefaultValue())
tgt.setDefaultValue(convertType(src.getDefaultValue())); tgt.setDefaultValue(convertType(src.getDefaultValue()));
@ -1516,6 +1518,7 @@ public class VersionConvertor_14_50 {
if (src.hasBinding()) if (src.hasBinding())
tgt.setBinding(convertElementDefinitionBindingComponent(src.getBinding())); tgt.setBinding(convertElementDefinitionBindingComponent(src.getBinding()));
for (org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionMappingComponent t : src.getMapping()) tgt.addMapping(convertElementDefinitionMappingComponent(t)); for (org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionMappingComponent t : src.getMapping()) tgt.addMapping(convertElementDefinitionMappingComponent(t));
}
return tgt; return tgt;
} }

View File

@ -134,7 +134,7 @@ public class ValueSetCheckerSimple implements ValueSetChecker {
cs = findSpecialCodeSystem(system); cs = findSpecialCodeSystem(system);
} }
if (cs == null) { if (cs == null) {
warningMessage = "Unable to resolve system "+system+" - system is not specified or implicit"; warningMessage = "Unable to resolve system "+system;
if (!inExpansion) if (!inExpansion)
throw new FHIRException(warningMessage); throw new FHIRException(warningMessage);
} }
@ -144,8 +144,12 @@ public class ValueSetCheckerSimple implements ValueSetChecker {
throw new FHIRException(warningMessage); throw new FHIRException(warningMessage);
} }
if (cs!=null) if (cs!=null) {
res = validateCode(code, cs); res = validateCode(code, cs);
} else {
// it's in the expansion, but we could find it in a code system
res = findCodeInExpansion(code);
}
} else { } else {
inExpansion = checkExpansion(code); inExpansion = checkExpansion(code);
} }
@ -175,13 +179,38 @@ public class ValueSetCheckerSimple implements ValueSetChecker {
return null; return null;
} }
boolean checkExpansion(Coding code) { private ValidationResult findCodeInExpansion(Coding code) {
if (valueset==null || !valueset.hasExpansion())
return null;
return findCodeInExpansion(code, valueset.getExpansion().getContains());
}
private ValidationResult findCodeInExpansion(Coding code, List<ValueSetExpansionContainsComponent> contains) {
for (ValueSetExpansionContainsComponent containsComponent: contains) {
if (containsComponent.getSystem().equals(code.getSystem()) && containsComponent.getCode().equals(code.getCode())) {
ConceptDefinitionComponent ccd = new ConceptDefinitionComponent();
ccd.setCode(containsComponent.getCode());
ccd.setDisplay(containsComponent.getDisplay());
ValidationResult res = new ValidationResult(ccd);
return res;
}
if (containsComponent.hasContains()) {
ValidationResult res = findCodeInExpansion(code, containsComponent.getContains());
if (res != null) {
return res;
}
}
}
return null;
}
private boolean checkExpansion(Coding code) {
if (valueset==null || !valueset.hasExpansion()) if (valueset==null || !valueset.hasExpansion())
return false; return false;
return checkExpansion(code, valueset.getExpansion().getContains()); return checkExpansion(code, valueset.getExpansion().getContains());
} }
boolean checkExpansion(Coding code, List<ValueSetExpansionContainsComponent> contains) { private boolean checkExpansion(Coding code, List<ValueSetExpansionContainsComponent> contains) {
for (ValueSetExpansionContainsComponent containsComponent: contains) { for (ValueSetExpansionContainsComponent containsComponent: contains) {
if (containsComponent.getSystem().equals(code.getSystem()) && containsComponent.getCode().equals(code.getCode())) if (containsComponent.getSystem().equals(code.getSystem()) && containsComponent.getCode().equals(code.getCode()))
return true; return true;

View File

@ -30,6 +30,8 @@ public class XVerExtensionManager {
BadVersion, Unknown, Invalid, Valid BadVersion, Unknown, Invalid, Valid
} }
public static final String XVER_EXT_MARKER = "XVER_EXT_MARKER";
private Map<String, JsonObject> lists = new HashMap<>(); private Map<String, JsonObject> lists = new HashMap<>();
private IWorkerContext context; private IWorkerContext context;
@ -81,6 +83,7 @@ public class XVerExtensionManager {
JsonObject path = root.getAsJsonObject(e); JsonObject path = root.getAsJsonObject(e);
StructureDefinition sd = new StructureDefinition(); StructureDefinition sd = new StructureDefinition();
sd.setUserData(XVER_EXT_MARKER, "true");
sd.setUrl(url); sd.setUrl(url);
sd.setVersion(context.getVersion()); sd.setVersion(context.getVersion());
sd.setFhirVersion(FHIRVersion.fromCode(context.getVersion())); sd.setFhirVersion(FHIRVersion.fromCode(context.getVersion()));

View File

@ -26,6 +26,7 @@ public class I18nConstants {
public final static String CODESYSTEM_CS_VS_MISMATCH = "CodeSystem_CS_VS_MisMatch"; public final static String CODESYSTEM_CS_VS_MISMATCH = "CodeSystem_CS_VS_MisMatch";
public final static String CODESYSTEM_CS_VS_WRONGSYSTEM = "CodeSystem_CS_VS_WrongSystem"; public final static String CODESYSTEM_CS_VS_WRONGSYSTEM = "CodeSystem_CS_VS_WrongSystem";
public final static String EXTENSION_EXT_CONTEXT_WRONG = "Extension_EXT_Context_Wrong"; public final static String EXTENSION_EXT_CONTEXT_WRONG = "Extension_EXT_Context_Wrong";
public final static String EXTENSION_EXT_CONTEXT_WRONG_XVER = "EXTENSION_EXT_CONTEXT_WRONG_XVER";
public final static String EXTENSION_EXT_COUNT_MISMATCH = "Extension_EXT_Count_Mismatch"; public final static String EXTENSION_EXT_COUNT_MISMATCH = "Extension_EXT_Count_Mismatch";
public final static String EXTENSION_EXT_COUNT_NOTFOUND = "Extension_EXT_Count_NotFound"; public final static String EXTENSION_EXT_COUNT_NOTFOUND = "Extension_EXT_Count_NotFound";
public final static String EXTENSION_EXT_FIXED_BANNED = "Extension_EXT_Fixed_Banned"; public final static String EXTENSION_EXT_FIXED_BANNED = "Extension_EXT_Fixed_Banned";

View File

@ -498,3 +498,4 @@ TYPE_SPECIFIC_CHECKS_DT_DECIMAL_CHARS = Found {0} decimal places which exceeds t
Validation_VAL_Profile_WrongType = Specified profile type was "{0}", but found type "{1}" Validation_VAL_Profile_WrongType = Specified profile type was "{0}", but found type "{1}"
Validation_VAL_Profile_WrongType2 = Type mismatch processing profile {0} at path {1}: The element type is {4}, but the profile {3} is for a different type {2} Validation_VAL_Profile_WrongType2 = Type mismatch processing profile {0} at path {1}: The element type is {4}, but the profile {3} is for a different type {2}
VALIDATION_VAL_ILLEGAL_TYPE_CONSTRAINT = Illegal constraint in profile {0} at path {1} - cannot constrain to type {2} from base types {3} VALIDATION_VAL_ILLEGAL_TYPE_CONSTRAINT = Illegal constraint in profile {0} at path {1} - cannot constrain to type {2} from base types {3}
EXTENSION_EXT_CONTEXT_WRONG_XVER = The extension {0} from FHIR version {3} is not allowed to be used at this point (allowed = {1}; this element is [{2}; this is a warning since contexts may be renamed between FHIR versions)

View File

@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
public class PackageCacheTests { public class PackageCacheTests {
@ -17,7 +18,11 @@ public class PackageCacheTests {
public void testPath() throws IOException { public void testPath() throws IOException {
PackageCacheManager cache = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); PackageCacheManager cache = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
cache.clear(); cache.clear();
Assertions.assertTrue(cache.listPackages().isEmpty()); List<String> list = cache.listPackages();
if (!list.isEmpty()) {
System.out.println("remaining packages: "+list.toString());
}
Assertions.assertTrue(list.isEmpty());
NpmPackage npm = cache.loadPackage("hl7.fhir.pubpack", "0.0.3"); NpmPackage npm = cache.loadPackage("hl7.fhir.pubpack", "0.0.3");
npm.loadAllFiles(); npm.loadAllFiles();
Assertions.assertNotNull(npm); Assertions.assertNotNull(npm);
@ -30,6 +35,7 @@ public class PackageCacheTests {
npm.save(dir); npm.save(dir);
NpmPackage npm2 = cache.loadPackage("hl7.fhir.pubpack", "file:" + dir.getAbsolutePath()); NpmPackage npm2 = cache.loadPackage("hl7.fhir.pubpack", "file:" + dir.getAbsolutePath());
Assertions.assertNotNull(npm2); Assertions.assertNotNull(npm2);
Assertions.assertFalse(cache.listPackages().isEmpty()); list = cache.listPackages();
Assertions.assertFalse(list.isEmpty());
} }
} }

View File

@ -1567,17 +1567,26 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
} }
} }
if (!ok) { if (!ok) {
if (definition.hasUserData(XVerExtensionManager.XVER_EXT_MARKER)) {
warning(errors, IssueType.STRUCTURE, container.line(), container.col(), stack.getLiteralPath(), false, I18nConstants.EXTENSION_EXT_CONTEXT_WRONG_XVER, extUrl, contexts.toString(), plist.toString());
} else {
rule(errors, IssueType.STRUCTURE, container.line(), container.col(), stack.getLiteralPath(), false, I18nConstants.EXTENSION_EXT_CONTEXT_WRONG, extUrl, contexts.toString(), plist.toString()); rule(errors, IssueType.STRUCTURE, container.line(), container.col(), stack.getLiteralPath(), false, I18nConstants.EXTENSION_EXT_CONTEXT_WRONG, extUrl, contexts.toString(), plist.toString());
}
return false; return false;
} else { } else {
if (definition.hasContextInvariant()) { if (definition.hasContextInvariant()) {
for (StringType s : definition.getContextInvariant()) { for (StringType s : definition.getContextInvariant()) {
if (!fpe.evaluateToBoolean(hostContext, resource, hostContext.getRootResource(), container, fpe.parse(s.getValue()))) { if (!fpe.evaluateToBoolean(hostContext, resource, hostContext.getRootResource(), container, fpe.parse(s.getValue()))) {
if (definition.hasUserData(XVerExtensionManager.XVER_EXT_MARKER)) {
warning(errors, IssueType.STRUCTURE, container.line(), container.col(), stack.getLiteralPath(), false, I18nConstants.PROFILE_EXT_NOT_HERE, extUrl, s.getValue());
return true;
} else {
rule(errors, IssueType.STRUCTURE, container.line(), container.col(), stack.getLiteralPath(), false, I18nConstants.PROFILE_EXT_NOT_HERE, extUrl, s.getValue()); rule(errors, IssueType.STRUCTURE, container.line(), container.col(), stack.getLiteralPath(), false, I18nConstants.PROFILE_EXT_NOT_HERE, extUrl, s.getValue());
return false; return false;
} }
} }
} }
}
return true; return true;
} }
} }