Navigation Menu

Skip to content

Commit

Permalink
Added allergies to search suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
k-joseph committed Jun 29, 2015
1 parent f0454f5 commit 14e0690
Showing 1 changed file with 19 additions and 4 deletions.
Expand Up @@ -35,6 +35,9 @@
import org.openmrs.api.ObsService;
import org.openmrs.api.context.Context;
import org.openmrs.api.impl.BaseOpenmrsService;
import org.openmrs.module.allergyapi.Allergies;
import org.openmrs.module.allergyapi.Allergy;
import org.openmrs.module.allergyapi.api.PatientService;
import org.openmrs.module.chartsearch.GeneratingJson;
import org.openmrs.module.chartsearch.api.ChartSearchService;
import org.openmrs.module.chartsearch.api.db.CategoryFilterDAO;
Expand All @@ -50,7 +53,6 @@
import org.openmrs.util.PrivilegeConstants;
import org.springframework.transaction.annotation.Transactional;


/**
* It is a default implementation of {@link ChartSearchService}.
*/
Expand Down Expand Up @@ -330,21 +332,34 @@ public void indexAllPatientData(Integer numberOfResults, SolrServer solrServer,
@Override
public List<String> getAllPossibleSearchSuggestions(Integer patientId) {
ObsService obsService = Context.getObsService();
List<String> conceptNameSuggestions = new ArrayList<String>();
List<String> suggestions = new ArrayList<String>();

List<Obs> allPatientObs = obsService.getObservationsByPerson(new Patient(patientId));
Allergies allAllergies = Context.getService(PatientService.class).getAllergies(
Context.getPatientService().getPatient(patientId));

for (Obs currentObs : allPatientObs) {
if (currentObs != null && currentObs.getConcept() != null && currentObs.getConcept().getName() != null) {
String currentConceptName = currentObs.getConcept().getName().getName();
if (StringUtils.isNotBlank(currentConceptName)) {
conceptNameSuggestions.add(currentConceptName);
suggestions.add(currentConceptName);
}
}
}
//TODO add previous search terms, allergies and appointments to conceptNameSuggestions list
for (Allergy allergy : allAllergies) {
if (allergy != null) {
String nonCoded = allergy.getAllergen().getNonCodedAllergen();
String coded = allergy.getAllergen().getCodedAllergen().getName().getName();
if (StringUtils.isNotBlank(nonCoded)) {
suggestions.add(nonCoded);
} else {
suggestions.add(coded);
}
}
}

return conceptNameSuggestions;
return suggestions;
}

@Override
Expand Down

0 comments on commit 14e0690

Please sign in to comment.