Class IdType

All Implemented Interfaces:
ca.uhn.fhir.model.api.IElement, Externalizable, Serializable, org.hl7.fhir.instance.model.api.IBase, org.hl7.fhir.instance.model.api.IBaseDatatype, org.hl7.fhir.instance.model.api.IBaseElement, org.hl7.fhir.instance.model.api.IBaseHasExtensions, org.hl7.fhir.instance.model.api.IIdType, org.hl7.fhir.instance.model.api.IPrimitiveType<String>

public final class IdType extends UriType implements org.hl7.fhir.instance.model.api.IPrimitiveType<String>, org.hl7.fhir.instance.model.api.IIdType
This class represents the logical identity for a resource, or as much of that identity is known. In FHIR, every resource must have a "logical ID" which is defined by the FHIR specification as:

Any combination of upper or lower case ASCII letters ('A'..'Z', and 'a'..'z', numerals ('0'..'9'), '-' and '.', with a length limit of 64 characters. (This might be an integer, an un-prefixed OID, UUID or any other identifier pattern that meets these constraints.)

This class contains that logical ID, and can optionally also contain a relative or absolute URL representing the resource identity. For example, the following are all valid values for IdType, and all might represent the same resource:

  • 123 (just a resource's ID)
  • Patient/123 (a relative identity)
  • http://example.com/Patient/123 (an absolute identity)
  • http://example.com/Patient/123/_history/1 (an absolute identity with a version id)
  • Patient/123/_history/1 (a relative identity with a version id)

Note that the 64 character limit applies only to the ID portion ("123" in the examples above).

In most situations, you only need to populate the resource's ID (e.g. 123) in resources you are constructing and the encoder will infer the rest from the context in which the object is being used. On the other hand, the parser will always try to populate the complete absolute identity on objects it creates as a convenience.

Regex for ID: [a-z0-9\-\.]{1,64}

See Also:
  • Field Details

  • Constructor Details

    • IdType

      public IdType()
      Create a new empty ID
    • IdType

      public IdType(BigDecimal thePid)
      Create a new ID, using a BigDecimal input. Uses BigDecimal.toPlainString() to generate the string representation.
    • IdType

      public IdType(long theId)
      Create a new ID using a long
    • IdType

      public IdType(String theValue)
      Create a new ID using a string. This String may contain a simple ID (e.g. "1234") or it may contain a complete URL (http://example.com/fhir/Patient/1234).

      Description: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.

      regex: [a-z0-9\-\.]{1,36}

    • IdType

      public IdType(String theResourceType, BigDecimal theIdPart)
      Constructor
      Parameters:
      theResourceType - The resource type (e.g. "Patient")
      theIdPart - The ID (e.g. "123")
    • IdType

      public IdType(String theResourceType, Long theIdPart)
      Constructor
      Parameters:
      theResourceType - The resource type (e.g. "Patient")
      theIdPart - The ID (e.g. "123")
    • IdType

      public IdType(String theResourceType, String theId)
      Constructor
      Parameters:
      theResourceType - The resource type (e.g. "Patient")
      theId - The ID (e.g. "123")
    • IdType

      public IdType(String theResourceType, String theId, String theVersionId)
      Constructor
      Parameters:
      theResourceType - The resource type (e.g. "Patient")
      theId - The ID (e.g. "123")
      theVersionId - The version ID ("e.g. "456")
    • IdType

      public IdType(String theBaseUrl, String theResourceType, String theId, String theVersionId)
      Constructor
      Parameters:
      theBaseUrl - The server base URL (e.g. "http://example.com/fhir")
      theResourceType - The resource type (e.g. "Patient")
      theId - The ID (e.g. "123")
      theVersionId - The version ID ("e.g. "456")
    • IdType

      public IdType(UriType theUrl)
      Creates an ID based on a given URL
  • Method Details

    • applyTo

      public void applyTo(org.hl7.fhir.instance.model.api.IBaseResource theResource)
      Specified by:
      applyTo in interface org.hl7.fhir.instance.model.api.IIdType
    • asBigDecimal

      Deprecated.
      Use getIdPartAsBigDecimal() instead (this method was deprocated because its name is ambiguous)
    • copy

      public IdType copy()
      Overrides:
      copy in class UriType
    • equals

      public boolean equals(Object theArg0)
      Overrides:
      equals in class Object
    • equalsIgnoreBase

      public boolean equalsIgnoreBase(IdType theId)
      Returns true if this IdType matches the given IdType in terms of resource type and ID, but ignores the URL base
    • getBaseUrl

      public String getBaseUrl()
      Returns the portion of this resource ID which corresponds to the server base URL. For example given the resource ID http://example.com/fhir/Patient/123 the base URL would be http://example.com/fhir.

      This method may return null if the ID contains no base (e.g. "Patient/123")

      Specified by:
      getBaseUrl in interface org.hl7.fhir.instance.model.api.IIdType
    • getIdPart

      public String getIdPart()
      Returns only the logical ID part of this ID. For example, given the ID "http://example,.com/fhir/Patient/123/_history/456", this method would return "123".
      Specified by:
      getIdPart in interface org.hl7.fhir.instance.model.api.IIdType
    • getIdPartAsBigDecimal

      Returns the unqualified portion of this ID as a big decimal, or null if the value is null
      Throws:
      NumberFormatException - If the value is not a valid BigDecimal
    • getIdPartAsLong

      Returns the unqualified portion of this ID as a Long, or null if the value is null
      Specified by:
      getIdPartAsLong in interface org.hl7.fhir.instance.model.api.IIdType
      Throws:
      NumberFormatException - If the value is not a valid Long
    • getResourceType

      Specified by:
      getResourceType in interface org.hl7.fhir.instance.model.api.IIdType
    • getValue

      public String getValue()
      Returns the value of this ID. Note that this value may be a fully qualified URL, a relative/partial URL, or a simple ID. Use getIdPart() to get just the ID portion.
      Specified by:
      getValue in interface org.hl7.fhir.instance.model.api.IIdType
      Specified by:
      getValue in interface org.hl7.fhir.instance.model.api.IPrimitiveType<String>
      Overrides:
      getValue in class PrimitiveType<String>
      See Also:
    • getValueAsString

      Specified by:
      getValueAsString in interface org.hl7.fhir.instance.model.api.IPrimitiveType<String>
      Overrides:
      getValueAsString in class PrimitiveType<String>
    • asStringValue

      Overrides:
      asStringValue in class PrimitiveType<String>
    • getVersionIdPart

      Specified by:
      getVersionIdPart in interface org.hl7.fhir.instance.model.api.IIdType
    • getVersionIdPartAsLong

      Specified by:
      getVersionIdPartAsLong in interface org.hl7.fhir.instance.model.api.IIdType
    • hasBaseUrl

      public boolean hasBaseUrl()
      Returns true if this ID has a base url
      Specified by:
      hasBaseUrl in interface org.hl7.fhir.instance.model.api.IIdType
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class UriType
    • hasIdPart

      public boolean hasIdPart()
      Specified by:
      hasIdPart in interface org.hl7.fhir.instance.model.api.IIdType
    • hasResourceType

      public boolean hasResourceType()
      Specified by:
      hasResourceType in interface org.hl7.fhir.instance.model.api.IIdType
    • hasVersionIdPart

      public boolean hasVersionIdPart()
      Specified by:
      hasVersionIdPart in interface org.hl7.fhir.instance.model.api.IIdType
    • isAbsolute

      public boolean isAbsolute()
      Returns true if this ID contains an absolute URL (in other words, a URL starting with "http://" or "https://"
      Specified by:
      isAbsolute in interface org.hl7.fhir.instance.model.api.IIdType
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface org.hl7.fhir.instance.model.api.IBase
      Specified by:
      isEmpty in interface org.hl7.fhir.instance.model.api.IIdType
      Overrides:
      isEmpty in class PrimitiveType<String>
    • isIdPartValid

      public boolean isIdPartValid()
      Specified by:
      isIdPartValid in interface org.hl7.fhir.instance.model.api.IIdType
    • isIdPartValidLong

      public boolean isIdPartValidLong()
      Returns true if the unqualified ID is a valid Long value (in other words, it consists only of digits)
      Specified by:
      isIdPartValidLong in interface org.hl7.fhir.instance.model.api.IIdType
    • isLocal

      public boolean isLocal()
      Returns true if the ID is a local reference (in other words, it begins with the '#' character)
      Specified by:
      isLocal in interface org.hl7.fhir.instance.model.api.IIdType
    • isUrn

      public boolean isUrn()
    • isVersionIdPartValidLong

      public boolean isVersionIdPartValidLong()
      Specified by:
      isVersionIdPartValidLong in interface org.hl7.fhir.instance.model.api.IIdType
    • setValue

      public IdType setValue(String theValue)
      Set the value

      Description: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.

      regex: [a-z0-9\-\.]{1,36}

      Specified by:
      setValue in interface org.hl7.fhir.instance.model.api.IIdType
      Specified by:
      setValue in interface org.hl7.fhir.instance.model.api.IPrimitiveType<String>
      Overrides:
      setValue in class PrimitiveType<String>
    • setValueAsString

      public void setValueAsString(String theValue)
      Set the value

      Description: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.

      regex: [a-z0-9\-\.]{1,36}

      Specified by:
      setValueAsString in interface org.hl7.fhir.instance.model.api.IPrimitiveType<String>
      Overrides:
      setValueAsString in class PrimitiveType<String>
    • toString

      public String toString()
      Overrides:
      toString in class PrimitiveType<String>
    • toUnqualified

      Returns a new IdType containing this IdType's values but with no server base URL if one is present in this IdType. For example, if this IdType contains the ID "http://foo/Patient/1", this method will return a new IdType containing ID "Patient/1".
      Specified by:
      toUnqualified in interface org.hl7.fhir.instance.model.api.IIdType
    • toUnqualifiedVersionless

      Specified by:
      toUnqualifiedVersionless in interface org.hl7.fhir.instance.model.api.IIdType
    • toVersionless

      Specified by:
      toVersionless in interface org.hl7.fhir.instance.model.api.IIdType
    • withResourceType

      public IdType withResourceType(String theResourceName)
      Specified by:
      withResourceType in interface org.hl7.fhir.instance.model.api.IIdType
    • withServerBase

      public IdType withServerBase(String theServerBase, String theResourceType)
      Returns a view of this ID as a fully qualified URL, given a server base and resource name (which will only be used if the ID does not already contain those respective parts). Essentially, because IdType can contain either a complete URL or a partial one (or even jut a simple ID), this method may be used to translate into a complete URL.
      Specified by:
      withServerBase in interface org.hl7.fhir.instance.model.api.IIdType
      Parameters:
      theServerBase - The server base (e.g. "http://example.com/fhir")
      theResourceType - The resource name (e.g. "Patient")
      Returns:
      A fully qualified URL for this ID (e.g. "http://example.com/fhir/Patient/1")
    • withVersion

      public IdType withVersion(String theVersion)
      Creates a new instance of this ID which is identical, but refers to the specific version of this resource ID noted by theVersion.
      Specified by:
      withVersion in interface org.hl7.fhir.instance.model.api.IIdType
      Parameters:
      theVersion - The actual version string, e.g. "1". If theVersion is blank or null, returns the same as toVersionless()}
      Returns:
      A new instance of IdType which is identical, but refers to the specific version of this resource ID noted by theVersion.
    • newRandomUuid

      public static IdType newRandomUuid()
      Construct a new ID with with form "urn:uuid:[UUID]" where [UUID] is a new, randomly created UUID generated by UUID.randomUUID()
    • of

      public static IdType of(org.hl7.fhir.instance.model.api.IBaseResource theResouce)
      Retrieves the ID from the given resource instance
    • fhirType

      public String fhirType()
      Specified by:
      fhirType in interface org.hl7.fhir.instance.model.api.IBase
      Overrides:
      fhirType in class UriType
    • setParts

      public org.hl7.fhir.instance.model.api.IIdType setParts(String theBaseUrl, String theResourceType, String theIdPart, String theVersionIdPart)
      Specified by:
      setParts in interface org.hl7.fhir.instance.model.api.IIdType