source: Scheduling/trunk/m/BSDXUT.m@ 1463

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

Moved some unit tests around; Unit tests for BSDX25; minor refactoring for BSDX25

File size: 12.4 KB
Line 
1BSDXUT ; VEN/SMH - Unit Tests for Scheduling GUI ; 6/28/12 10:14am
2 ;;1.7T1;BSDX;;Aug 31, 2011;Build 18
3 ; Licensed under LGPL
4 ;
5 ; Change Log:
6 ; June 21 2012: Initial Version
7 ;
8UT07 ; Unit Tests for BSDX07 - Assumes you have Patients with DFNs 1,2,3,4,5
9 ; HLs/Resources are created as part of the UT
10 ; Set-up - Create Clinics
11 N RESNAM S RESNAM="UTCLINIC"
12 N HLRESIENS ; holds output of UTCR^BSDXUT - HL IEN^Resource IEN
13 D
14 . N $ET S $ET="D ^%ZTER B"
15 . S HLRESIENS=$$UTCR^BSDXUT(RESNAM)
16 . I HLRESIENS<0 S $EC=",U1," ; not supposed to happen - hard crash if so
17 ;
18 N HLIEN,RESIEN
19 S HLIEN=$P(HLRESIENS,U)
20 S RESIEN=$P(HLRESIENS,U,2)
21 ;
22 ; Get start and end times
23 N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
24 N APPTTIME S APPTTIME=$P(TIMES,U)
25 N ENDTIME S ENDTIME=$P(TIMES,U,2)
26 ;
27 N ZZZ,DFN
28 ; Test for normality:
29 S DFN=3
30 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
31 ; Does Appt exist?
32 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
33 I 'APPID W "Error Making Appt-1" QUIT
34 I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-2"
35 I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-3"
36 I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-4"
37 ;
38 ; Do it again for a different patient
39 S DFN=2
40 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
41 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
42 I 'APPID W "Error Making Appt-5" QUIT
43 I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-6"
44 I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-7"
45 I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-8"
46 ;
47 ; Again for a different patient (4)
48 S DFN=4
49 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
50 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
51 I 'APPID W "Error Making Appt-9" QUIT
52 I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-10"
53 I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-11"
54 I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-12"
55 ;
56 ; Delete appointment set for Patient 4 (made above)
57 N BSDX,DFN
58 S DFN=4
59 S BSDX("PAT")=DFN
60 S BSDX("CLN")=HLIEN
61 S BSDX("ADT")=APPTTIME
62 D ROLLBACK^BSDX07(APPID,.BSDX)
63 I +$G(^BSDXAPPT(APPID,0)) W "Error in deleting appointment-1",!
64 I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-2",!
65 I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-3",!
66 ;
67 ; Again for a different patient (5)
68 S DFN=5
69 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
70 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
71 I 'APPID W "Error Making Appt-13" QUIT
72 I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-14"
73 I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-15"
74 I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-16"
75 ; Now cancel that appointment
76 D APPDEL^BSDX08(.ZZZ,APPID,"PC",1,"Sam's Cancel Note")
77 ; Now make it again
78 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
79 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
80 I 'APPID W "Error Making Appt-17" QUIT
81 I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-18"
82 I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-19"
83 I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-20"
84 ;
85 ; Delete appointment set for Patient 1 (not made)... needs to not crash
86 D
87 . N $ET S $ET="D ^%ZTER S $EC="""" W ""Failure to del non-existent appt"",!"
88 . N BSDX
89 . S BSDX("PAT")=1
90 . S BSDX("CLN")=HLIEN
91 . S BSDX("ADT")=APPTTIME
92 . D ROLLBACK^BSDX07(APPID,.BSDX)
93 ;
94 ; Test for bad start date
95 D APPADD^BSDX07(.ZZZ,2100123,3100123.3,2,RESNAM,30,"Sam's Note",1)
96 I +$P(^BSDXTMP($J,1),U,2)'=-2 W "Error in -2",!
97 ; Test for bad end date
98 D APPADD^BSDX07(.ZZZ,3100123,2100123.3,2,RESNAM,30,"Sam's Note",1)
99 I +$P(^BSDXTMP($J,1),U,2)'=-3 W "Error in -3",!
100 ; Test for end date without time - obsolete
101 ; Test for mumps error
102 N BSDXDIE S BSDXDIE=1
103 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,1,RESNAM,30,"Sam's Note",1)
104 I +$P(^BSDXTMP($J,1),U,2)'=-100 W "Error in -100: M Error",!
105 K BSDXDIE
106 ; Test for TRESTART -- retired in v 1.7
107 ; Test for non-numeric patient
108 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,"CAT,DOG",RESNAM,30,"Sam's Note",1)
109 I +$P(^BSDXTMP($J,1),U,2)'=-5 W "Error in -5",!
110 ; Test for a non-existent patient
111 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,8989898989,RESNAM,30,"Sam's Note",1)
112 I +$P(^BSDXTMP($J,1),U,2)'=-6 W "Error in -6",!
113 ; Test for a non-existent resource name
114 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,3,"lkajsflkjsadf",30,"Sam's Note",1)
115 I +$P(^BSDXTMP($J,1),U,2)'=-7 W "Error in -7",!
116 ; Test for corrupted resource
117 ; Can't test for -8 since it requires DB corruption
118 ; Test for inability to add appointment to BSDX Appointment (-9)
119 ; Also requires something wrong in the DB
120 ; Test for inability to add appointment to 2,44
121 ; Test by creating a duplicate appointment
122 ; Get start and end times
123 N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
124 N APPTTIME S APPTTIME=$P(TIMES,U)
125 N ENDTIME S ENDTIME=$P(TIMES,U,2)
126 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
127 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
128 I +$P(^BSDXTMP($J,1),U,2)'=-10 W "Error in -10",!
129 ;
130 ; Test that ROLLBACK^BSDX07 occurs properly in various places
131 N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
132 N APPTTIME S APPTTIME=$P(TIMES,U)
133 N ENDTIME S ENDTIME=$P(TIMES,U,2)
134 S DFN=4
135 N BSDXSIMERR1 S BSDXSIMERR1=1
136 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
137 N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
138 I +APPID W "Error in deleting appointment-4",!
139 I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-5",!
140 I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-6",!
141 ;
142 K BSDXSIMERR1
143 N BSDXSIMERR2 S BSDXSIMERR2=1
144 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
145 N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
146 I +APPID W "Error in deleting appointment-7",!
147 I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-8",!
148 I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-9",!
149 ;
150 K BSDXSIMERR2
151 N BSDXSIMERR4 S BSDXSIMERR4=1
152 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
153 N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
154 I +APPID W "Error in deleting appointment-16",!
155 I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-17",!
156 I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-18",!
157 ;
158 K BSDXSIMERR4
159 N BSDXSIMERR5 S BSDXSIMERR5=1
160 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
161 N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
162 I +APPID W "Error in deleting appointment-19",!
163 I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-20",!
164 I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-21",!
165 ;
166 ; Okay now we do UTs for an unlinked resource (not linked to PIMS)
167 N RESNAM S RESNAM="UTCLINICUL" ; Unlinked Clinic
168 N RESIEN
169 D
170 . N $ET S $ET="D ^%ZTER B"
171 . S RESIEN=$$UTCRRES^BSDXUT(RESNAM)
172 . I RESIEN<0 S $EC=",U1," ; not supposed to happen - hard crash if so
173 ;
174 ; Get start and end times
175 N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
176 N APPTTIME S APPTTIME=$P(TIMES,U)
177 N ENDTIME S ENDTIME=$P(TIMES,U,2)
178 ;
179 N ZZZ,DFN
180 ; Test for normality:
181 S DFN=3
182 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
183 ; Does Appt exist?
184 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
185 I 'APPID W "Error Making Appt-101" QUIT
186 I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-102"
187 I $D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-103"
188 ;
189 ; Again for a different patient (4)
190 S DFN=4
191 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
192 N APPID S APPID=+$P(^BSDXTMP($J,1),U)
193 I 'APPID W "Error Making Appt-104" QUIT
194 I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-105"
195 I $D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-106"
196 ;
197 ; Delete appointment set for Patient 4 (made above)
198 N BSDX,DFN
199 S DFN=4
200 D ROLLBACK^BSDX07(APPID)
201 I +$G(^BSDXAPPT(APPID,0)) W "Error in deleting appointment-1",!
202 ;
203 ; Duplicate appointments... This is SUPPOSED to fail for now (v1.7)
204 N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
205 N APPTTIME S APPTTIME=$P(TIMES,U)
206 N ENDTIME S ENDTIME=$P(TIMES,U,2)
207 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
208 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
209 I +$P(^BSDXTMP($J,1),U,2)'=-10 W "Error in -10 in Unlinked Section (existing bug)",!
210 ;
211 ; Test that ROLLBACK^BSDX07 occurs properly in various places
212 N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
213 N APPTTIME S APPTTIME=$P(TIMES,U)
214 N ENDTIME S ENDTIME=$P(TIMES,U,2)
215 S DFN=4
216 N BSDXSIMERR1 S BSDXSIMERR1=1
217 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
218 N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
219 I +APPID W "Error in deleting appointment-101",!
220 ;
221 ; These are never triggered, so we should still have an appointment
222 K BSDXSIMERR1
223 N BSDXSIMERR2 S BSDXSIMERR2=1
224 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
225 N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
226 I '+APPID W "Error in deleting appointment-102",!
227 ;
228 K BSDXSIMERR2
229 N BSDXSIMERR4 S BSDXSIMERR4=1
230 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
231 N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
232 I '+APPID W "Error in deleting appointment-103",!
233 ;
234 K BSDXSIMERR4
235 N BSDXSIMERR5 S BSDXSIMERR5=1
236 D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
237 N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
238 I '+APPID W "Error in deleting appointment-104",!
239 QUIT
240 ;
241UTCR(RESNAM) ; $$ - Create Unit Test Clinic and Resource Pair ; Private
242 ; Input: Resource Name By Value
243 ; Output: -1^Error or HLIEN^RESIEN for Success (file 44 IEN^file 9002018.1 IEN)
244 ; DO NOT USE IN A PRODUCTION ENVIRONTMENT. INTENDED FOR TESTING ONLY
245 N HLIEN S HLIEN=$$UTCR44(RESNAM)
246 I +HLIEN=-1 QUIT HLIEN
247 ;
248 N RESIEN S RESIEN=$$UTCRRES(RESNAM,HLIEN)
249 I +RESIEN=-1 QUIT RESIEN
250 E QUIT HLIEN_U_RESIEN
251 ;
252UTCR44(HLNAME) ; $$ - Create Unit Test Clinic in File 44; Private ; TESTING ONLY CODE
253 ; Output: -1^Error or IEN for Success
254 ; Input: Hosp Location Name by Value
255 ; DO NOT USE IN A PRODUCTION ENVIRONTMENT. INTENDED FOR TESTING ONLY
256 ;
257 I $D(^SC("B",HLNAME)) Q $O(^(HLNAME,""))
258 ;
259 N SAM
260 S SAM(44,"?+1,",.01)=HLNAME ; Name
261 S SAM(44,"?+1,",2)="C" ; Type = Clinic
262 S SAM(44,"?+1,",2.1)=1 ; Type Extension (not used)
263 S SAM(44,"?+1,",3.5)=$O(^DG(40.8,0)) ; Division (not yet used)
264 S SAM(44,"?+1,",8)=295 ; Stop Code Number (not used)
265 S SAM(44,"?+1,",9)="M" ; Service (not used)
266 S SAM(44,"?+1,",1912)=15 ; Length of Appt (not used)
267 S SAM(44,"?+1,",1917)=4 ; Display increments per hour (not used)
268 S SAM(44,"?+1,",1918)=8 ; Overbooks/day max (not used)
269 S SAM(44,"?+1,",2000.5)=0 ; Require Action Profiles: Yes (not used)
270 S SAM(44,"?+1,",2001)=999 ; Allowable consecutive no-shows (not used)
271 S SAM(44,"?+1,",2002)=999 ; Max # days for Future Booking (not used)
272 S SAM(44,"?+1,",2005)=365 ; Max # days for Auto Rebook (not used)
273 S SAM(44,"?+1,",2502)="N" ; Non-Count Clinic (not used)
274 S SAM(44,"?+1,",2504)="Y" ; Clinic meets at this Facility? (not used)
275 S SAM(44,"?+1,",2507)=9 ; Appointment Type (not used)
276 ;
277 N BSDXERR,BSDXIEN
278 D UPDATE^DIE("",$NA(SAM),$NA(BSDXIEN),$NA(BSDXERR))
279 Q $S($D(BSDXERR):-1_U_BSDXERR("DIERR",1,"TEXT",1),1:BSDXIEN(1))
280 ;
281UTCRRES(NAME,HLIEN) ; $$ - Create Unit Test Resource in 9002018.1 (BSDX RESOURCE); Private
282 ; Input: Hospital Location IEN
283 ; Output: -1^Error or IEN for Success
284 ; DO NOT USE IN A PRODUCTION ENVIRONTMENT. INTENDED FOR TESTING ONLY
285 I $D(^BSDXRES("B",NAME)) Q $O(^(NAME,""))
286 S HLIEN=$G(HLIEN) ; If we don't send one in
287 N RES ; garbage variable
288 D RSRC^BSDX16(.RES,"|"_NAME_"||"_HLIEN)
289 N RTN S RTN=@$Q(^BSDXTMP($J,0)) ; return array next value
290 Q $S(RTN=0:-1_U_RTN,1:+RTN) ; 0 means an error has occurred; 1 means IEN returned
291 ;
292TIMES() ; $$ - Create a next available appointment time^ending time; Private
293 ; Output: appttime^endtime
294 N NOW S NOW=$$NOW^XLFDT() ; Now time
295 N LAST S LAST=$O(^BSDXAPPT("B"," "),-1) ; highest time in file
296 N TIME2USE S TIME2USE=$S(NOW>LAST:NOW,1:LAST) ; Which time to use?
297 S TIME2USE=$E(TIME2USE,1,12) ; Strip away seconds
298 N APPTIME S APPTIME=$$FMADD^XLFDT(TIME2USE,0,0,15,0) ; Add 15 min
299 N ENDTIME S ENDTIME=$$FMADD^XLFDT(APPTIME,0,0,15,0) ; Add 15 more min
300 Q APPTIME_U_ENDTIME ; quit with apptime^endtime
301 ;
302TIMEHL(HLIEN) ; $$ - Create a next available appointment time^ending time by HL; Private
303 ; Input: HLIEN
304 ; Output: Next available appointment time for the HLIEN
305 N LAST S LAST=$O(^SC(HLIEN,"S",""),-1)
306 Q $$FMADD^XLFDT(LAST,1,0,15,0) ; Add 1 day and 15 minutes
Note: See TracBrowser for help on using the repository browser.