SDAMA308 ;BPOIFO/JFW-Filter API Appointment Statuses; 5/10/04 8:13am [5/17/04 10:14am]
;;5.3;Scheduling;**301,406**;13 Aug 1993
;
;** GET APPOINTMENT STATUS **
; - Replaces $$STATUS^SDAM1 -
;*****************************************************************
; CHANGE LOG
;
; DATE PATCH DESCRIPTION
;-------- ---------- -----------------------------------------
;12/04/03 SD*5.3*301 ROUTINE COMPLETED
;10/11/06 SD*5.3*406 PRINT STATUS TEXT UPDATED
;
;*****************************************************************
;
STATUS(DFN,SDT,SDCL,SDSTS,SDCHKIN,SDCHKOUT,SDEIFN) ;Retrieve Appointment Status
;
; Input: DFN := IFN of Patient
; SDT := Appointment Date/Time (FM Format)
; SDCL := IFN of Clinic
; SDSTS := Current VistA Appointment Status (Optional)
; SDCHKIN := Appointment Check-In Date/Time (Optional)
; SDCHKOUT := Appointment Check-Out Date/Time (Optional)
; SDEIFN := Outpatient Encounter IFN for Appointment (Optional)
; Output: Appoinment Status IFN ; Status Name ; Print Status ;
; Check In Date/Time ; Check Out Date/Time ;
; Admission Movement IFN
; -1 if errors with DFN,SDT or SDCL
;
; Initialize Global Variables
N SDI,SDQUIT,SDCODE,SDSTSD,SDPSTS,SDINDCTR,SDAMVT,VADMVT,VAINDT
S SDQUIT=0
;Validate parameters
F SDI="VDFN","FMDATE","VCLIN" Q:SDQUIT D @SDI
Q:SDQUIT -1
; Set initial Status value, if no value set to NULL
S SDSTSD=$S($G(SDSTS)]"":$P($T(@SDSTS),";;",3),1:"")
; No R appt status in original VistA code
S:$G(SDSTS)="R" SDSTSD=""
; If Status is null check for non-count clinic
I $G(SDSTSD)="" S SDCODE=$$GETSTOP^SDAMA305($G(SDCL)) S:$P($G(SDCODE),"^",3)="Y" SDSTSD="NON-COUNT"
;Get admission movement ifn
S VAINDT=$G(SDT) D ADM^VADPT2
;Inpatient? (Check Status, Admission IFN?, Domicillary Ward?, Ward Location = "D"?)
I SDSTSD["INPATIENT",$S('+VADMVT:1,'$P(^DG(43,1,0),"^",21):0,1:$P($G(^DIC(42,+$P($G(^DGPM(VADMVT,0)),"^",6),0)),"^",3)="D") S SDSTSD=""
; Determine Checked In/Out Indicator
S SDINDCTR=$S(+$G(SDCHKOUT):"CHECKED OUT",+$G(SDCHKIN):"CHECKED IN",SDSTSD]"":"",$G(SDT)>(DT+.2359):"FUTURE",1:"NO ACTION TAKEN") S:SDSTSD="" SDSTSD=SDINDCTR
I SDSTSD="NO ACTION TAKEN",$P($G(SDT),".")=DT,SDINDCTR'["CHECKED" S SDINDCTR="TODAY"
I SDSTSD="CHECKED OUT"!(SDSTSD="CHECKED IN"),SDT'<$$REQDT^SDM1A,'$P($G(^SCE(+$G(SDEIFN),0)),"^",7) S SDSTSD="NO ACTION TAKEN"
; Determine PRINT STATUS
S SDPSTS=$S(SDSTSD=SDINDCTR!(SDINDCTR=""):SDSTSD,1:"")
I SDPSTS="" D
.I SDSTSD["INPATIENT",$P($G(^SC(SDCL,0)),U,17)'="Y",$P($G(^SCE(+$G(SDEIFN),0)),U,7)="" S SDPSTS=$P(SDSTSD," ")_"/ACT REQ" Q
.I SDSTSD="NO ACTION TAKEN",SDINDCTR="CHECKED OUT"!(SDINDCTR="CHECKED IN") S SDPSTS="ACT REQ/"_SDINDCTR Q
.S SDPSTS=$S(SDSTSD="NO ACTION TAKEN":SDSTSD,1:$P(SDSTSD," "))_"/"_SDINDCTR
I SDSTSD["INPATIENT",SDINDCTR="" D
.I SDT>(DT+.2359) S SDPSTS=$P(SDSTSD," ")_"/FUTURE" Q
.S SDPSTS=$P(SDSTSD," ")_"/NO ACT TAKN"
;Get Appointment Status IFN
S SDAMVT=+$O(^SD(409.63,"AC",SDSTSD,0))
Q SDAMVT_";"_SDSTSD_";"_SDPSTS_";"_$G(SDCHKIN)_";"_$G(SDCHKOUT)_";"_+VADMVT
VDFN ; Verify for valid patient dfn
I $G(DFN)="" S SDQUIT=1
E I '$D(^DPT(DFN)) S SDQUIT=1
Q
VCLIN ; Verify for valid clinic dfn
I $G(SDCL)="" S SDQUIT=1
E I '$D(^SC(SDCL,0)) S SDQUIT=1
Q
FMDATE ;
; Appointment Date must be a valid internal FileMan Format
N X,Y,%H,%T,%Y
S Y=$G(SDT) D DD^%DT I Y=-1 S SDQUIT=1
; Appointment Date cannot be imprecise
I 'SDQUIT S X=$G(SDT) D H^%DTC I %H=0 S SDQUIT=1
Q
;
;LIST OF VISTA STATUS CODES /NEW DESCRIPTIONS /OLD DESCRIPTIONS
CC ;;CANCELLED BY CLINIC;;CANCELLED BY CLINIC
CCR ;;CANCELLED BY CLINIC & RESCHEDULED;;CANCELLED BY CLINIC & AUTO RE-BOOK
CP ;;CANCELLED BY PATIENT;;CANCELLED BY PATIENT
CPR ;;CANCELLED BY PATIENT & RESCHEDULED;;CANCELLED BY PATIENT & AUTO-REBOOK
R ;;SCHEDULED/KEPT;;
I ;;INPATIENT;;INPATIENT APPOINTMENT
NS ;;NO-SHOW;;NO-SHOW
NSR ;;NO-SHOW & RESCHEDULED;;NO-SHOW & AUTO RE-BOOK
NT ;;NO ACTION TAKEN;;NO ACTION TAKEN
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDAMA308 4224 printed Dec 13, 2024@02:47:23 Page 2
SDAMA308 ;BPOIFO/JFW-Filter API Appointment Statuses; 5/10/04 8:13am [5/17/04 10:14am]
+1 ;;5.3;Scheduling;**301,406**;13 Aug 1993
+2 ;
+3 ;** GET APPOINTMENT STATUS **
+4 ; - Replaces $$STATUS^SDAM1 -
+5 ;*****************************************************************
+6 ; CHANGE LOG
+7 ;
+8 ; DATE PATCH DESCRIPTION
+9 ;-------- ---------- -----------------------------------------
+10 ;12/04/03 SD*5.3*301 ROUTINE COMPLETED
+11 ;10/11/06 SD*5.3*406 PRINT STATUS TEXT UPDATED
+12 ;
+13 ;*****************************************************************
+14 ;
STATUS(DFN,SDT,SDCL,SDSTS,SDCHKIN,SDCHKOUT,SDEIFN) ;Retrieve Appointment Status
+1 ;
+2 ; Input: DFN := IFN of Patient
+3 ; SDT := Appointment Date/Time (FM Format)
+4 ; SDCL := IFN of Clinic
+5 ; SDSTS := Current VistA Appointment Status (Optional)
+6 ; SDCHKIN := Appointment Check-In Date/Time (Optional)
+7 ; SDCHKOUT := Appointment Check-Out Date/Time (Optional)
+8 ; SDEIFN := Outpatient Encounter IFN for Appointment (Optional)
+9 ; Output: Appoinment Status IFN ; Status Name ; Print Status ;
+10 ; Check In Date/Time ; Check Out Date/Time ;
+11 ; Admission Movement IFN
+12 ; -1 if errors with DFN,SDT or SDCL
+13 ;
+14 ; Initialize Global Variables
+15 NEW SDI,SDQUIT,SDCODE,SDSTSD,SDPSTS,SDINDCTR,SDAMVT,VADMVT,VAINDT
+16 SET SDQUIT=0
+17 ;Validate parameters
+18 FOR SDI="VDFN","FMDATE","VCLIN"
if SDQUIT
QUIT
DO @SDI
+19 if SDQUIT
QUIT -1
+20 ; Set initial Status value, if no value set to NULL
+21 SET SDSTSD=$SELECT($GET(SDSTS)]"":$PIECE($TEXT(@SDSTS),";;",3),1:"")
+22 ; No R appt status in original VistA code
+23 if $GET(SDSTS)="R"
SET SDSTSD=""
+24 ; If Status is null check for non-count clinic
+25 IF $GET(SDSTSD)=""
SET SDCODE=$$GETSTOP^SDAMA305($GET(SDCL))
if $PIECE($GET(SDCODE),"^",3)="Y"
SET SDSTSD="NON-COUNT"
+26 ;Get admission movement ifn
+27 SET VAINDT=$GET(SDT)
DO ADM^VADPT2
+28 ;Inpatient? (Check Status, Admission IFN?, Domicillary Ward?, Ward Location = "D"?)
+29 IF SDSTSD["INPATIENT"
IF $SELECT('+VADMVT:1,'$PIECE(^DG(43,1,0),"^",21):0,1:$PIECE($GET(^DIC(42,+$PIECE($GET(^DGPM(VADMVT,0)),"^",6),0)),"^",3)="D")
SET SDSTSD=""
+30 ; Determine Checked In/Out Indicator
+31 SET SDINDCTR=$SELECT(+$GET(SDCHKOUT):"CHECKED OUT",+$GET(SDCHKIN):"CHECKED IN",SDSTSD]"":"",$GET(SDT)>(DT+.2359):"FUTURE",1:"NO ACTION TAKEN")
if SDSTSD=""
SET SDSTSD=SDINDCTR
+32 IF SDSTSD="NO ACTION TAKEN"
IF $PIECE($GET(SDT),".")=DT
IF SDINDCTR'["CHECKED"
SET SDINDCTR="TODAY"
+33 IF SDSTSD="CHECKED OUT"!(SDSTSD="CHECKED IN")
IF SDT'<$$REQDT^SDM1A
IF '$PIECE($GET(^SCE(+$GET(SDEIFN),0)),"^",7)
SET SDSTSD="NO ACTION TAKEN"
+34 ; Determine PRINT STATUS
+35 SET SDPSTS=$SELECT(SDSTSD=SDINDCTR!(SDINDCTR=""):SDSTSD,1:"")
+36 IF SDPSTS=""
Begin DoDot:1
+37 IF SDSTSD["INPATIENT"
IF $PIECE($GET(^SC(SDCL,0)),U,17)'="Y"
IF $PIECE($GET(^SCE(+$GET(SDEIFN),0)),U,7)=""
SET SDPSTS=$PIECE(SDSTSD," ")_"/ACT REQ"
QUIT
+38 IF SDSTSD="NO ACTION TAKEN"
IF SDINDCTR="CHECKED OUT"!(SDINDCTR="CHECKED IN")
SET SDPSTS="ACT REQ/"_SDINDCTR
QUIT
+39 SET SDPSTS=$SELECT(SDSTSD="NO ACTION TAKEN":SDSTSD,1:$PIECE(SDSTSD," "))_"/"_SDINDCTR
End DoDot:1
+40 IF SDSTSD["INPATIENT"
IF SDINDCTR=""
Begin DoDot:1
+41 IF SDT>(DT+.2359)
SET SDPSTS=$PIECE(SDSTSD," ")_"/FUTURE"
QUIT
+42 SET SDPSTS=$PIECE(SDSTSD," ")_"/NO ACT TAKN"
End DoDot:1
+43 ;Get Appointment Status IFN
+44 SET SDAMVT=+$ORDER(^SD(409.63,"AC",SDSTSD,0))
+45 QUIT SDAMVT_";"_SDSTSD_";"_SDPSTS_";"_$GET(SDCHKIN)_";"_$GET(SDCHKOUT)_";"_+VADMVT
VDFN ; Verify for valid patient dfn
+1 IF $GET(DFN)=""
SET SDQUIT=1
+2 IF '$TEST
IF '$DATA(^DPT(DFN))
SET SDQUIT=1
+3 QUIT
VCLIN ; Verify for valid clinic dfn
+1 IF $GET(SDCL)=""
SET SDQUIT=1
+2 IF '$TEST
IF '$DATA(^SC(SDCL,0))
SET SDQUIT=1
+3 QUIT
FMDATE ;
+1 ; Appointment Date must be a valid internal FileMan Format
+2 NEW X,Y,%H,%T,%Y
+3 SET Y=$GET(SDT)
DO DD^%DT
IF Y=-1
SET SDQUIT=1
+4 ; Appointment Date cannot be imprecise
+5 IF 'SDQUIT
SET X=$GET(SDT)
DO H^%DTC
IF %H=0
SET SDQUIT=1
+6 QUIT
+7 ;
+8 ;LIST OF VISTA STATUS CODES /NEW DESCRIPTIONS /OLD DESCRIPTIONS
CC ;;CANCELLED BY CLINIC;;CANCELLED BY CLINIC
CCR ;;CANCELLED BY CLINIC & RESCHEDULED;;CANCELLED BY CLINIC & AUTO RE-BOOK
CP ;;CANCELLED BY PATIENT;;CANCELLED BY PATIENT
CPR ;;CANCELLED BY PATIENT & RESCHEDULED;;CANCELLED BY PATIENT & AUTO-REBOOK
R ;;SCHEDULED/KEPT;;
I ;;INPATIENT;;INPATIENT APPOINTMENT
NS ;;NO-SHOW;;NO-SHOW
NSR ;;NO-SHOW & RESCHEDULED;;NO-SHOW & AUTO RE-BOOK
NT ;;NO ACTION TAKEN;;NO ACTION TAKEN