Index: /Scheduling/trunk/m/BSDX25.m
===================================================================
--- /Scheduling/trunk/m/BSDX25.m	(revision 1465)
+++ /Scheduling/trunk/m/BSDX25.m	(revision 1466)
@@ -1,3 +1,3 @@
-BSDX25	; VEN/SMH - WINDOWS SCHEDULING RPCS ; 6/29/12 12:04pm
+BSDX25	; VEN/SMH - WINDOWS SCHEDULING RPCS ; 7/3/12 12:27pm
 	;;1.7T1;BSDX;;Aug 31, 2011;Build 18
 	; Licensed under LGPL
@@ -34,4 +34,11 @@
 	; - Another number or text if not
 	;
+	; Error reference:
+	; -1 -> Invalid Appointment ID
+	; -2 -> Invalid Check-in Date
+	; -3 -> Cannot check-in due to Fileman Filer failure
+	; -10 -> BSDXAPI error
+	; -100 -> Mumps Error
+	;
 	; Turn off SDAM Appointment Events BSDX Protocol Processing
 	N BSDXNOEV
@@ -44,4 +51,7 @@
 	N $ET S $ET="G ERROR^BSDX25"
 	;
+	; Test for error trap for Unit Tests
+	I $G(BSDXDIE) N X S X=1/0
+	;
 	N BSDXI S BSDXI=0
 	;
@@ -51,10 +61,6 @@
 	S ^BSDXTMP($J,0)="T00020ERRORID"_$C(30)
 	;
-	I '+BSDXAPPTID D ERR("Invalid Appointment ID") QUIT
-	I '$D(^BSDXAPPT(BSDXAPPTID,0)) D ERR("Invalid Appointment ID") QUIT
-	;
-	; Lock the node for synchronizing access to appointment
-	LOCK +^BSDXAPPT(BSDXAPPTID):1
-	ELSE  DO ERR("-7~Lock not acquired") QUIT
+	I '+BSDXAPPTID D ERR("-1~Invalid Appointment ID") QUIT
+	I '$D(^BSDXAPPT(BSDXAPPTID,0)) D ERR("-1~Invalid Appointment ID") QUIT
 	;
 	; Remove Date formatting v.1.5. Client will send date as FM Date.
@@ -62,14 +68,11 @@
 	;S %DT="T",X=BSDXCDT D ^%DT S BSDXCDT=Y
 	S BSDXCDT=+BSDXCDT  ; Strip off zeros if C# sends them
-	I BSDXCDT=-1 D ERR(70) Q
+	I BSDXCDT'>2000000 D ERR("-2~Invalid Check-in Date") QUIT
 	I BSDXCDT>$$NOW^XLFDT S BSDXCDT=$$NOW^XLFDT
 	;
-	;Checkin BSDX APPOINTMENT entry
-	N BSDXERR S BSDXERR=$$BSDXCHK(BSDXAPPTID,BSDXCDT)
-	I BSDXERR D ERR("BSDX08: Fileman Filer failed to check-in appt") QUIT
-	;
-	N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPPTID,0)
-	N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5)
-	N BSDXSTART S BSDXSTART=$P(BSDXNOD,U)
+	; Some data
+	N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPPTID,0) ; Appointment Node
+	N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; DFN
+	N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Appointment Start Time
 	;
 	; Get Hospital Location IEN from BSDXAPPT to BSDXRES (RESOUCE:HOSPITAL LOCATION)
@@ -77,11 +80,21 @@
 	I BSDXSC1,'$D(^SC(BSDXSC1,0)) S BSDXSC1="" ; Null it off if it doesn't exist
 	;
+	; Check if we can check-in using BSDXAPI
+	N BSDXERR S BSDXERR=0
+	I BSDXSC1 S BSDXERR=$$CHECKIC1^BSDXAPI(BSDXPATID,BSDXSC1,BSDXSTART)
+	I BSDXERR D ERR(-10_"~"_$P(BSDXERR,U,2)) QUIT
+	;
+	; Checkin BSDX APPOINTMENT entry
+	; Failure Analysis: If we fail here, no changes were made.
+	N BSDXERR S BSDXERR=$$BSDXCHK(BSDXAPPTID,BSDXCDT)
+	I BSDXERR D ERR("-3~Fileman Filer failed to check-in appt") QUIT
+	;
 	; File check-in using BSDXAPI
