Refactor `CommonCodeSystemTerminologyService` method `validateCode` (#5631)
* Refactored CommonCodeSystemTerminologyService validateCode method and added more tests
This commit is contained in:
parent
250bc7b031
commit
cbd733c340
|
@ -1,6 +1,10 @@
|
||||||
|
|
||||||
org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport.displayMismatch=Concept Display "{0}" does not match expected "{1}"
|
org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport.displayMismatch=Concept Display "{0}" does not match expected "{1}"
|
||||||
|
|
||||||
|
org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.unknownCodeInSystem=Unknown code "{0}#{1}"
|
||||||
|
org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.invalidCodeInSystem=Code {0} is not valid for system: {1}
|
||||||
|
org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.mismatchCodeSystem=Inappropriate CodeSystem URL "{0}" for ValueSet: {1}
|
||||||
|
org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.codeNotFoundInValueSet=Code "{0}" is not in valueset: {1}
|
||||||
|
|
||||||
ca.uhn.fhir.jpa.term.TermReadSvcImpl.expansionRefersToUnknownCs=Unknown CodeSystem URI "{0}" referenced from ValueSet
|
ca.uhn.fhir.jpa.term.TermReadSvcImpl.expansionRefersToUnknownCs=Unknown CodeSystem URI "{0}" referenced from ValueSet
|
||||||
ca.uhn.fhir.jpa.term.TermReadSvcImpl.valueSetNotYetExpanded=ValueSet "{0}" has not yet been pre-expanded. Performing in-memory expansion without parameters. Current status: {1} | {2}
|
ca.uhn.fhir.jpa.term.TermReadSvcImpl.valueSetNotYetExpanded=ValueSet "{0}" has not yet been pre-expanded. Performing in-memory expansion without parameters. Current status: {1} | {2}
|
||||||
|
|
|
@ -20,9 +20,9 @@ import java.util.stream.Collectors;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class NpmSearchR4Test extends BaseJpaR4Test {
|
public class JpaPackageCacheSearchR4Test extends BaseJpaR4Test {
|
||||||
|
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(NpmSearchR4Test.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(JpaPackageCacheSearchR4Test.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
public IPackageInstallerSvc igInstaller;
|
public IPackageInstallerSvc igInstaller;
|
||||||
@Autowired
|
@Autowired
|
|
@ -24,15 +24,11 @@ import ca.uhn.fhir.rest.param.UriParam;
|
||||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.partition.RequestTenantPartitionInterceptor;
|
import ca.uhn.fhir.rest.server.interceptor.partition.RequestTenantPartitionInterceptor;
|
||||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||||
import ca.uhn.fhir.test.utilities.JettyUtil;
|
|
||||||
import ca.uhn.fhir.test.utilities.ProxyUtil;
|
import ca.uhn.fhir.test.utilities.ProxyUtil;
|
||||||
import ca.uhn.fhir.test.utilities.server.HttpServletExtension;
|
import ca.uhn.fhir.test.utilities.server.HttpServletExtension;
|
||||||
import ca.uhn.fhir.util.ClasspathUtil;
|
import ca.uhn.fhir.util.ClasspathUtil;
|
||||||
import ca.uhn.fhir.util.JsonUtil;
|
import ca.uhn.fhir.util.JsonUtil;
|
||||||
import ca.uhn.fhir.validation.ValidationResult;
|
import ca.uhn.fhir.validation.ValidationResult;
|
||||||
import org.eclipse.jetty.server.Server;
|
|
||||||
import org.eclipse.jetty.ee10.servlet.ServletHandler;
|
|
||||||
import org.eclipse.jetty.ee10.servlet.ServletHolder;
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.hl7.fhir.r4.model.Enumerations;
|
import org.hl7.fhir.r4.model.Enumerations;
|
||||||
|
@ -82,9 +78,9 @@ import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@TestMethodOrder(MethodOrderer.MethodName.class)
|
@TestMethodOrder(MethodOrderer.MethodName.class)
|
||||||
public class NpmR4Test extends BaseJpaR4Test {
|
public class PackageInstallerSvcR4Test extends BaseJpaR4Test {
|
||||||
|
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(NpmR4Test.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(PackageInstallerSvcR4Test.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("myImplementationGuideDaoR4")
|
@Qualifier("myImplementationGuideDaoR4")
|
||||||
protected IFhirResourceDao<ImplementationGuide> myImplementationGuideDao;
|
protected IFhirResourceDao<ImplementationGuide> myImplementationGuideDao;
|
|
@ -17,7 +17,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import jakarta.annotation.Nonnull;
|
import jakarta.annotation.Nonnull;
|
||||||
import jakarta.annotation.Nullable;
|
import jakarta.annotation.Nullable;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.Validate;
|
|
||||||
import org.fhir.ucum.UcumEssenceService;
|
import org.fhir.ucum.UcumEssenceService;
|
||||||
import org.fhir.ucum.UcumException;
|
import org.fhir.ucum.UcumException;
|
||||||
import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40;
|
import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40;
|
||||||
|
@ -30,16 +29,18 @@ import org.hl7.fhir.dstu2.model.ValueSet;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.r4.model.CodeSystem;
|
import org.hl7.fhir.r4.model.CodeSystem;
|
||||||
import org.hl7.fhir.r5.model.Resource;
|
import org.hl7.fhir.r5.model.Resource;
|
||||||
|
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
|
|
||||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||||
|
@ -65,8 +66,8 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
|
||||||
public static final String UCUM_CODESYSTEM_URL = "http://unitsofmeasure.org";
|
public static final String UCUM_CODESYSTEM_URL = "http://unitsofmeasure.org";
|
||||||
public static final String UCUM_VALUESET_URL = "http://hl7.org/fhir/ValueSet/ucum-units";
|
public static final String UCUM_VALUESET_URL = "http://hl7.org/fhir/ValueSet/ucum-units";
|
||||||
public static final String ALL_LANGUAGES_VALUESET_URL = "http://hl7.org/fhir/ValueSet/all-languages";
|
public static final String ALL_LANGUAGES_VALUESET_URL = "http://hl7.org/fhir/ValueSet/all-languages";
|
||||||
private static final String USPS_CODESYSTEM_URL = "https://www.usps.com/";
|
public static final String USPS_CODESYSTEM_URL = "https://www.usps.com/";
|
||||||
private static final String USPS_VALUESET_URL = "http://hl7.org/fhir/us/core/ValueSet/us-core-usps-state";
|
public static final String USPS_VALUESET_URL = "http://hl7.org/fhir/us/core/ValueSet/us-core-usps-state";
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(CommonCodeSystemsTerminologyService.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(CommonCodeSystemsTerminologyService.class);
|
||||||
private static final Map<String, String> USPS_CODES = Collections.unmodifiableMap(buildUspsCodes());
|
private static final Map<String, String> USPS_CODES = Collections.unmodifiableMap(buildUspsCodes());
|
||||||
private static final Map<String, String> ISO_4217_CODES = Collections.unmodifiableMap(buildIso4217Codes());
|
private static final Map<String, String> ISO_4217_CODES = Collections.unmodifiableMap(buildIso4217Codes());
|
||||||
|
@ -81,8 +82,7 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public CommonCodeSystemsTerminologyService(FhirContext theFhirContext) {
|
public CommonCodeSystemsTerminologyService(FhirContext theFhirContext) {
|
||||||
Validate.notNull(theFhirContext);
|
Objects.requireNonNull(theFhirContext);
|
||||||
|
|
||||||
myFhirContext = theFhirContext;
|
myFhirContext = theFhirContext;
|
||||||
myVersionCanonicalizer = new VersionCanonicalizer(theFhirContext);
|
myVersionCanonicalizer = new VersionCanonicalizer(theFhirContext);
|
||||||
}
|
}
|
||||||
|
@ -108,136 +108,109 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
|
||||||
public CodeValidationResult validateCode(
|
public CodeValidationResult validateCode(
|
||||||
@Nonnull ValidationSupportContext theValidationSupportContext,
|
@Nonnull ValidationSupportContext theValidationSupportContext,
|
||||||
@Nonnull ConceptValidationOptions theOptions,
|
@Nonnull ConceptValidationOptions theOptions,
|
||||||
String theCodeSystem,
|
final String theCodeSystem,
|
||||||
String theCode,
|
final String theCode,
|
||||||
String theDisplay,
|
final String theDisplay,
|
||||||
String theValueSetUrl) {
|
final String theValueSetUrl) {
|
||||||
/* **************************************************************************************
|
/* **************************************************************************************
|
||||||
* NOTE: Update validation_support_modules.html if any of the support in this module
|
* NOTE: Update validation_support_modules.md if any of the support in this module
|
||||||
* changes in any way!
|
* changes in any way!
|
||||||
* **************************************************************************************/
|
* **************************************************************************************/
|
||||||
|
|
||||||
Map<String, String> handlerMap = null;
|
String valueSet = defaultString(theValueSetUrl);
|
||||||
String expectSystem = null;
|
String system = defaultString(theCodeSystem);
|
||||||
switch (defaultString(theValueSetUrl)) {
|
|
||||||
case USPS_VALUESET_URL:
|
|
||||||
handlerMap = USPS_CODES;
|
|
||||||
expectSystem = USPS_CODESYSTEM_URL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CURRENCIES_VALUESET_URL:
|
if (!isBlank(valueSet)) {
|
||||||
handlerMap = ISO_4217_CODES;
|
final String expectSystem = getCodeSystemForValueSet(valueSet);
|
||||||
expectSystem = CURRENCIES_CODESYSTEM_URL;
|
if (!isBlank(system) && !system.equals(expectSystem)) {
|
||||||
break;
|
return getValidateCodeResultInError("mismatchCodeSystem", system, valueSet);
|
||||||
|
|
||||||
case LANGUAGES_VALUESET_URL:
|
|
||||||
expectSystem = LANGUAGES_CODESYSTEM_URL;
|
|
||||||
if (!expectSystem.equals(theCodeSystem) && !(theCodeSystem == null && theOptions.isInferSystem())) {
|
|
||||||
return new CodeValidationResult()
|
|
||||||
.setSeverity(IssueSeverity.ERROR)
|
|
||||||
.setMessage("Inappropriate CodeSystem URL \"" + theCodeSystem + "\" for ValueSet: "
|
|
||||||
+ theValueSetUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IBaseResource languagesVs = myLanguagesVs;
|
|
||||||
if (languagesVs == null) {
|
|
||||||
languagesVs = theValidationSupportContext
|
|
||||||
.getRootValidationSupport()
|
|
||||||
.fetchValueSet("http://hl7.org/fhir/ValueSet/languages");
|
|
||||||
myLanguagesVs = myVersionCanonicalizer.valueSetToValidatorCanonical(languagesVs);
|
|
||||||
}
|
|
||||||
Optional<org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent> match =
|
|
||||||
myLanguagesVs.getCompose().getInclude().stream()
|
|
||||||
.flatMap(t -> t.getConcept().stream())
|
|
||||||
.filter(t -> theCode.equals(t.getCode()))
|
|
||||||
.findFirst();
|
|
||||||
if (match.isPresent()) {
|
|
||||||
return new CodeValidationResult()
|
|
||||||
.setCode(theCode)
|
|
||||||
.setDisplay(match.get().getDisplay());
|
|
||||||
} else {
|
|
||||||
return new CodeValidationResult()
|
|
||||||
.setSeverity(IssueSeverity.ERROR)
|
|
||||||
.setMessage("Code \"" + theCode + "\" is not in valueset: " + theValueSetUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
case ALL_LANGUAGES_VALUESET_URL:
|
|
||||||
expectSystem = LANGUAGES_CODESYSTEM_URL;
|
|
||||||
if (!expectSystem.equals(theCodeSystem) && !(theCodeSystem == null && theOptions.isInferSystem())) {
|
|
||||||
return new CodeValidationResult()
|
|
||||||
.setSeverity(IssueSeverity.ERROR)
|
|
||||||
.setMessage("Inappropriate CodeSystem URL \"" + theCodeSystem + "\" for ValueSet: "
|
|
||||||
+ theValueSetUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
LookupCodeResult outcome = lookupLanguageCode(theCode);
|
|
||||||
if (outcome.isFound()) {
|
|
||||||
return new CodeValidationResult().setCode(theCode).setDisplay(outcome.getCodeDisplay());
|
|
||||||
} else {
|
|
||||||
return new CodeValidationResult()
|
|
||||||
.setSeverity(IssueSeverity.ERROR)
|
|
||||||
.setMessage("Code \"" + theCode + "\" is not in valueset: " + theValueSetUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
case MIMETYPES_VALUESET_URL:
|
|
||||||
// This is a pretty naive implementation - Should be enhanced in future
|
|
||||||
return new CodeValidationResult().setCode(theCode).setDisplay(theDisplay);
|
|
||||||
|
|
||||||
case UCUM_VALUESET_URL: {
|
|
||||||
String system = theCodeSystem;
|
|
||||||
expectSystem = UCUM_CODESYSTEM_URL;
|
|
||||||
if (system == null && theOptions.isInferSystem()) {
|
|
||||||
system = expectSystem;
|
system = expectSystem;
|
||||||
}
|
}
|
||||||
CodeValidationResult validationResult =
|
|
||||||
validateLookupCode(theValidationSupportContext, theCode, system);
|
switch (valueSet) {
|
||||||
if (validationResult != null) {
|
case USPS_VALUESET_URL:
|
||||||
return validationResult;
|
return validateCodeUsingCodeMap(theCode, system, USPS_CODES);
|
||||||
}
|
case CURRENCIES_VALUESET_URL:
|
||||||
|
return validateCodeUsingCodeMap(theCode, system, ISO_4217_CODES);
|
||||||
|
case LANGUAGES_VALUESET_URL:
|
||||||
|
return validateLanguageCodeInValueSet(theValidationSupportContext, theCode);
|
||||||
|
case ALL_LANGUAGES_VALUESET_URL:
|
||||||
|
return validateLanguageCode(theCode, valueSet);
|
||||||
|
case MIMETYPES_VALUESET_URL:
|
||||||
|
// This is a pretty naive implementation - Should be enhanced in future
|
||||||
|
return getValidateCodeResultOk(theCode, theDisplay);
|
||||||
|
case UCUM_VALUESET_URL: {
|
||||||
|
return validateCodeUsingSystemLookup(theValidationSupportContext, theCode, system);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handlerMap != null) {
|
if (isBlank(valueSet)) {
|
||||||
String display = handlerMap.get(theCode);
|
return validateCodeUsingSystemLookup(theValidationSupportContext, theCode, system);
|
||||||
if (display != null) {
|
|
||||||
if (expectSystem.equals(theCodeSystem) || theOptions.isInferSystem()) {
|
|
||||||
return new CodeValidationResult().setCode(theCode).setDisplay(display);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String actualSystem = defaultIfBlank(theCodeSystem, expectSystem);
|
|
||||||
String unknownCodeMessage = myFhirContext
|
|
||||||
.getLocalizer()
|
|
||||||
.getMessage("ca.uhn.fhir.jpa.term.TermReadSvcImpl.unknownCodeInSystem", actualSystem, theCode);
|
|
||||||
return new CodeValidationResult().setSeverity(IssueSeverity.ERROR).setMessage(unknownCodeMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isBlank(theValueSetUrl)) {
|
|
||||||
return validateLookupCode(theValidationSupportContext, theCode, theCodeSystem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private static String getCodeSystemForValueSet(final String theValueSetUrl) {
|
||||||
public CodeValidationResult validateLookupCode(
|
String theCodeSystem = null;
|
||||||
ValidationSupportContext theValidationSupportContext, String theCode, String theSystem) {
|
switch (defaultString(theValueSetUrl)) {
|
||||||
LookupCodeResult lookupResult =
|
case USPS_VALUESET_URL:
|
||||||
lookupCode(theValidationSupportContext, new LookupCodeRequest(theSystem, theCode));
|
theCodeSystem = USPS_CODESYSTEM_URL;
|
||||||
CodeValidationResult validationResult = null;
|
break;
|
||||||
if (lookupResult != null) {
|
case CURRENCIES_VALUESET_URL:
|
||||||
if (lookupResult.isFound()) {
|
theCodeSystem = CURRENCIES_CODESYSTEM_URL;
|
||||||
validationResult = new CodeValidationResult()
|
break;
|
||||||
.setCode(lookupResult.getSearchedForCode())
|
case LANGUAGES_VALUESET_URL:
|
||||||
.setDisplay(lookupResult.getCodeDisplay());
|
case ALL_LANGUAGES_VALUESET_URL:
|
||||||
} else if (lookupResult.getErrorMessage() != null) {
|
theCodeSystem = LANGUAGES_CODESYSTEM_URL;
|
||||||
validationResult = new CodeValidationResult()
|
break;
|
||||||
.setSeverity(IssueSeverity.ERROR)
|
case MIMETYPES_VALUESET_URL:
|
||||||
.setMessage(lookupResult.getErrorMessage());
|
theCodeSystem = MIMETYPES_CODESYSTEM_URL;
|
||||||
|
break;
|
||||||
|
case UCUM_VALUESET_URL:
|
||||||
|
theCodeSystem = UCUM_CODESYSTEM_URL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return theCodeSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CodeValidationResult getValidateCodeResultInError(
|
||||||
|
final String errorCode, final String theFirstParam, final String theSecondParam) {
|
||||||
|
String message = getErrorMessage(errorCode, theFirstParam, theSecondParam);
|
||||||
|
return getValidateCodeResultError(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CodeValidationResult getValidateCodeResultOk(final String theCode, final String theDisplay) {
|
||||||
|
return new CodeValidationResult().setCode(theCode).setDisplay(theDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CodeValidationResult getValidateCodeResultError(final String theMessage) {
|
||||||
|
return new CodeValidationResult().setSeverity(IssueSeverity.ERROR).setMessage(theMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CodeValidationResult validateCodeUsingCodeMap(
|
||||||
|
final String theCode, final String theSystem, final Map<String, String> theCodeMap) {
|
||||||
|
if (theCodeMap.containsKey(theCode)) {
|
||||||
|
return getValidateCodeResultOk(theCode, theCodeMap.get(theCode));
|
||||||
|
} else {
|
||||||
|
return getValidateCodeResultInError("unknownCodeInSystem", theSystem, theCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return validationResult;
|
@Nullable
|
||||||
|
public CodeValidationResult validateCodeUsingSystemLookup(
|
||||||
|
final ValidationSupportContext theValidationSupportContext, final String theCode, final String theSystem) {
|
||||||
|
LookupCodeResult result = lookupCode(theValidationSupportContext, new LookupCodeRequest(theSystem, theCode));
|
||||||
|
if (result == null) {
|
||||||
|
return getValidateCodeResultInError("unknownCodeInSystem", theSystem, theCode);
|
||||||
|
}
|
||||||
|
if (result.isFound()) {
|
||||||
|
return getValidateCodeResultOk(theCode, result.getCodeDisplay());
|
||||||
|
} else if (result.getErrorMessage() != null) {
|
||||||
|
return getValidateCodeResultError(result.getErrorMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -267,23 +240,50 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String display = map.get(code);
|
|
||||||
if (isNotBlank(display)) {
|
|
||||||
LookupCodeResult retVal = new LookupCodeResult();
|
LookupCodeResult retVal = new LookupCodeResult();
|
||||||
retVal.setSearchedForCode(code);
|
retVal.setSearchedForCode(code);
|
||||||
retVal.setSearchedForSystem(system);
|
retVal.setSearchedForSystem(system);
|
||||||
|
|
||||||
|
String display = map.get(code);
|
||||||
|
if (isNotBlank(display)) {
|
||||||
retVal.setFound(true);
|
retVal.setFound(true);
|
||||||
retVal.setCodeDisplay(display);
|
retVal.setCodeDisplay(display);
|
||||||
|
} else {
|
||||||
|
// If we get here it means we know the CodeSystem but the code was bad
|
||||||
|
retVal.setFound(false);
|
||||||
|
String invalidCodeMessage = getErrorMessage("invalidCodeInSystem", code, system);
|
||||||
|
retVal.setErrorMessage(invalidCodeMessage);
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here it means we know the codesystem but the code was bad
|
private CodeValidationResult validateLanguageCode(final String theCode, final String theValueSetUrl) {
|
||||||
LookupCodeResult retVal = new LookupCodeResult();
|
LookupCodeResult outcome = lookupLanguageCode(theCode);
|
||||||
retVal.setSearchedForCode(code);
|
if (outcome.isFound()) {
|
||||||
retVal.setSearchedForSystem(system);
|
return getValidateCodeResultOk(theCode, outcome.getCodeDisplay());
|
||||||
retVal.setFound(false);
|
} else {
|
||||||
retVal.setErrorMessage("Code '" + code + "' is not valid for system: " + system);
|
return getValidateCodeResultInError("codeNotFoundInValueSet", theCode, theValueSetUrl);
|
||||||
return retVal;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CodeValidationResult validateLanguageCodeInValueSet(
|
||||||
|
final ValidationSupportContext theValidationSupportContext, final String theCode) {
|
||||||
|
final String valueSet = LANGUAGES_VALUESET_URL;
|
||||||
|
if (myLanguagesVs == null) {
|
||||||
|
IBaseResource languagesVs =
|
||||||
|
theValidationSupportContext.getRootValidationSupport().fetchValueSet(valueSet);
|
||||||
|
myLanguagesVs = myVersionCanonicalizer.valueSetToValidatorCanonical(languagesVs);
|
||||||
|
}
|
||||||
|
Optional<ConceptReferenceComponent> match = myLanguagesVs.getCompose().getInclude().stream()
|
||||||
|
.flatMap(t -> t.getConcept().stream())
|
||||||
|
.filter(t -> theCode.equals(t.getCode()))
|
||||||
|
.findFirst();
|
||||||
|
if (match.isPresent()) {
|
||||||
|
return getValidateCodeResultOk(theCode, match.get().getDisplay());
|
||||||
|
} else {
|
||||||
|
return getValidateCodeResultInError("codeNotFoundInValueSet", theCode, valueSet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LookupCodeResult lookupLanguageCode(String theCode) {
|
private LookupCodeResult lookupLanguageCode(String theCode) {
|
||||||
|
@ -291,61 +291,45 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
|
||||||
initializeBcp47LanguageMap();
|
initializeBcp47LanguageMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
int langRegionSeparatorIndex = StringUtils.indexOfAny(theCode, '-', '_');
|
final LookupCodeResult lookupCodeResult = new LookupCodeResult();
|
||||||
boolean hasRegionAndCodeSegments = langRegionSeparatorIndex > 0;
|
lookupCodeResult.setSearchedForSystem(LANGUAGES_CODESYSTEM_URL);
|
||||||
String language;
|
lookupCodeResult.setSearchedForCode(theCode);
|
||||||
String region;
|
|
||||||
|
final int langRegionSeparatorIndex = StringUtils.indexOfAny(theCode, '-', '_');
|
||||||
|
final boolean hasRegionAndCodeSegments = langRegionSeparatorIndex > 0;
|
||||||
|
|
||||||
|
final boolean found;
|
||||||
|
final String display;
|
||||||
|
|
||||||
if (hasRegionAndCodeSegments) {
|
if (hasRegionAndCodeSegments) {
|
||||||
// we look for languages in lowercase only
|
// we look for languages in lowercase only
|
||||||
// this will allow case insensitivity for language portion of code
|
// this will allow case insensitivity for language portion of code
|
||||||
language = myLanguagesLanugageMap.get(
|
String language = myLanguagesLanugageMap.get(
|
||||||
theCode.substring(0, langRegionSeparatorIndex).toLowerCase());
|
theCode.substring(0, langRegionSeparatorIndex).toLowerCase());
|
||||||
region = myLanguagesRegionMap.get(
|
String region = myLanguagesRegionMap.get(
|
||||||
theCode.substring(langRegionSeparatorIndex + 1).toUpperCase());
|
theCode.substring(langRegionSeparatorIndex + 1).toUpperCase());
|
||||||
|
|
||||||
if (language == null || region == null) {
|
|
||||||
// In case the user provides both a language and a region, they must both be valid for the lookup to
|
// In case the user provides both a language and a region, they must both be valid for the lookup to
|
||||||
// succeed.
|
// succeed.
|
||||||
|
found = language != null && region != null;
|
||||||
|
display = found ? language + " " + region : null;
|
||||||
|
if (!found) {
|
||||||
ourLog.warn("Couldn't find a valid bcp47 language-region combination from code: {}", theCode);
|
ourLog.warn("Couldn't find a valid bcp47 language-region combination from code: {}", theCode);
|
||||||
return buildNotFoundLookupCodeResult(theCode);
|
|
||||||
} else {
|
|
||||||
return buildLookupResultForLanguageAndRegion(theCode, language, region);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// In case user has only provided a language, we build the lookup from only that.
|
// In case user has only provided a language, we build the lookup from only that.
|
||||||
// NB: we only use the lowercase version of the language
|
// NB: we only use the lowercase version of the language
|
||||||
language = myLanguagesLanugageMap.get(theCode.toLowerCase());
|
String language = myLanguagesLanugageMap.get(theCode.toLowerCase());
|
||||||
if (language == null) {
|
found = language != null;
|
||||||
|
display = language;
|
||||||
|
if (!found) {
|
||||||
ourLog.warn("Couldn't find a valid bcp47 language from code: {}", theCode);
|
ourLog.warn("Couldn't find a valid bcp47 language from code: {}", theCode);
|
||||||
return buildNotFoundLookupCodeResult(theCode);
|
|
||||||
} else {
|
|
||||||
return buildLookupResultForLanguage(theCode, language);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LookupCodeResult buildLookupResultForLanguageAndRegion(
|
lookupCodeResult.setFound(found);
|
||||||
@Nonnull String theOriginalCode, @Nonnull String theLanguage, @Nonnull String theRegion) {
|
lookupCodeResult.setCodeDisplay(display);
|
||||||
LookupCodeResult lookupCodeResult = buildNotFoundLookupCodeResult(theOriginalCode);
|
|
||||||
lookupCodeResult.setCodeDisplay(theLanguage + " " + theRegion);
|
|
||||||
lookupCodeResult.setFound(true);
|
|
||||||
return lookupCodeResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LookupCodeResult buildLookupResultForLanguage(
|
|
||||||
@Nonnull String theOriginalCode, @Nonnull String theLanguage) {
|
|
||||||
LookupCodeResult lookupCodeResult = buildNotFoundLookupCodeResult(theOriginalCode);
|
|
||||||
lookupCodeResult.setCodeDisplay(theLanguage);
|
|
||||||
lookupCodeResult.setFound(true);
|
|
||||||
return lookupCodeResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LookupCodeResult buildNotFoundLookupCodeResult(@Nonnull String theOriginalCode) {
|
|
||||||
LookupCodeResult lookupCodeResult = new LookupCodeResult();
|
|
||||||
lookupCodeResult.setFound(false);
|
|
||||||
lookupCodeResult.setSearchedForSystem(LANGUAGES_CODESYSTEM_URL);
|
|
||||||
lookupCodeResult.setSearchedForCode(theOriginalCode);
|
|
||||||
return lookupCodeResult;
|
return lookupCodeResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,24 +388,20 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private LookupCodeResult lookupUcumCode(String theCode) {
|
private LookupCodeResult lookupUcumCode(String theCode) {
|
||||||
InputStream input = ClasspathUtil.loadResourceAsStream("/ucum-essence.xml");
|
|
||||||
String outcome;
|
|
||||||
LookupCodeResult retVal = new LookupCodeResult();
|
LookupCodeResult retVal = new LookupCodeResult();
|
||||||
retVal.setSearchedForCode(theCode);
|
retVal.setSearchedForCode(theCode);
|
||||||
retVal.setSearchedForSystem(UCUM_CODESYSTEM_URL);
|
retVal.setSearchedForSystem(UCUM_CODESYSTEM_URL);
|
||||||
|
|
||||||
try {
|
try (InputStream input = ClasspathUtil.loadResourceAsStream("/ucum-essence.xml")) {
|
||||||
UcumEssenceService svc = new UcumEssenceService(input);
|
UcumEssenceService svc = new UcumEssenceService(input);
|
||||||
outcome = svc.analyse(theCode);
|
String outcome = svc.analyse(theCode);
|
||||||
if (outcome != null) {
|
if (outcome != null) {
|
||||||
retVal.setFound(true);
|
retVal.setFound(true);
|
||||||
retVal.setCodeDisplay(outcome);
|
retVal.setCodeDisplay(outcome);
|
||||||
}
|
}
|
||||||
} catch (UcumException e) {
|
} catch (UcumException | IOException e) {
|
||||||
ourLog.debug("Failed parse UCUM code: {}", theCode, e);
|
ourLog.debug("Failed parse UCUM code: {}", theCode, e);
|
||||||
retVal.setErrorMessage(e.getMessage());
|
retVal.setErrorMessage(e.getMessage());
|
||||||
} finally {
|
|
||||||
ClasspathUtil.close(input);
|
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
@ -470,7 +450,7 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Validate.notNull(normalized);
|
Objects.requireNonNull(normalized);
|
||||||
|
|
||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
@ -1373,4 +1353,8 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
|
||||||
codes.put("ZWE", "Zimbabwe");
|
codes.put("ZWE", "Zimbabwe");
|
||||||
return codes;
|
return codes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getErrorMessage(String errorCode, String theFirstParam, String theSecondParam) {
|
||||||
|
return myFhirContext.getLocalizer().getMessage(getClass(), errorCode, theFirstParam, theSecondParam);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,35 @@ package org.hl7.fhir.common.hapi.validation.support;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.context.support.ConceptValidationOptions;
|
import ca.uhn.fhir.context.support.ConceptValidationOptions;
|
||||||
import ca.uhn.fhir.context.support.IValidationSupport;
|
import ca.uhn.fhir.context.support.IValidationSupport.CodeValidationResult;
|
||||||
import ca.uhn.fhir.context.support.ValidationSupportContext;
|
import ca.uhn.fhir.context.support.IValidationSupport.IssueSeverity;
|
||||||
|
import ca.uhn.fhir.context.support.IValidationSupport.LookupCodeResult;
|
||||||
import ca.uhn.fhir.context.support.LookupCodeRequest;
|
import ca.uhn.fhir.context.support.LookupCodeRequest;
|
||||||
|
import ca.uhn.fhir.context.support.ValidationSupportContext;
|
||||||
import ca.uhn.fhir.fhirpath.BaseValidationTestWithInlineMocks;
|
import ca.uhn.fhir.fhirpath.BaseValidationTestWithInlineMocks;
|
||||||
import ca.uhn.fhir.i18n.Msg;
|
import ca.uhn.fhir.i18n.Msg;
|
||||||
|
import ca.uhn.fhir.rest.api.Constants;
|
||||||
|
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.r4.model.CodeSystem;
|
import org.hl7.fhir.r4.model.CodeSystem;
|
||||||
import org.hl7.fhir.r4.model.ValueSet;
|
import org.hl7.fhir.r4.model.ValueSet;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.CsvSource;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.ALL_LANGUAGES_VALUESET_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.CURRENCIES_CODESYSTEM_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.CURRENCIES_VALUESET_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.LANGUAGES_CODESYSTEM_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.LANGUAGES_VALUESET_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.MIMETYPES_CODESYSTEM_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.MIMETYPES_VALUESET_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.UCUM_CODESYSTEM_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.UCUM_VALUESET_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.USPS_CODESYSTEM_URL;
|
||||||
|
import static org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService.USPS_VALUESET_URL;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
@ -31,214 +49,356 @@ public class CommonCodeSystemsTerminologyServiceTest extends BaseValidationTestW
|
||||||
mySvc = new CommonCodeSystemsTerminologyService(myCtx);
|
mySvc = new CommonCodeSystemsTerminologyService(myCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testUcum_LookupCode_Good() {
|
@CsvSource({"Cel, (degree Celsius)", "kg/m2, (kilogram) / (meter ^ 2)"})
|
||||||
IValidationSupport.LookupCodeResult outcome = mySvc.lookupCode(newSupport(), new LookupCodeRequest("http://unitsofmeasure.org", "Cel"));
|
public void testLookupCode_withUnitsOfMeasureWithKnownCode_returnsFound(final String theCode, final String theDisplay) {
|
||||||
assert outcome != null;
|
final String system = UCUM_CODESYSTEM_URL;
|
||||||
assertTrue(outcome.isFound());
|
LookupCodeResult outcome = mySvc.lookupCode(newSupport(), new LookupCodeRequest(system, theCode));
|
||||||
|
lookupCodeResultOk(outcome, theCode, system, theDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUcum_LookupCode_Good2() {
|
public void testLookupCode_withUnitsOfMeasureWithUnknownCode_returnsNotFound() {
|
||||||
IValidationSupport.LookupCodeResult outcome = mySvc.lookupCode(newSupport(), new LookupCodeRequest("http://unitsofmeasure.org", "kg/m2"));
|
final String code = "someCode";
|
||||||
assert outcome != null;
|
LookupCodeResult outcome = mySvc.lookupCode(newSupport(), new LookupCodeRequest(UCUM_CODESYSTEM_URL, code));
|
||||||
assertTrue(outcome.isFound());
|
lookupCodeResultError(outcome, code, "Error processing unit '" + code +"': The unit '" + code + "' is unknown' at position 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUcum_LookupCode_Bad() {
|
public void testLookupCode_withUnknownSystem_returnsNull() {
|
||||||
IValidationSupport.LookupCodeResult outcome = mySvc.lookupCode(newSupport(), new LookupCodeRequest("http://unitsofmeasure.org", "AAAAA"));
|
LookupCodeResult outcome = mySvc.lookupCode(newSupport(), new LookupCodeRequest("http://foo", "someCode"));
|
||||||
assert outcome != null;
|
|
||||||
assertFalse(outcome.isFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUcum_LookupCode_UnknownSystem() {
|
|
||||||
IValidationSupport.LookupCodeResult outcome = mySvc.lookupCode(newSupport(), new LookupCodeRequest("http://foo", "AAAAA"));
|
|
||||||
assertNull(outcome);
|
assertNull(outcome);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void lookupCode_languageOnlyLookup_isCaseInsensitive() {
|
@CsvSource({"SGN, Sign languages", "sgn, Sign languages", "EN-US, English United States", "en-us, English United States"})
|
||||||
IValidationSupport.LookupCodeResult outcomeUpper = mySvc.lookupCode(newSupport(), new LookupCodeRequest("urn:ietf:bcp:47", "SGN", "Sign Languages", null));
|
public void testLookupCode_withLanguageOnlyWithKnownCode_returnsFound(final String theCode, final String theDisplay) {
|
||||||
IValidationSupport.LookupCodeResult outcomeLower = mySvc.lookupCode(newSupport(), new LookupCodeRequest("urn:ietf:bcp:47", "sgn", "Sign Languages", null));
|
final String system = LANGUAGES_CODESYSTEM_URL;
|
||||||
assertNotNull(outcomeUpper);
|
LookupCodeResult outcome = mySvc.lookupCode(newSupport(), new LookupCodeRequest(system, theCode, null, null));
|
||||||
assertNotNull(outcomeLower);
|
lookupCodeResultOk(outcome, theCode, system, theDisplay);
|
||||||
assertTrue(outcomeLower.isFound());
|
|
||||||
assertTrue(outcomeUpper.isFound());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lookupCode_languageAndRegionLookup_isCaseInsensitive() {
|
public void testValidateCode_withUnitsOfMeasureWithKnownCode_returnsValid() {
|
||||||
IValidationSupport.LookupCodeResult outcomeUpper = mySvc.lookupCode(newSupport(), new LookupCodeRequest("urn:ietf:bcp:47", "EN-US", "English", null));
|
final String code = "mg";
|
||||||
IValidationSupport.LookupCodeResult outcomeLower = mySvc.lookupCode(newSupport(), new LookupCodeRequest("urn:ietf:bcp:47", "en-us", "English", null));
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), UCUM_CODESYSTEM_URL, code, null, UCUM_VALUESET_URL);
|
||||||
assertNotNull(outcomeUpper);
|
validateCodeResultOk(result, code, "(milligram)");
|
||||||
assertNotNull(outcomeLower);
|
|
||||||
assertTrue(outcomeLower.isFound());
|
|
||||||
assertTrue(outcomeUpper.isFound());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUcum_ValidateCode_Good() {
|
public void testValidateCodeInValueSet_withUnitsOfMeasureWithKnownCode_returnsValid() {
|
||||||
ValueSet vs = new ValueSet();
|
final ValueSet vs = new ValueSet().setUrl(UCUM_VALUESET_URL);
|
||||||
vs.setUrl("http://hl7.org/fhir/ValueSet/ucum-units");
|
final String code = "mg";
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateCodeInValueSet(newSupport(), newOptions(), "http://unitsofmeasure.org", "mg", null, vs);
|
CodeValidationResult result = mySvc.validateCodeInValueSet(newSupport(), newOptions(), UCUM_CODESYSTEM_URL, code, null, vs);
|
||||||
assert outcome != null;
|
validateCodeResultOk(result, code, "(milligram)");
|
||||||
assertTrue(outcome.isOk());
|
|
||||||
assertEquals("(milligram)", outcome.getDisplay());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUcum_ValidateCode_Good_SystemInferred() {
|
public void testValidateCodeInValueSet_withUnitsOfMeasureWithInferSystem_returnsValid() {
|
||||||
ValueSet vs = new ValueSet();
|
final ValueSet vs = new ValueSet().setUrl(UCUM_VALUESET_URL);
|
||||||
vs.setUrl("http://hl7.org/fhir/ValueSet/ucum-units");
|
final String code = "mg";
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateCodeInValueSet(newSupport(), newOptions().setInferSystem(true), null, "mg", null, vs);
|
CodeValidationResult result = mySvc.validateCodeInValueSet(newSupport(), newOptions().setInferSystem(true), null, code, null, vs);
|
||||||
assert outcome != null;
|
validateCodeResultOk(result, code, "(milligram)");
|
||||||
assertTrue(outcome.isOk());
|
|
||||||
assertEquals("(milligram)", outcome.getDisplay());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUcum_ValidateCode_Bad() {
|
public void testValidateCodeInValueSet_withUnitsOfMeasureWithUnknownCode_returnsInvalid() {
|
||||||
ValueSet vs = new ValueSet();
|
final String code = "FOO";
|
||||||
vs.setUrl("http://hl7.org/fhir/ValueSet/ucum-units");
|
final ValueSet vs = new ValueSet().setUrl(UCUM_VALUESET_URL);
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateCodeInValueSet(newSupport(), newOptions(), "http://unitsofmeasure.org", "aaaaa", null, vs);
|
CodeValidationResult result = mySvc.validateCodeInValueSet(newSupport(), newOptions(), UCUM_CODESYSTEM_URL, code, null, vs);
|
||||||
assertNotNull(outcome);
|
validateCodeResultError(result, "Error processing unit '" + code +"': The unit '" + code + "' is unknown' at position 0");
|
||||||
assertFalse(outcome.isOk());
|
}
|
||||||
assertEquals("Error processing unit 'aaaaa': The unit 'aaaaa' is unknown' at position 0", outcome.getMessage());
|
|
||||||
assertEquals("error", outcome.getSeverityCode());
|
@ParameterizedTest
|
||||||
|
@CsvSource({"en-CA, English Canada", "en-US, English United States"})
|
||||||
|
public void testValidateLookupCode_withLanguagesWithKnownCode_returnsValid(final String theCode, final String theDisplay) {
|
||||||
|
CodeValidationResult result = mySvc.validateCodeUsingSystemLookup(newSupport(), theCode, LANGUAGES_CODESYSTEM_URL);
|
||||||
|
validateCodeResultOk(result, theCode, theDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"en-CA, English (Canada)", "en-US, English (United States)"})
|
||||||
|
public void testValidateCode_withLanguagesWithKnownCode_returnsValid(final String theCode, final String theDisplay) {
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), LANGUAGES_CODESYSTEM_URL, theCode, null, LANGUAGES_VALUESET_URL);
|
||||||
|
validateCodeResultOk(result, theCode, theDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLanguagesLanguagesCs_GoodCode() {
|
public void testValidateCode_withLanguagesWithUnknownCode_returnsInvalid() {
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateLookupCode(newSupport(), "en-CA", "urn:ietf:bcp:47");
|
final String code = "FOO";
|
||||||
assert outcome != null;
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), LANGUAGES_CODESYSTEM_URL, code, null, LANGUAGES_VALUESET_URL);
|
||||||
assertTrue(outcome.isOk());
|
validateCodeResultError(result, "Code \""+ code +"\" is not in valueset: " + LANGUAGES_VALUESET_URL);
|
||||||
assertEquals("English Canada", outcome.getDisplay());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLanguagesLanguagesCs_BadCode() {
|
public void testValidateCode_withLanguagesWithIncorrectSystem_returnsInvalid() {
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateLookupCode(newSupport(), "en-FOO", "urn:ietf:bcp:47");
|
final String system = "FOO";
|
||||||
assertNull(outcome);
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), system, "en-US", null, LANGUAGES_VALUESET_URL);
|
||||||
|
validateCodeResultError(result, "Inappropriate CodeSystem URL \"" + system + "\" for ValueSet: " + LANGUAGES_VALUESET_URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"en-CA, English Canada", "en-US, English United States"})
|
||||||
|
public void testValidateCode_withAllLanguagesWithKnownCode_returnsValid(final String theCode, final String theDisplay) {
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), LANGUAGES_CODESYSTEM_URL, theCode, null, ALL_LANGUAGES_VALUESET_URL);
|
||||||
|
validateCodeResultOk(result, theCode, theDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateCode_withAllLanguagesWithUnknownCode_returnsInvalid() {
|
||||||
|
final String code = "FOO";
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), LANGUAGES_CODESYSTEM_URL, code, null, ALL_LANGUAGES_VALUESET_URL);
|
||||||
|
validateCodeResultError(result, "Code \"" + code + "\" is not in valueset: " + ALL_LANGUAGES_VALUESET_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLanguages_CommonLanguagesVs_GoodCode() {
|
public void testValidateCode_withAllLanguagesWithIncorrectSystem_returnsInvalid() {
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateCode(newSupport(), newOptions(), "urn:ietf:bcp:47", "en-US", null, "http://hl7.org/fhir/ValueSet/languages");
|
final String system = "FOO";
|
||||||
assert outcome != null;
|
final String valueSet = ALL_LANGUAGES_VALUESET_URL;
|
||||||
assertTrue(outcome.isOk());
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), system, "en-US", null, valueSet);
|
||||||
assertEquals("English (United States)", outcome.getDisplay());
|
validateCodeResultError(result, "Inappropriate CodeSystem URL \"" + system + "\" for ValueSet: " + valueSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"nl, Dutch", "nl-NL, Dutch Netherlands"})
|
||||||
|
public void testLookupCode_withLanguagesWithKnownLanguageOnlyCode_returnsFound(final String theCode, final String theDisplay) {
|
||||||
|
final String system = LANGUAGES_CODESYSTEM_URL;
|
||||||
|
LookupCodeResult result = mySvc.lookupCode(newSupport(), new LookupCodeRequest(system, theCode));
|
||||||
|
lookupCodeResultOk(result, theCode, system, theDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLanguages_CommonLanguagesVs_OnlyLanguage_NoRegion() {
|
public void testFetchCodeSystem_withCountriesForDSTU3_returnsOk() {
|
||||||
IValidationSupport.LookupCodeResult nl = mySvc.lookupCode(newSupport(), new LookupCodeRequest("urn:ietf:bcp:47", "nl"));
|
|
||||||
assertTrue(nl.isFound());
|
|
||||||
assertEquals("Dutch", nl.getCodeDisplay());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLanguages_CommonLanguagesVs_LanguageAndRegion() {
|
|
||||||
IValidationSupport.LookupCodeResult nl = mySvc.lookupCode(newSupport(), new LookupCodeRequest("urn:ietf:bcp:47", "nl-NL"));
|
|
||||||
assertTrue(nl.isFound());
|
|
||||||
assertEquals("Dutch Netherlands", nl.getCodeDisplay());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLanguages_CommonLanguagesVs_BadCode() {
|
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateCode(newSupport(), newOptions(), "urn:ietf:bcp:47", "FOO", null, "http://hl7.org/fhir/ValueSet/languages");
|
|
||||||
assert outcome != null;
|
|
||||||
assertFalse(outcome.isOk());
|
|
||||||
assertEquals("Code \"FOO\" is not in valueset: http://hl7.org/fhir/ValueSet/languages", outcome.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLanguages_CommonLanguagesVs_BadSystem() {
|
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateCode(newSupport(), newOptions(), "FOO", "en-US", null, "http://hl7.org/fhir/ValueSet/languages");
|
|
||||||
assert outcome != null;
|
|
||||||
assertFalse(outcome.isOk());
|
|
||||||
assertEquals("Inappropriate CodeSystem URL \"FOO\" for ValueSet: http://hl7.org/fhir/ValueSet/languages", outcome.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLanguages_AllLanguagesVs_GoodCode() {
|
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateCode(newSupport(), newOptions(), "urn:ietf:bcp:47", "en-US", null, "http://hl7.org/fhir/ValueSet/all-languages");
|
|
||||||
assert outcome != null;
|
|
||||||
assertTrue(outcome.isOk());
|
|
||||||
assertEquals("English United States", outcome.getDisplay());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLanguages_AllLanguagesVs_BadCode() {
|
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateCode(newSupport(), newOptions(), "urn:ietf:bcp:47", "FOO", null, "http://hl7.org/fhir/ValueSet/all-languages");
|
|
||||||
assert outcome != null;
|
|
||||||
assertFalse(outcome.isOk());
|
|
||||||
assertEquals("Code \"FOO\" is not in valueset: http://hl7.org/fhir/ValueSet/all-languages", outcome.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLanguages_AllLanguagesVs_BadSystem() {
|
|
||||||
IValidationSupport.CodeValidationResult outcome = mySvc.validateCode(newSupport(), newOptions(), "FOO", "en-US", null, "http://hl7.org/fhir/ValueSet/all-languages");
|
|
||||||
assert outcome != null;
|
|
||||||
assertFalse(outcome.isOk());
|
|
||||||
assertEquals("Inappropriate CodeSystem URL \"FOO\" for ValueSet: http://hl7.org/fhir/ValueSet/all-languages", outcome.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFetchCodeSystemBuiltIn_Iso3166_R4() {
|
|
||||||
CodeSystem cs = (CodeSystem) mySvc.fetchCodeSystem(CommonCodeSystemsTerminologyService.COUNTRIES_CODESYSTEM_URL);
|
|
||||||
assert cs != null;
|
|
||||||
assertEquals(498, cs.getConcept().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFetchCodeSystemBuiltIn_Iso3166_DSTU3() {
|
|
||||||
CommonCodeSystemsTerminologyService svc = new CommonCodeSystemsTerminologyService(FhirContext.forDstu3Cached());
|
CommonCodeSystemsTerminologyService svc = new CommonCodeSystemsTerminologyService(FhirContext.forDstu3Cached());
|
||||||
org.hl7.fhir.dstu3.model.CodeSystem cs = (org.hl7.fhir.dstu3.model.CodeSystem) svc.fetchCodeSystem(CommonCodeSystemsTerminologyService.COUNTRIES_CODESYSTEM_URL);
|
org.hl7.fhir.dstu3.model.CodeSystem cs = (org.hl7.fhir.dstu3.model.CodeSystem) svc.fetchCodeSystem(CommonCodeSystemsTerminologyService.COUNTRIES_CODESYSTEM_URL);
|
||||||
assert cs != null;
|
assertNotNull(cs);
|
||||||
assertEquals(498, cs.getConcept().size());
|
assertEquals(498, cs.getConcept().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFetchCodeSystemBuiltIn_Iso3166_R5() {
|
public void testFetchCodeSystem_withCountriesForR4_returnsOk() {
|
||||||
|
CodeSystem cs = (CodeSystem) mySvc.fetchCodeSystem(CommonCodeSystemsTerminologyService.COUNTRIES_CODESYSTEM_URL);
|
||||||
|
assertNotNull(cs);
|
||||||
|
assertEquals(498, cs.getConcept().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFetchCodeSystem_withCountriesForR5_returnsOk() {
|
||||||
CommonCodeSystemsTerminologyService svc = new CommonCodeSystemsTerminologyService(FhirContext.forR5Cached());
|
CommonCodeSystemsTerminologyService svc = new CommonCodeSystemsTerminologyService(FhirContext.forR5Cached());
|
||||||
org.hl7.fhir.r5.model.CodeSystem cs = (org.hl7.fhir.r5.model.CodeSystem) svc.fetchCodeSystem(CommonCodeSystemsTerminologyService.COUNTRIES_CODESYSTEM_URL);
|
org.hl7.fhir.r5.model.CodeSystem cs = (org.hl7.fhir.r5.model.CodeSystem) svc.fetchCodeSystem(CommonCodeSystemsTerminologyService.COUNTRIES_CODESYSTEM_URL);
|
||||||
assert cs != null;
|
assertNotNull(cs);
|
||||||
assertEquals(498, cs.getConcept().size());
|
assertEquals(498, cs.getConcept().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFetchCodeSystemBuiltIn_Iso3166_DSTU2() {
|
public void testFetchCodeSystem_withCountriesForDSTU2_returnsOk() {
|
||||||
CommonCodeSystemsTerminologyService svc = new CommonCodeSystemsTerminologyService(FhirContext.forDstu2Cached());
|
CommonCodeSystemsTerminologyService svc = new CommonCodeSystemsTerminologyService(FhirContext.forDstu2Cached());
|
||||||
IBaseResource cs = svc.fetchCodeSystem(CommonCodeSystemsTerminologyService.COUNTRIES_CODESYSTEM_URL);
|
IBaseResource cs = svc.fetchCodeSystem(CommonCodeSystemsTerminologyService.COUNTRIES_CODESYSTEM_URL);
|
||||||
assertNull(cs);
|
assertNull(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"WA, Washington", "PR, Puerto Rico"})
|
||||||
|
public void testValidateCode_withUSPostalWithKnownCode_returnsValid(final String theCode, final String theDisplay) {
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), USPS_CODESYSTEM_URL, theCode, null, null);
|
||||||
|
validateCodeResultOk(result, theCode, theDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"WA, Washington", "PR, Puerto Rico"})
|
||||||
|
public void testValidateCode_withUSPostalValueSetWithKnownCode_returnsValid(final String theCode, final String theDisplay) {
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), USPS_CODESYSTEM_URL, theCode, null, USPS_VALUESET_URL);
|
||||||
|
validateCodeResultOk(result, theCode, theDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFetchCodeSystemBuiltIn_Iso_R4() {
|
public void testValidateCode_withUSPostalValueSetWithUnknownCode_returnsInvalid() {
|
||||||
CodeSystem cs = (CodeSystem) mySvc.fetchCodeSystem(CommonCodeSystemsTerminologyService.CURRENCIES_CODESYSTEM_URL);
|
final String system = USPS_CODESYSTEM_URL;
|
||||||
assert cs != null;
|
final String code = "FOO";
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), system, code, null, USPS_VALUESET_URL);
|
||||||
|
validateCodeResultError(result, "Unknown code \"" + system + "#" + code + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"WA, Washington", "PR, Puerto Rico"})
|
||||||
|
public void testLookupCode_withUSPostalWithKnownCode_returnsValid(final String theCode, final String theDisplay) {
|
||||||
|
final String system = USPS_CODESYSTEM_URL;
|
||||||
|
LookupCodeResult result = mySvc.lookupCode(newSupport(), new LookupCodeRequest(system, theCode));
|
||||||
|
lookupCodeResultOk(result, theCode, system, theDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLookupCode_withUSPostalWithUnknownCode_returnsNotFound() {
|
||||||
|
final String system = USPS_CODESYSTEM_URL;
|
||||||
|
final String code = "invalidUSPS";
|
||||||
|
LookupCodeResult result = mySvc.lookupCode(newSupport(), new LookupCodeRequest(system, code));
|
||||||
|
lookupCodeResultError(result, code, "Code " + code + " is not valid for system: " + system);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"USD, United States dollar", "CAD, Canadian dollar", "EUR, Euro"})
|
||||||
|
public void testValidateCode_withCurrenciesWithKnownCode_returnsValid(final String theCode, final String theDisplay) {
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), CURRENCIES_CODESYSTEM_URL, theCode, null, null);
|
||||||
|
validateCodeResultOk(result, theCode, theDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"USD, United States dollar", "CAD, Canadian dollar", "EUR, Euro"})
|
||||||
|
public void testValidateCode_withCurrenciesValueSetWithKnownCode_returnsValid(final String theCode, final String theDisplay) {
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), CURRENCIES_CODESYSTEM_URL, theCode, null, CURRENCIES_VALUESET_URL);
|
||||||
|
validateCodeResultOk(result, theCode, theDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateCode_withCurrenciesValueSetWithUnknownCode_returnsInvalid() {
|
||||||
|
final String system = CURRENCIES_CODESYSTEM_URL;
|
||||||
|
final String code = "invalidCurrency";
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), system, code, null, CURRENCIES_VALUESET_URL);
|
||||||
|
validateCodeResultError(result, "Unknown code \"" + system + "#" + code + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"USD, United States dollar", "CAD, Canadian dollar", "EUR, Euro"})
|
||||||
|
public void testLookupCode_withCurrenciesWithKnownCode_returnsValid(final String theCode, final String theDisplay) {
|
||||||
|
final String system = CURRENCIES_CODESYSTEM_URL;
|
||||||
|
LookupCodeResult result = mySvc.lookupCode(newSupport(), new LookupCodeRequest(system, theCode));
|
||||||
|
lookupCodeResultOk(result, theCode, system, theDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLookupCode_withCurrenciesWithUnknownCode_returnsNotFound() {
|
||||||
|
final String system = CURRENCIES_CODESYSTEM_URL;
|
||||||
|
final String code = "FOO";
|
||||||
|
LookupCodeResult result = mySvc.lookupCode(newSupport(), new LookupCodeRequest(system, code));
|
||||||
|
lookupCodeResultError(result, code, "Code " + code + " is not valid for system: " + system);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFetchCodeSystem_withCurrencies_returnsOk() {
|
||||||
|
CodeSystem cs = (CodeSystem) mySvc.fetchCodeSystem(CURRENCIES_CODESYSTEM_URL);
|
||||||
|
assertNotNull(cs);
|
||||||
assertEquals(182, cs.getConcept().size());
|
assertEquals(182, cs.getConcept().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFetchCodeSystemBuiltIn_Unknown() {
|
public void testFetchCodeSystem_withUnknownSystem_returnsNull() {
|
||||||
CodeSystem cs = (CodeSystem) mySvc.fetchCodeSystem("http://foo");
|
CodeSystem cs = (CodeSystem) mySvc.fetchCodeSystem("http://foo");
|
||||||
assertNull(cs);
|
assertNull(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFetchCodeSystemUrlDstu3() {
|
public void testGetCodeSystemUrl_forDSTU3_throwsException() {
|
||||||
try {
|
try {
|
||||||
CommonCodeSystemsTerminologyService.getCodeSystemUrl(myCtx, new org.hl7.fhir.dstu3.model.CodeSystem());
|
CommonCodeSystemsTerminologyService.getCodeSystemUrl(myCtx, new org.hl7.fhir.dstu3.model.CodeSystem());
|
||||||
|
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
assertEquals(Msg.code(696) + "Can not handle version: DSTU3", e.getMessage());
|
assertEquals(Msg.code(696) + "Can not handle version: DSTU3", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFetchCodeSystem_withMimeType_returnsOk() {
|
||||||
|
CodeSystem cs = (CodeSystem) mySvc.fetchCodeSystem(MIMETYPES_CODESYSTEM_URL);
|
||||||
|
assertNull(cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = { EncodingEnum.JSON_PLAIN_STRING, Constants.CT_FHIR_JSON_NEW, Constants.CT_FHIR_JSON })
|
||||||
|
public void testValidateCode_withMimetypesValueSetWithStandardCode_returnsValid(String theCode) {
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), MIMETYPES_CODESYSTEM_URL, theCode, null, MIMETYPES_VALUESET_URL);
|
||||||
|
validateCodeResultOk(result, theCode, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = { EncodingEnum.JSON_PLAIN_STRING, Constants.CT_FHIR_JSON_NEW, Constants.CT_FHIR_JSON })
|
||||||
|
public void testValidateCode_withMimetypesValueSetWithInferSystemWithStandardCode_returnsValid(String theCode) {
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions().setInferSystem(true), null, theCode, null, MIMETYPES_VALUESET_URL);
|
||||||
|
validateCodeResultOk(result, theCode, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateCode_withMimetypesValueSetWithMismatchSystem_returnsInvalid() {
|
||||||
|
final String system = "someSystem";
|
||||||
|
final String valueSet = MIMETYPES_VALUESET_URL;
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), system, system, null, valueSet);
|
||||||
|
validateCodeResultError(result, "Inappropriate CodeSystem URL \"" + system + "\" for ValueSet: " + valueSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = { EncodingEnum.JSON_PLAIN_STRING, Constants.CT_FHIR_JSON_NEW, Constants.CT_FHIR_JSON })
|
||||||
|
public void testValidateCode_withMimetypesWithStandardCode_returnsValid(String theCode) {
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), MIMETYPES_CODESYSTEM_URL, theCode, null, null);
|
||||||
|
validateCodeResultOk(result, theCode, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateCode_withMimetypeValueSetWithArbitraryCode_returnsValid() {
|
||||||
|
final String code = "someCode";
|
||||||
|
final String display = "displayValue";
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), MIMETYPES_CODESYSTEM_URL, code, display, MIMETYPES_VALUESET_URL);
|
||||||
|
validateCodeResultOk(result, code, display);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateCode_withMimetypesWithArbitraryCode_returnsValid() {
|
||||||
|
final String code = "someCode";
|
||||||
|
final String display = "displayValue";
|
||||||
|
CodeValidationResult result = mySvc.validateCode(newSupport(), newOptions(), MIMETYPES_CODESYSTEM_URL, code, display, null);
|
||||||
|
validateCodeResultOk(result, code, null);
|
||||||
|
|
||||||
|
// the display null in result bug is reported here: https://github.com/hapifhir/hapi-fhir/issues/5643
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = { EncodingEnum.JSON_PLAIN_STRING, Constants.FORMAT_TURTLE, Constants.CT_FHIR_JSON_NEW, Constants.CT_FHIR_JSON })
|
||||||
|
public void testLookupCode_withMimetypesWithStandardCode_returnFound(String code) {
|
||||||
|
final String system = MIMETYPES_CODESYSTEM_URL;
|
||||||
|
LookupCodeResult result = mySvc.lookupCode(newSupport(), new LookupCodeRequest(system, code));
|
||||||
|
lookupCodeResultOk(result, code, system, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLookupCode_withMimetypesWithArbitraryCode_returnsFound() {
|
||||||
|
final String system = MIMETYPES_CODESYSTEM_URL;
|
||||||
|
final String code = "someCode";
|
||||||
|
LookupCodeResult result = mySvc.lookupCode(newSupport(), new LookupCodeRequest(system, code));
|
||||||
|
lookupCodeResultOk(result, code, system, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateCodeResultOk(final CodeValidationResult theResult, final String theCode, final String theDisplay) {
|
||||||
|
assertNotNull(theResult);
|
||||||
|
assertTrue(theResult.isOk());
|
||||||
|
assertEquals(theCode, theResult.getCode());
|
||||||
|
assertEquals(theDisplay, theResult.getDisplay());
|
||||||
|
assertNull(theResult.getSeverity());
|
||||||
|
assertNull(theResult.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateCodeResultError(final CodeValidationResult theResult, final String theError) {
|
||||||
|
assertNotNull(theResult);
|
||||||
|
assertFalse(theResult.isOk());
|
||||||
|
assertEquals(IssueSeverity.ERROR, theResult.getSeverity());
|
||||||
|
assertEquals(theError, theResult.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lookupCodeResultOk(final LookupCodeResult theResult, final String theCode, final String theSystem, final String theDisplay) {
|
||||||
|
assertNotNull(theResult);
|
||||||
|
assertEquals(theSystem, theResult.getSearchedForSystem());
|
||||||
|
assertEquals(theCode, theResult.getSearchedForCode());
|
||||||
|
assertTrue(theResult.isFound());
|
||||||
|
assertEquals(theDisplay, theResult.getCodeDisplay());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lookupCodeResultError(final LookupCodeResult theResult, final String theCode, final String theMessage) {
|
||||||
|
assertNotNull(theResult);
|
||||||
|
assertEquals(theCode, theResult.getSearchedForCode());
|
||||||
|
assertFalse(theResult.isFound());
|
||||||
|
assertEquals(theMessage, theResult.getErrorMessage());
|
||||||
|
assertNull(theResult.getCodeDisplay());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private ValidationSupportContext newSupport() {
|
private ValidationSupportContext newSupport() {
|
||||||
return new ValidationSupportContext(myCtx.getValidationSupport());
|
return new ValidationSupportContext(myCtx.getValidationSupport());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue