source: Scheduling/trunk/m/BSDX08.m@ 1455

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

Refactored BSDX08 and BSDX29 routines; plus new UT routine BSDXUT1

File size: 9.6 KB
RevLine 
[1455]1BSDX08 ; VW/UJO/SMH - WINDOWS SCHEDULING RPCS ; 6/22/12 4:19pm
2 ;;1.7T1;BSDX;;Aug 31, 2011;Build 18
[1076]3 ;
4 ; Original by HMW. New Written by Sam Habiel. Licensed under LGPL.
5 ;
6 ; Change History
7 ; 3101022 UJO/SMH v1.42
8 ; - Transaction now restartable. Thanks to
9 ; --> Zach Gonzalez and Rick Marshall for fix.
10 ; - Extra TROLLBACK in Lock Statement when lock fails.
11 ; --> Removed--Rollback is already in ERR tag.
12 ; - Added new statements to old SD code in AVUPDT to obviate
13 ; --> need to restore variables in transaction
14 ; - Refactored this chunk of code. Don't really know whether it
15 ; --> worked in the first place. Waiting for bug report to know.
16 ; - Refactored all of APPDEL.
17 ;
[1080]18 ; 3111125 UJO/SMH v1.5
19 ; - Added ability to remove checked in appointments. Added a couple
20 ; of units tests for that under UT2.
21 ; - Minor reformatting because of how KIDS adds tabs.
22 ;
[1076]23 ; Error Reference:
24 ; -1~BSDX08: Appt record is locked. Please contact technical support.
25 ; -2~BSDX08: Invalid Appointment ID
[1007]26 ; -3~BSDX08: Invalid Appointment ID
[1076]27 ; -4~BSDX08: Cancelled appointment does not have a Resouce ID
28 ; -5~BSDX08: Resouce ID does not exist in BSDX RESOURCE
29 ; -6~BSDX08: Invalid Hosp Location stored in Database
30 ; -7~BSDX08: Patient does not have an appointment in PIMS Clinic
31 ; -8^BSDX08: Unable to find associated PIMS appointment for this patient
32 ; -9^BSDX08: BSDXAPI returned an error: (error)
33 ; -100~BSDX08 Error: (Mumps Error)
[614]34 ;
35APPDELD(BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT) ;EP
36 ;Entry point for debugging
[1452]37 ;D DEBUG^%Serenji("APPDEL^BSDX08(.BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT)")
[614]38 Q
39 ;
40APPDEL(BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT) ;EP
[1007]41 ;Called by RPC: BSDX CANCEL APPOINTMENT
42 ;Cancels existing appointment in BSDX APPOINTMENT and 44/2 subfiles
[1080]43 ;Input Parameters:
[1007]44 ; - BSDXAPTID is entry number in BSDX APPOINTMENT file
45 ; - BSDXTYP is C for clinic-cancelled and PC for patient cancelled
46 ; - BSDXCR is pointer to CANCELLATION REASON File (409.2)
47 ; - BSDXNOT is user note
[614]48 ;
[1080]49 ; Returns error code in recordset field ERRORID. Empty string is success.
50 ; Returns Global Array. Must use this type in RPC.
[614]51 ;
[1080]52 ; Return Array: set Return and clear array
[1007]53 S BSDXY=$NA(^BSDXTMP($J))
[1080]54 K ^BSDXTMP($J)
[1007]55 ;
[1080]56 ; Set min DUZ vars if they don't exist
57 D ^XBKVAR
[1007]58 ;
[1080]59 ; $ET
60 N $ET S $ET="G ETRAP^BSDX08"
61 ;
62 ; Counter
[1007]63 N BSDXI S BSDXI=0
[1454]64 ;
[1080]65 ; Header Node
[1041]66 S ^BSDXTMP($J,BSDXI)="T00100ERRORID"_$C(30)
[1007]67 ;
[1080]68 ; Lock BSDX node, only to synchronize access to the globals.
69 ; It's not expected that the error will ever happen as no filing
70 ; is supposed to take 5 seconds.
71 L +^BSDXAPPT(BSDXAPTID):5 I '$T D ERR(BSDXI,"-1~BSDX08: Appt record is locked. Please contact technical support.") Q
[1007]72 ;
[1080]73 ; Turn off SDAM APPT PROTOCOL BSDX Entries
[614]74 N BSDXNOEV
75 S BSDXNOEV=1 ;Don't execute BSDX CANCEL APPOINTMENT protocol
76 ;
[1080]77 ;;;test for error inside transaction. See if %ZTER works
[1454]78 I $G(BSDXDIE) S X=1/0
[1080]79 ;
80 ; Check appointment ID and whether it exists
81 I '+BSDXAPTID D ERR(BSDXI,"-2~BSDX08: Invalid Appointment ID") Q
[1007]82 I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR(BSDXI,"-3~BSDX08: Invalid Appointment ID") Q
[1455]83 ;
[1007]84 ; Start Processing:
[1455]85 ; First, get data
[1007]86 N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPTID,0) ; BSDX Appt Node
87 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; Patient ID
88 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Start Time
[614]89 ;
[1455]90 ; Check the resource ID and whether it exists
[1007]91 N BSDXSC1 S BSDXSC1=$P(BSDXNOD,U,7) ;RESOURCEID
[1080]92 ; If the resouce id doesn't exist...
[1007]93 I BSDXSC1="" D ERR(BSDXI,"-4~BSDX08: Cancelled appointment does not have a Resouce ID") QUIT
[1080]94 I '$D(^BSDXRES(BSDXSC1,0)) D ERR(BSDXI,"-5~BSDX08: Resouce ID does not exist in BSDX RESOURCE") QUIT
[1455]95 ;
96 ; Process PIMS issues first:
97 ; cancel appt in "S" nodes in file 2 and 44, then update Legacy PIMS Availability
[1007]98 ; Get zero node of resouce
[1455]99 N BSDXNOD S BSDXNOD=^BSDXRES(BSDXSC1,0)
[1080]100 ; Get Hosp location
[1007]101 N BSDXLOC S BSDXLOC=$P(BSDXNOD,U,4)
[1080]102 ; Error indicator for Hosp Location filing for getting out of routine
103 N BSDXERR S BSDXERR=0
[1455]104 ; For BSDXC
105 N BSDXC
[1080]106 ; Only file in 2/44 if there is an associated hospital location
[1454]107 I BSDXLOC D QUIT:BSDXERR
[1455]108 . S BSDXC("PAT")=BSDXPATID
109 . S BSDXC("CLN")=BSDXLOC
110 . S BSDXC("TYP")=BSDXTYP
111 . S BSDXC("ADT")=BSDXSTART
112 . S BSDXC("CDT")=$$NOW^XLFDT()
113 . S BSDXC("NOT")=BSDXNOT
114 . S:'+$G(BSDXCR) BSDXCR=11 ;Other
115 . S BSDXC("CR")=BSDXCR
116 . S BSDXC("USR")=DUZ
117 . ;
118 . S BSDXERR=$$CANCELCK^BSDXAPI(.BSDXC) ; 0 or 1^error message
119 . I BSDXERR D ERR(BSDXI,"-9^BSDX08: BSDXAPI returned an error: "_$P(BSDXERR,U,2)) QUIT
120 . ;
121 . N BSDXLEN S BSDXLEN=$$APPLEN^BSDXAPI(BSDXPATID,BSDXLOC,BSDXSTART)
122 . ; DEBUG
123 . I 'BSDXLEN S $EC=",U1,"
124 . ; DEBUG
[1007]125 . ; Cancel through BSDXAPI
[1455]126 . S BSDXERR=$$CANCEL^BSDXAPI(.BSDXC)
127 . I BSDXERR=1 D ERR(BSDXI,"-9^BSDX08: BSDXAPI returned an error: "_$P(BSDXZ,U,2)) QUIT
[1007]128 . ; Update Legacy PIMS clinic Availability
[614]129 . D AVUPDT(BSDXLOC,BSDXSTART,BSDXLEN)
130 ;
[1455]131 D BSDXCAN(BSDXAPTID) ; Add a cancellation date in BSDX APPOINTMENT
132 ;
[1007]133 L -^BSDXAPPT(BSDXAPTID)
[614]134 S BSDXI=BSDXI+1
135 S ^BSDXTMP($J,BSDXI)=""_$C(30)
136 S BSDXI=BSDXI+1
137 S ^BSDXTMP($J,BSDXI)=$C(31)
138 Q
139 ;
[1007]140AVUPDT(BSDXSCD,BSDXSTART,BSDXLEN) ;Update Legacy PIMS Clinic availability
[614]141 ;See SDCNP0
[1007]142 N SD,S ; Start Date
[1454]143 S (SD,S)=BSDXSTART
[1080]144 N I ; Clinic IEN in 44
[614]145 S I=BSDXSCD
[1080]146 ; if day has no schedule in legacy PIMS, forget about this update.
[614]147 Q:'$D(^SC(I,"ST",SD\1,1))
[1080]148 N SL ; Clinic characteristics node (length of appt, when appts start etc)
[1007]149 S SL=^SC(I,"SL")
[1080]150 N X ; Hour Clinic Display Begins
151 S X=$P(SL,U,3)
152 N STARTDAY ; When does the day start?
153 S STARTDAY=$S($L(X):X,1:8) ; If defined, use it; otherwise, 8am
154 N SB ; ?? Who knows? Day Start - 1 divided by 100.
155 S SB=STARTDAY-1/100
156 S X=$P(SL,U,6) ; Now X is Display increments per hour
157 N HSI ; Slots per hour, try 1
158 S HSI=$S(X:X,1:4) ; if defined, use it; otherwise, 4
159 N SI ; Slots per hour, try 2
160 S SI=$S(X="":4,X<3:4,X:X,1:4) ; If slots "", or less than 3, then 4
161 N STR ; ??
162 S STR="#@!$* XXWVUTSRQPONMLKJIHGFEDCBA0123456789jklmnopqrstuvwxyz"
163 N SDDIF ; Slots per hour diff??
164 S SDDIF=$S(HSI<3:8/HSI,1:2)
[1007]165 S SL=BSDXLEN ; Dammit, reusing variable; SL now Appt Length from GUI
166 S S=^SC(I,"ST",SD\1,1) ; reusing var again; S now Day Pattern from PIMS
[1080]167 N Y ; Hours since start of Date
168 S Y=SD#1-SB*100 ;SD#1=FM Time portion; -SB minus start of day; conv to hrs
169 N ST ; ??
170 ; Y#1 -> Minutes; *SI -> * Slots per hour; \.6 trunc min to hour
171 ; Y\1 -> Hours since start of day; * SI: * slots
[1454]172 S ST=Y#1*SI\.6+(Y\1*SI)
[1080]173 N SS ; how many slots are supposed to be taken by appointment
174 S SS=SL*HSI/60 ; (nb: try SL: 30 min; HSI: 4 slots)
[1007]175 N I
[1080]176 I Y'<1 D ; If Hours since start of Date is greater than 1
177 . ; loop through pattern. Tired of documenting.
178 . F I=ST+ST:SDDIF D Q:Y="" Q:SS'>0
[1454]179 . . S Y=$E(STR,$F(STR,$E(S,I+1))) Q:Y=""
[1080]180 . . S S=$E(S,1,I)_Y_$E(S,I+2,999)
[1454]181 . . S SS=SS-1
[1080]182 . . Q:SS'>0
[1007]183 S ^SC(BSDXSCD,"ST",SD\1,1)=S ; new pattern; global set
[614]184 Q
185 ;
186BSDXCAN(BSDXAPTID) ;
187 ;Cancel BSDX APPOINTMENT entry
188 N %DT,X,BSDXDATE,Y,BSDXIENS,BSDXFDA,BSDXMSG
189 S %DT="XT",X="NOW" D ^%DT ; X ^DD("DD")
190 S BSDXDATE=Y
191 S BSDXIENS=BSDXAPTID_","
192 S BSDXFDA(9002018.4,BSDXIENS,.12)=BSDXDATE
193 K BSDXMSG
194 D FILE^DIE("","BSDXFDA","BSDXMSG")
195 Q
196 ;
197CANEVT(BSDXPAT,BSDXSTART,BSDXSC) ;EP Called by BSDX CANCEL APPOINTMENT event
198 ;when appointments cancelled via PIMS interface.
199 ;Propagates cancellation to BSDXAPPT and raises refresh event to running GUI clients
200 N BSDXFOUND,BSDXRES
201 Q:+$G(BSDXNOEV)
202 Q:'+$G(BSDXSC)
203 S BSDXFOUND=0
204 I $D(^BSDXRES("ALOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ALOC",BSDXSC,0)) S BSDXFOUND=$$CANEVT1(BSDXRES,BSDXSTART,BSDXPAT)
205 I BSDXFOUND D CANEVT3(BSDXRES) Q
206 I $D(^BXDXRES("ASSOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ASSOC",BSDXSC,0)) S BSDXFOUND=$$CANEVT1(BSDXRES,BSDXSTART,BSDXPAT)
207 I BSDXFOUND D CANEVT3(BSDXRES)
208 Q
209 ;
210CANEVT1(BSDXRES,BSDXSTART,BSDXPAT) ;
211 ;Get appointment id in BSDXAPT
212 ;If found, call BSDXCAN(BSDXAPPT) and return 1
213 ;else return 0
214 N BSDXFOUND,BSDXAPPT
215 S BSDXFOUND=0
216 Q:'+BSDXRES BSDXFOUND
217 Q:'$D(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART)) BSDXFOUND
218 S BSDXAPPT=0 F S BSDXAPPT=$O(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART,BSDXAPPT)) Q:'+BSDXAPPT D Q:BSDXFOUND
[1455]219 . N BSDXNOD
[614]220 . S BSDXNOD=$G(^BSDXAPPT(BSDXAPPT,0)) Q:BSDXNOD=""
221 . I $P(BSDXNOD,U,5)=BSDXPAT,$P(BSDXNOD,U,12)="" S BSDXFOUND=1 Q
222 I BSDXFOUND,+$G(BSDXAPPT) D BSDXCAN(BSDXAPPT)
223 Q BSDXFOUND
224 ;
225CANEVT3(BSDXRES) ;
226 ;Call RaiseEvent to notify GUI clients
227 ;
228 N BSDXRESN
229 S BSDXRESN=$G(^BSDXRES(BSDXRES,0))
230 Q:BSDXRESN=""
231 S BSDXRESN=$P(BSDXRESN,"^")
232 ;D EVENT^BSDX23("SCHEDULE-"_BSDXRESN,"","","")
233 D EVENT^BMXMEVN("BSDX SCHEDULE",BSDXRESN)
234 Q
235 ;
236ERR(BSDXI,BSDXERR) ;Error processing
237 S BSDXI=BSDXI+1
238 S BSDXERR=$TR(BSDXERR,"^","~")
239 S ^BSDXTMP($J,BSDXI)=BSDXERR_$C(30)
240 S BSDXI=BSDXI+1
241 S ^BSDXTMP($J,BSDXI)=$C(31)
[1007]242 L -^BSDXAPPT(BSDXAPTID)
243 QUIT
[614]244 ;
245ETRAP ;EP Error trap entry
[1007]246 N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap
[1080]247 D ^%ZTER
248 S $EC="" ; Clear Error
[1007]249 ; Log error message and send to client
[1080]250 I '$D(BSDXI) N BSDXI S BSDXI=0
[1007]251 D ERR(BSDXI,"-100~BSDX08 Error: "_$G(%ZTERZE))
252 QUIT
[1080]253 ;
254 ;;;NB: This is code that is unused in both original and port.
255 ; ; If not appt in the "S" node is found in ^SC then check associated RPMS Clinic Multiple
256 ; I BSDXSCIEN="" D I 'BSDXZ Q ;Q:BSDXZ
[1007]257 ; . S BSDXERR="BSDX08: Unable to find associated RPMS appointment for this patient. "
258 ; . S BSDXZ=1
[1080]259 ; . ; Check if there are associated RPMS clinics. (not currently used) Does the multiple exist? No, then quit
[1007]260 ; . I '$D(^BSDXRES(BSDXSC1,20)) S BSDXZ=0 QUIT
[1080]261 ; . ; Loop through the multiple. Get Location and then the ^SC "S" node IEN.
[1007]262 ; . N BSDX1 S BSDX1=0
263 ; . F S BSDX1=$O(^BSDXRES(BSDXSC1,20,BSDX1)) Q:'+BSDX1 Q:BSDXZ=0 D
264 ; . . Q:'$D(^BSDXRES(BSDXSC1,20,BSDX1,0))
265 ; . . S BSDXLOC=$P(^BSDXRES(BSDXSC1,20,BSDX1,0),U)
[1080]266 ; . . S BSDXSCIEN=$$SCIEN^BSDXAPI(BSDXPATID,BSDXLOC,BSDXSTART) I +BSDXSCIEN S BSDXZ=0 Q
Note: See TracBrowser for help on using the repository browser.