BQIDCAPC ;GDIT/HS/ALA-Scheduled Visits by Clinic Stop ; 21 Nov 2005 6:04 PM
;;2.3;ICARE MANAGEMENT SYSTEM;**3,4**;Apr 18, 2012;Build 66
;
Q
;
APT(DATA,PARMS,MPARMS) ;EP
;
;Description
; Executable to retrieve patients which have appointments in a hospital location that
; is associated with a clinical stop code.
;Input
; PARMS = Array of parameters and their values
; MPARMS = Multiple array of a parameter
;Expected to return DATA
;Parameters
; CLIN = Clinic Stop Code parameter
; LOC = Hosp Location internal entry number associated with CLIN
; FDT = Starting date for the FROM date parameter
; EDT = Ending date for the THRU date parameter
; DFN = Patient internal entry number
; APSTAT = Appointment status
;
NEW II,UID
S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
S DATA=$NA(^TMP("BQIDCAPC",UID))
K @DATA
S II=0
;
FND ; Find the patients with appts for one or more clinic stop codes
NEW CLIN,FROM,THRU,LOC,NM,N,FRDT,ENDT,LABEL,APST,STOP,FDT,EDT,DFN,LABEL
NEW STR,SLOC,STAT,APSTAT,APTYPE,APRANGE,RFROM,RTHRU
S NM=""
F S NM=$O(PARMS(NM)) Q:NM="" S @NM=PARMS(NM)
I $G(APTYPE)'="" D
. NEW MIEN,MAPS
. S MIEN=$O(^BQI(90506,10,3,8,3,"B",APTYPE,"")) I MIEN="" Q
. S MAPS=$P(^BQI(90506,10,3,8,3,MIEN,0),U,2)
. F N=1:1:$L(MAPS,"~") S NM=$P($P(MAPS,"~",N),"=",1),MPARMS(NM,$P($P(MAPS,"~",N),"=",2))=""
;
I $D(MPARMS("APTYPE"))>0 D
. NEW MPM,MIEN,MAPS
. S MPM=""
. F S MPM=$O(MPARMS("APTYPE",MPM)) Q:MPM="" D
.. S MIEN=$O(^BQI(90506,10,3,8,3,"B",MPM,"")) I MIEN="" Q
.. S MAPS=$P(^BQI(90506,10,3,8,3,MIEN,0),U,2)
.. F N=1:1:$L(MAPS,"~") S NM=$P($P(MAPS,"~",N),"=",1),MPARMS(NM,$P($P(MAPS,"~",N),"=",2))=""
;
S LABEL="FND1" D
. I $G(APSTAT)'="",APSTAT'="AC",APSTAT["C" S LABEL="FNDALL" Q
. I $D(MPARMS("APSTAT")) D Q
.. S APST="",STOP=""
.. F S APST=$O(MPARMS("APSTAT",APST)) Q:APST="" D Q:STOP
... I APST'="AC",APST["C" S LABEL="FNDALL",STOP=1 Q
I LABEL="FNDALL" D FNDALL Q
I $G(CLIN)]"" D FND1
I $D(MPARMS("CLIN")) S CLIN="" F S CLIN=$O(MPARMS("CLIN",CLIN)) Q:CLIN="" D FND1
Q
;
FND1 ; Check one clinic stop code
; If timeframe is selected populate start and end dates
I $G(APRANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(APRANGE,PPIEN,"APRANGE")
S LOC=""
F S LOC=$O(^SC("ASTOP",CLIN,LOC)) Q:LOC="" D
. S FDT=$S($G(RFROM)'="":RFROM,1:$G(FROM))
. S EDT=$S($G(RTHRU)'="":RTHRU,1:$G(THRU))
. NEW APCHK
. F S FDT=$O(^SC(LOC,"S",FDT)) Q:FDT=""!(FDT\1>EDT) D
.. S N=0
.. F S N=$O(^SC(LOC,"S",FDT,1,N)) Q:'N D
... NEW DA,IENS
... S DA(2)=LOC,DA(1)=FDT,DA=N,IENS=$$IENS^DILF(.DA)
... S DFN=$$GET1^DIQ(44.003,IENS,.01,"I") I DFN="" Q
... ; User may now select Living, Deceased or both as a filter so
... ; if no filters defined assume living patients otherwise let filter decide
... ;I $O(^BQICARE(OWNR,1,PLIEN,15,0))="",$P($G(^DPT(DFN,.35)),U,1)'="" Q
... I '$$HRN^BQIUL1(DFN) Q
... ; If patient has no visit in last 3 years, quit
... ;I '$$VTHR^BQIUL1(DFN) Q
... I $G(APSTAT)'="" D Q
.... I $G(APSTAT)="AC" S APCHK=""
.... I $G(APSTAT)'="AC" S APCHK=APSTAT
.... I $P($G(^DPT(DFN,"S",FDT,0)),U,2)'=APCHK Q
.... S @DATA@(DFN)=""
... I $D(MPARMS("APSTAT")) D Q
.... S APST=""
.... F S APST=$O(MPARMS("APSTAT",APST)) Q:APST="" D
..... I $G(APST)="AC" S APCHK=""
..... I $G(APST)'="AC" S APCHK=APST
..... I $P($G(^DPT(DFN,"S",FDT,0)),U,2)'=APCHK Q
..... S @DATA@(DFN)=""
... ;S @DATA@(DFN)=""
Q
;
FNDALL ; Loop through all patients since cancelled status selected
; If timeframe is selected populate start and end dates
NEW FRDT,ENDT
I $G(APRANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(APRANGE,PPIEN,"APRANGE")
S FRDT=$S($G(RFROM)'="":RFROM,1:$G(FROM))
S ENDT=$S($G(RTHRU)'="":RTHRU,1:$G(THRU))
I $G(CLIN)]"" D
.S LOC=""
.F S LOC=$O(^SC("ASTOP",CLIN,LOC)) Q:LOC="" S LOC(LOC)=""
I $D(MPARMS("CLIN")) D
. S CLIN=""
. F S CLIN=$O(MPARMS("CLIN",CLIN)) Q:CLIN="" D
.. S LOC=""
.. F S LOC=$O(^SC("ASTOP",CLIN,LOC)) Q:LOC="" S LOC(LOC)=""
NEW APCHK
S DFN=0
F S DFN=$O(^DPT(DFN)) Q:'DFN D
. ; *disabled* since user may now select Living, Deceased or both as a filter
. ;I $P($G(^DPT(DFN,.35)),U,1)'="" Q
. I '$$HRN^BQIUL1(DFN) Q
. ; If patient has no visit in last 3 years, quit
. ;I '$$VTHR^BQIUL1(DFN) Q
. S FDT=FRDT,EDT=ENDT
. F S FDT=$O(^DPT(DFN,"S",FDT)) Q:'FDT!(FDT\1>EDT) D
.. S STR=$G(^DPT(DFN,"S",FDT,0)) I STR="" Q
.. S SLOC=$P(STR,U),STAT=$P(STR,U,2) I SLOC="" Q
.. I '$D(LOC(SLOC)) Q
.. I $D(APSTAT) D Q
... I APSTAT="AC",STAT'="" Q
... I STAT'=APSTAT Q
... S @DATA@(DFN)=""
.. I $D(MPARMS("APSTAT")) D Q
... I STAT'="",'$D(MPARMS("APSTAT",STAT)) Q
... I STAT="",'$D(MPARMS("APSTAT","AC")) Q
... S @DATA@(DFN)=""
.. S @DATA@(DFN)=""
Q
BQIDCAPC ;GDIT/HS/ALA-Scheduled Visits by Clinic Stop ; 21 Nov 2005 6:04 PM
+1 ;;2.3;ICARE MANAGEMENT SYSTEM;**3,4**;Apr 18, 2012;Build 66
+2 ;
+3 QUIT
+4 ;
APT(DATA,PARMS,MPARMS) ;EP
+1 ;
+2 ;Description
+3 ; Executable to retrieve patients which have appointments in a hospital location that
+4 ; is associated with a clinical stop code.
+5 ;Input
+6 ; PARMS = Array of parameters and their values
+7 ; MPARMS = Multiple array of a parameter
+8 ;Expected to return DATA
+9 ;Parameters
+10 ; CLIN = Clinic Stop Code parameter
+11 ; LOC = Hosp Location internal entry number associated with CLIN
+12 ; FDT = Starting date for the FROM date parameter
+13 ; EDT = Ending date for the THRU date parameter
+14 ; DFN = Patient internal entry number
+15 ; APSTAT = Appointment status
+16 ;
+17 NEW II,UID
+18 SET UID=$SELECT($GET(ZTSK):"Z"_ZTSK,1:$JOB)
+19 SET DATA=$NAME(^TMP("BQIDCAPC",UID))
+20 KILL @DATA
+21 SET II=0
+22 ;
FND ; Find the patients with appts for one or more clinic stop codes
+1 NEW CLIN,FROM,THRU,LOC,NM,N,FRDT,ENDT,LABEL,APST,STOP,FDT,EDT,DFN,LABEL
+2 NEW STR,SLOC,STAT,APSTAT,APTYPE,APRANGE,RFROM,RTHRU
+3 SET NM=""
+4 FOR
SET NM=$ORDER(PARMS(NM))
IF NM=""
QUIT
SET @NM=PARMS(NM)
+5 IF $GET(APTYPE)'=""
Begin DoDot:1
+6 NEW MIEN,MAPS
+7 SET MIEN=$ORDER(^BQI(90506,10,3,8,3,"B",APTYPE,""))
IF MIEN=""
QUIT
+8 SET MAPS=$PIECE(^BQI(90506,10,3,8,3,MIEN,0),U,2)
+9 FOR N=1:1:$LENGTH(MAPS,"~")
SET NM=$PIECE($PIECE(MAPS,"~",N),"=",1)
SET MPARMS(NM,$PIECE($PIECE(MAPS,"~",N),"=",2))=""
End DoDot:1
+10 ;
+11 IF $DATA(MPARMS("APTYPE"))>0
Begin DoDot:1
+12 NEW MPM,MIEN,MAPS
+13 SET MPM=""
+14 FOR
SET MPM=$ORDER(MPARMS("APTYPE",MPM))
IF MPM=""
QUIT
Begin DoDot:2
+15 SET MIEN=$ORDER(^BQI(90506,10,3,8,3,"B",MPM,""))
IF MIEN=""
QUIT
+16 SET MAPS=$PIECE(^BQI(90506,10,3,8,3,MIEN,0),U,2)
+17 FOR N=1:1:$LENGTH(MAPS,"~")
SET NM=$PIECE($PIECE(MAPS,"~",N),"=",1)
SET MPARMS(NM,$PIECE($PIECE(MAPS,"~",N),"=",2))=""
End DoDot:2
End DoDot:1
+18 ;
+19 SET LABEL="FND1"
Begin DoDot:1
+20 IF $GET(APSTAT)'=""
IF APSTAT'="AC"
IF APSTAT["C"
SET LABEL="FNDALL"
QUIT
+21 IF $DATA(MPARMS("APSTAT"))
Begin DoDot:2
+22 SET APST=""
SET STOP=""
+23 FOR
SET APST=$ORDER(MPARMS("APSTAT",APST))
IF APST=""
QUIT
Begin DoDot:3
+24 IF APST'="AC"
IF APST["C"
SET LABEL="FNDALL"
SET STOP=1
QUIT
End DoDot:3
IF STOP
QUIT
End DoDot:2
QUIT
End DoDot:1
+25 IF LABEL="FNDALL"
DO FNDALL
QUIT
+26 IF $GET(CLIN)]""
DO FND1
+27 IF $DATA(MPARMS("CLIN"))
SET CLIN=""
FOR
SET CLIN=$ORDER(MPARMS("CLIN",CLIN))
IF CLIN=""
QUIT
DO FND1
+28 QUIT
+29 ;
FND1 ; Check one clinic stop code
+1 ; If timeframe is selected populate start and end dates
+2 IF $GET(APRANGE)'=""
IF $GET(PPIEN)'=""
DO RANGE^BQIDCAH1(APRANGE,PPIEN,"APRANGE")
+3 SET LOC=""
+4 FOR
SET LOC=$ORDER(^SC("ASTOP",CLIN,LOC))
IF LOC=""
QUIT
Begin DoDot:1
+5 SET FDT=$SELECT($GET(RFROM)'="":RFROM,1:$GET(FROM))
+6 SET EDT=$SELECT($GET(RTHRU)'="":RTHRU,1:$GET(THRU))
+7 NEW APCHK
+8 FOR
SET FDT=$ORDER(^SC(LOC,"S",FDT))
IF FDT=""!(FDT\1>EDT)
QUIT
Begin DoDot:2
+9 SET N=0
+10 FOR
SET N=$ORDER(^SC(LOC,"S",FDT,1,N))
IF 'N
QUIT
Begin DoDot:3
+11 NEW DA,IENS
+12 SET DA(2)=LOC
SET DA(1)=FDT
SET DA=N
SET IENS=$$IENS^DILF(.DA)
+13 SET DFN=$$GET1^DIQ(44.003,IENS,.01,"I")
IF DFN=""
QUIT
+14 ; User may now select Living, Deceased or both as a filter so
+15 ; if no filters defined assume living patients otherwise let filter decide
+16 ;I $O(^BQICARE(OWNR,1,PLIEN,15,0))="",$P($G(^DPT(DFN,.35)),U,1)'="" Q
+17 IF '$$HRN^BQIUL1(DFN)
QUIT
+18 ; If patient has no visit in last 3 years, quit
+19 ;I '$$VTHR^BQIUL1(DFN) Q
+20 IF $GET(APSTAT)'=""
Begin DoDot:4
+21 IF $GET(APSTAT)="AC"
SET APCHK=""
+22 IF $GET(APSTAT)'="AC"
SET APCHK=APSTAT
+23 IF $PIECE($GET(^DPT(DFN,"S",FDT,0)),U,2)'=APCHK
QUIT
+24 SET @DATA@(DFN)=""
End DoDot:4
QUIT
+25 IF $DATA(MPARMS("APSTAT"))
Begin DoDot:4
+26 SET APST=""
+27 FOR
SET APST=$ORDER(MPARMS("APSTAT",APST))
IF APST=""
QUIT
Begin DoDot:5
+28 IF $GET(APST)="AC"
SET APCHK=""
+29 IF $GET(APST)'="AC"
SET APCHK=APST
+30 IF $PIECE($GET(^DPT(DFN,"S",FDT,0)),U,2)'=APCHK
QUIT
+31 SET @DATA@(DFN)=""
End DoDot:5
End DoDot:4
QUIT
+32 ;S @DATA@(DFN)=""
End DoDot:3
End DoDot:2
End DoDot:1
+33 QUIT
+34 ;
FNDALL ; Loop through all patients since cancelled status selected
+1 ; If timeframe is selected populate start and end dates
+2 NEW FRDT,ENDT
+3 IF $GET(APRANGE)'=""
IF $GET(PPIEN)'=""
DO RANGE^BQIDCAH1(APRANGE,PPIEN,"APRANGE")
+4 SET FRDT=$SELECT($GET(RFROM)'="":RFROM,1:$GET(FROM))
+5 SET ENDT=$SELECT($GET(RTHRU)'="":RTHRU,1:$GET(THRU))
+6 IF $GET(CLIN)]""
Begin DoDot:1
+7 SET LOC=""
+8 FOR
SET LOC=$ORDER(^SC("ASTOP",CLIN,LOC))
IF LOC=""
QUIT
SET LOC(LOC)=""
End DoDot:1
+9 IF $DATA(MPARMS("CLIN"))
Begin DoDot:1
+10 SET CLIN=""
+11 FOR
SET CLIN=$ORDER(MPARMS("CLIN",CLIN))
IF CLIN=""
QUIT
Begin DoDot:2
+12 SET LOC=""
+13 FOR
SET LOC=$ORDER(^SC("ASTOP",CLIN,LOC))
IF LOC=""
QUIT
SET LOC(LOC)=""
End DoDot:2
End DoDot:1
+14 NEW APCHK
+15 SET DFN=0
+16 FOR
SET DFN=$ORDER(^DPT(DFN))
IF 'DFN
QUIT
Begin DoDot:1
+17 ; *disabled* since user may now select Living, Deceased or both as a filter
+18 ;I $P($G(^DPT(DFN,.35)),U,1)'="" Q
+19 IF '$$HRN^BQIUL1(DFN)
QUIT
+20 ; If patient has no visit in last 3 years, quit
+21 ;I '$$VTHR^BQIUL1(DFN) Q
+22 SET FDT=FRDT
SET EDT=ENDT
+23 FOR
SET FDT=$ORDER(^DPT(DFN,"S",FDT))
IF 'FDT!(FDT\1>EDT)
QUIT
Begin DoDot:2
+24 SET STR=$GET(^DPT(DFN,"S",FDT,0))
IF STR=""
QUIT
+25 SET SLOC=$PIECE(STR,U)
SET STAT=$PIECE(STR,U,2)
IF SLOC=""
QUIT
+26 IF '$DATA(LOC(SLOC))
QUIT
+27 IF $DATA(APSTAT)
Begin DoDot:3
+28 IF APSTAT="AC"
IF STAT'=""
QUIT
+29 IF STAT'=APSTAT
QUIT
+30 SET @DATA@(DFN)=""
End DoDot:3
QUIT
+31 IF $DATA(MPARMS("APSTAT"))
Begin DoDot:3
+32 IF STAT'=""
IF '$DATA(MPARMS("APSTAT",STAT))
QUIT
+33 IF STAT=""
IF '$DATA(MPARMS("APSTAT","AC"))
QUIT
+34 SET @DATA@(DFN)=""
End DoDot:3
QUIT
+35 SET @DATA@(DFN)=""
End DoDot:2
End DoDot:1
+36 QUIT