Class IdHelperService


  • @Service
    public class IdHelperService
    extends Object
    This class is used to convert between PIDs (the internal primary key for a particular resource as stored in the 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.

    • Method Detail

      • resolveResourceIdentity

        @Nonnull
        public IResourceLookup resolveResourceIdentity​(@Nonnull
                                                       ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId,
                                                       String theResourceType,
                                                       String theResourceId,
                                                       ca.uhn.fhir.rest.api.server.RequestDetails theRequestDetails)
                                                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 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
      • 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
      • getPidOrThrowException

        @Nonnull
        public Long getPidOrThrowException​(org.hl7.fhir.instance.model.api.IIdType theId,
                                           ca.uhn.fhir.rest.api.server.RequestDetails theRequestDetails)
      • getPidToIdMap

        public Map<Long,​org.hl7.fhir.instance.model.api.IIdType> getPidToIdMap​(Collection<org.hl7.fhir.instance.model.api.IIdType> theIds,
                                                                                     ca.uhn.fhir.rest.api.server.RequestDetails theRequestDetails)
      • isValidPid

        public static boolean isValidPid​(org.hl7.fhir.instance.model.api.IIdType theId)