2 * View logic for OnsiteActivityViews
4 * application logic specific to the OnsiteActivityView listing page
6 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
8 * LICENSE: This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * @author Jerry Padgett <sjpadgett@gmail.com>
23 * @link http://www.open-emr.org
27 onsiteActivityViews: new model.OnsiteActivityViewCollection(),
29 onsiteActivityView: null,
32 isInitializing: false,
33 fetchParams: { filter: '', orderBy: 'patientId', orderDesc: 'DESC', page: 1, status: 'waiting' },
34 fetchInProgress: false,
38 // ensure initialization only occurs once
39 if (actpage.isInitialized || actpage.isInitializing) return;
40 actpage.isInitializing = true;
42 if (!$.isReady && console) console.warn('page was initialized before dom is ready. views may not render properly.');
44 // make the return button clickable
45 $("#returnHome").click(function(e) {
47 window.location.href = './provider';
49 function showPaymentModal(cpid,recid){
50 var title = 'Patient Online Payment';
53 { text: 'Help', close: false, style: 'info btn-sm',id: 'formHelp'},
54 { text: 'Cancel', close: true, style: 'default btn-sm'},
55 //{ text: 'Download', close: false, style: 'success btn-sm',id:'downloadTemplate'},
56 { text: 'Done', style: 'danger btn-sm', close:true}],
58 subtitle: 'Provider Audit.',
61 url: './../portal_payment.php?pid='+cpid+'&user='+cuser+'&recid='+recid
63 return eModal.ajax(params)
64 .then(function () { });
66 function showDocumentModal(cpid,recid){
67 var title = 'Patient Documents';
70 { text: 'Help', close: false, style: 'info btn-sm',id: 'formHelp'},
71 { text: 'Cancel', close: true, style: 'default btn-sm'},
72 //{ text: 'Download', close: false, style: 'success btn-sm',id:'downloadTemplate'},
73 { text: 'Done', style: 'danger btn-sm', close:true}],
75 subtitle: 'Provider Audit.',
78 url: './onsitedocuments?pid='+cpid+'&user='+cuser+'&recid='+recid
80 return eModal.iframe(params)
81 .then(function () { });
83 function showProfileModal(cpid){
84 var title = 'Demographics Legend Red: Chart Values. Blue: Patient Edits.';
87 { text: 'Help', close: false, style: 'info btn-sm',id: 'formHelp'},
88 { text: 'Cancel', close: true, style: 'default btn-sm'},
89 { text: 'Revert Edits', close: false, style: 'success btn-sm',id:'replaceAllButton'},
90 { text: 'Commit to Chart', style: 'danger btn-sm', close: false,id:'savePatientButton'}],
92 subtitle: 'Provider Audit.',
95 url: './patientdata?pid='+cpid+'&user='+cuser
97 return eModal.ajax(params)
98 .then(function () { });
101 $(document.body).on('hidden.bs.modal', function (){
102 window.location.href = './onsiteactivityviews';
105 // initialize the collection view
106 this.collectionView = new view.CollectionView({
107 el: $("#onsiteActivityViewCollectionContainer"),
108 templateEl: $("#onsiteActivityViewCollectionTemplate"),
109 collection: actpage.onsiteActivityViews
112 // initialize the search filter
113 $('#filter').change(function(obj) {
114 actpage.fetchParams.filter = $('#filter').val();
115 actpage.fetchParams.page = 1;
116 actpage.fetchOnsiteActivityViews(actpage.fetchParams);
119 // make the rows clickable ('rendered' is a custom event, not a standard backbone event)
120 this.collectionView.on('rendered',function(){
121 // attach click handler to the table rows for selection
122 $('table.collection tbody tr').click(function(e) {
124 var m = actpage.onsiteActivityViews.get(this.id);
125 var cpid = m.get('patientId');
126 var activity = m.get('activity');
127 var recid = m.get('tableArgs');
128 if(activity == 'document')
129 showDocumentModal(cpid,recid);
130 else if(activity == 'profile')
131 showProfileModal(cpid);
132 else if(activity == 'payment')
133 showPaymentModal(cpid);
136 // make the headers clickable for sorting
137 $('table.collection thead tr th').click(function(e) {
139 var prop = this.id.replace('header_','');
141 // toggle the ascending/descending before we change the sort prop
142 actpage.fetchParams.orderDesc = (prop == actpage.fetchParams.orderBy && !actpage.fetchParams.orderDesc) ? '1' : '';
143 actpage.fetchParams.orderBy = prop;
144 actpage.fetchParams.page = 1;
145 actpage.fetchOnsiteActivityViews(actpage.fetchParams);
148 // attach click handlers to the pagination controls
149 $('.pageButton').click(function(e) {
151 actpage.fetchParams.page = this.id.substr(5);
152 actpage.fetchOnsiteActivityViews(actpage.fetchParams);
155 actpage.isInitialized = true;
156 actpage.isInitializing = false;
159 this.fetchOnsiteActivityViews({ filter: '', orderBy: 'Date', orderDesc: 'DESC', page: 1, status: 'waiting' });
161 // initialize the model view
162 this.modelView = new view.ModelView({
163 el: $("#onsiteActivityViewModelContainer")
166 this.modelView.templateEl = $("#onsiteActivityViewModelTemplate");
168 if (model.longPollDuration > 0) {
169 setInterval(function () {
171 if (!actpage.dialogIsOpen) {
172 actpage.fetchOnsiteActivityViews(actpage.fetchParams,true);
175 }, model.longPollDuration);
180 * Fetch the collection data from the server
181 * @param object params passed through to collection.fetch
182 * @param bool true to hide the loading animation
184 fetchOnsiteActivityViews: function(params, hideLoader) {
185 // persist the params so that paging/sorting/filtering will play together nicely
186 //params.status = 'waiting';
187 actpage.fetchParams = params;
189 if (actpage.fetchInProgress) {
190 if (console) console.log('supressing fetch because it is already in progress');
193 actpage.fetchInProgress = true;
195 if (!hideLoader) app.showProgress('loader');
197 actpage.onsiteActivityViews.fetch({
201 success: function() {
202 if (actpage.onsiteActivityViews.collectionHasChanged) {
203 // TODO: add any logic necessary if the collection has changed
204 // the sync event will trigger the view to re-render
206 app.hideProgress('loader');
207 actpage.fetchInProgress = false;
209 error: function(m, r) {
210 app.appendAlert(app.getErrorMessage(r), 'alert-error',0,'collectionAlert');
211 app.hideProgress('loader');
212 actpage.fetchInProgress = false;
218 * show the dialog for editing a model
221 showDetailDialog: function(m) {
223 // show the modal dialog
224 $('#onsiteActivityViewDetailDialog').modal({ show: true });
226 // if a model was specified then that means a user is editing an existing record
227 // if not, then the user is creating a new record
228 actpage.onsiteActivityView = m ? m : new model.OnsiteActivityViewModel();
230 actpage.modelView.model = actpage.onsiteActivityView;
232 if (actpage.onsiteActivityView.id == null || actpage.onsiteActivityView.id == '') {
233 // this is a new record, there is no need to contact the server
234 actpage.renderModelView(false);
236 app.showProgress('modelLoader');
238 // fetch the model from the server so we are not updating stale data
239 actpage.onsiteActivityView.fetch({
241 success: function() {
242 // data returned from the server. render the model view
243 actpage.renderModelView(true);
246 error: function(m, r) {
247 app.appendAlert(app.getErrorMessage(r), 'alert-error',0,'modelAlert');
248 app.hideProgress('modelLoader');
256 * Render the model template in the popup
257 * @param bool show the delete button
259 renderModelView: function(showDeleteButton) {
260 actpage.modelView.render();
262 app.hideProgress('modelLoader');
263 // initialize any special controls
267 .on('changeDate', function(ev){
268 $('.date-picker').datepicker('hide');
271 // this happens if the datepicker input.value isn't a valid date
272 if (console) console.log('datepicker error: '+error.message);
274 if (showDeleteButton) {
275 // attach click handlers to the delete buttons
276 $('#deleteOnsiteActivityViewButton').click(function(e) {
278 $('#confirmDeleteOnsiteActivityViewContainer').show('fast');
281 $('#cancelDeleteOnsiteActivityViewButton').click(function(e) {
283 $('#confirmDeleteOnsiteActivityViewContainer').hide('fast');
286 $('#confirmDeleteOnsiteActivityViewButton').click(function(e) {
288 actpage.deleteModel();
292 // no point in initializing the click handlers if we don't show the button
293 $('#deleteOnsiteActivityViewButtonContainer').hide();