Source:
public void testProgramaticallyContainedByReferenceAreStillResolvable() { String sp = "{" + "\"resourceType\": \"SearchParameter\",\n" + " \"id\": \"medicationadministration-ingredient-medication\",\n" + " \"url\": \"<LINK_0>\",\n" + " \"name\": \"MEDICATIONADMINISTRATION-INGREDIENT-MEDICATION\",\n" + " \"status\": \"active\",\n" + " \"code\": \"medicationadministration-ingredient-medication\",\n" + " \"base\": [\n" + " \"MedicationAdministration\"\n" + " ],\n" + " \"type\": \"token\",\n" + " \"description\": \"This search parameter is used to find a MedicationAdministration by contained medication\",\n" + " \"expression\": \"MedicationAdministration.medication.resolve().ingredient.item.as(Reference).resolve().code\",\n" + " \"xpathUsage\": \"normal\"\n" + "}\n"; mySearchParameterDao.create(myFhirCtx.newJsonParser().parseResource(SearchParameter.class, sp)); mySearchParamRegistry.forceRefresh(); Medication ingredient = new Medication(); ingredient.getCode().addCoding().setSystem("system").setCode("code"); Medication medication = new Medication(); medication.addIngredient().setItem(new Reference(ingredient)); MedicationAdministration medAdmin = new MedicationAdministration(); medAdmin.setMedication(new Reference(medication)); myMedicationAdministrationDao.create(medAdmin); runInTransaction(()->{ List<ResourceIndexedSearchParamToken> tokens = myResourceIndexedSearchParamTokenDao .findAll() .stream() .filter(t -> t.getParamName().equals("medicationadministration-ingredient-medication")) .collect(Collectors.toList()); ourLog.info("Tokens: {}", tokens); assertEquals(tokens.toString(), 1, tokens.size()); }); SearchParameterMap map = new SearchParameterMap(); map.add("medicationadministration-ingredient-medication", new TokenParam("system","code")); assertEquals(1, myMedicationAdministrationDao.search(map).size().intValue()); }

Target:
public void testProgramaticallyContainedByReferenceAreStillResolvable() { SearchParameter sp = new SearchParameter(); sp.setUrl("<LINK_0>"); sp.setName("MEDICATIONADMINISTRATION-INGREDIENT-MEDICATION"); sp.setStatus(Enumerations.PublicationStatus.ACTIVE); sp.setCode("medicationadministration-ingredient-medication"); sp.addBase("MedicationAdministration"); sp.setType(Enumerations.SearchParamType.TOKEN); sp.setExpression("MedicationAdministration.medication.resolve().ingredient.item.as(Reference).resolve().code"); mySearchParameterDao.create(sp); mySearchParamRegistry.forceRefresh(); Medication ingredient = new Medication(); ingredient.getCode().addCoding().setSystem("system").setCode("code"); Medication medication = new Medication(); medication.addIngredient().setItem(new Reference(ingredient)); MedicationAdministration medAdmin = new MedicationAdministration(); medAdmin.setMedication(new Reference(medication)); myMedicationAdministrationDao.create(medAdmin); runInTransaction(()->{ List<ResourceIndexedSearchParamToken> tokens = myResourceIndexedSearchParamTokenDao .findAll() .stream() .filter(t -> t.getParamName().equals("medicationadministration-ingredient-medication")) .collect(Collectors.toList()); ourLog.info("Tokens: {}", tokens); assertEquals(tokens.toString(), 1, tokens.size()); }); SearchParameterMap map = new SearchParameterMap(); map.add("medicationadministration-ingredient-medication", new TokenParam("system","code")); assertEquals(1, myMedicationAdministrationDao.search(map).size().intValue()); }