pacing 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,852 @@
1
+ require 'spec_helper'
2
+ require 'date'
3
+
4
+ RSpec.describe Pacing::Pacer do
5
+ describe "monthly pacer" do
6
+ it "return some data" do
7
+ school_plan = {
8
+ school_plan_services: [
9
+ {
10
+ school_plan_type: 'IEP',
11
+ start_date: '04-01-2022',
12
+ end_date: '04-01-2023',
13
+ type_of_service: 'Language Therapy',
14
+ frequency: 6,
15
+ interval: 'monthly',
16
+ time_per_session_in_minutes: 30,
17
+ completed_visits_for_current_interval: 7,
18
+ extra_sessions_allowable: 1,
19
+ interval_for_extra_sessions_allowable: 'monthly'
20
+ }, {
21
+ school_plan_type: 'IEP',
22
+ start_date: '04-01-2022',
23
+ end_date: '04-01-2023',
24
+ type_of_service: 'Physical Therapy',
25
+ frequency: 6,
26
+ interval: 'monthly',
27
+ time_per_session_in_minutes: 30,
28
+ completed_visits_for_current_interval: 2,
29
+ extra_sessions_allowable: 1,
30
+ interval_for_extra_sessions_allowable: 'monthly'
31
+ }
32
+ ]
33
+ }
34
+
35
+ date = '04-22-2022'
36
+ non_business_days = ['04-25-2022']
37
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
38
+
39
+ expect(results).to eq({
40
+ school_plan_services: [
41
+ {
42
+ school_plan_type: 'IEP',
43
+ start_date: '04-01-2022',
44
+ end_date: '04-01-2023',
45
+ type_of_service: 'Language Therapy',
46
+ frequency: 6,
47
+ interval: 'monthly',
48
+ time_per_session_in_minutes: 30,
49
+ completed_visits_for_current_interval: 7,
50
+ extra_sessions_allowable: 1,
51
+ interval_for_extra_sessions_allowable: 'monthly',
52
+ remaining_visits: 0,
53
+ reset_date: '04-30-2022',
54
+ pace: 2,
55
+ pace_indicator: "🐇"
56
+ }, {
57
+ school_plan_type: 'IEP',
58
+ start_date: '04-01-2022',
59
+ end_date: '04-01-2023',
60
+ type_of_service: 'Physical Therapy',
61
+ frequency: 6,
62
+ interval: 'monthly',
63
+ time_per_session_in_minutes: 30,
64
+ completed_visits_for_current_interval: 2,
65
+ extra_sessions_allowable: 1,
66
+ interval_for_extra_sessions_allowable: 'monthly',
67
+ remaining_visits: 4,
68
+ reset_date: '04-30-2022',
69
+ pace: -3,
70
+ pace_indicator: "🐢"
71
+ }
72
+ ]
73
+ })
74
+ end
75
+
76
+ it "should return a positive pacing when more visits are completed than expected before a particular point in time" do
77
+ school_plan = {
78
+ school_plan_services: [
79
+ {
80
+ school_plan_type: 'IEP',
81
+ start_date: '04-01-2022',
82
+ end_date: '04-01-2023',
83
+ type_of_service: 'Speech Therapy',
84
+ frequency: 12,
85
+ interval: 'monthly',
86
+ time_per_session_in_minutes: 30,
87
+ completed_visits_for_current_interval: 8,
88
+ extra_sessions_allowable: 1,
89
+ interval_for_extra_sessions_allowable: 'monthly'
90
+ }, {
91
+ school_plan_type: 'IEP',
92
+ start_date: '04-01-2022',
93
+ end_date: '04-01-2023',
94
+ type_of_service: 'Physical Therapy',
95
+ frequency: 6,
96
+ interval: 'monthly',
97
+ time_per_session_in_minutes: 30,
98
+ completed_visits_for_current_interval: 4,
99
+ extra_sessions_allowable: 1,
100
+ interval_for_extra_sessions_allowable: 'monthly'
101
+ }
102
+ ]
103
+ }
104
+
105
+ date = '04-16-2022'
106
+ non_business_days = ['04-25-2022']
107
+
108
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
109
+
110
+ expect(results).to eq(
111
+ {
112
+ school_plan_services: [
113
+ {
114
+ school_plan_type: 'IEP',
115
+ start_date: '04-01-2022',
116
+ end_date: '04-01-2023',
117
+ type_of_service: 'Speech Therapy',
118
+ frequency: 12,
119
+ interval: 'monthly',
120
+ time_per_session_in_minutes: 30,
121
+ completed_visits_for_current_interval: 8,
122
+ extra_sessions_allowable: 1,
123
+ interval_for_extra_sessions_allowable: 'monthly',
124
+ remaining_visits: 4,
125
+ reset_date: '04-30-2022',
126
+ pace: 2,
127
+ pace_indicator: "🐇"
128
+ }, {
129
+ school_plan_type: 'IEP',
130
+ start_date: '04-01-2022',
131
+ end_date: '04-01-2023',
132
+ type_of_service: 'Physical Therapy',
133
+ frequency: 6,
134
+ interval: 'monthly',
135
+ time_per_session_in_minutes: 30,
136
+ completed_visits_for_current_interval: 4,
137
+ extra_sessions_allowable: 1,
138
+ interval_for_extra_sessions_allowable: 'monthly',
139
+ remaining_visits: 2,
140
+ reset_date: '04-30-2022',
141
+ pace: 1,
142
+ pace_indicator: "🐇"
143
+ }
144
+ ]
145
+ })
146
+ end
147
+
148
+ it "should return a negative pacing when fewer visits are completed than expected before a particular point in time" do
149
+ school_plan = {
150
+ school_plan_services: [
151
+ {
152
+ school_plan_type: 'IEP',
153
+ start_date: '04-01-2022',
154
+ end_date: '04-01-2023',
155
+ type_of_service: 'Speech Therapy',
156
+ frequency: 12,
157
+ interval: 'monthly',
158
+ time_per_session_in_minutes: 30,
159
+ completed_visits_for_current_interval: 3,
160
+ extra_sessions_allowable: 1,
161
+ interval_for_extra_sessions_allowable: 'monthly'
162
+ }, {
163
+ school_plan_type: 'IEP',
164
+ start_date: '04-01-2022',
165
+ end_date: '04-01-2023',
166
+ type_of_service: 'Physical Therapy',
167
+ frequency: 6,
168
+ interval: 'monthly',
169
+ time_per_session_in_minutes: 30,
170
+ completed_visits_for_current_interval: 1,
171
+ extra_sessions_allowable: 1,
172
+ interval_for_extra_sessions_allowable: 'monthly'
173
+ }
174
+ ]
175
+ }
176
+
177
+ date = '04-28-2022'
178
+ non_business_days = ['04-25-2022']
179
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
180
+
181
+ expect(results).to eq(
182
+ {
183
+ school_plan_services: [
184
+ {
185
+ school_plan_type: 'IEP',
186
+ start_date: '04-01-2022',
187
+ end_date: '04-01-2023',
188
+ type_of_service: 'Speech Therapy',
189
+ frequency: 12,
190
+ interval: 'monthly',
191
+ time_per_session_in_minutes: 30,
192
+ completed_visits_for_current_interval: 3,
193
+ extra_sessions_allowable: 1,
194
+ interval_for_extra_sessions_allowable: 'monthly',
195
+ remaining_visits: 9,
196
+ reset_date: '04-30-2022',
197
+ pace: -8,
198
+ pace_indicator: "🐢"
199
+ }, {
200
+ school_plan_type: 'IEP',
201
+ start_date: '04-01-2022',
202
+ end_date: '04-01-2023',
203
+ type_of_service: 'Physical Therapy',
204
+ frequency: 6,
205
+ interval: 'monthly',
206
+ time_per_session_in_minutes: 30,
207
+ completed_visits_for_current_interval: 1,
208
+ extra_sessions_allowable: 1,
209
+ interval_for_extra_sessions_allowable: 'monthly',
210
+ remaining_visits: 5,
211
+ reset_date: '04-30-2022',
212
+ pace: -5,
213
+ pace_indicator: "🐢"
214
+ }
215
+ ]
216
+ }
217
+ )
218
+ end
219
+
220
+ it "should return a zero(neutral) pacing when visits completed equal expected visits at a particular point in time" do
221
+ school_plan = {
222
+ school_plan_services: [
223
+ {
224
+ school_plan_type: 'IEP',
225
+ start_date: '05-01-2022',
226
+ end_date: '05-01-2023',
227
+ type_of_service: 'Speech Therapy',
228
+ frequency: 12,
229
+ interval: 'monthly',
230
+ time_per_session_in_minutes: 30,
231
+ completed_visits_for_current_interval: 6,
232
+ extra_sessions_allowable: 1,
233
+ interval_for_extra_sessions_allowable: 'monthly'
234
+ }, {
235
+ school_plan_type: 'IEP',
236
+ start_date: '05-01-2022',
237
+ end_date: '05-01-2023',
238
+ type_of_service: 'Physical Therapy',
239
+ frequency: 6,
240
+ interval: 'monthly',
241
+ time_per_session_in_minutes: 30,
242
+ completed_visits_for_current_interval: 3,
243
+ extra_sessions_allowable: 1,
244
+ interval_for_extra_sessions_allowable: 'monthly'
245
+ }
246
+ ]
247
+ }
248
+
249
+ date = '05-16-2022'
250
+ non_business_days = ['05-25-2022']
251
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
252
+
253
+ expect(results).to eq(
254
+ {
255
+ school_plan_services: [
256
+ {
257
+ school_plan_type: 'IEP',
258
+ start_date: '05-01-2022',
259
+ end_date: '05-01-2023',
260
+ type_of_service: 'Speech Therapy',
261
+ frequency: 12,
262
+ interval: 'monthly',
263
+ time_per_session_in_minutes: 30,
264
+ completed_visits_for_current_interval: 6,
265
+ extra_sessions_allowable: 1,
266
+ interval_for_extra_sessions_allowable: 'monthly',
267
+ remaining_visits: 6,
268
+ reset_date: '05-31-2022',
269
+ pace: 0,
270
+ pace_indicator: "😁"
271
+ }, {
272
+ school_plan_type: 'IEP',
273
+ start_date: '05-01-2022',
274
+ end_date: '05-01-2023',
275
+ type_of_service: 'Physical Therapy',
276
+ frequency: 6,
277
+ interval: 'monthly',
278
+ time_per_session_in_minutes: 30,
279
+ completed_visits_for_current_interval: 3,
280
+ extra_sessions_allowable: 1,
281
+ interval_for_extra_sessions_allowable: 'monthly',
282
+ remaining_visits: 3,
283
+ reset_date: '05-31-2022',
284
+ pace: 0,
285
+ pace_indicator: "😁"
286
+ }
287
+ ]
288
+ }
289
+ )
290
+ end
291
+ end
292
+
293
+ describe "weekly pacer" do
294
+ it "should return a positive pacing when more visits are completed than expected before a particular point in time" do
295
+
296
+ school_plan = {
297
+ school_plan_services: [
298
+ {
299
+ school_plan_type: 'IEP',
300
+ start_date: '04-01-2022',
301
+ end_date: '04-01-2023',
302
+ type_of_service: 'Speech Therapy',
303
+ frequency: 3,
304
+ interval: 'weekly',
305
+ time_per_session_in_minutes: 30,
306
+ completed_visits_for_current_interval: 2,
307
+ extra_sessions_allowable: 1,
308
+ interval_for_extra_sessions_allowable: 'weekly'
309
+ }, {
310
+ school_plan_type: 'IEP',
311
+ start_date: '04-01-2022',
312
+ end_date: '04-01-2023',
313
+ type_of_service: 'Physical Therapy',
314
+ frequency: 2,
315
+ interval: 'weekly',
316
+ time_per_session_in_minutes: 30,
317
+ completed_visits_for_current_interval: 1,
318
+ extra_sessions_allowable: 1,
319
+ interval_for_extra_sessions_allowable: 'weekly'
320
+ }
321
+ ]
322
+ }
323
+
324
+ date = '04-16-2022'
325
+ non_business_days = ['04-25-2022']
326
+
327
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
328
+
329
+ expect(results).to eq(
330
+ {
331
+ school_plan_services: [
332
+ {
333
+ school_plan_type: 'IEP',
334
+ start_date: '04-01-2022',
335
+ end_date: '04-01-2023',
336
+ type_of_service: 'Speech Therapy',
337
+ frequency: 3,
338
+ interval: 'weekly',
339
+ time_per_session_in_minutes: 30,
340
+ completed_visits_for_current_interval: 2,
341
+ extra_sessions_allowable: 1,
342
+ interval_for_extra_sessions_allowable: 'weekly',
343
+ remaining_visits: 1,
344
+ reset_date: '04-22-2022',
345
+ pace: 2,
346
+ pace_indicator: "🐇"
347
+ }, {
348
+ school_plan_type: 'IEP',
349
+ start_date: '04-01-2022',
350
+ end_date: '04-01-2023',
351
+ type_of_service: 'Physical Therapy',
352
+ frequency: 2,
353
+ interval: 'weekly',
354
+ time_per_session_in_minutes: 30,
355
+ completed_visits_for_current_interval: 1,
356
+ extra_sessions_allowable: 1,
357
+ interval_for_extra_sessions_allowable: 'weekly',
358
+ remaining_visits: 1,
359
+ reset_date: '04-22-2022',
360
+ pace: 1,
361
+ pace_indicator: "🐇"
362
+ }
363
+ ]
364
+ })
365
+ end
366
+
367
+ it "should return a negative pacing when fewer visits are completed than expected before a particular point in time" do
368
+ school_plan = {
369
+ school_plan_services: [
370
+ {
371
+ school_plan_type: 'IEP',
372
+ start_date: '04-01-2022',
373
+ end_date: '04-01-2023',
374
+ type_of_service: 'Speech Therapy',
375
+ frequency: 4,
376
+ interval: 'weekly',
377
+ time_per_session_in_minutes: 30,
378
+ completed_visits_for_current_interval: 1,
379
+ extra_sessions_allowable: 1,
380
+ interval_for_extra_sessions_allowable: 'weekly'
381
+ }, {
382
+ school_plan_type: 'IEP',
383
+ start_date: '04-01-2022',
384
+ end_date: '04-01-2023',
385
+ type_of_service: 'Physical Therapy',
386
+ frequency: 2,
387
+ interval: 'weekly',
388
+ time_per_session_in_minutes: 30,
389
+ completed_visits_for_current_interval: 0,
390
+ extra_sessions_allowable: 1,
391
+ interval_for_extra_sessions_allowable: 'weekly'
392
+ }
393
+ ]
394
+ }
395
+
396
+ date = '04-21-2022'
397
+ non_business_days = ['04-25-2022']
398
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
399
+
400
+ expect(results).to eq(
401
+ {
402
+ school_plan_services: [
403
+ {
404
+ school_plan_type: 'IEP',
405
+ start_date: '04-01-2022',
406
+ end_date: '04-01-2023',
407
+ type_of_service: 'Speech Therapy',
408
+ frequency: 4,
409
+ interval: 'weekly',
410
+ time_per_session_in_minutes: 30,
411
+ completed_visits_for_current_interval: 1,
412
+ extra_sessions_allowable: 1,
413
+ interval_for_extra_sessions_allowable: 'weekly',
414
+ remaining_visits: 3,
415
+ reset_date: '04-22-2022',
416
+ pace: -3,
417
+ pace_indicator: "🐢"
418
+ }, {
419
+ school_plan_type: 'IEP',
420
+ start_date: '04-01-2022',
421
+ end_date: '04-01-2023',
422
+ type_of_service: 'Physical Therapy',
423
+ frequency: 2,
424
+ interval: 'weekly',
425
+ time_per_session_in_minutes: 30,
426
+ completed_visits_for_current_interval: 0,
427
+ extra_sessions_allowable: 1,
428
+ interval_for_extra_sessions_allowable: 'weekly',
429
+ remaining_visits: 2,
430
+ reset_date: '04-22-2022',
431
+ pace: -2,
432
+ pace_indicator: "🐢"
433
+ }
434
+ ]
435
+ }
436
+ )
437
+ end
438
+
439
+ it "should return a zero(neutral) pacing when visits completed equal expected visits at a particular point in time" do
440
+ school_plan = {
441
+ school_plan_services: [
442
+ {
443
+ school_plan_type: 'IEP',
444
+ start_date: '05-01-2022',
445
+ end_date: '05-01-2023',
446
+ type_of_service: 'Speech Therapy',
447
+ frequency: 4,
448
+ interval: 'weekly',
449
+ time_per_session_in_minutes: 30,
450
+ completed_visits_for_current_interval: 2,
451
+ extra_sessions_allowable: 1,
452
+ interval_for_extra_sessions_allowable: 'weekly'
453
+ }, {
454
+ school_plan_type: 'IEP',
455
+ start_date: '05-01-2022',
456
+ end_date: '05-01-2023',
457
+ type_of_service: 'Physical Therapy',
458
+ frequency: 2,
459
+ interval: 'weekly',
460
+ time_per_session_in_minutes: 30,
461
+ completed_visits_for_current_interval: 1,
462
+ extra_sessions_allowable: 1,
463
+ interval_for_extra_sessions_allowable: 'weekly'
464
+ }
465
+ ]
466
+ }
467
+
468
+ date = '05-18-2022'
469
+ non_business_days = ['05-25-2022']
470
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
471
+
472
+ expect(results).to eq(
473
+ {
474
+ school_plan_services: [
475
+ {
476
+ school_plan_type: 'IEP',
477
+ start_date: '05-01-2022',
478
+ end_date: '05-01-2023',
479
+ type_of_service: 'Speech Therapy',
480
+ frequency: 4,
481
+ interval: 'weekly',
482
+ time_per_session_in_minutes: 30,
483
+ completed_visits_for_current_interval: 2,
484
+ extra_sessions_allowable: 1,
485
+ interval_for_extra_sessions_allowable: 'weekly',
486
+ remaining_visits: 2,
487
+ reset_date: '05-22-2022',
488
+ pace: 0,
489
+ pace_indicator: "😁"
490
+ }, {
491
+ school_plan_type: 'IEP',
492
+ start_date: '05-01-2022',
493
+ end_date: '05-01-2023',
494
+ type_of_service: 'Physical Therapy',
495
+ frequency: 2,
496
+ interval: 'weekly',
497
+ time_per_session_in_minutes: 30,
498
+ completed_visits_for_current_interval: 1,
499
+ extra_sessions_allowable: 1,
500
+ interval_for_extra_sessions_allowable: 'weekly',
501
+ remaining_visits: 1,
502
+ reset_date: '05-22-2022',
503
+ pace: 0,
504
+ pace_indicator: "😁"
505
+ }
506
+ ]
507
+ }
508
+ )
509
+ end
510
+ end
511
+
512
+ describe "yearly pacer" do
513
+ it "should return a positive pacing when more visits are completed than expected before a particular point in time" do
514
+
515
+ school_plan = {
516
+ school_plan_services: [
517
+ {
518
+ school_plan_type: 'IEP',
519
+ start_date: '04-01-2022',
520
+ end_date: '04-01-2025',
521
+ type_of_service: 'Speech Therapy',
522
+ frequency: 12,
523
+ interval: 'yearly',
524
+ time_per_session_in_minutes: 30,
525
+ completed_visits_for_current_interval: 6,
526
+ extra_sessions_allowable: 1,
527
+ interval_for_extra_sessions_allowable: 'yearly'
528
+ }, {
529
+ school_plan_type: 'IEP',
530
+ start_date: '04-01-2022',
531
+ end_date: '04-01-2025',
532
+ type_of_service: 'Physical Therapy',
533
+ frequency: 6,
534
+ interval: 'yearly',
535
+ time_per_session_in_minutes: 30,
536
+ completed_visits_for_current_interval: 4,
537
+ extra_sessions_allowable: 1,
538
+ interval_for_extra_sessions_allowable: 'yearly'
539
+ }
540
+ ]
541
+ }
542
+
543
+ date = '08-16-2022'
544
+ non_business_days = ['04-25-2022']
545
+
546
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
547
+
548
+ expect(results).to eq(
549
+ {
550
+ school_plan_services: [
551
+ {
552
+ school_plan_type: 'IEP',
553
+ start_date: '04-01-2022',
554
+ end_date: '04-01-2025',
555
+ type_of_service: 'Speech Therapy',
556
+ frequency: 12,
557
+ interval: 'yearly',
558
+ time_per_session_in_minutes: 30,
559
+ completed_visits_for_current_interval: 6,
560
+ extra_sessions_allowable: 1,
561
+ interval_for_extra_sessions_allowable: 'yearly',
562
+ remaining_visits: 6,
563
+ reset_date: '04-01-2023',
564
+ pace: 1,
565
+ pace_indicator: "🐇"
566
+ }, {
567
+ school_plan_type: 'IEP',
568
+ start_date: '04-01-2022',
569
+ end_date: '04-01-2025',
570
+ type_of_service: 'Physical Therapy',
571
+ frequency: 6,
572
+ interval: 'yearly',
573
+ time_per_session_in_minutes: 30,
574
+ completed_visits_for_current_interval: 4,
575
+ extra_sessions_allowable: 1,
576
+ interval_for_extra_sessions_allowable: 'yearly',
577
+ remaining_visits: 2,
578
+ reset_date: '04-01-2023',
579
+ pace: 2,
580
+ pace_indicator: "🐇"
581
+ }
582
+ ]
583
+ })
584
+ end
585
+
586
+ it "should return a negative pacing when fewer visits are completed than expected before a particular point in time" do
587
+ school_plan = {
588
+ school_plan_services: [
589
+ {
590
+ school_plan_type: 'IEP',
591
+ start_date: '04-01-2022',
592
+ end_date: '04-01-2024',
593
+ type_of_service: 'Speech Therapy',
594
+ frequency: 12,
595
+ interval: 'yearly',
596
+ time_per_session_in_minutes: 30,
597
+ completed_visits_for_current_interval: 2,
598
+ extra_sessions_allowable: 1,
599
+ interval_for_extra_sessions_allowable: 'yearly'
600
+ }, {
601
+ school_plan_type: 'IEP',
602
+ start_date: '04-01-2022',
603
+ end_date: '04-01-2024',
604
+ type_of_service: 'Physical Therapy',
605
+ frequency: 6,
606
+ interval: 'yearly',
607
+ time_per_session_in_minutes: 30,
608
+ completed_visits_for_current_interval: 1,
609
+ extra_sessions_allowable: 1,
610
+ interval_for_extra_sessions_allowable: 'yearly'
611
+ }
612
+ ]
613
+ }
614
+
615
+ date = '08-15-2022'
616
+ non_business_days = ['04-25-2022']
617
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
618
+
619
+ expect(results).to eq(
620
+ {
621
+ school_plan_services: [
622
+ {
623
+ school_plan_type: 'IEP',
624
+ start_date: '04-01-2022',
625
+ end_date: '04-01-2024',
626
+ type_of_service: 'Speech Therapy',
627
+ frequency: 12,
628
+ interval: 'yearly',
629
+ time_per_session_in_minutes: 30,
630
+ completed_visits_for_current_interval: 2,
631
+ extra_sessions_allowable: 1,
632
+ interval_for_extra_sessions_allowable: 'yearly',
633
+ remaining_visits: 10,
634
+ reset_date: '04-01-2023',
635
+ pace: -2,
636
+ pace_indicator: "🐢"
637
+ }, {
638
+ school_plan_type: 'IEP',
639
+ start_date: '04-01-2022',
640
+ end_date: '04-01-2024',
641
+ type_of_service: 'Physical Therapy',
642
+ frequency: 6,
643
+ interval: 'yearly',
644
+ time_per_session_in_minutes: 30,
645
+ completed_visits_for_current_interval: 1,
646
+ extra_sessions_allowable: 1,
647
+ interval_for_extra_sessions_allowable: 'yearly',
648
+ remaining_visits: 5,
649
+ reset_date: '04-01-2023',
650
+ pace: -1,
651
+ pace_indicator: "🐢"
652
+ }
653
+ ]
654
+ }
655
+ )
656
+ end
657
+
658
+ it "should return a zero(neutral) pacing when visits completed equal expected visits at a particular point in time" do
659
+ school_plan = {
660
+ school_plan_services: [
661
+ {
662
+ school_plan_type: 'IEP',
663
+ start_date: '05-01-2022',
664
+ end_date: '05-01-2024',
665
+ type_of_service: 'Speech Therapy',
666
+ frequency: 12,
667
+ interval: 'yearly',
668
+ time_per_session_in_minutes: 30,
669
+ completed_visits_for_current_interval: 4,
670
+ extra_sessions_allowable: 1,
671
+ interval_for_extra_sessions_allowable: 'yearly'
672
+ }, {
673
+ school_plan_type: 'IEP',
674
+ start_date: '05-01-2022',
675
+ end_date: '05-01-2024',
676
+ type_of_service: 'Physical Therapy',
677
+ frequency: 6,
678
+ interval: 'yearly',
679
+ time_per_session_in_minutes: 30,
680
+ completed_visits_for_current_interval: 2,
681
+ extra_sessions_allowable: 1,
682
+ interval_for_extra_sessions_allowable: 'yearly'
683
+ }
684
+ ]
685
+ }
686
+
687
+ date = '09-10-2022'
688
+ non_business_days = ['05-25-2022']
689
+ results = Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate
690
+
691
+ expect(results).to eq(
692
+ {
693
+ school_plan_services: [
694
+ {
695
+ school_plan_type: 'IEP',
696
+ start_date: '05-01-2022',
697
+ end_date: '05-01-2024',
698
+ type_of_service: 'Speech Therapy',
699
+ frequency: 12,
700
+ interval: 'yearly',
701
+ time_per_session_in_minutes: 30,
702
+ completed_visits_for_current_interval: 4,
703
+ extra_sessions_allowable: 1,
704
+ interval_for_extra_sessions_allowable: 'yearly',
705
+ remaining_visits: 8,
706
+ reset_date: '05-01-2023',
707
+ pace: 0,
708
+ pace_indicator: "😁"
709
+ }, {
710
+ school_plan_type: 'IEP',
711
+ start_date: '05-01-2022',
712
+ end_date: '05-01-2024',
713
+ type_of_service: 'Physical Therapy',
714
+ frequency: 6,
715
+ interval: 'yearly',
716
+ time_per_session_in_minutes: 30,
717
+ completed_visits_for_current_interval: 2,
718
+ extra_sessions_allowable: 1,
719
+ interval_for_extra_sessions_allowable: 'yearly',
720
+ remaining_visits: 4,
721
+ reset_date: '05-01-2023',
722
+ pace: 0,
723
+ pace_indicator: "😁"
724
+ }
725
+ ]
726
+ }
727
+ )
728
+ end
729
+ end
730
+
731
+ describe 'error handling' do
732
+ it "should respond with friendly error message for a misformed date" do
733
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
734
+ date = '22-1-2022'
735
+ non_business_days = ['25-1-2022']
736
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('The date should be formatted as a string in the format mm-dd-yyyy')
737
+ end
738
+
739
+ it "should respond with friendly error message for a misformed date" do
740
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
741
+ date = '22-1-2022'
742
+ non_business_days = ['25-1-2022']
743
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error(TypeError)
744
+ end
745
+
746
+ it "should respond with a friendly error message if no date is passed in" do
747
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
748
+ date = nil
749
+ non_business_days = ['25-01-2022']
750
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('You must pass in a date')
751
+ end
752
+
753
+ it "should respond with friendly error message for a misformed date for non-business-days" do
754
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
755
+ date = '04-22-2022'
756
+ non_business_days = ['25-1-2022']
757
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('"Non business days" dates should be formatted as a string in the format mm-dd-yyyy')
758
+ end
759
+
760
+ it "should respond with friendly error message for a misformed date for non-business-days if there is an array of dates" do
761
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
762
+ date = '04-22-2022'
763
+ non_business_days = ['25-1-2022', '04-22-2022']
764
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('"Non business days" dates should be formatted as a string in the format mm-dd-yyyy')
765
+ end
766
+
767
+ it "should respond with friendly error message if there is no school plan passed in" do
768
+ school_plan = nil
769
+ date = '04-22-2022'
770
+ non_business_days = ['04-22-2022']
771
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('You must pass in at least one school plan')
772
+ end
773
+
774
+ it "should respond with a friendly error message if the school plan is not passed in as a hash" do
775
+ school_plan = 1
776
+ date = '04-22-2022'
777
+ non_business_days = ['04-22-2022']
778
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('School plan must be a hash')
779
+ end
780
+
781
+ it "should respond with friendly error message for a misformed date in the school plan service" do
782
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '13-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
783
+ date = '04-22-2022'
784
+ non_business_days = ['04-01-2022', '04-22-2022']
785
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('School plan services start and end dates should be formatted as a string in the format mm-dd-yyyy')
786
+ end
787
+
788
+ it "should respond with friendly error message if no start or end date is passed in" do
789
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: nil, end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
790
+ date = '04-22-2022'
791
+ non_business_days = ['04-01-2022', '04-22-2022']
792
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('School plan services start and end dates can not be nil')
793
+ end
794
+
795
+ it "should respond with friendly error message if school plan type is not a string or not passed in" do
796
+ school_plan = {school_plan_services: [{school_plan_type: 1, start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
797
+ date = '04-22-2022'
798
+ non_business_days = ['04-01-2022', '04-22-2022']
799
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('School plan type must be a string and cannot be nil')
800
+ end
801
+
802
+ it "should respond with friendly error message if type of service is not a string or not passed in" do
803
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: nil, frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
804
+ date = '04-22-2022'
805
+ non_business_days = ['04-01-2022', '04-22-2022']
806
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('Type of service must be a string and cannot be nil')
807
+ end
808
+
809
+ it "should respond with friendly error message if frequency is not an integer or not passed in" do
810
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 'six', interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
811
+ date = '04-22-2022'
812
+ non_business_days = ['04-01-2022', '04-22-2022']
813
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('Frequency must be an integer and cannot be nil')
814
+ end
815
+
816
+ it "should respond with friendly error message if interval is not a string or not passed in" do
817
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: nil, time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
818
+ date = '04-22-2022'
819
+ non_business_days = ['04-01-2022', '04-22-2022']
820
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('Interval must be a string and cannot be nil')
821
+ end
822
+
823
+ it "should respond with friendly error message if time per session in minutes is not an integer or not passed in" do
824
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 'thirty', completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
825
+ date = '04-22-2022'
826
+ non_business_days = ['04-01-2022', '04-22-2022']
827
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('Time per session in minutes must be an integer and cannot be nil')
828
+ end
829
+
830
+ it "should respond with friendly error message if completed visits for current interval is not an integer or not passed in" do
831
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 'seven', extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
832
+ date = '04-22-2022'
833
+ non_business_days = ['04-01-2022', '04-22-2022']
834
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('Completed visits for current interval must be an integer and cannot be nil')
835
+ end
836
+
837
+ it "should respond with friendly error message if extra sessionss allowable is not an integer or not passed in" do
838
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 'one', interval_for_extra_sessions_allowable: 'monthly' }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
839
+ date = '04-22-2022'
840
+ non_business_days = ['04-01-2022', '04-22-2022']
841
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('Extra sessions allowable must be an integer and cannot be nil')
842
+ end
843
+
844
+ it "should respond with friendly error message if interval for extra sessions allowable is not a string or not passed in" do
845
+ school_plan = {school_plan_services: [{school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Language Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: nil }, {school_plan_type: 'IEP', start_date: '04-01-2022', end_date: '04-01-2023', type_of_service: 'Physical Therapy', frequency: 6, interval: 'monthly', time_per_session_in_minutes: 30, completed_visits_for_current_interval: 7, extra_sessions_allowable: 1, interval_for_extra_sessions_allowable: 'monthly' }]}
846
+ date = '04-22-2022'
847
+ non_business_days = ['04-01-2022', '04-22-2022']
848
+ expect { Pacing::Pacer.new(school_plan: school_plan, date: date, non_business_days: non_business_days ).calculate }.to raise_error('Interval for extra sessions allowable must be a string and cannot be nil')
849
+ end
850
+
851
+ end
852
+ end