From 56cbc5149ba2ac45965c7d14c2ec71bc58971236 Mon Sep 17 00:00:00 2001 From: ianmarshall Date: Mon, 8 Jun 2020 09:24:09 -0400 Subject: [PATCH] Add support for partial code description matching. --- .../jpa/search/lastn/ElasticsearchSvcImpl.java | 8 ++++---- .../search/lastn/ObservationCodeIndexSchema.json | 4 ++-- .../jpa/search/lastn/ObservationIndexSchema.json | 6 +++--- ...astNElasticsearchSvcMultipleObservationsIT.java | 14 ++++++++------ 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/lastn/ElasticsearchSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/lastn/ElasticsearchSvcImpl.java index 19df63325fb..92055d226ae 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/lastn/ElasticsearchSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/lastn/ElasticsearchSvcImpl.java @@ -412,8 +412,8 @@ public class ElasticsearchSvcImpl implements IElasticsearchSvc { if (textOnlyList.size() > 0) { BoolQueryBuilder myTextBoolQueryBuilder = QueryBuilders.boolQuery(); for (String textOnlyParam : textOnlyList) { - myTextBoolQueryBuilder.should(QueryBuilders.matchPhraseQuery("categoryconceptcodingdisplay", textOnlyParam)); - myTextBoolQueryBuilder.should(QueryBuilders.matchPhraseQuery("categoryconcepttext", textOnlyParam)); + myTextBoolQueryBuilder.should(QueryBuilders.matchQuery("categoryconceptcodingdisplay", textOnlyParam)); + myTextBoolQueryBuilder.should(QueryBuilders.matchQuery("categoryconcepttext", textOnlyParam)); } theBoolQueryBuilder.must(myTextBoolQueryBuilder); } @@ -510,8 +510,8 @@ public class ElasticsearchSvcImpl implements IElasticsearchSvc { if (textOnlyList.size() > 0) { BoolQueryBuilder myTextBoolQueryBuilder = QueryBuilders.boolQuery(); for (String textOnlyParam : textOnlyList) { - myTextBoolQueryBuilder.should(QueryBuilders.matchPhraseQuery("codeconceptcodingdisplay", textOnlyParam)); - myTextBoolQueryBuilder.should(QueryBuilders.matchPhraseQuery("codeconcepttext", textOnlyParam)); + myTextBoolQueryBuilder.should(QueryBuilders.matchQuery("codeconceptcodingdisplay", textOnlyParam)); + myTextBoolQueryBuilder.should(QueryBuilders.matchQuery("codeconcepttext", textOnlyParam)); } theBoolQueryBuilder.must(myTextBoolQueryBuilder); } diff --git a/hapi-fhir-jpaserver-base/src/main/resources/ca/uhn/fhir/jpa/search/lastn/ObservationCodeIndexSchema.json b/hapi-fhir-jpaserver-base/src/main/resources/ca/uhn/fhir/jpa/search/lastn/ObservationCodeIndexSchema.json index acedddf3490..9387f7b901e 100644 --- a/hapi-fhir-jpaserver-base/src/main/resources/ca/uhn/fhir/jpa/search/lastn/ObservationCodeIndexSchema.json +++ b/hapi-fhir-jpaserver-base/src/main/resources/ca/uhn/fhir/jpa/search/lastn/ObservationCodeIndexSchema.json @@ -12,13 +12,13 @@ "type" : "keyword" }, "codingdisplay" : { - "type" : "keyword" + "type" : "text" }, "codingsystem" : { "type" : "keyword" }, "text" : { - "type" : "keyword" + "type" : "text" } } } diff --git a/hapi-fhir-jpaserver-base/src/main/resources/ca/uhn/fhir/jpa/search/lastn/ObservationIndexSchema.json b/hapi-fhir-jpaserver-base/src/main/resources/ca/uhn/fhir/jpa/search/lastn/ObservationIndexSchema.json index a91869e41d5..5f76e5de590 100644 --- a/hapi-fhir-jpaserver-base/src/main/resources/ca/uhn/fhir/jpa/search/lastn/ObservationIndexSchema.json +++ b/hapi-fhir-jpaserver-base/src/main/resources/ca/uhn/fhir/jpa/search/lastn/ObservationIndexSchema.json @@ -18,10 +18,10 @@ "type" : "keyword" }, "codeconceptcodingdisplay" : { - "type" : "keyword" + "type" : "text" }, "categoryconcepttext" : { - "type" : "keyword" + "type" : "text" }, "categoryconceptcodingcode" : { "type" : "keyword" @@ -33,7 +33,7 @@ "type" : "keyword" }, "categoryconceptcodingdisplay" : { - "type" : "keyword" + "type" : "text" }, "effectivedtm" : { "type" : "date" diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsIT.java index e02cc26f229..e117fd946c7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsIT.java @@ -196,9 +196,9 @@ public class LastNElasticsearchSvcMultipleObservationsIT { SearchParameterMap searchParameterMap = new SearchParameterMap(); ReferenceParam subjectParam = new ReferenceParam("Patient", "", "3"); searchParameterMap.add(Observation.SP_SUBJECT, buildReferenceAndListParam(subjectParam)); - TokenParam categoryParam = new TokenParam("test-heart-rate"); + TokenParam categoryParam = new TokenParam(null, "test-heart-rate"); searchParameterMap.add(Observation.SP_CATEGORY, buildTokenAndListParam(categoryParam)); - TokenParam codeParam = new TokenParam("test-code-1"); + TokenParam codeParam = new TokenParam(null,"test-code-1"); searchParameterMap.add(Observation.SP_CODE, buildTokenAndListParam(codeParam)); searchParameterMap.setLastNMax(100); @@ -230,10 +230,12 @@ public class LastNElasticsearchSvcMultipleObservationsIT { SearchParameterMap searchParameterMap = new SearchParameterMap(); ReferenceParam subjectParam = new ReferenceParam("Patient", "", "3"); searchParameterMap.add(Observation.SP_SUBJECT, buildReferenceAndListParam(subjectParam)); - TokenParam categoryParam = new TokenParam("test-heart-rate display"); + // Check partial text + TokenParam categoryParam = new TokenParam("est-heart-ra"); categoryParam.setModifier(TokenParamModifier.TEXT); searchParameterMap.add(Observation.SP_CATEGORY, buildTokenAndListParam(categoryParam)); - TokenParam codeParam = new TokenParam("test-code-1 display"); + // Check partial text + TokenParam codeParam = new TokenParam("est-code-on"); codeParam.setModifier(TokenParamModifier.TEXT); searchParameterMap.add(Observation.SP_CODE, buildTokenAndListParam(codeParam)); searchParameterMap.setLastNMax(100); @@ -414,13 +416,13 @@ public class LastNElasticsearchSvcMultipleObservationsIT { CodeJson codeJson1 = new CodeJson(); codeJson1.setCodeableConceptText("Test Codeable Concept Field for First Code"); codeJson1.setCodeableConceptId(codeableConceptId1); - codeJson1.addCoding("http://mycodes.org/fhir/observation-code", "test-code-1", "test-code-1 display"); + codeJson1.addCoding("http://mycodes.org/fhir/observation-code", "test-code-1", "test-code-one display"); String codeableConceptId2 = UUID.randomUUID().toString(); CodeJson codeJson2 = new CodeJson(); codeJson2.setCodeableConceptText("Test Codeable Concept Field for Second Code"); codeJson2.setCodeableConceptId(codeableConceptId1); - codeJson2.addCoding("http://mycodes.org/fhir/observation-code", "test-code-2", "test-code-2 display"); + codeJson2.addCoding("http://mycodes.org/fhir/observation-code", "test-code-2", "test-code-two display"); // Create CodeableConcepts for two categories, each with three codings. // Create three codings and first category CodeableConcept