Source:
private void addObservationCodeCriteria(BoolQueryBuilder theBoolQueryBuilder, SearchParameterMap theSearchParameterMap, FhirContext theFhirContext) { String codeParamName = LastNParameterHelper.getCodeParamName(theFhirContext); if (theSearchParameterMap.containsKey(codeParamName)) { ArrayList<String> codeSystemHashList = new ArrayList<>(); ArrayList<String> codeOnlyList = new ArrayList<>(); ArrayList<String> systemOnlyList = new ArrayList<>(); ArrayList<String> textOnlyList = new ArrayList<>(); List<List<IQueryParameterType>> andOrParams = theSearchParameterMap.get(codeParamName); for (List<? extends IQueryParameterType> nextAnd : andOrParams) { codeSystemHashList.addAll(getCodingCodeSystemValues(nextAnd)); codeOnlyList.addAll(getCodingCodeOnlyValues(nextAnd)); systemOnlyList.addAll(getCodingSystemOnlyValues(nextAnd)); textOnlyList.addAll(getCodingTextOnlyValues(nextAnd)); } if (codeSystemHashList.size() > 0) { theBoolQueryBuilder.must(QueryBuilders.termsQuery("codeconceptcodingcode_system_hash", codeSystemHashList)); } if (codeOnlyList.size() > 0) { theBoolQueryBuilder.must(QueryBuilders.termsQuery("codeconceptcodingcode", codeOnlyList)); } if (systemOnlyList.size() > 0) { theBoolQueryBuilder.must(QueryBuilders.termsQuery("codeconceptcodingsystem", systemOnlyList)); } if (textOnlyList.size() > 0) { BoolQueryBuilder myTextBoolQueryBuilder = QueryBuilders.boolQuery(); for (String textOnlyParam : textOnlyList) { myTextBoolQueryBuilder.should(QueryBuilders.matchPhrasePrefixQuery("codeconceptcodingdisplay", textOnlyParam)); myTextBoolQueryBuilder.should(QueryBuilders.matchPhrasePrefixQuery("codeconcepttext", textOnlyParam)); } theBoolQueryBuilder.must(myTextBoolQueryBuilder); } } }

Target:
private void addObservationCodeCriteria(BoolQueryBuilder theBoolQueryBuilder, SearchParameterMap theSearchParameterMap, FhirContext theFhirContext) { String codeParamName = LastNParameterHelper.getCodeParamName(theFhirContext); if (theSearchParameterMap.containsKey(codeParamName)) { ArrayList<String> codeSystemHashList = new ArrayList<>(); ArrayList<String> codeOnlyList = new ArrayList<>(); ArrayList<String> systemOnlyList = new ArrayList<>(); ArrayList<String> textOnlyList = new ArrayList<>(); List<List<IQueryParameterType>> andOrParams = theSearchParameterMap.get(codeParamName); for (List<? extends IQueryParameterType> nextAnd : andOrParams) { codeSystemHashList.addAll(getCodingCodeSystemValues(nextAnd)); codeOnlyList.addAll(getCodingCodeOnlyValues(nextAnd)); systemOnlyList.addAll(getCodingSystemOnlyValues(nextAnd)); textOnlyList.addAll(getCodingTextOnlyValues(nextAnd)); } if (codeSystemHashList.size() > 0) { theBoolQueryBuilder.must(QueryBuilders.termsQuery(OBSERVATION_CODEHASH_FIELD_NAME, codeSystemHashList)); } if (codeOnlyList.size() > 0) { theBoolQueryBuilder.must(QueryBuilders.termsQuery(OBSERVATION_CODEVALUE_FIELD_NAME, codeOnlyList)); } if (systemOnlyList.size() > 0) { theBoolQueryBuilder.must(QueryBuilders.termsQuery(OBSERVATION_CODESYSTEM_FIELD_NAME, systemOnlyList)); } if (textOnlyList.size() > 0) { BoolQueryBuilder myTextBoolQueryBuilder = QueryBuilders.boolQuery(); for (String textOnlyParam : textOnlyList) { myTextBoolQueryBuilder.should(QueryBuilders.matchPhrasePrefixQuery(OBSERVATION_CODEDISPLAY_FIELD_NAME, textOnlyParam)); myTextBoolQueryBuilder.should(QueryBuilders.matchPhrasePrefixQuery(OBSERVATION_CODE_TEXT_FIELD_NAME, textOnlyParam)); } theBoolQueryBuilder.must(myTextBoolQueryBuilder); } } }