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

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

New Routine BSDXGPRV to get providers associated with hospital location

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