Skip to content

Commit

Permalink
Included Returned allergies after search among returned results
Browse files Browse the repository at this point in the history
  • Loading branch information
k-joseph committed Jun 28, 2015
1 parent f1cae45 commit 73ae6f3
Show file tree
Hide file tree
Showing 7 changed files with 1,237 additions and 1,037 deletions.
12 changes: 12 additions & 0 deletions api/src/main/java/org/openmrs/module/chartsearch/AllergyItem.java
Expand Up @@ -9,6 +9,8 @@
*/
package org.openmrs.module.chartsearch;

import java.util.Date;

public class AllergyItem extends ChartListItem {

private Integer allergyId;
Expand All @@ -27,6 +29,8 @@ public class AllergyItem extends ChartListItem {

private String allergenComment;

private Date allergenDate;

public Integer getAllergyId() {
return allergyId;
}
Expand Down Expand Up @@ -91,4 +95,12 @@ public void setAllergenComment(String allergenComment) {
this.allergenComment = allergenComment;
}

public Date getAllergenDate() {
return allergenDate;
}

public void setAllergenDate(Date allergenDate) {
this.allergenDate = allergenDate;
}

}
Expand Up @@ -542,6 +542,7 @@ public static JSONArray generateAllergiesJSONFromResults(List<ChartListItem> ret
json.put("allergenCodedReaction", allergy.getAllergenCodedReaction());
json.put("allergenNonCodedReaction", allergy.getAllergenNonCodedReaction());
json.put("allergenComment", allergy.getAllergenComment());
json.put("allergenDate", allergy.getAllergenDate().getTime());

allergies.add(json);
}
Expand Down
Expand Up @@ -14,6 +14,7 @@
import java.util.Collection;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.UpdateResponse;
Expand Down Expand Up @@ -79,7 +80,7 @@ private SolrInputDocument addAllergiesPropertiesToSolrDoc(Allergy allergy, Integ
List<AllergyReaction> reactions = allergy.getReactions();
String codedAllegen = null;
String severity = null;
String codedReaction = null;
String codedReaction = "";
String nonCodedReactions = null;

if (allergy.getAllergen().getCodedAllergen() != null) {
Expand All @@ -93,10 +94,20 @@ private SolrInputDocument addAllergiesPropertiesToSolrDoc(Allergy allergy, Integ
for (int i = 0; i < reactions.size(); i++) {
AllergyReaction reaction = reactions.get(i);

nonCodedReactions = reaction.getReactionNonCoded();
if (reaction.getReaction() != null) {
ConceptName codedReactioncName = reaction.getReaction().getName();
codedReaction = codedReactioncName.getName();
if (StringUtils.isNotBlank(reaction.getReactionNonCoded())) {
nonCodedReactions = reaction.getReactionNonCoded();
break;
} else {
if (reaction.getReaction() != null) {
String codedReactioncName = reaction.getReaction().getName().getName();
if (StringUtils.isNotBlank(codedReactioncName)) {
if (i == reactions.size() - 1) {
codedReaction += codedReactioncName;
} else {
codedReaction += codedReactioncName + ", ";
}
}
}
}

}
Expand All @@ -111,6 +122,8 @@ private SolrInputDocument addAllergiesPropertiesToSolrDoc(Allergy allergy, Integ
doc.addField("allergy_coded_reaction", codedReaction);
doc.addField("allergy_non_coded_reaction", nonCodedReactions);
doc.addField("allergy_comment", allergy.getComment());
doc.addField("allergy_date",
allergy.getDateChanged() != null ? allergy.getDateChanged() : allergy.getDateCreated());
}
return doc;
}
Expand Down
Expand Up @@ -245,6 +245,7 @@ private void searchAllergiesAndGenerateSolrDoc(Integer patientId, String searchT
item.setAllergenCodedReaction((String) document.get("allergy_coded_reaction"));
item.setAllergenNonCodedReaction((String) document.get("allergy_non_coded_reaction"));
item.setAllergenComment((String) document.get("allergy_comment"));
item.setAllergenDate((Date) document.get("allergy_date"));

list.add(item);

Expand Down
66 changes: 39 additions & 27 deletions omod/src/main/webapp/fragments/topArea.gsp
Expand Up @@ -271,17 +271,12 @@
if (typeof single_obsJSON !== 'undefined') {
if(key.keyCode == 39) {// =>>
var diffBtnIndecs = navigationIndex - peviousIndex;
var numberOfResults = jsonAfterParse.obs_groups.length + jsonAfterParse.obs_singles.length;
var numberOfResults = jsonAfterParse.obs_groups.length + jsonAfterParse.obs_singles.length + jsonAfterParse.patientAllergies.length;
if(wasGoingNext) {
if(navigationIndex != numberOfResults) {
if(navigationIndex >= 0 && diffBtnIndecs == 1) {
var obsId = single_obsJSON[navigationIndex].observation_id;
peviousIndex = navigationIndex;
navigationIndex++;
wasGoingNext = true;
focusOnNextObsAndDisplayItsDetails(obsId);
increamentNavigation(single_obsJSON);
}
}
} else {
Expand All @@ -291,12 +286,7 @@
navigationIndex = 1;
}
if(navigationIndex >= 0 && diffBtnIndecs == -1) {
var obsId = single_obsJSON[navigationIndex].observation_id;
peviousIndex = navigationIndex;
navigationIndex++;
wasGoingNext = true;
focusOnNextObsAndDisplayItsDetails(obsId);
increamentNavigation(single_obsJSON);
}
}
}
Expand All @@ -308,35 +298,57 @@
navigationIndex = navigationIndex - 2;
if(navigationIndex >= 0 && diffBtnIndecs == 1) {
var obsId = single_obsJSON[navigationIndex].observation_id;
peviousIndex = navigationIndex;
navigationIndex--;
wasGoingNext = false;
focusOnNextObsAndDisplayItsDetails(obsId);
decreamentNavigation(single_obsJSON);
}
} else {
if(navigationIndex >= 0 && diffBtnIndecs == -1) {
var obsId = single_obsJSON[navigationIndex].observation_id;
peviousIndex = navigationIndex;
navigationIndex--;
wasGoingNext = false;
focusOnNextObsAndDisplayItsDetails(obsId);
decreamentNavigation(single_obsJSON);
}
}
}
}
}
});
function increamentNavigation(single_obsJSON) {
var obs = single_obsJSON[navigationIndex];
var allergy = jsonAfterParse.patientAllergies[navigationIndex - (jsonAfterParse.obs_groups.length + jsonAfterParse.obs_singles.length)];
peviousIndex = navigationIndex;
navigationIndex++;
wasGoingNext = true;
if(obs && obs.observation_id) {
focusOnNextObsAndDisplayItsDetails(obs.observation_id);
} else if(allergy && allergy.allergenId > 0) {
focusOnNextAllergenAndDisplayItsDetails(allergy.allergenId);
}
}
function decreamentNavigation(single_obsJSON) {
var obs = single_obsJSON[navigationIndex];
var allergy = jsonAfterParse.patientAllergies[navigationIndex - (jsonAfterParse.obs_groups.length + jsonAfterParse.obs_singles.length)];
peviousIndex = navigationIndex;
navigationIndex--;
wasGoingNext = false;
if(obs && obs.observation_id) {
focusOnNextObsAndDisplayItsDetails(obs.observation_id);
} else if(allergy && allergy.allergenId > 0) {
focusOnNextAllergenAndDisplayItsDetails(allergy.allergenId);
}
}
function focusOnNextObsAndDisplayItsDetails(obsId) {
jq('#obs_single_'+obsId).focus();
load_single_detailed_obs(obsId);
}
function focusOnNextAllergenAndDisplayItsDetails(allergenId) {
jq('#allergen_' + allergenId).focus();
load_allergen(allergenId);
}
function hideSearchSuggestions() {
jq("#chart-searches-suggestions").hide();
}
Expand Down

0 comments on commit 73ae6f3

Please sign in to comment.