forked from KRMAssociatesInc/JDS-GTM
-
Notifications
You must be signed in to change notification settings - Fork 2
/
VPRJTPR.m
723 lines (723 loc) · 28.3 KB
/
VPRJTPR.m
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
VPRJTPR ;SLC/KCM -- Integration tests for RESTful queries
;
STARTUP ; Run once before all tests
N I,TAGS
F I=1:1:5 S TAGS(I)="MED"_I_"^VPRJTP02"
D BLDPT^VPRJTX(.TAGS)
Q
SHUTDOWN ; Run once after all tests
D CLRPT^VPRJTX
K ^VPRPTJ
K ^VPRPT
K ^VPRMETA("JPID")
K ^TMP
Q
SETUP ; Run before each test
K HTTPREQ,HTTPERR,HTTPRSP
Q
TEARDOWN ; Run after each test
K HTTPREQ,HTTPERR,HTTPRSP
Q
ASSERT(EXPECT,ACTUAL,MSG) ; convenience
D EQ^VPRJT(EXPECT,ACTUAL,$G(MSG))
Q
;
; POST data for POST query tests
POSTDATA1 ;; test POST query data for TIMERNG
;;{"range":"20060101..20061231"}
;;zzzzz
POSTDATA2 ;; test POST query data for LAST
;;{"range":"Metformin, Aspirin Tab"}
;;zzzzz
POSTDATA3 ;; test POST query data for ORDASC
;;{"order":"qualifiedName asc"}
;;zzzzz
POSTDATA4 ;; test POST query data for ORDDESC
;;{"order":"qualifiedName DESC"}
;;zzzzz
POSTDATA5 ;; test POST query data for ORDEMPTY
;;{"order":"stopped"}
;;zzzzz
POSTDATA6 ;; test POST query data for FILTER
;;{"filter":"gt(\"orders[].fillsRemaining\",4)"}
;;zzzzz
POSTDATA7 ;; test POST query data for FINDPAR
;;{"filter":"eq(\"products[].ingredientName\",\"METFORMIN\") eq(\"dosages[].dose\",\"250 MG\")"}
;;zzzzz
;
TIMERNG ;; @TEST query for range of time
;;{"data":{"updated":20120517174918,"totalItems":3,"items":[{
N ROOT,JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/index/med-time/?range=20060101..20061231")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(3,$G(JSON("data","totalItems")))
D ASSERT("METFORMIN",$G(JSON("data","items",3,"products",1,"ingredientName")))
; test POST query version
K HTTPER,JSON,PTIME,TIME
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETPOST^VPRJTX("/vpr/"_VPRJTPID_"/index/med-time/?query=true","POSTDATA1","VPRJTPR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(3,$G(JSON("data","totalItems")))
D ASSERT("METFORMIN",$G(JSON("data","items",3,"products",1,"ingredientName")))
Q
LAST ;; @TEST query for last instance of items in list
N ROOT,JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/last/med-ingredient-name?range=Metformin, Aspirin Tab")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(2,$G(JSON("data","totalItems")))
D ASSERT("urn:va:med:93EF:-7:18069",$G(JSON("data","items",1,"uid")))
D ASSERT("urn:va:med:93EF:-7:18068",$G(JSON("data","items",2,"uid")))
; test POST query version
K HTTPERR,JSON,PTIME,TIME
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETPOST^VPRJTX("/vpr/"_VPRJTPID_"/last/med-ingredient-name?query=true","POSTDATA2","VPRJTPR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(2,$G(JSON("data","totalItems")))
D ASSERT("urn:va:med:93EF:-7:18069",$G(JSON("data","items",1,"uid")))
D ASSERT("urn:va:med:93EF:-7:18068",$G(JSON("data","items",2,"uid")))
Q
ORDASC ;; @TEST query to return in different order
N ROOT,JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/index/medication?order=qualifiedName asc")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("WARFARIN",$G(JSON("data","items",5,"qualifiedName")))
; test POST query version
K HTTPER,JSON,PTIME,TIME
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETPOST^VPRJTX("/vpr/"_VPRJTPID_"/index/medication?query=true","POSTDATA3","VPRJTPR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("WARFARIN",$G(JSON("data","items",5,"qualifiedName")))
Q
ORDDESC ;; @TEST query to return in different order
N ROOT,JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/index/medication?order=qualifiedName DESC")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("WARFARIN",$G(JSON("data","items",1,"qualifiedName")))
; test POST query version
K HTTPER,JSON,PTIME,TIME
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETPOST^VPRJTX("/vpr/"_VPRJTPID_"/index/medication?query=true","POSTDATA4","VPRJTPR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("WARFARIN",$G(JSON("data","items",1,"qualifiedName")))
Q
ORDEMPTY ;; @TEST "order by" where field includes empty string
N ROOT,JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/index/medication?order=stopped")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("",$G(JSON("data","items",1,"stopped")))
D ASSERT("20080128",$G(JSON("data","items",5,"stopped")))
; test POST query version
K HTTPERR,JSON,PTIME,TIME
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETPOST^VPRJTX("/vpr/"_VPRJTPID_"/index/medication?query=true","POSTDATA5","VPRJTPR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("",$G(JSON("data","items",1,"stopped")))
D ASSERT("20080128",$G(JSON("data","items",5,"stopped")))
Q
FILTER ;; @TEST filter to return based on criteria
;;{"data":{"updated":20120517174918,"totalItems":3,"items":[{
N ROOT,JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/index/medication/?filter=gt(""orders[].fillsRemaining"",4)")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(1,$G(JSON("data","totalItems")))
D ASSERT("urn:va:med:93EF:-7:17203",$G(JSON("data","items",1,"uid")))
;D SHOWRSP^VPRJTX(ROOT)
; test POST query version
K HTTPERR,JSON,PTIME,TIME
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETPOST^VPRJTX("/vpr/"_VPRJTPID_"/index/medication/?query=true","POSTDATA6","VPRJTPR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(1,$G(JSON("data","totalItems")))
D ASSERT("urn:va:med:93EF:-7:17203",$G(JSON("data","items",1,"uid")))
Q
GETUID ;; @TEST getting an object by UID only
N JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/uid/"_"urn:va:med:93EF:-7:18068")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("ASPIRIN",$G(JSON("data","items",1,"qualifiedName")))
Q
EVERY ;; @TEST retrieving every object for a patient
N JSON,ERR,HTTPERR,VPRJTPID1,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/index/every")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(6,$G(JSON("data","totalItems")))
D ASSERT(0,$D(^TMP($J,$J)))
S VPRJTPID1=$$JPID4PID^VPRJPR(VPRJTPID)
; Cache is disable
;D ASSERT(10,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID1_"/every////"))))
;D ASSERT(0,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID1_"/every////"),$J)))
K JSON
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/index/every?start=3&limit=3")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(3,$G(JSON("data","currentItemCount")))
; Cache is disabled
;D ASSERT(10,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID1_"/every////"))))
;D ASSERT(0,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID1_"/every////"),$J)))
Q
FINDALL ;; @TEST finding every object in collection
N JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/find/med")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(5,$G(JSON("data","totalItems")))
Q
FINDPAR ;; @TEST finding with parameters
N JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/find/med?filter=eq(""products[].ingredientName"",""METFORMIN"") eq(""dosages[].dose"",""250 MG"")")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(1,$G(JSON("data","totalItems")))
D ASSERT("urn:va:med:93EF:-7:16982",$G(JSON("data","items",1,"uid")))
; test POST query version
K HTTPERR,JSON,PTIME,TIME
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETPOST^VPRJTX("/vpr/"_VPRJTPID_"/find/med?query=true","POSTDATA7","VPRJTPR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(1,$G(JSON("data","totalItems")))
D ASSERT("urn:va:med:93EF:-7:16982",$G(JSON("data","items",1,"uid")))
Q
FINDLIKE ;; @TEST finding using like()
N JSON,ERR,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/find/med?filter=like(""products[].ingredientName"",""ASPIRIN%25"")")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(1,$G(JSON("data","totalItems")))
D ASSERT("urn:va:med:93EF:-7:18068",$G(JSON("data","items",1,"uid")))
Q
ADDOBJ ;; @TEST adding object to store
N HTTPERR,VPRJPID,PTIME,TIME
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETPUT^VPRJTX("/vpr/"_VPRJTPID,"MED6","VPRJTP02")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D ASSERT("/vpr/"_VPRJPID_"/urn:va:med:93EF:-7:15231",HTTPREQ("location"))
D ASSERT(10,$D(^VPRPT(VPRJPID,VPRJTPID,"urn:va:med:93EF:-7:15231")))
D ASSERT(1,$D(^VPRPTI(VPRJPID,VPRJTPID,"attr","medication","79949668=","urn:va:med:93EF:-7:15231",1)))
Q
DELOBJ ;; @TEST remove object from store
N HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETDEL^VPRJTX("/vpr/uid/urn:va:med:93EF:-7:15231")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D ASSERT(0,$D(^VPRPT(VPRJPID,VPRJTPID,"urn:va:med:93EF:-7:15231")))
D ASSERT(0,$D(^VPRPTI(VPRJPID,VPRJTPID,"list","medication",20050331,"urn:va:med:93EF:-7:15231")))
Q
ADDPT ;; @TEST add new patient
N MYPID,JSON,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S TIME=$$CURRTIME^VPRJRUT
H 1
D SETPUT^VPRJTX("/vpr","DEMOG8","VPRJTP01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S MYPID="93EF;-8"
S VPRJPID=$$JPID4PID^VPRJPR(MYPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRPTJ("JPID",MYPID)))
D ASSERT("/vpr/"_MYPID_"/urn:va:patient:93EF:-8:-8",$G(HTTPREQ("location")))
; do it again, make sure we get the same PID
D SETPUT^VPRJTX("/vpr","DEMOG8","VPRJTP01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D ASSERT("/vpr/"_MYPID_"/urn:va:patient:93EF:-8:-8",$G(HTTPREQ("location")))
; now get the patient demographics
D SETGET^VPRJTX("/vpr/"_MYPID)
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(-88888888,$G(JSON("data","items",1,"ssn")))
D SETDEL^VPRJTX("/vpr/"_MYPID)
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(0,$D(^VPRPT(VPRJPID,MYPID)))
D ASSERT(0,$D(^VPRPTJ("JSON",VPRJPID,MYPID)))
D ASSERT(0,$D(^VPRPTI(VPRJPID,MYPID)))
D ASSERT(0,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")))
Q
NOICN ;; @TEST add patient without ICN
N HTTPERR,JSON,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S TIME=$$CURRTIME^VPRJRUT
H 1
D SETPUT^VPRJTX("/vpr","DEMOG9","VPRJTP01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S VPRJPID=$$JPID4PID^VPRJPR("93EF;-9")
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D ASSERT("/vpr/93EF;-9/urn:va:patient:93EF:-9:-9",HTTPREQ("location"))
; do it again for same pid
D SETPUT^VPRJTX("/vpr","DEMOG9","VPRJTP01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT("/vpr/93EF;-9/urn:va:patient:93EF:-9:-9",HTTPREQ("location"))
D ASSERT(1,$D(^VPRPT(VPRJPID,"93EF;-9"))>0)
; one more time for date of death
D SETPUT^VPRJTX("/vpr","DIED9","VPRJTP01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D ASSERT("/vpr/93EF;-9/urn:va:patient:93EF:-9:-9",HTTPREQ("location"))
D ASSERT(1,$D(^VPRPT(VPRJPID,"93EF;-9"))>0)
D SETGET^VPRJTX("/vpr/93EF;-9")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("666223456",$G(JSON("data","items",1,"ssn")))
D ASSERT("20120524",$G(JSON("data","items",1,"dateOfDeath")))
D ASSERT("93EF;-9",$G(JSON("data","items",1,"pid")))
D SETDEL^VPRJTX("/vpr/93EF;-9")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(0,$D(^VPRPT(VPRJPID,"93EF;-9")))
D ASSERT(0,$D(^VPRPTJ("JSON",VPRJPID,"93EF;-9")))
D ASSERT(0,$D(^VPRPTI(VPRJPID,"93EF;-9")))
D ASSERT(0,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")))
Q
ADDICN ;; @TEST add an ICN where the patient did not previously have one
N HTTPERR,JSON,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S TIME=$$CURRTIME^VPRJRUT
H 1
S ^VPRPTJ("JPID","93EF;-9")="52833885-af7c-4899-90be-b3a6630b2371"
S ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2371")=""
S ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2371","93EF;-9")=""
; store patient demographics
D SETPUT^VPRJTX("/vpr","DEMOG9","VPRJTP01",1)
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S VPRJPID=$$JPID4PID^VPRJPR("93EF;-9")
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D ASSERT("/vpr/93EF;-9/urn:va:patient:93EF:-9:-9",HTTPREQ("location"))
; Add ICN to patient
D SETPUT^VPRJTX("/vpr","NEWICN9","VPRJTP01",1)
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D ASSERT("/vpr/93EF;-9/urn:va:patient:93EF:-9:-9",HTTPREQ("location"))
D ASSERT(1,$D(^VPRPT(VPRJPID,"93EF;-9"))>0)
; Verify ICN is part of returned demographics
D SETGET^VPRJTX("/vpr/93EF;-9")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("666223456",$G(JSON("data","items",1,"ssn")))
D ASSERT("-999V123999",$G(JSON("data","items",1,"icn")))
D ASSERT("93EF;-9",$G(JSON("data","items",1,"pid")))
Q
NSITE ;; @TEST multiple sites for patient demographics
N HTTPREQ,HTTPERR,JSON,MYPID
D SETPUT^VPRJTX("/vpr/","D7BAD","VPRJTP01")
D RESPOND^VPRJRSP
D ASSERT(1,$G(HTTPERR)>0) ; should have bad ICN error
D ASSERT("",$G(HTTPREQ("location"))) ; location should be blank (not created)
D ASSERT(0,$D(^VPRPTJ("JPID","93CC;-7"))>1)
D ASSERT(0,$D(^VPRPTJ("JPID","-787V123787"))>1)
K HTTPREQ,HTTPERR
D SETPUT^VPRJTX("/vpr/"_VPRJTPID,"D7GOOD","VPRJTP01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
S MYPID=$P($G(HTTPREQ("location")),"/",3)
D ASSERT(1,$D(^VPRPTJ("JPID","-777V123777"))) ; Ensure forward node exists ICN
D ASSERT(MYPID,$G(^VPRPTJ("JPID","-777V123777"))) ; Ensure correct data for forward index ICN
D ASSERT(1,$D(^VPRPTJ("JPID","93EF;-7"))) ; Ensure forward node exists PID
D ASSERT(MYPID,$G(^VPRPTJ("JPID","93EF;-7"))) ; Ensure correct data for forward index PID
Q
FULLICN ;; @TEST get patient info using full ICN
N HTTPREQ,HTTPERR,JSON,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
D SETGET^VPRJTX("/vpr/-777V123777")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(2,$G(JSON("data","currentItemCount")))
D ASSERT("urn:va:patient:93EF:-7:-7",$G(JSON("data","items",2,"uid")))
D ASSERT(1,$D(^VPRPTJ("JPID","93EF;-7")))
D ASSERT(1,$D(^VPRPTJ("JPID","-777V123777")))
D ASSERT("urn:va:patient:93DD:-7:-7",$G(JSON("data","items",1,"uid")))
D ASSERT(1,$D(^VPRPTJ("JPID","93DD;-7")))
D ASSERT(1,$D(^VPRPTJ("JPID","-777V123777")))
Q
NUMFAC ;; @TEST fully numeric facility id
N MYPID,JSON,HTTPERR,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S TIME=$$CURRTIME^VPRJRUT
H 1
D SETPUT^VPRJTX("/vpr","NUMFAC","VPRJTP01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S MYPID="4321;-1"
D ASSERT("/vpr/"_MYPID_"/urn:va:patient:4321:-1:-1",HTTPREQ("location"))
S VPRJPID=$$JPID4PID^VPRJPR(MYPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
; do it again, make sure we get the same PID
D SETPUT^VPRJTX("/vpr","NUMFAC","VPRJTP01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
D ASSERT("/vpr/"_MYPID_"/urn:va:patient:4321:-1:-1",HTTPREQ("location"))
; now get the patient demographics
D SETGET^VPRJTX("/vpr/"_MYPID)
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(-111111111,$G(JSON("data","items",1,"ssn")))
D ASSERT("4321;-1",$G(JSON("data","items",1,"pid")))
D SETDEL^VPRJTX("/vpr/"_MYPID)
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(0,$D(^VPRPT(VPRJPID,MYPID)))
D ASSERT(0,$D(^VPRPTJ("JSON",VPRJPID,MYPID)))
D ASSERT(0,$D(^VPRPTI(VPRJPID,MYPID)))
D ASSERT(0,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")))
Q
DELCLTN ;; @TEST delete collection via REST
N HTTPERR,X,PTIME,TIME,VPRJPID
; The hang commands are necessary to ensure subsequent accesses on the lastAccessTime node don't happen within the same second
S VPRJPID=$$JPID4PID^VPRJPR(VPRJTPID)
D ASSERT(1,$G(VPRJPID)'="","JPID doesn't exist for this patient")
I $G(VPRJPID)="" QUIT
D ASSERT(1,$D(^VPRMETA("JPID",VPRJPID,"lastAccessTime")),"lastAccessTime doesn't exist for this patient")
S TIME=^VPRMETA("JPID",VPRJPID,"lastAccessTime")
H 1
S X=$O(^VPRPT(VPRJPID,VPRJTPID,"urn:va:med:")) D ASSERT(1,+(X["med"))
D SETDEL^VPRJTX("/vpr/"_VPRJTPID_"/collection/med")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
S PTIME=TIME
H 1
S TIME=$G(^VPRMETA("JPID",VPRJPID,"lastAccessTime"))
D ASSERT(1,TIME>PTIME)
S X=$O(^VPRPT(VPRJPID,VPRJTPID,"urn:va:med:")) D ASSERT(0,+(X["med"))
Q
DELSITE ;; @TEST REST endpoint to delete a site's patient data
N HTTPERR,PID1,PID2,JPID1,JPID2
S PID1="93EF;-7"
S PID2="93DD;-7"
S JPID=$$JPID4PID^VPRJPR(PID1)
D SETPUT^VPRJTX("/vpr","DEMOG7","VPRJTP01")
; Kill non-primary sites to test lastAccessTime
K ^VPRPTJ("JPID","1HDR;-7")
K ^VPRPTJ("JPID","1HDR;-777V123777")
K ^VPRPTJ("JPID","HDR1;-777V123777")
K ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2369","1HDR;-7")
K ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2369","1HDR;-777V123777")
K ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2369","HDR1;-777V123777")
D ASSERT(10,$D(^VPRPT(JPID,PID1)))
D ASSERT(10,$D(^VPRPTJ("JSON",JPID,PID1)))
D ASSERT(10,$D(^VPRPTJ("TEMPLATE",JPID,PID1)))
D ASSERT(1,^VPRPTI(JPID,PID1,"tally","collection","patient"))
D ASSERT(10,$D(^VPRPT(JPID,PID2)))
D ASSERT(10,$D(^VPRPTJ("JSON",JPID,PID2)))
D ASSERT(10,$D(^VPRPTJ("TEMPLATE",JPID,PID2)))
D ASSERT(1,^VPRPTI(JPID,PID2,"tally","collection","patient"))
D SETDEL^VPRJTX("/vpr/site/93EF")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(0,$D(^VPRPT(JPID,PID1)))
D ASSERT(0,$D(^VPRPTJ("JSON",JPID,PID1)))
D ASSERT(0,$D(^VPRPTJ("TEMPLATE",JPID,PID1)))
D ASSERT(0,^VPRPTI(JPID,PID1,"tally","collection","patient"))
D ASSERT(10,$D(^VPRPT(JPID,PID2)))
D ASSERT(10,$D(^VPRPTJ("JSON",JPID,PID2)))
D ASSERT(10,$D(^VPRPTJ("TEMPLATE",JPID,PID2)))
D ASSERT(10,$D(^VPRPTI(JPID,PID2)))
D ASSERT(1,$D(^VPRMETA("JPID",JPID,"lastAccessTime")))
D SETDEL^VPRJTX("/vpr/site/93DD")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(0,$D(^VPRPT(JPID,PID1)))
D ASSERT(0,$D(^VPRPTJ("JSON",JPID,PID1)))
D ASSERT(0,$D(^VPRPTJ("TEMPLATE",JPID,PID1)))
D ASSERT(0,$D(^VPRPT(JPID,PID2)))
D ASSERT(0,$D(^VPRPTJ("JSON",JPID,PID2)))
D ASSERT(0,$D(^VPRPTJ("TEMPLATE",JPID,PID2)))
D ASSERT(0,$D(^VPRMETA("JPID",JPID,"lastAccessTime")))
Q
GETDMOG1 ;; @TEST try to get demographics when none on file ICN
; Ensure requried variables are clean
N HTTPERR
K ^TMP("HTTPERR",$J)
; Setup Patient Asssociations
S ^VPRPTJ("JPID","8765;-1")="52833885-af7c-4899-90be-b3a6630b2373"
S ^VPRPTJ("JPID","-222V123222")="52833885-af7c-4899-90be-b3a6630b2373"
S ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2373")=""
S ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2373","8765;-1")=""
S ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2373","-222V123222")=""
; Try to get demographics for ICN
D SETGET^VPRJTX("vpr/mpid/-222V123222")
D RESPOND^VPRJRSP
D ASSERT(HTTPERR,400,"HTTPERR isn't set and should be")
D ASSERT($G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),225,"Incorrect error reason passed to client")
Q
GETDMOG2 ;; @TEST try to get demographics when none on file PID
; Ensure requried variables are clean
N HTTPERR
K ^TMP("HTTPERR",$J)
; Setup Patient Asssociations
S ^VPRPTJ("JPID","8765;-1")="52833885-af7c-4899-90be-b3a6630b2373"
S ^VPRPTJ("JPID","-222V123222")="52833885-af7c-4899-90be-b3a6630b2373"
S ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2373")=""
S ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2373","8765;-1")=""
S ^VPRPTJ("JPID","52833885-af7c-4899-90be-b3a6630b2373","-222V123222")=""
; Try to get demographics for PID
D SETGET^VPRJTX("vpr/mpid/8765;-1")
D RESPOND^VPRJRSP
D ASSERT(HTTPERR,400,"HTTPERR isn't set and should be")
D ASSERT($G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),225,"Incorrect error reason passed to client")
Q