kc-sdk 7.0.392-rc → 7.0.407

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,769 +1,734 @@
1
1
  'use strict';
2
2
 
3
- var kcSdkVersion = '7.0.392';
3
+ var kcSdkVersion = '7.0.407';
4
4
 
5
5
  var kcSdk = function kcSdk() {
6
- // locals
7
- var communicationPacket = {
8
- sender: 'kcSdk',
9
- windowName: '',
10
- action: '',
11
- value: null
12
- };
13
- var workflow = [];
14
- var callbackFns = [];
15
-
16
- var responseTime;
17
- var timeoutThresholdSeconds = 30;
18
-
19
- // window locals
20
- var kcWindowName = 'kc-sdk-launched-instance';
21
- var kcSentinelWindowName = '';
22
- var kcWindowParams = ['height=' + screen.height, 'width=' + screen.width, 'location=0', 'top=10', 'left=10'].join(',');
23
-
24
- var encoderWindowName = 'encoder-sdk-launched-instance';
25
- var encoderWindowParams = 'resizable=1,scrollbars=0,location=0,menubar=0,toolbar=0,top=10,left=10,width=950,height=500';
26
-
27
- var kcWindow = {
28
- reference: null,
29
- opened: false,
30
- name: kcWindowName,
31
- kcSentinelName: kcSentinelWindowName,
32
- currentWorkflow: {},
33
- responseTime: responseTime,
34
- launch: launchKc,
35
- openKcSentinel: openKcSentinel,
36
- loadPatientRecord: loadPatientRecord,
37
- assignConfig: assignConfig,
38
- setAuthToken: setAuthToken,
39
- setI9I10State: setI9I10State,
40
- setDemographics: setDemographics,
41
- addCodes: addCodes,
42
- clearPatientRecord: clearPatientRecord,
43
- closeAllKCWindowsExceptEncoder: closeAllKCWindowsExceptEncoder,
44
- deleteCodes: deleteCodes,
45
- getPayerList: getPayerList,
46
- getRowSpecificInfo: getRowSpecificInfo,
47
- clearSelectedRow: clearSelectedRow,
48
- hasCriticalEdits: hasCriticalEdits,
49
- hasEdits: hasEdits,
50
- launchCodeSummaryReport: launchCodeSummaryReport,
51
- launchEdits: launchEdits,
52
- launchFacilityLookup: launchFacilityLookup,
53
- launchIndex: launchIndex,
54
- launchLogic: launchLogic,
55
- launchTabular: launchTabular,
56
- logout: logout,
57
- openEncoder: openEncoderWindow,
58
- resetApplication: resetApplication,
59
- savePatientRecord: savePatientRecord,
60
- updateCodes: updateCodes,
61
- updateDemographics: updateDemographics,
62
- authTokenData: {}
63
- };
64
-
65
- var encoderWindow = {
66
- reference: null,
67
- name: encoderWindowName,
68
- opened: false,
69
- currentWorkflow: {},
70
- responseTime: responseTime,
71
- launch: launchEncoder,
72
- setAuthToken: setAuthToken,
73
- setI9I10State: setI9I10State,
74
- setDemographics: setDemographics,
75
- launchIndex: launchIndex,
76
- launchLogic: launchLogic,
77
- launchTabular: launchTabular,
78
- authTokenData: {}
79
- };
80
-
81
- // service
82
- var service = {
83
- encoderTabs: encoderTabs,
84
- sessionTypes: sessionTypes,
85
- patientType: patientType,
86
- i9I10States: i9I10States,
87
- listenerResponse: listenerResponse,
88
- kcWindow: kcWindow,
89
- encoderWindow: encoderWindow,
90
- closeAllKCWindows: closeAllKCWindows,
91
- kcWindowIsListening: false,
92
- encoderWindowIsListening: false,
93
- launchReferences: kcMreService.launchMre,
94
- setCallback: setCallback,
95
- callbacks: callbacks,
96
- workflow: workflow,
97
- addToWorkflow: addToWorkflow,
98
- removeFromWorkflow: removeFromWorkflow,
99
- processWorkflow: processWorkflow,
100
- clearWorkflow: clearWorkflow,
101
- workflowComplete: true,
102
- listenerException: false,
103
- version: kcSdkVersion
104
- };
105
-
106
- // listener for opened window messages
107
- window.addEventListener(
108
- 'message',
109
- function (e) {
110
- if (event.data.callback === 'kcRefreshed' && service.kcWindow.reference) {
111
- service.kcWindow.opened = true;
112
- service.kcWindowIsListening = true;
113
- } else if (event.data.callback === 'encoderRefreshed' && service.encoderWindow.reference) {
114
- service.encoderWindow.opened = true;
115
- service.encoderWindowIsListening = true;
116
- }
117
-
118
- if (!(service.kcWindow.reference && event.data.sender === 'kcWindow') && !(service.encoderWindow.reference && event.data.sender === 'encoderWindow')) {
119
- return;
120
- }
121
-
122
- var needsAuthentication = false;
123
- var callback = event.data.callback;
124
-
125
- switch (event.data.action) {
126
- case 'sdkServiceResponse':
127
- if (event.data.sender === 'kcWindow') {
128
- if (event.data.callback === 'kcListeningChanged') {
129
- service.kcWindowIsListening = service.listenerResponse.OPENKC === event.data.value;
130
- //if (service.kcWindow.name === kcSentinelWindowName) {
131
- // if (service.kcWindowIsListening) {
132
- // service.kcWindow.opened = true;
133
- // }
134
- // else {
135
- // closeKcWindow();
136
- // }
137
-
138
- //} else
139
- if (service.kcWindowIsListening) {
140
- service.kcWindow.opened = true;
141
- needsAuthentication = (service.workflow.length === 0 || (service.workflow.length > 0 && service.workflow[0].name !== 'setAuthToken'));
142
- } else {
6
+ // locals
7
+ var communicationPacket = {
8
+ sender: 'kcSdk',
9
+ windowName: '',
10
+ action: '',
11
+ value: null
12
+ };
13
+ var workflow = [];
14
+ var callbackFns = [];
15
+
16
+ var responseTime;
17
+ var timeoutThresholdSeconds = 30;
18
+
19
+ // window locals
20
+ var kcWindowName = 'kc-sdk-launched-instance';
21
+ var kcWindowParams = ['height=' + screen.height, 'width=' + screen.width, 'location=0', 'top=10', 'left=10'].join(',');
22
+
23
+ var encoderWindowName = 'encoder-sdk-launched-instance';
24
+ var encoderWindowParams = 'resizable=1,scrollbars=0,location=0,menubar=0,toolbar=0,top=10,left=10,width=950,height=500';
25
+
26
+ var kcWindow = {
27
+ reference: null,
28
+ opened: false,
29
+ name: kcWindowName,
30
+ currentWorkflow: {},
31
+ responseTime: responseTime,
32
+ launch: launchKc,
33
+ loadPatientRecord: loadPatientRecord,
34
+ assignConfig: assignConfig,
35
+ setAuthToken: setAuthToken,
36
+ setI9I10State: setI9I10State,
37
+ setDemographics: setDemographics,
38
+ addCodes: addCodes,
39
+ clearPatientRecord: clearPatientRecord,
40
+ closeAllKCWindowsExceptEncoder: closeAllKCWindowsExceptEncoder,
41
+ deleteCodes: deleteCodes,
42
+ getPayerList: getPayerList,
43
+ getRowSpecificInfo: getRowSpecificInfo,
44
+ clearSelectedRow: clearSelectedRow,
45
+ hasCriticalEdits: hasCriticalEdits,
46
+ hasEdits: hasEdits,
47
+ launchCodeSummaryReport: launchCodeSummaryReport,
48
+ launchEdits: launchEdits,
49
+ launchFacilityLookup: launchFacilityLookup,
50
+ launchIndex: launchIndex,
51
+ launchLogic: launchLogic,
52
+ launchTabular: launchTabular,
53
+ logout: logout,
54
+ openEncoder: openEncoderWindow,
55
+ resetApplication: resetApplication,
56
+ savePatientRecord: savePatientRecord,
57
+ updateCodes: updateCodes,
58
+ updateDemographics: updateDemographics,
59
+ authTokenData: {}
60
+ };
61
+
62
+ var encoderWindow = {
63
+ reference: null,
64
+ name: encoderWindowName,
65
+ opened: false,
66
+ currentWorkflow: {},
67
+ responseTime: responseTime,
68
+ launch: launchEncoder,
69
+ setAuthToken: setAuthToken,
70
+ setI9I10State: setI9I10State,
71
+ setDemographics: setDemographics,
72
+ launchIndex: launchIndex,
73
+ launchLogic: launchLogic,
74
+ launchTabular: launchTabular,
75
+ authTokenData: {}
76
+ };
77
+
78
+ // service
79
+ var service = {
80
+ encoderTabs: encoderTabs,
81
+ sessionTypes: sessionTypes,
82
+ patientType: patientType,
83
+ i9I10States: i9I10States,
84
+ listenerResponse: listenerResponse,
85
+ kcWindow: kcWindow,
86
+ encoderWindow: encoderWindow,
87
+ closeAllKCWindows: closeAllKCWindows,
88
+ kcWindowIsListening: false,
89
+ encoderWindowIsListening: false,
90
+ launchReferences: kcMreService.launchMre,
91
+ setCallback: setCallback,
92
+ callbacks: callbacks,
93
+ workflow: workflow,
94
+ addToWorkflow: addToWorkflow,
95
+ removeFromWorkflow: removeFromWorkflow,
96
+ processWorkflow: processWorkflow,
97
+ clearWorkflow: clearWorkflow,
98
+ workflowComplete: true,
99
+ listenerException: false,
100
+ version: kcSdkVersion
101
+ };
102
+
103
+ // listener for opened window messages
104
+ window.addEventListener(
105
+ 'message',
106
+ function (e) {
107
+ if (event.data.callback === 'kcRefreshed' && service.kcWindow.reference) {
108
+ service.kcWindow.opened = true;
109
+ service.kcWindowIsListening = true;
110
+ } else if (event.data.callback === 'encoderRefreshed' && service.encoderWindow.reference) {
111
+ service.encoderWindow.opened = true;
112
+ service.encoderWindowIsListening = true;
113
+ }
114
+
115
+ if (!(service.kcWindow.reference && event.data.sender === 'kcWindow') && !(service.encoderWindow.reference && event.data.sender === 'encoderWindow')) {
116
+ return;
117
+ }
118
+
119
+ var needsAuthentication = false;
120
+ var callback = event.data.callback;
121
+
122
+ switch (event.data.action) {
123
+ case 'sdkServiceResponse':
124
+ if (event.data.sender === 'kcWindow') {
125
+ if (event.data.callback === 'kcListeningChanged') {
126
+ service.kcWindowIsListening = service.listenerResponse.OPENKC === event.data.value;
127
+ if (service.kcWindowIsListening) {
128
+ needsAuthentication = service.workflow.length === 0 || (service.workflow.length > 0 && service.workflow[0].name !== 'setAuthToken');
129
+ } else {
130
+ closeKcWindow();
131
+ }
132
+ } else if (event.data.callback === 'kcRefreshed') {
133
+ callback = 'sdkServiceResponse';
134
+ clearWorkflow();
135
+ } else {
136
+ callback = 'sdkServiceResponse';
137
+ }
138
+ } else if (event.data.sender === 'encoderWindow') {
139
+ if (event.data.callback === 'encoderListeningChanged') {
140
+ service.encoderWindowIsListening = service.listenerResponse.OPENENCODER === event.data.value;
141
+ if (service.encoderWindowIsListening) {
142
+ needsAuthentication = service.workflow.length === 0 || (service.workflow.length > 0 && service.workflow[0].name !== 'setAuthToken');
143
+ } else {
144
+ closeEncoderWindow();
145
+ }
146
+ } else if (event.data.callback === 'encoderRefreshed') {
147
+ callback = 'sdkServiceResponse';
148
+ clearWorkflow();
149
+ } else {
150
+ callback = 'sdkServiceResponse';
151
+ }
152
+ }
153
+ break;
154
+ case 'sdkRequestException':
155
+ service.listenerException = true;
156
+ callback = event.data.action;
157
+ break;
158
+ default:
159
+ break;
160
+ }
161
+
162
+ invokeCallback(callback, event.data);
163
+
164
+ if (service.listenerException) {
165
+ stopWorkflow();
166
+ service.listenerException = false;
167
+ }
168
+
169
+ var cwf = event.data.sender === 'kcWindow' ? service.kcWindow.currentWorkflow : service.encoderWindow.currentWorkflow;
170
+
171
+ if (!cwf) {
172
+ stopWorkflow();
173
+ return;
174
+ }
175
+
176
+ if (needsAuthentication) {
177
+ service.workflow.unshift({
178
+ name: 'setAuthToken',
179
+ fn: service[event.data.sender].setAuthToken,
180
+ sendToWindow: [event.data.sender],
181
+ args: [service[event.data.sender].authTokenData, service[event.data.sender].name]
182
+ });
183
+ }
184
+
185
+ if (service.workflow.length === 0) {
186
+ clearTimeout(service[event.data.sender].responseTime);
187
+ }
188
+
189
+ if (cwf.workflowCompleteMessage === event.data.value) {
190
+ clearTimeout(service[event.data.sender].responseTime);
191
+ processWorkflow(service[event.data.sender]);
192
+ }
193
+ },
194
+ false
195
+ );
196
+
197
+ window.addEventListener('unload', function (event) {
198
+ service.closeAllKCWindows();
199
+ });
200
+
201
+ return service;
202
+ /////////////// return service
203
+
204
+ function openKc(url, authToken) {
205
+ if (!service.kcWindow.reference || !windowExists(service.kcWindow) || !service.kcWindowIsListening) {
206
+ kcWindow.authTokenData = authToken;
207
+
208
+ service.kcWindow.reference = window.open(url, kcWindowName, kcWindowParams);
209
+ service.kcWindow.opened = true;
210
+ service.kcWindow.reference.focus();
211
+ } else {
212
+ service.kcWindow.reference.focus();
213
+ processWorkflow(service.kcWindow);
214
+ }
215
+ }
216
+
217
+ function openEncoder(url, authToken) {
218
+ if (!service.encoderWindow.reference || !windowExists(service.encoderWindow) || !service.encoderWindowIsListening) {
219
+ encoderWindow.authTokenData = authToken;
220
+
221
+ service.encoderWindow.reference = window.open(url, encoderWindowName, encoderWindowParams);
222
+ service.encoderWindow.opened = true;
223
+ service.encoderWindow.reference.focus();
224
+ } else {
225
+ service.encoderWindow.reference.focus();
226
+ processWorkflow(service.encoderWindow);
227
+ }
228
+ }
229
+
230
+ // apis to send to our open windows
231
+ function loadPhraseInLogic(input) {
232
+ communicationPacket.action = 'logicRequest';
233
+ communicationPacket.value = input;
234
+ communication(communicationPacket, listeningWindows.ENCODER);
235
+ }
236
+
237
+ function loadPhraseInIndex(input) {
238
+ communicationPacket.action = 'indexRequest';
239
+ communicationPacket.value = input;
240
+ communication(communicationPacket, listeningWindows.ENCODER);
241
+ }
242
+
243
+ function loadCodeInTabular(input) {
244
+ communicationPacket.action = 'tabularRequest';
245
+ communicationPacket.value = input;
246
+ communication(communicationPacket, listeningWindows.ENCODER);
247
+ }
248
+
249
+ function loadPatientRecord(patientRecord) {
250
+ communicationPacket.action = 'loadPatientRecord';
251
+ communicationPacket.value = patientRecord;
252
+ communication(communicationPacket, listeningWindows.KC);
253
+ }
254
+
255
+ function assignConfig(input) {
256
+ communicationPacket.action = 'assignConfig';
257
+ communicationPacket.value = input;
258
+ communication(communicationPacket, listeningWindows.KC);
259
+ }
260
+
261
+ function setI9I10State(state) {
262
+ communicationPacket.action = 'setI9I10State';
263
+ communicationPacket.value = state;
264
+ communication(communicationPacket, listeningWindows.ALL);
265
+ }
266
+ function setAuthToken(data) {
267
+ communicationPacket.action = 'setAuthToken';
268
+ communicationPacket.value = data;
269
+ communication(communicationPacket, listeningWindows.ALL);
270
+ }
271
+
272
+ function setDemographics(demographicsData) {
273
+ communicationPacket.action = 'setDemographics';
274
+ communicationPacket.value = demographicsData;
275
+ communication(communicationPacket, listeningWindows.ALL);
276
+ }
277
+
278
+ function encoderStartupComplete() {
279
+ communicationPacket.action = 'encoderStartupComplete';
280
+ communicationPacket.value = '';
281
+ communication(communicationPacket, listeningWindows.ENCODER);
282
+ }
283
+
284
+ function closeAllKCWindows() {
285
+ communicationPacket.action = 'closeAllKCWindows';
286
+ communicationPacket.value = null;
287
+ communication(communicationPacket, listeningWindows.ALL);
288
+ }
289
+
290
+ function addCodes(codesData) {
291
+ communicationPacket.action = 'addCodes';
292
+ communicationPacket.value = codesData;
293
+ communication(communicationPacket, listeningWindows.KC);
294
+ if(service.kcWindow.opened === true) {
295
+ service.kcWindow.reference.focus();
296
+ }
297
+ }
298
+
299
+ function clearPatientRecord() {
300
+ communicationPacket.action = 'clearPatientRecord';
301
+ communicationPacket.value = null;
302
+ communication(communicationPacket, listeningWindows.KC);
303
+ if (service.kcWindow.opened === true) {
304
+ service.kcWindow.reference.focus();
305
+ }
306
+ }
307
+
308
+ function closeAllKCWindowsExceptEncoder() {
309
+ communicationPacket.action = 'closeAllKCWindowsExceptEncoder';
310
+ communicationPacket.value = null;
311
+ communication(communicationPacket, listeningWindows.ALL);
312
+ }
313
+
314
+ function deleteCodes(codes) {
315
+ communicationPacket.action = 'deleteCodes';
316
+ communicationPacket.value = codes;
317
+ communication(communicationPacket, listeningWindows.KC);
318
+ if (service.kcWindow.opened === true) {
319
+ service.kcWindow.reference.focus();
320
+ }
321
+ }
322
+
323
+ function getPayerList(payerList) {
324
+ communicationPacket.action = 'getPayerList';
325
+ communicationPacket.value = payerList;
326
+ communication(communicationPacket, listeningWindows.KC);
327
+ }
328
+
329
+ function getRowSpecificInfo(uniqueIds) {
330
+ communicationPacket.action = 'getRowSpecificInfo';
331
+ communicationPacket.value = uniqueIds;
332
+ communication(communicationPacket, listeningWindows.KC);
333
+ }
334
+
335
+ function clearSelectedRow() {
336
+ communicationPacket.action = 'clearSelectedRow';
337
+ communicationPacket.value = null;
338
+ communication(communicationPacket, listeningWindows.KC);
339
+ if (service.kcWindow.opened === true) {
340
+ service.kcWindow.reference.focus();
341
+ }
342
+ }
343
+ function hasCriticalEdits() {
344
+ communicationPacket.action = 'hasCriticalEdits';
345
+ communicationPacket.value = null;
346
+ communication(communicationPacket, listeningWindows.KC);
347
+ }
348
+ function hasEdits() {
349
+ communicationPacket.action = 'hasEdits';
350
+ communicationPacket.value = null;
351
+ communication(communicationPacket, listeningWindows.KC);
352
+ }
353
+ function launchCodeSummaryReport() {
354
+ communicationPacket.action = 'launchCodeSummaryReport';
355
+ communicationPacket.value = null;
356
+ communication(communicationPacket, listeningWindows.KC);
357
+ }
358
+ function launchEdits() {
359
+ communicationPacket.action = 'launchEdits';
360
+ communicationPacket.value = null;
361
+ communication(communicationPacket, listeningWindows.KC);
362
+ }
363
+ function launchFacilityLookup(codes) {
364
+ communicationPacket.action = 'launchFacilityLookup'
365
+ communicationPacket.value = codes;
366
+ communication(communicationPacket, listeningWindows.KC)
367
+ }
368
+ function launchIndex(codes) {
369
+ communicationPacket.action = 'launchIndex';
370
+ communicationPacket.value = codes;
371
+ communication(communicationPacket, service.encoderWindowIsListening ? listeningWindows.ENCODER : listeningWindows.KC);
372
+ if (service.encoderWindow.opened) {
373
+ service.encoderWindow.reference.focus();
374
+ }
375
+
376
+ }
377
+ function launchLogic(codes) {
378
+ communicationPacket.action = 'launchLogic';
379
+ communicationPacket.value = codes;
380
+ communication(communicationPacket, service.encoderWindowIsListening ? listeningWindows.ENCODER : listeningWindows.KC);
381
+ if (service.encoderWindow.opened == true) {
382
+ service.encoderWindow.reference.focus();
383
+ }
384
+
385
+ }
386
+ function launchTabular(codes) {
387
+ communicationPacket.action = 'launchTabular';
388
+ communicationPacket.value = codes;
389
+ communication(communicationPacket, service.encoderWindowIsListening ? listeningWindows.ENCODER : listeningWindows.KC);
390
+ if (service.encoderWindow.opened == true) {
391
+ service.encoderWindow.reference.focus();
392
+ }
393
+ }
394
+ function logout() {
395
+ communicationPacket.action = 'logout';
396
+ communicationPacket.value = null;
397
+ communication(communicationPacket, listeningWindows.KC);
398
+ if (service.kcWindow.opened === true) {
399
+ service.kcWindow.reference.focus();
400
+ }
401
+ }
402
+ function resetApplication() {
403
+ communicationPacket.action = 'resetApplication';
404
+ communicationPacket.value = null;
405
+ communication(communicationPacket, listeningWindows.KC);
406
+ if (service.kcWindow.opened === true) {
407
+ service.kcWindow.reference.focus();
408
+ }
409
+ }
410
+ function savePatientRecord() {
411
+ communicationPacket.action = 'savePatientRecord';
412
+ communicationPacket.value = null;
413
+ communication(communicationPacket, listeningWindows.KC);
414
+ if (service.kcWindow.opened === true) {
415
+ service.kcWindow.reference.focus();
416
+ }
417
+ }
418
+ function updateCodes(codes) {
419
+ communicationPacket.action = 'updateCodes';
420
+ communicationPacket.value = codes;
421
+ communication(communicationPacket, listeningWindows.KC);
422
+ if (service.kcWindow.opened === true) {
423
+ service.kcWindow.reference.focus();
424
+ }
425
+ }
426
+ function updateDemographics(updatedDemographics) {
427
+ communicationPacket.action = 'updateDemographics';
428
+ communicationPacket.value = updatedDemographics;
429
+ communication(communicationPacket, listeningWindows.KC);
430
+ if (service.kcWindow.opened === true) {
431
+ service.kcWindow.reference.focus();
432
+ }
433
+ }
434
+
435
+ function openEncoderWindow() {
436
+ communicationPacket.action = 'openEncoder';
437
+ communicationPacket.value = null;
438
+ communication(communicationPacket,service.encoderWindowIsListening ? listeningWindows.ENCODER : listeningWindows.KC);
439
+ if (service.encoderWindow.opened == true) {
440
+ service.encoderWindow.reference.focus();
441
+ }
442
+ }
443
+
444
+ // workflow to launch kc
445
+ function launchKc(url, authToken, state, demographics) {
446
+ kcWindow.authTokenData = authToken;
447
+
448
+ var wfArray = [
449
+ {
450
+ fn: openKc,
451
+ args: [url, authToken]
452
+ },
453
+ {
454
+ fn: setI9I10State,
455
+ args: state
456
+ },
457
+ {
458
+ fn: setDemographics,
459
+ args: demographics
460
+ }
461
+ ];
462
+
463
+ var updatedWf = wfArray.concat(service.workflow);
464
+ service.clearWorkflow();
465
+
466
+ service.addToWorkflow(updatedWf);
467
+
468
+ service.processWorkflow(service.kcWindow);
469
+ }
470
+
471
+ // workflow to launch encoder
472
+ function launchEncoder(url, authToken, state, demographics, request) {
473
+ encoderWindow.authTokenData = authToken;
474
+
475
+ var logicIndexRequest = JSON.stringify(
476
+ {
477
+ sessionType: request.sessionType,
478
+ phrase: request.codePhrase
479
+ },
480
+ null,
481
+ 2
482
+ );
483
+
484
+ var tabularRequest = JSON.stringify(
485
+ {
486
+ sessionType: request.sessionType,
487
+ code: request.codePhrase
488
+ },
489
+ null,
490
+ 2
491
+ );
492
+
493
+ var wfArray = [
494
+ {
495
+ fn: openEncoder,
496
+ args: [url, authToken]
497
+ },
498
+ {
499
+ fn: setI9I10State,
500
+ args: state
501
+ },
502
+ {
503
+ fn: setDemographics,
504
+ args: demographics
505
+ },
506
+ {
507
+ fn: encoderStartupComplete,
508
+ args: []
509
+ }
510
+ ];
511
+
512
+ if (request.encoderTab === service.encoderTabs.LOGIC) {
513
+ wfArray.push({
514
+ fn: loadPhraseInLogic,
515
+ args: logicIndexRequest
516
+ });
517
+ } else if (request.encoderTab === service.encoderTabs.INDEX) {
518
+ wfArray.push({
519
+ fn: loadPhraseInIndex,
520
+ args: logicIndexRequest
521
+ });
522
+ } else if (request.encoderTab === service.encoderTabs.TABULAR) {
523
+ wfArray.push({
524
+ fn: loadCodeInTabular,
525
+ args: tabularRequest
526
+ });
527
+ }
528
+
529
+ var updatedWf = wfArray.concat(service.workflow);
530
+ service.clearWorkflow();
531
+
532
+ service.addToWorkflow(updatedWf);
533
+
534
+ service.processWorkflow(service.encoderWindow);
535
+ }
536
+
537
+ // window functions
538
+ function communication(packet, listener) {
539
+ try {
540
+ var ourWindows = getWindowsToCommunicate(listener);
541
+
542
+ if (ourWindows.length === 0) {
543
+ console.log(new Error('No window listening'));
544
+ return;
545
+ }
546
+
547
+ if (packet.value) {
548
+ packet.value = typeof packet.value === 'string' ? JSON.parse(packet.value) : packet.value;
549
+ }
550
+ ourWindows.forEach(function (w) {
551
+ w.responseTime = 0;
552
+ packet.windowName = w.name;
553
+ messagingProvider.post(w.reference, packet);
554
+ responseTimeout(packet, w);
555
+ });
556
+ } catch (e) {
557
+ console.log(e);
558
+ stopWorkflow();
559
+ invokeCallback(service.callbacks.SDKEXCEPTION, { callback: packet.action, value: e });
560
+ }
561
+ }
562
+
563
+ function getWindowsToCommunicate(listener) {
564
+ var windowArray = [];
565
+
566
+ switch (listener) {
567
+ case listeningWindows.ENCODER:
568
+ if (service.encoderWindowIsListening) {
569
+ windowArray.push(service.encoderWindow);
570
+ }
571
+ break;
572
+
573
+ case listeningWindows.KC:
574
+ if (service.kcWindowIsListening) {
575
+ windowArray.push(service.kcWindow);
576
+ }
577
+ break;
578
+
579
+ case listeningWindows.ALL:
580
+ if (service.kcWindowIsListening) {
581
+ windowArray.push(service.kcWindow);
582
+ }
583
+ if (service.encoderWindowIsListening) {
584
+ windowArray.push(service.encoderWindow);
585
+ }
586
+
587
+ break;
588
+
589
+ default:
590
+ return [];
591
+ }
592
+
593
+ return windowArray.filter(function (w) {
594
+ return w !== null && windowExists(w);
595
+ });
596
+ }
597
+
598
+ function windowExists(window) {
599
+ if (!window.opened) {
600
+ if (!window.name) {
143
601
  closeKcWindow();
144
- }
145
- } else if (event.data.callback === 'kcRefreshed') {
146
- callback = 'sdkServiceResponse';
147
- clearWorkflow();
148
- } else {
149
- callback = 'sdkServiceResponse';
602
+ closeEncoderWindow();
150
603
  }
151
- } else if (event.data.sender === 'encoderWindow') {
152
- if (event.data.callback === 'encoderListeningChanged') {
153
- service.encoderWindowIsListening = service.listenerResponse.OPENENCODER === event.data.value;
154
- if (service.encoderWindowIsListening) {
155
- needsAuthentication = service.workflow.length === 0 || (service.workflow.length > 0 && service.workflow[0].name !== 'setAuthToken');
156
- } else {
604
+ if (window.name === service.kcWindow.name) {
605
+ closeKcWindow();
606
+ } else if (window.name === service.encoderWindow.name) {
157
607
  closeEncoderWindow();
158
- }
159
- } else if (event.data.callback === 'encoderRefreshed') {
160
- callback = 'sdkServiceResponse';
161
- clearWorkflow();
162
- } else {
163
- callback = 'sdkServiceResponse';
164
608
  }
165
- }
166
- break;
167
- case 'sdkRequestException':
168
- service.listenerException = true;
169
- callback = event.data.action;
170
- break;
171
- default:
172
- break;
173
- }
174
-
175
- invokeCallback(callback, event.data);
176
-
177
- if (service.listenerException) {
178
- stopWorkflow();
179
- service.listenerException = false;
180
- }
181
- if (kcSentinelWindowName !== '') {
182
- if (service[event.data.sender]) {
183
- clearTimeout(service[event.data.sender].responseTime);
609
+ return false;
184
610
  }
185
- return;
186
- }
187
- var cwf = event.data.sender === 'kcWindow' ? service.kcWindow.currentWorkflow : service.encoderWindow.currentWorkflow;
188
611
 
189
- if (!cwf) {
190
- stopWorkflow();
191
- return;
192
- }
193
-
194
- if (needsAuthentication) {
195
- service.workflow.unshift({
196
- name: 'setAuthToken',
197
- fn: service[event.data.sender].setAuthToken,
198
- sendToWindow: [event.data.sender],
199
- args: [service[event.data.sender].authTokenData, service[event.data.sender].name]
612
+ return true;
613
+ }
614
+
615
+ function closeKcWindow() {
616
+ service.kcWindow.opened = false;
617
+ service.kcWindowIsListening = false;
618
+ }
619
+
620
+ function closeEncoderWindow() {
621
+ service.encoderWindow.opened = false;
622
+ service.encoderWindowIsListening = false;
623
+ }
624
+
625
+ // workflow functions
626
+ function addToWorkflow(wf) {
627
+ var wfArray = Array.isArray(wf) ? wf : [wf];
628
+ var kcWindowFunctions = ['openKc', 'launchKc', 'loadPatientRecord', 'assignConfig', 'addCodes', 'clearPatientRecord', 'deleteCodes', 'getPayerList', 'getRowSpecificInfo', 'clearSelectedRow', 'hasCriticalEdits', 'hasEdits', 'launchCodeSummaryReport',
629
+ 'launchEdits', 'launchFacilityLookup', 'logout', 'resetApplication', 'savePatientRecord', 'updateCodes', 'updateDemographics'];
630
+ var encoderWindowFunctions = ['loadPhraseInLogic', 'loadPhraseInIndex', 'loadCodeInTabular'];
631
+ var allWindowFunctions = ['setI9I10State', 'setAuthToken', 'setDemographics', 'closeAllKCWindows', 'closeAllKCWindowsExceptEncoder', 'launchIndex', 'launchLogic', 'launchTabular','openEncoder'];
632
+
633
+ wfArray.forEach(function (w) {
634
+ w.sendToWindow = [];
635
+ if (kcWindowFunctions.indexOf(w.name) > -1) {
636
+ w.sendToWindow.push('kcWindow');
637
+ }
638
+ if (encoderWindowFunctions.indexOf(w.name) > -1) {
639
+ w.sendToWindow.push('encoderWindow');
640
+ }
641
+ if (allWindowFunctions.indexOf(w.name) > -1) {
642
+ w.sendToWindow.push('kcWindow');
643
+ w.sendToWindow.push('encoderWindow');
644
+ }
645
+ w.name = w.fn.name || w.fn.toString().match(/^function\s?([^\s(]*)/)[1];
646
+ service.workflow.push(w);
200
647
  });
201
- }
202
-
203
- if (service.workflow.length === 0) {
204
- clearTimeout(service[event.data.sender].responseTime);
205
- }
206
-
207
- if (cwf.workflowCompleteMessage === event.data.value) {
208
- clearTimeout(service[event.data.sender].responseTime);
209
- processWorkflow(service[event.data.sender]);
210
- }
211
- },
212
- false
213
- );
214
-
215
- window.addEventListener('unload', function (event) {
216
- service.closeAllKCWindows();
217
- });
218
-
219
- return service;
220
- /////////////// return service
221
-
222
- function openKc(url, authToken) {
223
- if (!service.kcWindow.reference || !windowExists(service.kcWindow) || !service.kcWindowIsListening) {
224
- kcWindow.authTokenData = authToken;
225
-
226
- service.kcWindow.reference = window.open(url, kcWindowName, kcWindowParams);
227
- service.kcWindow.opened = true;
228
- service.kcWindow.reference.focus();
229
- } else {
230
- service.kcWindow.reference.focus();
231
- processWorkflow(service.kcWindow);
232
- }
233
- }
234
-
235
- function openKcSentinel(url) {
236
- if (!service.kcWindow.reference || !windowExists(service.kcWindow) || !service.kcWindowIsListening) {
237
- kcSentinelWindowName = 'kc-sdk-launched-instance-sentinel'
238
- service.kcWindow.reference = window.open(url, kcWindowName, kcWindowParams);
239
- service.kcWindow.name = kcWindowName;
240
- service.kcWindow.opened = true;
241
- service.kcWindow.reference.focus();
242
- } else {
243
- service.kcWindow.reference.focus();
244
- }
245
- }
246
-
247
- function openEncoder(url, authToken) {
248
- if (!service.encoderWindow.reference || !windowExists(service.encoderWindow) || !service.encoderWindowIsListening) {
249
- encoderWindow.authTokenData = authToken;
250
-
251
- service.encoderWindow.reference = window.open(url, encoderWindowName, encoderWindowParams);
252
- service.encoderWindow.opened = true;
253
- service.encoderWindow.reference.focus();
254
- } else {
255
- service.encoderWindow.reference.focus();
256
- processWorkflow(service.encoderWindow);
257
- }
258
- }
259
-
260
- // apis to send to our open windows
261
- function loadPhraseInLogic(input) {
262
- communicationPacket.action = 'logicRequest';
263
- communicationPacket.value = input;
264
- communication(communicationPacket, listeningWindows.ENCODER);
265
- }
266
-
267
- function loadPhraseInIndex(input) {
268
- communicationPacket.action = 'indexRequest';
269
- communicationPacket.value = input;
270
- communication(communicationPacket, listeningWindows.ENCODER);
271
- }
272
-
273
- function loadCodeInTabular(input) {
274
- communicationPacket.action = 'tabularRequest';
275
- communicationPacket.value = input;
276
- communication(communicationPacket, listeningWindows.ENCODER);
277
- }
278
-
279
- function loadPatientRecord(patientRecord) {
280
- communicationPacket.action = 'loadPatientRecord';
281
- communicationPacket.value = patientRecord;
282
- communication(communicationPacket, listeningWindows.KC);
283
- }
284
-
285
- function assignConfig(input) {
286
- communicationPacket.action = 'assignConfig';
287
- communicationPacket.value = input;
288
- communication(communicationPacket, listeningWindows.KC);
289
- }
290
-
291
- function setI9I10State(state) {
292
- communicationPacket.action = 'setI9I10State';
293
- communicationPacket.value = state;
294
- communication(communicationPacket, listeningWindows.ALL);
295
- }
296
- function setAuthToken(data) {
297
- communicationPacket.action = 'setAuthToken';
298
- communicationPacket.value = data;
299
- communication(communicationPacket, listeningWindows.ALL);
300
- }
301
-
302
- function setDemographics(demographicsData) {
303
- communicationPacket.action = 'setDemographics';
304
- communicationPacket.value = demographicsData;
305
- communication(communicationPacket, listeningWindows.ALL);
306
- }
307
-
308
- function encoderStartupComplete() {
309
- communicationPacket.action = 'encoderStartupComplete';
310
- communicationPacket.value = '';
311
- communication(communicationPacket, listeningWindows.ENCODER);
312
- }
313
-
314
- function closeAllKCWindows() {
315
- communicationPacket.action = 'closeAllKCWindows';
316
- communicationPacket.value = null;
317
- communication(communicationPacket, listeningWindows.ALL);
318
- }
319
-
320
- function addCodes(codesData) {
321
- communicationPacket.action = 'addCodes';
322
- communicationPacket.value = codesData;
323
- communication(communicationPacket, listeningWindows.KC);
324
- if (service.kcWindow.opened === true) {
325
- service.kcWindow.reference.focus();
326
- }
327
- }
328
-
329
- function clearPatientRecord() {
330
- communicationPacket.action = 'clearPatientRecord';
331
- communicationPacket.value = null;
332
- communication(communicationPacket, listeningWindows.KC);
333
- if (service.kcWindow.opened === true) {
334
- service.kcWindow.reference.focus();
335
- }
336
- }
337
-
338
- function closeAllKCWindowsExceptEncoder() {
339
- communicationPacket.action = 'closeAllKCWindowsExceptEncoder';
340
- communicationPacket.value = null;
341
- communication(communicationPacket, listeningWindows.ALL);
342
- }
343
-
344
- function deleteCodes(codes) {
345
- communicationPacket.action = 'deleteCodes';
346
- communicationPacket.value = codes;
347
- communication(communicationPacket, listeningWindows.KC);
348
- if (service.kcWindow.opened === true) {
349
- service.kcWindow.reference.focus();
350
- }
351
- }
352
-
353
- function getPayerList(payerList) {
354
- communicationPacket.action = 'getPayerList';
355
- communicationPacket.value = payerList;
356
- communication(communicationPacket, listeningWindows.KC);
357
- }
358
-
359
- function getRowSpecificInfo(uniqueIds) {
360
- communicationPacket.action = 'getRowSpecificInfo';
361
- communicationPacket.value = uniqueIds;
362
- communication(communicationPacket, listeningWindows.KC);
363
- }
364
-
365
- function clearSelectedRow() {
366
- communicationPacket.action = 'clearSelectedRow';
367
- communicationPacket.value = null;
368
- communication(communicationPacket, listeningWindows.KC);
369
- if (service.kcWindow.opened === true) {
370
- service.kcWindow.reference.focus();
371
- }
372
- }
373
- function hasCriticalEdits() {
374
- communicationPacket.action = 'hasCriticalEdits';
375
- communicationPacket.value = null;
376
- communication(communicationPacket, listeningWindows.KC);
377
- }
378
- function hasEdits() {
379
- communicationPacket.action = 'hasEdits';
380
- communicationPacket.value = null;
381
- communication(communicationPacket, listeningWindows.KC);
382
- }
383
- function launchCodeSummaryReport() {
384
- communicationPacket.action = 'launchCodeSummaryReport';
385
- communicationPacket.value = null;
386
- communication(communicationPacket, listeningWindows.KC);
387
- }
388
- function launchEdits() {
389
- communicationPacket.action = 'launchEdits';
390
- communicationPacket.value = null;
391
- communication(communicationPacket, listeningWindows.KC);
392
- }
393
- function launchFacilityLookup(codes) {
394
- communicationPacket.action = 'launchFacilityLookup'
395
- communicationPacket.value = codes;
396
- communication(communicationPacket, listeningWindows.KC)
397
- }
398
- function launchIndex(codes) {
399
- communicationPacket.action = 'launchIndex';
400
- communicationPacket.value = codes;
401
- communication(communicationPacket, service.encoderWindowIsListening ? listeningWindows.ENCODER : listeningWindows.KC);
402
- if (service.encoderWindow.opened) {
403
- service.encoderWindow.reference.focus();
404
- }
405
-
406
- }
407
- function launchLogic(codes) {
408
- communicationPacket.action = 'launchLogic';
409
- communicationPacket.value = codes;
410
- communication(communicationPacket, service.encoderWindowIsListening ? listeningWindows.ENCODER : listeningWindows.KC);
411
- if (service.encoderWindow.opened == true) {
412
- service.encoderWindow.reference.focus();
413
- }
414
-
415
- }
416
- function launchTabular(codes) {
417
- communicationPacket.action = 'launchTabular';
418
- communicationPacket.value = codes;
419
- communication(communicationPacket, service.encoderWindowIsListening ? listeningWindows.ENCODER : listeningWindows.KC);
420
- if (service.encoderWindow.opened == true) {
421
- service.encoderWindow.reference.focus();
422
- }
423
- }
424
- function logout() {
425
- communicationPacket.action = 'logout';
426
- communicationPacket.value = null;
427
- communication(communicationPacket, listeningWindows.KC);
428
- if (service.kcWindow.opened === true) {
429
- service.kcWindow.reference.focus();
430
- }
431
- }
432
- function resetApplication() {
433
- communicationPacket.action = 'resetApplication';
434
- communicationPacket.value = null;
435
- communication(communicationPacket, listeningWindows.KC);
436
- if (service.kcWindow.opened === true) {
437
- service.kcWindow.reference.focus();
438
- }
439
- }
440
- function savePatientRecord() {
441
- communicationPacket.action = 'savePatientRecord';
442
- communicationPacket.value = null;
443
- communication(communicationPacket, listeningWindows.KC);
444
- if (service.kcWindow.opened === true) {
445
- service.kcWindow.reference.focus();
446
- }
447
- }
448
- function updateCodes(codes) {
449
- communicationPacket.action = 'updateCodes';
450
- communicationPacket.value = codes;
451
- communication(communicationPacket, listeningWindows.KC);
452
- if (service.kcWindow.opened === true) {
453
- service.kcWindow.reference.focus();
454
- }
455
- }
456
- function updateDemographics(updatedDemographics) {
457
- communicationPacket.action = 'updateDemographics';
458
- communicationPacket.value = updatedDemographics;
459
- communication(communicationPacket, listeningWindows.KC);
460
- if (service.kcWindow.opened === true) {
461
- service.kcWindow.reference.focus();
462
- }
463
- }
464
-
465
- function openEncoderWindow() {
466
- communicationPacket.action = 'openEncoder';
467
- communicationPacket.value = null;
468
- communication(communicationPacket, service.encoderWindowIsListening ? listeningWindows.ENCODER : listeningWindows.KC);
469
- if (service.encoderWindow.opened == true) {
470
- service.encoderWindow.reference.focus();
471
- }
472
- }
473
-
474
- // workflow to launch kc
475
- function launchKc(url, authToken, state, demographics) {
476
- kcWindow.authTokenData = authToken;
477
-
478
- var wfArray = [
479
- {
480
- fn: openKc,
481
- args: [url, authToken]
482
- },
483
- {
484
- fn: setI9I10State,
485
- args: state
486
- },
487
- {
488
- fn: setDemographics,
489
- args: demographics
490
- }
491
- ];
492
-
493
- var updatedWf = wfArray.concat(service.workflow);
494
- service.clearWorkflow();
495
-
496
- service.addToWorkflow(updatedWf);
497
-
498
- service.processWorkflow(service.kcWindow);
499
- }
500
-
501
- // workflow to launch encoder
502
- function launchEncoder(url, authToken, state, demographics, request) {
503
- encoderWindow.authTokenData = authToken;
504
-
505
- var logicIndexRequest = JSON.stringify(
506
- {
507
- sessionType: request.sessionType,
508
- phrase: request.codePhrase
509
- },
510
- null,
511
- 2
512
- );
648
+ return service.workflow;
649
+ }
513
650
 
514
- var tabularRequest = JSON.stringify(
515
- {
516
- sessionType: request.sessionType,
517
- code: request.codePhrase
518
- },
519
- null,
520
- 2
521
- );
651
+ function removeFromWorkflow(index) {
652
+ service.workflow.splice(index, 1);
653
+ }
522
654
 
523
- var wfArray = [
524
- {
525
- fn: openEncoder,
526
- args: [url, authToken]
527
- },
528
- {
529
- fn: setI9I10State,
530
- args: state
531
- },
532
- {
533
- fn: setDemographics,
534
- args: demographics
535
- },
536
- {
537
- fn: encoderStartupComplete,
538
- args: []
539
- }
540
- ];
541
-
542
- if (request.encoderTab === service.encoderTabs.LOGIC) {
543
- wfArray.push({
544
- fn: loadPhraseInLogic,
545
- args: logicIndexRequest
546
- });
547
- } else if (request.encoderTab === service.encoderTabs.INDEX) {
548
- wfArray.push({
549
- fn: loadPhraseInIndex,
550
- args: logicIndexRequest
551
- });
552
- } else if (request.encoderTab === service.encoderTabs.TABULAR) {
553
- wfArray.push({
554
- fn: loadCodeInTabular,
555
- args: tabularRequest
556
- });
557
- }
558
-
559
- var updatedWf = wfArray.concat(service.workflow);
560
- service.clearWorkflow();
561
-
562
- service.addToWorkflow(updatedWf);
563
-
564
- service.processWorkflow(service.encoderWindow);
565
- }
566
-
567
- // window functions
568
- function communication(packet, listener) {
569
- try {
570
- var ourWindows = getWindowsToCommunicate(listener);
571
-
572
- if (ourWindows.length === 0) {
573
- console.log(new Error('No window listening'));
574
- return;
575
- }
576
-
577
- if (packet.value) {
578
- packet.value = typeof packet.value === 'string' ? JSON.parse(packet.value) : packet.value;
579
- }
580
- ourWindows.forEach(function (w) {
581
- w.responseTime = 0;
582
- packet.windowName = w.name;
583
- messagingProvider.post(w.reference, packet);
584
- responseTimeout(packet, w);
585
- });
586
- } catch (e) {
587
- console.log(e);
588
- stopWorkflow();
589
- invokeCallback(service.callbacks.SDKEXCEPTION, { callback: packet.action, value: e });
590
- }
591
- }
592
-
593
- function getWindowsToCommunicate(listener) {
594
- var windowArray = [];
595
-
596
- switch (listener) {
597
- case listeningWindows.ENCODER:
598
- if (service.encoderWindowIsListening) {
599
- windowArray.push(service.encoderWindow);
655
+ function processWorkflow(windowToSend) {
656
+ service.workflowComplete = false;
657
+ if (service.workflow.length === 0) {
658
+ stopWorkflow();
659
+ return;
600
660
  }
601
- break;
602
661
 
603
- case listeningWindows.KC:
604
- if (service.kcWindowIsListening) {
605
- windowArray.push(service.kcWindow);
662
+ var cwf = service.workflow.shift() || {};
663
+
664
+ if (typeof windowToSend === 'string') {
665
+ if (windowToSend === service.kcWindow.name) {
666
+ windowToSend = service.kcWindow;
667
+ } else if (windowToSend === service.encoderWindow.name) {
668
+ windowToSend = service.encoderWindow;
669
+ } else {
670
+ stopWorkflow();
671
+ return;
672
+ }
606
673
  }
607
- break;
608
674
 
609
- case listeningWindows.ALL:
610
- if (service.kcWindowIsListening) {
611
- windowArray.push(service.kcWindow);
675
+ windowToSend.currentWorkflow = cwf;
676
+ cwf.workflowCompleteMessage = listenerResponse[cwf.name.toUpperCase()];
677
+
678
+ if (!windowToSend.currentWorkflow.fn) {
679
+ stopWorkflow();
680
+ return;
612
681
  }
613
- if (service.encoderWindowIsListening) {
614
- windowArray.push(service.encoderWindow);
682
+ var args = Array.isArray(windowToSend.currentWorkflow.args) ? windowToSend.currentWorkflow.args : [windowToSend.currentWorkflow.args];
683
+
684
+ if (args.length > 0) {
685
+ windowToSend.currentWorkflow.fn.apply(this, args);
686
+ } else {
687
+ windowToSend.currentWorkflow.fn.apply();
615
688
  }
689
+ }
616
690
 
617
- break;
691
+ function clearWorkflow() {
692
+ service.workflow.length = 0;
693
+ service.currentWorkflow = {};
694
+ }
618
695
 
619
- default:
620
- return [];
696
+ function stopWorkflow() {
697
+ service.workflowComplete = true;
698
+ clearTimeout(service.kcWindow.responseTime);
699
+ clearTimeout(service.encoderWindow.responseTime);
700
+ invokeCallback('workflowComplete');
621
701
  }
622
702
 
623
- return windowArray.filter(function (w) {
624
- return w !== null && windowExists(w);
625
- });
626
- }
627
-
628
- function windowExists(window) {
629
- if (!window.opened) {
630
- if (!window.name) {
631
- closeKcWindow();
632
- closeEncoderWindow();
633
- }
634
- if (window.name === service.kcWindow.name) {
635
- closeKcWindow();
636
- } else if (window.name === service.encoderWindow.name) {
637
- closeEncoderWindow();
638
- }
639
- return false;
640
- }
641
-
642
- return true;
643
- }
644
-
645
- function closeKcWindow() {
646
- service.kcWindow.opened = false;
647
- service.kcWindowIsListening = false;
648
- }
649
-
650
- function closeEncoderWindow() {
651
- service.encoderWindow.opened = false;
652
- service.encoderWindowIsListening = false;
653
- }
654
-
655
- // workflow functions
656
- function addToWorkflow(wf) {
657
- var wfArray = Array.isArray(wf) ? wf : [wf];
658
- var kcWindowFunctions = ['openKc', 'launchKc', 'openKcSentinel', 'loadPatientRecord', 'assignConfig', 'addCodes', 'clearPatientRecord', 'deleteCodes', 'getPayerList', 'getRowSpecificInfo', 'clearSelectedRow', 'hasCriticalEdits', 'hasEdits', 'launchCodeSummaryReport',
659
- 'launchEdits', 'launchFacilityLookup', 'logout', 'resetApplication', 'savePatientRecord', 'updateCodes', 'updateDemographics'];
660
- var encoderWindowFunctions = ['loadPhraseInLogic', 'loadPhraseInIndex', 'loadCodeInTabular'];
661
- var allWindowFunctions = ['setI9I10State', 'setAuthToken', 'setDemographics', 'closeAllKCWindows', 'closeAllKCWindowsExceptEncoder', 'launchIndex', 'launchLogic', 'launchTabular', 'openEncoder'];
662
-
663
- wfArray.forEach(function (w) {
664
- w.sendToWindow = [];
665
- if (kcWindowFunctions.indexOf(w.name) > -1) {
666
- w.sendToWindow.push('kcWindow');
667
- }
668
- if (encoderWindowFunctions.indexOf(w.name) > -1) {
669
- w.sendToWindow.push('encoderWindow');
670
- }
671
- if (allWindowFunctions.indexOf(w.name) > -1) {
672
- w.sendToWindow.push('kcWindow');
673
- w.sendToWindow.push('encoderWindow');
674
- }
675
- w.name = w.fn.name || w.fn.toString().match(/^function\s?([^\s(]*)/)[1];
676
- service.workflow.push(w);
677
- });
678
- return service.workflow;
679
- }
680
-
681
- function removeFromWorkflow(index) {
682
- service.workflow.splice(index, 1);
683
- }
684
-
685
- function processWorkflow(windowToSend) {
686
- service.workflowComplete = false;
687
- if (service.workflow.length === 0) {
688
- stopWorkflow();
689
- return;
690
- }
691
-
692
- var cwf = service.workflow.shift() || {};
693
-
694
- if (typeof windowToSend === 'string') {
695
- if (windowToSend === service.kcWindow.name) {
696
- windowToSend = service.kcWindow;
697
- } else if (windowToSend === service.encoderWindow.name) {
698
- windowToSend = service.encoderWindow;
699
- }
700
- //else if (windowToSend === service.kcWindow.kcSentinelName) {
701
- // windowToSend = service.kcWindow;
702
- // service.kcWindow.name = service.kcWindow.kcSentinelName;
703
- //}
704
- else {
703
+ // handles timeout of calls
704
+ function responseTimeout(packet, window) {
705
+ window.responseTime = setTimeout(function () {
706
+ responseFailed(packet, window);
707
+ }, timeoutThresholdSeconds * 1000);
708
+ }
709
+
710
+ function responseFailed(packet, window) {
711
+ invokeCallback(service.callbacks.SDKEXCEPTION, { callback: packet.action, value: 'Timed out.' });
705
712
  stopWorkflow();
706
- return;
707
- }
708
- }
709
-
710
- windowToSend.currentWorkflow = cwf;
711
- cwf.workflowCompleteMessage = listenerResponse[cwf.name.toUpperCase()];
712
-
713
- if (!windowToSend.currentWorkflow.fn) {
714
- stopWorkflow();
715
- return;
716
- }
717
- var args = Array.isArray(windowToSend.currentWorkflow.args) ? windowToSend.currentWorkflow.args : [windowToSend.currentWorkflow.args];
718
-
719
- if (args.length > 0) {
720
- windowToSend.currentWorkflow.fn.apply(this, args);
721
- } else {
722
- windowToSend.currentWorkflow.fn.apply();
723
- }
724
- }
725
-
726
- function clearWorkflow() {
727
- service.workflow.length = 0;
728
- service.currentWorkflow = {};
729
- }
730
-
731
- function stopWorkflow() {
732
- service.workflowComplete = true;
733
- clearTimeout(service.kcWindow.responseTime);
734
- clearTimeout(service.encoderWindow.responseTime);
735
- invokeCallback('workflowComplete');
736
- }
737
-
738
- // handles timeout of calls
739
- function responseTimeout(packet, window) {
740
- window.responseTime = setTimeout(function () {
741
- responseFailed(packet, window);
742
- }, timeoutThresholdSeconds * 1000);
743
- }
744
-
745
- function responseFailed(packet, window) {
746
- invokeCallback(service.callbacks.SDKEXCEPTION, { callback: packet.action, value: 'Timed out.' });
747
- stopWorkflow();
748
- }
749
-
750
- function setCallback(name, func) {
751
- callbackFns[name] = func;
752
- }
753
-
754
- function invokeCallback(callbackName, args) {
755
- var callbackFn = callbackFns[callbackName];
756
- var args = Array.isArray(args) ? args : [args];
757
- if (typeof callbackFn === 'function') {
758
- try {
759
- callbackFn.apply(this, args);
760
- } catch (e) {
761
- console.log(e);
762
- }
763
- }
764
- }
713
+ }
714
+
715
+ function setCallback(name, func) {
716
+ callbackFns[name] = func;
717
+ }
718
+
719
+ function invokeCallback(callbackName, args) {
720
+ var callbackFn = callbackFns[callbackName];
721
+ var args = Array.isArray(args) ? args : [args];
722
+ if (typeof callbackFn === 'function') {
723
+ try {
724
+ callbackFn.apply(this, args);
725
+ } catch (e) {
726
+ console.log(e);
727
+ }
728
+ }
729
+ }
765
730
  };
766
731
 
767
732
  (function (window) {
768
- window.kcSdk = new kcSdk();
733
+ window.kcSdk = new kcSdk();
769
734
  })(window);