From 142be0f5bcfcf22f53dc70078448c9a5affd4851 Mon Sep 17 00:00:00 2001 From: Tuncay NAMLI Date: Wed, 17 Nov 2021 10:52:50 +0300 Subject: [PATCH] :sparkles: feat: Enable 'not' modifier for URI search parameters. --- .../FHIRSearchParameterValueParser.scala | 2 +- .../io/onfhir/db/PrefixModifierHandler.scala | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/onfhir-common/src/main/scala/io/onfhir/api/parsers/FHIRSearchParameterValueParser.scala b/onfhir-common/src/main/scala/io/onfhir/api/parsers/FHIRSearchParameterValueParser.scala index 879fa692..2c2d6580 100644 --- a/onfhir-common/src/main/scala/io/onfhir/api/parsers/FHIRSearchParameterValueParser.scala +++ b/onfhir-common/src/main/scala/io/onfhir/api/parsers/FHIRSearchParameterValueParser.scala @@ -92,7 +92,7 @@ object FHIRSearchParameterValueParser { override def dataType:Parser[String] = uri | boolean | code /* Prefixes and Suffixes for URI type */ - override def suffixes:Parser[String] = """(:(missing|below|above))|$""".r ^^ {_.toString} + override def suffixes:Parser[String] = """(:(missing|below|above|not))|$""".r ^^ {_.toString} override def prefixes:Parser[String] = """""".r def parseUriName:Parser[(String, String)] = parseName diff --git a/onfhir-core/src/main/scala/io/onfhir/db/PrefixModifierHandler.scala b/onfhir-core/src/main/scala/io/onfhir/db/PrefixModifierHandler.scala index 39b75a98..b80545f5 100644 --- a/onfhir-core/src/main/scala/io/onfhir/db/PrefixModifierHandler.scala +++ b/onfhir-core/src/main/scala/io/onfhir/db/PrefixModifierHandler.scala @@ -267,18 +267,22 @@ object PrefixModifierHandler { val regularExpressionValue = FHIRUtil.escapeCharacters(uri) + "("+ FHIRUtil.escapeCharacters("/")+".*)*" // Match at the beginning of the uri regex(path, "\\A" + regularExpressionValue + "$") - case "" => + case _ => //If this is a query on Canonical URLs of the conformance and knowledge resources (e.g. StructureDefinition, ValueSet, PlanDefinition etc) and a version part is given |[version] - if(path == "url" && uri.contains("|")){ - val canonicalRef = Try(FHIRUtil.parseCanonicalReference(uri)).toOption - if(canonicalRef.exists(_.version.isDefined)) - and(equal(path, canonicalRef.get.getUrl()), equal("version", canonicalRef.get.version.get)) - else + var finalQuery = + if(path == "url" && uri.contains("|")){ + val canonicalRef = Try(FHIRUtil.parseCanonicalReference(uri)).toOption + if(canonicalRef.exists(_.version.isDefined)) + and(equal(path, canonicalRef.get.getUrl()), equal("version", canonicalRef.get.version.get)) + else + equal(path, uri) + } else { + // Exact match equal(path, uri) - } else { - // Exact match - equal(path, uri) - } + } + if(modifier == FHIR_PREFIXES_MODIFIERS.NOT) + finalQuery = not(finalQuery) + finalQuery case other => throw new InvalidParameterException(s"Modifier $other is not supported for FHIR uri queries!") }