Refactoring and txn restart fix to routines 26,29,31

This commit is contained in:
sam 2010-12-08 06:44:40 +00:00
parent 882f7bad40
commit 2f21f07db7
3 changed files with 276 additions and 212 deletions

View File

@ -1,4 +1,4 @@
BSDX26 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 11/18/10 5:36pm
BSDX26 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 12/6/10 3:08am
;;1.42;BSDX;;Sep 29, 2010
; Change History:
; 3101023 - UJO/SMH - Addition of restartable transaction; relocation of tx.
@ -33,17 +33,19 @@ UT ; Unit Tests
N bsdxdie S bsdxdie=1
D EDITAPT(.ZZZ,188,NOTE)
I +^BSDXTMP($J,1)'=-100 W "ERROR IN -100",! B
k bsdxdie
; Test 5: Trestart
N bsdxrestart S bsdxrestart=1
N %H S %H=$H
N NOTE S NOTE="New Note "_%H
D EDITAPT(.ZZZ,188,NOTE)
I ^BSDXAPPT(188,1,1,0)'=NOTE W "ERROR in TRESTART",! B
; Test for Hosp Location Update
; Test 6: for Hosp Location Update
N DATE S DATE=$$NOW^XLFDT()
S DATE=$E(DATE,1,12) ; Just get minutes b/c of HL file input transform
D APPADD^BSDX07(.ZZZ,DATE,DATE+.001,3,"Dr Office",30,"Old Note",1)
N APPID S APPID=+$P(^BSDXTMP($J,1),U)
D EDITAPT(.ZZZ,APTID,"New Note")
D EDITAPT(.ZZZ,APPID,"New Note")
I ^BSDXAPPT(APTID,1,1,0)'="New Note" W "Error in HL Section",! B
I $P(^SC(2,"S",DATE,1,1,0),U,4)'="New Note" W "Error in HL Section",! B
QUIT

View File

