removed transactions from BSDX07... still more work to be done though

This commit is contained in:
sam 2012-06-20 00:19:03 +00:00
parent ab78c286b4
commit 6a421d751d
2 changed files with 397 additions and 342 deletions

View File

@ -1,4 +1,4 @@
BSDX07 ; VW/UJO/SMH - WINDOWS SCHEDULING RPCS ; 6/18/12 5:12pm
BSDX07 ; VW/UJO/SMH - WINDOWS SCHEDULING RPCS ; 6/19/12 5:34pm
;;1.7T1;BSDX;;Aug 31, 2011;Build 18
; Licensed under LGPL
;
@ -27,10 +27,10 @@ BSDX07 ; VW/UJO/SMH - WINDOWS SCHEDULING RPCS ; 6/18/12 5:12pm
;
APPADDD(BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID) ;EP
;Entry point for debugging
D DEBUG^%Serenji("APPADD^BSDX07(.BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID)")
; D DEBUG^%Serenji("APPADD^BSDX07(.BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID)")
Q
;
UT ; Unit Tests
UT ; Unit Tests - Assumes you have Patients with DFNs 1,2 and 3
; Set-up - Create Clinics
N RESNAM S RESNAM="UTCLINIC"
N HLRESIENS ; holds output of UTCR^BSDX35 - HL IEN^Resource IEN
@ -48,23 +48,56 @@ UT ; Unit Tests
N APPTTIME S APPTTIME=$P(TIMES,U)
N ENDTIME S ENDTIME=$P(TIMES,U,2)
;
N ZZZ
N ZZZ,DFN
; Test for normality:
D APPADD(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
S DFN=3
D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
; Does Appt exist?
N APPID S APPID=+$P(^BSDXTMP($J,1),U)
I 'APPID W "Error Making Appt-1" QUIT
I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-2"
I '$D(^DPT(3,"S",APPTTIME)) W "Error Making Appt-3"
I '$D(^SC(HLIEN,"S",APPTTIME)) W "Error Making Appt-4"
I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-3"
I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-4"
;
; Do it again for a different patient
D APPADD(.ZZZ,APPTTIME,ENDTIME,2,RESNAM,30,"Sam's Note",1)
N APPID S APPID=+$P(^BSDXTMP($J,1),U) B
S DFN=2
D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
N APPID S APPID=+$P(^BSDXTMP($J,1),U)
I 'APPID W "Error Making Appt-5" QUIT
I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-6"
I '$D(^DPT(2,"S",APPTTIME)) W "Error Making Appt-7"
I '$D(^SC(HLIEN,"S",APPTTIME)) W "Error Making Appt-8"
I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-7"
I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-8"
;
; Again for a different patient (4)
S DFN=4
D APPADD(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
N APPID S APPID=+$P(^BSDXTMP($J,1),U)
I 'APPID W "Error Making Appt-9" QUIT
I +^BSDXAPPT(APPID,0)'=APPTTIME W "Error Making Appt-10"
I '$D(^DPT(DFN,"S",APPTTIME)) W "Error Making Appt-11"
I '$$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error Making Appt-12"
;
; Delete appointment set for Patient 4 (made above)
N BSDX,DFN
S DFN=4
S BSDX("PAT")=DFN
S BSDX("CLN")=HLIEN
S BSDX("ADT")=APPTTIME
D BSDXDEL^BSDX07(APPID)
S %=$$UNMAKE^BSDXAPI(.BSDX)
I +$G(^BSDXAPPT(APPID,0)) W "Error in deleting appointment-1",!
I $D(^DPT(DFN,"S",APPTTIME)) W "Error in deleting appointment-2",!
I $$SCIEN^BSDXAPI(DFN,HLIEN,APPTTIME) W "Error in deleting appointment-3",!
;
; Delete appointment set for Patient 1 (not made)... needs to not crash
D
. N $ET S $ET="D ^%ZTER S $EC="""" W ""Failure to del non-existent appt"",!"
. D BSDXDEL^BSDX07(9999999)
. N BSDX
. S BSDX("PAT")=1
. S BSDX("CLN")=HLIEN
. S BSDX("ADT")=APPTTIME
. S %=$$UNMAKE^BSDXAPI(.BSDX)
;
; Test for bad start date
D APPADD(.ZZZ,2100123,3100123.3,2,RESNAM,30,"Sam's Note",1)
@ -80,11 +113,11 @@ UT ; Unit Tests
D APPADD(.ZZZ,APPTTIME,ENDTIME,1,RESNAM,30,"Sam's Note",1)
I +$P(^BSDXTMP($J,1),U,2)'=-100 W "Error in -100: M Error",!
K BSDXDIE
; Test for TRESTART
s BSDXRESTART=1
D APPADD(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
I +$P(^BSDXTMP($J,1),U,2)'=0&(+$P(^BSDXTMP($J,1),U,2)'=-10) W "Error in TRESTART",!
k BSDXRESTART
; Test for TRESTART -- retired in v 1.7
; S BSDXRESTART=1
; D APPADD(.ZZZ,APPTTIME,ENDTIME,3,RESNAM,30,"Sam's Note",1)
; I +$P(^BSDXTMP($J,1),U,2)'=0&(+$P(^BSDXTMP($J,1),U,2)'=-10) W "Error in TRESTART",!
; K BSDXRESTART
; Test for non-numeric patient
D APPADD(.ZZZ,APPTTIME,ENDTIME,"CAT,DOG",RESNAM,30,"Sam's Note",1)
I +$P(^BSDXTMP($J,1),U,2)'=-5 W "Error in -5",!
@ -96,7 +129,7 @@ UT ; Unit Tests
I +$P(^BSDXTMP($J,1),U,2)'=-7 W "Error in -7",!
; Test for corrupted resource
; Can't test for -8 since it requires DB corruption
; Test for inability to add appointment to BSDX Appointment
; Test for inability to add appointment to BSDX Appointment (-9)
; Also requires something wrong in the DB
; Test for inability to add appointment to 2,44
; Test by creating a duplicate appointment
@ -140,22 +173,24 @@ APPADD(BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID,BSDXR
;
; Deal with optional arguments
S BSDXRADEXAM=$G(BSDXRADEXAM)
;
; Return Array; set Return and clear array
S BSDXY=$NA(^BSDXTMP($J))
K ^BSDXTMP($J)
;
; $ET
N $ET S $ET="G ETRAP^BSDX07"
;
; Counter
N BSDXI S BSDXI=0
;
; Lock BSDX node, only to synchronize access to the globals.
; It's not expected that the error will ever happen as no filing
; is supposed to take 5 seconds.
L +^BSDXAPPT(BSDXPATID):5 I '$T D ERR(BSDXI,"-1~Patient record is locked. Please contact technical support.") Q
;
; Header Node
S ^BSDXTMP($J,BSDXI)="I00020APPOINTMENTID^T00100ERRORID"_$C(30)
;Restartable Transaction; restore paramters when starting.
; (Params restored are what's passed here + BSDXI)
TSTART (BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID,BSDXI):T="BSDX ADD NEW APPOINTMENT^BSDX07"
;
; Turn off SDAM APPT PROTOCOL BSDX Entries
N BSDXNOEV
@ -167,9 +202,6 @@ APPADD(BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID,BSDXR
;;;test for error inside transaction. See if %ZTER works
I $G(BSDXDIE) S X=1/0
;;;test
;;;test for TRESTART
I $G(BSDXRESTART) K BSDXRESTART TRESTART
;;;test
;
; -- Start and End Date Processing --
; If C# sends the dates with extra zeros, remove them
@ -205,17 +237,12 @@ APPADD(BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID,BSDXR
; Reset Access Type ID if it doesn't say "WALKIN" and isn't a number
I BSDXATID'?.N&(BSDXATID'="WALKIN") S BSDXATID=""
;
; Done with all checks, let's make appointment in BSDX APPOINTMENT
N BSDXAPPTID
S BSDXAPPTID=$$BSDXADD(BSDXSTART,BSDXEND,BSDXPATID,BSDXRESD,BSDXATID,BSDXRADEXAM)
I 'BSDXAPPTID D ERR(BSDXI,"-9~BSDX07 Error: Unable to add appointment to BSDX APPOINTMENT file.") Q
I BSDXNOTE]"" D BSDXWP(BSDXAPPTID,BSDXNOTE)
;
; Then Create Subfiles in 2/44 Appointment
; Now, check if PIMS has any issues with us making the appt using MAKECK
N BSDXSCD S BSDXSCD=$P(BSDXRNOD,U,4) ; Hosp Location IEN
; Only if we have a valid Hosp Loc can we make an appointment
I +BSDXSCD,$D(^SC(BSDXSCD,0)) D I +BSDXERR D ERR(BSDXI,"-10~BSDX07 Error: MAKE^BSDXAPI returned error code: "_BSDXERR) Q
. N BSDXC
N BSDXERR ; Variable to hold value of $$MAKE and $$MAKECK
N BSDXC ; Array to send to MAKE and MAKECK APIs
; Only if we have a valid Hosp Location
I +BSDXSCD,$D(^SC(BSDXSCD,0)) D
. S BSDXC("PAT")=BSDXPATID
. S BSDXC("CLN")=BSDXSCD
. S BSDXC("TYP")=3 ;3 for scheduled appts, 4 for walkins
@ -226,26 +253,31 @@ APPADD(BSDXY,BSDXSTART,BSDXEND,BSDXPATID,BSDXRES,BSDXLEN,BSDXNOTE,BSDXATID,BSDXR
. S BSDXC("OI")=$TR(BSDXC("OI"),";"," ") ;No semicolons allowed by MAKE^BSDXAPI
. S BSDXC("OI")=$$STRIP(BSDXC("OI")) ;Strip control characters from note
. S BSDXC("USR")=DUZ
. S BSDXERR=$$MAKECK^BSDXAPI(.BSDXC)
I +BSDXERR D ERR(BSDXI,"-10~BSDX07 Error: MAKECK^BSDXAPI returned error code: "_BSDXERR) Q ; no need for roll back
;
; Done with all checks, let's make appointment in BSDX APPOINTMENT
N BSDXAPPTID
S BSDXAPPTID=$$BSDXADD(BSDXSTART,BSDXEND,BSDXPATID,BSDXRESD,BSDXATID,BSDXRADEXAM)
I 'BSDXAPPTID D ERR(BSDXI,"-9~BSDX07 Error: Unable to add appointment to BSDX APPOINTMENT file.") Q ; no roll back needed! No appts made.
I BSDXNOTE]"" D BSDXWP(BSDXAPPTID,BSDXNOTE) ; TODO: check for error and rollback
;
; Only if we have a valid Hosp Loc can we make an appointment in 2/44
; Use BSDXC array from before.
; NB: $$MAKE itself calls $$MAKECK to check again for being okay.
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
. S BSDXERR=$$MAKE^BSDXAPI(.BSDXC)
. Q:BSDXERR
. ;Update RPMS Clinic availability
. D AVUPDT(BSDXSCD,BSDXSTART,BSDXLEN)
. Q
;
;Return Recordset
TCOMMIT
L -^BSDXAPPT(BSDXPATID)
S BSDXI=BSDXI+1
S ^BSDXTMP($J,BSDXI)=BSDXAPPTID_"^"_$C(30)
S BSDXI=BSDXI+1
S ^BSDXTMP($J,BSDXI)=$C(31)
Q
BSDXDEL(BSDXAPPTID) ;Deletes appointment BSDXAPPTID from BSDXAPPOINTMETN
N DA,DIK
S DIK="^BSDXAPPT(",DA=BSDXAPPTID
D ^DIK
Q
;
STRIP(BSDXZ) ;Replace control characters with spaces
N BSDXI
F BSDXI=1:1:$L(BSDXZ) I (32>$A($E(BSDXZ,BSDXI))) S BSDXZ=$E(BSDXZ,1,BSDXI-1)_" "_$E(BSDXZ,BSDXI+1,999)
@ -271,6 +303,7 @@ BSDXADD(BSDXSTART,BSDXEND,BSDXPATID,BSDXRESD,BSDXATID,BSDXRADEXAM) ;ADD BSDX AP
;
BSDXWP(BSDXAPPTID,BSDXNOTE) ;
;Add WP field
N BSDXMSG
I BSDXNOTE]"" S BSDXNOTE(.5)=BSDXNOTE,BSDXNOTE=""
I $D(BSDXNOTE(0)) S BSDXNOTE(.5)=BSDXNOTE(0) K BSDXNOTE(0)
I $D(BSDXNOTE(.5)) D
@ -315,17 +348,30 @@ ADDEVT3(BSDXRES) ;
ERR(BSDXI,BSDXERR) ;Error processing
S BSDXI=BSDXI+1
S BSDXERR=$TR(BSDXERR,"^","~")
I $TL>0 TROLLBACK
S ^BSDXTMP($J,BSDXI)="0^"_BSDXERR_$C(30)
S BSDXI=BSDXI+1
S ^BSDXTMP($J,BSDXI)=$C(31)
L -^BSDXAPPT(BSDXPATID)
Q
;
ROLLBACK(BSDXAPPTID,BSDXC) ; Private EP; Roll back appointment set
; DO NOT USE except as an emergency measure - only if unforseen error occurs
; Input:
; Appointment ID to remove from ^BSDXAPPT
; BSDXC array (see array format in $$MAKE^BSDXAPI)
D BSDXDEL^BSDX07(BSDXAPPTID)
S:$D(BSDXC) %=$$UNMAKE^BSDXAPI(.BSDXC) ; rtn value always 0
QUIT
;
BSDXDEL(BSDXAPPTID) ;Private EP ; Deletes appointment BSDXAPPTID from ^BSDXAPPT
; DO NOT USE except in emergencies to roll back an appointment set
N DA,DIK
S DIK="^BSDXAPPT(",DA=BSDXAPPTID
D ^DIK
Q
;
ETRAP ;EP Error trap entry
N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap
; Rollback, otherwise ^XTER will be empty from future rollback
I $TL>0 TROLLBACK
D ^%ZTER
S $EC="" ; Clear Error
; Log error message and send to client

View File

@ -1,5 +1,5 @@
BSDXAPI ; IHS/ANMC/LJF & VW/SMH - SCHEDULING APIs ; 6/18/12 5:31pm
;;1.6;BSDX;;Aug 31, 2011;Build 18
BSDXAPI ; IHS/ANMC/LJF & VW/SMH - SCHEDULING APIs ; 6/19/12 5:42pm
;;1.7T1;BSDX;;Aug 31, 2011;Build 18
; Licensed under LGPL
;
;Orignal routine is BSDAPI by IHS/LJF, HMW, and MAW
@ -34,7 +34,9 @@ BSDXAPI ; IHS/ANMC/LJF & VW/SMH - SCHEDULING APIs ; 6/18/12 5:31pm
; 2012-06-18 (v 1.7)
; Removing transacions. Means that code SHOULD NOT fail. Took all checks
; out for making an appointment to MAKECK. We call this first to make sure
; that the appointment is okay to make before committing to make it.
; that the appointment is okay to make before committing to make it. We
; still have the provision to delete the data though if we fail when we
; actually make the appointment
;
MAKE1(DFN,CLIN,TYP,DATE,LEN,INFO) ; Simplified PEP w/ parameters for $$MAKE - making appointment
; Call like this for DFN 23435 having an appointment at Hospital Location 33
@ -69,13 +71,13 @@ MAKE(BSDR) ;PEP; call to store appt made
;
N BSDXMKCK S BSDXMKCK=$$MAKECK(.BSDR) ; Check if we can make appointment
I BSDXMKCK Q BSDXMKCK ; If we can't, quit with the reason why.
;
;Otherwise, we continue
;
NEW DIC,DA,Y,X,DD,DO,DLAYGO
N BSDXFDA,BSDXIENS,BSDXMSG ; FILE/UPDATE^DIE variables
;
I $D(^DPT(BSDR("PAT"),"S",BSDR("ADT"),0)),$P(^(0),U,2)["C" D
. ; "un-cancel" existing appt in file 2
. N BSDXFDA,BSDXIENS,BSDXMSG
. S BSDXIENS=BSDR("ADT")_","_BSDR("PAT")_","
. S BSDXFDA(2.98,BSDXIENS,".01")=BSDR("CLN")
. S BSDXFDA(2.98,BSDXIENS,"3")=""
@ -87,26 +89,27 @@ MAKE(BSDR) ;PEP; call to store appt made
. S BSDXFDA(2.98,BSDXIENS,"19")=""
. S BSDXFDA(2.98,BSDXIENS,"20")=$$NOW^XLFDT
. D FILE^DIE("","BSDXFDA","BSDXMSG")
. N BSDXTEMP S BSDXTEMP=$G(BSDXMSG)
E D
. N BSDXFDA,BSDXIENS,BSDXMSG
Q:$D(BSDXMSG) 1_U_"Fileman edit to DPT error: Patient="_BSDR("PAT")_" Appt="_BSDR("ADT")_" Error="_BSDXMSG("DIERR",1,"TEXT",1)
;
E D ; File new appointment/edit existing appointment in file 2
. S BSDXIENS="?+2,"_BSDR("PAT")_","
. S BSDXIENS(2)=BSDR("ADT")
. S BSDXFDA(2.98,BSDXIENS,.01)=BSDR("CLN")
. S BSDXFDA(2.98,BSDXIENS,"9")=BSDR("TYP")
. S BSDXFDA(2.98,BSDXIENS,"9.5")=9
. S BSDXFDA(2.98,BSDXIENS,"20")=$$NOW^XLFDT
. D UPDATE^DIE("","BSDXFDA","BSDXIENS","BSDXERR(1)")
I $G(BSDXERR(1)) Q 1_U_"FileMan add to DPT error: Patient="_BSDR("PAT")_" Appt="_BSDR("ADT")
; add appt to file 44
K DIC,DA,X,Y,DLAYGO,DD,DO
. D UPDATE^DIE("","BSDXFDA","BSDXIENS","BSDXMSG")
Q:$D(BSDXMSG) 1_U_"FileMan add to DPT error: Patient="_BSDR("PAT")_" Appt="_BSDR("ADT")_" Error="_BSDXMSG("DIERR",1,"TEXT",1)
;
; add appt to file 44. This adds it to the FIRST subfile (Appointment)
N DIC,DA,Y,X,DD,DO,DLAYGO
I '$D(^SC(BSDR("CLN"),"S",0)) S ^SC(BSDR("CLN"),"S",0)="^44.001DA^^"
I '$D(^SC(BSDR("CLN"),"S",BSDR("ADT"),0)) D I Y<1 Q 1_U_"Error adding date to file 44: Clinic="_BSDR("CLN")_" Date="_BSDR("ADT")
. S DIC="^SC("_BSDR("CLN")_",""S"",",DA(1)=BSDR("CLN"),(X,DINUM)=BSDR("ADT")
. S DIC("P")="44.001DA",DIC(0)="L",DLAYGO=44.001
. S Y=1 I '$D(@(DIC_X_")")) D FILE^DICN
;
; add appt for file 44, second subfile (Appointment/Patient)
; Sep 28 2010: Changed old style API to new style API. Keep for reference //smh
;K DIC,DA,X,Y,DLAYGO,DD,DO,DINUM
;S DIC="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
@ -135,6 +138,10 @@ MAKE(BSDR) ;PEP; call to store appt made
Q 0
;
MAKECK(BSDR) ; $$ - Is it okay to make an appointment? ; PEP
; Input: Same as $$MAKE
; Output: 1^error or 0 for success
; NB: This subroutine saves no data. Only checks whether it's okay.
;
I '$D(^DPT(+$G(BSDR("PAT")),0)) Q 1_U_"Patient not on file: "_$G(BSDR("PAT"))
I '$D(^SC(+$G(BSDR("CLN")),0)) Q 1_U_"Clinic not on file: "_$G(BSDR("CLN"))
I ($G(BSDR("TYP"))<3)!($G(BSDR("TYP"))>4) Q 1_U_"Appt Type error: "_$G(BSDR("TYP"))
@ -163,21 +170,23 @@ MAKECK(BSDR) ; $$ - Is it okay to make an appointment? ; PEP
UNMAKE(BSDR) ; Reverse Make - Private $$
; Only used in Emergiencies where Fileman data filing fails.
; If previous data exists, which caused an error, it's destroyed.
N BSDXFDA,BSDXIENS
S BSDXIENS=BSDR("ADT")_","_BSDR("PAT")_","
S BSDXFDA(2.98,BSDXIENS,".01")="@"
; NB: ^DIK stops for nobody
; Input: Same array as $$MAKE
; Output: Always 0
NEW DIK,DA
S DIK="^DPT("_BSDR("PAT")_",""S"","
S DA(1)=BSDR("PAT"),DA=BSDX("ADT")
D ^DIK
;
I '$D(^SC(BSDR("CLN"),"S",BSDR("ADT"),1)) QUIT 0 ; No stuff in HL file
N X S X=0 F S X=$O(^SC(BSDR("CLN"),"S",BSDR("ADT"),1,X)) Q:'X Q:+^(X,0)=BSDR("PAT")
N IEN S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
I 'IEN QUIT 0
;
I 'X QUIT 0 ; Patient doesn't have appointment
;
S BSDXIENS=X_","_BSDR("ADT")_","_BSDR("CLN")_","
S BSDXFDA(44.003,BSDXIENS,.01)="@"
N BSDXMSG
D FILE^DIE("","BSDXFDA","BSDXMSG")
I $D(BSDXMSG) S $EC=",U1," ; If we get an error here, we are REALLY out of control
NEW DIK,DA
S DIK="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),DA=IEN
D ^DIK
QUIT 0
;
CHECKIN1(DFN,CLIN,APDATE) ; Simplified PEP w/ parameters for $$CHECKIN - Checking in
; Call like this for DFN 23435 checking in now at Hospital Location 33
; for appt at Dec 20, 2009 @ 10:11:59