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