Skip to content

Commit

Permalink
✨ Implement 'encode' function to encode a string to a Base64-encoded …
Browse files Browse the repository at this point in the history
…binary
  • Loading branch information
dogukan10 committed Sep 19, 2024
1 parent 71c66f0 commit 5471818
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.json4s.JsonAST._

import java.time._
import java.time.temporal.Temporal
import java.util.Base64
import scala.concurrent.Await
import scala.concurrent.duration.DurationInt
import scala.language.postfixOps
Expand Down Expand Up @@ -856,7 +857,7 @@ class FhirPathFunctionEvaluator(context: FhirPathEnvironment, current: Seq[FhirP


/**
* String manipulation functions ttp://hl7.org/fhirpath/#string-manipulation
* String manipulation functions http://hl7.org/fhirpath/#string-manipulation
*
* @return
*/
Expand Down Expand Up @@ -1015,6 +1016,13 @@ class FhirPathFunctionEvaluator(context: FhirPathEnvironment, current: Seq[FhirP
current.headOption.map(c => Seq(FhirPathNumber(c.asInstanceOf[FhirPathString].s.length))).getOrElse(Nil)
}

@FhirPathFunction(documentation = "\uD83D\uDCDC Encodes the input string to a Base64-encoded binary.\n\n\uD83D\uDD19 <span style=\"color:#ff0000;\">_@return_</span>\n```\nZmluYWw=\n``` \n\uD83D\uDCA1 **E.g.** 'final'.encode()",
insertText = "encode()", detail = "", label = "encode", kind = "Method", returnType = Seq("base64Binary"), inputType = Seq("string"))
def encode(): Seq[FhirPathResult] = {
checkSingleString()
current.headOption.map(c => Seq(FhirPathString(Base64.getEncoder.encodeToString(c.asInstanceOf[FhirPathString].s.getBytes("UTF-8"))))).getOrElse(Nil)
}

/**
* Tree navigation function http://hl7.org/fhirpath/#tree-navigation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ class FhirPathEvaluatorTest extends Specification {
//length
FhirPathEvaluator().evaluateNumerical("Observation.performer.display.length()", observation) mustEqual Seq(12)
FhirPathEvaluator().evaluate("{}", observation) must empty
//encode
FhirPathEvaluator().evaluateString("Observation.status.encode()", observation).head mustEqual "ZmluYWw="
}
"evaluate paths with tree navigation functions" in {
FhirPathEvaluator().evaluate("Questionnaire.children()", questionnaire).length mustEqual 12
Expand Down

0 comments on commit 5471818

Please sign in to comment.