Class VersionUtilities

java.lang.Object
org.hl7.fhir.utilities.VersionUtilities

public class VersionUtilities extends Object
  • Field Details

  • Constructor Details

  • Method Details

    • packageForVersion

      @Nonnull public static String packageForVersion(@Nonnull String v)
      Returns the package name for the given FHIR version.
      Parameters:
      v - FHIR version string
      Returns:
      package name (e.g., "hl7.fhir.r4.core") or null if version not recognized
    • getCurrentVersion

      public static String getCurrentVersion(String v)
      Returns the current/latest version for a given FHIR version family.
      Parameters:
      v - FHIR version string
      Returns:
      current version string for that family
    • getCurrentPackageVersion

      Returns the current package version for a given FHIR version family.
      Parameters:
      v - FHIR version string
      Returns:
      package version (major.minor format)
    • isSupportedVersion

      public static boolean isSupportedVersion(@Nonnull String version)
      Checks if the given version is in the list of supported FHIR versions.
      Parameters:
      version - version string to check
      Returns:
      true if version is supported
    • listSupportedVersions

      public static String listSupportedVersions()
      Returns a comma-separated list of all supported FHIR versions.
      Returns:
      string listing supported versions
    • listSupportedMajorVersions

      Returns a comma-separated list of all supported major FHIR versions.
      Returns:
      string listing supported major versions
    • isR6Plus

      public static boolean isR6Plus(String version)
      returns true if version refers to any R6 release (including rX/RX variants)
    • isR6Ver

      public static boolean isR6Ver(@Nonnull String version)
      Checks if version refers to any R6 release.
      Parameters:
      version - version string to check
      Returns:
      true if R6 version
    • isR5Plus

      public static boolean isR5Plus(String version)
      returns true if version refers to any R5 release (including pre-release versions starting from 4.5) (including rX/RX variants)
    • isR5Ver

      public static boolean isR5Ver(@Nonnull String version)
      Checks if version refers to any R5 release (including 4.5+ pre-releases).
      Parameters:
      version - version string to check
      Returns:
      true if R5 version
    • isR4BVer

      public static boolean isR4BVer(@Nonnull String version)
      Checks if version refers to any R4B release.
      Parameters:
      version - version string to check
      Returns:
      true if R4B version
    • isR4Ver

      public static boolean isR4Ver(@Nonnull String version)
      Checks if version refers to any R4 release (including 3.2+ pre-releases).
      Parameters:
      version - version string to check
      Returns:
      true if R4 version
    • isR4Plus

      public static boolean isR4Plus(String version)
      returns true if version refers to any R4 release (including pre-release versions starting from 3.2) (including rX/RX variants)
    • isR3Ver

      public static boolean isR3Ver(@Nonnull String version)
      Checks if version refers to any R3 release.
      Parameters:
      version - version string to check
      Returns:
      true if R3 version
    • isR2BVer

      public static boolean isR2BVer(@Nonnull String version)
      Checks if version refers to any R2B release.
      Parameters:
      version - version string to check
      Returns:
      true if R2B version
    • isR2Ver

      public static boolean isR2Ver(@Nonnull String version)
      Checks if version refers to any R2 release.
      Parameters:
      version - version string to check
      Returns:
      true if R2 version
    • isCorePackage

      public static boolean isCorePackage(@Nonnull String s)
      Checks if the given string is a FHIR core package name.
      Parameters:
      s - package name to check
      Returns:
      true if it's a core package
    • versionWithoutLabels

      @Nullable public static String versionWithoutLabels(@Nullable String version)
      Returns version string with labels (pre-release/build info) removed.
      Parameters:
      version - version string
      Returns:
      version without labels, or null if invalid
    • getMajMin

      @Nullable public static String getMajMin(@Nullable String version)
      given any valid semver string, returns major.minor. Also accepts the special values rX/RX where X is a major FHIR version (2,2B,3,4,4B,5,6) returns null if not a valid semver
    • getMajMinPatch

      public static String getMajMinPatch(@Nullable String version)
      given any valid semver string, returns major.minor.patch. Also accepts the special values rX/RX where X is a major FHIR version (2,2B,3,4,4B,5,6) if there's no patch, it will be assumed to be 0 returns null if it's not a valid semver
    • getPatch

      public static String getPatch(@Nullable String version)
      given any valid semver string, returns just the patch version, with no labels. Also accepts the special values rX/RX where X is a major FHIR version (2,2B,3,4,4B,5,6)
    • isSemVer

      public static boolean isSemVer(@Nullable String version)
      returns true if this is a valid semver. Note that we accept major.minor without a patch (but maybe with labels). This routine does not accept the codes such as RX
    • isSemVerWithWildcards

      public static boolean isSemVerWithWildcards(@Nullable String version)
      Checks if version string is valid semver with wildcard support.
      Parameters:
      version - version string to validate
      Returns:
      true if valid semver with wildcards
    • versionHasWildcards

      public static boolean versionHasWildcards(@Nullable String version)
      Returns true if the version string contains any wildcard characters. Supported wildcards are: * (asterisk) anywhere, x/X (in major/minor/patch only), and ? (question mark suffix). Note: x and X are only wildcards in version number parts, not in release labels (after -) or build labels (after +).
      Parameters:
      version - version string to check
      Returns:
      true if version contains any wildcard characters, false otherwise
    • isThisOrLater

      public static boolean isThisOrLater(@Nonnull String criteria, @Nonnull String candidate, VersionUtilities.VersionPrecision precision)
      return true if the current version equals criteria, or later, based on the degree of precision specified This can be used to check e.g. if a feature is defined in 4.0, if (VersionUtilities.isThisOrLater("4.0", version)) this is only applicable to valid semver versions (though patch is optional) the criteria string can contain wildcards - see @versionMatches
      Parameters:
      criteria - The value to compare to
      candidate - The value being compared
      precision - how far into the version string to consider (usually just set to full if there's wildcards in the test string)
      Returns:
      Is current later or equal to criteria? For example, if this = 0.5 and current = 0.6 this method will return true
    • incMajorVersion

      public static String incMajorVersion(String v)
      given any semver, increment the major version and reset the minor and patch to .0.0, and remove any labels
    • incMinorVersion

      @Nonnull public static String incMinorVersion(@Nonnull String v)
      given any semver, increment the minor version and reset the patch to .0 and remove any labels
    • incPatchVersion

      @Nonnull public static String incPatchVersion(@Nonnull String v)
      given any semver, increment the patch and remove any labels
    • versionFromCode

      public static String versionFromCode(String version)
      Converts version code to standard version string.
      Parameters:
      version - version code or string
      Returns:
      standardized version string
    • parseVersionUrl

      Parses version information from a FHIR URL.
      Parameters:
      url - FHIR URL to parse
      Returns:
      VersionURLInfo object or null if not parseable
    • getExtendedCanonicalResourceNames

      same as getCanonicalResourceNames but add R5 supported types that are canonical too
    • getCanonicalResourceNames

      public static Set<String> getCanonicalResourceNames(String version)
      Returns set of canonical resource names for the given FHIR version.
      Parameters:
      version - FHIR version string
      Returns:
      set of canonical resource type names
    • getVersionForPackage

      public static String getVersionForPackage(@Nonnull String pid)
      Extracts FHIR version from package ID.
      Parameters:
      pid - package ID string
      Returns:
      version string or null if not extractable
    • versionMatches

      public static boolean versionMatches(@Nonnull String criteria, @Nonnull String candidate)
      returns true if v1 and v2 are both semver, and they 'match' matching means that the specific version provided in candidate is equal to the value provided by criteria, or is in the set of values defined by the critteria using applicable wildcards e.g. 2.0 matches 2.0 and not 2.0.0, 2.0.1 etc 2.0.0 matches 2.0.0 and not 2.0.1 or 2.0.0-something or 2.0.0+something 2.* matches 2.0 and 2.1 but not 2.0.0 or 2.1-something 2.x.x matches 2.0.1 and 2.1.0 etc but not 2.0 2.0.* matches 2.0.0, 2.0.1, and not 2.0.0-something or 2.0.0+something 2.0.0-* matches 2.0.0-prerelease or any other label but not 2.0.0+build 2.0.0+* matches 2.0.0+build or any other build but not 2.0.0 or 2.0.0-prerelease 2.0.x-* matches 2.0.1-prerelease or 2.0.1-prerelease but not 2.0.0 or 2.0.1 2.0? matches 2.0, 2.0.1, 2.0.0-build etc - anything that starts with 2.0 2.0.1? matches 2.0.1, 2.0.1-release, 2.0.1+build etc - anything that starts with 2.0.1 2.x? matches 2.anything (weird thing to do) wildcard summary: * = anything that goes in this part. (x and X are also acceptable wildcards for minor and patch, but not for release or build labels, where x and X are valid values) ? = anything that goes in this part and ignore the rest of the version. Note that the ? does not follow the part separator.
    • versionMatchesList

      public static boolean versionMatchesList(@Nonnull String v1, @Nonnull List<String> v2l)
      returns true if v1 matches any v2 using the rules for @versionMatches()
    • removeVersionFromCanonical

      @Nullable public static String removeVersionFromCanonical(@Nullable String url)
      Given a canonical URL of format {url}|{version}, remove the version part
    • getSpecUrl

      public static String getSpecUrl(@Nonnull String v)
      Returns the specification URL for the given FHIR version.
      Parameters:
      v - FHIR version string
      Returns:
      specification URL
    • getNameForVersion

      @Nonnull public static String getNameForVersion(@Nonnull String v)
      Returns the release name (R2, R3, etc.) for the given version.
      Parameters:
      v - FHIR version string
      Returns:
      release name (e.g., "R4", "R5")
    • compareVersions

      public static int compareVersions(@Nullable String ver1, @Nullable String ver2)
      given version ver1 and ver2, compare them as semver strings (special values also accepted). -1 means ver1 is earlier, 0 means they 'match' and 1 means ver2 is later (normal java sort order)
    • includedInRange

      public static boolean includedInRange(@Nonnull String startVer, @Nonnull String stopVer, @Nonnull String ver)
      true of ver is included in the range bounded by startVer and stopVer (or matches - bounds and inclusive)

      Special values also accepted e.g. r3 is in r3 to r5

      Parameters:
      ver -
      Returns:
    • getResourceTypesUrl

      public static String getResourceTypesUrl(@Nonnull String version)
      Returns the resource types URL for the given FHIR version.
      Parameters:
      version - FHIR version string
      Returns:
      resource types URL
    • iterateCorePublishedVersions

      public static List<String> iterateCorePublishedVersions(@Nonnull String startVer, @Nonnull String stopVer)
      given a range of core versions, list all the ones in the range (accepts either version of special values, returns actual versions)
    • checkVersionNotNullAndValid

      public static String checkVersionNotNullAndValid(String s, String label)
    • fixForSpecialValue

      public static String fixForSpecialValue(String version)