SCRPW75 ;BP-CIOFO/KEITH,ESW - Clinic Appointment Availability Extract (cont.) ; 5/15/03 3:15pm
;;5.3;Scheduling;**206,223,241,249,291**;AUG 13, 1993
;
NAVA(SDBDT,SDEDT,SDEX) ;Gather next available appointment wait time information
;Input: SDBDT=beginning date
;Input: SDEDT=ending date
;Input: SDEX='0' for user report, '1' for Austin extract
;Output: ^TMP("SDNAVA",$J) array in the format:
; ^TMP("SDNAVA",$J,division)='x'
; ^TMP("SDNAVA",$J,division,credit_pair)='x'
; ^TMP("SDNAVA",$J,division,credit_pair,clinic_ifn)='x'
; ^TMP("SDNAVA",$J,division;credit_pair,clinic_ifn,date_scheduled)='x'
; where 'x' consists of:
; piece 1 = flag '0' appts.
; 2 = ave. flag '0' wait time
; 3 = flag '1' appts.
; 4 = ave. flag '1' wait time
; 5 = flag '2' appts.
; 6 = ave. flag '2' wait time
; 7 = flag '3' appts.
; 8 = ave. flag '3' wait time
; 9 = follow-up next ava. appts.
; 10 = follow-up next ava. wait time
; 11 = follow-up non-next ava. appts. <2 days
; 12 = follow-up non-next ava. appts. <2 days wait time*
; 13 = follow-up non-next ava. appts. 2-7 days
; 14 = follow-up non-next ava. appts. 2-7 days wait time*
; 15 = follow-up non-next ava. appts. 8-30 days
; 16 = follow-up non-next ava. appts. 8-30 days wait time*
; 17 = follow-up non-next ava. appts. 31-60 days
; 18 = follow-up non-next ava. appts. 31-60 days wait time*
; 19 = follow-up non-next ava. appts. >60 days
; 20 = follow-up non-next ava. appts. >60 days wait time*
; 21 = non-follow-up next ava. appts.
; 22 = non-follow-up next ava. wait time
; 23 = non-follow-up non-next ava. appts. <2 days
; 24 = non-follow-up non-next ava. appts. <2 days wait time*
; 25 = non-follow-up non-next ava. appts. <2 days wait time**
; 26 = non-follow-up non-next ava. appts. 2-7 days
; 27 = non-follow-up non-next ava. appts. 2-7 days wait time*
; 28 = non-follow-up non-next ava. appts. 2-7 days wait time**
; 29 = non-follow-up non-next ava. appts. 8-30 days
; 30 = non-follow-up non-next ava. appts. 8-30 days wait time*
; 31 = non-follow-up non-next ava. appts. 8-30 days wait time**
; 32 = non-follow-up non-next ava. appts. 31-60 days
; 33 = non-follow-up non-next ava. appts. 31-60 days wait time*
; 34 = non-follow-up non-next ava. appts. 31-60 days wait time**
; 35 = non-follow-up non-next ava. appts. >60 days
; 36 = non-follow-up non-next ava. appts. >60 days wait time*
; 37 = non-follow-up non-next ava. appts. >60 days wait time**
; 38 = percent of non-next ava. appts. within 30 days
; 39 = percent of next ava. appts. within 30 days
;
; ^TMP("SDNAVB",$J) array in the format:
; ^TMP("SDNAVB",$J,division,credit_pair,clinic_ifn)='y'
; where 'y' consists of:
; piece 1 = % non-follow-up next ava. appts. within 30 days*
; 2 = % non-follow-up next ava. appts. within 30 days**
; 3 = % non-follow-up non-next ava. appts. within 30 days*
; 4 = % non-follow-up non-next ava. appts. within 30 days**
; 5 = sum of squared wait time next ava. appts.**
; 6 = sum of squared wait time non-follow-up appts.*
; 7 = sum of squared wait time non-follow-up appts.**
; 8 = total non-follow-up appointments
;
; * desired date to appointment date
; ** transaction date to appointment date
;
N SDT,SDCT,DFN,SDADT,SDAP,SDAP0,SDWAIT,SDSFU,SDCWT3,SDAVE
N SDCL,SDFLAG,SDX,SDY,SDZ,SDI,SC0,SDCP,SDSDEV,SDSDDT,SDAVE2
S SDT=SDBDT-1,(SDOUT,SDCT)=0
K ^TMP("SDWNAVA",$J),^TMP("SDXNAVA",$J),^TMP("SDYNAVA",$J),^TMP("SDZNAVA",$J),^TMP("SDNAVA",$J),^TMP("SDNAVB",$J)
;Iterate through 'date scheduled' xref
F S SDT=$O(^DPT("ASADM",SDT)) Q:SDOUT!'SDT!(SDT>SDEDT) S DFN=0 D
.F S DFN=$O(^DPT("ASADM",SDT,DFN)) Q:SDOUT!'DFN S SDADT=0 D
..I $G(SDREPORT(5))=1 I '$D(^TMP("SDIPLST",$J,DFN)) Q ;only selected patient if (5)
..Q:$E($P($G(^DPT(DFN,0)),U,9),1,5)="00000" ;exclude test patients
..F S SDADT=$O(^DPT("ASADM",SDT,DFN,SDADT)) Q:SDOUT!'SDADT D
...;Check for 'stop task' request
...S SDCT=SDCT+1 I SDCT#1000=0 D STOP Q:SDOUT
...;Get appointment node
...S SDAP0=$G(^DPT(DFN,"S",SDADT,0)) Q:$P(SDAP0,U,19)'=SDT
...I '$G(SDREPORT(5)) Q:$P(SDAP0,U,2)="C"!($P(SDAP0,U,2)="CA") ;quit if cancelled by clinic
...S SDCL=+SDAP0 Q:SDCL<1 ;get clinic
...;'next ava.' appointment indicator
...S SDFLAG=+$P(SDAP0,U,26)
...;'date desired' and 'follow up visit' indicator
...S SDX=$G(^DPT(DFN,"S",SDADT,1))
...S SDSDDT=+$P(SDX,U),SDSFU=$P(SDX,U,2),SDSDEV=""
...;Calculate wait time 1 (transaction date to appointment)
...S SDWAIT=$S(SDADT<SDT:0,1:$$FMDIFF^XLFDT(SDADT,SDT,1))
...;Calculate wait time 2 (date desired to appointment)
...S SDCWT3=$$CWT3(SDADT,SDFLAG,SDSDDT,SDSFU,.SDSDEV,.SDX,.SDY,.SDZ)
...;Gather patient appointment list information
...I $G(SDREPORT(4)),$D(^TMP("SDPLIST",$J,SDCL)) D
....N SDPNAME,SDATA,SDSSN
....S SDATA=$G(^DPT(DFN,0))
....S SDSSN=$P(SDATA,U,9),SDPNAME=$P(SDATA,U) Q:'$L(SDPNAME)
....S SDATA=SDSSN_U_$P(SDAP0,U,25)_U_SDFLAG_U_SDSDDT_U_SDSFU_U_SDWAIT_U_SDSDEV
....S ^TMP("SDPLIST",$J,SDCL,SDT,SDPNAME,DFN,SDADT)=SDATA
....Q
...I $G(SDREPORT(5)) I $D(^TMP("SDIPLST",$J,DFN,SDCL)) D GEN5A^SCRPW78(SDAP0,DFN,SDADT,SDCL,SDWAIT,SDT,SDSFU,SDSDEV,SDSDDT,SDFLAG)
...;Accrue phase II values ('next ava.' appts.)
...S $P(^TMP("SDXNAVA",$J,SDCL),U,((SDFLAG*2)+1))=$P($G(^TMP("SDXNAVA",$J,SDCL)),U,((SDFLAG*2)+1))+1
...S $P(^TMP("SDXNAVA",$J,SDCL),U,((SDFLAG*2)+2))=$P(^TMP("SDXNAVA",$J,SDCL),U,((SDFLAG*2)+2))+SDWAIT
...I SDWAIT<31 S $P(^TMP("SDXNAVA",$J,SDCL),U,9+(SDFLAG#2))=$P(^TMP("SDXNAVA",$J,SDCL),U,9+(SDFLAG#2))+1
...;Accrue sum of squared wait time for standard deviation
...I SDFLAG#2 S $P(^TMP("SDWNAVA",$J,SDCL),U,5)=$P($G(^TMP("SDWNAVA",$J,SDCL)),U,5)+(SDWAIT*SDWAIT)
...;Accrue phase III values ('date desired' deviation)
...I SDCWT3 D
....S $P(^TMP("SDYNAVA",$J,SDCL),U,SDX)=$P($G(^TMP("SDYNAVA",$J,SDCL)),U,SDX)+1
....S $P(^TMP("SDYNAVA",$J,SDCL),U,SDY)=$P(^TMP("SDYNAVA",$J,SDCL),U,SDY)+SDSDEV
....S:SDZ $P(^TMP("SDYNAVA",$J,SDCL),U,SDZ)=$P(^TMP("SDYNAVA",$J,SDCL),U,SDZ)+SDWAIT
....;Gather additional information for non-follow-up appointments
....I 'SDSFU D
.....;Accrue next ava. and non-next ava. appts. less than 31 days
.....N SDP S SDP=$S(SDFLAG#2:1,1:3)
.....I SDSDEV<31 S $P(^TMP("SDWNAVA",$J,SDCL),U,SDP)=$P($G(^TMP("SDWNAVA",$J,SDCL)),U,SDP)+1
.....I SDWAIT<31 S $P(^TMP("SDWNAVA",$J,SDCL),U,SDP+1)=$P($G(^TMP("SDWNAVA",$J,SDCL)),U,SDP+1)+1
.....;Accrue sum of squared wait time for standard deviation
.....S $P(^TMP("SDWNAVA",$J,SDCL),U,6)=$P($G(^TMP("SDWNAVA",$J,SDCL)),U,6)+(SDSDEV*SDSDEV)
.....S $P(^TMP("SDWNAVA",$J,SDCL),U,7)=$P(^TMP("SDWNAVA",$J,SDCL),U,7)+(SDWAIT*SDWAIT)
.....;Total of non-follow-up appointments
.....S $P(^TMP("SDWNAVA",$J,SDCL),U,8)=$P(^TMP("SDWNAVA",$J,SDCL),U,8)+1
.....Q
....Q
...;Accrue values for daily detail
...Q:SDEX=1!(SDFMT'="D")
...S $P(^TMP("SDXNAVA",$J,SDCL,SDT),U,((SDFLAG*2)+1))=$P($G(^TMP("SDXNAVA",$J,SDCL,SDT)),U,((SDFLAG*2)+1))+1
...S $P(^TMP("SDXNAVA",$J,SDCL,SDT),U,((SDFLAG*2)+2))=$P(^TMP("SDXNAVA",$J,SDCL,SDT),U,((SDFLAG*2)+2))+SDWAIT
...I SDWAIT<31 S $P(^TMP("SDXNAVA",$J,SDCL,SDT),U,9+(SDFLAG#2))=$P($G(^TMP("SDXNAVA",$J,SDCL,SDT)),U,9+(SDFLAG#2))+1
...I SDCWT3 D
....S $P(^TMP("SDYNAVA",$J,SDCL,SDT),U,SDX)=$P($G(^TMP("SDYNAVA",$J,SDCL,SDT)),U,SDX)+1
....S $P(^TMP("SDYNAVA",$J,SDCL,SDT),U,SDY)=$P(^TMP("SDYNAVA",$J,SDCL,SDT),U,SDY)+SDSDEV
....S:SDZ $P(^TMP("SDYNAVA",$J,SDCL,SDT),U,SDZ)=$P(^TMP("SDYNAVA",$J,SDCL,SDT),U,SDZ)+SDWAIT
...Q
..Q
.Q
Q:SDOUT S SDCL=0
D ACCRUE^SCRPW77
Q
;
STOP ;Check for stop task request
S:$D(ZTQUEUED) (SDOUT,ZTSTOP)=$S($$S^%ZTLOAD:1,1:0) Q
;
CWT3(SDADT,SDFLAG,SDSDDT,SDSFU,SDSDEV,SDX,SDY,SDZ) ;Get phase III data
;Input: SDADT=appointment date
;Input: SDFLAG='next ava.' appointment indicator
;Input: SDSDDT=desired date
;Input: SDSFU=follow up indicator
;Input: SDSDEV=deviation from desired date (pass by reference)
;Input: SDX, SDY, SDZ=string locations to update (pass by reference)
;Output: '1' if phase III data exists, '0' otherwise
;
N SDDCAT
I '$L(SDSDDT)!'$L(SDSFU) Q 0 ;no phase III data
S SDSDEV=$S(SDADT<SDSDDT:0,1:$$FMDIFF^XLFDT(SDADT,SDSDDT,1)) ;wait time
S SDDCAT=$$DCAT(SDSDEV) ;date range category
;follow-up next ava. appts.
I SDSFU,SDFLAG#2 S SDX=1,SDY=2,SDZ=0 Q 1
;follow-up non-next ava. appts.
I SDSFU,'(SDFLAG#2) S SDX=SDDCAT*2+1,SDY=SDX+1,SDZ=0 Q 1
;non-follow-up next ava. appts.
I 'SDSFU,SDFLAG#2 S SDX=13,SDY=14,SDZ=0 Q 1
;non-follow-up non-next ava. appts.
I 'SDSFU,'(SDFLAG#2) S SDX=SDDCAT+4*3,SDY=SDX+1,SDZ=SDX+2
Q 1
;
DCAT(SDSDEV) ;Determine date range category
;Input: SDSDEV=wait time
;Output: category where '1' = <2 days
; '2' = 2-7 days
; '3' = 8-30 days
; '4' = 31-60 days
; '5' = >60 days
;
Q:SDSDEV<2 1
Q:SDSDEV<8 2
Q:SDSDEV<31 3
Q:SDSDEV<61 4
Q 5
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSCRPW75 9649 printed Dec 13, 2024@02:44:07 Page 2
SCRPW75 ;BP-CIOFO/KEITH,ESW - Clinic Appointment Availability Extract (cont.) ; 5/15/03 3:15pm
+1 ;;5.3;Scheduling;**206,223,241,249,291**;AUG 13, 1993
+2 ;
NAVA(SDBDT,SDEDT,SDEX) ;Gather next available appointment wait time information
+1 ;Input: SDBDT=beginning date
+2 ;Input: SDEDT=ending date
+3 ;Input: SDEX='0' for user report, '1' for Austin extract
+4 ;Output: ^TMP("SDNAVA",$J) array in the format:
+5 ; ^TMP("SDNAVA",$J,division)='x'
+6 ; ^TMP("SDNAVA",$J,division,credit_pair)='x'
+7 ; ^TMP("SDNAVA",$J,division,credit_pair,clinic_ifn)='x'
+8 ; ^TMP("SDNAVA",$J,division;credit_pair,clinic_ifn,date_scheduled)='x'
+9 ; where 'x' consists of:
+10 ; piece 1 = flag '0' appts.
+11 ; 2 = ave. flag '0' wait time
+12 ; 3 = flag '1' appts.
+13 ; 4 = ave. flag '1' wait time
+14 ; 5 = flag '2' appts.
+15 ; 6 = ave. flag '2' wait time
+16 ; 7 = flag '3' appts.
+17 ; 8 = ave. flag '3' wait time
+18 ; 9 = follow-up next ava. appts.
+19 ; 10 = follow-up next ava. wait time
+20 ; 11 = follow-up non-next ava. appts. <2 days
+21 ; 12 = follow-up non-next ava. appts. <2 days wait time*
+22 ; 13 = follow-up non-next ava. appts. 2-7 days
+23 ; 14 = follow-up non-next ava. appts. 2-7 days wait time*
+24 ; 15 = follow-up non-next ava. appts. 8-30 days
+25 ; 16 = follow-up non-next ava. appts. 8-30 days wait time*
+26 ; 17 = follow-up non-next ava. appts. 31-60 days
+27 ; 18 = follow-up non-next ava. appts. 31-60 days wait time*
+28 ; 19 = follow-up non-next ava. appts. >60 days
+29 ; 20 = follow-up non-next ava. appts. >60 days wait time*
+30 ; 21 = non-follow-up next ava. appts.
+31 ; 22 = non-follow-up next ava. wait time
+32 ; 23 = non-follow-up non-next ava. appts. <2 days
+33 ; 24 = non-follow-up non-next ava. appts. <2 days wait time*
+34 ; 25 = non-follow-up non-next ava. appts. <2 days wait time**
+35 ; 26 = non-follow-up non-next ava. appts. 2-7 days
+36 ; 27 = non-follow-up non-next ava. appts. 2-7 days wait time*
+37 ; 28 = non-follow-up non-next ava. appts. 2-7 days wait time**
+38 ; 29 = non-follow-up non-next ava. appts. 8-30 days
+39 ; 30 = non-follow-up non-next ava. appts. 8-30 days wait time*
+40 ; 31 = non-follow-up non-next ava. appts. 8-30 days wait time**
+41 ; 32 = non-follow-up non-next ava. appts. 31-60 days
+42 ; 33 = non-follow-up non-next ava. appts. 31-60 days wait time*
+43 ; 34 = non-follow-up non-next ava. appts. 31-60 days wait time**
+44 ; 35 = non-follow-up non-next ava. appts. >60 days
+45 ; 36 = non-follow-up non-next ava. appts. >60 days wait time*
+46 ; 37 = non-follow-up non-next ava. appts. >60 days wait time**
+47 ; 38 = percent of non-next ava. appts. within 30 days
+48 ; 39 = percent of next ava. appts. within 30 days
+49 ;
+50 ; ^TMP("SDNAVB",$J) array in the format:
+51 ; ^TMP("SDNAVB",$J,division,credit_pair,clinic_ifn)='y'
+52 ; where 'y' consists of:
+53 ; piece 1 = % non-follow-up next ava. appts. within 30 days*
+54 ; 2 = % non-follow-up next ava. appts. within 30 days**
+55 ; 3 = % non-follow-up non-next ava. appts. within 30 days*
+56 ; 4 = % non-follow-up non-next ava. appts. within 30 days**
+57 ; 5 = sum of squared wait time next ava. appts.**
+58 ; 6 = sum of squared wait time non-follow-up appts.*
+59 ; 7 = sum of squared wait time non-follow-up appts.**
+60 ; 8 = total non-follow-up appointments
+61 ;
+62 ; * desired date to appointment date
+63 ; ** transaction date to appointment date
+64 ;
+65 NEW SDT,SDCT,DFN,SDADT,SDAP,SDAP0,SDWAIT,SDSFU,SDCWT3,SDAVE
+66 NEW SDCL,SDFLAG,SDX,SDY,SDZ,SDI,SC0,SDCP,SDSDEV,SDSDDT,SDAVE2
+67 SET SDT=SDBDT-1
SET (SDOUT,SDCT)=0
+68 KILL ^TMP("SDWNAVA",$JOB),^TMP("SDXNAVA",$JOB),^TMP("SDYNAVA",$JOB),^TMP("SDZNAVA",$JOB),^TMP("SDNAVA",$JOB),^TMP("SDNAVB",$JOB)
+69 ;Iterate through 'date scheduled' xref
+70 FOR
SET SDT=$ORDER(^DPT("ASADM",SDT))
if SDOUT!'SDT!(SDT>SDEDT)
QUIT
SET DFN=0
Begin DoDot:1
+71 FOR
SET DFN=$ORDER(^DPT("ASADM",SDT,DFN))
if SDOUT!'DFN
QUIT
SET SDADT=0
Begin DoDot:2
+72 ;only selected patient if (5)
IF $GET(SDREPORT(5))=1
IF '$DATA(^TMP("SDIPLST",$JOB,DFN))
QUIT
+73 ;exclude test patients
if $EXTRACT($PIECE($GET(^DPT(DFN,0)),U,9),1,5)="00000"
QUIT
+74 FOR
SET SDADT=$ORDER(^DPT("ASADM",SDT,DFN,SDADT))
if SDOUT!'SDADT
QUIT
Begin DoDot:3
+75 ;Check for 'stop task' request
+76 SET SDCT=SDCT+1
IF SDCT#1000=0
DO STOP
if SDOUT
QUIT
+77 ;Get appointment node
+78 SET SDAP0=$GET(^DPT(DFN,"S",SDADT,0))
if $PIECE(SDAP0,U,19)'=SDT
QUIT
+79 ;quit if cancelled by clinic
IF '$GET(SDREPORT(5))
if $PIECE(SDAP0,U,2)="C"!($PIECE(SDAP0,U,2)="CA")
QUIT
+80 ;get clinic
SET SDCL=+SDAP0
if SDCL<1
QUIT
+81 ;'next ava.' appointment indicator
+82 SET SDFLAG=+$PIECE(SDAP0,U,26)
+83 ;'date desired' and 'follow up visit' indicator
+84 SET SDX=$GET(^DPT(DFN,"S",SDADT,1))
+85 SET SDSDDT=+$PIECE(SDX,U)
SET SDSFU=$PIECE(SDX,U,2)
SET SDSDEV=""
+86 ;Calculate wait time 1 (transaction date to appointment)
+87 SET SDWAIT=$SELECT(SDADT<SDT:0,1:$$FMDIFF^XLFDT(SDADT,SDT,1))
+88 ;Calculate wait time 2 (date desired to appointment)
+89 SET SDCWT3=$$CWT3(SDADT,SDFLAG,SDSDDT,SDSFU,.SDSDEV,.SDX,.SDY,.SDZ)
+90 ;Gather patient appointment list information
+91 IF $GET(SDREPORT(4))
IF $DATA(^TMP("SDPLIST",$JOB,SDCL))
Begin DoDot:4
+92 NEW SDPNAME,SDATA,SDSSN
+93 SET SDATA=$GET(^DPT(DFN,0))
+94 SET SDSSN=$PIECE(SDATA,U,9)
SET SDPNAME=$PIECE(SDATA,U)
if '$LENGTH(SDPNAME)
QUIT
+95 SET SDATA=SDSSN_U_$PIECE(SDAP0,U,25)_U_SDFLAG_U_SDSDDT_U_SDSFU_U_SDWAIT_U_SDSDEV
+96 SET ^TMP("SDPLIST",$JOB,SDCL,SDT,SDPNAME,DFN,SDADT)=SDATA
+97 QUIT
End DoDot:4
+98 IF $GET(SDREPORT(5))
IF $DATA(^TMP("SDIPLST",$JOB,DFN,SDCL))
DO GEN5A^SCRPW78(SDAP0,DFN,SDADT,SDCL,SDWAIT,SDT,SDSFU,SDSDEV,SDSDDT,SDFLAG)
+99 ;Accrue phase II values ('next ava.' appts.)
+100 SET $PIECE(^TMP("SDXNAVA",$JOB,SDCL),U,((SDFLAG*2)+1))=$PIECE($GET(^TMP("SDXNAVA",$JOB,SDCL)),U,((SDFLAG*2)+1))+1
+101 SET $PIECE(^TMP("SDXNAVA",$JOB,SDCL),U,((SDFLAG*2)+2))=$PIECE(^TMP("SDXNAVA",$JOB,SDCL),U,((SDFLAG*2)+2))+SDWAIT
+102 IF SDWAIT<31
SET $PIECE(^TMP("SDXNAVA",$JOB,SDCL),U,9+(SDFLAG#2))=$PIECE(^TMP("SDXNAVA",$JOB,SDCL),U,9+(SDFLAG#2))+1
+103 ;Accrue sum of squared wait time for standard deviation
+104 IF SDFLAG#2
SET $PIECE(^TMP("SDWNAVA",$JOB,SDCL),U,5)=$PIECE($GET(^TMP("SDWNAVA",$JOB,SDCL)),U,5)+(SDWAIT*SDWAIT)
+105 ;Accrue phase III values ('date desired' deviation)
+106 IF SDCWT3
Begin DoDot:4
+107 SET $PIECE(^TMP("SDYNAVA",$JOB,SDCL),U,SDX)=$PIECE($GET(^TMP("SDYNAVA",$JOB,SDCL)),U,SDX)+1
+108 SET $PIECE(^TMP("SDYNAVA",$JOB,SDCL),U,SDY)=$PIECE(^TMP("SDYNAVA",$JOB,SDCL),U,SDY)+SDSDEV
+109 if SDZ
SET $PIECE(^TMP("SDYNAVA",$JOB,SDCL),U,SDZ)=$PIECE(^TMP("SDYNAVA",$JOB,SDCL),U,SDZ)+SDWAIT
+110 ;Gather additional information for non-follow-up appointments
+111 IF 'SDSFU
Begin DoDot:5
+112 ;Accrue next ava. and non-next ava. appts. less than 31 days
+113 NEW SDP
SET SDP=$SELECT(SDFLAG#2:1,1:3)
+114 IF SDSDEV<31
SET $PIECE(^TMP("SDWNAVA",$JOB,SDCL),U,SDP)=$PIECE($GET(^TMP("SDWNAVA",$JOB,SDCL)),U,SDP)+1
+115 IF SDWAIT<31
SET $PIECE(^TMP("SDWNAVA",$JOB,SDCL),U,SDP+1)=$PIECE($GET(^TMP("SDWNAVA",$JOB,SDCL)),U,SDP+1)+1
+116 ;Accrue sum of squared wait time for standard deviation
+117 SET $PIECE(^TMP("SDWNAVA",$JOB,SDCL),U,6)=$PIECE($GET(^TMP("SDWNAVA",$JOB,SDCL)),U,6)+(SDSDEV*SDSDEV)
+118 SET $PIECE(^TMP("SDWNAVA",$JOB,SDCL),U,7)=$PIECE(^TMP("SDWNAVA",$JOB,SDCL),U,7)+(SDWAIT*SDWAIT)
+119 ;Total of non-follow-up appointments
+120 SET $PIECE(^TMP("SDWNAVA",$JOB,SDCL),U,8)=$PIECE(^TMP("SDWNAVA",$JOB,SDCL),U,8)+1
+121 QUIT
End DoDot:5
+122 QUIT
End DoDot:4
+123 ;Accrue values for daily detail
+124 if SDEX=1!(SDFMT'="D")
QUIT
+125 SET $PIECE(^TMP("SDXNAVA",$JOB,SDCL,SDT),U,((SDFLAG*2)+1))=$PIECE($GET(^TMP("SDXNAVA",$JOB,SDCL,SDT)),U,((SDFLAG*2)+1))+1
+126 SET $PIECE(^TMP("SDXNAVA",$JOB,SDCL,SDT),U,((SDFLAG*2)+2))=$PIECE(^TMP("SDXNAVA",$JOB,SDCL,SDT),U,((SDFLAG*2)+2))+SDWAIT
+127 IF SDWAIT<31
SET $PIECE(^TMP("SDXNAVA",$JOB,SDCL,SDT),U,9+(SDFLAG#2))=$PIECE($GET(^TMP("SDXNAVA",$JOB,SDCL,SDT)),U,9+(SDFLAG#2))+1
+128 IF SDCWT3
Begin DoDot:4
+129 SET $PIECE(^TMP("SDYNAVA",$JOB,SDCL,SDT),U,SDX)=$PIECE($GET(^TMP("SDYNAVA",$JOB,SDCL,SDT)),U,SDX)+1
+130 SET $PIECE(^TMP("SDYNAVA",$JOB,SDCL,SDT),U,SDY)=$PIECE(^TMP("SDYNAVA",$JOB,SDCL,SDT),U,SDY)+SDSDEV
+131 if SDZ
SET $PIECE(^TMP("SDYNAVA",$JOB,SDCL,SDT),U,SDZ)=$PIECE(^TMP("SDYNAVA",$JOB,SDCL,SDT),U,SDZ)+SDWAIT
End DoDot:4
+132 QUIT
End DoDot:3
+133 QUIT
End DoDot:2
+134 QUIT
End DoDot:1
+135 if SDOUT
QUIT
SET SDCL=0
+136 DO ACCRUE^SCRPW77
+137 QUIT
+138 ;
STOP ;Check for stop task request
+1 if $DATA(ZTQUEUED)
SET (SDOUT,ZTSTOP)=$SELECT($$S^%ZTLOAD:1,1:0)
QUIT
+2 ;
CWT3(SDADT,SDFLAG,SDSDDT,SDSFU,SDSDEV,SDX,SDY,SDZ) ;Get phase III data
+1 ;Input: SDADT=appointment date
+2 ;Input: SDFLAG='next ava.' appointment indicator
+3 ;Input: SDSDDT=desired date
+4 ;Input: SDSFU=follow up indicator
+5 ;Input: SDSDEV=deviation from desired date (pass by reference)
+6 ;Input: SDX, SDY, SDZ=string locations to update (pass by reference)
+7 ;Output: '1' if phase III data exists, '0' otherwise
+8 ;
+9 NEW SDDCAT
+10 ;no phase III data
IF '$LENGTH(SDSDDT)!'$LENGTH(SDSFU)
QUIT 0
+11 ;wait time
SET SDSDEV=$SELECT(SDADT<SDSDDT:0,1:$$FMDIFF^XLFDT(SDADT,SDSDDT,1))
+12 ;date range category
SET SDDCAT=$$DCAT(SDSDEV)
+13 ;follow-up next ava. appts.
+14 IF SDSFU
IF SDFLAG#2
SET SDX=1
SET SDY=2
SET SDZ=0
QUIT 1
+15 ;follow-up non-next ava. appts.
+16 IF SDSFU
IF '(SDFLAG#2)
SET SDX=SDDCAT*2+1
SET SDY=SDX+1
SET SDZ=0
QUIT 1
+17 ;non-follow-up next ava. appts.
+18 IF 'SDSFU
IF SDFLAG#2
SET SDX=13
SET SDY=14
SET SDZ=0
QUIT 1
+19 ;non-follow-up non-next ava. appts.
+20 IF 'SDSFU
IF '(SDFLAG#2)
SET SDX=SDDCAT+4*3
SET SDY=SDX+1
SET SDZ=SDX+2
+21 QUIT 1
+22 ;
DCAT(SDSDEV) ;Determine date range category
+1 ;Input: SDSDEV=wait time
+2 ;Output: category where '1' = <2 days
+3 ; '2' = 2-7 days
+4 ; '3' = 8-30 days
+5 ; '4' = 31-60 days
+6 ; '5' = >60 days
+7 ;
+8 if SDSDEV<2
QUIT 1
+9 if SDSDEV<8
QUIT 2
+10 if SDSDEV<31
QUIT 3
+11 if SDSDEV<61
QUIT 4
+12 QUIT 5