Class IdHelperService
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 ResourcePersistentId
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
FieldsModifier and TypeFieldDescriptionstatic final javax.persistence.criteria.Predicate[]
protected IForcedIdDao
protected IResourceTableDao
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addResolvedPidToForcedId
(ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId theResourcePersistentId, ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId, String theResourceType, String theForcedId, Date theDeletedAt) Pre-cache a PID-to-Resource-ID mapping for later retrieval bytranslatePidsToForcedIds(Set)
and related methodsvoid
getPidOrNull
(org.hl7.fhir.instance.model.api.IBaseResource theResource) Deprecated.This method doesn't take a partition ID as input, so it is unsafe.getPidOrThrowException
(org.hl7.fhir.instance.model.api.IAnyResource theResource) getPidOrThrowException
(org.hl7.fhir.instance.model.api.IIdType theId) Deprecated.This method doesn't take a partition ID as input, so it is unsafe.getPidsOrThrowException
(List<org.hl7.fhir.instance.model.api.IIdType> theIds) Deprecated.This method doesn't take a partition ID as input, so it is unsafe.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) resolveResourceIdentity
(ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId) Given a forced ID, convert it to it's Long value.ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId
resolveResourcePersistentIds
(ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId, String theResourceType, String theId) Given a resource type and ID, determines the internal persistent ID for the resource.resolveResourcePersistentIds
(ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId, String theResourceType, List<String> theIds) Returns a mapping of Id -> ResourcePersistentId.List<ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId>
resolveResourcePersistentIdsWithCache
(ca.uhn.fhir.interceptor.model.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.org.hl7.fhir.instance.model.api.IIdType
org.hl7.fhir.instance.model.api.IIdType
translatePidIdToForcedId
(ca.uhn.fhir.context.FhirContext theCtx, String theResourceType, ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId theId) Given a persistent ID, returns the associated resource IDtranslatePidIdToForcedIdWithCache
(ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId theId) translatePidsToFhirResourceIds
(Set<Long> thePids) Given a set of PIDs, return a set of public FHIR Resource IDs.translatePidsToForcedIds
(Set<Long> thePids)
-
Field Details
-
EMPTY_PREDICATE_ARRAY
-
myForcedIdDao
-
myResourceTableDao
-
-
Constructor Details
-
IdHelperService
public IdHelperService()
-
-
Method Details
-
delete
-
resolveResourceIdentity
@Nonnull public IResourceLookup resolveResourceIdentity(@Nonnull ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId) throws ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException Given a forced ID, convert it to it's 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.- Throws:
ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException
- If the ID can not be found
-
resolveResourcePersistentIds
@Nonnull public Map<String,ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId> resolveResourcePersistentIds(@Nonnull ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId, String theResourceType, List<String> theIds) Returns a mapping of Id -> ResourcePersistentId. If any resource is not found, it will throw ResourceNotFound exception (and no map will be returned) -
resolveResourcePersistentIds
@Nonnull public ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId resolveResourcePersistentIds(@Nonnull ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId, String theResourceType, String theId) Given a resource type and ID, determines the internal persistent ID for the resource.- 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 isDaoConfig.ClientIdStrategyEnum.ALPHANUMERIC
) this will return true if the ID has any non-digit characters.In
DaoConfig.ClientIdStrategyEnum.ANY
mode it will always return true. -
resolveResourcePersistentIdsWithCache
@Nonnull public List<ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId> resolveResourcePersistentIdsWithCache(ca.uhn.fhir.interceptor.model.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)
-
translatePidIdToForcedId
@Nonnull public org.hl7.fhir.instance.model.api.IIdType translatePidIdToForcedId(ca.uhn.fhir.context.FhirContext theCtx, String theResourceType, ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId theId) Given a persistent ID, returns the associated resource ID -
translatePidIdToForcedIdWithCache
public Optional<String> translatePidIdToForcedIdWithCache(ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId theId) -
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"]
- 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.
-
translatePidsToForcedIds
-
getPidOrNull
@Deprecated @Nullable public Long getPidOrNull(org.hl7.fhir.instance.model.api.IBaseResource theResource) Deprecated.This method doesn't take a partition ID as input, so it is unsafe. It should be reworked to include the partition ID before any new use is incorporated -
getPidOrThrowException
@Deprecated @Nonnull public Long getPidOrThrowException(org.hl7.fhir.instance.model.api.IIdType theId) Deprecated.This method doesn't take a partition ID as input, so it is unsafe. It should be reworked to include the partition ID before any new use is incorporated -
getPidsOrThrowException
@Deprecated @Nonnull public List<Long> getPidsOrThrowException(List<org.hl7.fhir.instance.model.api.IIdType> theIds) Deprecated.This method doesn't take a partition ID as input, so it is unsafe. It should be reworked to include the partition ID before any new use is incorporated -
getPidOrThrowException
@Nonnull public Long getPidOrThrowException(@Nonnull org.hl7.fhir.instance.model.api.IAnyResource theResource) -
resourceIdFromPidOrThrowException
-
addResolvedPidToForcedId
public void addResolvedPidToForcedId(ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId theResourcePersistentId, @Nonnull ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId, String theResourceType, @Nullable String theForcedId, @Nullable Date theDeletedAt) Pre-cache a PID-to-Resource-ID mapping for later retrieval bytranslatePidsToForcedIds(Set)
and related methods -
isValidPid
-
isValidPid
-