Class IdHelperService
- All Implemented Interfaces:
IIdHelperService<JpaPid>
HFJ_RESOURCE
table), and the
public ID that a resource has.
These IDs are sometimes one and the same (by default, a resource that the server assigns the ID of
Patient/1
will simply use a PID of 1 and and ID of 1. However, they may also be different
in cases where a forced ID is used (an arbitrary client-assigned ID).
This service is highly optimized in order to minimize the number of DB calls as much as possible,
since ID resolution is fundamental to many basic operations. This service returns either
IResourceLookup
or BaseResourcePersistentId
depending on the method being called.
The former involves an extra database join that the latter does not require, so selecting the
right method here is important.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final jakarta.persistence.criteria.Predicate[]
protected IResourceTableDao
static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addResolvedPidToFhirId
(JpaPid theJpaPid, RequestPartitionId theRequestPartitionId, String theResourceType, String theFhirId, Date theDeletedAt) Pre-cache a PID-to-Resource-ID mapping for later retrieval bytranslatePidsToForcedIds(Set)
and related methodsgetPidOrNull
(RequestPartitionId theRequestPartitionId, org.hl7.fhir.instance.model.api.IBaseResource theResource) getPidOrThrowException
(RequestPartitionId theRequestPartitionId, org.hl7.fhir.instance.model.api.IIdType theId) getPidOrThrowException
(org.hl7.fhir.instance.model.api.IAnyResource theResource) getPidsOrThrowException
(RequestPartitionId theRequestPartitionId, List<org.hl7.fhir.instance.model.api.IIdType> theIds) boolean
idRequiresForcedId
(String theId) Returns true if the given resource ID should be stored in a forced ID.static boolean
isValidPid
(String theIdPart) static boolean
isValidPid
(org.hl7.fhir.instance.model.api.IIdType theId) newPidFromStringIdAndResourceName
(String thePid, String theResourceName) replaceDefault
(RequestPartitionId theRequestPartitionId) Map
<org.hl7.fhir.instance.model.api.IIdType, IResourceLookup<JpaPid>> resolveResourceIdentities
(RequestPartitionId theRequestPartitionId, Collection<org.hl7.fhir.instance.model.api.IIdType> theIds, ResolveIdentityMode theMode) resolveResourceIdentity
(RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId, ResolveIdentityMode theMode) Given a forced ID, convert it to its Long value.resolveResourcePersistentIds
(RequestPartitionId theRequestPartitionId, String theResourceType, String theId, ResolveIdentityMode theMode) Given a resource type and ID, determines the internal persistent ID for the resource.resolveResourcePersistentIds
(RequestPartitionId theRequestPartitionId, String theResourceType, List<String> theIds, ResolveIdentityMode theMode) Returns a mapping of Id -> IResourcePersistentId.resolveResourcePersistentIdsWithCache
(RequestPartitionId theRequestPartitionId, List<org.hl7.fhir.instance.model.api.IIdType> theIds) Given a collection of resource IDs (resource type + id), resolves the internal persistent IDs.resolveResourcePersistentIdsWithCache
(RequestPartitionId theRequestPartitionId, List<org.hl7.fhir.instance.model.api.IIdType> theIds, boolean theOnlyForcedIds) Given a collection of resource IDs (resource type + id), resolves the internal persistent IDs.org.hl7.fhir.instance.model.api.IIdType
resourceIdFromPidOrThrowException
(JpaPid thePid, String theResourceType) protected void
setDontCheckActiveTransactionForUnitTest
(boolean theDontCheckActiveTransactionForUnitTest) void
setPartitionSettingsForUnitTest
(PartitionSettings thePartitionSettings) org.hl7.fhir.instance.model.api.IIdType
translatePidIdToForcedId
(ca.uhn.fhir.context.FhirContext theCtx, String theResourceType, JpaPid theId) Given a persistent ID, returns the associated resource IDtranslatePidsToFhirResourceIds
(Set<JpaPid> thePids) Given a set of PIDs, return a set of public FHIR Resource IDs.translatePidsToForcedIds
(Set<JpaPid> theResourceIds) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ca.uhn.fhir.jpa.api.svc.IIdHelperService
resolveResourceIdentityPid
-
Field Details
-
EMPTY_PREDICATE_ARRAY
-
RESOURCE_PID
- See Also:
-
myResourceTableDao
-
-
Constructor Details
-
IdHelperService
public IdHelperService()
-
-
Method Details
-
setDontCheckActiveTransactionForUnitTest
protected void setDontCheckActiveTransactionForUnitTest(boolean theDontCheckActiveTransactionForUnitTest) -
resolveResourceIdentity
@Nonnull public IResourceLookup<JpaPid> resolveResourceIdentity(@Nonnull RequestPartitionId theRequestPartitionId, @Nullable String theResourceType, @Nonnull String theResourceId, @Nonnull ResolveIdentityMode theMode) throws ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException Given a forced ID, convert it to its Long value. Since you are allowed to use string IDs for resources, we need to convert those to the underlying Long values that are stored, for lookup and comparison purposes. Optionally filters out deleted resources.- Specified by:
resolveResourceIdentity
in interfaceIIdHelperService<JpaPid>
- Throws:
ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException
- If the ID can not be found
-
resolveResourceIdentities
@Nonnull public Map<org.hl7.fhir.instance.model.api.IIdType,IResourceLookup<JpaPid>> resolveResourceIdentities(@Nonnull RequestPartitionId theRequestPartitionId, Collection<org.hl7.fhir.instance.model.api.IIdType> theIds, ResolveIdentityMode theMode) - Specified by:
resolveResourceIdentities
in interfaceIIdHelperService<JpaPid>
-
resolveResourcePersistentIds
@Nonnull public Map<String,JpaPid> resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, List<String> theIds, ResolveIdentityMode theMode) Returns a mapping of Id -> IResourcePersistentId. If any resource is not found, it will throw ResourceNotFound exception (and no map will be returned) Optionally filters out deleted resources.- Specified by:
resolveResourcePersistentIds
in interfaceIIdHelperService<JpaPid>
-
resolveResourcePersistentIds
@Nonnull public JpaPid resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theId, ResolveIdentityMode theMode) Given a resource type and ID, determines the internal persistent ID for the resource. Optionally filters out deleted resources.- Specified by:
resolveResourcePersistentIds
in interfaceIIdHelperService<JpaPid>
- Throws:
ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException
- If the ID can not be found
-
idRequiresForcedId
Returns true if the given resource ID should be stored in a forced ID. Under default config (meaning client ID strategy isJpaStorageSettings.ClientIdStrategyEnum.ALPHANUMERIC
) this will return true if the ID has any non-digit characters.In
JpaStorageSettings.ClientIdStrategyEnum.ANY
mode it will always return true.- Specified by:
idRequiresForcedId
in interfaceIIdHelperService<JpaPid>
-
resolveResourcePersistentIdsWithCache
@Nonnull public List<JpaPid> resolveResourcePersistentIdsWithCache(RequestPartitionId theRequestPartitionId, List<org.hl7.fhir.instance.model.api.IIdType> theIds) Given a collection of resource IDs (resource type + id), resolves the internal persistent IDs.This implementation will always try to use a cache for performance, meaning that it can resolve resources that are deleted (but note that forced IDs can't change, so the cache can't return incorrect results)
- Specified by:
resolveResourcePersistentIdsWithCache
in interfaceIIdHelperService<JpaPid>
-
resolveResourcePersistentIdsWithCache
@Nonnull public List<JpaPid> resolveResourcePersistentIdsWithCache(@Nonnull RequestPartitionId theRequestPartitionId, List<org.hl7.fhir.instance.model.api.IIdType> theIds, boolean theOnlyForcedIds) Given a collection of resource IDs (resource type + id), resolves the internal persistent IDs.This implementation will always try to use a cache for performance, meaning that it can resolve resources that are deleted (but note that forced IDs can't change, so the cache can't return incorrect results)
- Specified by:
resolveResourcePersistentIdsWithCache
in interfaceIIdHelperService<JpaPid>
- Parameters:
theOnlyForcedIds
- Iftrue
, resources which are not existing forced IDs will not be resolved
-
translatePidIdToForcedId
@Nonnull public org.hl7.fhir.instance.model.api.IIdType translatePidIdToForcedId(ca.uhn.fhir.context.FhirContext theCtx, String theResourceType, JpaPid theId) Given a persistent ID, returns the associated resource ID- Specified by:
translatePidIdToForcedId
in interfaceIIdHelperService<JpaPid>
-
translatePidIdToForcedIdWithCache
- Specified by:
translatePidIdToForcedIdWithCache
in interfaceIIdHelperService<JpaPid>
-
replaceDefault
-
translatePidsToForcedIds
- Specified by:
translatePidsToForcedIds
in interfaceIIdHelperService<JpaPid>
-
addResolvedPidToFhirId
public void addResolvedPidToFhirId(@Nonnull JpaPid theJpaPid, @Nonnull RequestPartitionId theRequestPartitionId, @Nonnull String theResourceType, @Nonnull String theFhirId, @Nullable Date theDeletedAt) Pre-cache a PID-to-Resource-ID mapping for later retrieval bytranslatePidsToForcedIds(Set)
and related methods- Specified by:
addResolvedPidToFhirId
in interfaceIIdHelperService<JpaPid>
-
setPartitionSettingsForUnitTest
-
getPidsOrThrowException
@Nonnull public List<JpaPid> getPidsOrThrowException(@Nonnull RequestPartitionId theRequestPartitionId, List<org.hl7.fhir.instance.model.api.IIdType> theIds) - Specified by:
getPidsOrThrowException
in interfaceIIdHelperService<JpaPid>
-
getPidOrNull
@Nullable public JpaPid getPidOrNull(@Nonnull RequestPartitionId theRequestPartitionId, org.hl7.fhir.instance.model.api.IBaseResource theResource) - Specified by:
getPidOrNull
in interfaceIIdHelperService<JpaPid>
-
getPidOrThrowException
@Nonnull public JpaPid getPidOrThrowException(@Nonnull RequestPartitionId theRequestPartitionId, org.hl7.fhir.instance.model.api.IIdType theId) - Specified by:
getPidOrThrowException
in interfaceIIdHelperService<JpaPid>
-
getPidOrThrowException
@Nonnull public JpaPid getPidOrThrowException(@Nonnull org.hl7.fhir.instance.model.api.IAnyResource theResource) - Specified by:
getPidOrThrowException
in interfaceIIdHelperService<JpaPid>
-
resourceIdFromPidOrThrowException
public org.hl7.fhir.instance.model.api.IIdType resourceIdFromPidOrThrowException(JpaPid thePid, String theResourceType) - Specified by:
resourceIdFromPidOrThrowException
in interfaceIIdHelperService<JpaPid>
-
translatePidsToFhirResourceIds
Given a set of PIDs, return a set of public FHIR Resource IDs. This function will resolve a forced ID if it resolves, and if it fails to resolve to a forced it, will just return the pid Example: Let's say we have Patient/1(pid == 1), Patient/pat1 (pid == 2), Patient/3 (pid == 3), their pids would resolve as follows:[1,2,3] -> ["1","pat1","3"]
- Specified by:
translatePidsToFhirResourceIds
in interfaceIIdHelperService<JpaPid>
- Parameters:
thePids
- The Set of pids you would like to resolve to external FHIR Resource IDs.- Returns:
- A Set of strings representing the FHIR IDs of the pids.
-
newPid
- Specified by:
newPid
in interfaceIIdHelperService<JpaPid>
-
newPidFromStringIdAndResourceName
- Specified by:
newPidFromStringIdAndResourceName
in interfaceIIdHelperService<JpaPid>
-
isValidPid
-
isValidPid
-