BQIREFPL ;GDIT/HS/ALA-Get Referrals by Panel ; 31 Dec 2014 2:27 PM
;;2.6;ICARE MANAGEMENT SYSTEM;;Jul 07, 2017;Build 72
;
;
Q
;
EN(DATA,OWNR,PLIEN,PLIST) ;EP -- BQI GET REFERRALS BY PANEL
;Description - Entry point for the panel
;Input Parameters
; OWNR - Owner of panel
; PLIEN - Panel IEN
; PLIST - List of DFNs (optional)
NEW UID,II,DFN,HEADER,TMP,BHEADR,BVALUE,VAL,VALUE,FLDS,RFIEN,CIEN,CTYPD00015,QFL,TQFL
S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
S DATA=$NA(^TMP("BQIREFPL",UID))
K @DATA
;
S II=0
NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIREFPL D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
;
S RHEADR="",CTYP="RF" D RHD
; If a list of DFNs, process them instead of entire panel
I $D(PLIST)>0 D G DONE
. I $D(PLIST)>1 D
.. S LIST="",BN=""
.. F S BN=$O(PLIST(BN)) Q:BN="" S LIST=LIST_PLIST(BN)
.. K PLIST S PLIST=LIST
. F BQI=1:1 S DFN=$P(PLIST,$C(28),BQI) Q:DFN="" D
.. I $P($G(^BQICARE(OWNR,1,PLIEN,40,DFN,0)),"^",2)="R" Q
.. D PAT(.DATA,OWNR,PLIEN,DFN)
;
S DFN=0
I $O(^BQICARE(OWNR,1,PLIEN,40,DFN))="" D PAT(.DATA,OWNR,PLIEN,"") G DONE
;
F S DFN=$O(^BQICARE(OWNR,1,PLIEN,40,DFN)) Q:'DFN D
. I $P($G(^BQICARE(OWNR,1,PLIEN,40,DFN,0)),"^",2)="R" Q
. D PAT(.DATA,OWNR,PLIEN,DFN)
;
DONE ;
S II=II+1,@DATA@(II)=$C(31)
Q
;
ERR ;
D ^%ZTER
NEW Y,ERRDTM
S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
S BMXSEC="Recording that an error occurred at "_ERRDTM
I $D(II),$D(DATA) S II=II+1,@DATA@(II)=$C(31)
Q
;
PAT(DATA,OWNR,PLIEN,DFN) ;EP - Build record by patient
K VALUE
D HDR^BQIHEADR(OWNR,PLIEN,DFN,.BHEADR,.BVALUE)
S BVALUE=$$TKO^BQIUL1(BVALUE,"^"),VALUE(0)=BVALUE
;S VALUE(0)=BVALUE
S HEADR=BHEADR_RHEADR,HEADR=$$TKO^BQIUL1(HEADR,"^")
I II=0 S @DATA@(II)=HEADR_$C(30)
S CTYP="RF",CRE=0
;
D REFF
S TMP=$NA(^TMP("BQIREFS",UID)) K @TMP
I DFN'="" D RFPT(DFN,FLDS)
; Check for template
NEW DA,IENS,TEMPL,LYIEN,QFL
S TEMPL=""
I OWNR'=DUZ D
. S DA=$O(^BQICARE(OWNR,1,PLIEN,30,DUZ,4,"C",CTYP,""))
. I DA="" Q
. S DA(3)=OWNR,DA(2)=PLIEN,DA(1)=DUZ,IENS=$$IENS^DILF(.DA)
. S TEMPL=$$GET1^DIQ(90505.34,IENS,.01,"E")
I OWNR=DUZ D
. S DA=$O(^BQICARE(OWNR,1,PLIEN,4,"C",CTYP,""))
. I DA="" Q
. S DA(2)=OWNR,DA(1)=PLIEN,IENS=$$IENS^DILF(.DA)
. S TEMPL=$$GET1^DIQ(90505.14,IENS,.01,"E")
;
; If template, use it
I TEMPL'="" S TQFL=0 D G FIN:'TQFL
. S LYIEN=$$TPN^BQILYUTL(DUZ,TEMPL)
. I LYIEN="" S TQFL=1 Q
. I DFN="" S VALUE(1)="" Q
. I '$D(@TMP@(DFN)) S CRE=CRE+1,VALUE(CRE)=VALUE(0)_"^"
. S RFIEN="" F S RFIEN=$O(@TMP@(DFN,RFIEN)) Q:RFIEN="" S CRE=CRE+1,VALUE(CRE)=VALUE(0)_"^"
. S DOR=""
. F S DOR=$O(^BQICARE(DUZ,15,LYIEN,1,"C",DOR)) Q:DOR="" D
.. S IEN=""
.. F S IEN=$O(^BQICARE(DUZ,15,LYIEN,1,"C",DOR,IEN)) Q:IEN="" D
... S CODE=$P(^BQICARE(DUZ,15,LYIEN,1,IEN,0),U,1)
... S GIEN=$O(^BQI(90506.1,"B",CODE,"")) I GIEN="" Q
... S STVW=GIEN
... I $P(^BQI(90506.1,GIEN,0),U,10)=1 Q
... I $$GET1^DIQ(90506.1,GIEN_",",3.01,"E")="Patient" D
.... S STVW=GIEN D CVAL
.... F C=1:1:CRE S VALUE(C)=VALUE(C)_VAL_"^"
... I $$GET1^DIQ(90506.1,GIEN_",",3.01,"E")="Referrals" D
.... S RFIEN="",C=0 F S RFIEN=$O(@TMP@(DFN,RFIEN)) Q:RFIEN="" D RVAL(GIEN) S C=C+1,VALUE(C)=VALUE(C)_VAL_"^"
. ;
. F C=1:1:CRE S VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^")
. I DFN="" S VALUE(1)=""
. I $D(VALUE) D
.. F C=1:1:CRE S CLNG=$L(HEADR,"^")-$L(VALUE(C),"^") D
... I CLNG>0 S $P(VALUE(C),"^",$L(HEADR,"^"))=""
... I CLNG<0 S VALUE(C)=$P(VALUE(C),"^",1,$L(HEADR,"^"))
. ;F C=1:1:CRE S II=II+1,VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^"),@DATA@(II)=VALUE(C)_$C(30)
. F C=1:1:CRE S II=II+1,@DATA@(II)=VALUE(C)_$C(30)
. K VALUE S VALUE(0)=BVALUE
. ;
; If no template, check for customized
I OWNR=DUZ D Q
. S IEN=0,CIEN=$O(^BQICARE(OWNR,1,PLIEN,26,IEN))
. I CIEN'="" D Q
.. I DFN="" S VALUE(1)="" Q
.. I '$D(@TMP@(DFN)) S CRE=CRE+1,VALUE(CRE)=VALUE(0)_"^"
.. S RFIEN="" F S RFIEN=$O(@TMP@(DFN,RFIEN)) Q:RFIEN="" S CRE=CRE+1,VALUE(CRE)=VALUE(0)_"^"
.. F S IEN=$O(^BQICARE(OWNR,1,PLIEN,26,IEN)) Q:'IEN D
... S CODE=$P(^BQICARE(OWNR,1,PLIEN,26,IEN,0),"^",1)
... S SIEN=$O(^BQI(90506.1,"B",CODE,"")) I SIEN="" Q
... I $P(^BQI(90506.1,SIEN,0),U,10)=1 Q
... I $$GET1^DIQ(90506.1,SIEN_",",3.01,"E")="Patient" D
.... S STVW=SIEN D CVAL
.... F C=1:1:CRE S VALUE(C)=VALUE(C)_VAL_"^"
... I $$GET1^DIQ(90506.1,SIEN_",",3.01,"E")="Referrals" D
.... I '$D(@TMP@(DFN)) S VALUE(CRE)=VALUE(CRE)_"^" Q
.... S RFIEN="",C=0 F S RFIEN=$O(@TMP@(DFN,RFIEN)) Q:RFIEN="" D RVAL(SIEN) S C=C+1,VALUE(C)=VALUE(C)_VAL_"^"
.. I DFN="" S VALUE(1)=""
.. I $D(VALUE) D
.. F C=1:1:CRE S CLNG=$L(HEADR,"^")-$L(VALUE(C),"^") D
... I CLNG>0 S $P(VALUE(C),"^",$L(HEADR,"^"))=""
... I CLNG<0 S VALUE(C)=$P(VALUE(C),"^",1,$L(HEADR,"^"))
.. ;F C=1:1:CRE S II=II+1,VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^"),@DATA@(II)=VALUE(C)_$C(30)
.. F C=1:1:CRE S II=II+1,@DATA@(II)=VALUE(C)_$C(30)
. K VALUE S VALUE(0)=BVALUE
. ; If no customized found, use default
. I CIEN="" D STAND()
;
I OWNR'=DUZ D
. S IEN=0,CIEN=$O(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN))
. I CIEN'="" D Q
.. I DFN="" S VALUE(1)="" Q
.. I '$D(@TMP@(DFN)) S CRE=CRE+1,VALUE(CRE)=VALUE(0)_"^"
.. S RFIEN="" F S RFIEN=$O(@TMP@(DFN,RFIEN)) Q:RFIEN="" S CRE=CRE+1,VALUE(CRE)=VALUE(0)_"^"
.. F S IEN=$O(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN)) Q:'IEN D
... S CODE=$P(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN,0),"^",1)
... S SIEN=$O(^BQI(90506.1,"B",CODE,"")) I SIEN="" Q
... I $P(^BQI(90506.1,SIEN,0),U,10)=1 Q
... I $$GET1^DIQ(90506.1,SIEN_",",3.01,"E")="Patient" D
.... S STVW=SIEN D CVAL
.... F C=1:1:CRE S VALUE(C)=VALUE(C)_VAL_"^"
... I $$GET1^DIQ(90506.1,SIEN_",",3.01,"E")="Referrals" D
.... I '$D(@TMP@(DFN)) S VALUE(CRE)=VALUE(CRE)_"^" Q
.... S RFIEN="",C=0 F S RFIEN=$O(@TMP@(DFN,RFIEN)) Q:RFIEN="" D RVAL(SIEN) S C=C+1,VALUE(C)=VALUE(C)_VAL_"^"
.. ;
.. I $D(VALUE) D
.. F C=1:1:CRE S CLNG=$L(HEADR,"^")-$L(VALUE(C),"^") D
... I CLNG>0 S $P(VALUE(C),"^",$L(HEADR,"^"))=""
... I CLNG<0 S VALUE(C)=$P(VALUE(C),"^",1,$L(HEADR,"^"))
.. ;F C=1:1:CRE S II=II+1,VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^"),@DATA@(II)=VALUE(C)_$C(30)
.. F C=1:1:CRE S II=II+1,@DATA@(II)=VALUE(C)_$C(30)
. K VALUE S VALUE(0)=BVALUE
. ; If no customized found, use default
. I CIEN="" D STAND()
Q
;
STAND() ;EP - Get standard display
S CRE=0
S RHEADR=BHEADR D RSH() S HEADR=RHEADR
S RHEADR=$$TKO^BQIUL1(RHEADR,"^")
I II=0 S @DATA@(II)=RHEADR_$C(30)
I '$D(@TMP) S CRE=CRE+1,VALUE(CRE)=VALUE(0)_"^"
S RFIEN="" F S RFIEN=$O(@TMP@(DFN,RFIEN)) Q:RFIEN="" S CRE=CRE+1,VALUE(CRE)=VALUE(0)_"^"
S IEN=""
F S IEN=$O(^BQI(90506.1,"AC","D",IEN)) Q:IEN="" D
. I $P(^BQI(90506.1,IEN,0),U,10)=1 Q
. S KEY=$$GET1^DIQ(90506.1,IEN_",",3.1,"E")
. I KEY'="",'$$KEYCHK^BQIULSC(KEY,DUZ) Q
. I $P($G(^BQI(90506.1,IEN,3)),"^",4)'="O" D
.. S STVW=IEN
.. D CVAL
.. F C=1:1:CRE S VALUE(C)=VALUE(C)_VAL_"^"
;
;Get patient referrals
S IEN=""
F S IEN=$O(^BQI(90506.1,"AC","RF",IEN)) Q:IEN="" D
. I $P(^BQI(90506.1,IEN,0),U,10)=1 Q
. S KEY=$$GET1^DIQ(90506.1,IEN_",",3.1,"E")
. I KEY'="",'$$KEYCHK^BQIULSC(KEY,DUZ) Q
. I $P($G(^BQI(90506.1,IEN,3)),"^",4)'="O" D
.. S STVW=IEN
.. I '$D(@TMP@(DFN)) S VALUE(CRE)=VALUE(CRE)_"^" Q
.. S RFIEN="",C=0 F S RFIEN=$O(@TMP@(DFN,RFIEN)) Q:RFIEN="" D RVAL(IEN) S C=C+1,VALUE(C)=VALUE(C)_VAL_"^"
;
F C=1:1:CRE S VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^")
I DFN="" S VALUE(1)=""
I $D(VALUE) D
. F C=1:1:CRE S CLNG=$L(HEADR,"^")-$L(VALUE(C),"^") D
.. I CLNG>0 S $P(VALUE(C),"^",$L(HEADR,"^"))=""
.. I CLNG<0 S VALUE(C)=$P(VALUE(C),"^",1,$L(HEADR,"^"))
;F C=1:1:CRE S II=II+1,VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^"),@DATA@(II)=VALUE(C)_$C(30)
F C=1:1:CRE S II=II+1,@DATA@(II)=VALUE(C)_$C(30)
K VALUE S VALUE(0)=BVALUE
;
FIN ;
Q
;
CVAL ; Get demographic values
;Parameters
; FIL = FileMan file number
; FLD = FileMan field number
; EXEC = If an executable is needed to determine value
; HDR = Header value
;the executable expects the value to be returned in variable VAL
NEW FIL,FLD,EXEC
S FIL=$P(^BQI(90506.1,STVW,0),"^",5)
S FLD=$P(^BQI(90506.1,STVW,0),"^",6)
S EXEC=$$GET1^DIQ(90506.1,STVW_",",1,"E")
S EXEC=$G(^BQI(90506.1,STVW,1))
S HDR=$P(^BQI(90506.1,STVW,0),"^",8)
I $G(DFN)="" S VAL="" Q
;
I $G(EXEC)'="" X EXEC Q
;
I FIL'="",FLD'="" S VAL=$$GET1^DIQ(FIL,DFN_",",FLD,"E")
Q
;
REFF ;EP
NEW ORD,IEN,FLD,FIE
;set up fields by display order
S ORD="",FLDS=""
F S ORD=$O(^BQI(90506.1,"AD","RF",ORD)) Q:ORD="" D
. S IEN=""
. F S IEN=$O(^BQI(90506.1,"AD","RF",ORD,IEN)) Q:IEN="" D
.. S FLD=$$GET1^DIQ(90506.1,IEN_",",.06,"E"),FIE=$$GET1^DIQ(90506.1,IEN_",",.2,"I")
.. I FIE="" S FIE="E"
.. S FLDS=FLDS_FLD_"/"_FIE_";"
S FLDS=$$TKO^BQIUL1(FLDS,";")
Q
;
RFPT(DFN,FLDS) ;EP
NEW BGDT,BQIPAT
S TMP=$NA(^TMP("BQIREFS",UID)) K @TMP
S BGDT=$P($G(^BQI(90508,1,16)),"^",4) I BGDT="" S BGDT="T-12M"
S BGDT=$$DATE^BQIUL1(BGDT)
S BQIPAT(DFN)=""
D API^BMCAPI1(.BQIPAT,BGDT,"",FLDS,TMP)
K BQIPAT
;
Q
;
RVAL(STVW) ;EP
NEW FIL,FLD,EXEC,DTY
S FIL=$P(^BQI(90506.1,STVW,0),"^",5)
S FLD=$P(^BQI(90506.1,STVW,0),"^",6)
S EXEC=$G(^BQI(90506.1,STVW,1))
S DTY=$P(^BQI(90506.1,STVW,0),"^",20)
S ORD=$P($G(^BQI(90506.1,STVW,3)),"^",5)
I $G(DFN)="" S VAL="" Q
;
I $G(EXEC)'="" X EXEC Q
;
I FLD'="" S VAL=$G(@TMP@(DFN,ORD,FLD,DTYP))
Q
;
DSP() ;EP
NEW ORD,FIE,VAL
S VAL=""
S ORD=$$GET1^DIQ(90506.1,STVW_",",3.05,"E")
S FIE=$$GET1^DIQ(90506.1,STVW_",",.2,"I") S:FIE="" FIE="E"
S VAL=$G(@TMP@(DFN,RFIEN,ORD,FLD,FIE))
I FIE="I" S VAL=$$FMTMDY^BQIUL1(VAL)
Q VAL
;
RHD ;EP - Referral header
; Check for template
NEW DA,IENS,TEMPL,LYIEN,QFL,TQFL
S TEMPL=""
I OWNR'=DUZ D
. S DA=$O(^BQICARE(OWNR,1,PLIEN,30,DUZ,4,"C",CTYP,""))
. I DA="" Q
. S DA(3)=OWNR,DA(2)=PLIEN,DA(1)=DUZ,IENS=$$IENS^DILF(.DA)
. S TEMPL=$$GET1^DIQ(90505.34,IENS,.01,"E")
I OWNR=DUZ D
. S DA=$O(^BQICARE(OWNR,1,PLIEN,4,"C",CTYP,""))
. I DA="" Q
. S DA(2)=OWNR,DA(1)=PLIEN,IENS=$$IENS^DILF(.DA)
. S TEMPL=$$GET1^DIQ(90505.14,IENS,.01,"E")
;
; If template, use it
I TEMPL'="" S TQFL=0 D G FH:'TQFL
. S LYIEN=$$TPN^BQILYUTL(DUZ,TEMPL)
. I LYIEN="" S TQFL=1 Q
. S DOR=""
. F S DOR=$O(^BQICARE(DUZ,15,LYIEN,1,"C",DOR)) Q:DOR="" D
.. S IEN=""
.. F S IEN=$O(^BQICARE(DUZ,15,LYIEN,1,"C",DOR,IEN)) Q:IEN="" D
... S CODE=$P(^BQICARE(DUZ,15,LYIEN,1,IEN,0),U,1)
... S GIEN=$O(^BQI(90506.1,"B",CODE,"")) I GIEN="" Q
... S STVW=GIEN
... I $P(^BQI(90506.1,GIEN,0),U,10)=1 Q
... S HDR=$P(^BQI(90506.1,STVW,0),"^",8)
... S RHEADR=RHEADR_HDR_"^"
. S RHEADR=$$TKO^BQIUL1(RHEADR,"^")
;
; If no template, check for customized
I OWNR=DUZ D
. S IEN=0,CIEN=$O(^BQICARE(OWNR,1,PLIEN,26,IEN))
. I CIEN'="" D Q
.. F S IEN=$O(^BQICARE(OWNR,1,PLIEN,26,IEN)) Q:'IEN D
... S CODE=$P(^BQICARE(OWNR,1,PLIEN,26,IEN,0),"^",1)
... S SIEN=$O(^BQI(90506.1,"B",CODE,"")) I SIEN="" Q
... I $P(^BQI(90506.1,SIEN,0),U,10)=1 Q
... S HDR=$$GET1^DIQ(90506.1,SIEN_",",.08,"E")
... S RHEADR=RHEADR_HDR_"^"
. S RHEADR=$$TKO^BQIUL1(RHEADR,"^")
. ;
. ; If no customized found, use default
. I CIEN="" D RSH()
;
I OWNR'=DUZ D
. S IEN=0,CIEN=$O(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN))
. I CIEN'="" D Q
.. F S IEN=$O(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN)) Q:'IEN D
... S CODE=$P(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN,0),"^",1)
... S SIEN=$O(^BQI(90506.1,"B",CODE,"")) I SIEN="" Q
... I $P(^BQI(90506.1,SIEN,0),U,10)=1 Q
... S HDR=$P(^BQI(90506.1,SIEN,0),"^",8)
... S RHEADR=RHEADR_HDR_"^"
. S RHEADR=$$TKO^BQIUL1(RHEADR,"^")
. ;
. ; If no customized found, use default
. I CIEN="" D RSH()
;
FH ;
Q
;
RSH() ;EP - Get standard header
S IEN=""
F S IEN=$O(^BQI(90506.1,"AC","D",IEN)) Q:IEN="" D
. I $P(^BQI(90506.1,IEN,0),U,10)=1 Q
. S KEY=$$GET1^DIQ(90506.1,IEN_",",3.1,"E")
. I KEY'="",'$$KEYCHK^BQIULSC(KEY,DUZ) Q
. I $P($G(^BQI(90506.1,IEN,3)),"^",4)'="O" D
.. S STVW=IEN
.. S HDR=$P(^BQI(90506.1,STVW,0),"^",8)
.. S RHEADR=RHEADR_HDR_"^"
;
S IEN=""
F S IEN=$O(^BQI(90506.1,"AC","RF",IEN)) Q:IEN="" D
. I $P(^BQI(90506.1,IEN,0),U,10)=1 Q
. S KEY=$$GET1^DIQ(90506.1,IEN_",",3.1,"E")
. I KEY'="",'$$KEYCHK^BQIULSC(KEY,DUZ) Q
. I $P($G(^BQI(90506.1,IEN,3)),"^",4)'="O" D
.. S STVW=IEN
.. S HDR=$P(^BQI(90506.1,STVW,0),"^",8)
.. S RHEADR=RHEADR_HDR_"^"
S RHEADR=$$TKO^BQIUL1(RHEADR,"^")
Q
BQIREFPL ;GDIT/HS/ALA-Get Referrals by Panel ; 31 Dec 2014 2:27 PM
+1 ;;2.6;ICARE MANAGEMENT SYSTEM;;Jul 07, 2017;Build 72
+2 ;
+3 ;
+4 QUIT
+5 ;
EN(DATA,OWNR,PLIEN,PLIST) ;EP -- BQI GET REFERRALS BY PANEL
+1 ;Description - Entry point for the panel
+2 ;Input Parameters
+3 ; OWNR - Owner of panel
+4 ; PLIEN - Panel IEN
+5 ; PLIST - List of DFNs (optional)
+6 NEW UID,II,DFN,HEADER,TMP,BHEADR,BVALUE,VAL,VALUE,FLDS,RFIEN,CIEN,CTYPD00015,QFL,TQFL
+7 SET UID=$SELECT($GET(ZTSK):"Z"_ZTSK,1:$JOB)
+8 SET DATA=$NAME(^TMP("BQIREFPL",UID))
+9 KILL @DATA
+10 ;
+11 SET II=0
+12 ; SAC 2006 2.2.3.3.2
NEW $ESTACK,$ETRAP
SET $ETRAP="D ERR^BQIREFPL D UNWIND^%ZTER"
+13 ;
+14 SET RHEADR=""
SET CTYP="RF"
DO RHD
+15 ; If a list of DFNs, process them instead of entire panel
+16 IF $DATA(PLIST)>0
Begin DoDot:1
+17 IF $DATA(PLIST)>1
Begin DoDot:2
+18 SET LIST=""
SET BN=""
+19 FOR
SET BN=$ORDER(PLIST(BN))
IF BN=""
QUIT
SET LIST=LIST_PLIST(BN)
+20 KILL PLIST
SET PLIST=LIST
End DoDot:2
+21 FOR BQI=1:1
SET DFN=$PIECE(PLIST,$CHAR(28),BQI)
IF DFN=""
QUIT
Begin DoDot:2
+22 IF $PIECE($GET(^BQICARE(OWNR,1,PLIEN,40,DFN,0)),"^",2)="R"
QUIT
+23 DO PAT(.DATA,OWNR,PLIEN,DFN)
End DoDot:2
End DoDot:1
GOTO DONE
+24 ;
+25 SET DFN=0
+26 IF $ORDER(^BQICARE(OWNR,1,PLIEN,40,DFN))=""
DO PAT(.DATA,OWNR,PLIEN,"")
GOTO DONE
+27 ;
+28 FOR
SET DFN=$ORDER(^BQICARE(OWNR,1,PLIEN,40,DFN))
IF 'DFN
QUIT
Begin DoDot:1
+29 IF $PIECE($GET(^BQICARE(OWNR,1,PLIEN,40,DFN,0)),"^",2)="R"
QUIT
+30 DO PAT(.DATA,OWNR,PLIEN,DFN)
End DoDot:1
+31 ;
DONE ;
+1 SET II=II+1
SET @DATA@(II)=$CHAR(31)
+2 QUIT
+3 ;
ERR ;
+1 DO ^%ZTER
+2 NEW Y,ERRDTM
+3 SET Y=$$NOW^XLFDT()
XECUTE ^DD("DD")
SET ERRDTM=Y
+4 SET BMXSEC="Recording that an error occurred at "_ERRDTM
+5 IF $DATA(II)
IF $DATA(DATA)
SET II=II+1
SET @DATA@(II)=$CHAR(31)
+6 QUIT
+7 ;
PAT(DATA,OWNR,PLIEN,DFN) ;EP - Build record by patient
+1 KILL VALUE
+2 DO HDR^BQIHEADR(OWNR,PLIEN,DFN,.BHEADR,.BVALUE)
+3 SET BVALUE=$$TKO^BQIUL1(BVALUE,"^")
SET VALUE(0)=BVALUE
+4 ;S VALUE(0)=BVALUE
+5 SET HEADR=BHEADR_RHEADR
SET HEADR=$$TKO^BQIUL1(HEADR,"^")
+6 IF II=0
SET @DATA@(II)=HEADR_$CHAR(30)
+7 SET CTYP="RF"
SET CRE=0
+8 ;
+9 DO REFF
+10 SET TMP=$NAME(^TMP("BQIREFS",UID))
KILL @TMP
+11 IF DFN'=""
DO RFPT(DFN,FLDS)
+12 ; Check for template
+13 NEW DA,IENS,TEMPL,LYIEN,QFL
+14 SET TEMPL=""
+15 IF OWNR'=DUZ
Begin DoDot:1
+16 SET DA=$ORDER(^BQICARE(OWNR,1,PLIEN,30,DUZ,4,"C",CTYP,""))
+17 IF DA=""
QUIT
+18 SET DA(3)=OWNR
SET DA(2)=PLIEN
SET DA(1)=DUZ
SET IENS=$$IENS^DILF(.DA)
+19 SET TEMPL=$$GET1^DIQ(90505.34,IENS,.01,"E")
End DoDot:1
+20 IF OWNR=DUZ
Begin DoDot:1
+21 SET DA=$ORDER(^BQICARE(OWNR,1,PLIEN,4,"C",CTYP,""))
+22 IF DA=""
QUIT
+23 SET DA(2)=OWNR
SET DA(1)=PLIEN
SET IENS=$$IENS^DILF(.DA)
+24 SET TEMPL=$$GET1^DIQ(90505.14,IENS,.01,"E")
End DoDot:1
+25 ;
+26 ; If template, use it
+27 IF TEMPL'=""
SET TQFL=0
Begin DoDot:1
+28 SET LYIEN=$$TPN^BQILYUTL(DUZ,TEMPL)
+29 IF LYIEN=""
SET TQFL=1
QUIT
+30 IF DFN=""
SET VALUE(1)=""
QUIT
+31 IF '$DATA(@TMP@(DFN))
SET CRE=CRE+1
SET VALUE(CRE)=VALUE(0)_"^"
+32 SET RFIEN=""
FOR
SET RFIEN=$ORDER(@TMP@(DFN,RFIEN))
IF RFIEN=""
QUIT
SET CRE=CRE+1
SET VALUE(CRE)=VALUE(0)_"^"
+33 SET DOR=""
+34 FOR
SET DOR=$ORDER(^BQICARE(DUZ,15,LYIEN,1,"C",DOR))
IF DOR=""
QUIT
Begin DoDot:2
+35 SET IEN=""
+36 FOR
SET IEN=$ORDER(^BQICARE(DUZ,15,LYIEN,1,"C",DOR,IEN))
IF IEN=""
QUIT
Begin DoDot:3
+37 SET CODE=$PIECE(^BQICARE(DUZ,15,LYIEN,1,IEN,0),U,1)
+38 SET GIEN=$ORDER(^BQI(90506.1,"B",CODE,""))
IF GIEN=""
QUIT
+39 SET STVW=GIEN
+40 IF $PIECE(^BQI(90506.1,GIEN,0),U,10)=1
QUIT
+41 IF $$GET1^DIQ(90506.1,GIEN_",",3.01,"E")="Patient"
Begin DoDot:4
+42 SET STVW=GIEN
DO CVAL
+43 FOR C=1:1:CRE
SET VALUE(C)=VALUE(C)_VAL_"^"
End DoDot:4
+44 IF $$GET1^DIQ(90506.1,GIEN_",",3.01,"E")="Referrals"
Begin DoDot:4
+45 SET RFIEN=""
SET C=0
FOR
SET RFIEN=$ORDER(@TMP@(DFN,RFIEN))
IF RFIEN=""
QUIT
DO RVAL(GIEN)
SET C=C+1
SET VALUE(C)=VALUE(C)_VAL_"^"
End DoDot:4
End DoDot:3
End DoDot:2
+46 ;
+47 FOR C=1:1:CRE
SET VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^")
+48 IF DFN=""
SET VALUE(1)=""
+49 IF $DATA(VALUE)
Begin DoDot:2
+50 FOR C=1:1:CRE
SET CLNG=$LENGTH(HEADR,"^")-$LENGTH(VALUE(C),"^")
Begin DoDot:3
+51 IF CLNG>0
SET $PIECE(VALUE(C),"^",$LENGTH(HEADR,"^"))=""
+52 IF CLNG<0
SET VALUE(C)=$PIECE(VALUE(C),"^",1,$LENGTH(HEADR,"^"))
End DoDot:3
End DoDot:2
+53 ;F C=1:1:CRE S II=II+1,VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^"),@DATA@(II)=VALUE(C)_$C(30)
+54 FOR C=1:1:CRE
SET II=II+1
SET @DATA@(II)=VALUE(C)_$CHAR(30)
+55 KILL VALUE
SET VALUE(0)=BVALUE
+56 ;
End DoDot:1
IF 'TQFL
GOTO FIN
+57 ; If no template, check for customized
+58 IF OWNR=DUZ
Begin DoDot:1
+59 SET IEN=0
SET CIEN=$ORDER(^BQICARE(OWNR,1,PLIEN,26,IEN))
+60 IF CIEN'=""
Begin DoDot:2
+61 IF DFN=""
SET VALUE(1)=""
QUIT
+62 IF '$DATA(@TMP@(DFN))
SET CRE=CRE+1
SET VALUE(CRE)=VALUE(0)_"^"
+63 SET RFIEN=""
FOR
SET RFIEN=$ORDER(@TMP@(DFN,RFIEN))
IF RFIEN=""
QUIT
SET CRE=CRE+1
SET VALUE(CRE)=VALUE(0)_"^"
+64 FOR
SET IEN=$ORDER(^BQICARE(OWNR,1,PLIEN,26,IEN))
IF 'IEN
QUIT
Begin DoDot:3
+65 SET CODE=$PIECE(^BQICARE(OWNR,1,PLIEN,26,IEN,0),"^",1)
+66 SET SIEN=$ORDER(^BQI(90506.1,"B",CODE,""))
IF SIEN=""
QUIT
+67 IF $PIECE(^BQI(90506.1,SIEN,0),U,10)=1
QUIT
+68 IF $$GET1^DIQ(90506.1,SIEN_",",3.01,"E")="Patient"
Begin DoDot:4
+69 SET STVW=SIEN
DO CVAL
+70 FOR C=1:1:CRE
SET VALUE(C)=VALUE(C)_VAL_"^"
End DoDot:4
+71 IF $$GET1^DIQ(90506.1,SIEN_",",3.01,"E")="Referrals"
Begin DoDot:4
+72 IF '$DATA(@TMP@(DFN))
SET VALUE(CRE)=VALUE(CRE)_"^"
QUIT
+73 SET RFIEN=""
SET C=0
FOR
SET RFIEN=$ORDER(@TMP@(DFN,RFIEN))
IF RFIEN=""
QUIT
DO RVAL(SIEN)
SET C=C+1
SET VALUE(C)=VALUE(C)_VAL_"^"
End DoDot:4
End DoDot:3
+74 IF DFN=""
SET VALUE(1)=""
+75 IF $DATA(VALUE)
Begin DoDot:3
End DoDot:3
+76 FOR C=1:1:CRE
SET CLNG=$LENGTH(HEADR,"^")-$LENGTH(VALUE(C),"^")
Begin DoDot:3
+77 IF CLNG>0
SET $PIECE(VALUE(C),"^",$LENGTH(HEADR,"^"))=""
+78 IF CLNG<0
SET VALUE(C)=$PIECE(VALUE(C),"^",1,$LENGTH(HEADR,"^"))
End DoDot:3
+79 ;F C=1:1:CRE S II=II+1,VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^"),@DATA@(II)=VALUE(C)_$C(30)
+80 FOR C=1:1:CRE
SET II=II+1
SET @DATA@(II)=VALUE(C)_$CHAR(30)
End DoDot:2
QUIT
+81 KILL VALUE
SET VALUE(0)=BVALUE
+82 ; If no customized found, use default
+83 IF CIEN=""
DO STAND()
End DoDot:1
QUIT
+84 ;
+85 IF OWNR'=DUZ
Begin DoDot:1
+86 SET IEN=0
SET CIEN=$ORDER(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN))
+87 IF CIEN'=""
Begin DoDot:2
+88 IF DFN=""
SET VALUE(1)=""
QUIT
+89 IF '$DATA(@TMP@(DFN))
SET CRE=CRE+1
SET VALUE(CRE)=VALUE(0)_"^"
+90 SET RFIEN=""
FOR
SET RFIEN=$ORDER(@TMP@(DFN,RFIEN))
IF RFIEN=""
QUIT
SET CRE=CRE+1
SET VALUE(CRE)=VALUE(0)_"^"
+91 FOR
SET IEN=$ORDER(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN))
IF 'IEN
QUIT
Begin DoDot:3
+92 SET CODE=$PIECE(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN,0),"^",1)
+93 SET SIEN=$ORDER(^BQI(90506.1,"B",CODE,""))
IF SIEN=""
QUIT
+94 IF $PIECE(^BQI(90506.1,SIEN,0),U,10)=1
QUIT
+95 IF $$GET1^DIQ(90506.1,SIEN_",",3.01,"E")="Patient"
Begin DoDot:4
+96 SET STVW=SIEN
DO CVAL
+97 FOR C=1:1:CRE
SET VALUE(C)=VALUE(C)_VAL_"^"
End DoDot:4
+98 IF $$GET1^DIQ(90506.1,SIEN_",",3.01,"E")="Referrals"
Begin DoDot:4
+99 IF '$DATA(@TMP@(DFN))
SET VALUE(CRE)=VALUE(CRE)_"^"
QUIT
+100 SET RFIEN=""
SET C=0
FOR
SET RFIEN=$ORDER(@TMP@(DFN,RFIEN))
IF RFIEN=""
QUIT
DO RVAL(SIEN)
SET C=C+1
SET VALUE(C)=VALUE(C)_VAL_"^"
End DoDot:4
End DoDot:3
+101 ;
+102 IF $DATA(VALUE)
Begin DoDot:3
End DoDot:3
+103 FOR C=1:1:CRE
SET CLNG=$LENGTH(HEADR,"^")-$LENGTH(VALUE(C),"^")
Begin DoDot:3
+104 IF CLNG>0
SET $PIECE(VALUE(C),"^",$LENGTH(HEADR,"^"))=""
+105 IF CLNG<0
SET VALUE(C)=$PIECE(VALUE(C),"^",1,$LENGTH(HEADR,"^"))
End DoDot:3
+106 ;F C=1:1:CRE S II=II+1,VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^"),@DATA@(II)=VALUE(C)_$C(30)
+107 FOR C=1:1:CRE
SET II=II+1
SET @DATA@(II)=VALUE(C)_$CHAR(30)
End DoDot:2
QUIT
+108 KILL VALUE
SET VALUE(0)=BVALUE
+109 ; If no customized found, use default
+110 IF CIEN=""
DO STAND()
End DoDot:1
+111 QUIT
+112 ;
STAND() ;EP - Get standard display
+1 SET CRE=0
+2 SET RHEADR=BHEADR
DO RSH()
SET HEADR=RHEADR
+3 SET RHEADR=$$TKO^BQIUL1(RHEADR,"^")
+4 IF II=0
SET @DATA@(II)=RHEADR_$CHAR(30)
+5 IF '$DATA(@TMP)
SET CRE=CRE+1
SET VALUE(CRE)=VALUE(0)_"^"
+6 SET RFIEN=""
FOR
SET RFIEN=$ORDER(@TMP@(DFN,RFIEN))
IF RFIEN=""
QUIT
SET CRE=CRE+1
SET VALUE(CRE)=VALUE(0)_"^"
+7 SET IEN=""
+8 FOR
SET IEN=$ORDER(^BQI(90506.1,"AC","D",IEN))
IF IEN=""
QUIT
Begin DoDot:1
+9 IF $PIECE(^BQI(90506.1,IEN,0),U,10)=1
QUIT
+10 SET KEY=$$GET1^DIQ(90506.1,IEN_",",3.1,"E")
+11 IF KEY'=""
IF '$$KEYCHK^BQIULSC(KEY,DUZ)
QUIT
+12 IF $PIECE($GET(^BQI(90506.1,IEN,3)),"^",4)'="O"
Begin DoDot:2
+13 SET STVW=IEN
+14 DO CVAL
+15 FOR C=1:1:CRE
SET VALUE(C)=VALUE(C)_VAL_"^"
End DoDot:2
End DoDot:1
+16 ;
+17 ;Get patient referrals
+18 SET IEN=""
+19 FOR
SET IEN=$ORDER(^BQI(90506.1,"AC","RF",IEN))
IF IEN=""
QUIT
Begin DoDot:1
+20 IF $PIECE(^BQI(90506.1,IEN,0),U,10)=1
QUIT
+21 SET KEY=$$GET1^DIQ(90506.1,IEN_",",3.1,"E")
+22 IF KEY'=""
IF '$$KEYCHK^BQIULSC(KEY,DUZ)
QUIT
+23 IF $PIECE($GET(^BQI(90506.1,IEN,3)),"^",4)'="O"
Begin DoDot:2
+24 SET STVW=IEN
+25 IF '$DATA(@TMP@(DFN))
SET VALUE(CRE)=VALUE(CRE)_"^"
QUIT
+26 SET RFIEN=""
SET C=0
FOR
SET RFIEN=$ORDER(@TMP@(DFN,RFIEN))
IF RFIEN=""
QUIT
DO RVAL(IEN)
SET C=C+1
SET VALUE(C)=VALUE(C)_VAL_"^"
End DoDot:2
End DoDot:1
+27 ;
+28 FOR C=1:1:CRE
SET VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^")
+29 IF DFN=""
SET VALUE(1)=""
+30 IF $DATA(VALUE)
Begin DoDot:1
+31 FOR C=1:1:CRE
SET CLNG=$LENGTH(HEADR,"^")-$LENGTH(VALUE(C),"^")
Begin DoDot:2
+32 IF CLNG>0
SET $PIECE(VALUE(C),"^",$LENGTH(HEADR,"^"))=""
+33 IF CLNG<0
SET VALUE(C)=$PIECE(VALUE(C),"^",1,$LENGTH(HEADR,"^"))
End DoDot:2
End DoDot:1
+34 ;F C=1:1:CRE S II=II+1,VALUE(C)=$$TKO^BQIUL1(VALUE(C),"^"),@DATA@(II)=VALUE(C)_$C(30)
+35 FOR C=1:1:CRE
SET II=II+1
SET @DATA@(II)=VALUE(C)_$CHAR(30)
+36 KILL VALUE
SET VALUE(0)=BVALUE
+37 ;
FIN ;
+1 QUIT
+2 ;
CVAL ; Get demographic values
+1 ;Parameters
+2 ; FIL = FileMan file number
+3 ; FLD = FileMan field number
+4 ; EXEC = If an executable is needed to determine value
+5 ; HDR = Header value
+6 ;the executable expects the value to be returned in variable VAL
+7 NEW FIL,FLD,EXEC
+8 SET FIL=$PIECE(^BQI(90506.1,STVW,0),"^",5)
+9 SET FLD=$PIECE(^BQI(90506.1,STVW,0),"^",6)
+10 SET EXEC=$$GET1^DIQ(90506.1,STVW_",",1,"E")
+11 SET EXEC=$GET(^BQI(90506.1,STVW,1))
+12 SET HDR=$PIECE(^BQI(90506.1,STVW,0),"^",8)
+13 IF $GET(DFN)=""
SET VAL=""
QUIT
+14 ;
+15 IF $GET(EXEC)'=""
XECUTE EXEC
QUIT
+16 ;
+17 IF FIL'=""
IF FLD'=""
SET VAL=$$GET1^DIQ(FIL,DFN_",",FLD,"E")
+18 QUIT
+19 ;
REFF ;EP
+1 NEW ORD,IEN,FLD,FIE
+2 ;set up fields by display order
+3 SET ORD=""
SET FLDS=""
+4 FOR
SET ORD=$ORDER(^BQI(90506.1,"AD","RF",ORD))
IF ORD=""
QUIT
Begin DoDot:1
+5 SET IEN=""
+6 FOR
SET IEN=$ORDER(^BQI(90506.1,"AD","RF",ORD,IEN))
IF IEN=""
QUIT
Begin DoDot:2
+7 SET FLD=$$GET1^DIQ(90506.1,IEN_",",.06,"E")
SET FIE=$$GET1^DIQ(90506.1,IEN_",",.2,"I")
+8 IF FIE=""
SET FIE="E"
+9 SET FLDS=FLDS_FLD_"/"_FIE_";"
End DoDot:2
End DoDot:1
+10 SET FLDS=$$TKO^BQIUL1(FLDS,";")
+11 QUIT
+12 ;
RFPT(DFN,FLDS) ;EP
+1 NEW BGDT,BQIPAT
+2 SET TMP=$NAME(^TMP("BQIREFS",UID))
KILL @TMP
+3 SET BGDT=$PIECE($GET(^BQI(90508,1,16)),"^",4)
IF BGDT=""
SET BGDT="T-12M"
+4 SET BGDT=$$DATE^BQIUL1(BGDT)
+5 SET BQIPAT(DFN)=""
+6 DO API^BMCAPI1(.BQIPAT,BGDT,"",FLDS,TMP)
+7 KILL BQIPAT
+8 ;
+9 QUIT
+10 ;
RVAL(STVW) ;EP
+1 NEW FIL,FLD,EXEC,DTY
+2 SET FIL=$PIECE(^BQI(90506.1,STVW,0),"^",5)
+3 SET FLD=$PIECE(^BQI(90506.1,STVW,0),"^",6)
+4 SET EXEC=$GET(^BQI(90506.1,STVW,1))
+5 SET DTY=$PIECE(^BQI(90506.1,STVW,0),"^",20)
+6 SET ORD=$PIECE($GET(^BQI(90506.1,STVW,3)),"^",5)
+7 IF $GET(DFN)=""
SET VAL=""
QUIT
+8 ;
+9 IF $GET(EXEC)'=""
XECUTE EXEC
QUIT
+10 ;
+11 IF FLD'=""
SET VAL=$GET(@TMP@(DFN,ORD,FLD,DTYP))
+12 QUIT
+13 ;
DSP() ;EP
+1 NEW ORD,FIE,VAL
+2 SET VAL=""
+3 SET ORD=$$GET1^DIQ(90506.1,STVW_",",3.05,"E")
+4 SET FIE=$$GET1^DIQ(90506.1,STVW_",",.2,"I")
IF FIE=""
SET FIE="E"
+5 SET VAL=$GET(@TMP@(DFN,RFIEN,ORD,FLD,FIE))
+6 IF FIE="I"
SET VAL=$$FMTMDY^BQIUL1(VAL)
+7 QUIT VAL
+8 ;
RHD ;EP - Referral header
+1 ; Check for template
+2 NEW DA,IENS,TEMPL,LYIEN,QFL,TQFL
+3 SET TEMPL=""
+4 IF OWNR'=DUZ
Begin DoDot:1
+5 SET DA=$ORDER(^BQICARE(OWNR,1,PLIEN,30,DUZ,4,"C",CTYP,""))
+6 IF DA=""
QUIT
+7 SET DA(3)=OWNR
SET DA(2)=PLIEN
SET DA(1)=DUZ
SET IENS=$$IENS^DILF(.DA)
+8 SET TEMPL=$$GET1^DIQ(90505.34,IENS,.01,"E")
End DoDot:1
+9 IF OWNR=DUZ
Begin DoDot:1
+10 SET DA=$ORDER(^BQICARE(OWNR,1,PLIEN,4,"C",CTYP,""))
+11 IF DA=""
QUIT
+12 SET DA(2)=OWNR
SET DA(1)=PLIEN
SET IENS=$$IENS^DILF(.DA)
+13 SET TEMPL=$$GET1^DIQ(90505.14,IENS,.01,"E")
End DoDot:1
+14 ;
+15 ; If template, use it
+16 IF TEMPL'=""
SET TQFL=0
Begin DoDot:1
+17 SET LYIEN=$$TPN^BQILYUTL(DUZ,TEMPL)
+18 IF LYIEN=""
SET TQFL=1
QUIT
+19 SET DOR=""
+20 FOR
SET DOR=$ORDER(^BQICARE(DUZ,15,LYIEN,1,"C",DOR))
IF DOR=""
QUIT
Begin DoDot:2
+21 SET IEN=""
+22 FOR
SET IEN=$ORDER(^BQICARE(DUZ,15,LYIEN,1,"C",DOR,IEN))
IF IEN=""
QUIT
Begin DoDot:3
+23 SET CODE=$PIECE(^BQICARE(DUZ,15,LYIEN,1,IEN,0),U,1)
+24 SET GIEN=$ORDER(^BQI(90506.1,"B",CODE,""))
IF GIEN=""
QUIT
+25 SET STVW=GIEN
+26 IF $PIECE(^BQI(90506.1,GIEN,0),U,10)=1
QUIT
+27 SET HDR=$PIECE(^BQI(90506.1,STVW,0),"^",8)
+28 SET RHEADR=RHEADR_HDR_"^"
End DoDot:3
End DoDot:2
+29 SET RHEADR=$$TKO^BQIUL1(RHEADR,"^")
End DoDot:1
IF 'TQFL
GOTO FH
+30 ;
+31 ; If no template, check for customized
+32 IF OWNR=DUZ
Begin DoDot:1
+33 SET IEN=0
SET CIEN=$ORDER(^BQICARE(OWNR,1,PLIEN,26,IEN))
+34 IF CIEN'=""
Begin DoDot:2
+35 FOR
SET IEN=$ORDER(^BQICARE(OWNR,1,PLIEN,26,IEN))
IF 'IEN
QUIT
Begin DoDot:3
+36 SET CODE=$PIECE(^BQICARE(OWNR,1,PLIEN,26,IEN,0),"^",1)
+37 SET SIEN=$ORDER(^BQI(90506.1,"B",CODE,""))
IF SIEN=""
QUIT
+38 IF $PIECE(^BQI(90506.1,SIEN,0),U,10)=1
QUIT
+39 SET HDR=$$GET1^DIQ(90506.1,SIEN_",",.08,"E")
+40 SET RHEADR=RHEADR_HDR_"^"
End DoDot:3
End DoDot:2
QUIT
+41 SET RHEADR=$$TKO^BQIUL1(RHEADR,"^")
+42 ;
+43 ; If no customized found, use default
+44 IF CIEN=""
DO RSH()
End DoDot:1
+45 ;
+46 IF OWNR'=DUZ
Begin DoDot:1
+47 SET IEN=0
SET CIEN=$ORDER(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN))
+48 IF CIEN'=""
Begin DoDot:2
+49 FOR
SET IEN=$ORDER(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN))
IF 'IEN
QUIT
Begin DoDot:3
+50 SET CODE=$PIECE(^BQICARE(OWNR,1,PLIEN,30,DUZ,26,IEN,0),"^",1)
+51 SET SIEN=$ORDER(^BQI(90506.1,"B",CODE,""))
IF SIEN=""
QUIT
+52 IF $PIECE(^BQI(90506.1,SIEN,0),U,10)=1
QUIT
+53 SET HDR=$PIECE(^BQI(90506.1,SIEN,0),"^",8)
+54 SET RHEADR=RHEADR_HDR_"^"
End DoDot:3
End DoDot:2
QUIT
+55 SET RHEADR=$$TKO^BQIUL1(RHEADR,"^")
+56 ;
+57 ; If no customized found, use default
+58 IF CIEN=""
DO RSH()
End DoDot:1
+59 ;
FH ;
+1 QUIT
+2 ;
RSH() ;EP - Get standard header
+1 SET IEN=""
+2 FOR
SET IEN=$ORDER(^BQI(90506.1,"AC","D",IEN))
IF IEN=""
QUIT
Begin DoDot:1
+3 IF $PIECE(^BQI(90506.1,IEN,0),U,10)=1
QUIT
+4 SET KEY=$$GET1^DIQ(90506.1,IEN_",",3.1,"E")
+5 IF KEY'=""
IF '$$KEYCHK^BQIULSC(KEY,DUZ)
QUIT
+6 IF $PIECE($GET(^BQI(90506.1,IEN,3)),"^",4)'="O"
Begin DoDot:2
+7 SET STVW=IEN
+8 SET HDR=$PIECE(^BQI(90506.1,STVW,0),"^",8)
+9 SET RHEADR=RHEADR_HDR_"^"
End DoDot:2
End DoDot:1
+10 ;
+11 SET IEN=""
+12 FOR
SET IEN=$ORDER(^BQI(90506.1,"AC","RF",IEN))
IF IEN=""
QUIT
Begin DoDot:1
+13 IF $PIECE(^BQI(90506.1,IEN,0),U,10)=1
QUIT
+14 SET KEY=$$GET1^DIQ(90506.1,IEN_",",3.1,"E")
+15 IF KEY'=""
IF '$$KEYCHK^BQIULSC(KEY,DUZ)
QUIT
+16 IF $PIECE($GET(^BQI(90506.1,IEN,3)),"^",4)'="O"
Begin DoDot:2
+17 SET STVW=IEN
+18 SET HDR=$PIECE(^BQI(90506.1,STVW,0),"^",8)
+19 SET RHEADR=RHEADR_HDR_"^"
End DoDot:2
End DoDot:1
+20 SET RHEADR=$$TKO^BQIUL1(RHEADR,"^")
+21 QUIT