2 * Copyright (C) 2016 Kevin Yeh <kevin.y@integralemr.com>
3 * Copyright (C) 2016 Brady Miller <brady.g.miller@gmail.com>
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 3
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
17 * @author Kevin Yeh <kevin.y@integralemr.com>
18 * @author Brady Miller <brady.g.miller@gmail.com>
19 * @link http://www.open-emr.org
22 function tabStatus(title,url,name,closable,visible,locked)
25 self.visible=ko.observable(visible);
26 self.locked=ko.observable(locked);
27 self.closable=ko.observable(closable);
28 self.title=ko.observable(title);
29 self.url=ko.observable(url);
30 self.name=ko.observable(name);
35 function tabs_view_model()
37 this.tabsList=ko.observableArray();
38 this.tabsList.push(new tabStatus("One",webroot_url+"/interface/main/main_info.php","cal",true,true,false));
39 this.tabsList.push(new tabStatus("Two",webroot_url+"/interface/main/messages/messages.php?form_active=1","msg",true,false,false));
40 // this.tabsList.push(new tabStatus("Three"));
41 this.text=ko.observable("Test");
45 function activateTab(data)
47 for(var tabIdx=0;tabIdx<app_view_model.application_data.tabs.tabsList().length;tabIdx++)
49 var curTab=app_view_model.application_data.tabs.tabsList()[tabIdx];
54 curTab.visible(false);
64 function activateTabByName(name,hideOthers)
66 for(var tabIdx=0;tabIdx<app_view_model.application_data.tabs.tabsList().length;tabIdx++)
68 var curTab=app_view_model.application_data.tabs.tabsList()[tabIdx];
69 if(curTab.name()===name)
77 curTab.visible(false);
83 function tabClicked(data,evt)
88 function tabRefresh(data,evt)
90 // To do: Consider modification if part of frame.
91 data.window.location=data.window.location;
95 function tabClose(data,evt)
97 app_view_model.application_data.tabs.tabsList.remove(data);
100 function tabCloseByName(name)
102 for(var tabIdx=0;tabIdx<app_view_model.application_data.tabs.tabsList().length;tabIdx++)
104 var curTab=app_view_model.application_data.tabs.tabsList()[tabIdx];
105 if(curTab.name()===name)
112 function navigateTab(url,name)
114 top.restoreSession();
116 if($("iframe[name='"+name+"']").length>0)
118 $("iframe[name='"+name+"']").get(0).contentWindow.location=url;
122 curTab=new tabStatus("New",url,name,true,false,false);
123 app_view_model.application_data.tabs.tabsList.push(curTab);
127 function tabLockToggle(data,evt)
129 data.locked(!data.locked());
140 function refreshPatient(data,evt)
142 loadCurrentPatient();
146 function setEncounter(id)
148 app_view_model.application_data.patient().selectedEncounterID(id);
151 function chooseEncounterEvent(data,evt)
153 setEncounter(data.id());
154 goToEncounter(data.id());
157 function goToEncounter(encId)
159 var url=webroot_url+'/interface/patient_file/encounter/encounter_top.php?set_encounter=' + encId;
160 navigateTab(url,"enc");
161 activateTabByName("enc",true);
164 function reviewEncounter(encId)
166 var url=webroot_url+'/interface/patient_file/encounter/forms.php?review_id=' + encId;
167 navigateTab(url,"rev");
168 activateTabByName("rev",true);
171 function reviewEncounterEvent(data,evt)
173 reviewEncounter(data.id());
175 function clickNewEncounter(data,evt)
180 function newEncounter()
182 var url=webroot_url+'/interface/forms/newpatient/new.php?autoloaded=1&calenc='
183 navigateTab(url,"enc");
184 activateTabByName("enc",true);
188 function clickEncounterList(data,evt)
192 function encounterList()
194 var url=webroot_url+'/interface/patient_file/history/encounters.php'
195 navigateTab(url,"enc");
196 activateTabByName("enc",true);
200 function loadCurrentPatient()
202 var url=webroot_url+'/interface/patient_file/summary/demographics.php'
203 navigateTab(url,"pat");
204 activateTabByName("pat",true);
208 function menuActionClick(data,evt)
212 if(data.requirement===2)
214 var encounterID=app_view_model.application_data.patient().selectedEncounterID();
215 if(isEncounterLocked(encounterID))
217 alert("This encounter is locked. No new forms can be added.");
221 navigateTab(webroot_url+data.url(),data.target);
222 activateTabByName(data.target,true);
226 if(data.requirement===1)
228 alert('You must first select or add a patient.');
230 else if((data.requirement===2)||data.requirement===3)
232 alert('You must first select or create an encounter.');
238 function clearPatient()
240 top.restoreSession();
241 app_view_model.application_data.patient(null);
242 tabCloseByName('enc');
243 tabCloseByName('rev');
244 tabCloseByName('pop');
245 tabCloseByName('pat');
246 navigateTab(webroot_url+'/interface/main/finder/dynamic_finder.php','fin');
247 activateTabByName('fin',true);
248 //Ajax call to clear active patient in session
251 url: webroot_url+"/library/ajax/unset_session_ajax.php",
252 data: { func: "unset_pid"},
253 success:function( msg ) {