| 1 | BSDX07 ; VW/UJO/SMH - WINDOWS SCHEDULING RPCS ; 6/20/12 3:28pm
|
|---|
| 2 | ;;1.7T1;BSDX;;Aug 31, 2011;Build 18
|
|---|
| 3 | ; Licensed under LGPL
|
|---|
| 4 | ;
|
|---|
| 5 | ; Change Log:
|
|---|
| 6 | ; UJO/SMH
|
|---|
| 7 | ; v1.3 July 13 2010 - Add support i18n - Dates input as FM dates, not US.
|
|---|
| 8 | ; v1.42 Oct 22 2010 - Transaction now restartable by providing arguments
|
|---|
| 9 | ; thanks to Rick Marshall and Zach Gonzalez at Oroville.
|
|---|
| 10 | ; v1.42 Oct 30 2010 - Extensive refactoring.
|
|---|
| 11 | ; v1.5 Mar 15 2011 - End time does not have to have time anymore.
|
|---|
| 12 | ; It could be midnight of the next day
|
|---|
| 13 | ; v1.6 Apr 11 2011 - Support for Scheduling Radiology Exams...
|
|---|
| 14 | ; v1.7 Jun 20 2012 - Refactoring to remove transactions - many changes
|
|---|
| 15 | ;
|
|---|
| 16 | ; Error Reference:
|
|---|
| 17 | ; -1: Patient Record is locked. This means something is wrong!!!!
|
|---|
| 18 | ; -2: Start Time is not a valid Fileman date
|
|---|
| 19 | ; -3: End Time is not a valid Fileman date
|
|---|
| 20 | ; v1.5:obsolete::-4: End Time does not have time inside of it.
|
|---|
| 21 | ; -5: BSDXPATID is not numeric
|
|---|
| 22 | ; -6: Patient Does not exist in ^DPT
|
|---|
| 23 | ; -7: Resource Name does not exist in B index of BSDX RESOURCE
|
|---|
| 24 | ; -8: Resouce doesn't exist in ^BSDXRES
|
|---|
| 25 | ; -9: Couldn't add appointment to BSDX APPOINTMENT
|
|---|
| 26 | ; -10: Couldn't add appointment to files 2 and/or 44
|
|---|
| 27 | ; -100: Mumps Error
|
|---|
| 28 | ;
|
|---|
| 29 | APPADDD(BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID) ;EP
|
|---|
| 30 | ;Entry point for debugging
|
|---|
| 31 | ; D DEBUG^%Serenji("APPADD^BSDX07(.BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID)")
|
|---|
| 32 | Q
|
|---|
| 33 | ;
|
|---|
| 34 | UT ; Unit Tests - Assumes you have Patients with DFNs 1,2 and 3
|
|---|
| 35 | ; Set-up - Create Clinics
|
|---|
| 36 | N RESNAM S RESNAM="UTCLINIC"
|
|---|
| 37 | N HLRESIENS ; holds output of UTCR^BSDX35 - HL IEN^Resource IEN
|
|---|
| 38 | D
|
|---|
| 39 | . N $ET S $ET="D ^%ZTER B"
|
|---|
| 40 | . S HLRESIENS=$$UTCR^BSDX35(RESNAM)
|
|---|
| 41 | . I HLRESIENS<0 S $EC=",U1," ; not supposed to happen - hard crash if so
|
|---|
| 42 | ;
|
|---|
| 43 | N HLIEN,RESIEN
|
|---|
| 44 | S HLIEN=$P(HLRESIENS,U)
|
|---|
| 45 | S RESIEN=$P(HLRESIENS,U,2)
|
|---|
| 46 | ;
|
|---|
| 47 | ; Get start and end times
|
|---|
| 48 | N TIMES S TIMES=$$TIMES^BSDX35 ; appt time^end time
|
|---|
| 49 | N APPTTIME S APPTTIME=$P(TIMES,U)
|
|---|
| 50 | N ENDTIME S ENDTIME=$P(TIMES,U,2)
|
|---|
| 51 | ;
|
|---|
| 52 | N ZZZ,DFN
|
|---|
| 53 | ; Test for normality:
|
|---|
| 54 | S DFN=3
|
|---|
| 55 | D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
|
|---|
| 56 | ; Does Appt exist?
|
|---|
| 57 | N APPID S APPID=+$P(^BSDXTMP($J,1),U)
|
|---|
| 58 | I 'APPID W "Error Making Appt-1" QUIT
|
|---|
| 59 | I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-2"
|
|---|
| 60 | I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-3"
|
|---|
| 61 | I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-4"
|
|---|
| 62 | ;
|
|---|
| 63 | ; Do it again for a different patient
|
|---|
| 64 | S DFN=2
|
|---|
| 65 | D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
|
|---|
| 66 | N APPID S APPID=+$P(^BSDXTMP($J,1),U)
|
|---|
| 67 | I 'APPID W "Error Making Appt-5" QUIT
|
|---|
| 68 | I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-6"
|
|---|
| 69 | I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-7"
|
|---|
| 70 | I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-8"
|
|---|
| 71 | ;
|
|---|
| 72 | ; Again for a different patient (4)
|
|---|
| 73 | S DFN=4
|
|---|
| 74 | D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
|
|---|
| 75 | N APPID S APPID=+$P(^BSDXTMP($J,1),U)
|
|---|
| 76 | I 'APPID W "Error Making Appt-9" QUIT
|
|---|
| 77 | I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-10"
|
|---|
| 78 | I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-11"
|
|---|
| 79 | I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-12"
|
|---|
| 80 | ;
|
|---|
| 81 | ; Delete appointment set for Patient 4 (made above)
|
|---|
| 82 | N BSDX,DFN
|
|---|
| 83 | S DFN=4
|
|---|
| 84 | S BSDX("PAT")=DFN
|
|---|
| 85 | S BSDX("CLN")=HLIEN
|
|---|
| 86 | S BSDX("ADT")=APPTTIME
|
|---|
| 87 | D ROLLBACK(APPID,.BSDX)
|
|---|
| 88 | I +$G(^BSDXAPPT(APPID,0)) W "Error in deleting appointment-1",!
|
|---|
| 89 | I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-2",!
|
|---|
| 90 | I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-3",!
|
|---|
| 91 | ;
|
|---|
| 92 | ; Again for a different patient (5)
|
|---|
| 93 | S DFN=5
|
|---|
| 94 | D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
|
|---|
| 95 | N APPID S APPID=+$P(^BSDXTMP($J,1),U)
|
|---|
| 96 | I 'APPID W "Error Making Appt-13" QUIT
|
|---|
| 97 | I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-14"
|
|---|
| 98 | I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-15"
|
|---|
| 99 | I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-16"
|
|---|
| 100 | ; Now cancel that appointment
|
|---|
| 101 | D APPDEL^BSDX08(.ZZZ,APPID,"PC",1,"Sam's Cancel Note")
|
|---|
| 102 | ; Now make it again
|
|---|
| 103 | D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
|
|---|
| 104 | N APPID S APPID=+$P(^BSDXTMP($J,1),U)
|
|---|
| 105 | I 'APPID W "Error Making Appt-17" QUIT
|
|---|
| 106 | I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-18"
|
|---|
| 107 | I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-19"
|
|---|
| 108 | I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-20"
|
|---|
| 109 | ;
|
|---|
| 110 | ; Delete appointment set for Patient 1 (not made)... needs to not crash
|
|---|
| 111 | D
|
|---|
| 112 | . N $ET S $ET="D ^%ZTER S $EC="""" W ""Failure to del non-existent appt"",!"
|
|---|
| 113 | . N BSDX
|
|---|
| 114 | . S BSDX("PAT")=1
|
|---|
| 115 | . S BSDX("CLN")=HLIEN
|
|---|
| 116 | . S BSDX("ADT")=APPTTIME
|
|---|
| 117 | . D ROLLBACK(APPID,.BSDX)
|
|---|
| 118 | ;
|
|---|
| 119 | ; Test for bad start date
|
|---|
| 120 | D APPADD(.ZZZ,2100123,3100123.3,2,RESNAM,30,"Sam's Note",1)
|
|---|
| 121 | I +$P(^BSDXTMP($J,1),U,2)'=-2 W "Error in -2",!
|
|---|
| 122 | ; Test for bad end date
|
|---|
| 123 | D APPADD(.ZZZ,3100123,2100123.3,2,RESNAM,30,"Sam's Note",1)
|
|---|
| 124 | I +$P(^BSDXTMP($J,1),U,2)'=-3 W "Error in -3",!
|
|---|
| 125 | ; Test for end date without time - obsolete
|
|---|
| 126 | ; D APPADD(.ZZZ,3100123.1,3100123,2,RESNAM,30,"Sam's Note",1)
|
|---|
| 127 | ; I +$P(^BSDXTMP($J,1),U,2)'=-4 W "Error in -4",!
|
|---|
| 128 | ; Test for mumps error
|
|---|
| 129 | S BSDXDIE=1
|
|---|
| 130 | D APPADD(.ZZZ,APPTTIME,ENDTIME,1,RESNAM,30,"Sam's Note",1)
|
|---|
| 131 | I +$P(^BSDXTMP($J,1),U,2)'=-100 W "Error in -100: M Error",!
|
|---|
| 132 | K BSDXDIE
|
|---|
| 133 | ; Test for TRESTART -- retired in v 1.7
|
|---|
| 134 | ; S BSDXRESTART=1
|
|---|
| 135 | ; D APPADD(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
|
|---|
| 136 | ; I +$P(^BSDXTMP($J,1),U,2)'=0&(+$P(^BSDXTMP($J,1),U,2)'=-10) W "Error in TRESTART",!
|
|---|
| 137 | ; K BSDXRESTART
|
|---|
| 138 | ; Test for non-numeric patient
|
|---|
| 139 | D APPADD(.ZZZ,APPTTIME,ENDTIME,"CAT,DOG",RESNAM,30,"Sam's Note",1)
|
|---|
| 140 | I +$P(^BSDXTMP($J,1),U,2)'=-5 W "Error in -5",!
|
|---|
| 141 | ; Test for a non-existent patient
|
|---|
| 142 | D APPADD(.ZZZ,APPTTIME,ENDTIME,8989898989,RESNAM,30,"Sam's Note",1)
|
|---|
| 143 | I +$P(^BSDXTMP($J,1),U,2)'=-6 W "Error in -6",!
|
|---|
| 144 | ; Test for a non-existent resource name
|
|---|
| 145 | D APPADD(.ZZZ,APPTTIME,ENDTIME,3,"lkajsflkjsadf",30,"Sam's Note",1)
|
|---|
| 146 | I +$P(^BSDXTMP($J,1),U,2)'=-7 W "Error in -7",!
|
|---|
| 147 | ; Test for corrupted resource
|
|---|
| 148 | ; Can't test for -8 since it requires DB corruption
|
|---|
| 149 | ; Test for inability to add appointment to BSDX Appointment (-9)
|
|---|
| 150 | ; Also requires something wrong in the DB
|
|---|
| 151 | ; Test for inability to add appointment to 2,44
|
|---|
| 152 | ; Test by creating a duplicate appointment
|
|---|
| 153 | ; Get start and end times
|
|---|
| 154 | N TIMES S TIMES=$$TIMES^BSDX35 ; appt time^end time
|
|---|
| 155 | N APPTTIME S APPTTIME=$P(TIMES,U)
|
|---|
| 156 | N ENDTIME S ENDTIME=$P(TIMES,U,2)
|
|---|
| 157 | D APPADD(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
|
|---|
| 158 | D APPADD(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
|
|---|
| 159 | I +$P(^BSDXTMP($J,1),U,2)'=-10 W "Error in -10",!
|
|---|
| 160 | ;
|
|---|
| 161 | ; Test that rollback occurs properly in various places
|
|---|
| 162 | N TIMES S TIMES=$$TIMES^BSDX35 ; appt time^end time
|
|---|
| 163 | N APPTTIME S APPTTIME=$P(TIMES,U)
|
|---|
| 164 | N ENDTIME S ENDTIME=$P(TIMES,U,2)
|
|---|
| 165 | S DFN=4
|
|---|
| 166 | N BSDXSIMERR1 S BSDXSIMERR1=1
|
|---|
| 167 | D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
|
|---|
| 168 | N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
|
|---|
| 169 | I +APPID W "Error in deleting appointment-4",!
|
|---|
| 170 | I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-5",!
|
|---|
| 171 | I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-6",!
|
|---|
| 172 | ;
|
|---|
| 173 | K BSDXSIMERR1
|
|---|
| 174 | N BSDXSIMERR2 S BSDXSIMERR2=1
|
|---|
| 175 | D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
|
|---|
| 176 | N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
|
|---|
| 177 | I +APPID W "Error in deleting appointment-7",!
|
|---|
| 178 | I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-8",!
|
|---|
| 179 | I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-9",!
|
|---|
| 180 | ;
|
|---|
| 181 | K BSDXSIMERR2
|
|---|
| 182 | N BSDXSIMERR4 S BSDXSIMERR4=1
|
|---|
| 183 | D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
|
|---|
| 184 | N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
|
|---|
| 185 | I +APPID W "Error in deleting appointment-16",!
|
|---|
| 186 | I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-17",!
|
|---|
| 187 | I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-18",!
|
|---|
| 188 | ;
|
|---|
| 189 | K BSDXSIMERR4
|
|---|
| 190 | N BSDXSIMERR5 S BSDXSIMERR5=1
|
|---|
| 191 | D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
|
|---|
| 192 | N APPID S APPID=$O(^BSDXAPPT("B",APPTTIME,""))
|
|---|
| 193 | I +APPID W "Error in deleting appointment-19",!
|
|---|
| 194 | I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-20",!
|
|---|
| 195 | I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-21",!
|
|---|
| 196 | QUIT
|
|---|
| 197 | ;
|
|---|
| 198 | APPADD(BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID,BSDXRADEXAM) ;EP
|
|---|
| 199 | ;
|
|---|
| 200 | ;Called by RPC: BSDX ADD NEW APPOINTMENT
|
|---|
| 201 | ;
|
|---|
| 202 | ;Add new appointment to 3 files
|
|---|
| 203 | ; - BSDX APPOINTMENT
|
|---|
| 204 | ; - Hosp Location Appointment SubSubfile if Resource is linked to clinic
|
|---|
| 205 | ; - Patient Appointment Subfile if Resource is linked to clinic
|
|---|
| 206 | ;
|
|---|
| 207 | ;Paramters:
|
|---|
| 208 | ;BSDXY: Global Return (RPC must be set to Global Array)
|
|---|
| 209 | ;BSDXSTART: FM Start Date
|
|---|
| 210 | ;BSDXEND: FM End Date
|
|---|
| 211 | ;BSDXPATID: Patient DFN
|
|---|
| 212 | ;BSDXRES is ResourceName in BSDX RESOURCE file (not IEN)
|
|---|
| 213 | ;BSDXLEN is the appointment duration in minutes
|
|---|
| 214 | ;BSDXNOTE is the Appiontment Note
|
|---|
| 215 | ;BSDXATID is used for 2 purposes:
|
|---|
| 216 | ; if BSDXATID = "WALKIN" then BSDAPI is called to create a walkin appt.
|
|---|
| 217 | ; if BSDXATID = a number, then it is the access type id (used for rebooking)
|
|---|
| 218 | ;BSDXRADEXAM is used to store the Radiology Exam to which this appointment is tied to (optional)
|
|---|
| 219 | ;
|
|---|
| 220 | ;Return:
|
|---|
| 221 | ; ADO.net Recordset having fields:
|
|---|
| 222 | ; AppointmentID and ErrorNumber
|
|---|
| 223 | ;
|
|---|
| 224 | ; NB: Specifying BSDXLEN and BSDXEND is redundant. For future programmers
|
|---|
| 225 | ; to sort out
|
|---|
| 226 | ;
|
|---|
| 227 | ;Test lines:
|
|---|
| 228 | ;BSDX ADD NEW APPOINTMENT^3091122.0930^3091122.1000^370^Dr Office^30^EXAM^WALKIN
|
|---|
| 229 | ;
|
|---|
| 230 | ; Deal with optional arguments
|
|---|
| 231 | S BSDXRADEXAM=$G(BSDXRADEXAM)
|
|---|
| 232 | ;
|
|---|
| 233 | ; Return Array; set Return and clear array
|
|---|
| 234 | S BSDXY=$NA(^BSDXTMP($J))
|
|---|
| 235 | K ^BSDXTMP($J)
|
|---|
| 236 | ;
|
|---|
| 237 | ; $ET
|
|---|
| 238 | N $ET S $ET="G ETRAP^BSDX07"
|
|---|
| 239 | ;
|
|---|
| 240 | ; Counter
|
|---|
| 241 | N BSDXI S BSDXI=0
|
|---|
| 242 | ;
|
|---|
| 243 | ; Lock BSDX node, only to synchronize access to the globals.
|
|---|
| 244 | ; It's not expected that the error will ever happen as no filing
|
|---|
| 245 | ; is supposed to take 5 seconds.
|
|---|
| 246 | L +^BSDXAPPT(BSDXPATID):5 I '$T D ERR(BSDXI,"-1~Patient record is locked. Please contact technical support.") Q
|
|---|
| 247 | ;
|
|---|
| 248 | ; Header Node
|
|---|
| 249 | S ^BSDXTMP($J,BSDXI)="I00020APPOINTMENTID^T00100ERRORID"_$C(30)
|
|---|
| 250 | ;
|
|---|
| 251 | ; Turn off SDAM APPT PROTOCOL BSDX Entries
|
|---|
| 252 | N BSDXNOEV
|
|---|
| 253 | S BSDXNOEV=1 ;Don't execute BSDX ADD APPOINTMENT protocol
|
|---|
| 254 | ;
|
|---|
| 255 | ; Set Error Message to be empty
|
|---|
| 256 | N BSDXERR S BSDXERR=0
|
|---|
| 257 | ;
|
|---|
| 258 | ;;;test for error inside transaction. See if %ZTER works
|
|---|
| 259 | I $G(BSDXDIE) S X=1/0
|
|---|
| 260 | ;;;test
|
|---|
| 261 | ;
|
|---|
| 262 | ; -- Start and End Date Processing --
|
|---|
| 263 | ; If C# sends the dates with extra zeros, remove them
|
|---|
| 264 | S BSDXSTART=+BSDXSTART,BSDXEND=+BSDXEND
|
|---|
| 265 | ; Are the dates valid? Must be FM Dates > than 2010
|
|---|
| 266 | I BSDXSTART'>3100000 D ERR(BSDXI,"-2~BSDX07 Error: Invalid Start Time") Q
|
|---|
| 267 | I BSDXEND'>3100000 D ERR(BSDXI,"-3~BSDX07 Error: Invalid End Time") Q
|
|---|
| 268 | ;
|
|---|
| 269 | ;; If Ending date doesn't have a time, this is an error --rm 1.5
|
|---|
| 270 | ; I $L(BSDXEND,".")=1 D ERR(BSDXI,"-4~BSDX07 Error: Invalid End Time") Q
|
|---|
| 271 | ;
|
|---|
| 272 | ; If the Start Date is greater than the end date, swap dates
|
|---|
| 273 | N BSDXTMP
|
|---|
| 274 | I BSDXSTART>BSDXEND S BSDXTMP=BSDXEND,BSDXEND=BSDXSTART,BSDXSTART=BSDXTMP
|
|---|
| 275 | ;
|
|---|
| 276 | ; Check if the patient exists:
|
|---|
| 277 | ; - DFN valid number?
|
|---|
| 278 | ; - Valid Patient in file 2?
|
|---|
| 279 | I '+BSDXPATID D ERR(BSDXI,"-5~BSDX07 Error: Invalid Patient ID") Q
|
|---|
| 280 | I '$D(^DPT(BSDXPATID,0)) D ERR(BSDXI,"-6~BSDX07 Error: Invalid Patient ID") Q
|
|---|
| 281 | ;
|
|---|
| 282 | ;Validate Resource entry
|
|---|
| 283 | I '$D(^BSDXRES("B",BSDXRES)) D ERR(BSDXI,"-7~BSDX07 Error: Invalid Resource ID") Q
|
|---|
| 284 | N BSDXRESD ; Resource IEN
|
|---|
| 285 | S BSDXRESD=$O(^BSDXRES("B",BSDXRES,0))
|
|---|
| 286 | N BSDXRNOD ; Resouce zero node
|
|---|
| 287 | S BSDXRNOD=$G(^BSDXRES(BSDXRESD,0))
|
|---|
| 288 | I BSDXRNOD="" D ERR(BSDXI,"-8~BSDX07 Error: invalid Resource entry.") Q
|
|---|
| 289 | ;
|
|---|
| 290 | ; Walk-in (Unscheduled) Appointment?
|
|---|
| 291 | N BSDXWKIN S BSDXWKIN=0
|
|---|
| 292 | I BSDXATID="WALKIN" S BSDXWKIN=1
|
|---|
| 293 | ; Reset Access Type ID if it doesn't say "WALKIN" and isn't a number
|
|---|
| 294 | I BSDXATID'?.N&(BSDXATID'="WALKIN") S BSDXATID=""
|
|---|
| 295 | ;
|
|---|
| 296 | ; Now, check if PIMS has any issues with us making the appt using MAKECK
|
|---|
| 297 | N BSDXSCD S BSDXSCD=$P(BSDXRNOD,U,4) ; Hosp Location IEN
|
|---|
| 298 | N BSDXERR ; Variable to hold value of $$MAKE and $$MAKECK
|
|---|
| 299 | N BSDXC ; Array to send to MAKE and MAKECK APIs
|
|---|
| 300 | ; Only if we have a valid Hosp Location
|
|---|
| 301 | I +BSDXSCD,$D(^SC(BSDXSCD,0)) D
|
|---|
| 302 | . S BSDXC("PAT")=BSDXPATID
|
|---|
| 303 | . S BSDXC("CLN")=BSDXSCD
|
|---|
| 304 | . S BSDXC("TYP")=3 ;3 for scheduled appts, 4 for walkins
|
|---|
| 305 | . S:BSDXWKIN BSDXC("TYP")=4
|
|---|
| 306 | . S BSDXC("ADT")=BSDXSTART
|
|---|
| 307 | . S BSDXC("LEN")=BSDXLEN
|
|---|
| 308 | . S BSDXC("OI")=$E($G(BSDXNOTE),1,150) ;File 44 has 150 character limit on OTHER field
|
|---|
| 309 | . S BSDXC("OI")=$TR(BSDXC("OI"),";"," ") ;No semicolons allowed by MAKE^BSDXAPI
|
|---|
| 310 | . S BSDXC("OI")=$$STRIP(BSDXC("OI")) ;Strip control characters from note
|
|---|
| 311 | . S BSDXC("USR")=DUZ
|
|---|
| 312 | . S BSDXERR=$$MAKECK^BSDXAPI(.BSDXC)
|
|---|
| 313 | I +BSDXERR D ERR(BSDXI,"-10~BSDX07 Error: MAKECK^BSDXAPI returned error code: "_BSDXERR) Q ; no need for roll back
|
|---|
| 314 | ;
|
|---|
| 315 | ; Done with all checks, let's make appointment in BSDX APPOINTMENT
|
|---|
| 316 | N BSDXAPPTID
|
|---|
| 317 | S BSDXAPPTID=$$BSDXADD(BSDXSTART,BSDXEND,BSDXPATID,BSDXRESD,BSDXATID,BSDXRADEXAM)
|
|---|
| 318 | I 'BSDXAPPTID D ERR(BSDXI,"-9~BSDX07 Error: Unable to add appointment to BSDX APPOINTMENT file.") Q ; no roll back needed! No appts made.
|
|---|
| 319 | I BSDXNOTE]"" D BSDXWP(BSDXAPPTID,BSDXNOTE) ; no error checks are made here
|
|---|
| 320 | ; I don't think it's important b/c users can detect right away if the WP
|
|---|
| 321 | ; filing fails.
|
|---|
| 322 | ;
|
|---|
| 323 | I $G(BSDXSIMERR1) D ERR(BSDXI,"-11~BSDX07 Error: Simulated Error"),ROLLBACK(BSDXAPPTID,.BSDXC) Q ; UT Line
|
|---|
| 324 | ;
|
|---|
| 325 | ; Only if we have a valid Hosp Loc can we make an appointment in 2/44
|
|---|
| 326 | ; Use BSDXC array from before.
|
|---|
| 327 | ; NB: $$MAKE itself calls $$MAKECK to check again for being okay.
|
|---|
| 328 | I +BSDXSCD,$D(^SC(BSDXSCD,0)) D I +BSDXERR D ERR(BSDXI,"-10~BSDX07 Error: MAKE^BSDXAPI returned error code: "_BSDXERR),ROLLBACK(BSDXAPPTID,.BSDXC) Q
|
|---|
| 329 | . S BSDXERR=$$MAKE^BSDXAPI(.BSDXC)
|
|---|
| 330 | . Q:BSDXERR
|
|---|
| 331 | . D AVUPDT(BSDXSCD,BSDXSTART,BSDXLEN) ; Update RPMS Clinic availability
|
|---|
| 332 | ;
|
|---|
| 333 | ;Return Recordset
|
|---|
| 334 | L -^BSDXAPPT(BSDXPATID)
|
|---|
| 335 | S BSDXI=BSDXI+1
|
|---|
| 336 | S ^BSDXTMP($J,BSDXI)=BSDXAPPTID_"^"_$C(30)
|
|---|
| 337 | S BSDXI=BSDXI+1
|
|---|
| 338 | S ^BSDXTMP($J,BSDXI)=$C(31)
|
|---|
| 339 | Q
|
|---|
| 340 | STRIP(BSDXZ) ;Replace control characters with spaces
|
|---|
| 341 | N BSDXI
|
|---|
| 342 | F BSDXI=1:1:$L(BSDXZ) I (32>$A($E(BSDXZ,BSDXI))) S BSDXZ=$E(BSDXZ,1,BSDXI-1)_" "_$E(BSDXZ,BSDXI+1,999)
|
|---|
| 343 | Q BSDXZ
|
|---|
| 344 | ;
|
|---|
| 345 | BSDXADD(BSDXSTART,BSDXEND,BSDXPATID,BSDXRESD,BSDXATID,BSDXRADEXAM) ;ADD BSDX APPOINTMENT ENTRY
|
|---|
| 346 | ;Returns ien in BSDXAPPT or 0 if failed
|
|---|
| 347 | ;Create entry in BSDX APPOINTMENT
|
|---|
| 348 | N BSDXAPPTID
|
|---|
| 349 | S BSDXFDA(9002018.4,"+1,",.01)=BSDXSTART
|
|---|
| 350 | S BSDXFDA(9002018.4,"+1,",.02)=BSDXEND
|
|---|
| 351 | S BSDXFDA(9002018.4,"+1,",.05)=BSDXPATID
|
|---|
| 352 | S BSDXFDA(9002018.4,"+1,",.07)=BSDXRESD
|
|---|
| 353 | S BSDXFDA(9002018.4,"+1,",.08)=$G(DUZ)
|
|---|
| 354 | S BSDXFDA(9002018.4,"+1,",.09)=$$NOW^XLFDT
|
|---|
| 355 | S:BSDXATID="WALKIN" BSDXFDA(9002018.4,"+1,",.13)="y"
|
|---|
| 356 | S:BSDXATID?.N BSDXFDA(9002018.4,"+1,",.06)=BSDXATID
|
|---|
| 357 | S BSDXFDA(9002018.4,"+1,",.14)=$G(BSDXRADEXAM)
|
|---|
| 358 | N BSDXIEN,BSDXMSG
|
|---|
| 359 | D UPDATE^DIE("","BSDXFDA","BSDXIEN","BSDXMSG")
|
|---|
| 360 | S BSDXAPPTID=+$G(BSDXIEN(1))
|
|---|
| 361 | Q BSDXAPPTID
|
|---|
| 362 | ;
|
|---|
| 363 | BSDXWP(BSDXAPPTID,BSDXNOTE) ;
|
|---|
| 364 | ;Add WP field
|
|---|
| 365 | N BSDXMSG
|
|---|
| 366 | I BSDXNOTE]"" S BSDXNOTE(.5)=BSDXNOTE,BSDXNOTE=""
|
|---|
| 367 | I $D(BSDXNOTE(0)) S BSDXNOTE(.5)=BSDXNOTE(0) K BSDXNOTE(0)
|
|---|
| 368 | I $D(BSDXNOTE(.5)) D
|
|---|
| 369 | . D WP^DIE(9002018.4,BSDXAPPTID_",",1,"","BSDXNOTE","BSDXMSG")
|
|---|
| 370 | Q
|
|---|
| 371 | ;
|
|---|
| 372 | ADDEVT(BSDXPATID,BSDXSTART,BSDXSC,BSDXSCDA) ;EP
|
|---|
| 373 | ;Called by BSDX ADD APPOINTMENT protocol
|
|---|
| 374 | ;BSDXSC=IEN of clinic in ^SC
|
|---|
| 375 | ;BSDXSCDA=IEN for ^SC(BSDXSC,"S",BSDXSTART,1,BSDXSCDA). Use to get Length & Note
|
|---|
| 376 | ;
|
|---|
| 377 | N BSDXNOD,BSDXLEN,BSDXAPPTID,BSDXNODP,BSDXWKIN,BSDXRES
|
|---|
| 378 | Q:+$G(BSDXNOEV)
|
|---|
| 379 | I $D(^BSDXRES("ALOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ALOC",BSDXSC,0))
|
|---|
| 380 | E I $D(^BSDXRES("ASSOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ASSOC",BSDXSC,0))
|
|---|
| 381 | Q:'+$G(BSDXRES)
|
|---|
| 382 | S BSDXNOD=$G(^SC(BSDXSC,"S",BSDXSTART,1,BSDXSCDA,0))
|
|---|
| 383 | Q:BSDXNOD=""
|
|---|
| 384 | S BSDXNODP=$G(^DPT(BSDXPATID,"S",BSDXSTART,0))
|
|---|
| 385 | S BSDXWKIN=""
|
|---|
| 386 | S:$P(BSDXNODP,U,7)=4 BSDXWKIN="WALKIN" ;Purpose of Visit field of DPT Appointment subfile
|
|---|
| 387 | S BSDXLEN=$P(BSDXNOD,U,2)
|
|---|
| 388 | Q:'+BSDXLEN
|
|---|
| 389 | S BSDXEND=$$FMADD^XLFDT(BSDXSTART,0,0,BSDXLEN,0)
|
|---|
| 390 | S BSDXAPPTID=$$BSDXADD(BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXWKIN)
|
|---|
| 391 | Q:'+BSDXAPPTID
|
|---|
| 392 | S BSDXNOTE=$P(BSDXNOD,U,4)
|
|---|
| 393 | I BSDXNOTE]"" D BSDXWP(BSDXAPPTID,BSDXNOTE)
|
|---|
| 394 | D ADDEVT3(BSDXRES)
|
|---|
| 395 | Q
|
|---|
| 396 | ;
|
|---|
| 397 | ADDEVT3(BSDXRES) ;
|
|---|
| 398 | ;Call RaiseEvent to notify GUI clients
|
|---|
| 399 | N BSDXRESN
|
|---|
| 400 | S BSDXRESN=$G(^BSDXRES(BSDXRES,0))
|
|---|
| 401 | Q:BSDXRESN=""
|
|---|
| 402 | S BSDXRESN=$P(BSDXRESN,"^")
|
|---|
| 403 | ;D EVENT^BSDX23("SCHEDULE-"_BSDXRESN,"","","")
|
|---|
| 404 | D EVENT^BMXMEVN("BSDX SCHEDULE",BSDXRESN)
|
|---|
| 405 | Q
|
|---|
| 406 | ;
|
|---|
| 407 | ROLLBACK(BSDXAPPTID,BSDXC) ; Private EP; Roll back appointment set
|
|---|
| 408 | ; DO NOT USE except as an emergency measure - only if unforseen error occurs
|
|---|
| 409 | ; Input:
|
|---|
| 410 | ; Appointment ID to remove from ^BSDXAPPT
|
|---|
| 411 | ; BSDXC array (see array format in $$MAKE^BSDXAPI)
|
|---|
| 412 | ; NB: I am not sure whether I want to do $G to protect??
|
|---|
| 413 | ; I send the variables to this EP from the Symbol Table in ETRAP
|
|---|
| 414 | D BSDXDEL^BSDX07(BSDXAPPTID)
|
|---|
| 415 | S:$D(BSDXC) %=$$UNMAKE^BSDXAPI(.BSDXC) ; rtn value always 0
|
|---|
| 416 | QUIT
|
|---|
| 417 | ;
|
|---|
| 418 | BSDXDEL(BSDXAPPTID) ;Private EP ; Deletes appointment BSDXAPPTID from ^BSDXAPPT
|
|---|
| 419 | ; DO NOT USE except in emergencies to roll back an appointment set
|
|---|
| 420 | N DA,DIK
|
|---|
| 421 | S DIK="^BSDXAPPT(",DA=BSDXAPPTID
|
|---|
| 422 | D ^DIK
|
|---|
| 423 | Q
|
|---|
| 424 | ;
|
|---|
| 425 | ERR(BSDXI,BSDXERR) ;Error processing - different from error trap.
|
|---|
| 426 | S BSDXI=BSDXI+1
|
|---|
| 427 | S BSDXERR=$TR(BSDXERR,"^","~")
|
|---|
| 428 | S ^BSDXTMP($J,BSDXI)="0^"_BSDXERR_$C(30)
|
|---|
| 429 | S BSDXI=BSDXI+1
|
|---|
| 430 | S ^BSDXTMP($J,BSDXI)=$C(31)
|
|---|
| 431 | L -^BSDXAPPT(BSDXPATID)
|
|---|
| 432 | Q
|
|---|
| 433 | ;
|
|---|
| 434 | ETRAP ;EP Error trap entry
|
|---|
| 435 | N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap
|
|---|
| 436 | D ^%ZTER
|
|---|
| 437 | S $EC="" ; Clear Error
|
|---|
| 438 | I +$G(BSDXAPPTID) D ROLLBACK(BSDXAPPTID,.BSDXC) ; Rollback if BSDXAPPTID exists
|
|---|
| 439 | ; Log error message and send to client
|
|---|
| 440 | I '$D(BSDXI) N BSDXI S BSDXI=0
|
|---|
| 441 | D ERR(BSDXI,"-100~BSDX07 Error: "_$G(%ZTERZE))
|
|---|
| 442 | Q:$Q 1_U_"Mumps Error" Q
|
|---|
| 443 | ;
|
|---|
| 444 | DAY ;;^SUN^MON^TUES^WEDNES^THURS^FRI^SATUR
|
|---|
| 445 | ;
|
|---|
| 446 | DOW S %=$E(X,1,3),Y=$E(X,4,5),Y=Y>2&'(%#4)+$E("144025036146",Y)
|
|---|
| 447 | F %=%:-1:281 S Y=%#4=1+1+Y
|
|---|
| 448 | S Y=$E(X,6,7)+Y#7
|
|---|
| 449 | Q
|
|---|
| 450 | ;
|
|---|
| 451 | AVUPDT(BSDXSCD,BSDXSTART,BSDXLEN) ;Update RPMS Clinic availability
|
|---|
| 452 | ;SEE SDM1
|
|---|
| 453 | N Y,DFN
|
|---|
| 454 | N SL,STARTDAY,X,SC,SB,HSI,SI,STR,SDDIF,SDMAX,SDDATE,SDDMAX,SDSDATE,CCXN,MXOK,COV,SDPROG
|
|---|
| 455 | N X1,SDEDT,X2,SD,SM,SS,S,SDLOCK,ST,I
|
|---|
| 456 | S Y=BSDXSCD,DFN=BSDXPATID
|
|---|
| 457 | 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
|
|---|
| 458 | ;Determine maximum days for scheduling
|
|---|
| 459 | S SDMAX(1)=$P($G(^SC(+SC,"SDP")),U,2) S:'SDMAX(1) SDMAX(1)=365
|
|---|
| 460 | S (SDMAX,SDDMAX)=$$FMADD^XLFDT(DT,SDMAX(1))
|
|---|
| 461 | S SDDATE=BSDXSTART
|
|---|
| 462 | S SDSDATE=SDDATE,SDDATE=SDDATE\1
|
|---|
| 463 | 1 ;L Q:$D(SDXXX) S CCXN=0 K MXOK,COV,SDPROT Q:DFN<0 S SC=+SC
|
|---|
| 464 | Q:$D(SDXXX) S CCXN=0 K MXOK,COV,SDPROT Q:DFN<0 S SC=+SC
|
|---|
| 465 | S X1=DT,SDEDT=365 S:$D(^SC(SC,"SDP")) SDEDT=$P(^SC(SC,"SDP"),"^",2)
|
|---|
| 466 | S X2=SDEDT D C^%DTC S SDEDT=X
|
|---|
| 467 | S Y=BSDXSTART
|
|---|
| 468 | EN1 S (X,SD)=Y,SM=0 D DOW
|
|---|
| 469 | 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,".")
|
|---|
| 470 | S S=BSDXLEN
|
|---|
| 471 | ;Check if BSDXLEN evenly divisible by appointment length
|
|---|
| 472 | S RPMSL=$P(SL,U)
|
|---|
| 473 | I BSDXLEN<RPMSL S BSDXLEN=RPMSL
|
|---|
| 474 | I BSDXLEN#RPMSL'=0 D
|
|---|
| 475 | . S BSDXINC=BSDXLEN\RPMSL
|
|---|
| 476 | . S BSDXINC=BSDXINC+1
|
|---|
| 477 | . S BSDXLEN=RPMSL*BSDXINC
|
|---|
| 478 | S SL=S_U_$P(SL,U,2,99)
|
|---|
| 479 | SC S SDLOCK=$S('$D(SDLOCK):1,1:SDLOCK+1) Q:SDLOCK>9
|
|---|
| 480 | L +^SC(SC,"ST",$P(SD,"."),1):5 G:'$T SC
|
|---|
| 481 | S SDLOCK=0,S=^SC(SC,"ST",$P(SD,"."),1)
|
|---|
| 482 | S I=SD#1-SB*100,ST=I#1*SI\.6+($P(I,".")*SI),SS=SL*HSI/60*SDDIF+ST+ST
|
|---|
| 483 | I (I<1!'$F(S,"["))&(S'["CAN") L -^SC(SC,"ST",$P(SD,"."),1) Q
|
|---|
| 484 | 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
|
|---|
| 485 | ;
|
|---|
| 486 | SP I ST+ST>$L(S),$L(S)<80 S S=S_" " G SP
|
|---|
| 487 | S SDNOT=1
|
|---|
| 488 | S ABORT=0
|
|---|
| 489 | F I=ST+ST:SDDIF:SS-SDDIF D Q:ABORT
|
|---|
| 490 | . S ST=$E(S,I+1) S:ST="" ST=" "
|
|---|
| 491 | . S Y=$E(STR,$F(STR,ST)-2)
|
|---|
| 492 | . I S["CAN"!(ST="X"&($D(^SC(+SC,"ST",$P(SD,"."),"CAN")))) S ABORT=1 Q
|
|---|
| 493 | . I Y="" S ABORT=1 Q
|
|---|
| 494 | . 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
|
|---|
| 495 | . Q
|
|---|
| 496 | S ^SC(SC,"ST",$P(SD,"."),1)=S
|
|---|
| 497 | L -^SC(SC,"ST",$P(SD,"."),1)
|
|---|
| 498 | Q
|
|---|