diff --git a/fhirpath/src/main/java/au/csiro/pathling/fhirpath/function/ConversionFunctions.java b/fhirpath/src/main/java/au/csiro/pathling/fhirpath/function/ConversionFunctions.java new file mode 100644 index 0000000000..172e70316b --- /dev/null +++ b/fhirpath/src/main/java/au/csiro/pathling/fhirpath/function/ConversionFunctions.java @@ -0,0 +1,42 @@ +package au.csiro.pathling.fhirpath.function; + +import au.csiro.pathling.fhirpath.StringCoercible; +import au.csiro.pathling.fhirpath.collection.Collection; +import au.csiro.pathling.fhirpath.validation.FhirPathFunction; +import au.csiro.pathling.utilities.Preconditions; +import javax.annotation.Nonnull; + +/** + * Functions for converting between different types. + * + * @see FHIRPath Specification - + * Conversion + */ +@SuppressWarnings("unused") +public class ConversionFunctions { + + /** + * If the input collection contains a single item, this function will return a single String if: + * + * If the item is not one of the above types, the result is false. + * + * @param input The input collection + * @return A collection containing the single item as a String, or an empty collection if the + * input collection is empty or contains more than one item. + * @see FHIRPath Specification + * - toString + */ + @FhirPathFunction + @Nonnull + public static Collection toString(@Nonnull final Collection input) { + Preconditions.checkUserInput(input instanceof StringCoercible, + "toString() can only be applied to a StringCoercible path"); + return ((StringCoercible) input).asStringPath(); + } + +} diff --git a/fhirpath/src/main/java/au/csiro/pathling/fhirpath/function/StandardFunctions.java b/fhirpath/src/main/java/au/csiro/pathling/fhirpath/function/StandardFunctions.java index f1301dca6f..199873a2d7 100644 --- a/fhirpath/src/main/java/au/csiro/pathling/fhirpath/function/StandardFunctions.java +++ b/fhirpath/src/main/java/au/csiro/pathling/fhirpath/function/StandardFunctions.java @@ -17,26 +17,12 @@ package au.csiro.pathling.fhirpath.function; -import au.csiro.pathling.fhirpath.StringCoercible; -import au.csiro.pathling.fhirpath.collection.Collection; -import au.csiro.pathling.fhirpath.validation.FhirPathFunction; -import au.csiro.pathling.utilities.Preconditions; -import javax.annotation.Nonnull; - /** * Implementation of standard FHIRPath functions. */ @SuppressWarnings("unused") public class StandardFunctions { - // TODO: This should be a string collection with a StringCoercible argument - @FhirPathFunction - public static Collection toString(@Nonnull final Collection input) { - Preconditions.checkUserInput(input instanceof StringCoercible, - "toString() can only be applied to a StringCoercible path"); - return ((StringCoercible) input).asStringPath(); - } - private StandardFunctions() { }