Added more test cases for R4

This commit is contained in:
Frank Tao 2020-09-19 12:36:14 -04:00
parent 64f2bae2e7
commit 05de0c5031
3 changed files with 127 additions and 2 deletions

View File

@ -118,7 +118,7 @@ public class BaseJpaResourceProviderCodeSystemR4 extends JpaResourceProviderR4<C
@IdParam(optional = true) IdType theId,
@OperationParam(name = "url", min = 0, max = 1) UriType theCodeSystemUrl,
@OperationParam(name = "code", min = 0, max = 1) CodeType theCode,
@OperationParam(name = "version", min = 0, max = 1) UriType theVersion,
@OperationParam(name = "version", min = 0, max = 1) StringType theVersion,
@OperationParam(name = "display", min = 0, max = 1) StringType theDisplay,
@OperationParam(name = "coding", min = 0, max = 1) Coding theCoding,
@OperationParam(name = "codeableConcept", min = 0, max = 1) CodeableConcept theCodeableConcept,

View File

@ -2654,8 +2654,10 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
if (isNoneBlank(theCodeSystemVersion)) {
predicates.add(criteriaBuilder.equal(systemVersionJoin.get("myCodeSystemVersionId"), theCodeSystemVersion));
} else {
query.orderBy(criteriaBuilder.desc(root.get("myUpdated")));
}
Predicate outerPredicate = criteriaBuilder.and(predicates.toArray(new Predicate[0]));
query.where(outerPredicate);
@ -2669,6 +2671,9 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
return new CodeValidationResult().setCode(concept.getCode()).setDisplay(concept.getDisplay());
}
for (TermConcept c :resultsList)
System.out.println(c);
if (isBlank(theDisplay))
return createFailureCodeValidationResult(theCodeSystemUrl, theCode);
else

View File

@ -9,6 +9,7 @@ import javax.annotation.Nonnull;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.r4.model.CodeType;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
@ -430,4 +431,123 @@ public class ResourceProviderR4CodeSystemValidationTest extends BaseResourceProv
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
assertEquals("Systolic blood pressure--inspiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
}
@Test
public void testValidateCodeWithUrlAndVersion_v1() {
String url = "http://url";
createCodeSystem(url, "v1", "1", "Code v1 display");
createCodeSystem(url, "v2", "1", "Code v2 display");
Parameters inParams = new Parameters();
inParams.addParameter().setName("url").setValue(new UriType(url));
inParams.addParameter().setName("version").setValue(new StringType("v1"));
inParams.addParameter().setName("code").setValue(new CodeType("1"));
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
ourLog.info("Response Parameters\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(respParam));
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
assertEquals("Code v1 display", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
}
@Test
public void testValidateCodeWithUrlAndVersion_v2() {
String url = "http://url";
createCodeSystem(url, "v1", "1", "Code v1 display");
createCodeSystem(url, "v2", "1", "Code v2 display");
Parameters inParams = new Parameters();
inParams.addParameter().setName("url").setValue(new UriType(url));
inParams.addParameter().setName("version").setValue(new StringType("v2"));
inParams.addParameter().setName("code").setValue(new CodeType("1"));
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
ourLog.info("Response Parameters\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(respParam));
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
assertEquals("Code v2 display", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
}
@Test
public void testValidateCodeWithUrlAndVersion_noVersion() {
String url = "http://url";
createCodeSystem(url, "v1", "1", "Code v1 display");
createCodeSystem(url, "v2", "1", "Code v2 display");
Parameters inParams = new Parameters();
inParams.addParameter().setName("url").setValue(new UriType(url));
inParams.addParameter().setName("code").setValue(new CodeType("1"));
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
ourLog.info("Response Parameters\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(respParam));
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
assertEquals("Code v2 display", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
}
@Test
public void testValidateCodeWithUrlAndVersion_noVersion_null_v1() {
String url = "http://url";
createCodeSystem(url, null, "1", "Code v1 display");
createCodeSystem(url, "v2", "1", "Code v2 display");
Parameters inParams = new Parameters();
inParams.addParameter().setName("url").setValue(new UriType(url));
inParams.addParameter().setName("code").setValue(new CodeType("1"));
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
ourLog.info("Response Parameters\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(respParam));
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
assertEquals("Code v2 display", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
}
@Test
public void testValidateCodeWithUrlAndVersion_noVersion_null_v2() {
String url = "http://url";
createCodeSystem(url, "v1", "1", "Code v1 display");
createCodeSystem(url, null, "1", "Code v2 display");
Parameters inParams = new Parameters();
inParams.addParameter().setName("url").setValue(new UriType(url));
inParams.addParameter().setName("code").setValue(new CodeType("1"));
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
ourLog.info("Response Parameters\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(respParam));
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
assertEquals("Code v2 display", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
}
private void createCodeSystem(String url, String version, String code, String display) {
CodeSystem codeSystem = new CodeSystem();
codeSystem.setUrl(url).setVersion(version);
ConceptDefinitionComponent concept1 = codeSystem.addConcept();
concept1.setCode("1000").setDisplay("Code Dispaly 1000");
ConceptDefinitionComponent concept = codeSystem.addConcept();
concept.setCode(code).setDisplay(display);
ConceptDefinitionComponent concept2 = codeSystem.addConcept();
concept2.setCode("2000").setDisplay("Code Dispaly 2000");
ourLog.info("CodeSystem: \n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(codeSystem));
myCodeSystemDao.create(codeSystem, mySrd);
}
}