source: Scheduling/trunk/m/BSDXUT1.m@ 1460

Last change on this file since 1460 was 1460, checked in by Sam Habiel, 12 years ago

refactored BSDX26; still working on BSDX08

File size: 6.2 KB
Line 
1BSDXUT1 ; VEN/SMH - Unit Tests for Scheduling GUI - cont. ; 6/25/12 4:13pm
2 ;;1.7T1;BSDX;;Aug 31, 2011;Build 18
3 ;
4 ;
5UT29 ; Unit Test for BSDX29
6 ; HLs/Resources are created as part of the UT
7 ; Patients 1,2,3,4,5 must exist
8 ;
9 I '$$TM^%ZTLOAD() W "Cannot test. Taskman is not running!" QUIT
10 ;
11 ; Set-up - Create Clinics
12 N RESNAM S RESNAM="UTCLINIC"
13 N HLRESIENS ; holds output of UTCR^BSDXUT - HL IEN^Resource IEN
14 D
15 . N $ET S $ET="D ^%ZTER B"
16 . S HLRESIENS=$$UTCR^BSDXUT(RESNAM)
17 . I HLRESIENS<0 S $EC=",U1," ; not supposed to happen - hard crash if so
18 ;
19 N HLIEN,RESIEN
20 S HLIEN=$P(HLRESIENS,U)
21 S RESIEN=$P(HLRESIENS,U,2)
22 ;
23 ; Turn off SDAM APPT PROTOCOL BSDX Entries
24 N BSDXNOEV
25 S BSDXNOEV=1 ;Don't execute BSDX ADD APPOINTMENT protocol
26 ;
27 ; Create a bunch of appointments in PIMS (25 actually)
28 N DFN
29 N BSDXAPPT,BSDXDATE
30 N BSDXI
31 F BSDXI=1:1:5 D
32 . N APPTTIME S APPTTIME=$$TIMEHL^BSDXUT(HLIEN) ; appt time
33 . F DFN=1,2,3,4,5 D
34 . . N % S %=$$MAKE1^BSDXAPI(DFN,HLIEN,3,APPTTIME,15,"Sam Test Appt"_DFN)
35 . . I % W "Error in $$MAKE1^BSDXAPI for TIME "_APPTTIME_" for DFN "_DFN,!,%,!
36 . . E S BSDXAPPT(DFN,APPTTIME)="",BSDXDATE(APPTTIME)=""
37 ;
38 ; Check that appointments are not in ^BSDXAPPT
39 N DFN,APPTTIME S (DFN,APPTTIME)=""
40 F S DFN=$O(BSDXAPPT(DFN)) Q:'DFN D
41 . F S APPTTIME=$O(BSDXAPPT(DFN,APPTTIME)) Q:'APPTTIME D
42 . . I $D(^BSDXAPPT("APAT",DFN,APPTTIME)) W "Appt for "_DFN_" @ "_APPTTIME_" present",!
43 ;
44 ; Now, copy those appointments using BSDX29 to ^BSDXAPPT
45 N FIRSTDATE S FIRSTDATE=$O(BSDXDATE(""))
46 N LASTDATE S LASTDATE=$O(BSDXDATE(""),-1)
47 N ZZZ ; garbage
48 D BSDXCP^BSDX29(.ZZZ,RESIEN,HLIEN,FIRSTDATE,LASTDATE)
49 I +^BSDXTMP($J,1)=0 W "Error... task not created",! QUIT
50 ;
51 W "Waiting for 5 seconds for it to finish",! HANG 5
52 N DFN,APPTTIME S (DFN,APPTTIME)=""
53 F S DFN=$O(BSDXAPPT(DFN)) Q:'DFN D
54 . F S APPTTIME=$O(BSDXAPPT(DFN,APPTTIME)) Q:'APPTTIME D
55 . . I '$D(^BSDXAPPT("APAT",DFN,APPTTIME)) W "Appt for "_DFN_" @ "_APPTTIME_" missing",!
56 ;
57 ; Do all of this again making sure that events execute.
58 K BSDXNOEV
59 ;
60 ; Create a bunch of appointments in PIMS (25 actually)
61 N DFN
62 N BSDXAPPT,BSDXDATE
63 N BSDXI
64 F BSDXI=1:1:5 D
65 . N APPTTIME S APPTTIME=$$TIMEHL^BSDXUT(HLIEN) ; appt time
66 . F DFN=1,2,3,4,5 D
67 . . N % S %=$$MAKE1^BSDXAPI(DFN,HLIEN,3,APPTTIME,15,"Sam Test Appt"_DFN)
68 . . I % W "Error in $$MAKE1^BSDXAPI for TIME "_APPTTIME_" for DFN "_DFN,!,%,!
69 . . E S BSDXAPPT(DFN,APPTTIME)="",BSDXDATE(APPTTIME)=""
70 ;
71 ; Check that appointments are in ^BSDXAPPT (different from last time)
72 N DFN,APPTTIME S (DFN,APPTTIME)=""
73 F S DFN=$O(BSDXAPPT(DFN)) Q:'DFN D
74 . F S APPTTIME=$O(BSDXAPPT(DFN,APPTTIME)) Q:'APPTTIME D
75 . . I '$D(^BSDXAPPT("APAT",DFN,APPTTIME)) W "Appt for "_DFN_" @ "_APPTTIME_" present",!
76 ;
77 ; Now, copy those appointments using BSDX29 to ^BSDXAPPT
78 N FIRSTDATE S FIRSTDATE=$O(BSDXDATE(""))
79 N LASTDATE S LASTDATE=$O(BSDXDATE(""),-1)
80 N ZZZ ; garbage
81 D BSDXCP^BSDX29(.ZZZ,RESIEN,HLIEN,FIRSTDATE,LASTDATE)
82 I +^BSDXTMP($J,1)=0 W "Error... task not created",! QUIT
83 ;
84 W "Waiting for 5 seconds for it to finish",! HANG 5
85 W ^BSDXTMP("BSDXCOPY",+^BSDXTMP($J,1)),!
86 W "Last line should say 0",!
87 QUIT
88 ;
89UT26 ; Unit Tests - BSDX26
90 ;
91 ; Test 1: Make sure this damn thing works
92 ; Set-up - Create Clinics
93 N RESNAM S RESNAM="UTCLINIC"
94 N HLRESIENS ; holds output of UTCR^BSDXUT - HL IEN^Resource IEN
95 D
96 . N $ET S $ET="D ^%ZTER B"
97 . S HLRESIENS=$$UTCR^BSDXUT(RESNAM)
98 . I HLRESIENS<0 S $EC=",U1," ; not supposed to happen - hard crash if so
99 ;
100 N HLIEN,RESIEN
101 S HLIEN=$P(HLRESIENS,U)
102 S RESIEN=$P(HLRESIENS,U,2)
103 ;
104 ; Get start and end times
105 N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
106 N APPTTIME S APPTTIME=$P(TIMES,U)
107 N ENDTIME S ENDTIME=$P(TIMES,U,2)
108 ;
109 ; Make appt
110 N ZZZ,DFN
111 S DFN=3
112 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
113 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
114 ;
115 ; Now edit the note - basic test
116 N %H S %H=$H
117 N NOTE S NOTE="New Note "_%H
118 D EDITAPT^BSDX26(.ZZZ,APPID,NOTE)
119 I ^BSDXAPPT(APPID,1,1,0)'=NOTE W "ERROR 1",!
120 I $P(^SC(HLIEN,"S",APPTTIME,1,1,0),U,4)'=NOTE W "Error in HL Section",!
121 ;
122 ; Test 2: Test Error -1
123 ; -1 --> ApptID not a number
124 N ZZZ
125 N NOTE S NOTE="Nothing important"
126 D EDITAPT^BSDX26(.ZZZ,"BLAHBLAH",NOTE)
127 I +^BSDXTMP($J,1)'=-1 W "ERROR IN -1",!
128 ;
129 ; Test 3: Test Error -2
130 ; -2 --> ApptID not in ^BSDXAPPT
131 D EDITAPT^BSDX26(.ZZZ,298734322,NOTE)
132 I +^BSDXTMP($J,1)'=-2 W "ERROR IN -2",!
133 ;
134 ; Test 4: M Error
135 N BSDXDIE S BSDXDIE=1
136 D EDITAPT^BSDX26(.ZZZ,188,NOTE)
137 I +^BSDXTMP($J,1)'=-100 W "ERROR IN -100",!
138 K BSDXDIE
139 ; Test 5: Trestart -- retired in v1.7
140 ;
141 ; Test 6: UTs for an unlinked resource (not linked to PIMS)
142 N RESNAM S RESNAM="UTCLINICUL" ; Unlinked Clinic
143 N RESIEN
144 D
145 . N $ET S $ET="D ^%ZTER B"
146 . S RESIEN=$$UTCRRES^BSDXUT(RESNAM)
147 . I RESIEN<0 S $EC=",U1," ; not supposed to happen - hard crash if so
148 ;
149 ; Get start and end times
150 N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
151 N APPTTIME S APPTTIME=$P(TIMES,U)
152 N ENDTIME S ENDTIME=$P(TIMES,U,2)
153 ;
154 N ZZZ,DFN
155 S DFN=3
156 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
157 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
158 ; Now edit the note - basic test
159 N %H S %H=$H
160 N NOTE S NOTE="New Note "_%H
161 D EDITAPT^BSDX26(.ZZZ,APPID,NOTE)
162 I ^BSDXAPPT(APPID,1,1,0)'=NOTE W "ERROR 2",!
163 ;
164 ; Test 7: Simulated failure in BSDXAPI
165 N RESNAM S RESNAM="UTCLINIC"
166 N HLRESIENS ; holds output of UTCR^BSDXUT - HL IEN^Resource IEN
167 D
168 . N $ET S $ET="D ^%ZTER B"
169 . S HLRESIENS=$$UTCR^BSDXUT(RESNAM)
170 . I HLRESIENS<0 S $EC=",U1," ; not supposed to happen - hard crash if so
171 ;
172 N HLIEN,RESIEN
173 S HLIEN=$P(HLRESIENS,U)
174 S RESIEN=$P(HLRESIENS,U,2)
175 ;
176 ; Get start and end times
177 N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
178 N APPTTIME S APPTTIME=$P(TIMES,U)
179 N ENDTIME S ENDTIME=$P(TIMES,U,2)
180 ;
181 ; Make appt
182 N ZZZ,DFN
183 S DFN=3
184 N ORIGNOTE S ORIGNOTE="Sam's Note"
185 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,ORIGNOTE,1)
186 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
187 ;
188 ; Create the error condition
189 N BSDXSIMERR1 S BSDXSIMERR1=1
190 ;
191 ; Try to edit the note. Should still be "Sam's Note"
192 N %H S %H=$H
193 N NOTE S NOTE="New Note "_%H
194 D EDITAPT^BSDX26(.ZZZ,APPID,NOTE)
195 I +^BSDXTMP($J,1)'=-4 W "Simulated error not triggered",!
196 I ^BSDXAPPT(APPID,1,1,0)'=ORIGNOTE ZWRITE ^(*) W "ERROR 3",!
197 I $P(^SC(HLIEN,"S",APPTTIME,1,1,0),U,4)'=ORIGNOTE W "ERROR 4",!
198 QUIT
Note: See TracBrowser for help on using the repository browser.