Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RA-340 Include results from Proficient Locales when adding diagnosis … #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
import org.openmrs.ConceptSearchResult;
import org.openmrs.ConceptSource;
import org.openmrs.api.ConceptService;
import org.openmrs.api.context.Context;
import org.openmrs.api.impl.BaseOpenmrsService;
import org.openmrs.module.emrapi.EmrApiProperties;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -102,10 +107,26 @@ public Concept getConcept(String mappingOrUuid) {

@Override
public List<ConceptSearchResult> conceptSearch(String query, Locale locale, Collection<ConceptClass> classes, Collection<Concept> inSets, Collection<ConceptSource> sources, Integer limit) {
if (limit == null) {
limit = 100;
}
return dao.conceptSearch(query, locale, classes, inSets, sources, limit);
List<ConceptSearchResult> csr=new ArrayList<ConceptSearchResult>();
if (limit == null) {
limit = 100;
}
Set<Locale>locales=new LinkedHashSet<Locale>();
List<Locale> allLocales=Context.getAdministrationService().getSearchLocales();
locales.add(locale);
for(Locale l:allLocales) {
locales.add(l);

}
if(locales!=null) {
for(Locale proficientlocale:locales) {
List<ConceptSearchResult> profconceptSearchResults=dao.conceptSearch(query, proficientlocale, classes, inSets, sources, limit);
if(profconceptSearchResults!=null) {
csr.addAll(profconceptSearchResults);
}
}
}
return csr;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,22 @@ public void testConceptSearchInAnotherLocale() throws Exception {
ConceptClass diagnosis = conceptService.getConceptClassByName("Diagnosis");

List<ConceptSearchResult> searchResults = emrConceptService.conceptSearch("malaria", Locale.FRENCH, Collections.singleton(diagnosis), null, null, null);
ConceptSearchResult firstResult = searchResults.get(0);

assertThat(searchResults.size(), is(1));
assertThat(firstResult.getConcept(), is(concepts.get("cerebral malaria")));
assertThat(firstResult.getConceptName().getName(), is("Malaria célébrale"));
/* Result in proficient_Locale are included which is en in this case
*/
assertThat(searchResults.size(), is(3));

ConceptSearchResult firstResult = searchResults.get(0);
ConceptSearchResult secondResult = searchResults.get(1);
ConceptSearchResult thirdResult = searchResults.get(2);

assertThat(firstResult.getConcept(), is(concepts.get("cerebral malaria")));
assertThat(firstResult.getConceptName().getName(), is("Malaria célébrale"));

assertThat(secondResult.getConcept(), is(concepts.get("malaria")));
assertThat(secondResult.getConceptName().getName(), is("Malaria"));

assertThat(thirdResult.getConcept(), is(concepts.get("cerebral malaria")));
assertThat(thirdResult.getConceptName().getName(), is("Cerebral Malaria"));
}

@Test
Expand Down