Let RemoteTerminologyServiceValidationSupport.validateCodeInValueSet … (#3073)

* Let RemoteTerminologyServiceValidationSupport.validateCodeInValueSet work when code system is present, even when theOptions.isInferSystem() is true

* Add test for specific use case added

Co-authored-by: juan.marchionatto <juan.marchionatto@smilecdr.com>
This commit is contained in:
jmarchionatto 2021-10-14 15:40:27 -04:00 committed by GitHub
parent 87e594d416
commit 05aa4447f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 7 deletions

View File

@ -13,10 +13,12 @@ import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.ValueSet;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@ -49,20 +51,28 @@ public class RemoteTerminologyServiceValidationSupport extends BaseValidationSup
@Override
public CodeValidationResult validateCodeInValueSet(ValidationSupportContext theValidationSupportContext, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, @Nonnull IBaseResource theValueSet) {
if (theOptions != null) {
if (theOptions.isInferSystem()) {
return null;
IBaseResource valueSet = theValueSet;
// some external validators require the system when the code is passed
// so let's try to get it from the VS if is is not present
String codeSystem = theCodeSystem;
if (isNotBlank(theCode) && isBlank(codeSystem)) {
ValueSet vs = (ValueSet) theValueSet;
if ( vs.getCompose() != null && vs.getCompose().getInclude() != null && vs.getCompose().getInclude().size() > 0) {
codeSystem = vs.getCompose().getInclude().iterator().next().getSystem();
}
}
IBaseResource valueSet = theValueSet;
// Remote terminology services shouldn't be used to validate codes with an implied system
if (isBlank(codeSystem)) { return null; }
String valueSetUrl = DefaultProfileValidationSupport.getConformanceResourceUrl(myCtx, valueSet);
if (isNotBlank(valueSetUrl)) {
valueSet = null;
} else {
valueSetUrl = null;
}
return invokeRemoteValidateCode(theCodeSystem, theCode, theDisplay, valueSetUrl, valueSet);
return invokeRemoteValidateCode(codeSystem, theCode, theDisplay, valueSetUrl, valueSet);
}
@Override

View File

@ -28,11 +28,13 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class RemoteTerminologyServiceValidationSupportTest {
@ -147,10 +149,10 @@ public class RemoteTerminologyServiceValidationSupportTest {
}
/**
* Remote terminology services shouldn't be used to validatre codes with an implied system
* Remote terminology services shouldn't be used to validate codes with an implied system
*/
@Test
public void testValidateCodeInValueSet_InferSystem() {
public void testValidateCodeInValueSet_InferSystem_codeSystemNotPresent() {
createNextValueSetReturnParameters(true, DISPLAY, null);
ValueSet valueSet = new ValueSet();
@ -160,6 +162,27 @@ public class RemoteTerminologyServiceValidationSupportTest {
assertEquals(null, outcome);
}
/**
* Remote terminology services can be used to validate codes when code system is present,
* even when inferSystem is true
*/
@Test
public void testValidateCodeInValueSet_InferSystem_codeSystemIsPresent() {
createNextValueSetReturnParameters(true, DISPLAY, null);
ValueSet valueSet = new ValueSet();
valueSet.setUrl(VALUE_SET_URL);
String systemUrl = "http://hl7.org/fhir/ValueSet/administrative-gender";
valueSet.setCompose(new ValueSet.ValueSetComposeComponent().setInclude(
Collections.singletonList(new ValueSet.ConceptSetComponent().setSystem(systemUrl)) ));
IValidationSupport.CodeValidationResult outcome = mySvc.validateCodeInValueSet(null,
new ConceptValidationOptions().setInferSystem(true), null, CODE, DISPLAY, valueSet);
// validate service doesn't do early return (as when no code system is present)
assertNotNull(outcome);
}
@Test
public void testIsValueSetSupported_False() {
myValueSetProvider.myNextReturnValueSets = new ArrayList<>();