source: EDIS/trunk/java/tracking-ui-core/src/main/flex/gov/va/med/edp/model/TrackingModelLocator.as@ 1261

Last change on this file since 1261 was 1261, checked in by Solomon Blaz, 13 years ago

set version number embedded in flex application to match the one in the project pom.xml files: 1.0.1.WorldVistA-SNAPSHOT

File size: 11.3 KB
Line 
1/* TrackingModelLocator.as */
2
3package gov.va.med.edp.model
4{
5import com.adobe.cairngorm.model.ModelLocator;
6
7import flash.events.TimerEvent;
8import flash.net.URLRequest;
9import flash.net.navigateToURL;
10import flash.utils.Timer;
11
12import gov.va.med.edp.model.reports.ReportsModel;
13import gov.va.med.edp.pt.demog.model.PatientChecksModel;
14import gov.va.med.edp.vo.LogEditParamsVO;
15import gov.va.med.edp.vo.LogSelectorVO;
16import gov.va.med.edp.vo.SessionVO;
17import gov.va.med.edp.vo.VisitVO;
18
19import mx.collections.ArrayCollection;
20import mx.collections.XMLListCollection;
21import mx.rpc.Fault;
22
23
24[Bindable]
25public class TrackingModelLocator implements ModelLocator
26{
27 // Possible view states for the application
28 public static const VIEW_APP_INTRO: int = 0;
29 public static const VIEW_APP_SIGN_IN: int = 1;
30 public static const VIEW_APP_TRIAGE: int = 2;
31 public static const VIEW_APP_UPDATE: int = 3;
32 public static const VIEW_APP_DISPOSITION: int = 4;
33 public static const VIEW_APP_EDIT_CLOSED: int = 5;
34 public static const VIEW_APP_DISPLAY_BOARD: int = 6;
35 public static const VIEW_APP_ASSIGN_STAFF: int = 7;
36 public static const VIEW_APP_REPORTS: int = 8;
37 public static const VIEW_APP_CONFIGURE: int = 9;
38 public static const VIEW_APP_VERSION_INCOMPATIBILITY: int = 90;
39 public static const VIEW_APP_NO_VIEWS: int = 99;
40
41 public static const VIEW_EDIT_MESSAGE: String = "Message";
42 public static const VIEW_EDIT_SIGN_IN: String = "SignIn";
43 public static const VIEW_EDIT_TRIAGE: String = "Triage";
44 public static const VIEW_EDIT_UPDATE: String = "Update";
45 public static const VIEW_EDIT_UPDATE_NORES: String = "UpdateNoRes";
46 public static const VIEW_EDIT_DISP_DELAY: String = "DispDelay";
47 public static const VIEW_EDIT_DISP_DELAY_CODED: String = "DispDelayCoded";
48 public static const VIEW_EDIT_CLOSED: String = "EditClosed";
49 public static const VIEW_EDIT_CLOSED_CODED: String = "EditClosedCoded";
50
51 public static const APP_NAME_BIGBOARD: String = "bigboard";
52 public static const APP_NAME_TRACKING: String = "tracking";
53
54 public var bigboardInfo: BigBoardDebugInfo;
55
56 public var appName: String = "";
57 public var appClientVersion: String = "1.0.1.WorldVistA-SNAPSHOT";
58 public var contextRoot: String = "";
59 public var appViewList: ArrayCollection;
60 public var appViewState: int = VIEW_APP_INTRO;
61 public var logEntryViewState: String = "";
62 public var logEntryTitle: String = "";
63
64 // Session information
65 public var session: SessionVO;
66 public var rootURL: String;
67 public var logoutURL: String;
68 public var helpContextRootURL: String;
69
70 // Reports
71 public var reports: ReportsModel = new ReportsModel();
72
73 // Debug
74 public var debug: DebugModel = new DebugModel();
75
76 // Log Editor
77 public var logArea: int;
78 public var logEntryList: LogEntryList = new LogEntryList();
79 public var logEdit: LogEdit = new LogEdit();
80 public var logEditParams: LogEditParamsVO;
81 public var matchingDiagnoses: ArrayCollection;
82 public var matchingDiagnosesLoaded: Boolean = false;
83
84 // Patient Selection
85 public var patientChecksModel:PatientChecksModel = new PatientChecksModel();
86
87 public var matchingClosedVisits: ArrayCollection;
88 public var matchingClosedVisitsIndex: int = -1;
89
90 // Display Board
91 public var boardSortField: String = "";
92 public var boardSortDescending: Boolean;
93 public var boardReady: Boolean = false;
94 public var boardData: XMLListCollection;
95 public var boardSpec: BoardSpec = new BoardSpec();
96 public var boardLastUpdated: Date;
97
98 // Configure
99 public var config: Config = new Config();
100
101 // Connectivity
102 public var reconnectFunction:Function;
103 public var disconnectionFault:Fault = null;
104 private var _disconnected: Boolean = false;
105 private var _connecting: Boolean = false;
106 private var _reconnectTimer: Timer;
107
108 public var reloadFunction:Function; // function for reloading the flash application in case of fatal error or sommat
109
110 private static const RECONNECT_SECONDS:int = 10;
111
112 //Singleton logic -----------------------------------------------------------
113
114 private static var modelLocator: TrackingModelLocator;
115
116 public static function getInstance(): TrackingModelLocator
117 {
118 if (modelLocator == null) {
119 modelLocator = new TrackingModelLocator();
120 }
121 return modelLocator;
122 }
123
124 public function TrackingModelLocator()
125 {
126 if (modelLocator != null) {
127 throw new Error("Only one TrackingModelLocator should be instantiated.");
128 }
129 }
130
131 public function isDisconnected(): Boolean {
132 return disconnected;
133 }
134
135 public function buildSiteDate(): Date
136 {
137 var now:Date = new Date();
138 return new Date(now.time - session.baseTime.time + session.siteTime.time);
139 }
140
141 public function synchToLastEntry(): void
142 {
143 for (var i:int = 0; i < logEntryList.entries.length; i++) {
144 var logSelector: LogSelectorVO = logEntryList.entries[i];
145 if (logSelector.id == logEdit.entry.id) {
146 logEntryList.selectedIndex = -1; // force binding to fire
147 logEntryList.selectedIndex = i;
148 logEntryList.selectedID = logSelector.id;
149 return;
150 } // if
151 } // for
152 } // synchToLastEntry
153
154 public function synchToClosedEntry(): void
155 {
156 for (var i: int = 0; i < matchingClosedVisits.length; i++) {
157 var visit: VisitVO = matchingClosedVisits[i];
158 if (visit.id == logEdit.entry.id) {
159 matchingClosedVisitsIndex = -1; // force binding to fire
160 matchingClosedVisitsIndex = i;
161 return;
162 } // if
163 } // for
164 } // synchToClosedEntry
165
166 public function appViewTitle(view: int): String
167 {
168 switch (appViewState) {
169 case VIEW_APP_SIGN_IN:
170 return "EDIS Sign In";
171 case VIEW_APP_TRIAGE:
172 return "EDIS Triage";
173 case VIEW_APP_UPDATE:
174 return "EDIS Update";
175 case VIEW_APP_DISPOSITION:
176 return "EDIS Disposition";
177 case VIEW_APP_EDIT_CLOSED:
178 return "EDIS Edit Closed Visit";
179 case VIEW_APP_DISPLAY_BOARD:
180 return "EDIS Display Board";
181 case VIEW_APP_ASSIGN_STAFF:
182 return "EDIS Staff List";
183 case VIEW_APP_REPORTS:
184 return "EDIS Reports";
185 case VIEW_APP_CONFIGURE:
186 return "EDIS Configuration";
187 case VIEW_APP_NO_VIEWS:
188 return "EDIS";
189 default:
190 return "EDIS";
191 }
192 }
193
194 public function appViewHelp(view: int): String
195 {
196 switch (appViewState) {
197 case VIEW_APP_SIGN_IN:
198 return "SignIn";
199 case VIEW_APP_TRIAGE:
200 return "Triage";
201 case VIEW_APP_UPDATE:
202 return "Update";
203 case VIEW_APP_DISPOSITION:
204 return "Disposition";
205 case VIEW_APP_EDIT_CLOSED:
206 return "EditClosedVisit";
207 case VIEW_APP_DISPLAY_BOARD:
208 return "DisplayBoard";
209 case VIEW_APP_ASSIGN_STAFF:
210 return "StaffList";
211 case VIEW_APP_REPORTS:
212 return "Reports";
213 case VIEW_APP_CONFIGURE:
214 return "Configuration";
215 case VIEW_APP_NO_VIEWS:
216 return "General";
217 default:
218 return "General";
219 }
220 }
221
222 public function setEditState(): void
223 {
224 // always start at the beginning
225 logEntryViewState = "";
226
227 if (logEdit.entry == null) {
228 logEntryViewState = VIEW_EDIT_MESSAGE;
229 return;
230 }
231
232 // convenient place to clear lookup list since this is called when entry changes
233 matchingDiagnoses = null;
234
235 switch (appViewState) {
236 case VIEW_APP_SIGN_IN:
237 logEntryViewState = VIEW_EDIT_SIGN_IN;
238 break;
239 case VIEW_APP_TRIAGE:
240 logEntryViewState = VIEW_EDIT_TRIAGE;
241 break;
242 case VIEW_APP_UPDATE:
243 logEditParams.promptResidents ?
244 logEntryViewState = VIEW_EDIT_UPDATE : logEntryViewState = VIEW_EDIT_UPDATE_NORES;
245 break;
246 case VIEW_APP_DISPOSITION:
247 logEditParams.codedDiagnosis ?
248 logEntryViewState = VIEW_EDIT_DISP_DELAY_CODED :
249 logEntryViewState = VIEW_EDIT_DISP_DELAY;
250 break;
251 case VIEW_APP_EDIT_CLOSED:
252 logEditParams.codedDiagnosis ?
253 logEntryViewState = VIEW_EDIT_CLOSED_CODED :
254 logEntryViewState = VIEW_EDIT_CLOSED;
255 break;
256 default:
257 logEntryViewState = VIEW_EDIT_MESSAGE;
258 break;
259 } // switch
260 } // setEditState
261
262 public function modifiedViews(): String
263 {
264 var x: String = "";
265 if (logEdit.dirty) {
266 var viewName: String = logEntryViewState;
267 viewName = (viewName.substr(0, 4) == "Disp") ? "Disposition" : viewName;
268 viewName = (viewName.substr(0, 4) == "Upda") ? "Update" : viewName;
269 viewName = (viewName.substr(0, 4) == "Edit") ? "Edit Closed" : viewName;
270 x += "\t" + viewName + "\n";
271 }
272 x += config.staffMods ? "\tStaff Configuration \n" : "";
273 x += config.bedMods ? "\tRoom / Area Configuration \n" : "";
274 x += config.boardMods ? "\tDisplay Board Configuration \n" : "";
275 x += config.colorMods ? "\tColor Configuration \n" : "";
276 x += config.paramMods ? "\tParameter Configuration \n" : "";
277 x += config.selectionMods ? "\tSelection List Configuration \n" : "";
278 return x;
279 }
280
281 public function entryRemoveReady(): void
282 {
283 var ready: Boolean = true;
284
285 // special dispositions that allow immediate removal
286 if ((logEdit.entry.disposition == logEditParams.errorIEN) ||
287 (logEdit.entry.disposition == logEditParams.nurseEvalIEN) ||
288 (logEdit.entry.disposition == logEditParams.leftIEN)) {
289 logEdit.entry.removeReady = true;
290 return;
291 }
292
293 if (logEdit.entry.requireDiagnosis && (logEdit.entry.diagnoses.length == 0)) {
294 ready = false;
295 }
296 if (logEdit.entry.requireDisposition &&
297 ((logEdit.entry.disposition == logEditParams.emptyValue) ||
298 (logEdit.entry.disposition < 1))) {
299 ready = false;
300 }
301 if (logEdit.entry.requireDelay &&
302 ((logEdit.entry.delay == logEditParams.emptyValue) ||
303 (logEdit.entry.delay < 1))) {
304 ready = false;
305 }
306 if (Number(logEdit.entry.provider) < 1) {
307 ready = false;
308 }
309
310 logEdit.entry.removeReady = ready;
311 }
312
313 public function logout(): void {
314 var request: URLRequest = new URLRequest(logoutURL);
315 navigateToURL(request, "_top");
316 }
317
318 public function get disconnected(): Boolean {
319 return _disconnected;
320 }
321
322 public function set disconnected(b:Boolean):void {
323 if (_disconnected && !b) {
324 stopReconnectCountdown();
325 disconnectionFault = null;
326 } else if (!_disconnected && b) {
327 startReconnectCountdown();
328 }
329 _disconnected = b;
330 }
331
332 public function get connecting(): Boolean {
333 return _connecting;
334 }
335
336 public function set connecting(b:Boolean):void {
337 _connecting = b;
338 if (disconnected) {
339 if (!_connecting) {
340 startReconnectCountdown();
341 } else {
342 stopReconnectCountdown();
343 }
344 }
345 }
346
347 [Bindable(event="reconnectSecondsChanged")]
348 public function get reconnectSeconds():int {
349 if (_reconnectTimer == null) return RECONNECT_SECONDS;
350 return _reconnectTimer.repeatCount - _reconnectTimer.currentCount;
351 }
352
353 public function attemptReconnect():void {
354 stopReconnectCountdown();
355 reconnectFunction.call(null);
356 }
357
358 private function reconnectCountDown(e:TimerEvent):void {
359 dispatchEvent(new Event("reconnectSecondsChanged"));
360 }
361
362 private function reconnectTimerComplete(e:TimerEvent):void {
363 attemptReconnect();
364 }
365
366 private function startReconnectCountdown():void {
367 if (_reconnectTimer == null) {
368 _reconnectTimer = new Timer(1000, RECONNECT_SECONDS);
369 _reconnectTimer.addEventListener(TimerEvent.TIMER, reconnectCountDown);
370 _reconnectTimer.addEventListener(TimerEvent.TIMER_COMPLETE, reconnectTimerComplete);
371 }
372 _reconnectTimer.reset();
373 _reconnectTimer.start();
374 }
375
376 private function stopReconnectCountdown():void {
377 if (_reconnectTimer != null) {
378 _reconnectTimer.reset();
379 }
380 }
381
382} // class
383} // package
Note: See TracBrowser for help on using the repository browser.