Skip to content

Commit

Permalink
Added basic display for Managing Notes
Browse files Browse the repository at this point in the history
  • Loading branch information
k-joseph committed Jun 17, 2015
1 parent ee4bdfd commit 6b427fd
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 20 deletions.
Expand Up @@ -24,6 +24,7 @@
import org.openmrs.api.context.Context;
import org.openmrs.module.chartsearch.api.ChartSearchService;

import com.google.common.collect.Lists;
import com.openmrs.module.chartsearch.saving.ChartSearchBookmark;
import com.openmrs.module.chartsearch.saving.ChartSearchHistory;
import com.openmrs.module.chartsearch.saving.ChartSearchNote;
Expand Down Expand Up @@ -271,7 +272,7 @@ public JSONObject saveANewNoteOrCommentOnToASearch(String searchPhrase, Integer
chartSearchService.saveSearchNote(note);

if (null != chartSearchService.getSearchNote(note.getNoteId())) {
GeneratingJson.addBothPersonalAndGlobalNotesToJSON(searchPhrase, patientId, json);
GeneratingJson.addBothPersonalAndGlobalNotesToJSON(searchPhrase, patientId, json, false);
} else {
json = null;
}
Expand All @@ -291,7 +292,7 @@ public JSONObject deleteSearchNote(String uuid, String searchPhrase, Integer pat
}
}

GeneratingJson.addBothPersonalAndGlobalNotesToJSON(searchPhrase, patientId, json);
GeneratingJson.addBothPersonalAndGlobalNotesToJSON(searchPhrase, patientId, json, false);

return json;
}
Expand Down Expand Up @@ -389,6 +390,31 @@ public JSONArray setBookmarkAsDefaultSearch(String uuid) {
return GeneratingJson.getAllSearchBookmarksToReturnTomanagerUI(false);
}

public JSONArray fetchAllNotesForManageUI(boolean wholePageIsToBeLoaded) {
JSONArray jsonArr = new JSONArray();
List<ChartSearchNote> allNotes = Lists.reverse(chartSearchService.getAllSearchNotes());//re-arrange to get the most recent/added first

for (ChartSearchNote note : allNotes) {
JSONObject json = new JSONObject();
if (note.getNoteOwner().getUserId().equals(Context.getAuthenticatedUser().getUserId())) {//manage owned notes only
json.put("uuid", note.getUuid());
json.put("createdOrLastModifiedAt", note.getCreatedOrLastModifiedAt().getTime());
json.put("backgroundColor", note.getDisplayColor());
json.put("formatedCreatedOrLastModifiedAt", Context.getDateFormat()
.format(note.getCreatedOrLastModifiedAt()));

GeneratingJson.addPhraseAndCommentNotesAttributes(wholePageIsToBeLoaded, note, json);

json.put("patientId", note.getPatient().getPatientId());
json.put("patientFName", note.getPatient().getFamilyName());
json.put("priority", note.getPriority());
}
jsonArr.add(json);
}

return jsonArr;
}

