This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
/
index.html
1242 lines (1102 loc) · 101 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>SMART on FHIR Scheduling App Tutorial</title>
<style media="screen">
.highlight table td { padding: 5px; }
.highlight table pre { margin: 0; }
.highlight .gh {
color: #999999;
}
.highlight .sr {
color: #f6aa11;
}
.highlight .go {
color: #888888;
}
.highlight .gp {
color: #555555;
}
.highlight .gs {
}
.highlight .gu {
color: #aaaaaa;
}
.highlight .nb {
color: #f6aa11;
}
.highlight .cm {
color: #75715e;
}
.highlight .cp {
color: #75715e;
}
.highlight .c1 {
color: #75715e;
}
.highlight .cs {
color: #75715e;
}
.highlight .c, .highlight .ch, .highlight .cd, .highlight .cpf {
color: #75715e;
}
.highlight .err {
color: #960050;
}
.highlight .gr {
color: #960050;
}
.highlight .gt {
color: #960050;
}
.highlight .gd {
color: #49483e;
}
.highlight .gi {
color: #49483e;
}
.highlight .ge {
color: #49483e;
}
.highlight .kc {
color: #66d9ef;
}
.highlight .kd {
color: #66d9ef;
}
.highlight .kr {
color: #66d9ef;
}
.highlight .no {
color: #66d9ef;
}
.highlight .kt {
color: #66d9ef;
}
.highlight .mf {
color: #ae81ff;
}
.highlight .mh {
color: #ae81ff;
}
.highlight .il {
color: #ae81ff;
}
.highlight .mi {
color: #ae81ff;
}
.highlight .mo {
color: #ae81ff;
}
.highlight .m, .highlight .mb, .highlight .mx {
color: #ae81ff;
}
.highlight .sc {
color: #ae81ff;
}
.highlight .se {
color: #ae81ff;
}
.highlight .ss {
color: #ae81ff;
}
.highlight .sd {
color: #e6db74;
}
.highlight .s2 {
color: #e6db74;
}
.highlight .sb {
color: #e6db74;
}
.highlight .sh {
color: #e6db74;
}
.highlight .si {
color: #e6db74;
}
.highlight .sx {
color: #e6db74;
}
.highlight .s1 {
color: #e6db74;
}
.highlight .s, .highlight .sa, .highlight .dl {
color: #e6db74;
}
.highlight .na {
color: #a6e22e;
}
.highlight .nc {
color: #a6e22e;
}
.highlight .nd {
color: #a6e22e;
}
.highlight .ne {
color: #a6e22e;
}
.highlight .nf, .highlight .fm {
color: #a6e22e;
}
.highlight .vc {
color: #ffffff;
}
.highlight .nn {
color: #ffffff;
}
.highlight .ni {
color: #ffffff;
}
.highlight .bp {
color: #ffffff;
}
.highlight .vg {
color: #ffffff;
}
.highlight .vi {
color: #ffffff;
}
.highlight .nv, .highlight .vm {
color: #ffffff;
}
.highlight .w {
color: #ffffff;
}
.highlight {
color: #ffffff;
}
.highlight .n, .highlight .py, .highlight .nx {
color: #ffffff;
}
.highlight .nl {
color: #f92672;
}
.highlight .ow {
color: #f92672;
}
.highlight .nt {
color: #f92672;
}
.highlight .k, .highlight .kv {
color: #f92672;
}
.highlight .kn {
color: #f92672;
}
.highlight .kp {
color: #f92672;
}
.highlight .o {
color: #f92672;
}
</style>
<style media="print">
* {
-webkit-transition:none!important;
transition:none!important;
}
.highlight table td { padding: 5px; }
.highlight table pre { margin: 0; }
.highlight, .highlight .w {
color: #586e75;
}
.highlight .err {
color: #002b36;
background-color: #dc322f;
}
.highlight .c, .highlight .ch, .highlight .cd, .highlight .cm, .highlight .cpf, .highlight .c1, .highlight .cs {
color: #657b83;
}
.highlight .cp {
color: #b58900;
}
.highlight .nt {
color: #b58900;
}
.highlight .o, .highlight .ow {
color: #93a1a1;
}
.highlight .p, .highlight .pi {
color: #93a1a1;
}
.highlight .gi {
color: #859900;
}
.highlight .gd {
color: #dc322f;
}
.highlight .gh {
color: #268bd2;
background-color: #002b36;
font-weight: bold;
}
.highlight .k, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kv {
color: #6c71c4;
}
.highlight .kc {
color: #cb4b16;
}
.highlight .kt {
color: #cb4b16;
}
.highlight .kd {
color: #cb4b16;
}
.highlight .s, .highlight .sa, .highlight .sb, .highlight .sc, .highlight .dl, .highlight .sd, .highlight .s2, .highlight .sh, .highlight .sx, .highlight .s1 {
color: #859900;
}
.highlight .sr {
color: #2aa198;
}
.highlight .si {
color: #d33682;
}
.highlight .se {
color: #d33682;
}
.highlight .nn {
color: #b58900;
}
.highlight .nc {
color: #b58900;
}
.highlight .no {
color: #b58900;
}
.highlight .na {
color: #268bd2;
}
.highlight .m, .highlight .mb, .highlight .mf, .highlight .mh, .highlight .mi, .highlight .il, .highlight .mo, .highlight .mx {
color: #859900;
}
.highlight .ss {
color: #859900;
}
</style>
<link href="stylesheets/screen.css" rel="stylesheet" media="screen" />
<link href="stylesheets/print.css" rel="stylesheet" media="print" />
<script src="javascripts/all.js"></script>
</head>
<body class="index" data-languages="["code"]">
<a href="#" id="nav-button">
<span>
NAV
<img src="images/navbar.png" alt="" />
</span>
</a>
<div class="toc-wrapper">
<img src="images/logo.png" class="logo" alt="" />
<div class="lang-selector">
<a href="#" data-language-name="code">code</a>
</div>
<div class="search">
<input type="text" class="search" id="input-search" placeholder="Search">
</div>
<ul class="search-results"></ul>
<ul id="toc" class="toc-list-h1">
<li>
<a href="#introduction" class="toc-h1 toc-link" data-title="Introduction">Introduction</a>
</li>
<li>
<a href="#prerequisites" class="toc-h1 toc-link" data-title="Prerequisites">Prerequisites</a>
</li>
<li>
<a href="#project-setup" class="toc-h1 toc-link" data-title="Project Setup">Project Setup</a>
</li>
<li>
<a href="#1-trigger-a-github-pages-deployment" class="toc-h1 toc-link" data-title="1.) Trigger a GitHub Pages Deployment">1.) Trigger a GitHub Pages Deployment</a>
</li>
<li>
<a href="#2-register-your-app-with-cerner" class="toc-h1 toc-link" data-title="2.) Register Your App with Cerner">2.) Register Your App with Cerner</a>
</li>
<li>
<a href="#3-request-authorization" class="toc-h1 toc-link" data-title="3.) Request Authorization">3.) Request Authorization</a>
</li>
<li>
<a href="#4-how-the-app-works" class="toc-h1 toc-link" data-title="4.) How the App Works">4.) How the App Works</a>
<ul class="toc-list-h2">
<li>
<a href="#requesting-access-to-fhir-resources" class="toc-h2 toc-link" data-title="Requesting Access to FHIR Resources">Requesting Access to FHIR Resources</a>
</li>
<li>
<a href="#accessing-fhir-resources" class="toc-h2 toc-link" data-title="Accessing FHIR Resources">Accessing FHIR Resources</a>
</li>
<li>
<a href="#displaying-fhir-resources" class="toc-h2 toc-link" data-title="Displaying FHIR Resources">Displaying FHIR Resources</a>
</li>
</ul>
</li>
<li>
<a href="#5-test-your-app" class="toc-h1 toc-link" data-title="5.) Test your App">5.) Test your App</a>
</li>
<li>
<a href="#6-add-appointment-booking" class="toc-h1 toc-link" data-title="6.) Add Appointment Booking">6.) Add Appointment Booking</a>
</li>
<li>
<a href="#7-add-patient-search-and-create" class="toc-h1 toc-link" data-title="7.) Add Patient Search and Create">7.) Add Patient Search and Create</a>
</li>
<li>
<a href="#summary" class="toc-h1 toc-link" data-title="Summary">Summary</a>
</li>
</ul>
</div>
<div class="page-wrapper">
<div class="dark-box"></div>
<div class="content">
<h1 id='introduction'>Introduction</h1>
<p>This tutorial will walk you through creating an app in Cerner's SMART on FHIR ecosystem. In particular, your app will focus on FHIR scheduling workflows.</p>
<p>After completing this tutorial you will know how to:</p>
<ul>
<li>Create a basic SMART on FHIR app that interacts with scheduling resources.</li>
<li>Self register an app with Cerner.</li>
<li>Run an app in Cerner's SMART on FHIR sandbox.</li>
</ul>
<h1 id='prerequisites'>Prerequisites</h1>
<ul>
<li>A public <a href="http://www.github.com">GitHub</a> account</li>
</ul>
<h1 id='project-setup'>Project Setup</h1>
<p>First, you'll want to fork this tutorial from <a href="https://github.com/cerner/smart-on-fhir-scheduling-tutorial">smart-on-fhir-scheduling-tutorial</a> to your GitHub account.</p>
<p>The <code>smart-on-fhir-scheduling-tutorial/source/scheduling-app</code> folder contains the example SMART app which you'll be using throughout this tutorial. Let's take a look at some of the notable files contained within:</p>
<p><strong>fhir-client-v0.1.12.js</strong></p>
<p>Located in the lib/js folder, this is a version of <a href="https://github.com/smart-on-fhir/client-js"><code>fhir-client.js</code></a> which is an open source library designed to assist with calling a FHIR API and handling the SMART on FHIR authorization workflow. This tutorial uses this library when walking you through building your first SMART app.</p>
<p>Additional documentation on <code>fhir-client.js</code> can be found <a href="http://docs.smarthealthit.org/clients/javascript/">here</a>.</p>
<aside class="notice">
This tutorial is designed to have a minimal footprint so we made the decision to directly include `fhir-client.js` for simplicity. For your production applications we'd recommend pulling in `fhir-client.js` using npm or some other package manager to easily keep your application up to date.
</aside>
<p><strong>launch.html</strong></p>
<p>launch.html is the SMART app's initial entry point and in a real production environment, would be invoked by the application launching your SMART app (for instance, the EHR or patient portal). In the <a href="http://docs.smarthealthit.org/">SMART documentation</a>, this is your app's "launch URL". In this tutorial, this page will be invoked when you launch your app from Cerner's <a href="https://code.cerner.com/developer/smart-on-fhir/apps">code console</a>.</p>
<p>As the entry point into your SMART app, this page will kick-off the SMART authorization workflow.</p>
<p><strong>index.html</strong></p>
<p>This page will be invoked via redirect from the Authorization server at the conclusion of the SMART authorization workflow. When this page is invoked, your SMART app will have everything it needs to run and access the FHIR API.</p>
<p>The other content you see in the source folder is the site for this tutorial. We used <a href="https://github.com/lord/slate">Slate</a> to create the documentation for this tutorial.</p>
<h1 id='1-trigger-a-github-pages-deployment'>1.) Trigger a GitHub Pages Deployment</h1>
<blockquote>
<p>/scheduling-app/index.html</p>
</blockquote>
<div class="highlight"><pre class="highlight html tab-html"><code><span class="cp"><!DOCTYPE html></span>
<span class="nt"><html</span> <span class="na">lang=</span><span class="s">'en'</span> <span class="na">hidden</span><span class="nt">></span>
<span class="nt"><head></span>
...
<span class="nt"></head></span>
<span class="nt"><body></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'container'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
-> <span class="nt"><h1></span>[GITHUB USERNAME] Scheduling App<span class="nt"></h1></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
...
</code></pre></div>
<blockquote>
<p>Go to your GitHub account, select the Repositories tab and select the smart-on-fhir-scheduling-tutorial repository. Select the Branch button and switch to the gh-pages branch. Directly edit <code>/scheduling-app/index.html</code> by clicking on the pencil icon. Once you've made the change, commit directly to the gh-pages branch.</p>
</blockquote>
<p>For the purposes of this tutorial we will be hosting our SMART app through <a href="https://help.github.com/articles/what-is-github-pages">GitHub Pages</a>. GitHub Pages is a convenient way to host static or client rendered web sites.</p>
<p>Setting up GitHub pages is easy, so easy in fact that it's already done for you. GitHub pages works by hosting content from a repository branch named "gh-pages". Since you forked the tutorial, the gh-pages branch has already been created, however, GitHub won't publish your site until you make a change to that branch, so let's make a change. Modify the index.html page to include your GitHub username in the app's title, and commit directly to the gh-pages branch.</p>
<p>Use the GitHub UI to directly edit <code>index.html</code>. Simply switch the branch to gh-pages, navigate to <code>/scheduling-app/index.html</code> and click the pencil icon. Commit your changes to deploy.</p>
<p>Once the app has been deployed go to <code>https://<github username>.github.io/smart-on-fhir-scheduling-tutorial/scheduling-app/health</code> to ensure your app is available.</p>
<aside class="notice">
GitHub Pages sites have a limit of 10 builds per hour, so if your page isn't updating, this could be the reason.
</aside>
<h1 id='2-register-your-app-with-cerner'>2.) Register Your App with Cerner</h1>
<p>Now that we have deployed a SMART app, let's register it to access Cerner's FHIR resources. Cerner has created a self-registration console to allow developers to run SMART apps in a sandbox environment. Navigate to Cerner's <a href="https://code.cerner.com/developer/smart-on-fhir/apps">code console</a>. If you don't have a Cerner Care Account, go ahead and sign up for one (it's free!). Once logged into the console, click on the "+ New App" button in the top right toolbar and fill in the following details:</p>
<table><thead>
<tr>
<th>Field</th>
<th>Value</th>
<th>Description</th>
</tr>
</thead><tbody>
<tr>
<td>App Name</td>
<td>Cool App</td>
<td>Any name your heart desires.</td>
</tr>
<tr>
<td>SMART Launch URI</td>
<td><code>https://<github username>.github.io/smart-on-fhir-scheduling-tutorial/scheduling-app/launch.html</code></td>
<td>The page that launches your app.</td>
</tr>
<tr>
<td>Redirect URI</td>
<td><code>https://<github username>.github.io/smart-on-fhir-scheduling-tutorial/scheduling-app/</code></td>
<td>The main logic for your app.</td>
</tr>
<tr>
<td>App Type</td>
<td>Provider</td>
<td>You are creating a provider-facing facing app.</td>
</tr>
<tr>
<td>FHIR Spec</td>
<td>dstu2</td>
<td>Your app will run against Cerner's implementation of the DSTU 2 FHIR specification.</td>
</tr>
<tr>
<td>Authorized</td>
<td>Yes</td>
<td>Authorized apps will go through secured OAuth 2 login.</td>
</tr>
<tr>
<td>Standard Scopes</td>
<td>online_access</td>
<td>The already-checked standard scopes are required to launch your SMART app. Offline access is for system-facing apps, so we need online access.</td>
</tr>
<tr>
<td>User Scopes</td>
<td>Appointment write, Patient read, Patient write, and Slot read</td>
<td>Your app needs to be able to write appointments, read and write patients, and read slots.</td>
</tr>
<tr>
<td>Patient Scopes</td>
<td>None</td>
<td>Your app does not need any patient scopes.</td>
</tr>
</tbody></table>
<p>Click "Register" to complete the process. This will add the app to your account and create a client id for app authorization.</p>
<p>The new OAuth 2 client id for your app will be displayed in a banner at the top of the page and can be viewed at any time by clicking on the application icon to view more details.</p>
<aside class="notice">
After initially registering your SMART app, it can take up to 10 minutes for your app details to propogate throughout our sandbox. So, please wait 10 minutes before trying to launch your app - you can continue working through this tutorial in the mean time.
</aside>
<h1 id='3-request-authorization'>3.) Request Authorization</h1>
<blockquote>
<p>/scheduling-app/launch.html</p>
</blockquote>
<div class="highlight"><pre class="highlight html tab-html"><code><span class="cp"><!DOCTYPE html></span>
<span class="nt"><html</span> <span class="na">lang=</span><span class="s">'en'</span> <span class="na">hidden</span><span class="nt">></span>
<span class="nt"><head></span>
...
<span class="nt"></head></span>
<span class="nt"><body></span>
...
<span class="nt"><script></span>
<span class="nx">FHIR</span><span class="p">.</span><span class="nx">oauth2</span><span class="p">.</span><span class="nx">authorize</span><span class="p">({</span>
<span class="o">-></span> <span class="dl">'</span><span class="s1">client_id</span><span class="dl">'</span><span class="p">:</span> <span class="dl">'</span><span class="s1">[CLIENT ID]</span><span class="dl">'</span><span class="p">,</span>
<span class="dl">'</span><span class="s1">scope</span><span class="dl">'</span><span class="p">:</span> <span class="dl">'</span><span class="s1">user/Appointment.write user/Patient.read user/Patient.write user/Slot.read launch online_access openid profile</span><span class="dl">'</span>
<span class="p">});</span>
<span class="nt"></script></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'spinner'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'bounce1'</span><span class="nt">></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'bounce2'</span><span class="nt">></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'bounce3'</span><span class="nt">></div></span>
<span class="nt"></div></span>
<span class="nt"></body></span>
<span class="nt"></html></span>
</code></pre></div>
<blockquote>
<p>Make sure to use the client id generated by the code console for your <code>FHIR.oauth2.authorize</code> call and redeploy your site.</p>
</blockquote>
<p>The responsibility of <code>launch.html</code> is to redirect to the appropriate FHIR authorization server. As you can see in the code, <code>fhir-client.js</code> makes our job pretty easy. All we have to do is call <code>FHIR.oauth2.authorize</code> supplying the client id generated by Cerner's code console during registration and the scopes we registered.</p>
<p>Your app's client id is found on the app details page that can be accessed by clicking on the application icon in the <a href="https://code.cerner.com/developer/smart-on-fhir/apps">code console</a>. Copy the client id into the authorize call in <code>launch.html</code>, commit the changes back to your repo and redeploy your site.</p>
<p>For the purposes of this tutorial you don't need to modify the OAuth 2 scopes. This list should match the scopes that you registered the application with.</p>
<p>Please refer to Cerner's <a href="https://engineering.cerner.com/smart-on-fhir-tutorial/#request-authorization">base SMART on FHIR tutorial</a> for more information on request authorization.</p>
<h1 id='4-how-the-app-works'>4.) How the App Works</h1><h2 id='requesting-access-to-fhir-resources'>Requesting Access to FHIR Resources</h2>
<blockquote>
<p>/scheduling-app/src/js/scheduling-app.js</p>
</blockquote>
<div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="p">...</span>
<span class="nx">FHIR</span><span class="p">.</span><span class="nx">oauth2</span><span class="p">.</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">smart</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// Query the FHIR server for Slots</span>
<span class="nx">smart</span><span class="p">.</span><span class="nx">api</span><span class="p">.</span><span class="nx">fetchAll</span><span class="p">({</span><span class="na">type</span><span class="p">:</span> <span class="dl">'</span><span class="s1">Slot</span><span class="dl">'</span><span class="p">,</span> <span class="na">query</span><span class="p">:</span> <span class="nx">slotParams</span><span class="p">}).</span><span class="nx">then</span><span class="p">(</span>
<span class="c1">// Display Appointment information if the call succeeded</span>
<span class="kd">function</span><span class="p">(</span><span class="nx">slots</span><span class="p">)</span> <span class="p">{</span>
<span class="p">...</span>
<span class="p">},</span>
<span class="c1">// Display 'Failed to read Slots from FHIR server' if the call failed</span>
<span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="p">...</span>
<span class="p">}</span>
<span class="p">);</span>
<span class="p">});</span>
<span class="p">...</span>
</code></pre></div>
<blockquote>
<p>No code changes are required for this step.</p>
</blockquote>
<p>Now that the app has successfully been authenticated, it's time to call a FHIR resource, but first we need to obtain an OAuth2 access token. We have an authorization code that was passed as a query param to the redirect URI (<code>index.html</code>) by the authorization server. The authorization code is exchanged for an access token through POST to the authorization server. Again, <code>fhir-client.js</code> makes this easy for us.</p>
<p>The <code>scheduling-app.js</code> file registers a form on submit event which uses the <code>FHIR.oauth2.ready()</code> function to exchange the authorization code for the access token and stores it in session storage for later use.</p>
<h2 id='accessing-fhir-resources'>Accessing FHIR Resources</h2>
<blockquote>
<p>/scheduling-app/src/js/scheduling-app.js - onReady</p>
</blockquote>
<div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="p">...</span>
<span class="nx">FHIR</span><span class="p">.</span><span class="nx">oauth2</span><span class="p">.</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">smart</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// Query the FHIR server for Slots</span>
<span class="nx">smart</span><span class="p">.</span><span class="nx">api</span><span class="p">.</span><span class="nx">fetchAll</span><span class="p">({</span><span class="na">type</span><span class="p">:</span> <span class="dl">'</span><span class="s1">Slot</span><span class="dl">'</span><span class="p">,</span> <span class="na">query</span><span class="p">:</span> <span class="nx">slotParams</span><span class="p">}).</span><span class="nx">then</span><span class="p">(</span>
<span class="c1">// Display Appointment information if the call succeeded</span>
<span class="kd">function</span><span class="p">(</span><span class="nx">slots</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// If any Slots matched the criteria, display them</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">slots</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">slotsHTML</span> <span class="o">=</span> <span class="dl">''</span><span class="p">;</span>
<span class="nx">slots</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">slot</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">slotsHTML</span> <span class="o">=</span> <span class="nx">slotsHTML</span> <span class="o">+</span> <span class="nx">slotHTML</span><span class="p">(</span><span class="nx">slot</span><span class="p">.</span><span class="nx">id</span><span class="p">,</span> <span class="nx">slot</span><span class="p">.</span><span class="nx">type</span><span class="p">.</span><span class="nx">text</span><span class="p">,</span> <span class="nx">slot</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="nx">slot</span><span class="p">.</span><span class="nx">end</span><span class="p">);</span>
<span class="p">});</span>
<span class="nx">renderSlots</span><span class="p">(</span><span class="nx">slotsHTML</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">// If no Slots matched the criteria, inform the user</span>
<span class="k">else</span> <span class="p">{</span>
<span class="nx">renderSlots</span><span class="p">(</span><span class="dl">'</span><span class="s1"><p>No Slots found for the selected query parameters.</p></span><span class="dl">'</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">},</span>
<span class="c1">// Display 'Failed to read Slots from FHIR server' if the call failed</span>
<span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">clearUI</span><span class="p">();</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#errors</span><span class="dl">'</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="dl">'</span><span class="s1"><p>Failed to read Slots from FHIR server</p></span><span class="dl">'</span><span class="p">);</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#errors-row</span><span class="dl">'</span><span class="p">).</span><span class="nx">show</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">);</span>
<span class="p">});</span>
<span class="p">...</span>
</code></pre></div>
<blockquote>
<p>No code changes are required for this step.</p>
</blockquote>
<p>With access token in hand we're ready to request a FHIR resource and again, we will be using <code>fhir-client.js</code>.</p>
<p>For the purposes of this tutorial we'll be retrieving information that allows the user to book appointments.</p>
<p>The <code>fhir-client.js</code> library defines a useful function we can use to retrieve this information: <code>smart.api.fetchAll()</code>. This uses the <a href="https://github.com/FHIR/fhir.js">fhir.js</a> API to retrieve resources and returns a JavaScript promise. We then set up functions to handle success and failure cases.</p>
<p>On a success, we're taking the response from the FHIR server and building HTML strings to display to our users.</p>
<p>The <code>fhir-client.js</code> library defines several more APIs that will come in handy while developing smart app. Read about them <a href="http://docs.smarthealthit.org/clients/javascript/">here</a>.</p>
<h2 id='displaying-fhir-resources'>Displaying FHIR Resources</h2>
<blockquote>
<p>/scheduling-app/index.html</p>
</blockquote>
<div class="highlight"><pre class="highlight html tab-html"><code>...
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'slots-holder-row'</span> <span class="na">class=</span><span class="s">'row mt-5'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'slots-holder'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><h2></span>Slots<span class="nt"></h2></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><button</span> <span class="na">class=</span><span class="s">'btn btn-danger'</span> <span class="na">id=</span><span class="s">'clear-slots'</span><span class="nt">></span>Clear Results<span class="nt"></button></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'slots'</span><span class="nt">></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
...
</code></pre></div>
<blockquote>
<p>scheduling-app.js - renderSlots</p>
</blockquote>
<div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="p">...</span>
<span class="kd">function</span> <span class="nx">renderSlots</span><span class="p">(</span><span class="nx">slotsHTML</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">clearUI</span><span class="p">();</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#slots</span><span class="dl">'</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="nx">slotsHTML</span><span class="p">);</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#slots-holder-row</span><span class="dl">'</span><span class="p">).</span><span class="nx">show</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">...</span>
</code></pre></div>
<blockquote>
<p>No code changes are required for this step.</p>
</blockquote>
<p>The last remaining task for our application is displaying the resource information we've retrieved. In <code>index.html</code> we define a hidden div element to hold Slot information. On a successful FHIR server call we'll invoke <code>renderSlots</code> which will show the div as well as update its HTML to display Slots.</p>
<h1 id='5-test-your-app'>5.) Test your App</h1>
<blockquote>
<p>Any time you need to redeploy your app via GitHub Pages, commit changes to your gh-pages branch.</p>
</blockquote>
<p>Now that we have a snazzy SMART app, it's time to test it.</p>
<p>Return to the <a href="https://code.cerner.com/developer/smart-on-fhir/apps">code console</a> and click on the app you registered earlier. To launch your app through the code console click the "Begin Testing" button. The console will ask if the app you're launching requires a patient in context - your app does not, so select "No" then "Next". Please note the Millennium username and password displayed in the launch dialog, you'll need those credentials to log in and authorize your app. Finally, click "Launch" and the console will redirect to your application.</p>
<p>Log in with the credentials you received (you'll only need to do this once per browser session) and play with your app!</p>
<aside class="notice">
You will find that this application is preloaded with Practitioners, Locations, and Slot types to search by. In a production scenario, you would need to work with Cerner to gather this information before deploying your app to a client site.
</aside>
<p>In particular, some limitations to be aware of are:</p>
<ul>
<li>Cerner's implementation of the Practitioner resource only allows search by id, so you need to know Practitioners ahead of time to use them in your app.</li>
<li>Slot types can use standard (LOINC, SNOMED, etc.) or proprietary codes. A single standard code may represent multiple proprietary codes, e.g. a standard code for Office Visit may correspond to multiple proprietary codes like Office Visit Doctor A and Office Visit Doctor B.</li>
<li>Cerner's FHIR server does not implement the ValueSet resource, so again, you need to know Slot types ahead of time to use them in your app.</li>
<li>Cerner's FHIR server does not implement the Location resource, so finally, you need to know Locations ahead of time to use them in your app.</li>
</ul>
<p>Cerner will work with you before a go-live to ensure you have all the information for your app to succeed!</p>
<aside class="notice">
You may have noticed a date range search is included in the Slot query. It is strongly recommended to use as small of a date range as you are able to - scheduling data involves a ton of database rows.
</aside>
<p>One Practitioner may have sixteen half-hour slots on a given day. Multiply that number by each Slot type and Location they are available at. Then multiply that by the number of Practitioners a practice may contain. Even for a small office of five Practitioners with only a handful of Slot types, there could be as many as 1,600 Slots for one week. For larger offices, it is entirely possible to see numbers like ten million Slots per month! That will take a long time for your app to request.</p>
<h1 id='6-add-appointment-booking'>6.) Add Appointment Booking</h1>
<blockquote>
<p>/scheduling-app/index.html</p>
</blockquote>
<div class="highlight"><pre class="highlight html tab-html"><code>...
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'appointment-holder-row'</span> <span class="na">class=</span><span class="s">'row mt-5'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'appointment-holder'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><h2></span>Appointment<span class="nt"></h2></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><button</span> <span class="na">class=</span><span class="s">'btn btn-danger'</span> <span class="na">id=</span><span class="s">'clear-appointment'</span><span class="nt">></span>Clear Results<span class="nt"></button></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'appointment'</span><span class="nt">></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
...
</code></pre></div>
<blockquote>
<p>Add this HTML to <code>index.html</code> immediately after the slots-holder-row div. Should be on line 118 if you haven't tweaked the file much.</p>
<p>/scheduling-app/src/js/scheduling-app.js - slotHTML</p>
</blockquote>
<div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="p">...</span>
<span class="kd">function</span> <span class="nx">slotHTML</span><span class="p">(</span><span class="nx">id</span><span class="p">,</span> <span class="nx">type</span><span class="p">,</span> <span class="nx">start</span><span class="p">,</span> <span class="nx">end</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">'</span><span class="s1">Slot: id:[</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">id</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">] type:[</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">type</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">] start:[</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">start</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">] end:[</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">end</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">]</span><span class="dl">'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">slotReference</span> <span class="o">=</span> <span class="dl">'</span><span class="s1">Slot/</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">id</span><span class="p">,</span>
<span class="nx">prettyStart</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nx">start</span><span class="p">),</span>
<span class="nx">prettyEnd</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nx">end</span><span class="p">);</span>
<span class="k">return</span> <span class="dl">"</span><span class="s2"><div class='card'></span><span class="dl">"</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><div class='card-body'></span><span class="dl">"</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><h5 class='card-title'></span><span class="dl">"</span> <span class="o">+</span> <span class="nx">type</span> <span class="o">+</span> <span class="dl">'</span><span class="s1"></h5></span><span class="dl">'</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><p class='card-text'>Start: </span><span class="dl">"</span> <span class="o">+</span> <span class="nx">prettyStart</span> <span class="o">+</span> <span class="dl">'</span><span class="s1"></p></span><span class="dl">'</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><p class='card-text'>End: </span><span class="dl">"</span> <span class="o">+</span> <span class="nx">prettyEnd</span> <span class="o">+</span> <span class="dl">'</span><span class="s1"></p></span><span class="dl">'</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><a href='javascript:void(0);' class='card-link' onclick='appointmentCreate(</span><span class="se">\"</span><span class="dl">"</span> <span class="o">+</span>
<span class="nx">slotReference</span> <span class="o">+</span> <span class="dl">"</span><span class="se">\"</span><span class="s2">, </span><span class="se">\"</span><span class="s2">Patient/12508016</span><span class="se">\"</span><span class="s2">);'>Book</a></span><span class="dl">"</span> <span class="o">+</span>
<span class="dl">'</span><span class="s1"></div></span><span class="dl">'</span> <span class="o">+</span>
<span class="dl">'</span><span class="s1"></div></span><span class="dl">'</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">...</span>
</code></pre></div>
<blockquote>
<p>Replace the slotHTML JavaScript function with this JavaScript. Should be on line 58.</p>
<p>/scheduling-app/src/js/scheduling-app.js</p>
</blockquote>
<div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="p">...</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#clear-appointment</span><span class="dl">'</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="dl">'</span><span class="s1">click</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#appointment</span><span class="dl">'</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="dl">''</span><span class="p">);</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#appointment-holder-row</span><span class="dl">'</span><span class="p">).</span><span class="nx">hide</span><span class="p">();</span>
<span class="p">});</span>
<span class="kd">function</span> <span class="nx">appointmentCreate</span><span class="p">(</span><span class="nx">slotReference</span><span class="p">,</span> <span class="nx">patientReference</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">clearUI</span><span class="p">();</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#loading-row</span><span class="dl">'</span><span class="p">).</span><span class="nx">show</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">appointmentBody</span> <span class="o">=</span> <span class="nx">appointmentJSON</span><span class="p">(</span><span class="nx">slotReference</span><span class="p">,</span> <span class="nx">patientReference</span><span class="p">);</span>
<span class="c1">// FHIR.oauth2.ready handles refreshing access tokens</span>
<span class="nx">FHIR</span><span class="p">.</span><span class="nx">oauth2</span><span class="p">.</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">smart</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">smart</span><span class="p">.</span><span class="nx">api</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span><span class="na">resource</span><span class="p">:</span> <span class="nx">appointmentBody</span><span class="p">}).</span><span class="nx">then</span><span class="p">(</span>
<span class="c1">// Display Appointment information if the call succeeded</span>
<span class="kd">function</span><span class="p">(</span><span class="nx">appointment</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">renderAppointment</span><span class="p">(</span><span class="nx">appointment</span><span class="p">.</span><span class="nx">headers</span><span class="p">(</span><span class="dl">'</span><span class="s1">Location</span><span class="dl">'</span><span class="p">));</span>
<span class="p">},</span>
<span class="c1">// Display 'Failed to write Appointment to FHIR server' if the call failed</span>
<span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">clearUI</span><span class="p">();</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#errors</span><span class="dl">'</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="dl">'</span><span class="s1"><p>Failed to write Appointment to FHIR server</p></span><span class="dl">'</span><span class="p">);</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#errors-row</span><span class="dl">'</span><span class="p">).</span><span class="nx">show</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">);</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">appointmentJSON</span><span class="p">(</span><span class="nx">slotReference</span><span class="p">,</span> <span class="nx">patientReference</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">{</span>
<span class="na">resourceType</span><span class="p">:</span> <span class="dl">'</span><span class="s1">Appointment</span><span class="dl">'</span><span class="p">,</span>
<span class="na">slot</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="na">reference</span><span class="p">:</span> <span class="nx">slotReference</span>
<span class="p">}</span>
<span class="p">],</span>
<span class="na">participant</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="na">actor</span><span class="p">:</span> <span class="p">{</span>
<span class="na">reference</span><span class="p">:</span> <span class="nx">patientReference</span>
<span class="p">},</span>
<span class="na">status</span><span class="p">:</span> <span class="dl">'</span><span class="s1">needs-action</span><span class="dl">'</span>
<span class="p">}</span>
<span class="p">],</span>
<span class="na">status</span><span class="p">:</span> <span class="dl">'</span><span class="s1">proposed</span><span class="dl">'</span>
<span class="p">};</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">renderAppointment</span><span class="p">(</span><span class="nx">appointmentLocation</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">clearUI</span><span class="p">();</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#appointment</span><span class="dl">'</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="dl">'</span><span class="s1"><p>Created Appointment </span><span class="dl">'</span> <span class="o">+</span> <span class="nx">appointmentLocation</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/</span><span class="se">\d</span><span class="sr">+$/</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="dl">'</span><span class="s1"></p></span><span class="dl">'</span><span class="p">);</span>
<span class="nx">$</span><span class="p">(</span><span class="dl">'</span><span class="s1">#appointment-holder-row</span><span class="dl">'</span><span class="p">).</span><span class="nx">show</span><span class="p">();</span>
<span class="p">}</span>
</code></pre></div>
<blockquote>
<p>Add this JavaScript to the bottom of <code>scheduling-app.js</code>.</p>
</blockquote>
<p>Now that we've tested searching for Slots, let's use the Slots to book Appointments. Make the changes noted on the sidebar in <code>index.html</code> and <code>scheduling-app.js</code>.</p>
<p>After making these changes, your app will be able to book Appointments for a common test Patient: Kristin Carter, patient id 12508016. Launch your app and test it out!</p>
<p>With many other consumers booking appointments for this patient, it's pretty likely that you will get some failures when you test. When we are searching for Slots, we are not searching by patient so if you attempt to book an Appointment for that patient when they are already unavailable, you will get an error from Cerner's FHIR server. Let's reduce some of these collisions by spreading the load to other patients.</p>
<h1 id='7-add-patient-search-and-create'>7.) Add Patient Search and Create</h1>
<blockquote>
<p>/scheduling-app/index.html</p>
</blockquote>
<div class="highlight"><pre class="highlight html tab-html"><code>...
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'patient-search-create-row'</span> <span class="na">class=</span><span class="s">'row mt-5'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'patient-search-create-info'</span><span class="nt">></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'accordion'</span> <span class="na">id=</span><span class="s">'patient-search-create-accordion'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'card'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'card-header'</span> <span class="na">id=</span><span class="s">'headingOne'</span><span class="nt">></span>
<span class="nt"><h5</span> <span class="na">class=</span><span class="s">'mb-0'</span><span class="nt">></span>
<span class="nt"><button</span> <span class="na">class=</span><span class="s">'btn btn-link'</span> <span class="na">type=</span><span class="s">'button'</span> <span class="na">data-toggle=</span><span class="s">'collapse'</span> <span class="na">data-target=</span><span class="s">'#collapseOne'</span> <span class="na">aria-expanded=</span><span class="s">'true'</span> <span class="na">ria-controls=</span><span class="s">'collapseOne'</span><span class="nt">></span>
Search for existing Patient
<span class="nt"></button></span>
<span class="nt"></h5></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'collapseOne'</span> <span class="na">class=</span><span class="s">'collapse show'</span> <span class="na">aria-labelledby=</span><span class="s">'headingOne'</span> <span class="na">data-parent=</span><span class="s">'#patient-search-create-accordion'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'card-body'</span><span class="nt">></span>
<span class="nt"><form</span> <span class="na">id=</span><span class="s">'patient-search-form'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'form-group row'</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">for=</span><span class="s">'patient-search-name'</span> <span class="na">class=</span><span class="s">'col-sm-2 col-form-label'</span><span class="nt">></span>Name<span class="nt"></label></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col-sm-10'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'text'</span> <span class="na">class=</span><span class="s">'form-control'</span> <span class="na">id=</span><span class="s">'patient-search-name'</span> <span class="na">placeholder=</span><span class="s">'Name'</span> <span class="na">required</span><span class="nt">></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><button</span> <span class="na">class=</span><span class="s">'btn btn-primary'</span> <span class="na">id=</span><span class="s">'patient-search'</span><span class="nt">></span>Search for Patients<span class="nt"></button></span>
<span class="nt"></form></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'card'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'card-header'</span> <span class="na">id=</span><span class="s">'headingTwo'</span><span class="nt">></span>
<span class="nt"><h5</span> <span class="na">class=</span><span class="s">'mb-0'</span><span class="nt">></span>
<span class="nt"><button</span> <span class="na">class=</span><span class="s">'btn btn-link collapsed'</span> <span class="na">type=</span><span class="s">'button'</span> <span class="na">data-toggle=</span><span class="s">'collapse'</span> <span class="na">data-target=</span><span class="s">'#collapseTwo'</span> <span class="na">ria-expanded=</span><span class="s">'false'</span> <span class="na">aria-controls=</span><span class="s">'collapseTwo'</span><span class="nt">></span>
Create new Patient
<span class="nt"></button></span>
<span class="nt"></h5></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'collapseTwo'</span> <span class="na">class=</span><span class="s">'collapse'</span> <span class="na">aria-labelledby=</span><span class="s">'headingTwo'</span> <span class="na">data-parent=</span><span class="s">'#patient-search-create-accordion'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'card-body'</span><span class="nt">></span>
<span class="nt"><form</span> <span class="na">id=</span><span class="s">'patient-create-form'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'form-group row'</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">for=</span><span class="s">'patient-create-firstname'</span> <span class="na">class=</span><span class="s">'col-sm-2 col-form-label'</span><span class="nt">></span>First Name<span class="nt"></label></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col-sm-10'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">class=</span><span class="s">'form-control'</span> <span class="na">type=</span><span class="s">'text'</span> <span class="na">name=</span><span class="s">'patient-create-firstname'</span> <span class="na">placeholder=</span><span class="s">'First name'</span> <span class="na">required</span><span class="nt">></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'form-group row'</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">for=</span><span class="s">'patient-create-middlename'</span> <span class="na">class=</span><span class="s">'col-sm-2 col-form-label'</span><span class="nt">></span>Middle Name<span class="nt"></label></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col-sm-10'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">class=</span><span class="s">'form-control'</span> <span class="na">type=</span><span class="s">'text'</span> <span class="na">name=</span><span class="s">'patient-create-middlename'</span> <span class="na">placeholder=</span><span class="s">'Middle name'</span> <span class="na">required</span><span class="nt">></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'form-group row'</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">for=</span><span class="s">'patient-create-lastname'</span> <span class="na">class=</span><span class="s">'col-sm-2 col-form-label'</span><span class="nt">></span>Last Name<span class="nt"></label></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col-sm-10'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">class=</span><span class="s">'form-control'</span> <span class="na">type=</span><span class="s">'text'</span> <span class="na">name=</span><span class="s">'patient-create-lastname'</span> <span class="na">placeholder=</span><span class="s">'Last name'</span> <span class="na">required</span><span class="nt">></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'form-group row'</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">for=</span><span class="s">'patient-create-phone'</span> <span class="na">class=</span><span class="s">'col-sm-2 col-form-label'</span><span class="nt">></span>Phone Number<span class="nt"></label></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col-sm-10'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">class=</span><span class="s">'form-control'</span> <span class="na">type=</span><span class="s">'tel'</span> <span class="na">name=</span><span class="s">'patient-create-phone'</span> <span class="na">placeholder=</span><span class="s">'555-555-5555'</span> <span class="na">attern=</span><span class="s">'[0-9]{3}-[0-9]{3}-[0-9]{4}'</span> <span class="na">required</span><span class="nt">></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><fieldset</span> <span class="na">class=</span><span class="s">'form-group'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><legend</span> <span class="na">class=</span><span class="s">'col-form-label col-sm-2 pt-0'</span><span class="nt">></span>Gender<span class="nt"></legend></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col-sm-10'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'form-check'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">class=</span><span class="s">'form-check-input'</span> <span class="na">type=</span><span class="s">'radio'</span> <span class="na">name=</span><span class="s">'gridRadios'</span> <span class="na">id=</span><span class="s">'patient-create-male'</span> <span class="na">value=</span><span class="s">'male'</span> <span class="na">checked</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">class=</span><span class="s">'form-check-label'</span> <span class="na">for=</span><span class="s">'patient-create-male'</span><span class="nt">></span>
Male
<span class="nt"></label></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'form-check'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">class=</span><span class="s">'form-check-input'</span> <span class="na">type=</span><span class="s">'radio'</span> <span class="na">name=</span><span class="s">'gridRadios'</span> <span class="na">id=</span><span class="s">'patient-create-female'</span> <span class="na">value=</span><span class="s">'female'</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">class=</span><span class="s">'form-check-label'</span> <span class="na">for=</span><span class="s">'patient-create-female'</span><span class="nt">></span>
Female
<span class="nt"></label></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></fieldset></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'form-group row'</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">for=</span><span class="s">'patient-create-birthdate'</span> <span class="na">class=</span><span class="s">'col-sm-2 col-form-label'</span><span class="nt">></span>Birthdate<span class="nt"></label></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col-sm-10'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">class=</span><span class="s">'form-control'</span> <span class="na">type=</span><span class="s">'date'</span> <span class="na">name=</span><span class="s">'patient-create-birthdate'</span> <span class="na">required</span><span class="nt">></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><button</span> <span class="na">class=</span><span class="s">'btn btn-primary'</span> <span class="na">id=</span><span class="s">'patient-create'</span><span class="nt">></span>Create Patient<span class="nt"></button></span>
<span class="nt"></form></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'patient-errors-row'</span> <span class="na">class=</span><span class="s">'row mt-5'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'patient-errors'</span><span class="nt">></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'patient-loading-row'</span> <span class="na">class=</span><span class="s">'row mt-5'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'loading'</span> <span class="na">class=</span><span class="s">'spinner'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'bounce1'</span><span class="nt">></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'bounce2'</span><span class="nt">></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'bounce3'</span><span class="nt">></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'patients-holder-row'</span> <span class="na">class=</span><span class="s">'row mt-5'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'patients-holder'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><h2></span>Patients<span class="nt"></h2></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><button</span> <span class="na">class=</span><span class="s">'btn btn-danger'</span> <span class="na">id=</span><span class="s">'clear-patients'</span><span class="nt">></span>Clear Results<span class="nt"></button></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'row'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">'col'</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">'patients'</span><span class="nt">></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
...
</code></pre></div>
<blockquote>
<p>Add this HTML to <code>index.html</code> immediately after the appointment-holder-row div. Should be on line 140.</p>
<p>/scheduling-app/src/js/scheduling-app.js - slotHTML</p>
</blockquote>
<div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="p">...</span>
<span class="kd">function</span> <span class="nx">slotHTML</span><span class="p">(</span><span class="nx">id</span><span class="p">,</span> <span class="nx">type</span><span class="p">,</span> <span class="nx">start</span><span class="p">,</span> <span class="nx">end</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">'</span><span class="s1">Slot: id:[</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">id</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">] type:[</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">type</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">] start:[</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">start</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">] end:[</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">end</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">]</span><span class="dl">'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">slotReference</span> <span class="o">=</span> <span class="dl">'</span><span class="s1">Slot/</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">id</span><span class="p">,</span>
<span class="nx">prettyStart</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nx">start</span><span class="p">),</span>
<span class="nx">prettyEnd</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nx">end</span><span class="p">);</span>
<span class="k">return</span> <span class="dl">"</span><span class="s2"><div class='card'></span><span class="dl">"</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><div class='card-body'></span><span class="dl">"</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><h5 class='card-title'></span><span class="dl">"</span> <span class="o">+</span> <span class="nx">type</span> <span class="o">+</span> <span class="dl">'</span><span class="s1"></h5></span><span class="dl">'</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><p class='card-text'>Start: </span><span class="dl">"</span> <span class="o">+</span> <span class="nx">prettyStart</span> <span class="o">+</span> <span class="dl">'</span><span class="s1"></p></span><span class="dl">'</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><p class='card-text'>End: </span><span class="dl">"</span> <span class="o">+</span> <span class="nx">prettyEnd</span> <span class="o">+</span> <span class="dl">'</span><span class="s1"></p></span><span class="dl">'</span> <span class="o">+</span>
<span class="dl">"</span><span class="s2"><a href='javascript:void(0);' class='card-link' onclick='askForPatient(</span><span class="se">\"</span><span class="dl">"</span> <span class="o">+</span>