Package org.hl7.fhir.utilities
Class VersionUtilities
java.lang.Object
org.hl7.fhir.utilities.VersionUtilities
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic enumstatic class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcheckVersionNotNullAndValid(String s, String label) static intcompareVersions(String ver1, String ver2) given version ver1 and ver2, compare them as semver strings (special values also accepted).static StringfixForSpecialValue(String version) getCanonicalResourceNames(String version) Returns set of canonical resource names for the given FHIR version.static StringReturns the current package version for a given FHIR version family.static StringReturns the current/latest version for a given FHIR version family.getExtendedCanonicalResourceNames(String version) same as getCanonicalResourceNames but add R5 supported types that are canonical toostatic Stringgiven any valid semver string, returns major.minor.static StringgetMajMinPatch(String version) given any valid semver string, returns major.minor.patch.static StringReturns the release name (R2, R3, etc.) for the given version.static Stringgiven any valid semver string, returns just the patch version, with no labels.static StringgetResourceTypesUrl(String version) Returns the resource types URL for the given FHIR version.static StringgetSpecUrl(String v) Returns the specification URL for the given FHIR version.static StringExtracts FHIR version from package ID.static booleanincludedInRange(String startVer, String stopVer, String ver) true of ver is included in the range bounded by startVer and stopVer (or matches - bounds and inclusive)static Stringgiven any semver, increment the major version and reset the minor and patch to .0.0, and remove any labelsstatic Stringgiven any semver, increment the minor version and reset the patch to .0 and remove any labelsstatic Stringgiven any semver, increment the patch and remove any labelsstatic booleanChecks if the given string is a FHIR core package name.static booleanChecks if version refers to any R2B release.static booleanChecks if version refers to any R2 release.static booleanChecks if version refers to any R3 release.static booleanChecks if version refers to any R4B release.static booleanreturns true if version refers to any R4 release (including pre-release versions starting from 3.2) (including rX/RX variants)static booleanChecks if version refers to any R4 release (including 3.2+ pre-releases).static booleanreturns true if version refers to any R5 release (including pre-release versions starting from 4.5) (including rX/RX variants)static booleanChecks if version refers to any R5 release (including 4.5+ pre-releases).static booleanreturns true if version refers to any R6 release (including rX/RX variants)static booleanChecks if version refers to any R6 release.static booleanreturns true if this is a valid semver.static booleanisSemVerWithWildcards(String version) Checks if version string is valid semver with wildcard support.static booleanisSupportedVersion(String version) Checks if the given version is in the list of supported FHIR versions.static booleanisThisOrLater(String criteria, 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.iterateCorePublishedVersions(String startVer, String stopVer) given a range of core versions, list all the ones in the range (accepts either version of special values, returns actual versions)static StringReturns a comma-separated list of all supported major FHIR versions.static StringReturns a comma-separated list of all supported FHIR versions.static StringReturns the package name for the given FHIR version.parseVersionUrl(String url) Parses version information from a FHIR URL.static StringGiven a canonical URL of format {url}|{version}, remove the version partstatic StringversionFromCode(String version) Converts version code to standard version string.static booleanversionHasWildcards(String version) Returns true if the version string contains any wildcard characters.static booleanversionMatches(String criteria, 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.static booleanversionMatchesList(String v1, List<String> v2l) returns true if v1 matches any v2 using the rules for @versionMatches()static StringversionWithoutLabels(String version) Returns version string with labels (pre-release/build info) removed.
-
Field Details
-
SUPPORTED_MAJOR_VERSIONS
-
SUPPORTED_VERSIONS
-
-
Constructor Details
-
VersionUtilities
public VersionUtilities()
-
-
Method Details
-
packageForVersion
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
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
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
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
returns true if version refers to any R6 release (including rX/RX variants) -
isR6Ver
Checks if version refers to any R6 release.- Parameters:
version- version string to check- Returns:
- true if R6 version
-
isR5Plus
returns true if version refers to any R5 release (including pre-release versions starting from 4.5) (including rX/RX variants) -
isR5Ver
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
Checks if version refers to any R4B release.- Parameters:
version- version string to check- Returns:
- true if R4B version
-
isR4Ver
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
returns true if version refers to any R4 release (including pre-release versions starting from 3.2) (including rX/RX variants) -
isR3Ver
Checks if version refers to any R3 release.- Parameters:
version- version string to check- Returns:
- true if R3 version
-
isR2BVer
Checks if version refers to any R2B release.- Parameters:
version- version string to check- Returns:
- true if R2B version
-
isR2Ver
Checks if version refers to any R2 release.- Parameters:
version- version string to check- Returns:
- true if R2 version
-
isCorePackage
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
Returns version string with labels (pre-release/build info) removed.- Parameters:
version- version string- Returns:
- version without labels, or null if invalid
-
getMajMin
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
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
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
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
Checks if version string is valid semver with wildcard support.- Parameters:
version- version string to validate- Returns:
- true if valid semver with wildcards
-
versionHasWildcards
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 tocandidate- The value being comparedprecision- 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.5andcurrent = 0.6this method will return true
-
incMajorVersion
given any semver, increment the major version and reset the minor and patch to .0.0, and remove any labels -
incMinorVersion
given any semver, increment the minor version and reset the patch to .0 and remove any labels -
incPatchVersion
given any semver, increment the patch and remove any labels -
versionFromCode
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
Returns set of canonical resource names for the given FHIR version.- Parameters:
version- FHIR version string- Returns:
- set of canonical resource type names
-
getVersionForPackage
Extracts FHIR version from package ID.- Parameters:
pid- package ID string- Returns:
- version string or null if not extractable
-
versionMatches
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
returns true if v1 matches any v2 using the rules for @versionMatches() -
removeVersionFromCanonical
Given a canonical URL of format {url}|{version}, remove the version part -
getSpecUrl
Returns the specification URL for the given FHIR version.- Parameters:
v- FHIR version string- Returns:
- specification URL
-
getNameForVersion
Returns the release name (R2, R3, etc.) for the given version.- Parameters:
v- FHIR version string- Returns:
- release name (e.g., "R4", "R5")
-
compareVersions
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
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
-
fixForSpecialValue
-