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
FieldsModifier and TypeFieldDescriptionstatic final javax.persistence.criteria.Predicate[]protected IForcedIdDaoprotected IResourceTableDaostatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddResolvedPidToForcedId(JpaPid theJpaPid, RequestPartitionId theRequestPartitionId, String theResourceType, String theForcedId, 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) booleanidRequiresForcedId(String theId) Returns true if the given resource ID should be stored in a forced ID.static booleanisValidPid(String theIdPart) static booleanisValidPid(org.hl7.fhir.instance.model.api.IIdType theId) newPidFromStringIdAndResourceName(String thePid, String theResourceName) resolveResourceIdentity(RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId) Given a forced ID, convert it to its Long value.resolveResourceIdentity(RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId, boolean theExcludeDeleted) Given a forced ID, convert it to its Long value.resolveResourcePersistentIds(RequestPartitionId theRequestPartitionId, String theResourceType, String theId) Given a resource type and ID, determines the internal persistent ID for the resource.resolveResourcePersistentIds(RequestPartitionId theRequestPartitionId, String theResourceType, String theId, boolean theExcludeDeleted) Given a resource type and ID, determines the internal persistent ID for the resource.resolveResourcePersistentIds(RequestPartitionId theRequestPartitionId, String theResourceType, List<String> theIds) Returns a mapping of Id -> IResourcePersistentId.resolveResourcePersistentIds(RequestPartitionId theRequestPartitionId, String theResourceType, List<String> theIds, boolean theExcludeDeleted) 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.IIdTyperesourceIdFromPidOrThrowException(JpaPid thePid, String theResourceType) org.hl7.fhir.instance.model.api.IIdTypetranslatePidIdToForcedId(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)
-
Field Details
-
EMPTY_PREDICATE_ARRAY
-
RESOURCE_PID
- See Also:
-
myForcedIdDao
-
myResourceTableDao
-
-
Constructor Details
-
IdHelperService
public IdHelperService()
-
-
Method Details
-
resolveResourceIdentity
@Nonnull public IResourceLookup<JpaPid> resolveResourceIdentity(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId) 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.- Specified by:
resolveResourceIdentityin interfaceIIdHelperService<JpaPid>- Throws:
ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException- If the ID can not be found
-
resolveResourceIdentity
@Nonnull public IResourceLookup<JpaPid> resolveResourceIdentity(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theResourceId, boolean theExcludeDeleted) 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:
resolveResourceIdentityin interfaceIIdHelperService<JpaPid>- Throws:
ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException- If the ID can not be found
-
resolveResourcePersistentIds
@Nonnull public Map<String,JpaPid> resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, List<String> theIds) Returns a mapping of Id -> IResourcePersistentId. If any resource is not found, it will throw ResourceNotFound exception (and no map will be returned)- Specified by:
resolveResourcePersistentIdsin interfaceIIdHelperService<JpaPid>
-
resolveResourcePersistentIds
@Nonnull public Map<String,JpaPid> resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, List<String> theIds, boolean theExcludeDeleted) 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:
resolveResourcePersistentIdsin interfaceIIdHelperService<JpaPid>
-
resolveResourcePersistentIds
@Nonnull public JpaPid resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theId) Given a resource type and ID, determines the internal persistent ID for the resource.- Specified by:
resolveResourcePersistentIdsin interfaceIIdHelperService<JpaPid>- Throws:
ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException- If the ID can not be found
-
resolveResourcePersistentIds
public JpaPid resolveResourcePersistentIds(@Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, String theId, boolean theExcludeDeleted) Given a resource type and ID, determines the internal persistent ID for the resource. Optionally filters out deleted resources.- Specified by:
resolveResourcePersistentIdsin 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.ANYmode it will always return true.- Specified by:
idRequiresForcedIdin 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:
resolveResourcePersistentIdsWithCachein interfaceIIdHelperService<JpaPid>
-
resolveResourcePersistentIdsWithCache
@Nonnull public List<JpaPid> 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.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:
resolveResourcePersistentIdsWithCachein 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:
translatePidIdToForcedIdin interfaceIIdHelperService<JpaPid>
-
translatePidIdToForcedIdWithCache
- Specified by:
translatePidIdToForcedIdWithCachein interfaceIIdHelperService<JpaPid>
-
translatePidsToForcedIds
- Specified by:
translatePidsToForcedIdsin interfaceIIdHelperService<JpaPid>
-
addResolvedPidToForcedId
public void addResolvedPidToForcedId(JpaPid theJpaPid, @Nonnull 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- Specified by:
addResolvedPidToForcedIdin interfaceIIdHelperService<JpaPid>
-
isValidPid
-
isValidPid
-
getPidsOrThrowException
@Nonnull public List<JpaPid> getPidsOrThrowException(@Nonnull RequestPartitionId theRequestPartitionId, List<org.hl7.fhir.instance.model.api.IIdType> theIds) - Specified by:
getPidsOrThrowExceptionin interfaceIIdHelperService<JpaPid>
-
getPidOrNull
@Nullable public JpaPid getPidOrNull(@Nonnull RequestPartitionId theRequestPartitionId, org.hl7.fhir.instance.model.api.IBaseResource theResource) - Specified by:
getPidOrNullin interfaceIIdHelperService<JpaPid>
-
getPidOrThrowException
@Nonnull public JpaPid getPidOrThrowException(@Nonnull RequestPartitionId theRequestPartitionId, org.hl7.fhir.instance.model.api.IIdType theId) - Specified by:
getPidOrThrowExceptionin interfaceIIdHelperService<JpaPid>
-
getPidOrThrowException
@Nonnull public JpaPid getPidOrThrowException(@Nonnull org.hl7.fhir.instance.model.api.IAnyResource theResource) - Specified by:
getPidOrThrowExceptionin interfaceIIdHelperService<JpaPid>
-
resourceIdFromPidOrThrowException
public org.hl7.fhir.instance.model.api.IIdType resourceIdFromPidOrThrowException(JpaPid thePid, String theResourceType) - Specified by:
resourceIdFromPidOrThrowExceptionin 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:
translatePidsToFhirResourceIdsin 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:
newPidin interfaceIIdHelperService<JpaPid>
-
newPidFromStringIdAndResourceName
- Specified by:
newPidFromStringIdAndResourceNamein interfaceIIdHelperService<JpaPid>
-