From f3639ee1ce0b0f3508353259c99ca779c9a86d71 Mon Sep 17 00:00:00 2001 From: ianmarshall Date: Fri, 16 Oct 2020 16:30:37 -0400 Subject: [PATCH] Changes to terminology loader to support preserving the original resource IDs for LOINC even when multiple versions are loaded. --- .mvn/wrapper/maven-wrapper.properties | 1 - .../uhn/fhir/jpa/term/TermLoaderSvcImpl.java | 16 +- .../fhir/jpa/term/loinc/BaseLoincHandler.java | 9 +- .../LoincIeeeMedicalDeviceCodeHandler.java | 9 +- .../LoincPartRelatedCodeMappingHandler.java | 11 +- .../term/loinc/LoincRsnaPlaybookHandler.java | 26 +++- .../TerminologyLoaderSvcLoincJpaTest.java | 58 ++++--- .../term/TerminologyLoaderSvcLoincTest.java | 144 +++++++++++++++--- .../loinc/v267_loincupload.properties | 4 +- .../loinc/v268_loincupload.properties | 4 +- 10 files changed, 222 insertions(+), 60 deletions(-) delete mode 100755 .mvn/wrapper/maven-wrapper.properties diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties deleted file mode 100755 index 00d32aab1d4..00000000000 --- a/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1 +0,0 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip \ No newline at end of file diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermLoaderSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermLoaderSvcImpl.java index 25a12a02b9f..cb15b42be6d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermLoaderSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermLoaderSvcImpl.java @@ -137,7 +137,15 @@ public class TermLoaderSvcImpl implements ITermLoaderSvc { ourLog.info("Beginning LOINC processing"); - return processLoincFiles(descriptors, theRequestDetails, uploadProperties); + + String codeSystemVersionId = uploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode()); + if (codeSystemVersionId != null ) { + // Load the code system with version and then remove the version property. + processLoincFiles(descriptors, theRequestDetails, uploadProperties, false); + uploadProperties.remove(LOINC_CODESYSTEM_VERSION.getCode()); + } + // Load the same code system with null version. This will become the default version. + return processLoincFiles(descriptors, theRequestDetails, uploadProperties, true); } } @@ -372,7 +380,7 @@ public class TermLoaderSvcImpl implements ITermLoaderSvc { // return new UploadStatistics(conceptCount, target); } - UploadStatistics processLoincFiles(LoadedFileDescriptors theDescriptors, RequestDetails theRequestDetails, Properties theUploadProperties) { + UploadStatistics processLoincFiles(LoadedFileDescriptors theDescriptors, RequestDetails theRequestDetails, Properties theUploadProperties, Boolean theCloseFiles) { final TermCodeSystemVersion codeSystemVersion = new TermCodeSystemVersion(); final Map code2concept = new HashMap<>(); final List valueSets = new ArrayList<>(); @@ -483,7 +491,9 @@ public class TermLoaderSvcImpl implements ITermLoaderSvc { iterateOverZipFileOptional(theDescriptors, theUploadProperties.getProperty(LOINC_PART_LINK_FILE_PRIMARY.getCode(), LOINC_PART_LINK_FILE_PRIMARY_DEFAULT.getCode()), handler, ',', QuoteMode.NON_NUMERIC, false); iterateOverZipFileOptional(theDescriptors, theUploadProperties.getProperty(LOINC_PART_LINK_FILE_SUPPLEMENTARY.getCode(), LOINC_PART_LINK_FILE_SUPPLEMENTARY_DEFAULT.getCode()), handler, ',', QuoteMode.NON_NUMERIC, false); - IOUtils.closeQuietly(theDescriptors); + if (theCloseFiles) { + IOUtils.closeQuietly(theDescriptors); + } valueSets.add(getValueSetLoincAll(theUploadProperties)); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseLoincHandler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseLoincHandler.java index 5e17816f996..c8c3eeaa239 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseLoincHandler.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseLoincHandler.java @@ -190,10 +190,15 @@ public abstract class BaseLoincHandler implements IRecordHandler { ValueSet getValueSet(String theValueSetId, String theValueSetUri, String theValueSetName, String theVersionPropertyName) { String version; + String codeSystemVersion = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode()); if (isNotBlank(theVersionPropertyName)) { - version = myUploadProperties.getProperty(theVersionPropertyName); + if (codeSystemVersion != null) { + version = myUploadProperties.getProperty(theVersionPropertyName) + "-" + codeSystemVersion; + } else { + version = myUploadProperties.getProperty(theVersionPropertyName); + } } else { - version = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode()); + version = codeSystemVersion; } ValueSet vs; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincIeeeMedicalDeviceCodeHandler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincIeeeMedicalDeviceCodeHandler.java index ab951be38d5..f486000777c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincIeeeMedicalDeviceCodeHandler.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincIeeeMedicalDeviceCodeHandler.java @@ -53,7 +53,13 @@ public class LoincIeeeMedicalDeviceCodeHandler extends BaseLoincHandler implemen @Override public void accept(CSVRecord theRecord) { - String loincIeeeCmVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()); + String codeSystemVersionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode()); + String loincIeeeCmVersion; + if (codeSystemVersionId != null) { + loincIeeeCmVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()) + "-" + codeSystemVersionId; + } else { + loincIeeeCmVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()); + } String loincNumber = trim(theRecord.get("LOINC_NUM")); String longCommonName = trim(theRecord.get("LOINC_LONG_COMMON_NAME")); String ieeeCode = trim(theRecord.get("IEEE_CF_CODE10")); @@ -63,7 +69,6 @@ public class LoincIeeeMedicalDeviceCodeHandler extends BaseLoincHandler implemen String sourceCodeSystemUri = ITermLoaderSvc.LOINC_URI; String targetCodeSystemUri = ITermLoaderSvc.IEEE_11073_10101_URI; String conceptMapId; - String codeSystemVersionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode()); if (codeSystemVersionId != null) { conceptMapId = LOINC_IEEE_CM_ID + "-" + codeSystemVersionId; } else { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincPartRelatedCodeMappingHandler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincPartRelatedCodeMappingHandler.java index e67a0fef7c7..aea45c79a3c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincPartRelatedCodeMappingHandler.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincPartRelatedCodeMappingHandler.java @@ -77,8 +77,16 @@ public class LoincPartRelatedCodeMappingHandler extends BaseLoincHandler impleme String extCodeSystemVersion = trim(theRecord.get("ExtCodeSystemVersion")); String extCodeSystemCopyrightNotice = trim(theRecord.get("ExtCodeSystemCopyrightNotice")); + // CodeSystem version from properties file + String codeSystemVersionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode()); + // ConceptMap version from properties files - String loincPartMapVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()); + String loincPartMapVersion; + if (codeSystemVersionId != null) { + loincPartMapVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()) + "-" + codeSystemVersionId; + } else { + loincPartMapVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()); + } Enumerations.ConceptMapEquivalence equivalence; switch (trim(defaultString(mapType))) { @@ -131,7 +139,6 @@ public class LoincPartRelatedCodeMappingHandler extends BaseLoincHandler impleme break; } String conceptMapId; - String codeSystemVersionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode()); if (codeSystemVersionId != null) { conceptMapId = loincPartMapId + "-" + codeSystemVersionId; } else { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincRsnaPlaybookHandler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincRsnaPlaybookHandler.java index 831206b62aa..d1ba6f681bc 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincRsnaPlaybookHandler.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincRsnaPlaybookHandler.java @@ -82,25 +82,37 @@ public class LoincRsnaPlaybookHandler extends BaseLoincHandler implements IRecor String rpid = trim(theRecord.get("RPID")); String longName = trim(theRecord.get("LongName")); - // ConceptMap version from properties files - String loincRsnaCmVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()); - // CodeSystem version from properties file String codeSystemVersionId = myUploadProperties.getProperty(LOINC_CODESYSTEM_VERSION.getCode()); + // ConceptMap version from properties files + String loincRsnaCmVersion; + if (codeSystemVersionId != null) { + loincRsnaCmVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()) + "-" + codeSystemVersionId; + } else { + loincRsnaCmVersion = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()); + } + + // RSNA Codes VS ValueSet vs; - if (!myIdToValueSet.containsKey(RSNA_CODES_VS_ID)) { + String rsnaCodesValueSetId; + if (codeSystemVersionId != null) { + rsnaCodesValueSetId = RSNA_CODES_VS_ID + "-" + codeSystemVersionId; + } else { + rsnaCodesValueSetId = RSNA_CODES_VS_ID; + } + if (!myIdToValueSet.containsKey(rsnaCodesValueSetId)) { vs = new ValueSet(); vs.setUrl(RSNA_CODES_VS_URI); - vs.setId(RSNA_CODES_VS_ID); + vs.setId(rsnaCodesValueSetId); vs.setName(RSNA_CODES_VS_NAME); vs.setStatus(Enumerations.PublicationStatus.ACTIVE); vs.setVersion(codeSystemVersionId); - myIdToValueSet.put(RSNA_CODES_VS_ID, vs); + myIdToValueSet.put(rsnaCodesValueSetId, vs); myValueSets.add(vs); } else { - vs = myIdToValueSet.get(RSNA_CODES_VS_ID); + vs = myIdToValueSet.get(rsnaCodesValueSetId); } if (!myCodesInRsnaPlaybookValueSet.contains(loincNumber)) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincJpaTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincJpaTest.java index 5b44a99f9e3..4d822fb9d6a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincJpaTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincJpaTest.java @@ -3,13 +3,12 @@ package ca.uhn.fhir.jpa.term; import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.jpa.entity.TermCodeSystem; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; -import org.eclipse.jetty.http.HttpStatus; -import org.hl7.fhir.r4.model.CodeSystem; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class TerminologyLoaderSvcLoincJpaTest extends BaseJpaR4Test { private TermLoaderSvcImpl mySvc; @@ -31,35 +30,48 @@ public class TerminologyLoaderSvcLoincJpaTest extends BaseJpaR4Test { // Load LOINC marked as version 2.67 TerminologyLoaderSvcLoincTest.addLoincMandatoryFilesWithPropertiesFileToZip(myFiles, "v267_loincupload.properties"); mySvc.loadLoinc(myFiles.getFiles(), mySrd); + myTerminologyDeferredStorageSvc.saveAllDeferred(); runInTransaction(() -> { assertEquals(1, myTermCodeSystemDao.count()); - assertEquals(1, myTermCodeSystemVersionDao.count()); - assertEquals(1, myResourceTableDao.count()); + assertEquals(2, myTermCodeSystemVersionDao.count()); + assertEquals(24, myTermValueSetDao.count()); + assertEquals(12, myTermConceptMapDao.count()); + assertEquals(38, myResourceTableDao.count()); TermCodeSystem myTermCodeSystem = myTermCodeSystemDao.findByCodeSystemUri("http://loinc.org"); - TermCodeSystemVersion myTermCodeSystemVersion = myTermCodeSystemVersionDao.findByCodeSystemPidAndVersion(myTermCodeSystem.getPid(), "2.67"); - assertEquals(myTermCodeSystem.getCurrentVersion().getPid(), myTermCodeSystemVersion.getPid()); - assertEquals(myTermCodeSystem.getResource().getId(), myTermCodeSystemVersion.getResource().getId()); + TermCodeSystemVersion myTermCodeSystemVersion_versioned = myTermCodeSystemVersionDao.findByCodeSystemPidAndVersion(myTermCodeSystem.getPid(), "2.67"); + assertNotEquals(myTermCodeSystem.getCurrentVersion().getPid(), myTermCodeSystemVersion_versioned.getPid()); + assertNotEquals(myTermCodeSystem.getResource().getId(), myTermCodeSystemVersion_versioned.getResource().getId()); + + TermCodeSystemVersion myTermCodeSystemVersion_nonversioned = myTermCodeSystemVersionDao.findByCodeSystemPidVersionIsNull(myTermCodeSystem.getPid()); + assertEquals(myTermCodeSystem.getCurrentVersion().getPid(), myTermCodeSystemVersion_nonversioned.getPid()); + assertEquals(myTermCodeSystem.getResource().getId(), myTermCodeSystemVersion_nonversioned.getResource().getId()); - assertEquals(1, myResourceTableDao.count()); }); // Update LOINC marked as version 2.67 myFiles = new ZipCollectionBuilder(); TerminologyLoaderSvcLoincTest.addLoincMandatoryFilesWithPropertiesFileToZip(myFiles, "v267_loincupload.properties"); mySvc.loadLoinc(myFiles.getFiles(), mySrd); + myTerminologyDeferredStorageSvc.saveAllDeferred(); runInTransaction(() -> { assertEquals(1, myTermCodeSystemDao.count()); - assertEquals(1, myTermCodeSystemVersionDao.count()); + assertEquals(2, myTermCodeSystemVersionDao.count()); + assertEquals(24, myTermValueSetDao.count()); + assertEquals(12, myTermConceptMapDao.count()); + assertEquals(38, myResourceTableDao.count()); TermCodeSystem myTermCodeSystem = myTermCodeSystemDao.findByCodeSystemUri("http://loinc.org"); - TermCodeSystemVersion myTermCodeSystemVersion = myTermCodeSystemVersionDao.findByCodeSystemPidAndVersion(myTermCodeSystem.getPid(), "2.67"); - assertEquals(myTermCodeSystem.getCurrentVersion().getPid(), myTermCodeSystemVersion.getPid()); - assertEquals(myTermCodeSystem.getResource().getId(), myTermCodeSystemVersion.getResource().getId()); + TermCodeSystemVersion myTermCodeSystemVersion_versioned = myTermCodeSystemVersionDao.findByCodeSystemPidAndVersion(myTermCodeSystem.getPid(), "2.67"); + assertNotEquals(myTermCodeSystem.getCurrentVersion().getPid(), myTermCodeSystemVersion_versioned.getPid()); + assertNotEquals(myTermCodeSystem.getResource().getId(), myTermCodeSystemVersion_versioned.getResource().getId()); + + TermCodeSystemVersion myTermCodeSystemVersion_nonversioned = myTermCodeSystemVersionDao.findByCodeSystemPidVersionIsNull(myTermCodeSystem.getPid()); + assertEquals(myTermCodeSystem.getCurrentVersion().getPid(), myTermCodeSystemVersion_nonversioned.getPid()); + assertEquals(myTermCodeSystem.getResource().getId(), myTermCodeSystemVersion_nonversioned.getResource().getId()); - assertEquals(1, myResourceTableDao.count()); }); @@ -67,17 +79,27 @@ public class TerminologyLoaderSvcLoincJpaTest extends BaseJpaR4Test { myFiles = new ZipCollectionBuilder(); TerminologyLoaderSvcLoincTest.addLoincMandatoryFilesWithPropertiesFileToZip(myFiles, "v268_loincupload.properties"); mySvc.loadLoinc(myFiles.getFiles(), mySrd); + myTerminologyDeferredStorageSvc.saveAllDeferred(); runInTransaction(() -> { assertEquals(1, myTermCodeSystemDao.count()); - assertEquals(2, myTermCodeSystemVersionDao.count()); + assertEquals(3, myTermCodeSystemVersionDao.count()); + assertEquals(36, myTermValueSetDao.count()); + assertEquals(18, myTermConceptMapDao.count()); + assertEquals(57, myResourceTableDao.count()); TermCodeSystem myTermCodeSystem = myTermCodeSystemDao.findByCodeSystemUri("http://loinc.org"); - TermCodeSystemVersion mySecondTermCodeSystemVersion = myTermCodeSystemVersionDao.findByCodeSystemPidAndVersion(myTermCodeSystem.getPid(), "2.68"); - assertEquals(myTermCodeSystem.getCurrentVersion().getPid(), mySecondTermCodeSystemVersion.getPid()); - assertEquals(myTermCodeSystem.getResource().getId(), mySecondTermCodeSystemVersion.getResource().getId()); + TermCodeSystemVersion mySecondTermCodeSystemVersion_versioned = myTermCodeSystemVersionDao.findByCodeSystemPidAndVersion(myTermCodeSystem.getPid(), "2.68"); + assertNotEquals(myTermCodeSystem.getCurrentVersion().getPid(), mySecondTermCodeSystemVersion_versioned.getPid()); + assertNotEquals(myTermCodeSystem.getResource().getId(), mySecondTermCodeSystemVersion_versioned.getResource().getId()); - assertEquals(2, myResourceTableDao.count()); + TermCodeSystemVersion myTermCodeSystemVersion_versioned = myTermCodeSystemVersionDao.findByCodeSystemPidAndVersion(myTermCodeSystem.getPid(), "2.67"); + assertNotEquals(myTermCodeSystem.getCurrentVersion().getPid(), myTermCodeSystemVersion_versioned.getPid()); + assertNotEquals(myTermCodeSystem.getResource().getId(), myTermCodeSystemVersion_versioned.getResource().getId()); + + TermCodeSystemVersion myTermCodeSystemVersion_nonversioned = myTermCodeSystemVersionDao.findByCodeSystemPidVersionIsNull(myTermCodeSystem.getPid()); + assertEquals(myTermCodeSystem.getCurrentVersion().getPid(), myTermCodeSystemVersion_nonversioned.getPid()); + assertEquals(myTermCodeSystem.getResource().getId(), myTermCodeSystemVersion_nonversioned.getResource().getId()); }); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java index 54ee51eb873..90a823633ee 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java @@ -43,6 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -54,6 +55,24 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest { private ITermCodeSystemStorageSvc myTermCodeSystemStorageSvc; @Captor private ArgumentCaptor mySystemCaptor; + @Captor + private ArgumentCaptor mySystemCaptor_267_first; + @Captor + private ArgumentCaptor mySystemCaptor_267_second; + @Captor + private ArgumentCaptor mySystemCaptor_268; + @Captor + private ArgumentCaptor> myValueSetsCaptor_267_first; + @Captor + private ArgumentCaptor> myValueSetsCaptor_267_second; + @Captor + private ArgumentCaptor> myValueSetsCaptor_268; + @Captor + private ArgumentCaptor> myConceptMapCaptor_267_first; + @Captor + private ArgumentCaptor> myConceptMapCaptor_267_second; + @Captor + private ArgumentCaptor> myConceptMapCaptor_268; private ZipCollectionBuilder myFiles; @Mock private ITermDeferredStorageSvc myTermDeferredStorageSvc; @@ -404,78 +423,161 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest { public void testLoadLoincMultipleVersions() throws IOException { // Load LOINC marked as version 2.67 + addLoincMandatoryFilesWithPropertiesFileToZip(myFiles, "v267_loincupload.properties"); mySvc.loadLoinc(myFiles.getFiles(), mySrd); - verify(myTermCodeSystemStorageSvc, times(1)).storeNewCodeSystemVersion(mySystemCaptor.capture(), myCsvCaptor.capture(), any(RequestDetails.class), myValueSetsCaptor.capture(), myConceptMapCaptor.capture()); - CodeSystem loincCS = mySystemCaptor.getValue(); - assertEquals("2.67", loincCS.getVersion()); - List loincVS_resources = myValueSetsCaptor.getValue(); + verify(myTermCodeSystemStorageSvc, times(2)).storeNewCodeSystemVersion(mySystemCaptor_267_first.capture(), myCsvCaptor.capture(), any(RequestDetails.class), myValueSetsCaptor_267_first.capture(), myConceptMapCaptor_267_first.capture()); + List loincCSResources = mySystemCaptor_267_first.getAllValues(); + assertEquals(2, loincCSResources.size()); + assertEquals("2.67", loincCSResources.get(0).getVersion()); + assertNull(loincCSResources.get(1).getVersion()); + + List> loincVS_resourceLists = myValueSetsCaptor_267_first.getAllValues(); + assertEquals(2, loincVS_resourceLists.size()); + List loincVS_resources = loincVS_resourceLists.get(0); for (ValueSet loincVS : loincVS_resources) { if (loincVS.getId().startsWith("LL1000-0") || loincVS.getId().startsWith("LL1001-8") || loincVS.getId().startsWith("LL1892-0")) { - assertEquals("2.67.Beta.1", loincVS.getVersion()); + assertEquals("Beta.1-2.67", loincVS.getVersion()); } else { assertEquals("2.67", loincVS.getVersion()); } } - List loincCM_resources = myConceptMapCaptor.getValue(); + loincVS_resources = loincVS_resourceLists.get(1); + for (ValueSet loincVS : loincVS_resources) { + if (loincVS.getId().startsWith("LL1000-0") || loincVS.getId().startsWith("LL1001-8") || loincVS.getId().startsWith("LL1892-0")) { + assertEquals("Beta.1", loincVS.getVersion()); + } else if (loincVS.getId().equals("loinc-all")) { + assertEquals("1.0.0", loincVS.getVersion()); + } else { + assertNull(loincVS.getVersion()); + } + } + + List> loincCM_resourceLists = myConceptMapCaptor_267_first.getAllValues(); + assertEquals(2, loincCM_resourceLists.size()); + List loincCM_resources = loincCM_resourceLists.get(0); for (ConceptMap loincCM : loincCM_resources) { - assertEquals("2.67.Beta.1", loincCM.getVersion()); + assertEquals("Beta.1-2.67", loincCM.getVersion()); assertEquals(1, loincCM.getGroup().size()); ConceptMap.ConceptMapGroupComponent group = loincCM.getGroup().get(0); assertEquals(ITermLoaderSvc.LOINC_URI, group.getSource()); assertEquals("2.67", group.getSourceVersion()); } + loincCM_resources = loincCM_resourceLists.get(1); + for (ConceptMap loincCM : loincCM_resources) { + assertEquals("Beta.1", loincCM.getVersion()); + assertEquals(1, loincCM.getGroup().size()); + ConceptMap.ConceptMapGroupComponent group = loincCM.getGroup().get(0); + assertEquals(ITermLoaderSvc.LOINC_URI, group.getSource()); + assertNull(group.getSourceVersion()); + } + + reset(myTermCodeSystemStorageSvc); // Update LOINC marked as version 2.67 myFiles = new ZipCollectionBuilder(); addLoincMandatoryFilesWithPropertiesFileToZip(myFiles, "v267_loincupload.properties"); mySvc.loadLoinc(myFiles.getFiles(), mySrd); - verify(myTermCodeSystemStorageSvc, times(2)).storeNewCodeSystemVersion(mySystemCaptor.capture(), myCsvCaptor.capture(), any(RequestDetails.class), myValueSetsCaptor.capture(), myConceptMapCaptor.capture()); - loincCS = mySystemCaptor.getValue(); - assertEquals("2.67", loincCS.getVersion()); - loincVS_resources = myValueSetsCaptor.getValue(); + verify(myTermCodeSystemStorageSvc, times(2)).storeNewCodeSystemVersion(mySystemCaptor_267_second.capture(), myCsvCaptor.capture(), any(RequestDetails.class), myValueSetsCaptor_267_second.capture(), myConceptMapCaptor_267_second.capture()); + loincCSResources = mySystemCaptor_267_second.getAllValues(); + assertEquals(2, loincCSResources.size()); + assertEquals("2.67", loincCSResources.get(0).getVersion()); + assertNull(loincCSResources.get(1).getVersion()); + + loincVS_resourceLists = myValueSetsCaptor_267_second.getAllValues(); + assertEquals(2, loincVS_resourceLists.size()); + loincVS_resources = loincVS_resourceLists.get(0); for (ValueSet loincVS : loincVS_resources) { if (loincVS.getId().startsWith("LL1000-0") || loincVS.getId().startsWith("LL1001-8") || loincVS.getId().startsWith("LL1892-0")) { - assertEquals("2.67.Beta.1", loincVS.getVersion()); + assertEquals("Beta.1-2.67", loincVS.getVersion()); } else { assertEquals("2.67", loincVS.getVersion()); } } - loincCM_resources = myConceptMapCaptor.getValue(); + loincVS_resources = loincVS_resourceLists.get(1); + for (ValueSet loincVS : loincVS_resources) { + if (loincVS.getId().startsWith("LL1000-0") || loincVS.getId().startsWith("LL1001-8") || loincVS.getId().startsWith("LL1892-0")) { + assertEquals("Beta.1", loincVS.getVersion()); + } else if (loincVS.getId().equals("loinc-all")) { + assertEquals("1.0.0", loincVS.getVersion()); + } else { + assertNull(loincVS.getVersion()); + } + } + + loincCM_resourceLists = myConceptMapCaptor_267_second.getAllValues(); + assertEquals(2, loincCM_resourceLists.size()); + loincCM_resources = loincCM_resourceLists.get(0); for (ConceptMap loincCM : loincCM_resources) { - assertEquals("2.67.Beta.1", loincCM.getVersion()); + assertEquals("Beta.1-2.67", loincCM.getVersion()); assertEquals(1, loincCM.getGroup().size()); ConceptMap.ConceptMapGroupComponent group = loincCM.getGroup().get(0); assertEquals(ITermLoaderSvc.LOINC_URI, group.getSource()); assertEquals("2.67", group.getSourceVersion()); } + loincCM_resources = loincCM_resourceLists.get(1); + for (ConceptMap loincCM : loincCM_resources) { + assertEquals("Beta.1", loincCM.getVersion()); + assertEquals(1, loincCM.getGroup().size()); + ConceptMap.ConceptMapGroupComponent group = loincCM.getGroup().get(0); + assertEquals(ITermLoaderSvc.LOINC_URI, group.getSource()); + assertNull(group.getSourceVersion()); + } + + reset(myTermCodeSystemStorageSvc); // Load LOINC marked as version 2.68 myFiles = new ZipCollectionBuilder(); addLoincMandatoryFilesWithPropertiesFileToZip(myFiles, "v268_loincupload.properties"); mySvc.loadLoinc(myFiles.getFiles(), mySrd); - verify(myTermCodeSystemStorageSvc, times(3)).storeNewCodeSystemVersion(mySystemCaptor.capture(), myCsvCaptor.capture(), any(RequestDetails.class), myValueSetsCaptor.capture(), myConceptMapCaptor.capture()); - loincCS = mySystemCaptor.getValue(); - assertEquals("2.68", loincCS.getVersion()); - loincVS_resources = myValueSetsCaptor.getValue(); + verify(myTermCodeSystemStorageSvc, times(2)).storeNewCodeSystemVersion(mySystemCaptor_268.capture(), myCsvCaptor.capture(), any(RequestDetails.class), myValueSetsCaptor_268.capture(), myConceptMapCaptor_268.capture()); + loincCSResources = mySystemCaptor_268.getAllValues(); + assertEquals(2, loincCSResources.size()); + assertEquals("2.68", loincCSResources.get(0).getVersion()); + assertNull(loincCSResources.get(1).getVersion()); + + loincVS_resourceLists = myValueSetsCaptor_268.getAllValues(); + assertEquals(2, loincVS_resourceLists.size()); + loincVS_resources = loincVS_resourceLists.get(0); for (ValueSet loincVS : loincVS_resources) { if (loincVS.getId().startsWith("LL1000-0") || loincVS.getId().startsWith("LL1001-8") || loincVS.getId().startsWith("LL1892-0")) { - assertEquals("2.68.Beta.1", loincVS.getVersion()); + assertEquals("Beta.1-2.68", loincVS.getVersion()); } else { assertEquals("2.68", loincVS.getVersion()); } } - loincCM_resources = myConceptMapCaptor.getValue(); + loincVS_resources = loincVS_resourceLists.get(1); + for (ValueSet loincVS : loincVS_resources) { + if (loincVS.getId().startsWith("LL1000-0") || loincVS.getId().startsWith("LL1001-8") || loincVS.getId().startsWith("LL1892-0")) { + assertEquals("Beta.1", loincVS.getVersion()); + } else if (loincVS.getId().equals("loinc-all")) { + assertEquals("1.0.0", loincVS.getVersion()); + } else { + assertNull(loincVS.getVersion()); + } + } + + loincCM_resourceLists = myConceptMapCaptor_268.getAllValues(); + assertEquals(2, loincCM_resourceLists.size()); + loincCM_resources = loincCM_resourceLists.get(0); for (ConceptMap loincCM : loincCM_resources) { - assertEquals("2.68.Beta.1", loincCM.getVersion()); + assertEquals("Beta.1-2.68", loincCM.getVersion()); assertEquals(1, loincCM.getGroup().size()); ConceptMap.ConceptMapGroupComponent group = loincCM.getGroup().get(0); assertEquals(ITermLoaderSvc.LOINC_URI, group.getSource()); assertEquals("2.68", group.getSourceVersion()); } + loincCM_resources = loincCM_resourceLists.get(1); + for (ConceptMap loincCM : loincCM_resources) { + assertEquals("Beta.1", loincCM.getVersion()); + assertEquals(1, loincCM.getGroup().size()); + ConceptMap.ConceptMapGroupComponent group = loincCM.getGroup().get(0); + assertEquals(ITermLoaderSvc.LOINC_URI, group.getSource()); + assertNull(group.getSourceVersion()); + } } diff --git a/hapi-fhir-jpaserver-base/src/test/resources/loinc/v267_loincupload.properties b/hapi-fhir-jpaserver-base/src/test/resources/loinc/v267_loincupload.properties index f883e9d6923..f9a049fdf06 100644 --- a/hapi-fhir-jpaserver-base/src/test/resources/loinc/v267_loincupload.properties +++ b/hapi-fhir-jpaserver-base/src/test/resources/loinc/v267_loincupload.properties @@ -67,11 +67,11 @@ loinc.codesystem.version=2.67 # This is the version identifier for the answer list file ## Key may be omitted -loinc.answerlist.version=2.67.Beta.1 +loinc.answerlist.version=Beta.1 # This is the version identifier for uploaded ConceptMap resources ## Key may be omitted -loinc.conceptmap.version=2.67.Beta.1 +loinc.conceptmap.version=Beta.1 # Group ## Default value if key not provided: AccessoryFiles/GroupFile/Group.csv 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 5623432769c..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 @@ -67,11 +67,11 @@ loinc.codesystem.version=2.68 # This is the version identifier for the answer list file ## Key may be omitted -loinc.answerlist.version=2.68.Beta.1 +loinc.answerlist.version=Beta.1 # This is the version identifier for uploaded ConceptMap resources ## Key may be omitted -loinc.conceptmap.version=2.68.Beta.1 +loinc.conceptmap.version=Beta.1 # Group ## Default value if key not provided: AccessoryFiles/GroupFile/Group.csv