Added CodeSystem/$validate-code for R5

This commit is contained in:
Frank Tao 2020-09-19 14:13:07 -04:00
parent 7db9f7475b
commit 01d88a665d
4 changed files with 98 additions and 4 deletions

View File

@ -117,8 +117,8 @@ public class BaseJpaResourceProviderCodeSystemR4 extends JpaResourceProviderR4<C
HttpServletRequest theServletRequest,
@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) StringType theVersion,
@OperationParam(name = "code", min = 0, max = 1) CodeType theCode,
@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

@ -23,9 +23,13 @@ package ca.uhn.fhir.jpa.provider.r5;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.provider.BaseJpaResourceProviderValueSetDstu2;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r5.model.BooleanType;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.CodeType;
@ -98,4 +102,36 @@ public class BaseJpaResourceProviderCodeSystemR5 extends JpaResourceProviderR5<C
endRequest(theServletRequest);
}
}
/**
* $validate-code operation
*/
@SuppressWarnings("unchecked")
@Operation(name = JpaConstants.OPERATION_VALIDATE_CODE, idempotent = true, returnParameters = {
@OperationParam(name = "result", type = BooleanType.class, min = 1),
@OperationParam(name = "message", type = StringType.class),
@OperationParam(name = "display", type = StringType.class)
})
public Parameters validateCode(
HttpServletRequest theServletRequest,
@IdParam(optional = true) IdType theId,
@OperationParam(name = "url", min = 0, max = 1) UriType theCodeSystemUrl,
@OperationParam(name = "version", min = 0, max = 1) StringType theVersion,
@OperationParam(name = "code", min = 0, max = 1) CodeType theCode,
@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,
RequestDetails theRequestDetails
) {
startRequest(theServletRequest);
try {
IFhirResourceDaoCodeSystem<CodeSystem, Coding, CodeableConcept> dao = (IFhirResourceDaoCodeSystem<CodeSystem, Coding, CodeableConcept>) getDao();
IValidationSupport.CodeValidationResult result = dao.validateCode(theId, theCodeSystemUrl, theVersion, theCode, theDisplay, theCoding, theCodeableConcept, theRequestDetails);
return (Parameters) BaseJpaResourceProviderValueSetDstu2.toValidateCodeResult(getContext(), result);
} finally {
endRequest(theServletRequest);
}
}
}

View File

@ -94,7 +94,7 @@ public class ResourceProviderR4CodeSystemValidationTest extends BaseResourceProv
Parameters inParams = new Parameters();
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
inParams.addParameter().setName("display").setValue(new CodeType("Systolic blood pressure.inspiration - expiration"));
inParams.addParameter().setName("display").setValue(new StringType("Systolic blood pressure.inspiration - expiration"));
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
@ -112,7 +112,7 @@ public class ResourceProviderR4CodeSystemValidationTest extends BaseResourceProv
Parameters inParams = new Parameters();
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
inParams.addParameter().setName("display").setValue(new CodeType("Old Systolic blood pressure.inspiration - expiration"));
inParams.addParameter().setName("display").setValue(new StringType("Old Systolic blood pressure.inspiration - expiration"));
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
@ -156,7 +156,7 @@ public class ResourceProviderR4CodeSystemValidationTest extends BaseResourceProv
Parameters inParams = new Parameters();
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
inParams.addParameter().setName("display").setValue(new CodeType("Systolic blood pressure.inspiration - expiration"));
inParams.addParameter().setName("display").setValue(new StringType("Systolic blood pressure.inspiration - expiration"));
try {
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();

View File

@ -0,0 +1,58 @@
package ca.uhn.fhir.jpa.provider.r5;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hl7.fhir.r5.model.BooleanType;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.r5.model.Parameters;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.UriType;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ResourceProviderR5CodeSystemTest extends BaseResourceProviderR5Test {
private static final Logger ourLog = LoggerFactory.getLogger(ResourceProviderR5CodeSystemTest.class);
@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"));
inParams.addParameter().setName("display").setValue(new StringType("Code v1 display"));
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());
}
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);
}
}