source: Scheduling/trunk/m/BSDX07.m@ 989

Last change on this file since 989 was 988, checked in by Sam Habiel, 14 years ago

Support for restartable transactions for BSDX07

File size: 9.5 KB
Line 
1BSDX07 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 10/4/10 6:22pm
2 ;;1.42;BSDX;;Sep 29, 2010
3 ;
4 ; Change Log:
5 ; UJO/SMH
6 ; v1.3 July 13 2010 - Add support i18n - Dates input as FM dates, not US.
7 ; v1.42 Oct 22 2010 - Transaction now restartable by providing arguments
8 ; thanks to Rick Marshall and Zach Gonzalez at Oroville.
9 ;
10 ;
11APPADDD(BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID) ;EP
12 ;Entry point for debugging
13 D DEBUG^%Serenji("APPADD^BSDX07(.BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID)")
14 Q
15 ;
16APPADD(BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID) ;EP
17 ;Called by BSDX ADD NEW APPOINTMENT
18 ;Add new appointment
19 ;BSDXRES is ResourceName
20 ;BSDXLEN is the appointment duration in minutes
21 ;BSDXATID is used for 2 purposes:
22 ; if BSDXATID = "WALKIN" then BSDAPI is called to create a walkin appt.
23 ; if BSDXATID = a number, then it is the access type id (used for rebooking)
24 ;
25 ;Create entry in BSDX APPOINTMENT
26 ;Returns recordset having fields
27 ; AppointmentID and ErrorNumber
28 ;
29 ;Test lines:
30 ;BSDX ADD NEW APPOINTMENT^3091122.0930^3091122.1000^370^2^PEDIATRICIAN,DEMO^EXAM^SCRATCH NOTE
31 ;
32 ;Lock BSDX node
33 L +^BSDXAPPT(BSDXPATID):5 I '$T D ERR(BSDXI+1,"Another user is working with this patient's record. Please try again later") Q
34 ;
35 ;Restartable Transaction; restore paramters when starting.
36 TSTART (BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID):T="BSDX ADD NEW APPOINTMENT^BSDX07"
37 ;
38 N BSDXERR,BSDXIEN,BSDXDEP,BSDXI,BSDXJ,BSDXAPPTI,BSDXDJ,BSDXRESD,BSDXRNOD,BSDXSCD,BSDXC,BSDXERR,BSDXWKIN
39 N BSDXNOEV
40 S BSDXNOEV=1 ;Don't execute BSDX ADD APPOINTMENT protocol
41 K ^BSDXTMP($J)
42 S X="ETRAP^BSDX07",@^%ZOSF("TRAP")
43 S BSDXERR=0
44 S BSDXI=0
45 S BSDXY="^BSDXTMP("_$J_")"
46 S ^BSDXTMP($J,BSDXI)="I00020APPOINTMENTID^T00020ERRORID"_$C(30)
47 S BSDXI=BSDXI+1
48 ; v1.3 - date passed in as FM Date, not US date.
49 ;Check input data for errors
50 ; S:BSDXSTART["@0000" BSDXSTART=$P(BSDXSTART,"@")
51 ; S:BSDXEND["@0000" BSDXEND=$P(BSDXEND,"@")
52 ; S %DT="T",X=BSDXSTART D ^%DT S BSDXSTART=Y
53 ; I BSDXSTART=-1 D ERR(BSDXI+1,"BSDX07 Error: Invalid Start Time") Q
54 ; S %DT="T",X=BSDXEND D ^%DT S BSDXEND=Y
55 ; I BSDXEND=-1 D ERR(BSDXI+1,"BSDX07 Error: Invalid End Time") Q
56 ;
57 ; If C# sends the dates with extra zeros, remove them
58 S BSDXSTART=+BSDXSTART,BSDXEND=+BSDXEND
59 ;
60 I $L(BSDXEND,".")=1 D ERR(BSDXI+1,"BSDX07 Error: Invalid End Time") Q
61 I BSDXSTART>BSDXEND S BSDXTMP=BSDXEND,BSDXEND=BSDXSTART,BSDXSTART=BSDXTMP
62 I '+BSDXPATID,'$D(^DPT(BSDXPATID,0)) D ERR(BSDXI+1,"BSDX07 Error: Invalid Patient ID") Q
63 ;Validate Resource entry
64 S BSDXERR=0 K BSDXRESD
65 I '$D(^BSDXRES("B",BSDXRES)) D ERR(BSDXI+1,"BSDX07 Error: Invalid Resource ID") Q
66 S BSDXRESD=$O(^BSDXRES("B",BSDXRES,0))
67 S BSDXWKIN=0
68 I BSDXATID="WALKIN" S BSDXWKIN=1
69 I BSDXATID'?.N&(BSDXATID'="WALKIN") S BSDXATID=""
70 ;
71 S BSDXAPPTID=$$BSDXADD(BSDXSTART,BSDXEND,BSDXPATID,BSDXRESD,BSDXATID)
72 I 'BSDXAPPTID D ERR(BSDXI+1,"BSDX07 Error: Unable to add appointment to BSDX APPOINTMENT file.") Q
73 I BSDXNOTE]"" D BSDXWP(BSDXAPPTID,BSDXNOTE)
74 ;
75 ;Create RPMS Appointment
76 S BSDXRNOD=$G(^BSDXRES(BSDXRESD,0))
77 ;I BSDXRNOD="" D ERR(BSDXI+1,"BSDX07 Error: Unable to add appointment -- invalid Resource entry."),BSDXDEL(BSDXAPPTID) Q
78 I BSDXRNOD="" D ERR(BSDXI+1,"BSDX07 Error: Unable to add appointment -- invalid Resource entry.") Q
79 S BSDXSCD=$P(BSDXRNOD,U,4)
80 ;I +BSDXSCD,$D(^SC(BSDXSCD,0)) D I +BSDXERR D ERR(BSDXI+1,"BSDX07 Error: Unable to make appointment. MAKE^BSDAPI returned error code: "_BSDXERR),BSDXDEL(BSDXAPPTID) Q
81 I +BSDXSCD,$D(^SC(BSDXSCD,0)) D I +BSDXERR D ERR(BSDXI+1,"BSDX07 Error: Unable to make appointment. MAKE^BSDAPI returned error code: "_BSDXERR) Q
82 . S BSDXC("PAT")=BSDXPATID
83 . S BSDXC("CLN")=BSDXSCD
84 . S BSDXC("TYP")=3 ;3 for scheduled appts, 4 for walkins
85 . S:BSDXWKIN BSDXC("TYP")=4
86 . S BSDXC("ADT")=BSDXSTART
87 . S BSDXC("LEN")=BSDXLEN
88 . S BSDXC("OI")=$E($G(BSDXNOTE),1,150) ;File 44 has 150 character limit on OTHER field
89 . S BSDXC("OI")=$TR(BSDXC("OI"),";"," ") ;No semicolons allowed by MAKE^BSDAPI
90 . S BSDXC("OI")=$$STRIP(BSDXC("OI")) ;Strip control characters from note
91 . S BSDXC("USR")=DUZ
92 . S BSDXERR=$$MAKE^BSDXAPI(.BSDXC)
93 . Q:BSDXERR
94 . D AVUPDT(BSDXSCD,BSDXSTART,BSDXLEN)
95 . ;L
96 . Q
97 ;
98 ;Update RPMS Clinic availability
99 ;Return Recordset
100 TCOMMIT
101 L -^BSDXAPPT(BSDXPATID)
102 S BSDXI=BSDXI+1
103 S ^BSDXTMP($J,BSDXI)=BSDXAPPTID_"^"_$C(30)
104 S BSDXI=BSDXI+1
105 S ^BSDXTMP($J,BSDXI)=$C(31)
106 Q
107BSDXDEL(BSDXAPPTID) ;Deletes appointment BSDXAPPTID from BSDXAPPOINTMETN
108 N DA,DIK
109 S DIK="^BSDXAPPT(",DA=BSDXAPPTID
110 D ^DIK
111 Q
112 ;
113STRIP(BSDXZ) ;Replace control characters with spaces
114 N BSDXI
115 F BSDXI=1:1:$L(BSDXZ) I (32>$A($E(BSDXZ,BSDXI))) S BSDXZ=$E(BSDXZ,1,BSDXI-1)_" "_$E(BSDXZ,BSDXI+1,999)
116 Q BSDXZ
117 ;
118BSDXADD(BSDXSTART,BSDXEND,BSDXPATID,BSDXRESD,BSDXATID) ;ADD BSDX APPOINTMENT ENTRY
119 ;Returns ien in BSDXAPPT or 0 if failed
120 ;Create entry in BSDX APPOINTMENT
121 N BSDXAPPTID
122 S BSDXFDA(9002018.4,"+1,",.01)=BSDXSTART
123 S BSDXFDA(9002018.4,"+1,",.02)=BSDXEND
124 S BSDXFDA(9002018.4,"+1,",.05)=BSDXPATID
125 S BSDXFDA(9002018.4,"+1,",.07)=BSDXRESD
126 S BSDXFDA(9002018.4,"+1,",.08)=$G(DUZ)
127 ;S BSDXFDA(9002018.4,"+1,",.09)=$G(DT) ;MJL 1/25/2007
128 S BSDXFDA(9002018.4,"+1,",.09)=$$NOW^XLFDT
129 S:BSDXATID="WALKIN" BSDXFDA(9002018.4,"+1,",.13)="y"
130 S:BSDXATID?.N BSDXFDA(9002018.4,"+1,",.06)=BSDXATID
131 K BSDXIEN,BSDXMSG
132 D UPDATE^DIE("","BSDXFDA","BSDXIEN","BSDXMSG")
133 S BSDXAPPTID=+$G(BSDXIEN(1))
134 Q BSDXAPPTID
135 ;
136BSDXWP(BSDXAPPTID,BSDXNOTE) ;
137 ;Add WP field
138 I BSDXNOTE]"" S BSDXNOTE(.5)=BSDXNOTE,BSDXNOTE=""
139 I $D(BSDXNOTE(0)) S BSDXNOTE(.5)=BSDXNOTE(0) K BSDXNOTE(0)
140 I $D(BSDXNOTE(.5)) D
141 . D WP^DIE(9002018.4,BSDXAPPTID_",",1,"","BSDXNOTE","BSDXMSG")
142 Q
143 ;
144ADDEVT(BSDXPATID,BSDXSTART,BSDXSC,BSDXSCDA) ;EP
145 ;Called by BSDX ADD APPOINTMENT protocol
146 ;BSDXSC=IEN of clinic in ^SC
147 ;BSDXSCDA=IEN for ^SC(BSDXSC,"S",BSDXSTART,1,BSDXSCDA). Use to get Length & Note
148 ;
149 N BSDXNOD,BSDXLEN,BSDXAPPTID,BSDXNODP,BSDXWKIN,BSDXRES
150 Q:+$G(BSDXNOEV)
151 I $D(^BSDXRES("ALOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ALOC",BSDXSC,0))
152 E I $D(^BSDXRES("ASSOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ASSOC",BSDXSC,0))
153 Q:'+$G(BSDXRES)
154 S BSDXNOD=$G(^SC(BSDXSC,"S",BSDXSTART,1,BSDXSCDA,0))
155 Q:BSDXNOD=""
156 S BSDXNODP=$G(^DPT(BSDXPATID,"S",BSDXSTART,0))
157 S BSDXWKIN=""
158 S:$P(BSDXNODP,U,7)=4 BSDXWKIN="WALKIN" ;Purpose of Visit field of DPT Appointment subfile
159 S BSDXLEN=$P(BSDXNOD,U,2)
160 Q:'+BSDXLEN
161 S BSDXEND=$$FMADD^XLFDT(BSDXSTART,0,0,BSDXLEN,0)
162 S BSDXAPPTID=$$BSDXADD(BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXWKIN)
163 Q:'+BSDXAPPTID
164 S BSDXNOTE=$P(BSDXNOD,U,4)
165 I BSDXNOTE]"" D BSDXWP(BSDXAPPTID,BSDXNOTE)
166 D ADDEVT3(BSDXRES)
167 Q
168 ;
169ADDEVT3(BSDXRES) ;
170 ;Call RaiseEvent to notify GUI clients
171 N BSDXRESN
172 S BSDXRESN=$G(^BSDXRES(BSDXRES,0))
173 Q:BSDXRESN=""
174 S BSDXRESN=$P(BSDXRESN,"^")
175 ;D EVENT^BSDX23("SCHEDULE-"_BSDXRESN,"","","")
176 D EVENT^BMXMEVN("BSDX SCHEDULE",BSDXRESN)
177 Q
178 ;
179ERR(BSDXI,BSDXERR) ;Error processing
180 D ^%ZTER ;XXX: remove after we figure out the cause of error
181 S BSDXI=BSDXI+1
182 S BSDXERR=$TR(BSDXERR,"^","~")
183 TROLLBACK
184 S ^BSDXTMP($J,BSDXI)="0^"_BSDXERR_$C(30)
185 S BSDXI=BSDXI+1
186 S ^BSDXTMP($J,BSDXI)=$C(31)
187 L
188 Q
189 ;
190ETRAP ;EP Error trap entry
191 D ^%ZTER
192 I '$D(BSDXI) N BSDXI S BSDXI=999999
193 S BSDXI=BSDXI+1
194 D ERR(BSDXI,"BSDX07 Error: "_$G(%ZTERROR))
195 Q
196 ;
197DAY ;;^SUN^MON^TUES^WEDNES^THURS^FRI^SATUR
198 ;
199DOW S %=$E(X,1,3),Y=$E(X,4,5),Y=Y>2&'(%#4)+$E("144025036146",Y)
200 F %=%:-1:281 S Y=%#4=1+1+Y
201 S Y=$E(X,6,7)+Y#7
202 Q
203 ;
204AVUPDT(BSDXSCD,BSDXSTART,BSDXLEN) ;Update RPMS Clinic availability
205 ;SEE SDM1
206 N Y,DFN
207 N SL,STARTDAY,X,SC,SB,HSI,SI,STR,SDDIF,SDMAX,SDDATE,SDDMAX,SDSDATE,CCXN,MXOK,COV,SDPROG
208 N X1,SDEDT,X2,SD,SM,SS,S,SDLOCK,ST,I
209 S Y=BSDXSCD,DFN=BSDXPATID
210 S SL=$G(^SC(+Y,"SL")),X=$P(SL,U,3),STARTDAY=$S($L(X):X,1:8),SC=Y,SB=STARTDAY-1/100,X=$P(SL,U,6),HSI=$S(X=1:X,X:X,1:4),SI=$S(X="":4,X<3:4,X:X,1:4),STR="#@!$* XXWVUTSRQPONMLKJIHGFEDCBA0123456789jklmnopqrstuvwxyz",SDDIF=$S(HSI<3:8/HSI,1:2) K Y
211 ;Determine maximum days for scheduling
212 S SDMAX(1)=$P($G(^SC(+SC,"SDP")),U,2) S:'SDMAX(1) SDMAX(1)=365
213 S (SDMAX,SDDMAX)=$$FMADD^XLFDT(DT,SDMAX(1))
214 S SDDATE=BSDXSTART
215 S SDSDATE=SDDATE,SDDATE=SDDATE\1
2161 ;L Q:$D(SDXXX) S CCXN=0 K MXOK,COV,SDPROT Q:DFN<0 S SC=+SC
217 Q:$D(SDXXX) S CCXN=0 K MXOK,COV,SDPROT Q:DFN<0 S SC=+SC
218 S X1=DT,SDEDT=365 S:$D(^SC(SC,"SDP")) SDEDT=$P(^SC(SC,"SDP"),"^",2)
219 S X2=SDEDT D C^%DTC S SDEDT=X
220 S Y=BSDXSTART
221EN1 S (X,SD)=Y,SM=0 D DOW
222S I '$D(^SC(SC,"ST",$P(SD,"."),1)) S SS=+$O(^SC(+SC,"T"_Y,SD)) Q:SS'>0 Q:^(SS,1)="" S ^SC(+SC,"ST",$P(SD,"."),1)=$E($P($T(DAY),U,Y+2),1,2)_" "_$E(SD,6,7)_$J("",SI+SI-6)_^(1),^(0)=$P(SD,".")
223 S S=BSDXLEN
224 ;Check if BSDXLEN evenly divisible by appointment length
225 S RPMSL=$P(SL,U)
226 I BSDXLEN<RPMSL S BSDXLEN=RPMSL
227 I BSDXLEN#RPMSL'=0 D
228 . S BSDXINC=BSDXLEN\RPMSL
229 . S BSDXINC=BSDXINC+1
230 . S BSDXLEN=RPMSL*BSDXINC
231 S SL=S_U_$P(SL,U,2,99)
232SC S SDLOCK=$S('$D(SDLOCK):1,1:SDLOCK+1) Q:SDLOCK>9
233 L +^SC(SC,"ST",$P(SD,"."),1):5 G:'$T SC
234 S SDLOCK=0,S=^SC(SC,"ST",$P(SD,"."),1)
235 S I=SD#1-SB*100,ST=I#1*SI\.6+($P(I,".")*SI),SS=SL*HSI/60*SDDIF+ST+ST
236 I (I<1!'$F(S,"["))&(S'["CAN") L -^SC(SC,"ST",$P(SD,"."),1) Q
237 I SM<7 S %=$F(S,"[",SS-1) S:'%!($P(SL,"^",6)<3) %=999 I $F(S,"]",SS)'<%!(SDDIF=2&$E(S,ST+ST+1,SS-1)["[") S SM=7
238 ;
239SP I ST+ST>$L(S),$L(S)<80 S S=S_" " G SP
240 S SDNOT=1
241 S ABORT=0
242 F I=ST+ST:SDDIF:SS-SDDIF D Q:ABORT
243 . S ST=$E(S,I+1) S:ST="" ST=" "
244 . S Y=$E(STR,$F(STR,ST)-2)
245 . I S["CAN"!(ST="X"&($D(^SC(+SC,"ST",$P(SD,"."),"CAN")))) S ABORT=1 Q
246 . I Y="" S ABORT=1 Q
247 . S:Y'?1NL&(SM<6) SM=6 S ST=$E(S,I+2,999) S:ST="" ST=" " S S=$E(S,1,I)_Y_ST
248 . Q
249 S ^SC(SC,"ST",$P(SD,"."),1)=S
250 L -^SC(SC,"ST",$P(SD,"."),1)
251 Q
Note: See TracBrowser for help on using the repository browser.