+	; Failure Analysis: If we fail here, we need to roll back first check-in.
 	N BSDXERR S BSDXERR=0
 	I BSDXSC1 S BSDXERR=$$CHECKIN1^BSDXAPI(BSDXPATID,BSDXSC1,BSDXSTART)
-	I BSDXERR D ERR($P(BSDXZ,U,2)) QUIT
-	;
-	; Unlock
-	LOCK -^BSDXAPPT(BSDXAPPTID)
+	I BSDXERR D  QUIT
+	. N % S %=$$BSDXCHK(BSDXAPPTID,"@") ; No Error checking to prevent loop.
+	. D ERR(-10_"~"_$P(BSDXERR,U,2)) ; Send error message to client
 	;
 	S BSDXI=BSDXI+1
@@ -98,4 +111,6 @@
 	; Output: 1^Error for error
 	;         0 for success
+	;
+	Q:$G(BSDXSIMERR1) 1_U_"Simulated Error 1"
 	;
 	N BSDXIENS,BSDXMSG,BSDXFDA ; Filer variables
@@ -145,8 +160,4 @@
 	I '$D(^BSDXAPPT(BSDXAPPTID,0)) D ERR("-2~Invalid Appointment ID") QUIT
 	;
-	; Lock the node for synchronizing access to appointment
-	LOCK +^BSDXAPPT(BSDXAPPTID):1
-	ELSE  DO ERR("-7~Lock not acquired") QUIT
-	;
 	; Remove checkin from BSDX APPOINTMENT entry
 	N BSDXERR S BSDXERR=$$BSDXCHK(BSDXAPPTID,"@")
@@ -167,10 +178,7 @@
 	;
 	N BSDXZ ; Scratch variable to hold error message
-	I BSDXSC1]"",$D(^SC(BSDXSC1,0)) S BSDXZ=$$RMCI^BSDXAPI(BSDXPATID,BSDXSC1,BSDXSTART)
+	I BSDXSC1]"",$D(^SC(BSDXSC1,0)) S BSDXZ=$$RMCI^BSDXAPI1(BSDXPATID,BSDXSC1,BSDXSTART)
 	I +$G(BSDXZ) D ERR("-5~"_$P(BSDXZ,U,2)) QUIT
 	; 
-	; Unlock
-	LOCK -^BSDXAPPT(BSDXAPPTID)
-	;
 	; Return ADO recordset
 	S BSDXI=BSDXI+1
@@ -225,11 +233,18 @@
 	S $ETRAP="D ^%ZTER HALT"  ; Emergency Error Trap for the wise
 	D ^%ZTER
-	S $EC=""  ; Clear Error
+	; VEN/SMH: NB: I make a conscious decision not to roll back anything
+	; here in the error trap. Once the error is fixed, users can 
+	; undo or redo the check-in.
+	; Individual portions of this routine may choose to do rolling back
+	; of their own (e.g. a failed call to BSDXAPI causes rollback to occur
+	; in CHECKIN)
+	;
 	; Log error message and send to client
 	D ERR("-100~Mumps Error")
-	Q
+	Q:$Q "-100^Mumps Error" Q
 	;
 ERR(BSDXERR)	;Error processing
-	I $G(BSDXAPPTID) LOCK -^BSDXAPPT(BSDXAPPTID)
+	; If last line is $C(31), we are done. No more errors to send to client.
+	I ^BSDXTMP($J,$O(^BSDXTMP($J," "),-1))=$C(31) QUIT
 	S BSDXERR=$G(BSDXERR)
 	S BSDXERR=$P(BSDXERR,"~")_"~"_$TEXT(+0)_":"_$P(BSDXERR,"~",2) ; Append Routine Name
Index: /Scheduling/trunk/m/BSDXAPI.m
===================================================================
--- /Scheduling/trunk/m/BSDXAPI.m	(revision 1465)
+++ /Scheduling/trunk/m/BSDXAPI.m	(revision 1466)
@@ -1,45 +1,10 @@
-BSDXAPI	; IHS/ANMC/LJF & VW/SMH - SCHEDULING APIs ; 6/29/12 12:19pm
+BSDXAPI	; IHS/ANMC/LJF & VW/SMH - SCHEDULING APIs ; 7/3/12 12:30pm
 	;;1.7T1;BSDX;;Aug 31, 2011;Build 18
 	; Licensed under LGPL  
 	;
