From 8e7b4e8437bb7f09b3cd14f57f3d9cb5231e61b8 Mon Sep 17 00:00:00 2001 From: ianmarshall Date: Tue, 29 Sep 2020 21:05:28 -0400 Subject: [PATCH] Changes per code review. --- ...ava => FhirVersionIndependentConcept.java} | 13 +- ...add-codeystem-validate-code-operation.yaml | 4 + .../2081-loinc-loader-multiple-version.yaml | 4 + .../fhir/jpa/term/BaseTermReadSvcImpl.java | 22 +- .../term/TermCodeSystemStorageSvcImpl.java | 2 +- .../FhirResourceDaoDstu3ConceptMapTest.java | 2 +- ...eProviderDstu3CodeSystemVersionedTest.java | 47 +- .../r4/ResourceProviderR4CodeSystemTest.java | 512 +++++++++++++++- ...rceProviderR4CodeSystemValidationTest.java | 560 ------------------ ...urceProviderR4CodeSystemVersionedTest.java | 2 +- .../r4/ResourceProviderR4ConceptMapTest.java | 2 +- .../r5/ResourceProviderR5CodeSystemTest.java | 68 ++- .../r5/ResourceProviderR5ConceptMapTest.java | 5 +- ... => TerminologyLoaderSvcLoincJpaTest.java} | 2 +- .../jpa/term/TerminologySvcImplR4Test.java | 2 +- .../loinc/v268_loincupload.properties | 8 +- ...oryTerminologyServerValidationSupport.java | 30 +- ...mmonCodeSystemsTerminologyServiceTest.java | 2 + 18 files changed, 670 insertions(+), 617 deletions(-) rename hapi-fhir-base/src/main/java/ca/uhn/fhir/util/{VersionIndependentConcept.java => FhirVersionIndependentConcept.java} (80%) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2081-add-codeystem-validate-code-operation.yaml create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2081-loinc-loader-multiple-version.yaml delete mode 100644 hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemValidationTest.java rename hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/{TerminologyLoaderSvcLoincIntegratedTest.java => TerminologyLoaderSvcLoincJpaTest.java} (97%) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionIndependentConcept.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirVersionIndependentConcept.java similarity index 80% rename from hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionIndependentConcept.java rename to hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirVersionIndependentConcept.java index ec5439fbffc..cd524b8ef7a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionIndependentConcept.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirVersionIndependentConcept.java @@ -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 { +public class FhirVersionIndependentConcept implements Comparable { private final String mySystem; private final String mySystemVersion; @@ -36,15 +35,15 @@ public class VersionIndependentConcept implements Comparable 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 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); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java index b55e14cf0f0..e8ba5fbb1b0 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java @@ -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()); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java index 0c5e09b6f6e..7202a38c741 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java @@ -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(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3CodeSystemVersionedTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3CodeSystemVersionedTest.java index c75bfec66ba..6f71a5d227d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3CodeSystemVersionedTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3CodeSystemVersionedTest.java @@ -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()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java index 6b2fed44ea6..c8dfce5efd9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java @@ -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); + } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemValidationTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemValidationTest.java deleted file mode 100644 index 0b55d5f4450..00000000000 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemValidationTest.java +++ /dev/null @@ -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); - } -} diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemVersionedTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemVersionedTest.java index f5e28967d36..3c13aef9a8e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemVersionedTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemVersionedTest.java @@ -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()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java index 35e1def3af6..9236a043090 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java @@ -1721,7 +1721,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test } @Test - public void testTranslateWithReverseConcaptMapUrlAndVersion() { + public void testTranslateWithReverseConceptMapUrlAndVersion() { //- conceptMap1 v1 ConceptMap conceptMap1 = new ConceptMap(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5CodeSystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5CodeSystemTest.java index f584c47a50d..9d3d8914a5a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5CodeSystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5CodeSystemTest.java @@ -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()); + } + + } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ConceptMapTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ConceptMapTest.java index 04b55803ce4..a2cb18581f0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ConceptMapTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ConceptMapTest.java @@ -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(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincIntegratedTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincJpaTest.java similarity index 97% rename from hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincIntegratedTest.java rename to hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincJpaTest.java index b6703763dbe..5b44a99f9e3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincIntegratedTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincJpaTest.java @@ -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; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java index 5c53c12b29d..48f4f4465ff 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java @@ -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()); } } diff --git a/hapi-fhir-jpaserver-base/src/test/resources/loinc/v268_loincupload.properties b/hapi-fhir-jpaserver-base/src/test/resources/loinc/v268_loincupload.properties index 7f4854293de..cb7d1eb0345 100644 --- a/hapi-fhir-jpaserver-base/src/test/resources/loinc/v268_loincupload.properties +++ b/hapi-fhir-jpaserver-base/src/test/resources/loinc/v268_loincupload.properties @@ -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 diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/InMemoryTerminologyServerValidationSupport.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/InMemoryTerminologyServerValidationSupport.java index 4704912f7fb..d6bad82267d 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/InMemoryTerminologyServerValidationSupport.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/InMemoryTerminologyServerValidationSupport.java @@ -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))); - } + 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 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 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 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 contains = expansionVs.getExpansion().getContains(); - flattenAndConvertCodesR5(contains, codesInValueSetExpansion); + flattenAndConvertCodesR5(contains, codes); break; } case DSTU2: diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyServiceTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyServiceTest.java index b3cb3984ee9..898b973c042 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyServiceTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyServiceTest.java @@ -129,4 +129,6 @@ public class CommonCodeSystemsTerminologyServiceTest { assertEquals("Can not handle version: DSTU3", e.getMessage()); } } + + }