@ -1,79 +1,92 @@
BSDX29 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 7/18/10 2:03pm
;;1.41;BSDX;;Sep 29, 2010
BSDX29 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 12/6/10 6:05am
;;1.42;BSDX;;Sep 29, 2010
;
; Change Log:
; v1.3 by WV/SMH on 3100713
; - Beginning and Ending dates passed as FM Dates
; v1.42 by WV/SMH on 3101023
; - Transaction moved; now restartable too.
; --> Thanks to Zach Gonzalez and Rick Marshall.
; - Refactoring of major portions of routine
;
BSDXCPD(BSDXY,BSDXRES,BSDX44,BSDXBEG,BSDXEND) ;EP
;Entry point for debugging
;
;D DEBUG^%Serenji("BSDXCP^BSDX29(.BSDXY,BSDXRES,BSDX44,BSDXBEG,BSDXEND)")
D DEBUG^%Serenji("BSDXCP^BSDX29(.BSDXY,BSDXRES,BSDX44,BSDXBEG,BSDXEND)")
Q
;
BSDXCP(BSDXY,BSDXRES,BSDX44,BSDXBEG,BSDXEND) ;EP
;Copy appointments from HOSPITAL LOCATION entry BSDX44 to BSDX RESOURCE entry BSDXRES
;Beginning with appointments on day BSDXBEG and ending on BSDXEND, inclusive
;Called by RPC: BSDX COPY APPOINTMENTS
;
;Returns ADO Recordset formatted fields containing count of records copied and error message:
; Parameters:
; - BSDXY: Global Return
; - BSDXRES: BSDX RESOURCE to copy appointments to
; - BSDX44: Hospital Location IEN to copy appointments from
; - BSDXBEG: Beginning Date in FM Format
; - BSDXEND: End Date in FM Format
;
; July 13 2010: D dates (BEG and END) from US format to FM Dates for i18n
;Returns ADO Recordset containing TASK_NUMBER and ERRORID
;
;
S BSDXY="^BSDXTMP("_$J_")"
N BSDXI,BSDXST,ZTSK
S BSDXI=0
S X="ETRAP^BSDX29",@^%ZOSF("TRAP")
; Return Array
S BSDXY=$NA(^BSDXTMP($J))
K ^BSDXTMP($J)
; $ET
N $ET S $ET="G ETRAP^BSDX29"
; Counter
N BSDXI S BSDXI=0
; Header Node
S ^BSDXTMP($J,0)="T00010TASK_NUMBER^T00020ERRORID"_$C(30)
;
;Convert beginning and ending dates
;
;TODO:Validate FM Dates coming through
;
; Make dates inclusive; add 1 to FM dates
S BSDXBEG=BSDXBEG-1
S BSDXEND=BSDXEND+1
;
; Taskman variables
N ZTSK,ZTRTN,ZTDTH,ZTDESC,ZTSAVE
; Task Load
S ZTRTN="ZTM^BSDX29",ZTDTH=$H,ZTDESC="COPY PATIENT APPTS"
S ZTSAVE("BSDXBEG")="",ZTSAVE("BSDXEND")="",ZTSAVE("BSDX44")="",ZTSAVE("BSDXRES")=""
D ^%ZTLOAD
;
; Set up return ADO.net dataset
N BSDXST S BSDXST=$S($G(ZTSK)>0:"OK",1:"Unable to create task.")
S BSDXI=BSDXI+1
S BSDXST=$S($G(ZTSK)>0:"OK",1:"Unable to create task.")
S ^BSDXTMP($J,BSDXI)=$G(ZTSK)_"^"_BSDXST_$C(30)_$C(31)
Q
;
ZTMTST ;
;
S %DT="AE" D ^%DT S BSDXBEG=Y
S %DT="AE" D ^%DT S BSDXEND=Y
S BSDX44=3,BSDXSRES=1,ZTSK=3380
D ZTM
Q
QUIT
;
ZTMD ;EP - Debug entry point
;D DEBUG^%Serenji("ZTM^BSDX29")
Q
;
ZTM ;EP
;Taskman entry point
S X="ZTMERR^BSDX29",@^%ZOSF("TRAP")
;$O through ^SC(BSDX44,"S",
ZTM ;EP - Taskman entry point
; Variables set up in ZTSAVE above
;
Q:'$D(ZTSK)
N BSDXCNT,BSDXIEN,BSDXNOD,BSDXNOTE,BSDXCAN,BSDXPAT,BSDXLEN,BSDXMADE,BSDXCLRK,BSDXPAT,BSDXQUIT
S BSDXCNT=0,BSDXQUIT=0
; $ET
N $ET S $ET="G ZTMERR^BSDX29"
; Txn
TSTART (BSDXBEG,BSDXEND,BSDX44,BSDXRES):T="BSDX COPY APPOINTMENT^BSDX29"
;$O through ^SC(BSDX44,"S",
N BSDXCNT S BSDXCNT=0 ; Count of Copied Appointments
N BSDXQUIT S BSDXQUIT=0 ; Quit Flag to be retrieved from an external proc
; Set Count
S ^BSDXTMP("BSDXCOPY",ZTSK)=BSDXCNT
TSTART
; Loop through dates here.
F S BSDXBEG=$O(^SC(BSDX44,"S",BSDXBEG)) Q:'+BSDXBEG Q:BSDXBEG>BSDXEND Q:BSDXQUIT D
. S BSDXIEN=0 F S BSDXIEN=$O(^SC(BSDX44,"S",BSDXBEG,1,BSDXIEN)) Q:'+BSDXIEN Q:BSDXQUIT D
. . S BSDXNOD=$G(^SC(BSDX44,"S",BSDXBEG,1,BSDXIEN,0))
. . Q:'+BSDXNOD
. . S BSDXCAN=$P(BSDXNOD,U,9)
. . Q:BSDXCAN="C"
. . S BSDXPAT=$P(BSDXNOD,U)
. . S BSDXLEN=$P(BSDXNOD,U,2) ;duration in minutes
. . S BSDXCLRK=$P(BSDXNOD,U,6) ;appt made by (clerk)
. . S BSDXMADE=$P(BSDXNOD,U,7) ;date appt made
. . S BSDXNOTE=$P(BSDXNOD,U,4) ;'OTHER' field contains note
. ; Loop through Entries in each date in the subsubfile.
. ; Quit if we are at the end or if a remote process requests a quit.
. N BSDXIEN S BSDXIEN=0
. F S BSDXIEN=$O(^SC(BSDX44,"S",BSDXBEG,1,BSDXIEN)) Q:'+BSDXIEN Q:BSDXQUIT D
. . N BSDXNOD S BSDXNOD=$G(^SC(BSDX44,"S",BSDXBEG,1,BSDXIEN,0)) ; Node
. . Q:'+BSDXNOD ; Quit if no node
. . N BSDXCAN S BSDXCAN=$P(BSDXNOD,U,9) ; Cancel flag
. . Q:BSDXCAN="C" ; Quit if appt cancelled
. . N BSDXPAT S BSDXPAT=$P(BSDXNOD,U) ; Patient
. . N BSDXLEN S BSDXLEN=$P(BSDXNOD,U,2) ;duration in minutes
. . N BSDXCLRK S BSDXCLRK=$P(BSDXNOD,U,6) ;appt made by (clerk)
. . N BSDXMADE S BSDXMADE=$P(BSDXNOD,U,7) ;date appt made
. . N BSDXNOTE S BSDXNOTE=$P(BSDXNOD,U,4) ;'OTHER' field contains note
. . S BSDXCNT=BSDXCNT+$$XFER(BSDXRES,BSDXBEG,BSDXPAT,BSDXLEN,BSDXCLRK,BSDXMADE,BSDXNOTE)
. . I +BSDXCNT,BSDXCNT#10=0 S ^BSDXTMP("BSDXCOPY",ZTSK)=BSDXCNT_" records copied." ;every 10th record
. . I $D(^BSDXTMP("BSDXCOPY",ZTSK,"CANCEL")) S BSDXQUIT=1 ;Check for cancel flag
@ -84,10 +97,13 @@ ZTM ;EP
S ^BSDXTMP("BSDXCOPY",ZTSK)=$S(BSDXQUIT:"Cancelled. No records copied.",1:"Finished. "_BSDXCNT_" records copied.")
Q
;
ZTMERR ;
TROLLBACK
ZTMERR ; For now, error from TM is only in trap; not returned to client.
N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap
; Rollback before logging the error
I $TL>0 TROLLBACK
D ^%ZTER
Q
S $EC="" ; Clear Error
QUIT
;
XFER(BSDXRES,BSDXBEG,BSDXPAT,BSDXLEN,BSDXCLRK,BSDXMADE,BSDXNOTE) ;EP
;
@ -131,19 +147,22 @@ XFER(BSDXRES,BSDXBEG,BSDXPAT,BSDXLEN,BSDXCLRK,BSDXMADE,BSDXNOTE) ;EP
;
ERR(BSDXI,BSDXCNT,BSDXERR) ;Error processing
S BSDXI=BSDXI+1
S BSDXERR=$TR(BSDXERR,"^","~")
S ^BSDXTMP($J,BSDXI)=BSDXCNT_"^"_BSDXERR_$C(30)
S BSDXI=BSDXI+1
S ^BSDXTMP($J,BSDXI)=$C(31)
Q
;
ETRAP ;EP Error trap entry
; No Txn here. So don't rollback anything
N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap
D ^%ZTER
I '$D(BSDXI) N BSDXI S BSDXI=999
S BSDXI=BSDXI+1
D ERR(BSDXI,$G(BSDXCNT),"Routine: BSDX29, Error: "_$G(%ZTERROR))
S $EC="" ; Clear error
I '$D(BSDXI) N BSDXI S BSDXI=0
D ERR(BSDXI,$G(BSDXCNT),"~100~BSDX29, Error: "_$G(%ZTERZE))
Q
;
CPSTAT(BSDXY,BSDXTSK) ;EP
CPSTAT(BSDXY,BSDXTSK) ;EP - Note: As of Dec 6 2010: Inactive Code
;Return status (copied record count) of tasked job having ZTSK=BSDXTSK
;
S BSDXY="^BSDXTMP("_$J_")"
@ -159,7 +178,7 @@ CPSTAT(BSDXY,BSDXTSK) ;EP
S ^BSDXTMP($J,BSDXI)=BSDXCNT_"^"_"OK"_$C(30)_$C(31)
Q
;
CPCANC(BSDXY,BSDXTSK) ;EP
CPCANC(BSDXY,BSDXTSK) ;EP Note: As of Dec 6 2010: Inactive code.
;Signal tasked job having ZTSK=BSDXTSK to cancel
;Returns current record count of copy process
;

View File

@ -1,58 +1,103 @@
BSDX31 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ;
;;1.41;BSDX;;Sep 29, 2010
BSDX31 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 12/6/10 8:25am
;;1.42;BSDX;;Sep 29, 2010
; Change Log:
; v1.42 Oct 23 2010 WV/SMH
; - Change transaction to restartable. Thanks to Zach Gonzalez
; --> and Rick Marshall for their help.
; v1.42 Dec 6 2010: Extensive refactoring
;
; Error Reference:
; -1: zero or null Appt ID
; -2: Invalid APPT ID (doesn't exist in ^BSDXAPPT)
; -3: No-show flag is invalid
; -100: M Error
;
;
NOSHOWD(BSDXY,BSDXAPTID,BSDXNS) ;EP
;Entry point for debugging
;
;D DEBUG^%Serenji("NOSHOW^BSDX31(.BSDXY,BSDXAPTID,BSDXNS)")
D DEBUG^%Serenji("NOSHOW^BSDX31(.BSDXY,BSDXAPTID,BSDXNS)")
Q
;
NOSHOW(BSDXY,BSDXAPTID,BSDXNS) ;EP
;Called by BSDX NOSHOW
;Sets appointment noshow flag in BSDX APPOINTMENT file
UT ; Unit Tests
; Test 1: Sanity Check
N ZZZ ; Garbage return variable
N DATE S DATE=$$NOW^XLFDT()
S DATE=$E(DATE,1,12) ; Just get minutes b/c of HL file input transform
D APPADD^BSDX07(.ZZZ,DATE,DATE+.0001,3,"Dr Office",30,"Old Note",1)
N APPID S APPID=+$P(^BSDXTMP($J,1),U)
D NOSHOW(.ZZZ,APPID,1)
I $P(^BSDXAPPT(APPID,0),U,10)'=1 W "ERROR T1",! B
I $P(^DPT(3,"S",DATE,0),U,2)'="N" W "ERROR T1",! B
; Test 2: Undo noshow
D NOSHOW(.ZZZ,APPID,0)
I $P(^BSDXAPPT(APPID,0),U,10)'="0" W "ERROR T2",! B
I $P(^DPT(3,"S",DATE,0),U,2)'="" W "ERROR T2",! B
; Test 3: -1
D NOSHOW(.ZZZ,"",0)
I $P(^BSDXTMP($J,1),U)'=-1 W "ERROR T3",! B
; Test 4: -2
D NOSHOW(.ZZZ,2938748233,0)
I $P(^BSDXTMP($J,1),U)'=-2 W "ERROR T4",! B
QUIT
NOSHOW(BSDXY,BSDXAPTID,BSDXNS) ;EP - No show a patient
; Called by RPC: BSDX NOSHOW
; Sets appointment noshow flag in BSDX APPOINTMENT file and "S" node in File 2
;
; Parameters:
; BSDXY: Global Return
; BSDXAPTID is entry number in BSDX APPOINTMENT file
; BSDXNS = 1: NOSHOW, 0: CANCEL NOSHO
;Calls CANCEL^BSDAPI to set noshow data in ^DPT
;Returns error code in recordset field ERRORID
;
N BSDXNOD,BSDXPATID,BSDXSTART,BSDXID,BSDXI,BSDXZ,BSDXERR,BSDXMSG,BSDXFDA,BSDXIENS
N BSDXNOEV
S BSDXNOEV=1 ;Don't execute protocol
; Returns ADO.net record set with fields
; - ERRORID; ERRORTEXT
; ERRORID of 1 is okay
; Anything else is an error.
;
D ^XBKVAR S X="ETRAP^BSDX31",@^%ZOSF("TRAP")
S BSDXI=0
; Return Array; set and clear
S BSDXY=$NA(^BSDXTMP($J))
K ^BSDXTMP($J)
S BSDXY="^BSDXTMP("_$J_")"
; $ET
N $ET S $ET="G ETRAP^BSDX31"
; Basline vars
D ^XBKVAR ; Set up baseline variables (DUZ, DUZ(2)) if they don't exist
; Counter
N BSDXI S BSDXI=0
; Header Node
S ^BSDXTMP($J,BSDXI)="I00020ERRORID^T00030ERRORTEXT"_$C(30)
S BSDXI=BSDXI+1
TSTART
I '+BSDXAPTID D ERR(0,"BSDX31: Invalid Appointment ID") Q
I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR(0,"BSDX31: Invalid Appointment ID") Q
; Begin transaction
TSTART (BSDXI,BSDXY,BSDXAPTID,BSDXNS):T="BSDX NOSHOW CANCEL^BSDX29"
; Turn off SDAM APPT PROTOCOL BSDX Entries
N BSDXNOEV S BSDXNOEV=1 ;Don't execute protocol
; Appointment ID check
I '+BSDXAPTID D ERR(-1,"BSDX31: Invalid Appointment ID") Q
I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR(-2,"BSDX31: Invalid Appointment ID") Q
; Noshow value check - Must be 1 or 0
S BSDXNS=+BSDXNS
I BSDXNS'=1&(BSDXNS'=0) D ERR(0,"BSDX31: Invalid No Show value") Q
;
;Edit BSDX APPOINTMENT entry NOSHOW field
S BSDXNOD=^BSDXAPPT(BSDXAPTID,0)
I BSDXNOD="" D ERR(0,"BSDX31: Invalid Appointment ID") Q
S BSDXPATID=$P(BSDXNOD,U,5)
S BSDXSTART=$P(BSDXNOD,U)
;
D BSDXNOS(BSDXAPTID,BSDXNS)
I $D(BSDXMSG("DIERR")) S BSDXMSG=$G(BSDXMSG("DIERR",1,"TEXT",1)) D ERR(0,"BSDX31: "_BSDXMSG) Q
;
I BSDXNS'=1&(BSDXNS'=0) D ERR(-3,"BSDX31: Invalid No Show value") Q
; Get Some data
N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPTID,0) ; Node
N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; DFN
N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Start Date/Time
; Edit BSDX APPOINTMENT entry
N BSDXMSG ;
D BSDXNOS(BSDXAPTID,BSDXNS,.BSDXMSG) ;Edit BSDX APPOINTMENT entry NOSHOW field
I $D(BSDXMSG("DIERR")) S BSDXMSG=$G(BSDXMSG("DIERR",1,"TEXT",1)) D ERR(-4,"BSDX31: "_BSDXMSG) Q
; Edit File 2 "S" node entry
N BSDXZ,BSDXERR ; Error variables to control looping
S BSDXSC1=$P(BSDXNOD,U,7) ;RESOURCEID
I BSDXSC1]"",$D(^BSDXRES(BSDXSC1,0)) D I $G(BSDXZ)]"" S BSDXERR="BSDX31: APNOSHO Returned: "_BSDXZ D ERR(0,BSDXERR) Q
; If Resource ID exists, and HL exists (means that Resource is linked), No show in File 2
I BSDXSC1]"",$D(^BSDXRES(BSDXSC1,0)) D I $G(BSDXZ)]"" S BSDXERR="BSDX31: APNOSHO Returned: "_BSDXZ D ERR(-5,BSDXERR) Q
. S BSDXNOD=^BSDXRES(BSDXSC1,0)
. S BSDXSC1=$P(BSDXNOD,U,4) ;HOSPITAL LOCATION
. I BSDXSC1]"",$D(^SC(BSDXSC1,0)) D APNOSHO(.BSDXZ,BSDXSC1,BSDXPATID,BSDXSTART,BSDXNS)
;
TCOMMIT
S BSDXI=BSDXI+1
S ^BSDXTMP($J,BSDXI)="1^"_$C(30)
S ^BSDXTMP($J,BSDXI)="1^"_$C(30) ; 1 means everything okay
S BSDXI=BSDXI+1
S ^BSDXTMP($J,BSDXI)=$C(31)
Q
QUIT
;
APNOSHO(BSDXZ,BSDXSC1,BSDXDFN,BSDXSD,BSDXNS) ;
; update file 2 info
@ -77,14 +122,13 @@ APNOSHO(BSDXZ,BSDXSC1,BSDXDFN,BSDXSD,BSDXNS) ;
S BSDXZ=$G(BSDXMSG("DIERR",1,"TEXT",1))
Q
;
BSDXNOS(BSDXAPTID,BSDXNS) ;
BSDXNOS(BSDXAPTID,BSDXNS,BSDXMSG) ;
;
N BSDXFDA,BSDXIENS
S BSDXIENS=BSDXAPTID_","
S BSDXFDA(9002018.4,BSDXIENS,.1)=BSDXNS ;NOSHOW
D FILE^DIE("","BSDXFDA","BSDXMSG")
;
Q
QUIT
;
NOSEVT(BSDXPAT,BSDXSTART,BSDXSC) ;EP Called by BSDX NOSHOW APPOINTMENT event
;when appointments NOSHOW via PIMS interface.
@ -129,7 +173,6 @@ NOSEVT3(BSDXRES) ;
;
;
ERR(BSDXERID,ERRTXT) ;Error processing
S:'+$G(BSDXI) BSDXI=999999
S BSDXI=BSDXI+1
TROLLBACK
S ^BSDXTMP($J,BSDXI)=BSDXERID_"^"_ERRTXT_$C(30)