SDECRT0 ;ALB/SAT - VISTA SCHEDULING RPCS ;JAN 15, 2016
;;5.3;Scheduling;**627**;Aug 13, 1993;Build 249
;
Q
;
FIND(CLN,APPT,APPN,ORDER,BSDMODE,SDX,SDSTART,SDSTOP,SDREP,SDATE) ;EP; -- set up ^tmp sort for patient's appt
; called by START^SDECRT and SINGLE^SDECRT
; assumes SD variables SDX,SDSTART,SDSTOP,SDREP,SDATE are set
; CLN=clinic ien, APPT=appt date/time, APPN=appt ien in ^SC
; ORDER=1 means sort by terminal digit (or chart # per site param)
; ORDER=2 means sort by clinic; ORDER=3 means sort by principal clinic
; ORDER=4 means sort by name; ORDER="" means single routing slip
; BSDMODE="WI" for walkins, "SD" for same day, "" for all others
; BSDMODE="CR" used for chart requests in routine BSDROUT
;
;
NEW DFN,HRCN,TERM,FIRST
NEW BSDSC,BSDGD,BSDL
S DFN=$P(^SC(CLN,"S",APPT,1,APPN,0),U) ;patient ien
S HRCN=$$HRCN^SDECF2(DFN,$$FAC^SDECU(CLN)) ;chart #
S TERM=$$HRCNT^SDECF2(HRCN) ;terminal digit format
I $$GET1^DIQ(9009020.2,+$$DIVC^SDECU(CLN),.18)="NO" D
. S TERM=$$HRCND^SDECF2(HRCN) ;use chart # per site param
;
Q:'$$PRTOK(DFN,APPT,TERM) ;okay to print this appt?
;
S FIRST=$$FIRST(DFN,APPT) ;first appt that day?
;
D STOPS(DFN,APPT,CLN,TERM,ORDER) ;xray, lab, ekg stops
I ORDER=1 D TDO(DFN,APPT,CLN,TERM,"",FIRST) Q
I ORDER=2 D CLO(DFN,APPT,CLN,TERM,"",FIRST) Q
I ORDER=3 D PCO(DFN,APPT,CLN,TERM,"",FIRST) Q
D NMO(DFN,APPT,CLN,TERM,"",FIRST) Q
;
TDO(P,D,C,T,S,F) ; -- sort by terminal digit
I $G(F) S ^TMP("SDRS",$J," "_T," "_T,P)=1 ;1st for patient for date
S ^TMP("SDRS",$J," "_T," "_T,P,D)=C_U_$G(S)_U_$G(BSDMODE)
Q
;
CLO(P,D,C,T,S,F) ; -- sort by clinic
NEW N S N=$$GET1^DIQ(44,C,.01) Q:N="" ;clinic name
I SDX["ALL",SDSTART]"",SDSTART]N Q ;not in print range
I SDX["ALL",SDSTOP]"",N]SDSTOP Q ;not in print range
;
I $G(F),'$D(^TMP("SDRS",$J,P)) S ^TMP("SDRS",$J,P,N)=1 ;1st for patient for date
S ^TMP("SDRS1",$J,P,D)=N
;
S ^TMP("SDRS",$J,N," "_T,P,D)=C_U_$G(S)_U_$G(BSDMODE)
Q
;
PCO(P,D,C,T,S,F) ; -- sort by principal clinic
NEW PRINC S PRINC=$$PRIN^SDECU(C)
I PRINC="UNAFFILIATED CLINICS" S PRINC=$$GET1^DIQ(44,+C,.01)
I SDX["ALL",SDSTART]"",SDSTART]PRINC Q ;not print range
I SDX["ALL",SDSTOP]"",PRINC]SDSTOP Q ;not print range
;
I $G(F),'$D(^TMP("SDRS",$J,P)) S ^TMP("SDRS",$J,P,PRINC)=1 ;1st 4 pat 4 dt
S ^TMP("SDRS1",$J,P,D)=PRINC ;sort by patient then date/time
;
S ^TMP("SDRS",$J,PRINC," "_T,P,D)=C_U_$G(S)_U_$G(BSDMODE)
Q
;
NMO(P,D,C,T,S,F) ; -- sort by name
NEW N S N=$$GET1^DIQ(2,P,.01) ;patient name
I $G(F) S ^TMP("SDRS",$J,N," "_T,P)=1 ;1st for patient for date
S ^TMP("SDRS",$J,N," "_T,P,D)=C_U_$G(S)_U_$G(BSDMODE)
Q
;
;
STOPS(P,D,C,T,ORDER) ; checks for xray, lab or ekg stops
NEW I,A,STOP
F I=3,4,5 I $P(^DPT(P,"S",D,0),U,I)]"" D
. S A=$P(^DPT(P,"S",D,0),U,I),STOP=$S(I=3:"LAB",I=4:"XRAY",1:"EKG")
. I ORDER=1 D TDO(P,A,C,T,STOP) Q
. I ORDER=2 D CLO(P,A,C,T,STOP) Q
. I ORDER=3 D PCO(P,A,C,T,STOP) Q
. D NMO(P,A,C,T,STOP)
Q
;
PRTOK(P,D,TERM) ; -- check to see if rs should be printed for patient
; remove cancelled appts from list
I ('$G(^DPT(P,"S",D,0)))!($P($G(^DPT(P,"S",D,0)),U,2)["C") Q 0
;
I SDX["ALL",SDSTART="" Q 1 ;1st printing of all routing slips
;
; can have range of items to print; checking range
; clinic ranges to be checked later
;NEW X S X=1 I SDX["ALL" D Q X
NEW X S X=1 I 'SDREP D Q X
. I SDX["ADD",$P(^DPT(P,"S",D,0),U,13)]"" S X=0 Q ;if add-on, don't print if already printed
. I ORDER=1,SDSTART]"",SDSTART]$E(TERM,1,2) S X=0 Q ;before beginning
. I ORDER=1,SDSTOP]"",$E(TERM,1,2)]SDSTOP S X=0 Q ;after end
. I ORDER=4,SDSTART]$$GET1^DIQ(2,P,.01) S X=0 Q ;before beginning
. I ORDER=4,$$GET1^DIQ(2,P,.01)]SDSTOP S X=0 Q ;before beginning
;
; if reprinting add-ons, only reprint those already printed that day
I SDREP,SDX["ADD" Q $S($P($G(^DPT(P,"S",D,0)),U,13)\1=SDSTART:1,1:0)
;
Q 1
;
FIRST(DFN,DATE) ;EP -- returns 1 if first appt that day for patient
I (ORDER'=2),(ORDER'=3) Q 0 ;for sorts by clinic only
NEW X,Y
S X=DATE\1
F S X=$O(^DPT(DFN,"S",X)) Q:(X\1>DATE\1) Q:'X Q:$D(Y) D
. Q:$P(^DPT(DFN,"S",X,0),U,2)["C" ;ignore cancelled appts
. S Y=$S(X=DATE:1,1:0)
Q $G(Y)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDECRT0 4437 printed Nov 22, 2024@18:02:37 Page 2
SDECRT0 ;ALB/SAT - VISTA SCHEDULING RPCS ;JAN 15, 2016
+1 ;;5.3;Scheduling;**627**;Aug 13, 1993;Build 249
+2 ;
+3 QUIT
+4 ;
FIND(CLN,APPT,APPN,ORDER,BSDMODE,SDX,SDSTART,SDSTOP,SDREP,SDATE) ;EP; -- set up ^tmp sort for patient's appt
+1 ; called by START^SDECRT and SINGLE^SDECRT
+2 ; assumes SD variables SDX,SDSTART,SDSTOP,SDREP,SDATE are set
+3 ; CLN=clinic ien, APPT=appt date/time, APPN=appt ien in ^SC
+4 ; ORDER=1 means sort by terminal digit (or chart # per site param)
+5 ; ORDER=2 means sort by clinic; ORDER=3 means sort by principal clinic
+6 ; ORDER=4 means sort by name; ORDER="" means single routing slip
+7 ; BSDMODE="WI" for walkins, "SD" for same day, "" for all others
+8 ; BSDMODE="CR" used for chart requests in routine BSDROUT
+9 ;
+10 ;
+11 NEW DFN,HRCN,TERM,FIRST
+12 NEW BSDSC,BSDGD,BSDL
+13 ;patient ien
SET DFN=$PIECE(^SC(CLN,"S",APPT,1,APPN,0),U)
+14 ;chart #
SET HRCN=$$HRCN^SDECF2(DFN,$$FAC^SDECU(CLN))
+15 ;terminal digit format
SET TERM=$$HRCNT^SDECF2(HRCN)
+16 IF $$GET1^DIQ(9009020.2,+$$DIVC^SDECU(CLN),.18)="NO"
Begin DoDot:1
+17 ;use chart # per site param
SET TERM=$$HRCND^SDECF2(HRCN)
End DoDot:1
+18 ;
+19 ;okay to print this appt?
if '$$PRTOK(DFN,APPT,TERM)
QUIT
+20 ;
+21 ;first appt that day?
SET FIRST=$$FIRST(DFN,APPT)
+22 ;
+23 ;xray, lab, ekg stops
DO STOPS(DFN,APPT,CLN,TERM,ORDER)
+24 IF ORDER=1
DO TDO(DFN,APPT,CLN,TERM,"",FIRST)
QUIT
+25 IF ORDER=2
DO CLO(DFN,APPT,CLN,TERM,"",FIRST)
QUIT
+26 IF ORDER=3
DO PCO(DFN,APPT,CLN,TERM,"",FIRST)
QUIT
+27 DO NMO(DFN,APPT,CLN,TERM,"",FIRST)
QUIT
+28 ;
TDO(P,D,C,T,S,F) ; -- sort by terminal digit
+1 ;1st for patient for date
IF $GET(F)
SET ^TMP("SDRS",$JOB," "_T," "_T,P)=1
+2 SET ^TMP("SDRS",$JOB," "_T," "_T,P,D)=C_U_$GET(S)_U_$GET(BSDMODE)
+3 QUIT
+4 ;
CLO(P,D,C,T,S,F) ; -- sort by clinic
+1 ;clinic name
NEW N
SET N=$$GET1^DIQ(44,C,.01)
if N=""
QUIT
+2 ;not in print range
IF SDX["ALL"
IF SDSTART]""
IF SDSTART]N
QUIT
+3 ;not in print range
IF SDX["ALL"
IF SDSTOP]""
IF N]SDSTOP
QUIT
+4 ;
+5 ;1st for patient for date
IF $GET(F)
IF '$DATA(^TMP("SDRS",$JOB,P))
SET ^TMP("SDRS",$JOB,P,N)=1
+6 SET ^TMP("SDRS1",$JOB,P,D)=N
+7 ;
+8 SET ^TMP("SDRS",$JOB,N," "_T,P,D)=C_U_$GET(S)_U_$GET(BSDMODE)
+9 QUIT
+10 ;
PCO(P,D,C,T,S,F) ; -- sort by principal clinic
+1 NEW PRINC
SET PRINC=$$PRIN^SDECU(C)
+2 IF PRINC="UNAFFILIATED CLINICS"
SET PRINC=$$GET1^DIQ(44,+C,.01)
+3 ;not print range
IF SDX["ALL"
IF SDSTART]""
IF SDSTART]PRINC
QUIT
+4 ;not print range
IF SDX["ALL"
IF SDSTOP]""
IF PRINC]SDSTOP
QUIT
+5 ;
+6 ;1st 4 pat 4 dt
IF $GET(F)
IF '$DATA(^TMP("SDRS",$JOB,P))
SET ^TMP("SDRS",$JOB,P,PRINC)=1
+7 ;sort by patient then date/time
SET ^TMP("SDRS1",$JOB,P,D)=PRINC
+8 ;
+9 SET ^TMP("SDRS",$JOB,PRINC," "_T,P,D)=C_U_$GET(S)_U_$GET(BSDMODE)
+10 QUIT
+11 ;
NMO(P,D,C,T,S,F) ; -- sort by name
+1 ;patient name
NEW N
SET N=$$GET1^DIQ(2,P,.01)
+2 ;1st for patient for date
IF $GET(F)
SET ^TMP("SDRS",$JOB,N," "_T,P)=1
+3 SET ^TMP("SDRS",$JOB,N," "_T,P,D)=C_U_$GET(S)_U_$GET(BSDMODE)
+4 QUIT
+5 ;
+6 ;
STOPS(P,D,C,T,ORDER) ; checks for xray, lab or ekg stops
+1 NEW I,A,STOP
+2 FOR I=3,4,5
IF $PIECE(^DPT(P,"S",D,0),U,I)]""
Begin DoDot:1
+3 SET A=$PIECE(^DPT(P,"S",D,0),U,I)
SET STOP=$SELECT(I=3:"LAB",I=4:"XRAY",1:"EKG")
+4 IF ORDER=1
DO TDO(P,A,C,T,STOP)
QUIT
+5 IF ORDER=2
DO CLO(P,A,C,T,STOP)
QUIT
+6 IF ORDER=3
DO PCO(P,A,C,T,STOP)
QUIT
+7 DO NMO(P,A,C,T,STOP)
End DoDot:1
+8 QUIT
+9 ;
PRTOK(P,D,TERM) ; -- check to see if rs should be printed for patient
+1 ; remove cancelled appts from list
+2 IF ('$GET(^DPT(P,"S",D,0)))!($PIECE($GET(^DPT(P,"S",D,0)),U,2)["C")
QUIT 0
+3 ;
+4 ;1st printing of all routing slips
IF SDX["ALL"
IF SDSTART=""
QUIT 1
+5 ;
+6 ; can have range of items to print; checking range
+7 ; clinic ranges to be checked later
+8 ;NEW X S X=1 I SDX["ALL" D Q X
+9 NEW X
SET X=1
IF 'SDREP
Begin DoDot:1
+10 ;if add-on, don't print if already printed
IF SDX["ADD"
IF $PIECE(^DPT(P,"S",D,0),U,13)]""
SET X=0
QUIT
+11 ;before beginning
IF ORDER=1
IF SDSTART]""
IF SDSTART]$EXTRACT(TERM,1,2)
SET X=0
QUIT
+12 ;after end
IF ORDER=1
IF SDSTOP]""
IF $EXTRACT(TERM,1,2)]SDSTOP
SET X=0
QUIT
+13 ;before beginning
IF ORDER=4
IF SDSTART]$$GET1^DIQ(2,P,.01)
SET X=0
QUIT
+14 ;before beginning
IF ORDER=4
IF $$GET1^DIQ(2,P,.01)]SDSTOP
SET X=0
QUIT
End DoDot:1
QUIT X
+15 ;
+16 ; if reprinting add-ons, only reprint those already printed that day
+17 IF SDREP
IF SDX["ADD"
QUIT $SELECT($PIECE($GET(^DPT(P,"S",D,0)),U,13)\1=SDSTART:1,1:0)
+18 ;
+19 QUIT 1
+20 ;
FIRST(DFN,DATE) ;EP -- returns 1 if first appt that day for patient
+1 ;for sorts by clinic only
IF (ORDER'=2)
IF (ORDER'=3)
QUIT 0
+2 NEW X,Y
+3 SET X=DATE\1
+4 FOR
SET X=$ORDER(^DPT(DFN,"S",X))
if (X\1>DATE\1)
QUIT
if 'X
QUIT
if $DATA(Y)
QUIT
Begin DoDot:1
+5 ;ignore cancelled appts
if $PIECE(^DPT(DFN,"S",X,0),U,2)["C"
QUIT
+6 SET Y=$SELECT(X=DATE:1,1:0)
End DoDot:1
+7 QUIT $GET(Y)