Changes per code review.
This commit is contained in:
parent
c593958d2c
commit
8e7b4e8437
|
@ -20,12 +20,11 @@ package ca.uhn.fhir.util;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.builder.CompareToBuilder;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
public class VersionIndependentConcept implements Comparable<VersionIndependentConcept> {
|
||||
public class FhirVersionIndependentConcept implements Comparable<FhirVersionIndependentConcept> {
|
||||
|
||||
private final String mySystem;
|
||||
private final String mySystemVersion;
|
||||
|
@ -36,15 +35,15 @@ public class VersionIndependentConcept implements Comparable<VersionIndependentC
|
|||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public VersionIndependentConcept(String theSystem, String theCode) {
|
||||
public FhirVersionIndependentConcept(String theSystem, String theCode) {
|
||||
this(theSystem, theCode, null);
|
||||
}
|
||||
|
||||
public VersionIndependentConcept(String theSystem, String theCode, String theDisplay) {
|
||||
public FhirVersionIndependentConcept(String theSystem, String theCode, String theDisplay) {
|
||||
this(theSystem, theCode, theDisplay, null);
|
||||
}
|
||||
|
||||
public VersionIndependentConcept(String theSystem, String theCode, String theDisplay, String theSystemVersion) {
|
||||
public FhirVersionIndependentConcept(String theSystem, String theCode, String theDisplay, String theSystemVersion) {
|
||||
mySystem = theSystem;
|
||||
mySystemVersion = theSystemVersion;
|
||||
myCode = theCode;
|
||||
|
@ -81,7 +80,7 @@ public class VersionIndependentConcept implements Comparable<VersionIndependentC
|
|||
return false;
|
||||
}
|
||||
|
||||
VersionIndependentConcept that = (VersionIndependentConcept) theO;
|
||||
FhirVersionIndependentConcept that = (FhirVersionIndependentConcept) theO;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(mySystem, that.mySystem)
|
||||
|
@ -95,7 +94,7 @@ public class VersionIndependentConcept implements Comparable<VersionIndependentC
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(VersionIndependentConcept theOther) {
|
||||
public int compareTo(FhirVersionIndependentConcept theOther) {
|
||||
CompareToBuilder b = new CompareToBuilder();
|
||||
b.append(mySystem, theOther.getSystem());
|
||||
b.append(myCode, theOther.getCode());
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
type: add
|
||||
issue: 2081
|
||||
title: "An implementation of CodeSystem validate-code operation has been added for R4 and R5."
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
type: add
|
||||
issue: 2081
|
||||
title: "Terminology loader for LOINC will now support specifying version and loading multiple versions of LOINC."
|
|
@ -845,13 +845,13 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
|
|||
/*
|
||||
* Filters
|
||||
*/
|
||||
String codeSystemIdentifier;
|
||||
String codeSystemUrlAndVersion;
|
||||
if (codeSystemVersion != null) {
|
||||
codeSystemIdentifier = theSystem + "|" + codeSystemVersion;
|
||||
codeSystemUrlAndVersion = theSystem + "|" + codeSystemVersion;
|
||||
} else {
|
||||
codeSystemIdentifier = theSystem;
|
||||
codeSystemUrlAndVersion = theSystem;
|
||||
}
|
||||
handleFilters(bool, codeSystemIdentifier, qb, theIncludeOrExclude);
|
||||
handleFilters(bool, codeSystemUrlAndVersion, qb, theIncludeOrExclude);
|
||||
|
||||
Query luceneQuery = bool.createQuery();
|
||||
|
||||
|
@ -988,19 +988,19 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
|
|||
break;
|
||||
case "parent":
|
||||
case "child":
|
||||
isCodeSystemLoingOrThrowInvalidRequestException(theCodeSystemIdentifier, theFilter.getProperty());
|
||||
isCodeSystemLoincOrThrowInvalidRequestException(theCodeSystemIdentifier, theFilter.getProperty());
|
||||
handleFilterLoincParentChild(theBool, theFilter);
|
||||
break;
|
||||
case "ancestor":
|
||||
isCodeSystemLoingOrThrowInvalidRequestException(theCodeSystemIdentifier, theFilter.getProperty());
|
||||
isCodeSystemLoincOrThrowInvalidRequestException(theCodeSystemIdentifier, theFilter.getProperty());
|
||||
handleFilterLoincAncestor(theCodeSystemIdentifier, theBool, theFilter);
|
||||
break;
|
||||
case "descendant":
|
||||
isCodeSystemLoingOrThrowInvalidRequestException(theCodeSystemIdentifier, theFilter.getProperty());
|
||||
isCodeSystemLoincOrThrowInvalidRequestException(theCodeSystemIdentifier, theFilter.getProperty());
|
||||
handleFilterLoincDescendant(theCodeSystemIdentifier, theBool, theFilter);
|
||||
break;
|
||||
case "copyright":
|
||||
isCodeSystemLoingOrThrowInvalidRequestException(theCodeSystemIdentifier, theFilter.getProperty());
|
||||
isCodeSystemLoincOrThrowInvalidRequestException(theCodeSystemIdentifier, theFilter.getProperty());
|
||||
handleFilterLoincCopyright(theBool, theFilter);
|
||||
break;
|
||||
default:
|
||||
|
@ -1009,7 +1009,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
|
|||
}
|
||||
}
|
||||
|
||||
private void isCodeSystemLoingOrThrowInvalidRequestException(String theSystemIdentifier, String theProperty) {
|
||||
private void isCodeSystemLoincOrThrowInvalidRequestException(String theSystemIdentifier, String theProperty) {
|
||||
String systemUrl = getUrlFromIdentifier(theSystemIdentifier);
|
||||
if (!isCodeSystemLoinc(systemUrl)) {
|
||||
throw new InvalidRequestException("Invalid filter, property " + theProperty + " is LOINC-specific and cannot be used with system: " + systemUrl);
|
||||
|
@ -2070,7 +2070,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
|
|||
ArrayList<Predicate> predicates;
|
||||
Coding coding;
|
||||
|
||||
//-- get the latest ConceptMapVersion if theTranslationRequest has url, but ConceptMapVersion
|
||||
//-- get the latest ConceptMapVersion if theTranslationRequest has ConceptMap url but no ConceptMap version
|
||||
String latestConceptMapVersion = null;
|
||||
if (theTranslationRequest.hasUrl() && !theTranslationRequest.hasConceptMapVersion())
|
||||
latestConceptMapVersion = getLatestConceptMapVersion(theTranslationRequest);
|
||||
|
@ -2174,7 +2174,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
|
|||
ArrayList<Predicate> predicates;
|
||||
Coding coding;
|
||||
|
||||
//-- get the latest ConceptMapVersion if theTranslationRequest has url, but ConceptMapVersion
|
||||
//-- get the latest ConceptMapVersion if theTranslationRequest has ConceptMap url but no ConceptMap version
|
||||
String latestConceptMapVersion = null;
|
||||
if (theTranslationRequest.hasUrl() && !theTranslationRequest.hasConceptMapVersion())
|
||||
latestConceptMapVersion = getLatestConceptMapVersion(theTranslationRequest);
|
||||
|
|
|
@ -235,7 +235,7 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc {
|
|||
@Transactional(propagation = Propagation.NEVER)
|
||||
public void deleteCodeSystemVersion(TermCodeSystemVersion theCodeSystemVersion) {
|
||||
// Delete TermCodeSystemVersion
|
||||
ourLog.info(" * Deleting code system version {}", theCodeSystemVersion.getCodeSystemVersionId());
|
||||
ourLog.info(" * Deleting TermCodeSystemVersion {}", theCodeSystemVersion.getCodeSystemVersionId());
|
||||
deleteCodeSystemVersion(theCodeSystemVersion.getPid());
|
||||
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ public class FhirResourceDaoDstu3ConceptMapTest extends BaseJpaDstu3Test {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testConcaptMapTwoConceptMapWithSameUrlOneWithoutVersion() {
|
||||
public void testConceptMapTwoConceptMapWithSameUrlOneWithoutVersion() {
|
||||
|
||||
String theUrl = "http://loinc.org/property/analyte-suffix";
|
||||
ConceptMap theConceptMap1 = new ConceptMap();
|
||||
|
|
|
@ -4,8 +4,6 @@ import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
|
|||
import ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoDstu3TerminologyTest;
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
||||
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
||||
import ca.uhn.fhir.jpa.provider.dstu3.BaseResourceProviderDstu3Test;
|
||||
import ca.uhn.fhir.jpa.provider.dstu3.ResourceProviderDstu3ValueSetTest;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
@ -21,7 +19,6 @@ import org.hl7.fhir.dstu3.model.Enumerations;
|
|||
import org.hl7.fhir.dstu3.model.Parameters;
|
||||
import org.hl7.fhir.dstu3.model.StringType;
|
||||
import org.hl7.fhir.dstu3.model.UriType;
|
||||
//import org.hl7.fhir.dstu3.model.codesystems.ConceptSubsumptionOutcome;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -377,6 +374,48 @@ public class ResourceProviderDstu3CodeSystemVersionedTest extends BaseResourcePr
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupOperationByCodeAndSystemBuiltInCode() {
|
||||
// First test with no version specified (should return the one and only version defined).
|
||||
Parameters respParam = ourClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "code", new CodeType("N"))
|
||||
.andParameter("system", new UriType("http://hl7.org/fhir/v2/0243"))
|
||||
.execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals("v2 Identity May Be Divulged", ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("2.8.2", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals("No", ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
|
||||
// Repeat with version specified.
|
||||
respParam = ourClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "code", new CodeType("N"))
|
||||
.andParameter("system", new UriType("http://hl7.org/fhir/v2/0243"))
|
||||
.andParameter("version", new StringType("2.8.2"))
|
||||
.execute();
|
||||
|
||||
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals("v2 Identity May Be Divulged", ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("2.8.2", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals("No", ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubsumesOnCodes_Subsumes() {
|
||||
// First test with no version specified (should return result for last version created).
|
||||
|
@ -722,7 +761,7 @@ public class ResourceProviderDstu3CodeSystemVersionedTest extends BaseResourcePr
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCodeSystemName() throws IOException {
|
||||
public void testUpdateCodeSystemById() throws IOException {
|
||||
|
||||
CodeSystem initialCodeSystem = ourClient.read().resource(CodeSystem.class).withId(parentChildCs1Id).execute();
|
||||
assertEquals("Parent Child CodeSystem 1", initialCodeSystem.getName());
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
|||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.hl7.fhir.r4.model.codesystems.ConceptSubsumptionOutcome;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -27,11 +28,14 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test
|
|||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderR4CodeSystemTest.class);
|
||||
private Long parentChildCsId;
|
||||
|
||||
private IIdType myCsId;
|
||||
private static final String CS_ACME_URL = "http://acme.org";
|
||||
|
||||
@BeforeEach
|
||||
@Transactional
|
||||
public void before02() throws IOException {
|
||||
CodeSystem cs = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml");
|
||||
myCodeSystemDao.create(cs, mySrd);
|
||||
myCsId = myCodeSystemDao.create(cs, mySrd).getId().toUnqualifiedVersionless();
|
||||
|
||||
CodeSystem parentChildCs = new CodeSystem();
|
||||
parentChildCs.setUrl(SYSTEM_PARENTCHILD);
|
||||
|
@ -261,7 +265,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test
|
|||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals("Married", ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(3).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).booleanValue());
|
||||
assertFalse(((BooleanType) respParam.getParameter().get(3).getValue()).booleanValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -427,7 +431,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCodeSystemName() throws IOException {
|
||||
public void testUpdateCodeSystemById() throws IOException {
|
||||
|
||||
CodeSystem initialCodeSystem = myClient.read().resource(CodeSystem.class).withId(parentChildCsId).execute();
|
||||
assertEquals("Parent Child CodeSystem", initialCodeSystem.getName());
|
||||
|
@ -446,5 +450,507 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test
|
|||
assertEquals("Updated Parent Child CodeSystem", updatedCodeSystem.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCode() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeNotFoundByCode() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5-a"));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Unknown code {http://acme.org}8452-5-a", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeMatchDisplay() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
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();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeNotMatchDisplay() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
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();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Unknown code {http://acme.org}8452-5 - Concept Display : Old Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeWithoutUrl() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: Either CodeSystem ID or CodeSystem identifier must be provided. Unable to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeWithId() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
|
||||
Parameters respParam = myClient.operation().onInstance(myCsId).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeWithoutCodeOrCodingOrCodeableConcept() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("display").setValue(new StringType("Systolic blood pressure.inspiration - expiration"));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: No code, coding, or codeableConcept provided to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeWithCodeAndCoding() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-1")));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: $validate-code can only validate (code) OR (coding) OR (codeableConcept)",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodingWithUrlNotMatch() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5").setSystem("http://url2")));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: Coding.system 'http://url2' does not equal with CodeSystem.url 'http://acme.org'. Unable to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCoding() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5")));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodingWithSystem() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5").setSystem(CS_ACME_URL)));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodingUrlNotMatch() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5").setSystem("http://url2")));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: Coding.system 'http://url2' does not equal with CodeSystem.url 'http://acme.org'. Unable to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodingWithDisplay() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5").setDisplay("Systolic blood pressure.inspiration - expiration")));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeNotFoundByCoding() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5-a")));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Unknown code {http://acme.org}8452-5-a", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConcept() {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithSystem() {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem(CS_ACME_URL);
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithDisplay() {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem(CS_ACME_URL).setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeNotFoundByCodeableConcept() {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5-a");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Unknown code {http://acme.org}8452-5-a", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptUrlNotMatch() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem("http://url2").setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: Coding.system 'http://url2' does not equal with CodeSystem.url 'http://acme.org'. Unable to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithMultipleMatchedEntries() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem(CS_ACME_URL).setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
cc.addCoding().setCode("8451-7").setSystem(CS_ACME_URL).setDisplay("Systolic blood pressure--inspiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithMultipleMatchedFirstEntry() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem(CS_ACME_URL).setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
cc.addCoding().setCode("8451-7-a").setSystem(CS_ACME_URL).setDisplay("Systolic blood pressure--inspiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithMultipleMatchedSecondEntry() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5-a").setSystem(CS_ACME_URL).setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
cc.addCoding().setCode("8451-7").setSystem(CS_ACME_URL).setDisplay("Systolic blood pressure--inspiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACME_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
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);
|
||||
|
||||
CodeSystem.ConceptDefinitionComponent concept1 = codeSystem.addConcept();
|
||||
concept1.setCode("1000").setDisplay("Code Dispaly 1000");
|
||||
|
||||
CodeSystem.ConceptDefinitionComponent concept = codeSystem.addConcept();
|
||||
concept.setCode(code).setDisplay(display);
|
||||
|
||||
CodeSystem.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,560 +0,0 @@
|
|||
package ca.uhn.fhir.jpa.provider.r4;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
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;
|
||||
import org.hl7.fhir.r4.model.Parameters;
|
||||
import org.hl7.fhir.r4.model.StringType;
|
||||
import org.hl7.fhir.r4.model.UriType;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
||||
public class ResourceProviderR4CodeSystemValidationTest extends BaseResourceProviderR4Test {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderR4CodeSystemValidationTest.class);
|
||||
|
||||
private IIdType myCsId;
|
||||
private static final String CS_ACME_URL = "http://acme.org";
|
||||
|
||||
@BeforeEach
|
||||
@Transactional
|
||||
public void before02() throws IOException {
|
||||
loadAndPersistCodeSystem();
|
||||
}
|
||||
|
||||
private void loadAndPersistCodeSystem() throws IOException {
|
||||
CodeSystem codeSystem = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml");
|
||||
codeSystem.setId("CodeSystem/cs");
|
||||
persistCodeSystem(codeSystem);
|
||||
}
|
||||
|
||||
private void persistCodeSystem(CodeSystem theCodeSystem) {
|
||||
new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(@Nonnull TransactionStatus theStatus) {
|
||||
myCsId = myCodeSystemDao.create(theCodeSystem, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
});
|
||||
myCodeSystemDao.readEntity(myCsId, null).getId();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCode() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeNotFoundByCode() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5-a"));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Unknown code {http://acme.org}8452-5-a", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeMatchDisplay() throws Exception {
|
||||
|
||||
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 StringType("Systolic blood pressure.inspiration - expiration"));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeNotMatchDisplay() throws Exception {
|
||||
|
||||
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 StringType("Old Systolic blood pressure.inspiration - expiration"));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Unknown code {http://acme.org}8452-5 - Concept Display : Old Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeWithoutUrl() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: Either CodeSystem ID or CodeSystem identifier must be provided. Unable to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeWithId() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
|
||||
Parameters respParam = myClient.operation().onInstance(myCsId).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeWithoutCodeOrCodingOrCodeableConcept() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("display").setValue(new StringType("Systolic blood pressure.inspiration - expiration"));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: No code, coding, or codeableConcept provided to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeWithCodeAndCoding() throws Exception {
|
||||
|
||||
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("coding").setValue((new Coding().setCode("8452-1")));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: $validate-code can only validate (code) OR (coding) OR (codeableConcept)",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodingWithUrlNotMatch() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5").setSystem("http://url2")));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: Coding.system 'http://url2' does not equal with CodeSystem.url 'http://acme.org'. Unable to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCoding() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5")));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodingWithSystem() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5").setSystem(CS_ACMS_URL)));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodingUrlNotMatch() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5").setSystem("http://url2")));
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: Coding.system 'http://url2' does not equal with CodeSystem.url 'http://acme.org'. Unable to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodingWithDisplay() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5").setDisplay("Systolic blood pressure.inspiration - expiration")));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeNotFoundByCoding() throws Exception {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("coding").setValue((new Coding().setCode("8452-5-a")));
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Unknown code {http://acme.org}8452-5-a", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConcept() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithSystem() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem(CS_ACMS_URL);
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithDisplay() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem(CS_ACMS_URL).setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeNotFoundByCodeableConcept() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5-a");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Unknown code {http://acme.org}8452-5-a", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptUrlNotMatch() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem("http://url2").setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
try {
|
||||
myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("HTTP 400 Bad Request: Coding.system 'http://url2' does not equal with CodeSystem.url 'http://acme.org'. Unable to validate.",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithMultipleMatchedEntries() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem(CS_ACMS_URL).setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
cc.addCoding().setCode("8451-7").setSystem(CS_ACMS_URL).setDisplay("Systolic blood pressure--inspiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithMultipleMatchedFirstEntry() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5").setSystem(CS_ACMS_URL).setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
cc.addCoding().setCode("8451-7-a").setSystem(CS_ACMS_URL).setDisplay("Systolic blood pressure--inspiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeableConceptWithMultipleMatchedSecondEntry() throws Exception {
|
||||
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("8452-5-a").setSystem(CS_ACMS_URL).setDisplay("Systolic blood pressure.inspiration - expiration");
|
||||
cc.addCoding().setCode("8451-7").setSystem(CS_ACMS_URL).setDisplay("Systolic blood pressure--inspiration");
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("url").setValue(new UriType(CS_ACMS_URL));
|
||||
inParams.addParameter().setName("codeableConcept").setValue(cc);
|
||||
|
||||
Parameters respParam = myClient.operation().onType(CodeSystem.class).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -783,7 +783,7 @@ public class ResourceProviderR4CodeSystemVersionedTest extends BaseResourceProvi
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCodeSystemName() throws IOException {
|
||||
public void testUpdateCodeSystemById() throws IOException {
|
||||
|
||||
CodeSystem initialCodeSystem = myClient.read().resource(CodeSystem.class).withId(parentChildCs1Id).execute();
|
||||
assertEquals("Parent Child CodeSystem 1", initialCodeSystem.getName());
|
||||
|
|
|
@ -1721,7 +1721,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTranslateWithReverseConcaptMapUrlAndVersion() {
|
||||
public void testTranslateWithReverseConceptMapUrlAndVersion() {
|
||||
|
||||
//- conceptMap1 v1
|
||||
ConceptMap conceptMap1 = new ConceptMap();
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package ca.uhn.fhir.jpa.provider.r5;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
||||
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.codesystems.ConceptSubsumptionOutcome;
|
||||
import org.hl7.fhir.r5.model.Enumerations;
|
||||
import org.hl7.fhir.r5.model.Coding;
|
||||
|
@ -28,11 +30,13 @@ public class ResourceProviderR5CodeSystemTest extends BaseResourceProviderR5Test
|
|||
private static final Logger ourLog = LoggerFactory.getLogger(ResourceProviderR5CodeSystemTest.class);
|
||||
private Long parentChildCsId;
|
||||
|
||||
private IIdType myCsId;
|
||||
|
||||
@BeforeEach
|
||||
@Transactional
|
||||
public void before02() throws IOException {
|
||||
CodeSystem cs = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml");
|
||||
myCodeSystemDao.create(cs, mySrd);
|
||||
myCsId = myCodeSystemDao.create(cs, mySrd).getId().toUnqualifiedVersionless();
|
||||
|
||||
CodeSystem parentChildCs = new CodeSystem();
|
||||
parentChildCs.setUrl(SYSTEM_PARENTCHILD);
|
||||
|
@ -171,5 +175,67 @@ public class ResourceProviderR5CodeSystemTest extends BaseResourceProviderR5Test
|
|||
assertEquals(false, ((BooleanType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeFoundByCodeWithId() {
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("code").setValue(new CodeType("8452-5"));
|
||||
|
||||
Parameters respParam = myClient.operation().onInstance(myCsId).named("validate-code").withParameters(inParams).execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Systolic blood pressure.inspiration - expiration", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupOperationByCodeAndSystemBuiltInCode() {
|
||||
// First test with no version specified (should return the one and only version defined).
|
||||
Parameters respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "code", new CodeType("ACSN"))
|
||||
.andParameter("system", new UriType("http://terminology.hl7.org/CodeSystem/v2-0203"))
|
||||
.execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals("v2.0203", ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("2.9", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals("Accession ID", ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(3).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).getValue());
|
||||
|
||||
// Repeat with version specified.
|
||||
respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "code", new CodeType("ACSN"))
|
||||
.andParameter("system", new UriType("http://terminology.hl7.org/CodeSystem/v2-0203"))
|
||||
.andParameter("version", new StringType("2.9"))
|
||||
.execute();
|
||||
|
||||
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals("v2.0203", ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("2.9", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals("Accession ID", ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(3).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence;
|
||||
import org.hl7.fhir.r5.model.BooleanType;
|
||||
import org.hl7.fhir.r5.model.CodeType;
|
||||
import org.hl7.fhir.r5.model.Coding;
|
||||
|
@ -26,7 +25,7 @@ public class ResourceProviderR5ConceptMapTest extends BaseResourceProviderR5Test
|
|||
private static final Logger ourLog = LoggerFactory.getLogger(ResourceProviderR5ConceptMapTest.class);
|
||||
|
||||
@Test
|
||||
public void testTranslateWithConcaptMapUrlAndVersion() {
|
||||
public void testTranslateWithConceptMapUrlAndVersion() {
|
||||
|
||||
//- conceptMap1 v1
|
||||
ConceptMap conceptMap1 = new ConceptMap();
|
||||
|
@ -109,7 +108,7 @@ public class ResourceProviderR5ConceptMapTest extends BaseResourceProviderR5Test
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTranslateWithReverseConcaptMapUrlAndVersion() {
|
||||
public void testTranslateWithReverseConceptMapUrlAndVersion() {
|
||||
|
||||
//- conceptMap1 v1
|
||||
ConceptMap conceptMap1 = new ConceptMap();
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test;
|
|||
import java.io.IOException;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TerminologyLoaderSvcLoincIntegratedTest extends BaseJpaR4Test {
|
||||
public class TerminologyLoaderSvcLoincJpaTest extends BaseJpaR4Test {
|
||||
private TermLoaderSvcImpl mySvc;
|
||||
|
||||
private ZipCollectionBuilder myFiles;
|
|
@ -290,7 +290,7 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test {
|
|||
createAndPersistConceptMap("v1");
|
||||
fail();
|
||||
} catch (UnprocessableEntityException e) {
|
||||
assertEquals("Can not create multiple ConceptMap resources with ConceptMap.url \"http://example.com/my_concept_map\", ConceptMap.version \"v1\", already have one with resource ID: ConceptMap/" + myConceptMapId.getIdPart(), e.getMessage());
|
||||
assertEquals("Can not create multiple ConceptMap resources with ConceptMap.url \"http://example.com/my_concept_map\" and ConceptMap.version \"v1\", already have one with resource ID: ConceptMap/" + myConceptMapId.getIdPart(), e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
### MANDATORY ###
|
||||
#################
|
||||
|
||||
# This is the version identifier for the LOINC code system
|
||||
## Key may be omitted if only a single version of LOINC is being kept.
|
||||
loinc.codesystem.version=2.68
|
||||
|
||||
# Answer lists (ValueSets of potential answers/values for LOINC "questions")
|
||||
## File must be present
|
||||
loinc.answerlist.file=AccessoryFiles/AnswerFile/AnswerList.csv
|
||||
|
@ -65,6 +61,10 @@ loinc.universal.lab.order.valueset.file=AccessoryFiles/LoincUniversalLabOrdersVa
|
|||
### OPTIONAL ###
|
||||
################
|
||||
|
||||
# This is the version identifier for the LOINC code system
|
||||
## Key may be omitted if only a single version of LOINC is being kept.
|
||||
loinc.codesystem.version=2.68
|
||||
|
||||
# This is the version identifier for the answer list file
|
||||
## Key may be omitted
|
||||
loinc.answerlist.version=Beta.1
|
||||
|
|
|
@ -91,23 +91,23 @@ public class InMemoryTerminologyServerValidationSupport implements IValidationSu
|
|||
return new ValueSetExpansionOutcome(expansion, null);
|
||||
}
|
||||
|
||||
private org.hl7.fhir.r5.model.ValueSet expandValueSetToCanonical(ValidationSupportContext theValidationSupportContext, IBaseResource theValueSetToExpand, @Nullable String theWantSystemIdentifier, @Nullable String theWantCode) {
|
||||
private org.hl7.fhir.r5.model.ValueSet expandValueSetToCanonical(ValidationSupportContext theValidationSupportContext, IBaseResource theValueSetToExpand, @Nullable String theWantSystemUrlAndVersion, @Nullable String theWantCode) {
|
||||
org.hl7.fhir.r5.model.ValueSet expansionR5;
|
||||
switch (theValueSetToExpand.getStructureFhirVersionEnum()) {
|
||||
case DSTU2: {
|
||||
expansionR5 = expandValueSetDstu2(theValidationSupportContext, (ca.uhn.fhir.model.dstu2.resource.ValueSet) theValueSetToExpand, theWantSystemIdentifier, theWantCode);
|
||||
expansionR5 = expandValueSetDstu2(theValidationSupportContext, (ca.uhn.fhir.model.dstu2.resource.ValueSet) theValueSetToExpand, theWantSystemUrlAndVersion, theWantCode);
|
||||
break;
|
||||
}
|
||||
case DSTU2_HL7ORG: {
|
||||
expansionR5 = expandValueSetDstu2Hl7Org(theValidationSupportContext, (ValueSet) theValueSetToExpand, theWantSystemIdentifier, theWantCode);
|
||||
expansionR5 = expandValueSetDstu2Hl7Org(theValidationSupportContext, (ValueSet) theValueSetToExpand, theWantSystemUrlAndVersion, theWantCode);
|
||||
break;
|
||||
}
|
||||
case DSTU3: {
|
||||
expansionR5 = expandValueSetDstu3(theValidationSupportContext, (org.hl7.fhir.dstu3.model.ValueSet) theValueSetToExpand, theWantSystemIdentifier, theWantCode);
|
||||
expansionR5 = expandValueSetDstu3(theValidationSupportContext, (org.hl7.fhir.dstu3.model.ValueSet) theValueSetToExpand, theWantSystemUrlAndVersion, theWantCode);
|
||||
break;
|
||||
}
|
||||
case R4: {
|
||||
expansionR5 = expandValueSetR4(theValidationSupportContext, (org.hl7.fhir.r4.model.ValueSet) theValueSetToExpand, theWantSystemIdentifier, theWantCode);
|
||||
expansionR5 = expandValueSetR4(theValidationSupportContext, (org.hl7.fhir.r4.model.ValueSet) theValueSetToExpand, theWantSystemUrlAndVersion, theWantCode);
|
||||
break;
|
||||
}
|
||||
case R5: {
|
||||
|
@ -153,15 +153,9 @@ public class InMemoryTerminologyServerValidationSupport implements IValidationSu
|
|||
}
|
||||
switch (myCtx.getVersion().getVersion()) {
|
||||
case DSTU2_HL7ORG:
|
||||
if (codeSystemVersion != null) {
|
||||
vs = new org.hl7.fhir.dstu2.model.ValueSet()
|
||||
.setCompose(new org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent()
|
||||
.addInclude(new org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent().setSystem(codeSystemUrl).setVersion(codeSystemVersion)));
|
||||
} else {
|
||||
vs = new org.hl7.fhir.dstu2.model.ValueSet()
|
||||
.setCompose(new org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent()
|
||||
.addInclude(new org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent().setSystem(theCodeSystem)));
|
||||
}
|
||||
break;
|
||||
case DSTU3:
|
||||
if (codeSystemVersion != null) {
|
||||
|
@ -228,25 +222,25 @@ public class InMemoryTerminologyServerValidationSupport implements IValidationSu
|
|||
case DSTU2_HL7ORG: {
|
||||
ValueSet expansionVs = (ValueSet) theExpansion;
|
||||
List<ValueSet.ValueSetExpansionContainsComponent> contains = expansionVs.getExpansion().getContains();
|
||||
flattenAndConvertCodesDstu2(contains, codesInValueSetExpansion);
|
||||
flattenAndConvertCodesDstu2(contains, codes);
|
||||
break;
|
||||
}
|
||||
case DSTU3: {
|
||||
org.hl7.fhir.dstu3.model.ValueSet expansionVs = (org.hl7.fhir.dstu3.model.ValueSet) theExpansion;
|
||||
List<org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent> contains = expansionVs.getExpansion().getContains();
|
||||
flattenAndConvertCodesDstu3(contains, codesInValueSetExpansion);
|
||||
flattenAndConvertCodesDstu3(contains, codes);
|
||||
break;
|
||||
}
|
||||
case R4: {
|
||||
org.hl7.fhir.r4.model.ValueSet expansionVs = (org.hl7.fhir.r4.model.ValueSet) theExpansion;
|
||||
List<org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent> contains = expansionVs.getExpansion().getContains();
|
||||
flattenAndConvertCodesR4(contains, codesInValueSetExpansion);
|
||||
flattenAndConvertCodesR4(contains, codes);
|
||||
break;
|
||||
}
|
||||
case R5: {
|
||||
org.hl7.fhir.r5.model.ValueSet expansionVs = (org.hl7.fhir.r5.model.ValueSet) theExpansion;
|
||||
List<org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent> contains = expansionVs.getExpansion().getContains();
|
||||
flattenAndConvertCodesR5(contains, codesInValueSetExpansion);
|
||||
flattenAndConvertCodesR5(contains, codes);
|
||||
break;
|
||||
}
|
||||
case DSTU2:
|
||||
|
|
|
@ -129,4 +129,6 @@ public class CommonCodeSystemsTerminologyServiceTest {
|
|||
assertEquals("Can not handle version: DSTU3", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue