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
addResolvedPidToFhirIdAfterCommit
(JpaPid theJpaPid, RequestPartitionId theRequestPartitionId, String theResourceType, String theFhirId, Date theDeletedAt) This method can be called to pre-emptively add entries to the ID cache.getPidOrNull
(RequestPartitionId theRequestPartitionId, org.hl7.fhir.instance.model.api.IBaseResource theResource) getPidOrThrowException
(org.hl7.fhir.instance.model.api.IAnyResource theResource) boolean
idRequiresForcedId
(String theId) Returns true if the given resource ID should be stored in a forced ID.static boolean
isValidPid
(String theIdPart) 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.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
getPidOrThrowException, resolveResourceIdentityPid, resolveResourcePids
-
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>
-
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>
-
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>
-
addResolvedPidToFhirIdAfterCommit
public void addResolvedPidToFhirIdAfterCommit(@Nonnull JpaPid theJpaPid, @Nonnull RequestPartitionId theRequestPartitionId, @Nonnull String theResourceType, @Nonnull String theFhirId, @Nullable Date theDeletedAt) This method can be called to pre-emptively add entries to the ID cache. It should be called by DAO methods if they are creating or changing the deleted status of a resource. This method returns immediately, but the data is not added to the internal caches until the current DB transaction is successfully committed, and nothing is added if the transaction rolls back.- Specified by:
addResolvedPidToFhirIdAfterCommit
in interfaceIIdHelperService<JpaPid>
-
setPartitionSettingsForUnitTest
-
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 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
-