Skip to content

Commit

Permalink
add another special modifier :nsw for token search for not starts with
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuncay NAMLI committed Sep 15, 2020
1 parent 586f930 commit 71d10a2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion onfhir-common/src/main/scala/io/onfhir/api/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ package object api {
val IN = ":in"
val NOT_IN = ":not-in"
val OF_TYPE = ":of-type"
val STARTS_WITH = ":sw" // onFHIR specific extension for handling starts-with queries in coded fields
// onFHIR specific extension for handling starts-with queries in coded fields
val STARTS_WITH = ":sw"
val NOT_STARTS_WITH=":nsw"

// Prefixes
val DESCENDING="-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ object FHIRSearchParameterValueParser {
override def dataType:Parser[String] = tokenType | boolean

/* Suffix Definitions for Token */
override def suffixes:Parser[String] = """(:(missing|text|in|below|above|not-in|not|of-type|sw))|$""".r ^^ {_.toString}
override def suffixes:Parser[String] = """(:(missing|text|in|below|above|not-in|not|of-type|sw|nsw))|$""".r ^^ {_.toString}
override def prefixes:Parser[String] = """""".r

def parseTokenName:Parser[(String, String)] = parseName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ object PrefixModifierHandler {
//Without modifier
case "" =>
handleTokenCodeSystemQuery(systemPath, codePath, system, code)
case FHIR_PREFIXES_MODIFIERS.STARTS_WITH =>
handleTokenStartsWithModifier(systemPath, codePath, system, code)
case FHIR_PREFIXES_MODIFIERS.STARTS_WITH | FHIR_PREFIXES_MODIFIERS.NOT_STARTS_WITH =>
handleTokenStartsWithModifier(systemPath, codePath, system, code, modifier == FHIR_PREFIXES_MODIFIERS.NOT_STARTS_WITH)
case FHIR_PREFIXES_MODIFIERS.IN | FHIR_PREFIXES_MODIFIERS.NOT_IN =>
handleTokenInModifier(systemPath, codePath, code.get, modifier)
case FHIR_PREFIXES_MODIFIERS.BELOW | FHIR_PREFIXES_MODIFIERS.ABOVE =>
Expand All @@ -347,11 +347,13 @@ object PrefixModifierHandler {
* @param code
* @return
*/
private def handleTokenStartsWithModifier(systemPath:String, codePath:String, system:Option[String], code:Option[String]):Bson = {
private def handleTokenStartsWithModifier(systemPath:String, codePath:String, system:Option[String], code:Option[String], isNot:Boolean):Bson = {
if(code.isEmpty)
throw new InvalidParameterException(s"Code value should be given when modifier ':sw' is used!")
val pattern = Pattern.compile("^"+code.get+"")
val codeStartsWithQuery = Filters.regex(codePath, pattern )
var codeStartsWithQuery = Filters.regex(codePath, pattern )
if(isNot)
codeStartsWithQuery = Filters.not(codeStartsWithQuery)

system match {
// Query like [code] -> the value of [code] matches a Coding.code or Identifier.value irrespective of the value of the system property
Expand Down

0 comments on commit 71d10a2

Please sign in to comment.