Suggested test that includes case where ConceptVersion is not specified in $translate operation.
This commit is contained in:
parent
2fd692f5bb
commit
b4a87adc64
|
@ -0,0 +1,206 @@
|
||||||
|
package ca.uhn.fhir.jpa.provider.dstu3;
|
||||||
|
|
||||||
|
import org.hl7.fhir.dstu3.model.BooleanType;
|
||||||
|
import org.hl7.fhir.dstu3.model.CodeType;
|
||||||
|
import org.hl7.fhir.dstu3.model.Coding;
|
||||||
|
import org.hl7.fhir.dstu3.model.ConceptMap;
|
||||||
|
import org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent;
|
||||||
|
import org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent;
|
||||||
|
import org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent;
|
||||||
|
import org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence;
|
||||||
|
import org.hl7.fhir.dstu3.model.Parameters;
|
||||||
|
import org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent;
|
||||||
|
import org.hl7.fhir.dstu3.model.StringType;
|
||||||
|
import org.hl7.fhir.dstu3.model.UriType;
|
||||||
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
public class ResourceProviderDstu3ConceptMap_Ian_Test extends BaseResourceProviderDstu3Test {
|
||||||
|
private static final Logger ourLog = LoggerFactory.getLogger(ResourceProviderDstu3ConceptMap_Ian_Test.class);
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
@Transactional
|
||||||
|
public void before02() {
|
||||||
|
//- conceptMap v1
|
||||||
|
ConceptMap conceptMap = new ConceptMap();
|
||||||
|
conceptMap.setUrl(CM_URL).setVersion("v1").setSource(new UriType(VS_URL)).setTarget(new UriType(VS_URL_2));
|
||||||
|
|
||||||
|
ConceptMapGroupComponent group1 = conceptMap.addGroup();
|
||||||
|
group1.setSource(CS_URL).setSourceVersion("Version 1").setTarget(CS_URL_2).setTargetVersion("Version 2");
|
||||||
|
|
||||||
|
SourceElementComponent element1 = group1.addElement();
|
||||||
|
element1.setCode("11111").setDisplay("Source Code 11111");
|
||||||
|
|
||||||
|
TargetElementComponent target1 = element1.addTarget();
|
||||||
|
target1.setCode("12222").setDisplay("Target Code 12222").setEquivalence(ConceptMapEquivalence.EQUAL);
|
||||||
|
|
||||||
|
IIdType conceptMapId1 = myConceptMapDao.create(conceptMap, mySrd).getId().toUnqualifiedVersionless();
|
||||||
|
conceptMap = myConceptMapDao.read(conceptMapId1);
|
||||||
|
|
||||||
|
ourLog.info("ConceptMap: v1 \n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(conceptMap));
|
||||||
|
|
||||||
|
//- conceptMap v2
|
||||||
|
conceptMap = new ConceptMap();
|
||||||
|
conceptMap.setUrl(CM_URL).setVersion("v2").setSource(new UriType(VS_URL)).setTarget(new UriType(VS_URL_2));
|
||||||
|
|
||||||
|
ConceptMapGroupComponent group2 = conceptMap.addGroup();
|
||||||
|
group2.setSource(CS_URL).setSourceVersion("Version 1").setTarget(CS_URL_2).setTargetVersion("Version 2");
|
||||||
|
|
||||||
|
SourceElementComponent element2 = group2.addElement();
|
||||||
|
element2.setCode("11111").setDisplay("Source Code 11111");
|
||||||
|
|
||||||
|
TargetElementComponent target2 = element2.addTarget();
|
||||||
|
target2.setCode("13333").setDisplay("Target Code 13333").setEquivalence(ConceptMapEquivalence.EQUAL);
|
||||||
|
|
||||||
|
IIdType conceptMapId2 = myConceptMapDao.create(conceptMap, mySrd).getId().toUnqualifiedVersionless();
|
||||||
|
conceptMap = myConceptMapDao.read(conceptMapId2);
|
||||||
|
|
||||||
|
ourLog.info("ConceptMap: v2 \n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(conceptMap));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTranslateWithVersionedConcaptMapUrl_v2() {
|
||||||
|
|
||||||
|
// Call translate with ConceptMap v2.
|
||||||
|
Parameters inParams = new Parameters();
|
||||||
|
inParams.addParameter().setName("url").setValue(new UriType(CM_URL));
|
||||||
|
inParams.addParameter().setName("conceptMapVersion").setValue(new StringType("v2"));
|
||||||
|
inParams.addParameter().setName("system").setValue(new UriType(CS_URL));
|
||||||
|
inParams.addParameter().setName("targetsystem").setValue(new UriType(CS_URL_2));
|
||||||
|
inParams.addParameter().setName("code").setValue(new CodeType("11111"));
|
||||||
|
|
||||||
|
ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams));
|
||||||
|
|
||||||
|
Parameters respParams = ourClient
|
||||||
|
.operation()
|
||||||
|
.onType(ConceptMap.class)
|
||||||
|
.named("translate")
|
||||||
|
.withParameters(inParams)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
ourLog.info("Response Parameters\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(respParams));
|
||||||
|
|
||||||
|
// Should return v2 since v2 specified.
|
||||||
|
ParametersParameterComponent param = getParameterByName(respParams, "result");
|
||||||
|
assertTrue(((BooleanType) param.getValue()).booleanValue());
|
||||||
|
|
||||||
|
param = getParameterByName(respParams, "message");
|
||||||
|
assertEquals("Matches found!", ((StringType) param.getValue()).getValueAsString());
|
||||||
|
|
||||||
|
assertEquals(1, getNumberOfParametersByName(respParams, "match"));
|
||||||
|
param = getParametersByName(respParams, "match").get(0);
|
||||||
|
assertEquals(3, param.getPart().size());
|
||||||
|
ParametersParameterComponent part = getPartByName(param, "equivalence");
|
||||||
|
assertEquals("equal", ((CodeType) part.getValue()).getValueAsString());
|
||||||
|
part = getPartByName(param, "concept");
|
||||||
|
Coding coding = (Coding) part.getValue();
|
||||||
|
assertEquals("13333", coding.getCode());
|
||||||
|
assertEquals("Target Code 13333", coding.getDisplay());
|
||||||
|
assertFalse(coding.getUserSelected());
|
||||||
|
assertEquals(CS_URL_2, coding.getSystem());
|
||||||
|
assertEquals("Version 2", coding.getVersion());
|
||||||
|
part = getPartByName(param, "source");
|
||||||
|
assertEquals(CM_URL, ((UriType) part.getValue()).getValueAsString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTranslateWithVersionedConcaptMapUrl_v1() {
|
||||||
|
|
||||||
|
// Call translate with ConceptMap v1.
|
||||||
|
Parameters inParams = new Parameters();
|
||||||
|
inParams.addParameter().setName("url").setValue(new UriType(CM_URL));
|
||||||
|
inParams.addParameter().setName("conceptMapVersion").setValue(new StringType("v1"));
|
||||||
|
inParams.addParameter().setName("system").setValue(new UriType(CS_URL));
|
||||||
|
inParams.addParameter().setName("targetsystem").setValue(new UriType(CS_URL_2));
|
||||||
|
inParams.addParameter().setName("code").setValue(new CodeType("11111"));
|
||||||
|
|
||||||
|
ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams));
|
||||||
|
|
||||||
|
Parameters respParams = ourClient
|
||||||
|
.operation()
|
||||||
|
.onType(ConceptMap.class)
|
||||||
|
.named("translate")
|
||||||
|
.withParameters(inParams)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
ourLog.info("Response Parameters\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(respParams));
|
||||||
|
|
||||||
|
// Should return v1 since v1 specified.
|
||||||
|
ParametersParameterComponent param = getParameterByName(respParams, "result");
|
||||||
|
assertTrue(((BooleanType) param.getValue()).booleanValue());
|
||||||
|
|
||||||
|
param = getParameterByName(respParams, "message");
|
||||||
|
assertEquals("Matches found!", ((StringType) param.getValue()).getValueAsString());
|
||||||
|
|
||||||
|
assertEquals(1, getNumberOfParametersByName(respParams, "match"));
|
||||||
|
param = getParametersByName(respParams, "match").get(0);
|
||||||
|
assertEquals(3, param.getPart().size());
|
||||||
|
ParametersParameterComponent part = getPartByName(param, "equivalence");
|
||||||
|
assertEquals("equal", ((CodeType) part.getValue()).getValueAsString());
|
||||||
|
part = getPartByName(param, "concept");
|
||||||
|
Coding coding = (Coding) part.getValue();
|
||||||
|
assertEquals("12222", coding.getCode());
|
||||||
|
assertEquals("Target Code 12222", coding.getDisplay());
|
||||||
|
assertFalse(coding.getUserSelected());
|
||||||
|
assertEquals(CS_URL_2, coding.getSystem());
|
||||||
|
assertEquals("Version 2", coding.getVersion());
|
||||||
|
part = getPartByName(param, "source");
|
||||||
|
assertEquals(CM_URL, ((UriType) part.getValue()).getValueAsString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTranslateWithVersionedConcaptMapUrl_NoVersion() {
|
||||||
|
|
||||||
|
// Call translate with no ConceptMap version.
|
||||||
|
Parameters inParams = new Parameters();
|
||||||
|
inParams.addParameter().setName("url").setValue(new UriType(CM_URL));
|
||||||
|
inParams.addParameter().setName("system").setValue(new UriType(CS_URL));
|
||||||
|
inParams.addParameter().setName("targetsystem").setValue(new UriType(CS_URL_2));
|
||||||
|
inParams.addParameter().setName("code").setValue(new CodeType("11111"));
|
||||||
|
|
||||||
|
ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams));
|
||||||
|
|
||||||
|
Parameters respParams = ourClient
|
||||||
|
.operation()
|
||||||
|
.onType(ConceptMap.class)
|
||||||
|
.named("translate")
|
||||||
|
.withParameters(inParams)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
ourLog.info("Response Parameters\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(respParams));
|
||||||
|
|
||||||
|
// Should return v2 since v2 is the most recently updated version.
|
||||||
|
ParametersParameterComponent param = getParameterByName(respParams, "result");
|
||||||
|
assertTrue(((BooleanType) param.getValue()).booleanValue());
|
||||||
|
|
||||||
|
param = getParameterByName(respParams, "message");
|
||||||
|
assertEquals("Matches found!", ((StringType) param.getValue()).getValueAsString());
|
||||||
|
|
||||||
|
assertEquals(1, getNumberOfParametersByName(respParams, "match"));
|
||||||
|
param = getParametersByName(respParams, "match").get(0);
|
||||||
|
assertEquals(3, param.getPart().size());
|
||||||
|
ParametersParameterComponent part = getPartByName(param, "equivalence");
|
||||||
|
assertEquals("equal", ((CodeType) part.getValue()).getValueAsString());
|
||||||
|
part = getPartByName(param, "concept");
|
||||||
|
Coding coding = (Coding) part.getValue();
|
||||||
|
assertEquals("13333", coding.getCode());
|
||||||
|
assertEquals("Target Code 13333", coding.getDisplay());
|
||||||
|
assertFalse(coding.getUserSelected());
|
||||||
|
assertEquals(CS_URL_2, coding.getSystem());
|
||||||
|
assertEquals("Version 2", coding.getVersion());
|
||||||
|
part = getPartByName(param, "source");
|
||||||
|
assertEquals(CM_URL, ((UriType) part.getValue()).getValueAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue