diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaPersistedResourceValidationSupport.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaPersistedResourceValidationSupport.java index 06ede2ad0da..f6234960c7f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaPersistedResourceValidationSupport.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaPersistedResourceValidationSupport.java @@ -125,19 +125,7 @@ public class JpaPersistedResourceValidationSupport implements IValidationSupport private Optional getCodeSystemCurrentVersion(UriType theUrl) { if (! theUrl.getValueAsString().contains("loinc")) return Optional.empty(); - IFhirResourceDao valueSetResourceDao = myDaoRegistry.getResourceDao(myCodeSystemType); - String forcedId = "loinc"; - - // try/catch ignores exception because we need code to fall back to other options - IBaseResource codeSystem; - try { - codeSystem = valueSetResourceDao.read(new IdDt("CodeSystem", forcedId)); - - } catch (Exception theE) { - return Optional.empty(); - } - - return Optional.ofNullable(codeSystem); + return myTermReadSvc.readByForcedId("loinc"); } 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 10cbc569fdc..cd15e180327 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 @@ -28,6 +28,7 @@ import ca.uhn.fhir.context.support.ValueSetExpansionOptions; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IDao; +import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem; import ca.uhn.fhir.jpa.config.HibernatePropertiesProvider; import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc; @@ -54,6 +55,7 @@ import ca.uhn.fhir.jpa.entity.TermConceptPropertyTypeEnum; import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; +import ca.uhn.fhir.jpa.model.entity.ForcedId; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.jpa.model.sched.ISchedulerService; @@ -139,6 +141,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.PostConstruct; import javax.persistence.EntityManager; +import javax.persistence.NonUniqueResultException; import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContextType; import javax.persistence.TypedQuery; @@ -2552,4 +2555,23 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { return theReqLang.equalsIgnoreCase(theStoredLang); } + + + @Override + public Optional readByForcedId(String theForcedId) { + @SuppressWarnings("unchecked") + List resultList = (List) myEntityManager.createQuery( + "select f.myResource from ForcedId f " + + "where f.myResourceType = 'CodeSystem' and f.myForcedId = '" + theForcedId + "'").getResultList(); + if (resultList.isEmpty()) return Optional.empty(); + + if (resultList.size() > 1) throw new NonUniqueResultException( + "More than one CodeSystem is pointed by forcedId: " + theForcedId + ". Was constraint " + + ForcedId.IDX_FORCEDID_TYPE_FID + " removed?"); + + IFhirResourceDao csDao = myDaoRegistry.getResourceDao("CodeSystem"); + IBaseResource cs = csDao.toResource(resultList.get(0), false); + return Optional.of(cs ); + } + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/api/ITermReadSvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/api/ITermReadSvc.java index 43c4ab902cc..fe6adeffee9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/api/ITermReadSvc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/api/ITermReadSvc.java @@ -136,4 +136,6 @@ public interface ITermReadSvc extends IValidationSupport { */ boolean isLoincNotGenericUnversionedValueSet(String theUrl); + Optional readByForcedId(String theForcedId); + }