kc-sdk 6.4.7971 → 6.8.10817

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