-	;Orignal routine is BSDAPI by IHS/LJF, HMW, and MAW
+	; Orignal routine is BSDAPI by IHS/LJF, HMW, and MAW
 	; mods (many) by WV/SMH
-	;Move to BSDX namespace as BSDXAPI from BSDAPI by WV/SMH
-	; Change History:
-	; 2010-11-5: (1.42)
-	; - Fixed errors having to do uncanceling patient appointments if it was 
-	;   a patient cancelled appointment.
-	; - Use new style Fileman API for storing appointments in file 44 in 
-	;   $$MAKE due to problems with legacy API.
-	; 2010-11-12: (1.42)
-	; - Changed ="C" to ["C" in SCIEN. Cancelled appointments can be "PC" as 
-	;   well. 
-	; 2010-12-5 (1.42)
-	; Added an entry point to update the patient note in file 44.
-	; 2010-12-6 (1.42)
-	; MAKE1 incorrectly put info field in BSDR("INFO") rather than BSDR("OI")
-	; 2010-12-8 (1.42)
-	; Removed restriction on max appt length. Even though this restriction
-	; exists in fileman (120 minutes), PIMS ignores it. Therefore, I 
-	; will ignore it here too.
-	; 2011-01-25 (v.1.5)
-	; Added entry point $$RMCI to remove checked in appointments.
-	; In $$CANCEL, if the appointment is checked in, delete check-in rather than
-	;  spitting an error message to the user saying 'Delete the check-in'
-	; Changed all lines that look like this:
-	;  I $G(BSDR("ADT"))'?7N1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
-	; to:
-	;  I $G(BSDR("ADT"))'?7N.1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
-	; to allow for date at midnight which does not have a dot at the end.
-	; 2011-01-26 (v.1.5)
-	; More user friendly message if patient already has appointment in $$MAKE:
-	;  Spits out pt name and user friendly date.
-	; 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. We
-	; still have the provision to delete the data though if we fail when we 
-	; actually make the appointment.
-	; CANCELCK exists for the same purpose.
+	; Move to BSDX namespace as BSDXAPI from BSDAPI by WV/SMH
+	; Change history is located in BSDXAPI1 (to save space).
 	;
 MAKE1(DFN,CLIN,TYP,DATE,LEN,INFO)	; Simplified PEP w/ parameters for $$MAKE - making appointment
@@ -230,4 +195,68 @@
 	;              = 1^message means error with reason message
 	;
+	I $G(BSDXDIE2) N X S X=1/0
+	;
+	N BSDXERR S BSDXERR=$$CHECKICK(.BSDR)
+	I BSDXERR Q BSDXERR
+	;
+	; find ien for appt in file 44
+	NEW IEN,DIE,DA,DR
+	S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
+	;
+	; remember before status
+	; Failure analysis: Only ^TMP global is set here.
+	NEW SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL,SDMODE
+	S DFN=BSDR("PAT"),SDT=BSDR("ADT"),SDCL=BSDR("CLN"),SDMODE=2,SDDA=IEN
+	S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
+	D BEFORE^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
+	;
+	; set checkin; Old Code -- keep for ref VEN/SMH 3 Jul 2012
+	; S DIE="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
+	; S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),DA=IEN
+	; S DR="309///"_BSDR("CDT")_";302///`"_BSDR("USR")_";305///"_$$NOW^XLFDT
+	; D ^DIE
+	;
+	I $D(BSDXSIMERR3) Q 1_U_"Simulated Error"
+	;
+	; Failure analysis: If this fails, no other changes were made in this routine
+	N BSDXIENS S BSDXIENS=IEN_","_BSDR("ADT")_","_BSDR("CLN")_","
+	N BSDXFDA
+	S BSDXFDA(44.003,BSDXIENS,309)=BSDR("CDT")
+	S BSDXFDA(44.003,BSDXIENS,302)=BSDR("USR")
+	S BSDXFDA(44.003,BSDXIENS,305)=$$NOW^XLFDT()
+	N BSDXERR
+	D UPDATE^DIE("","BSDXFDA","BSDXERR")
+	;
+	I $D(BSDXERR) Q 1_U_"Error checking in appointment to file 44. Error: "_BSDXERR("DIERR",1,"TEXT",1)
+	;
+	; set after status
+	S SDDA=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
+	S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
+	D AFTER^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
+	;
+	; Point of no Return
+	; call event driver
+	D EVT^SDAMEVT(.SDATA,4,SDMODE,SDCIHDL)
+	Q 0
+	;
+CHECKIC1(DFN,CLIN,APDATE)	; Simplified PEP w/ parameters for $$CHECKICK -
+	; Check-in Check
+	; Call like this for DFN 23435 checking in now at Hospital Location 33
+	; for appt at Dec 20, 2009 @ 10:11:59 
+	; S RESULT=$$CHECKIC1^BSDXAPI(23435,33,3091220.221159)
+	N BSDR
+	S BSDR("PAT")=DFN          ;DFN
+	S BSDR("CLN")=CLIN         ;Hosp Loc IEN
+	S BSDR("ADT")=APDATE       ;Appt Date
+	S BSDR("CDT")=$$NOW^XLFDT  ;Check-in date defaults to now
+	S BSDR("USR")=DUZ          ;Check-in user defaults to current
+	Q $$CHECKICK(.BSDR)
+	;
+CHECKICK(BSDR) ; $$ PEP; - Is it okay to check-in patient?
+	; Input: Same as $$CHECKIN
+	; Output: 0 if okay or 1^message if error
+	;
+	I $G(BSDXSIMERR2) Q 1_U_"Simulated Error"
+	;
 	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"))
