Skip to content

Commit

Permalink
Fixed all issues with the allergies indexer and returned them in the …
Browse files Browse the repository at this point in the history
…json from the server
  • Loading branch information
k-joseph committed Jun 25, 2015
1 parent c133b26 commit cc20f91
Show file tree
Hide file tree
Showing 4 changed files with 758 additions and 753 deletions.
Expand Up @@ -38,7 +38,6 @@
import org.openmrs.module.chartsearch.cache.ChartSearchNote;
import org.openmrs.module.chartsearch.solr.ChartSearchSearcher;


/**
* Responsible for generating the JSON object to be returned to the view(s)
*/
Expand All @@ -56,7 +55,7 @@ public static String generateJson(boolean wholePageIsToBeLoaded) {

JSONObject jsonToReturn = new JSONObject();
@SuppressWarnings("rawtypes")
List returnedResults = SearchAPI.getInstance().getResults();
List<ChartListItem> returnedResults = SearchAPI.getInstance().getResults();
boolean foundNoResults = false;
JSONObject noResults = new JSONObject();
String searchPhrase = SearchAPI.getInstance().getSearchPhrase().getPhrase();
Expand Down Expand Up @@ -92,13 +91,15 @@ public static String generateJson(boolean wholePageIsToBeLoaded) {
JSONArray bookmarks = getAllSearchBookmarksToReturnToUI(wholePageIsToBeLoaded);
List<String> catNms = SearchAPI.getSelectedCategoryNames();
String[] appliedCats = new String[catNms.size()];
JSONArray allergies = generateAllergiesJSONFromResults(returnedResults);

jsonToReturn.put("noResults", noResults);
jsonToReturn.put("retrievalTime", SearchAPI.getInstance().getRetrievalTime());
jsonToReturn.put("searchSuggestions", searchSuggestions);
jsonToReturn.put("searchHistory", history);
jsonToReturn.put("searchBookmarks", bookmarks);
jsonToReturn.put("appliedFacets", (String[]) catNms.toArray(appliedCats));
jsonToReturn.put("patientAllergies", allergies);

addBothPersonalAndGlobalNotesToJSON(searchPhrase, patientId, jsonToReturn, wholePageIsToBeLoaded);

Expand Down Expand Up @@ -524,6 +525,42 @@ public static Set<Obs> generateObsSinglesFromSearchResults() {
return obsSingles;
}

public static JSONArray generateAllergiesJSONFromResults(List<ChartListItem> returnedResults) {
JSONArray allergies = new JSONArray();

for (ChartListItem item : returnedResults) {
if (item != null && item instanceof AllergyItem) {
AllergyItem allergy = (AllergyItem) item;
JSONObject json = new JSONObject();
if (allergy.getAllergyId() != null) {
Integer allergyId = allergy.getAllergyId();
String allergyUuid = allergy.getUuid();
String allergenCodedName = allergy.getAllergenCodedName();
String allergenNonCodedName = allergy.getAllergenNonCodedName();
String allergenSeverity = allergy.getAllergenSeverity();
String allergenType = allergy.getAllergenType();
String allergenCodedReaction = allergy.getAllergenCodedReaction();
String allergenNonCodedReaction = allergy.getAllergenNonCodedReaction();
String allergenComment = allergy.getAllergenComment();

json.put("allergenId", allergyId);
json.put("allergenUuid", allergyUuid);
json.put("allergenCodedName", allergenCodedName);
json.put("allergenNonCodedName", allergenNonCodedName);
json.put("allergenSeverity", allergenSeverity);
json.put("allergenType", allergenType);
json.put("allergenCodedReaction", allergenCodedReaction);
json.put("allergenNonCodedReaction", allergenNonCodedReaction);
json.put("allergenComment", allergenComment);

allergies.add(json);
}
}
}

return allergies;
}

public static JSONObject generateLocationJson(String location) {
JSONObject jsonLocation = new JSONObject();
jsonLocation.put("location", location);
Expand Down
Expand Up @@ -45,7 +45,7 @@ public void indexPatientAllergies(Integer patientId, SolrServer solrServer) {
}
}
for (Allergy allergy : allergies) {
SolrInputDocument doc = addAllergiesPropertiesToSolrDoc(allergy);
SolrInputDocument doc = addAllergiesPropertiesToSolrDoc(allergy, patientId);

docs.add(doc);
}
Expand All @@ -71,7 +71,7 @@ public void indexPatientAllergies(Integer patientId, SolrServer solrServer) {
}
}

private SolrInputDocument addAllergiesPropertiesToSolrDoc(Allergy allergy) {
private SolrInputDocument addAllergiesPropertiesToSolrDoc(Allergy allergy, Integer patientId) {
SolrInputDocument doc = new SolrInputDocument();

if (allergy != null && allergy.getAllergyId() != null) {
Expand Down Expand Up @@ -104,6 +104,7 @@ private SolrInputDocument addAllergiesPropertiesToSolrDoc(Allergy allergy) {
doc.addField("id", allergy.getUuid());
doc.addField("allergy_id", allergy.getAllergyId());
doc.addField("allergy_coded_name", codedAllegen);
doc.addField("patient_id", patientId);
doc.addField("allergy_non_coded_name", nonCodedAllergen);
doc.addField("allergy_severity", severity);
doc.addField("allergy_type", allergy.getAllergen().getAllergenType());
Expand Down
Expand Up @@ -20,6 +20,7 @@
import org.openmrs.Patient;
import org.openmrs.api.context.Context;
import org.openmrs.module.appui.UiSessionContext;
import org.openmrs.module.chartsearch.AllergyItem;
import org.openmrs.module.chartsearch.ChartListItem;
import org.openmrs.module.chartsearch.EncounterItem;
import org.openmrs.module.chartsearch.FormItem;
Expand Down Expand Up @@ -91,6 +92,9 @@ public static void searchAndReturnResults(SearchPhrase search_phrase, Patient pa
updatedItems.add(chartListItem);
}

if(chartListItem instanceof AllergyItem) {
updatedItems.add(chartListItem);
}
}
//setting results to show.
searchAPIInstance.setResults(updatedItems);
Expand Down

0 comments on commit cc20f91

Please sign in to comment.