diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties index aecaba0f495..71aee0c17e2 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties @@ -142,6 +142,7 @@ ca.uhn.fhir.jpa.binstore.BinaryAccessProvider.unknownType=Content in resource of ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateCodeSystemUrl=Can not create multiple CodeSystem resources with CodeSystem.url "{0}", already have one with resource ID: {1} ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateConceptMapUrl=Can not create multiple ConceptMap resources with ConceptMap.url "{0}", already have one with resource ID: {1} +ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateConceptMapUrlAndVersion=Can not create multiple ConceptMap resources with ConceptMap.url "{0}", ConceptMap.version "{1}", already have one with resource ID: {2} ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateValueSetUrl=Can not create multiple ValueSet resources with ValueSet.url "{0}", already have one with resource ID: {1} ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.expansionTooLarge=Expansion of ValueSet produced too many codes (maximum {0}) - Operation aborted! diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptMapDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptMapDao.java index 7e7d1933939..f3b609faa6e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptMapDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptMapDao.java @@ -39,9 +39,7 @@ public interface ITermConceptMapDao extends JpaRepository @Query("SELECT cm FROM TermConceptMap cm WHERE cm.myResourcePid = :resource_pid") Optional findTermConceptMapByResourcePid(@Param("resource_pid") Long theResourcePid); - //-- Replaced with next method. Should it be removed? - @Deprecated - @Query("SELECT cm FROM TermConceptMap cm WHERE cm.myUrl = :url") + @Query("SELECT cm FROM TermConceptMap cm WHERE cm.myUrl = :url and cm.myVersion is null") Optional findTermConceptMapByUrl(@Param("url") String theUrl); @Query(value="SELECT cm FROM TermConceptMap cm INNER JOIN ResourceTable r ON r.myId = cm.myResourcePid WHERE cm.myUrl = :url ORDER BY r.myUpdated DESC") diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java index b8cde329e0e..99f7617ebcd 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java @@ -1550,7 +1550,12 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { */ String conceptMapUrl = termConceptMap.getUrl(); String conceptMapVersion = termConceptMap.getVersion(); - Optional optionalExistingTermConceptMapByUrl = myConceptMapDao.findTermConceptMapByUrlAndVersion(conceptMapUrl, conceptMapVersion); + Optional optionalExistingTermConceptMapByUrl = null; + if (isBlank(conceptMapVersion)) { + optionalExistingTermConceptMapByUrl = myConceptMapDao.findTermConceptMapByUrl(conceptMapUrl); + } else { + optionalExistingTermConceptMapByUrl = myConceptMapDao.findTermConceptMapByUrlAndVersion(conceptMapUrl, conceptMapVersion); + } if (!optionalExistingTermConceptMapByUrl.isPresent()) { try { if (isNotBlank(source)) { @@ -1631,13 +1636,22 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } else { TermConceptMap existingTermConceptMap = optionalExistingTermConceptMapByUrl.get(); - String msg = myContext.getLocalizer().getMessage( - BaseTermReadSvcImpl.class, - "cannotCreateDuplicateConceptMapUrlAndVersion", - conceptMapUrl, conceptMapVersion, - existingTermConceptMap.getResource().getIdDt().toUnqualifiedVersionless().getValue()); - - throw new UnprocessableEntityException(msg); + if (isBlank(conceptMapVersion)) { + String msg = myContext.getLocalizer().getMessage( + BaseTermReadSvcImpl.class, + "cannotCreateDuplicateConceptMapUrl", + conceptMapUrl, + existingTermConceptMap.getResource().getIdDt().toUnqualifiedVersionless().getValue()); + throw new UnprocessableEntityException(msg); + + } else { + String msg = myContext.getLocalizer().getMessage( + BaseTermReadSvcImpl.class, + "cannotCreateDuplicateConceptMapUrlAndVersion", + conceptMapUrl, conceptMapVersion, + existingTermConceptMap.getResource().getIdDt().toUnqualifiedVersionless().getValue()); + throw new UnprocessableEntityException(msg); + } } ourLog.info("Done storing TermConceptMap[{}] for {}", termConceptMap.getId(), theConceptMap.getIdElement().toVersionless().getValueAsString()); @@ -1949,6 +1963,14 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { predicates.add(criteriaBuilder.equal(groupJoin.get("myTarget"), translationQuery.getTargetSystem().getValueAsString())); } + if (translationQuery.hasUrl()) { + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myUrl"), translationQuery.getUrl().getValueAsString())); + } + + if (translationQuery.hasConceptMapVersion()) { + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myVerion"), translationQuery.getConceptMapVersion().getValueAsString())); + } + if (translationQuery.hasSource()) { predicates.add(criteriaBuilder.equal(conceptMapJoin.get("mySource"), translationQuery.getSource().getValueAsString())); } @@ -2032,6 +2054,14 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { predicates.add(criteriaBuilder.equal(groupJoin.get("myTargetVersion"), coding.getVersion())); } + if (translationQuery.hasUrl()) { + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myUrl"), translationQuery.getUrl().getValueAsString())); + } + + if (translationQuery.hasConceptMapVersion()) { + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myVerion"), translationQuery.getConceptMapVersion().getValueAsString())); + } + if (translationQuery.hasTargetSystem()) { predicates.add(criteriaBuilder.equal(groupJoin.get("mySource"), translationQuery.getTargetSystem().getValueAsString())); }