Allscripts Enhancements

Enahancements to Allscript ePrescribe website

  1. // ==UserScript==
  2. // @name Allscripts Enhancements
  3. // @namespace jewelmirror.com
  4. // @author marcin@jewelmirror.com
  5. // @description Enahancements to Allscript ePrescribe website
  6. // @version 0.4
  7. // @grant none
  8. // @include https://eprescribe.allscripts.com/Sig.aspx*
  9. // @include https://eprescribe.allscripts.com/ScriptPad.aspx*
  10. // @include https://eprescribe.allscripts.com/ReviewHistory.aspx*
  11. // ==/UserScript==
  12.  
  13.  
  14. // +-----------------------------------------------------------------------------+
  15. // $Author: marcin $
  16. // $Revision: 1.7 $
  17. // +-----------------------------------------------------------------------------+
  18. // Revision history
  19. // 0.1 - Initial release. Supports filtering of sigs
  20. // 0.2 - Added support for chaning destination in bulk in script pad
  21. // 0.3 - Review Hisotry - added checkbox to select all meds when reviewing history
  22. // 0.4 - Review History - added checkbox to selected all PBM Reported medications
  23. // +-----------------------------------------------------------------------------+
  24. // Copyright (C) 2014 Marcin Matuszkiewicz <marcin@jewelmirror.com>
  25. //
  26. //
  27. // This program is free software; you can redistribute it and/or
  28. // modify it under the terms of the GNU General Public License
  29. // as published by the Free Software Foundation; either version 2
  30. // of the License, or (at your option) any later version.
  31. //
  32. //
  33. // This program is distributed in the hope that it will be useful,
  34. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. // GNU General Public License for more details.
  37. //
  38. //
  39. // A copy of the GNU General Public License is included along with this program:
  40. // openemr/interface/login/GnuGPL.html
  41. // For more information write to the Free Software
  42. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  43. //
  44. // Author: Marcin Matuszkiewicz <marcin@jewelmirror.com>
  45. //
  46. // +------------------------------------------------------------------------------+
  47.  
  48. var pages = {
  49. sig: "Sig.aspx",
  50. rxpad: "ScriptPad.aspx",
  51. reviewhx: "ReviewHistory.aspx"
  52. }
  53.  
  54. var id_cb_all = 'id_cb_all';
  55.  
  56.  
  57. // +------------------------------------------------------------------------------+
  58. // Functions related to filtering sigs
  59. // +------------------------------------------------------------------------------+
  60. function CreateFilter() {
  61. var sel = document.createElement('select');
  62. sel.setAttribute('id', 'sigfilter_id');
  63.  
  64. var opt;
  65.  
  66. for ( i = 0; i < FilterValue.length; i++) {
  67. opt = document.createElement('option');
  68. opt.setAttribute('value', FilterValue[i]);
  69. opt.innerHTML = FilterStr[i];
  70. sel.appendChild(opt);
  71. }
  72.  
  73. return sel;
  74. }
  75.  
  76. function Filter() {
  77. // If SIGs have not been saved yet, save them. Note that this is going to cause stale sigs if user changes daily frequency. User should use Save SIGs button to manually change sigs after changing daily frequency
  78. if (SigValues.length < 1) {
  79. SaveSIGs();
  80. }
  81. var sel = document.getElementById('sigfilter_id');
  82. var str = sel.options[sel.selectedIndex].text;
  83.  
  84. var pattern = new RegExp('.*' + str + '.*');
  85. //var pattern = /.*PAIN.*/;
  86.  
  87. var sel = document.getElementById('ctl00_ContentPlaceHolder1_LstSig');
  88.  
  89. var opt = sel.getElementsByTagName('option');
  90.  
  91. // Remove all options
  92. for ( i = opt.length - 1; i >= 0; i--) {
  93. sel.remove(i);
  94. }
  95.  
  96. for ( i = 0; i < SigValues.length; i++) {
  97. t = SigStrings[i].match(pattern);
  98.  
  99. if (t) {
  100. var e = document.createElement('option');
  101. e.setAttribute('value', SigValues[i]);
  102. e.innerHTML = SigStrings[i];
  103. sel.appendChild(e);
  104. }
  105. }
  106. }
  107.  
  108. function SaveSIGs() {
  109. SigValues = [];
  110. SigStrings = [];
  111.  
  112. console.log('Save SIGs');
  113.  
  114. var sel = document.getElementById('ctl00_ContentPlaceHolder1_LstSig');
  115. var opt = sel.getElementsByTagName('option');
  116.  
  117. for ( i = 0; i < opt.length; i++) {
  118. SigValues[i] = opt[i].value;
  119. SigStrings[i] = opt[i].text;
  120. }
  121.  
  122. console.log(SigStrings);
  123. }
  124.  
  125. // +------------------------------------------------------------------------------+
  126. // Functions related to prescription pad
  127. // +------------------------------------------------------------------------------+
  128. function GetDestValues()
  129. {
  130. var DestValues = [];
  131. var sel = document.getElementsByTagName('select');
  132.  
  133. for (i = 0; i < sel.length; i++)
  134. {
  135. opt = sel[i].getElementsByTagName('option');
  136. if (opt.length && IsValidDestValue(opt[0].value))
  137. {
  138. for (k = 0; k < opt.length; k++)
  139. {
  140. DestValues.push(opt[k].value);
  141. }
  142. }
  143. return DestValues;
  144. }
  145. }
  146.  
  147. function GetDestStrings()
  148. {
  149. var DestStrings = [];
  150. var sel = document.getElementsByTagName('select');
  151.  
  152. for (i = 0; i < sel.length; i++)
  153. {
  154. opt = sel[i].getElementsByTagName('option');
  155. if (opt.length && IsValidDestValue(opt[0].value))
  156. {
  157. for (k = 0; k < opt.length; k++)
  158. {
  159. DestStrings.push(opt[k].text);
  160. }
  161. }
  162. return DestStrings;
  163. }
  164. }
  165.  
  166. function CreateDestSelection(DestValues, DestStrings)
  167. {
  168. var select = document.createElement('select');
  169. select.setAttribute('id', 'selectChangeAll');
  170. //select.setAttribute('onChange', 'ChangeDestForAllScripts()');
  171. select.addEventListener("change", ChangeDestForAllScripts, true);
  172. var option;
  173. option = document.createElement('option');
  174. option.setAttribute('value', 'empty');
  175. option.setAttribute('disabled', true);
  176. option.setAttribute('selected', true);
  177. option.innerHTML = 'Change destiation for all scripts';
  178. select.appendChild(option);
  179. for (i = 0; i < DestValues.length; i++)
  180. {
  181. option = document.createElement('option');
  182. option.setAttribute('value', DestValues[i]);
  183. option.innerHTML = DestStrings[i];
  184. select.appendChild(option);
  185. }
  186. return select;
  187.  
  188. }
  189.  
  190. function GetDestSelections()
  191. {
  192. var DestSelections = [];
  193. var sel = document.getElementsByTagName('select');
  194.  
  195. for (i = 0; i < sel.length; i++)
  196. {
  197. opt = sel[i].getElementsByTagName('option');
  198. if (opt.length && IsValidDestValue(opt[0].value))
  199. {
  200. DestSelections.push(sel[i]);
  201. }
  202. }
  203. return DestSelections;
  204. }
  205.  
  206. function IsValidDestValue(value)
  207. {
  208. if (value == "PHARM" || value == "MOB" || value == "PRINT" || value == "ASSISTANT" || value == "PTSELFREPORTED")
  209. {
  210. return true;
  211. }
  212. else
  213. {
  214. return false;
  215. }
  216. }
  217.  
  218. function ChangeDestForAllScripts()
  219. {
  220. var myselect = document.getElementById("selectChangeAll");
  221. for (i = 0; i < DestSelections.length; i++)
  222. {
  223. DestSelections[i].value = myselect.options[myselect.selectedIndex].value;
  224. }
  225. }
  226.  
  227. /*
  228. * Functions related to reviewing medication history
  229. */
  230. function ReviewHistory() {
  231. $('.h4title:eq(1)').after('<tr id="mmsel"><td><div>Select</div><input type="checkbox" id="selall">All</input><input type="checkbox" id="selpbm">PBM History</input></td></tr>');
  232. $('#selall').bind('change', function() {
  233. console.log('hello');
  234. $('tr:.rgRow :checkbox').click();
  235. $('tr:.rgAltRow :checkbox').click();
  236. });
  237. $("#selpbm").bind('change', function() {
  238. $('td:contains(PBM Reported Rx)').prev().prev().prev().prev().prev().children().click();
  239. });
  240. }
  241.  
  242. loc = window.location.href;
  243.  
  244. if (loc.indexOf(pages['sig']) >= 0) {
  245. var FilterStr = ["PAIN", "ANXIETY", "INSOMNIA", "AS NEEDED", "NAUSEA", ""];
  246. var FilterValue = ["PAIN", "ANXIETY", "INSOMNIA", "PRN", "NAUSEA", "NONE"];
  247. var SigValues = [];
  248. var SigStrings = [];
  249.  
  250. //Resize sig containers
  251. //var sel = document.getElementById('ctl00_ContentPlaceHolder1_LstLatinSig');
  252. //sel.setAttribute('size', 10);
  253.  
  254. //var sel = document.getElementById('ctl00_ContentPlaceHolder1_LstSig');
  255. //sel.setAttribute('size', 10);
  256.  
  257. //var div = document.getElementById('ctl00_ContentPlaceHolder1_pnlButtons');
  258. var sigopt = document.getElementById('ctl00_ContentPlaceHolder1_rdgPrefer').parentNode;
  259.  
  260. var input = document.createElement('input');
  261. input.setAttribute('value', 'Save SIGs');
  262. input.setAttribute('type', 'button');
  263. input.addEventListener("click", SaveSIGs, true);
  264. input.className = 'btnstyle';
  265. sigopt.appendChild(input);
  266.  
  267. var input = document.createElement('input');
  268. input.setAttribute('value', 'Filter');
  269. input.setAttribute('type', 'button');
  270. input.addEventListener("click", Filter, true);
  271. input.className = 'btnstyle';
  272. sigopt.appendChild(input);
  273.  
  274. var sel = CreateFilter();
  275. sigopt.appendChild(sel);
  276. } else if (loc.indexOf(pages['rxpad']) >= 0) {
  277.  
  278. var DestValues = [];
  279. var DestStrings = [];
  280. var DestSelections = [];
  281.  
  282. DestValues = GetDestValues();
  283. DestStrings = GetDestStrings();
  284. DestSelections = GetDestSelections();
  285.  
  286. var tab = document.getElementById("ctl00_ContentPlaceHolder1_grdScriptPad_ctl00");
  287. var last_row = tab.rows[tab.rows.length-1];
  288.  
  289. if (!tab) {
  290. alert("No table");
  291. }
  292.  
  293. var tbody = tab.getElementsByTagName('tbody');
  294. //var row = tbody[0].insertRow(-1);
  295. var row = tab.insertRow(-1);
  296. if (last_row.className == 'rgRow'){
  297. row.className = 'rgAltRow';
  298. }
  299. else {
  300. row.class = 'rgRow';
  301. }
  302. var cell0 = row.insertCell(0);
  303. var cell1 = row.insertCell(1);
  304. var cell2 = row.insertCell(2);
  305. var cell3 = row.insertCell(3);
  306. var cell4 = row.insertCell(4);
  307. var cell5 = row.insertCell(5);
  308.  
  309. var selection = CreateDestSelection(DestValues, DestStrings);
  310. cell3.appendChild(selection);
  311. } else if (loc.indexOf(pages['reviewhx'])) {
  312. ReviewHistory();
  313. }