private <T> T getComponent(Class<T> clazz) {
List<T> list = Context.getRegisteredComponents(clazz);
if (list == null || list.size() == 0)
Expand Down
Expand Up @@ -100,14 +100,16 @@ public static String generateJson(boolean wholePageIsToBeLoaded) {
jsonToReturn.put("searchBookmarks", bookmarks);
jsonToReturn.put("appliedFacets", (String[]) catNms.toArray(appliedCats));

addBothPersonalAndGlobalNotesToJSON(searchPhrase, patientId, jsonToReturn);
addBothPersonalAndGlobalNotesToJSON(searchPhrase, patientId, jsonToReturn, wholePageIsToBeLoaded);

return jsonToReturn.toString();
}

public static void addBothPersonalAndGlobalNotesToJSON(String searchPhrase, Integer patientId, JSONObject json) {
JSONArray allPersonalNotes = GeneratingJson.getAllPersonalNotesOnASearch(searchPhrase, patientId);
JSONArray allGlobalNotes = GeneratingJson.getAllGlobalNotesOnASearch(searchPhrase, patientId);
public static void addBothPersonalAndGlobalNotesToJSON(String searchPhrase, Integer patientId, JSONObject json,
boolean wholePageIsToBeLoaded) {
JSONArray allPersonalNotes = GeneratingJson.getAllPersonalNotesOnASearch(searchPhrase, patientId,
wholePageIsToBeLoaded);
JSONArray allGlobalNotes = GeneratingJson.getAllGlobalNotesOnASearch(searchPhrase, patientId, wholePageIsToBeLoaded);
String userName = Context.getAuthenticatedUser().getUsername();
String systemId = Context.getAuthenticatedUser().getSystemId();

Expand Down Expand Up @@ -163,7 +165,7 @@ private static JSONObject generateHistoryJSON(boolean wholePageIsToBeLoaded, Cha
json = new JSONObject();

if (wholePageIsToBeLoaded) {
json.put("searchPhrase", appendBackwardSlashBeforeDoubleQuotes(history.getSearchPhrase()));
json.put("searchPhrase", appendBackwardSlashBeforeMustBePassedCharacters(history.getSearchPhrase()));
} else {
json.put("searchPhrase", history.getSearchPhrase());
}
Expand All @@ -175,7 +177,8 @@ private static JSONObject generateHistoryJSON(boolean wholePageIsToBeLoaded, Cha
return json;
}

public static JSONArray getAllPersonalNotesOnASearch(String searchPhrase, Integer patientId) {
public static JSONArray getAllPersonalNotesOnASearch(String searchPhrase, Integer patientId,
boolean wholePageIsToBeLoaded) {
JSONArray jsonArr = new JSONArray();
List<ChartSearchNote> allNotes = chartSearchService.getAllSearchNotes();
List<ChartSearchNote> allPersonalNotes = new ArrayList<ChartSearchNote>();
Expand All @@ -196,11 +199,10 @@ public static JSONArray getAllPersonalNotesOnASearch(String searchPhrase, Intege

json.put("uuid", note.getUuid());
json.put("createdOrLastModifiedAt", note.getCreatedOrLastModifiedAt().getTime());
json.put("comment", note.getComment());
json.put("backgroundColor", note.getDisplayColor());
json.put("formatedCreatedOrLastModifiedAt", Context.getDateFormat()
.format(note.getCreatedOrLastModifiedAt()));
json.put("searchPhrase", note.getSearchPhrase());
addPhraseAndCommentNotesAttributes(wholePageIsToBeLoaded, note, json);
json.put("noteOwner", null == userName ? systemId : userName);

jsonArr.add(json);
Expand All @@ -209,7 +211,18 @@ public static JSONArray getAllPersonalNotesOnASearch(String searchPhrase, Intege
return jsonArr;
}

public static JSONArray getAllGlobalNotesOnASearch(String searchPhrase, Integer patientId) {
public static void addPhraseAndCommentNotesAttributes(boolean wholePageIsToBeLoaded, ChartSearchNote note,
JSONObject json) {
if (wholePageIsToBeLoaded) {
json.put("comment", appendBackwardSlashBeforeMustBePassedCharacters(note.getComment()));
json.put("searchPhrase", appendBackwardSlashBeforeMustBePassedCharacters(note.getSearchPhrase()));
} else {
json.put("comment", note.getComment());
json.put("searchPhrase", note.getSearchPhrase());
}
}

public static JSONArray getAllGlobalNotesOnASearch(String searchPhrase, Integer patientId, boolean wholePageIsToBeLoaded) {
JSONArray jsonArr = new JSONArray();
List<ChartSearchNote> allNotes = chartSearchService.getAllSearchNotes();
List<ChartSearchNote> allGlobalNotes = new ArrayList<ChartSearchNote>();
Expand All @@ -231,9 +244,10 @@ public static JSONArray getAllGlobalNotesOnASearch(String searchPhrase, Integer
json.put("createdOrLastModifiedAt", note.getCreatedOrLastModifiedAt().getTime());
json.put("formatedCreatedOrLastModifiedAt", Context.getDateFormat()
.format(note.getCreatedOrLastModifiedAt()));
json.put("comment", note.getComment());
json.put("backgroundColor", note.getDisplayColor());
json.put("searchPhrase", note.getSearchPhrase());

addPhraseAndCommentNotesAttributes(wholePageIsToBeLoaded, note, json);

json.put("noteOwner", null == userName ? systemId : userName);

jsonArr.add(json);
Expand Down Expand Up @@ -284,8 +298,8 @@ private static JSONObject generateBookmarksJSON(boolean wholePageIsToBeLoaded, C
json = new JSONObject();

if (wholePageIsToBeLoaded) {
json.put("bookmarkName", appendBackwardSlashBeforeDoubleQuotes(curBookmark.getBookmarkName()));
json.put("searchPhrase", appendBackwardSlashBeforeDoubleQuotes(curBookmark.getSearchPhrase()));
json.put("bookmarkName", appendBackwardSlashBeforeMustBePassedCharacters(curBookmark.getBookmarkName()));
json.put("searchPhrase", appendBackwardSlashBeforeMustBePassedCharacters(curBookmark.getSearchPhrase()));
} else {
json.put("bookmarkName", curBookmark.getBookmarkName());
json.put("searchPhrase", curBookmark.getSearchPhrase());
Expand Down Expand Up @@ -631,13 +645,20 @@ public static JSONObject generateFacetsJson(Count facet) {
return counts;
}

private static String appendBackwardSlashBeforeDoubleQuotes(String str) {
private static String appendBackwardSlashBeforeMustBePassedCharacters(String str) {
if (str.contains("'")) {
//str = str.replace("'", "\\'");
}
if (str.contains("\"")) {
str = str.replace("\"", "\\\"");
}
return str;
}

public static void main(String[] dsds) {
System.out.println(appendBackwardSlashBeforeMustBePassedCharacters("testst's"));
}

private static <T> T getComponent(Class<T> clazz) {
List<T> list = Context.getRegisteredComponents(clazz);
if (list == null || list.size() == 0)
Expand Down
@@ -0,0 +1,18 @@
package org.openmrs.module.chartsearch;


public class TestPlayStationForMyModules {
private static String appendBackwardSlashBeforeMustBePassedCharacters(String str) {
if (str.contains("'")) {
str = str.replace("'", "\'");
}
if (str.contains("\"")) {
str = str.replace("\"", "\\\"");
}
return str;
}

public static void main(String[] dsds) {
System.out.println(appendBackwardSlashBeforeMustBePassedCharacters("testst's"));
}
}
@@ -0,0 +1,23 @@
/**
* 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.fragment.controller;

import org.openmrs.module.chartsearch.ChartSearchCache;
import org.openmrs.ui.framework.fragment.FragmentModel;

public class ManageNotesFragmentController {

ChartSearchCache cache = new ChartSearchCache();

public void controller(FragmentModel fragmentModel) {
fragmentModel.addAttribute("allFoundNotes", cache.fetchAllNotesForManageUI(true).toString());
}

}
Expand Up @@ -101,7 +101,7 @@ public JSONObject refreshSearchNotes(@RequestParam("searchPhrase") String search
@RequestParam("patientId") Integer patientId) {
JSONObject json = new JSONObject();

GeneratingJson.addBothPersonalAndGlobalNotesToJSON(searchPhrase, patientId, json);
GeneratingJson.addBothPersonalAndGlobalNotesToJSON(searchPhrase, patientId, json, false);

return json;
}
Expand Down
6 changes: 4 additions & 2 deletions omod/src/main/webapp/fragments/manageBookmarks.gsp
Expand Up @@ -36,7 +36,7 @@
});
jq("table").on('mouseenter', 'tr', function(event) {
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") {
if(event.delegateTarget.id !== "manage-notes-display-table" && 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 Expand Up @@ -105,8 +105,10 @@
jq.each(cats, function(key, value) {
jq('#dialog-bookmark-categories').append(jq("<option></option>").attr("value",key).text(value));
});
jq('#dialog-bookmark-categories option').prop('selected', true);
if(jq('#dialog-bookmark-categories option').text() !== "") {
jq('#dialog-bookmark-categories option').prop('selected', true);
}
invokeDialog("#selected-bookmark-dialog-content", "Editing '" + bkName + "' Bookmark", "450px");
},
error: function(e) {
Expand Down
67 changes: 66 additions & 1 deletion omod/src/main/webapp/fragments/manageNotes.gsp
@@ -1 +1,66 @@
<h1>Manage Notes</h1>
<style type="text/css">
</style>


<script type="text/javascript">
var allNotes =' ${ allFoundNotes }';
var notesAfterparse = JSON.parse(allNotes);
jq(document).ready(function(event) {
displayExistingNotes();
function displayExistingNotes() {
var displayNotes;
if(notesAfterparse && notesAfterparse.length !== 0) {
displayNotes = "<tr><th><input type='checkbox' id='select-all-notes' style='width:55%;height:1.5em;'/>Patient</th><th>Search Phrase</th><th>Comment/Note</th><th>Priority</th><th>Last Updated</th></tr>";
for(i = 0; i < notesAfterparse.length; i++) {
var note = notesAfterparse[i];
if(note) {
var uuid = note.uuid;
var patient = "<td><input type='checkbox' class='select-this-note' id='" + uuid + "' style='width:55%;height:1.5em;'/>" + note.patientFName + "</td>";
var phrase = "<td>" + note.searchPhrase + "</td>";
var comment = "<td><textarea class='m-notes-comment' style='width: 488px;'>" + note.comment + "</textarea></td>";
var priority = setPriorityDisplay(note.priority);
var date = new Date(note.createdOrLastModifiedAt);
displayNotes += "<tr>" + patient + phrase + comment + priority + "<td>" + date.toString() + "</td></tr>";
}
}
}
if(displayNotes && displayNotes !== "") {
jq("#manage-notes-display-table").html(displayNotes);
}
}
function setPriorityDisplay(priority) {
var allPiorities = ["LOW", "HIGH"];
var priorityDisplay = "";
if(priority === allPiorities[1]) {
priorityDisplay = "<td><select class='m-notes-priority'><option>" + allPiorities[1] + "</option><option>" + allPiorities[0] + "</option></select></td>";
} else {
priorityDisplay = "<td><select class='m-notes-priority'><option>" + allPiorities[0] + "</option><option>" + allPiorities[1] + "</option></select></td>";
}
return priorityDisplay;
}
});
</script>








<h1>Manage Notes</h1>
<div id="manage-notes-display">
<table id="manage-notes-display-table"></table>
</div>

0 comments on commit 6b427fd

Please sign in to comment.