Skip to content

Commit

Permalink
added allergies item at data-config.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
k-joseph committed Jun 16, 2015
1 parent fef7c97 commit a3a9a58
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 80 deletions.
94 changes: 94 additions & 0 deletions api/src/main/java/org/openmrs/module/chartsearch/AllergyItem.java
@@ -0,0 +1,94 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.chartsearch;

public class AllergyItem extends ChartListItem {

private Integer allergyId;

private String allergenCodedName;

private String allergenNonCodedName;

private String allergenSeverity;

private String allergenType;

private String allergenCodedReaction;

private String allergenNonCodedReaction;

private String allergenComment;

public Integer getAllergyId() {
return allergyId;
}

public void setAllergyId(Integer allergyId) {
this.allergyId = allergyId;
}

public String getAllergenCodedName() {
return allergenCodedName;
}

public void setAllergenCodedName(String allergenCodedName) {
this.allergenCodedName = allergenCodedName;
}

public String getAllergenNonCodedName() {
return allergenNonCodedName;
}

public void setAllergenNonCodedName(String allergenNonCodedName) {
this.allergenNonCodedName = allergenNonCodedName;
}

public String getAllergenSeverity() {
return allergenSeverity;
}

public void setAllergenSeverity(String allergenSeverity) {
this.allergenSeverity = allergenSeverity;
}

public String getAllergenType() {
return allergenType;
}

public void setAllergenType(String allergenType) {
this.allergenType = allergenType;
}

public String getAllergenCodedReaction() {
return allergenCodedReaction;
}

public void setAllergenCodedReaction(String allergenCodedReaction) {
this.allergenCodedReaction = allergenCodedReaction;
}

public String getAllergenNonCodedReaction() {
return allergenNonCodedReaction;
}

public void setAllergenNonCodedReaction(String allergenNonCodedReaction) {
this.allergenNonCodedReaction = allergenNonCodedReaction;
}

public String getAllergenComment() {
return allergenComment;
}

public void setAllergenComment(String allergenComment) {
this.allergenComment = allergenComment;
}

}
Expand Up @@ -334,7 +334,8 @@ public JSONObject returnDefaultSearchPhrase(String currentSPhrase, Integer patie
ChartSearchBookmark defaultBookmark = null;

for (ChartSearchBookmark bookmark : allBookmarks) {
if (bookmark.isDefaultSearch()) {
if (bookmark.isDefaultSearch()
&& bookmark.getBookmarkOwner().getUserId().equals(Context.getAuthenticatedUser().getUserId())) {
defaultBookmark = bookmark;
} else
getDefaultSearchFromHistoryIfItExists(currentSPhrase, json, lastSearchPhraseFromHistory);
Expand Down Expand Up @@ -375,12 +376,14 @@ public JSONArray setBookmarkAsDefaultSearch(String uuid) {
List<ChartSearchBookmark> allBookmarks = chartSearchService.getAllSearchBookmarks();

for (ChartSearchBookmark bookmark : allBookmarks) {
if (bookmark.getUuid().equals(uuid)) {
bookmark.setIsDefaultSearch(true);
} else {
bookmark.setIsDefaultSearch(false);
if (bookmark.getBookmarkOwner().getUserId().equals(Context.getAuthenticatedUser().getUserId())) {
if (bookmark.getUuid().equals(uuid)) {
bookmark.setIsDefaultSearch(true);
} else {
bookmark.setIsDefaultSearch(false);
}
chartSearchService.saveSearchBookmark(bookmark);
}
chartSearchService.saveSearchBookmark(bookmark);
}
}
return GeneratingJson.getAllSearchBookmarksToReturnTomanagerUI(false);
Expand Down
Expand Up @@ -24,12 +24,14 @@
import org.apache.commons.logging.LogFactory;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.FacetField;
import org.apache.solr.client.solrj.response.FacetField.Count;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.params.FacetParams;
import org.openmrs.api.context.Context;
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 @@ -78,19 +80,18 @@ public Long getDocumentListCount(Integer patientId, String searchText) throws Ex

SolrQuery query = new SolrQuery(String.format("text:(%s)", searchText));
query.addFilterQuery(String.format("person_id:%d", patientId));
query.setRows(0); // Intentionally setting to this value such that we
// get the count very quickly.
query.setRows(0); //Intentionally setting to this value such that we
//get the count very quickly.
QueryResponse response = solrServer.query(query);
return response.getResults().getNumFound();
}

@SuppressWarnings("unchecked")
public List<ChartListItem> getDocumentList(Integer patientId, String searchText, Integer start, Integer length,
List<String> selectedCategories) throws Exception {
SolrServer solrServer = SolrSingleton.getInstance().getServer();
SolrQuery query = new SolrQuery();
searchText = StringUtils.isNotBlank(searchText) ? searchText : "*";
//TODO check for existence of characters such as ", and : in the search text and submit as it is if so
//check for existence of characters such as ", and : in the search text and submit as it is if so
if (searchText.contains("\"")) {
String searchWhole = "text:" + searchText;
query.setQuery(searchWhole);
Expand All @@ -99,11 +100,9 @@ public List<ChartListItem> getDocumentList(Integer patientId, String searchText,
} else if (searchText.equals("*")) {
query.setQuery(String.format("text:(%s)", searchText));
} else {
//TODO re-use ChartSearchSntax class hear
ChartSearchSyntax searchSyntax = new ChartSearchSyntax(searchText);
searchText = searchSyntax.getSearchQuery();

// TODO Move to Eli's code
if (StringUtils.isNumeric(searchText)) {
//this allows 36 returning 36.* for numerics
searchText = searchText + ".*" + " || " + searchText;
Expand All @@ -113,20 +112,52 @@ public List<ChartListItem> getDocumentList(Integer patientId, String searchText,

query.addFilterQuery(String.format("person_id:%d", patientId));

//TODO add selected categories to the query here or use all categories
addSelectedFilterQueriesToQuery(query, selectedCategories);

query.setStart(start);
query.setRows(length);
query.setHighlight(true).setHighlightSnippets(1).setHighlightSimplePre("<b>").setHighlightSimplePost("</b>");
query.setParam("hl.fl", "text");

//TODO add facet fields here and if more than one, getAndUseCountsForFacetFields(..)
query.remove(FacetParams.FACET_FIELD);
query.setFacet(true);
//adding facet field for concept_class
query.addFacetField("concept_class_name");

List<ChartListItem> list = searchObservationsAndGenerateSolrDoc(solrServer, query);

searchAllergiesAndGenerateSolrDoc(patientId, searchText, solrServer, list);
searchEncounterTypesAndGenerateSolrDoc(patientId, searchText, solrServer, list);
searchEFormsAndGenerateSolrDoc(searchText, solrServer, list);

return list;
}

private void searchEFormsAndGenerateSolrDoc(String searchText, SolrServer solrServer, List<ChartListItem> list)
throws SolrServerException {
// forms
System.out.println("Forms:");
SolrQuery query2 = new SolrQuery(String.format("form_name:(%s)", searchText));
QueryResponse response2 = solrServer.query(query2);
Iterator<SolrDocument> iter2 = response2.getResults().iterator();

while (iter2.hasNext()) {
SolrDocument document = iter2.next();
FormItem item = new FormItem();
item.setUuid((String) document.get("id"));
item.setEncounterType((String) document.get("encounter_type_name"));
item.setFormId((Integer) document.get("form_id"));
item.setFormName((String) document.get("form_name"));
list.add(item);

System.out.println(document.get("form_id") + ", " + document.get("form_name") + ", "
+ document.get("encounter_type_name"));
}
}

@SuppressWarnings("unchecked")
private List<ChartListItem> searchObservationsAndGenerateSolrDoc(SolrServer solrServer, SolrQuery query)
throws SolrServerException {
System.out.println("Observations:");
QueryResponse response = solrServer.query(query);

Expand Down Expand Up @@ -169,7 +200,11 @@ public List<ChartListItem> getDocumentList(Integer patientId, String searchText,
System.out.println(document.get("obs_id") + ", " + document.get("concept_name") + ", "
+ document.get("obs_datetime"));
}

return list;
}

private void searchEncounterTypesAndGenerateSolrDoc(Integer patientId, String searchText, SolrServer solrServer,
List<ChartListItem> list) throws SolrServerException {
// Encounters
System.out.println("Encounters:");
SolrQuery query3 = new SolrQuery(String.format("encounter_type:(%s)", searchText));
Expand All @@ -188,27 +223,33 @@ public List<ChartListItem> getDocumentList(Integer patientId, String searchText,
System.out.println(document.get("encounter_id") + ", " + document.get("encounter_type") + ", "
+ document.get("encounter_datetime"));
}
}

private void searchAllergiesAndGenerateSolrDoc(Integer patientId, String searchText, SolrServer solrServer,
List<ChartListItem> list) throws SolrServerException {
SolrQuery query4 = new SolrQuery(String.format("allergy_text:(%s)", searchText));

// forms
System.out.println("Forms:");
SolrQuery query2 = new SolrQuery(String.format("form_name:(%s)", searchText));
QueryResponse response2 = solrServer.query(query2);
Iterator<SolrDocument> iter2 = response2.getResults().iterator();
query4.addFilterQuery(String.format("patient_id:%d", patientId));
QueryResponse response4 = solrServer.query(query4);
Iterator<SolrDocument> iter4 = response4.getResults().iterator();

while (iter2.hasNext()) {
SolrDocument document = iter2.next();
FormItem item = new FormItem();
while (iter4.hasNext()) {
SolrDocument document = iter4.next();
AllergyItem item = new AllergyItem();
item.setUuid((String) document.get("id"));
item.setEncounterType((String) document.get("encounter_type_name"));
item.setFormId((Integer) document.get("form_id"));
item.setFormName((String) document.get("form_name"));
item.setAllergyId((Integer) document.get("allergy_id"));
item.setAllergenCodedName((String) document.get("allergy_coded_name"));
item.setAllergenNonCodedName((String) document.get("allergy_non_coded_name"));
item.setAllergenSeverity((String) document.get("allergy_severity"));
item.setAllergenType((String) document.get("allergy_type"));
item.setAllergenCodedReaction((String) document.get("allergy_coded_reaction"));
item.setAllergenNonCodedReaction((String) document.get("allergy_non_coded_reaction"));
item.setAllergenComment((String) document.get("allergy_comment"));

list.add(item);

System.out.println(document.get("form_id") + ", " + document.get("form_name") + ", "
+ document.get("encounter_type_name"));
System.out.println("FOUND ALLERGY: " + document.toString());
}

return list;
}

/**
Expand Down
Expand Up @@ -21,7 +21,6 @@
import org.openmrs.api.context.Context;
import org.openmrs.module.appui.UiSessionContext;
import org.openmrs.module.chartsearch.ChartListItem;
import org.openmrs.module.chartsearch.ChartSearchCache;
import org.openmrs.module.chartsearch.EncounterItem;
import org.openmrs.module.chartsearch.FormItem;
import org.openmrs.module.chartsearch.ObsItem;
Expand Down
2 changes: 1 addition & 1 deletion omod/src/main/webapp/fragments/manageBookmarks.gsp
Expand Up @@ -36,7 +36,7 @@
});
jq("table").on('mouseenter', 'tr', function(event) {
if(event.target.localName !== "th" && event.target.localName !== "input" && event.target.localName !== "label" && event.target.offsetParent.id !== "todays-history" && event.target.offsetParent.id !== "this-weeks-history" && event.target.offsetParent.id !== "this-month-history" && event.target.offsetParent.id !== "other-history") {
if(event.delegateTarget.id !== "patient-search-results-table" && event.target.localName !== "th" && event.target.localName !== "input" && event.target.localName !== "label" && event.target.offsetParent.id !== "todays-history" && event.target.offsetParent.id !== "this-weeks-history" && event.target.offsetParent.id !== "this-month-history" && event.target.offsetParent.id !== "other-history") {
jq(this).css("cursor", "pointer");
jq(this).css('background', '#F0EAEA');
}
Expand Down
27 changes: 27 additions & 0 deletions server/src/main/resources/collection1/conf/data-config.xml
Expand Up @@ -76,5 +76,32 @@
where f.retired = 1">
</entity>

<entity name="allergies"
query="SELECT DISTINCT a.uuid AS id, a.allergy_id AS allergy_id, ac1.name AS allergy_coded_name, a.non_coded_allergen AS allergy_non_coded_name,
ac2.name AS allergy_severity, a.allergen_type AS allergy_type, ar2.name AS allergy_coded_reaction, ar2.reaction_non_coded AS allergy_non_coded_reaction, a.comment AS allergy_comment FROM allergy a
JOIN (SELECT cn1.name, a1.coded_allergen, a1.non_coded_allergen FROM concept_name cn1 INNER JOIN (SELECT DISTINCT coded_allergen, non_coded_allergen FROM allergy) AS a1 ON a1.coded_allergen = cn1.concept_id WHERE cn1.locale='en') AS ac1 ON ac1.coded_allergen = a.coded_allergen
LEFT JOIN (SELECT cn2.name, a2.severity_concept_id FROM concept_name cn2 INNER JOIN (SELECT DISTINCT severity_concept_id FROM allergy) AS a2 ON cn2.concept_id = a2.severity_concept_id WHERE cn2.locale='en') AS ac2 ON ac2.severity_concept_id = a.severity_concept_id
LEFT JOIN (SELECT cn.name, ar.allergy_id, ar.reaction_non_coded FROM concept_name cn INNER JOIN (SELECT DISTINCT allergy_id, reaction_concept_id, reaction_non_coded FROM allergy_reaction) AS ar ON ar.reaction_concept_id = cn.concept_id WHERE cn.locale='en') AS ar2 ON ar2.allergy_id = a.allergy_id
WHERE a.patient_id ='${dataimporter.request.personId}'"

deltaImportQuery="SELECT DISTINCT a.uuid AS id, a.allergy_id AS allergy_id, ac1.name AS allergy_coded_name, a.non_coded_allergen AS allergy_non_coded_name,
ac2.name AS allergy_severity, a.allergen_type AS allergy_type, ar2.name AS allergy_coded_reaction, ar2.reaction_non_coded AS allergy_non_coded_reaction, a.comment AS allergy_comment FROM allergy a
JOIN (SELECT cn1.name, a1.coded_allergen, a1.non_coded_allergen FROM concept_name cn1 INNER JOIN (SELECT DISTINCT coded_allergen, non_coded_allergen FROM allergy) AS a1 ON a1.coded_allergen = cn1.concept_id WHERE cn1.locale='en') AS ac1 ON ac1.coded_allergen = a.coded_allergen
LEFT JOIN (SELECT cn2.name, a2.severity_concept_id FROM concept_name cn2 INNER JOIN (SELECT DISTINCT severity_concept_id FROM allergy) AS a2 ON cn2.concept_id = a2.severity_concept_id WHERE cn2.locale='en') AS ac2 ON ac2.severity_concept_id = a.severity_concept_id
LEFT JOIN (SELECT cn.name, ar.allergy_id, ar.reaction_non_coded FROM concept_name cn INNER JOIN (SELECT DISTINCT allergy_id, reaction_concept_id, reaction_non_coded FROM allergy_reaction) AS ar ON ar.reaction_concept_id = cn.concept_id WHERE cn.locale='en') AS ar2 ON ar2.allergy_id = a.allergy_id
WHERE a.uuid='${dih.delta.id}'"

deltaQuery="SELECT a.uuid as id from openmrs.allergy a
INNER JOIN concept_name cn on cn.concept_id = a.coded_allergen
WHERE patient_id='${dataimporter.request.personId}'
AND a.voided=0 AND cn.voided=0
AND a.date_created &gt; '${dataimporter.request.lastIndexTime}"

deletedPkQuery="SELECT a.uuid as id from openmrs.allergy a
INNER JOIN concept_name cn on cn.concept_id = a.coded_allergen
WHERE patient_id='${dataimporter.request.personId}'
AND (a.voided=1 OR cn.voided=1) AND a.date_voided &gt; '${dataimporter.request.lastIndexTime}'">
</entity>

</document>
</dataConfig>

0 comments on commit a3a9a58

Please sign in to comment.