@@ -239,27 +268,6 @@
 	;
 	; find ien for appt in file 44
-	NEW IEN,DIE,DA,DR
-	S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
+	N IEN S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
 	I 'IEN Q 1_U_"Error trying to find appointment for checkin: Patient="_BSDR("PAT")_" Clinic="_BSDR("CLN")_" Appt="_BSDR("ADT")
-	;
-	; remember before status
-	NEW SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL,SDMODE
-	S DFN=BSDR("PAT"),SDT=BSDR("ADT"),SDCL=BSDR("CLN"),SDMODE=2,SDDA=IEN
-	S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
-	D BEFORE^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
-	;
-	; set checkin
-	S DIE="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
-	S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),DA=IEN
-	S DR="309///"_BSDR("CDT")_";302///`"_BSDR("USR")_";305///"_$$NOW^XLFDT
-	D ^DIE
-	;
-	; set after status
-	S SDDA=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
-	S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
-	D AFTER^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
-	;
-	; call event driver
-	D EVT^SDAMEVT(.SDATA,4,SDMODE,SDCIHDL)
 	Q 0
 	;
@@ -378,44 +386,4 @@
 	Q $S(X:1,1:0)
 	;
-RMCI(PAT,CLINIC,DATE)	 ;PEP; -- Remove Check-in; $$
-	; PAT = DFN
-	; CLINIC = SC IEN
-	; DATE = FM Date/Time of Appointment
-	;
-	; Returns:
-	; 0 if okay
-	; -1 if failure
-	;
-	; Call like this: $$RMCI(233,33,3110102.1130)
-	;
-	; Move my variables into the ones used by SDAPIs (just a convenience)
-	NEW SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL,SDMODE
-	S DFN=PAT,SDT=DATE,SDCL=CLINIC,SDMODE=2,SDDA=$$SCIEN(DFN,SDCL,SDT)
-	;
-	I SDDA<1 QUIT 0    ; Appt cancelled; cancelled appts rm'ed from file 44
-	;
-	; remember before status
-	S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
-	D BEFORE^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
-	;
-	; remove check-in using filer.
-	N BSDXIENS S BSDXIENS=SDDA_","_DATE_","_CLINIC_","
-	N BSDXFDA
-	S BSDXFDA(44.003,BSDXIENS,309)="@" ; CHECKED-IN
-	S BSDXFDA(44.003,BSDXIENS,302)="@" ; CHECK IN USER
-	S BSDXFDA(44.003,BSDXIENS,305)="@" ; CHECK IN ENTERED
-	N BSDXERR
-	D FILE^DIE("","BSDXFDA","BSDXERR")
-	I $D(BSDXERR) QUIT "-1~Can't file for Pat "_PAT_" in Clinic "_CLINIC_" at "_DATE_". Fileman reported an error: "_BSDXERR("DIERR",1,"TEXT",1)
-	;
-	; set after status
-	; S SDDA=$$SCIEN(DFN,SDCL,SDT) ;smh -why is this here? SDDA won't change.
-	S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
-	D AFTER^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
-	;
-	; call event driver
-	D EVT^SDAMEVT(.SDATA,4,SDMODE,SDCIHDL)
-	QUIT 0
-	;
 SCIEN(PAT,CLINIC,DATE)	;PEP; returns ien for appt in ^SC
 	NEW X,IEN
