SDAMA200 ;BPOIFO/ACS-Scheduling Replacement API Errors and Validation ; 12/13/04 3:13pm
;;5.3;Scheduling;**253,275,310,283,347,1015**;13 Aug 1993;Build 21
;
;*******************************************************************
; CHANGE LOG
;
; DATE PATCH DESCRIPTION
;-------- ---------- -------------------------------------
;09/20/02 SD*5.3*253 ROUTINE COMPLETED
;12/10/02 SD*5.3*275 ADDED PATIENT STATUS FILTER AND VALIDATION
;08/15/03 SD*5.3*310 ADD ERROR 114
;08/19/03 SD*5.3*283 ADDED 'NT' APPT STATUS MULTIPLE APPT STATUS
; VALUES ALLOWED, NULL FIELD LIST ALLOWED.
; REMOVED ERROR CODE 107.
;07/26/04 SD*5.3*347 NEW VARIABLES USED IN ^%DTC CALL.
; ALLOW FOR APPOINTMENT STATUSES R,NT OR
; R AND NT TO BE PASSED IF THE PATIENT STATUS
; IS SET TO O.
;
;*******************************************************************
;-------------------------------------------------------------------
; *** VALIDATE INPUT PARAMETERS ***
;INPUT
; SDIEN Patient, clinic, or facility IEN (required)
; SDFIELDS Fields requested (optional)
; SDAPSTAT Appointment status (optional)
; SDSTART Start date (optional)
; SDEND End date (optional)
; SDAPINAM The API that is calling this routine (required)
; SDRTNNAM The routine that is calling this routine (required)
; SDIOSTAT Patient status filter
;-------------------------------------------------------------------
;
VALIDATE(SDIEN,SDFIELDS,SDAPSTAT,SDSTART,SDEND,SDAPINAM,SDRTNNAM,SDIOSTAT) ;
;
N SDERRFLG
S SDERRFLG=0
;Validate IEN
I $G(SDIEN)="" D ERROR($S(SDAPINAM="GETPLIST":104,1:102),SDAPINAM,.SDERRFLG,SDRTNNAM)
I $G(SDIEN)'="",+$G(SDIEN)'=$G(SDIEN) D ERROR(110,SDAPINAM,.SDERRFLG,SDRTNNAM)
;
;Validate Appointment Status Filter
I $L($G(SDAPSTAT))>0 D
. ;validate each status, build new status list if necessary
. N SDNUM,SDPIECE,SDQUIT,SDAPVAL,SDNEWAP
. S SDQUIT=0
. ;get count of values passed in
. S SDNUM=$L(SDAPSTAT,";")
. S SDNEWAP=";"
. ;check each value passed in
. F SDPIECE=1:1:SDNUM S SDAPVAL=$P(SDAPSTAT,";",SDPIECE) D Q:SDQUIT=1
.. I $G(SDAPVAL)="" D ERROR(109,SDAPINAM,.SDERRFLG,SDRTNNAM) S SDQUIT=1 Q
.. I ";R;C;N;NT;"'[(";"_SDAPVAL_";") D ERROR(109,SDAPINAM,.SDERRFLG,SDRTNNAM) S SDQUIT=1 Q
.. ;build status string
.. S SDNEWAP=SDNEWAP_SDAPVAL_";"
.S SDAPSTAT=SDNEWAP
;set appointment status filter to 'all' if null or undefined
I $G(SDAPSTAT)="" S SDAPSTAT=";R;C;N;NT;"
;
;Validate start and end date/time variables if they are passed in
N SDSTVAL,SDENDVAL,%H,%T,%Y,X
S (SDSTVAL,SDENDVAL)=0
I $G(SDSTART)'="" D
. I +SDSTART'=SDSTART D ERROR(105,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
. S X=SDSTART D H^%DTC I %H=0 D ERROR(105,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
. S SDSTVAL=1
I $G(SDEND)'="" D
. I +SDEND'=SDEND D ERROR(106,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
. S X=SDEND D H^%DTC I %H=0 D ERROR(106,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
. S SDENDVAL=1
;If start and end dates are valid, make sure start date not > end date
I SDSTVAL,SDENDVAL D
. I SDSTART>SDEND D ERROR(111,SDAPINAM,.SDERRFLG,SDRTNNAM)
;
;Remove beginning and ending semi-colons from SDFIELDS list if present
I $L($G(SDFIELDS))>0 D
. I $E($G(SDFIELDS),1,1)=";" D
.. S SDFIELDS=$E(SDFIELDS,2,$L(SDFIELDS))
.. I $G(SDFIELDS)="" D ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM)
.I $L($G(SDFIELDS))>0 D
.. I $E($G(SDFIELDS),$L($G(SDFIELDS)),$L($G(SDFIELDS)))=";" D
... S SDFIELDS=$E(SDFIELDS,1,$L(SDFIELDS)-1)
... I $G(SDFIELDS)="" D ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM)
;
;Validate SDFIELDS list
N SDI,SDFIELD,SDNUM,SDEND
S (SDI,SDFIELD,SDNUM,SDEND)=0
;Check field list for valid numbers requested
I $G(SDFIELDS)]"" D
. ;get number of pieces
. S SDNUM=$L(SDFIELDS,";")
. ;validate each piece
. F SDI=1:1:SDNUM S SDFIELD=$P(SDFIELDS,";",SDI) D Q:SDEND
.. I $G(SDFIELD)="" D ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM) S SDEND=1 Q
.. I '$D(^SDAM(44.3,SDFIELD)) D ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM) S SDEND=1 Q
;If field list is null and API is not NEXTAPPT, set up to include all
I ($G(SDFIELDS)="")&(SDAPINAM'="NEXTAPPT") S SDI=0 D
. F S SDI=$O(^SDAM(44.3,SDI)) Q:+$G(SDI)=0 D
.. S SDFIELDS=$G(SDFIELDS)_SDI_";"
. ;remove ending semi-colon
. S SDFIELDS=$E(SDFIELDS,1,$L(SDFIELDS)-1)
;
;Validate Patient Status Filter
I $L($G(SDIOSTAT))>0 D
. I $L(SDIOSTAT)>1 D ERROR(112,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
. I "IO"'[SDIOSTAT D ERROR(112,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
;set patient status filter to 'both' if null or undefined
I $G(SDIOSTAT)="" S SDIOSTAT="IO"
;
;Validate Appt Status and Patient Status Filter Combination
;if they specify a patient status, they must specify scheduled/kept appt type "R"
I $G(SDIOSTAT)="I",$G(SDAPSTAT)'=";R;" D ERROR(113,SDAPINAM,.SDERRFLG,SDRTNNAM)
I $G(SDIOSTAT)="O",$S($G(SDAPSTAT)=";R;":0,$G(SDAPSTAT)=";NT;":0,$G(SDAPSTAT)=";R;NT;":0,$G(SDAPSTAT)=";NT;R;":0,1:1) D ERROR(113,SDAPINAM,.SDERRFLG,SDRTNNAM)
;
I SDERRFLG>0 Q -1
Q 1
;
ERROR(SDERRNUM,SDAPINAM,SDERRFLG,SDRTNNAM) ;
;Put error message in ^TMP global
S SDERRFLG=1
S $P(^TMP($J,SDRTNNAM,SDAPINAM,"ERROR",SDERRNUM),"^",1)=$P($T(@SDERRNUM),";;",2)
Q
;
;***************************************************************
; ERROR CODES AND MESSAGES USED FOR PARAMETER VALIDATION
;***************************************************************
;
101 ;;DATABASE IS UNAVAILABLE
102 ;;PATIENT ID IS REQUIRED
103 ;;INVALID FIELD LIST
104 ;;CLINIC ID IS REQUIRED
105 ;;INVALID START DATE
106 ;;INVALID END DATE
108 ;;FACILITY ID IS REQUIRED
109 ;;INVALID APPOINTMENT STATUS FILTER
110 ;;ID MUST BE NUMERIC
111 ;;START DATE CAN'T BE AFTER END DATE
112 ;;INVALID PATIENT STATUS FILTER
113 ;;APPT STATUS AND PATIENT STATUS FILTER COMBINATION UNSUPPORTED IN VISTA
114 ;;INVALID PATIENT ID
116 ;;DATA MISMATCH
117 ;;SDAPI ERROR
;
;------------------------------------------------------------------
;Additional APIs called from GETAPPT, GETPLIST, NEXTAPPT, GETALLCL
;------------------------------------------------------------------
;
PATAPPT(SDPATIEN) ;For a patient IEN, return Boolean value for existence of appointments on ^DPT
I $D(^DPT(SDPATIEN,"S")) Q 1
Q 0
;
CLNAPPT(SDCLIEN) ;For a clinic IEN, return Boolean value for existence of appointments on ^SC
I $D(^SC($G(SDCLIEN),"S")) Q 1
Q 0
GETCLIEN(SDPATIEN,SDAPPTDT) ; For a patient and appt date, return the clinic IEN on ^DPT
Q $P($G(^DPT($G(SDPATIEN),"S",$G(SDAPPTDT),0)),"^",1)
;
GETPTIEN(SDCLIEN,SDAPPTDT,SDPATCNT) ; For a clinic, appt date, and node, return the patient IEN on ^SC
Q $P($G(^SC($G(SDCLIEN),"S",$G(SDAPPTDT),1,$G(SDPATCNT),0)),"^",1)
;
GETSDDA(SDCLIEN,SDAPPTDT,SDPATIEN) ; For a clinic, appt date, and patient, return the SDDA node number on ^SC
N SDPATCNT,SDMATCH
S SDPATCNT=0,SDMATCH=0
F S SDPATCNT=$O(^SC($G(SDCLIEN),"S",$G(SDAPPTDT),1,SDPATCNT)) D Q:('SDPATCNT!SDMATCH)
. I 'SDPATCNT Q
. I $P($G(^SC(SDCLIEN,"S",SDAPPTDT,1,SDPATCNT,0)),"^",1)=SDPATIEN S SDMATCH=1
Q $G(SDPATCNT)
;
GETASTAT(SDPATIEN,SDAPPTDT) ;For a patient and appt date, return Appointment Status (N, C, R, or NT)
N SDSTAT
S SDSTAT=$P($G(^DPT(SDPATIEN,"S",SDAPPTDT,0)),"^",2)
S SDSTAT=$S($G(SDSTAT)="NT":"NT",$G(SDSTAT)="I":"R",$G(SDSTAT)["N":"N",$G(SDSTAT)["C":"C",1:"R")
Q SDSTAT
;
GETPSTAT(SDPATIEN,SDAPPTDT) ;For a patient and appt date, return Patient Status (I or O)
N SDSTAT
S SDSTAT=$P($G(^DPT(SDPATIEN,"S",SDAPPTDT,0)),"^",2)
S SDSTAT=$S($G(SDSTAT)="I":"I",1:"O")
Q SDSTAT
;
SDAMA200 ;BPOIFO/ACS-Scheduling Replacement API Errors and Validation ; 12/13/04 3:13pm
+1 ;;5.3;Scheduling;**253,275,310,283,347,1015**;13 Aug 1993;Build 21
+2 ;
+3 ;*******************************************************************
+4 ; CHANGE LOG
+5 ;
+6 ; DATE PATCH DESCRIPTION
+7 ;-------- ---------- -------------------------------------
+8 ;09/20/02 SD*5.3*253 ROUTINE COMPLETED
+9 ;12/10/02 SD*5.3*275 ADDED PATIENT STATUS FILTER AND VALIDATION
+10 ;08/15/03 SD*5.3*310 ADD ERROR 114
+11 ;08/19/03 SD*5.3*283 ADDED 'NT' APPT STATUS MULTIPLE APPT STATUS
+12 ; VALUES ALLOWED, NULL FIELD LIST ALLOWED.
+13 ; REMOVED ERROR CODE 107.
+14 ;07/26/04 SD*5.3*347 NEW VARIABLES USED IN ^%DTC CALL.
+15 ; ALLOW FOR APPOINTMENT STATUSES R,NT OR
+16 ; R AND NT TO BE PASSED IF THE PATIENT STATUS
+17 ; IS SET TO O.
+18 ;
+19 ;*******************************************************************
+20 ;-------------------------------------------------------------------
+21 ; *** VALIDATE INPUT PARAMETERS ***
+22 ;INPUT
+23 ; SDIEN Patient, clinic, or facility IEN (required)
+24 ; SDFIELDS Fields requested (optional)
+25 ; SDAPSTAT Appointment status (optional)
+26 ; SDSTART Start date (optional)
+27 ; SDEND End date (optional)
+28 ; SDAPINAM The API that is calling this routine (required)
+29 ; SDRTNNAM The routine that is calling this routine (required)
+30 ; SDIOSTAT Patient status filter
+31 ;-------------------------------------------------------------------
+32 ;
VALIDATE(SDIEN,SDFIELDS,SDAPSTAT,SDSTART,SDEND,SDAPINAM,SDRTNNAM,SDIOSTAT) ;
+1 ;
+2 NEW SDERRFLG
+3 SET SDERRFLG=0
+4 ;Validate IEN
+5 IF $GET(SDIEN)=""
DO ERROR($SELECT(SDAPINAM="GETPLIST":104,1:102),SDAPINAM,.SDERRFLG,SDRTNNAM)
+6 IF $GET(SDIEN)'=""
IF +$GET(SDIEN)'=$GET(SDIEN)
DO ERROR(110,SDAPINAM,.SDERRFLG,SDRTNNAM)
+7 ;
+8 ;Validate Appointment Status Filter
+9 IF $LENGTH($GET(SDAPSTAT))>0
Begin DoDot:1
+10 ;validate each status, build new status list if necessary
+11 NEW SDNUM,SDPIECE,SDQUIT,SDAPVAL,SDNEWAP
+12 SET SDQUIT=0
+13 ;get count of values passed in
+14 SET SDNUM=$LENGTH(SDAPSTAT,";")
+15 SET SDNEWAP=";"
+16 ;check each value passed in
+17 FOR SDPIECE=1:1:SDNUM
SET SDAPVAL=$PIECE(SDAPSTAT,";",SDPIECE)
Begin DoDot:2
+18 IF $GET(SDAPVAL)=""
DO ERROR(109,SDAPINAM,.SDERRFLG,SDRTNNAM)
SET SDQUIT=1
QUIT
+19 IF ";R;C;N;NT;"'[(";"_SDAPVAL_";")
DO ERROR(109,SDAPINAM,.SDERRFLG,SDRTNNAM)
SET SDQUIT=1
QUIT
+20 ;build status string
+21 SET SDNEWAP=SDNEWAP_SDAPVAL_";"
End DoDot:2
IF SDQUIT=1
QUIT
+22 SET SDAPSTAT=SDNEWAP
End DoDot:1
+23 ;set appointment status filter to 'all' if null or undefined
+24 IF $GET(SDAPSTAT)=""
SET SDAPSTAT=";R;C;N;NT;"
+25 ;
+26 ;Validate start and end date/time variables if they are passed in
+27 NEW SDSTVAL,SDENDVAL,%H,%T,%Y,X
+28 SET (SDSTVAL,SDENDVAL)=0
+29 IF $GET(SDSTART)'=""
Begin DoDot:1
+30 IF +SDSTART'=SDSTART
DO ERROR(105,SDAPINAM,.SDERRFLG,SDRTNNAM)
QUIT
+31 SET X=SDSTART
DO H^%DTC
IF %H=0
DO ERROR(105,SDAPINAM,.SDERRFLG,SDRTNNAM)
QUIT
+32 SET SDSTVAL=1
End DoDot:1
+33 IF $GET(SDEND)'=""
Begin DoDot:1
+34 IF +SDEND'=SDEND
DO ERROR(106,SDAPINAM,.SDERRFLG,SDRTNNAM)
QUIT
+35 SET X=SDEND
DO H^%DTC
IF %H=0
DO ERROR(106,SDAPINAM,.SDERRFLG,SDRTNNAM)
QUIT
+36 SET SDENDVAL=1
End DoDot:1
+37 ;If start and end dates are valid, make sure start date not > end date
+38 IF SDSTVAL
IF SDENDVAL
Begin DoDot:1
+39 IF SDSTART>SDEND
DO ERROR(111,SDAPINAM,.SDERRFLG,SDRTNNAM)
End DoDot:1
+40 ;
+41 ;Remove beginning and ending semi-colons from SDFIELDS list if present
+42 IF $LENGTH($GET(SDFIELDS))>0
Begin DoDot:1
+43 IF $EXTRACT($GET(SDFIELDS),1,1)=";"
Begin DoDot:2
+44 SET SDFIELDS=$EXTRACT(SDFIELDS,2,$LENGTH(SDFIELDS))
+45 IF $GET(SDFIELDS)=""
DO ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM)
End DoDot:2
+46 IF $LENGTH($GET(SDFIELDS))>0
Begin DoDot:2
+47 IF $EXTRACT($GET(SDFIELDS),$LENGTH($GET(SDFIELDS)),$LENGTH($GET(SDFIELDS)))=";"
Begin DoDot:3
+48 SET SDFIELDS=$EXTRACT(SDFIELDS,1,$LENGTH(SDFIELDS)-1)
+49 IF $GET(SDFIELDS)=""
DO ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM)
End DoDot:3
End DoDot:2
End DoDot:1
+50 ;
+51 ;Validate SDFIELDS list
+52 NEW SDI,SDFIELD,SDNUM,SDEND
+53 SET (SDI,SDFIELD,SDNUM,SDEND)=0
+54 ;Check field list for valid numbers requested
+55 IF $GET(SDFIELDS)]""
Begin DoDot:1
+56 ;get number of pieces
+57 SET SDNUM=$LENGTH(SDFIELDS,";")
+58 ;validate each piece
+59 FOR SDI=1:1:SDNUM
SET SDFIELD=$PIECE(SDFIELDS,";",SDI)
Begin DoDot:2
+60 IF $GET(SDFIELD)=""
DO ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM)
SET SDEND=1
QUIT
+61 IF '$DATA(^SDAM(44.3,SDFIELD))
DO ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM)
SET SDEND=1
QUIT
End DoDot:2
IF SDEND
QUIT
End DoDot:1
+62 ;If field list is null and API is not NEXTAPPT, set up to include all
+63 IF ($GET(SDFIELDS)="")&(SDAPINAM'="NEXTAPPT")
SET SDI=0
Begin DoDot:1
+64 FOR
SET SDI=$ORDER(^SDAM(44.3,SDI))
IF +$GET(SDI)=0
QUIT
Begin DoDot:2
+65 SET SDFIELDS=$GET(SDFIELDS)_SDI_";"
End DoDot:2
+66 ;remove ending semi-colon
+67 SET SDFIELDS=$EXTRACT(SDFIELDS,1,$LENGTH(SDFIELDS)-1)
End DoDot:1
+68 ;
+69 ;Validate Patient Status Filter
+70 IF $LENGTH($GET(SDIOSTAT))>0
Begin DoDot:1
+71 IF $LENGTH(SDIOSTAT)>1
DO ERROR(112,SDAPINAM,.SDERRFLG,SDRTNNAM)
QUIT
+72 IF "IO"'[SDIOSTAT
DO ERROR(112,SDAPINAM,.SDERRFLG,SDRTNNAM)
QUIT
End DoDot:1
+73 ;set patient status filter to 'both' if null or undefined
+74 IF $GET(SDIOSTAT)=""
SET SDIOSTAT="IO"
+75 ;
+76 ;Validate Appt Status and Patient Status Filter Combination
+77 ;if they specify a patient status, they must specify scheduled/kept appt type "R"
+78 IF $GET(SDIOSTAT)="I"
IF $GET(SDAPSTAT)'=";R;"
DO ERROR(113,SDAPINAM,.SDERRFLG,SDRTNNAM)
+79 IF $GET(SDIOSTAT)="O"
IF $SELECT($GET(SDAPSTAT)=";R;":0,$GET(SDAPSTAT)=";NT;":0,$GET(SDAPSTAT)=";R;NT;":0,$GET(SDAPSTAT)=";NT;R;":0,1:1)
DO ERROR(113,SDAPINAM,.SDERRFLG,SDRTNNAM)
+80 ;
+81 IF SDERRFLG>0
QUIT -1
+82 QUIT 1
+83 ;
ERROR(SDERRNUM,SDAPINAM,SDERRFLG,SDRTNNAM) ;
+1 ;Put error message in ^TMP global
+2 SET SDERRFLG=1
+3 SET $PIECE(^TMP($JOB,SDRTNNAM,SDAPINAM,"ERROR",SDERRNUM),"^",1)=$PIECE($TEXT(@SDERRNUM),";;",2)
+4 QUIT
+5 ;
+6 ;***************************************************************
+7 ; ERROR CODES AND MESSAGES USED FOR PARAMETER VALIDATION
+8 ;***************************************************************
+9 ;
101 ;;DATABASE IS UNAVAILABLE
102 ;;PATIENT ID IS REQUIRED
103 ;;INVALID FIELD LIST
104 ;;CLINIC ID IS REQUIRED
105 ;;INVALID START DATE
106 ;;INVALID END DATE
108 ;;FACILITY ID IS REQUIRED
109 ;;INVALID APPOINTMENT STATUS FILTER
110 ;;ID MUST BE NUMERIC
111 ;;START DATE CAN'T BE AFTER END DATE
112 ;;INVALID PATIENT STATUS FILTER
113 ;;APPT STATUS AND PATIENT STATUS FILTER COMBINATION UNSUPPORTED IN VISTA
114 ;;INVALID PATIENT ID
116 ;;DATA MISMATCH
117 ;;SDAPI ERROR
+1 ;
+2 ;------------------------------------------------------------------
+3 ;Additional APIs called from GETAPPT, GETPLIST, NEXTAPPT, GETALLCL
+4 ;------------------------------------------------------------------
+5 ;
PATAPPT(SDPATIEN) ;For a patient IEN, return Boolean value for existence of appointments on ^DPT
+1 IF $DATA(^DPT(SDPATIEN,"S"))
QUIT 1
+2 QUIT 0
+3 ;
CLNAPPT(SDCLIEN) ;For a clinic IEN, return Boolean value for existence of appointments on ^SC
+1 IF $DATA(^SC($GET(SDCLIEN),"S"))
QUIT 1
+2 QUIT 0
GETCLIEN(SDPATIEN,SDAPPTDT) ; For a patient and appt date, return the clinic IEN on ^DPT
+1 QUIT $PIECE($GET(^DPT($GET(SDPATIEN),"S",$GET(SDAPPTDT),0)),"^",1)
+2 ;
GETPTIEN(SDCLIEN,SDAPPTDT,SDPATCNT) ; For a clinic, appt date, and node, return the patient IEN on ^SC
+1 QUIT $PIECE($GET(^SC($GET(SDCLIEN),"S",$GET(SDAPPTDT),1,$GET(SDPATCNT),0)),"^",1)
+2 ;
GETSDDA(SDCLIEN,SDAPPTDT,SDPATIEN) ; For a clinic, appt date, and patient, return the SDDA node number on ^SC
+1 NEW SDPATCNT,SDMATCH
+2 SET SDPATCNT=0
SET SDMATCH=0
+3 FOR
SET SDPATCNT=$ORDER(^SC($GET(SDCLIEN),"S",$GET(SDAPPTDT),1,SDPATCNT))
Begin DoDot:1
+4 IF 'SDPATCNT
QUIT
+5 IF $PIECE($GET(^SC(SDCLIEN,"S",SDAPPTDT,1,SDPATCNT,0)),"^",1)=SDPATIEN
SET SDMATCH=1
End DoDot:1
IF ('SDPATCNT!SDMATCH)
QUIT
+6 QUIT $GET(SDPATCNT)
+7 ;
GETASTAT(SDPATIEN,SDAPPTDT) ;For a patient and appt date, return Appointment Status (N, C, R, or NT)
+1 NEW SDSTAT
+2 SET SDSTAT=$PIECE($GET(^DPT(SDPATIEN,"S",SDAPPTDT,0)),"^",2)
+3 SET SDSTAT=$SELECT($GET(SDSTAT)="NT":"NT",$GET(SDSTAT)="I":"R",$GET(SDSTAT)["N":"N",$GET(SDSTAT)["C":"C",1:"R")
+4 QUIT SDSTAT
+5 ;
GETPSTAT(SDPATIEN,SDAPPTDT) ;For a patient and appt date, return Patient Status (I or O)
+1 NEW SDSTAT
+2 SET SDSTAT=$PIECE($GET(^DPT(SDPATIEN,"S",SDAPPTDT,0)),"^",2)
+3 SET SDSTAT=$SELECT($GET(SDSTAT)="I":"I",1:"O")
+4 QUIT SDSTAT
+5 ;