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

Last change on this file since 1568 was 1563, checked in by Tariq Hamkari, 12 years ago

updated the BSDX version to 1.7

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