Index: /Scheduling/trunk/m/BSDXAPI1.m
===================================================================
--- /Scheduling/trunk/m/BSDXAPI1.m	(revision 1465)
+++ /Scheduling/trunk/m/BSDXAPI1.m	(revision 1466)
@@ -1,5 +1,48 @@
-BSDXAPI1 ; VEN/SMH - SCHEDULING APIs - Continued!!! ; 6/29/12 11:52am
+BSDXAPI1 ; VEN/SMH - SCHEDULING APIs - Continued!!! ; 7/3/12 12:37pm
 	;;1.7T1;BSDX;;Aug 31, 2011;Build 18
 	; Licensed under LGPL  
+	;
+	; Change History (BSDXAPI and BSDXAPI1)
+	; Pre 1.42:
+	; - Simplified entry points (MAKE1, CANCEL1, CHECKIN1)
+	; 2010-11-5: (1.42)
+	; - Fixed errors having to do uncanceling patient appointments if it was 
+	;   a patient cancelled appointment.
+	; - Use new style Fileman API for storing appointments in file 44 in 
+	;   $$MAKE due to problems with legacy API.
+	; 2010-11-12: (1.42)
+	; - Changed ="C" to ["C" in SCIEN. Cancelled appointments can be "PC" as 
+	;   well. 
+	; 2010-12-5 (1.42)
+	; Added an entry point to update the patient note in file 44.
+	; 2010-12-6 (1.42)
+	; MAKE1 incorrectly put info field in BSDR("INFO") rather than BSDR("OI")
+	; 2010-12-8 (1.42)
+	; Removed restriction on max appt length. Even though this restriction
+	; exists in fileman (120 minutes), PIMS ignores it. Therefore, I 
+	; will ignore it here too.
+	; 2011-01-25 (v.1.5)
+	; Added entry point $$RMCI to remove checked in appointments.
+	; In $$CANCEL, if the appointment is checked in, delete check-in rather than
+	;  spitting an error message to the user saying 'Delete the check-in'
+	; Changed all lines that look like this:
+	;  I $G(BSDR("ADT"))'?7N1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
+	; to:
+	;  I $G(BSDR("ADT"))'?7N.1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
+	; to allow for date at midnight which does not have a dot at the end.
+	; 2011-01-26 (v.1.5)
+	; More user friendly message if patient already has appointment in $$MAKE:
+	;  Spits out pt name and user friendly date.
+	; 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. We
+	; still have the provision to delete the data though if we fail when we 
+	; actually make the appointment.
+	; CANCELCK exists for the same purpose.
+	; CHECKINK ditto
+	; New API: $$NOWSHOW^BSDXAPI1 for no-showing patients
+	; Moved RMCI from BSDXAPI to BSDXAPI1 because BSDXAPI1 is getting larger
+	;  than 20000 characters.
 	;
 NOSHOW(PAT,CLINIC,DATE,NSFLAG) ; $$ PEP; No-show Patient at appt date (new in v1.7)
@@ -41,6 +84,6 @@
 	; 
 	; This M error trigger tests if ^BSDXAPPT rolls back. 
-	; I won't try to roll back ^DPT(,"S"
-	; The M error is caused here, so if I try to rollback, I can cause another
+	; I won't try to roll back ^DPT(,"S" because
+	; the M error is caused here, so if I try to rollback, I can cause another
 	; error. Infinite Errors then.
 	I $D(BSDXSIMERR3) N X S X=1/0
@@ -67,4 +110,8 @@
 	;
 	; Call like this: $$RMCI(233,33,3110102.1130)
+	;
+	; Check to see if we can remove the check-in
+	N BSDXERR S BSDXERR=$$RMCICK(PAT,CLINIC,DATE)
+	I BSDXERR Q BSDXERR
 	;
 	; Move my variables into the ones used by SDAPIs (just a convenience)
@@ -97,4 +144,21 @@
 	QUIT 0
 	;
+RMCICK(PAT,CLINIC,DATE)	;PEP; Can you remove a check-in for this patient?
+	; PAT - DFN by value
+	; CLINIC - ^SC ien by value
+	; DATE - Appointment Date
+	; Output: 0 if okay or 1 if error
+	;
+	; Get appointment IEN in ^SC(DA(2),"S",DA(1),1,
+	N SCIEN S SCIEN=$$SCIEN^BSDXAPI(PAT,CLINIC,DATE)
+	;
+	; If not there, it has been cancelled.
+	I 'SCIEN QUIT 0
+	;
+	; Check if checked out
+	I $$CO^BSDXAPI(PAT,CLINIC,DATE,SCIEN) Q 1_U_"Appointment Already Checked Out"
+	;
+	QUIT 0
+	;
 UPDATENT(PAT,CLINIC,DATE,NOTE)	; PEP; Update Note in ^SC for patient's appointment @ DATE
 	; PAT = DFN
Index: /Scheduling/trunk/m/BSDXUT1.m
===================================================================
--- /Scheduling/trunk/m/BSDXUT1.m	(revision 1465)
+++ /Scheduling/trunk/m/BSDXUT1.m	(revision 1466)
@@ -1,3 +1,3 @@
-BSDXUT1 ; VEN/SMH - Unit Tests for Scheduling GUI - cont. ; 6/29/12 12:32pm
+BSDXUT1 ; VEN/SMH - Unit Tests for Scheduling GUI - cont. ; 7/3/12 12:28pm
 	;;1.7T1;BSDX;;Aug 31, 2011;Build 18
 	;
@@ -94,5 +94,5 @@
 	I APPID=0 W "Error in test 6",!
 	D CHECKIN^BSDX25(.ZZZ,APPID,$$NOW^XLFDT) ; Checkin
-	S BSDXRESULT=$$RMCI^BSDXAPI(DFN,HLIEN,APPTTIME) ; remove checkin
+	S BSDXRESULT=$$RMCI^BSDXAPI1(DFN,HLIEN,APPTTIME) ; remove checkin
 	D APPDEL^BSDX08(.ZZZ,APPID,"PC",10,"Cancel Note") ; delete appt
 	I $P(^BSDXTMP($J,1),$C(30))'="" W "Error in test 6",!
@@ -140,5 +140,5 @@
 	I APPID=0 W "Error in test 6",!
 	D CHECKIN^BSDX25(.ZZZ,APPID,$$NOW^XLFDT) ; Checkin
-	S BSDXRESULT=$$RMCI^BSDXAPI(DFN,HLIEN,APPTTIME) ; remove checkin
+	S BSDXRESULT=$$RMCI^BSDXAPI1(DFN,HLIEN,APPTTIME) ; remove checkin
 	D APPDEL^BSDX08(.ZZZ,APPID,"PC",10,"Cancel Note") ; delete appt
 	I $P(^BSDXTMP($J,1),$C(30))'="" W "Error in test 6",!
@@ -191,5 +191,5 @@
 	I +^BSDXTMP($J,1)=0 W "Error... task not created",! QUIT
 	;
-	W "Waiting for 5 seconds for it to finish",! HANG 5
+	W "Waiting for 5 seconds for taskman to finish",! HANG 5
 	N DFN,APPTTIME S (DFN,APPTTIME)=""
 	F  S DFN=$O(BSDXAPPT(DFN)) Q:'DFN  D
@@ -224,5 +224,5 @@
 	I +^BSDXTMP($J,1)=0 W "Error... task not created",! QUIT
 	;
-	W "Waiting for 5 seconds for it to finish",! HANG 5
+	W "Waiting for 5 seconds for taskman to finish",! HANG 5
 	W:^BSDXTMP("BSDXCOPY",+^BSDXTMP($J,1))'["  0 records" "Copy failed",!
 	QUIT
Index: /Scheduling/trunk/m/BSDXUT2.m
===================================================================
--- /Scheduling/trunk/m/BSDXUT2.m	(revision 1465)
+++ /Scheduling/trunk/m/BSDXUT2.m	(revision 1466)
@@ -1,3 +1,3 @@
-BSDXUT2 ; VEN/SMH - Unit Tests for Scheduling GUI - cont. ; 6/29/12 12:23pm
+BSDXUT2 ; VEN/SMH - Unit Tests for Scheduling GUI - cont. ; 7/3/12 12:03pm
 	;;1.7T1;BSDX;;Aug 31, 2011;Build 18
 	;
@@ -49,9 +49,56 @@
 	IF +^BSDXTMP($J,1)'=-2 WRITE "ERROR IN Etest 2",!
 	; Tests for 3 to 5 difficult to produce
-	; Error tests follow: Mumps error test; Transaction restartability
+	; Error tests follow: Mumps error test;
+	; Error in RMCI
 	N BSDXDIE S BSDXDIE=1
 	D RMCI^BSDX25(.ZZZ,APPTID)
 	IF +^BSDXTMP($J,1)'=-100 WRITE "ERROR IN Etest 3",!
 	K BSDXDIE
+	; M Error in CHECKIN
+	N BSDXDIE S BSDXDIE=1
+	D CHECKIN^BSDX25(.ZZZ,APPTID,$$NOW^XLFDT())
+	IF +^BSDXTMP($J,1)'=-100 WRITE "ERROR IN Etest 8",!
+	K BSDXDIE
+	; M Error in $$CHECKIN^BSDXAPI
+	N BSDXDIE2 S BSDXDIE2=1
+	D CHECKIN^BSDX25(.ZZZ,APPTID,$$NOW^XLFDT())
+	IF +^BSDXTMP($J,1)'=-100 WRITE "ERROR IN Etest 9",!
+	K BSDXDIE2
+	;
+	; Get start and end times
+	N TIMES S TIMES=$$TIMES^BSDXUT ; appt time^end time
+	N APPTTIME S APPTTIME=$P(TIMES,U)
+	N ENDTIME S ENDTIME=$P(TIMES,U,2)
+	;
+	N ZZZ,DFN
+	S DFN=5
+	N ZZZ
+	D APPADD^BSDX07(.ZZZ,APPTTIME,ENDTIME,DFN,RESNAM,30,"Sam's Note",1)
+	N APPTID S APPTID=+^BSDXTMP($J,1)
+	N HL S HL=$$GET1^DIQ(9002018.4,APPTID,".07:.04","I")
+	;
+	; Simulated Error in $$BSDXCHK^BSDX25
+	N BSDXSIMERR1 S BSDXSIMERR1=1
+	D CHECKIN^BSDX25(.ZZZ,APPTID,$$NOW^XLFDT())
+	IF +^BSDXTMP($J,1)'=-3 WRITE "ERROR in Etest 10",!
+	IF $P(^BSDXAPPT(APPTID,0),U,3) WRITE "ERROR IN CHECKIN 111",!
+	IF +$G(^SC(HL,"S",APPTTIME,1,1,"C")) WRITE "ERROR IN CHECKIN 112",!
+	K BSDXSIMERR1
+	;
+	; Simulated Error in $$CHECKICK^BSDXAPI
+	N BSDXSIMERR2 S BSDXSIMERR2=1
+	D CHECKIN^BSDX25(.ZZZ,APPTID,$$NOW^XLFDT())
+	IF +^BSDXTMP($J,1)'=-10 WRITE "ERROR in Etest 11",!
+	IF $P(^BSDXAPPT(APPTID,0),U,3) WRITE "ERROR IN CHECKIN 113",!
+	IF +$G(^SC(HL,"S",APPTTIME,1,1,"C")) WRITE "ERROR IN CHECKIN 114",!
+	K BSDXSIMERR2
+	;
+	; Simulated Error in $$CHECKIN^BSDXAPI
+	N BSDXSIMERR3 S BSDXSIMERR3=1
+	D CHECKIN^BSDX25(.ZZZ,APPTID,$$NOW^XLFDT())
+	IF +^BSDXTMP($J,1)'=-10 WRITE "ERROR in Etest 11",!
+	IF $P(^BSDXAPPT(APPTID,0),U,3) WRITE "ERROR IN CHECKIN 115",!
+	IF +$G(^SC(HL,"S",APPTTIME,1,1,"C")) WRITE "ERROR IN CHECKIN 116",!
+	K BSDXSIMERR3
 	;
 	; Unlinked Clinic Tests
