Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: BTPWPTRG

BTPWPTRG.m

Go to the documentation of this file.
BTPWPTRG ;VNGT/HS/ALA-Event Worksheet Trigger ; 24 Nov 2009  11:13 AM
 ;;1.2;CARE MANAGEMENT EVENT TRACKING;;Jul 07, 2017;Build 71
 ;
 ;
INIT(DATA,CMIEN) ;EP -- BTPW EVENT WORKSHEET INITIAL
 NEW UID,II,VALUE,SOURCE,IEN,TYPE,BTPWX,VFIEN,FLD,ACT,FDATA,ABLE,CLFLAG
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BTPWPTRG",UID))
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BTPWPTRG D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S @DATA@(II)="T00008SOURCE^T00001CODE_TYPE^T00001ABLE_FLAG^T00001CLEAR_FLAG^T01024PARMS"_$C(30)
 D SRC
 S SOURCE=""
 F  S SOURCE=$O(BTPWX(SOURCE)) Q:SOURCE=""  D
 . S VALUE=$P(BTPWX(SOURCE),U,1),TYPE=$P(BTPWX(SOURCE),U,2),ABLE=$P(BTPWX(SOURCE),U,3),CLFLAG=$P(BTPWX(SOURCE),U,4)
 . D UP
 ;
 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
 ;
UP ; Update
 S II=II+1,@DATA@(II)=SOURCE_U_TYPE_U_ABLE_U_CLFLAG_U_VALUE_$C(30)
 Q
 ;
SRC ;
 NEW TDATA,TDATA1,EXEC,FNDDT,CLFLAG,FOLYN
 S TDATA=^BTPWP(CMIEN,0)
 S TDATA1=$G(^BTPWP(CMIEN,1))
 S VFIEN=$$FIND1^DIC(90506.3,"","MX","CMET Worksheet","","","ERROR")
 S ORD=""
 F  S ORD=$O(^BQI(90506.3,VFIEN,10,"C",ORD)) Q:ORD=""  D
 . S IEN=""
 . F  S IEN=$O(^BQI(90506.3,VFIEN,10,"C",ORD,IEN)) Q:IEN=""  D
 .. S CLFLAG=""
 .. I $P(^BQI(90506.3,VFIEN,10,IEN,0),"^",11)'="" Q
 .. S FLD=$P($G(^BQI(90506.3,VFIEN,10,IEN,3)),"^",1),TYPE=$P($G(^BQI(90506.3,VFIEN,10,IEN,1)),U,1)
 .. S SOURCE=$P(^BQI(90506.3,VFIEN,10,IEN,0),"^",7)
 .. S EXEC=$G(^BQI(90506.3,VFIEN,10,IEN,8))
 .. S ACT=$P($G(^BQI(90506.3,VFIEN,10,IEN,1)),U,5),VALUE="",ABLE="Y"
 .. I ACT="L" D
 ... ;S RCNN=$$GET1^DIQ(90620,CMIEN_",",FLD,"I")
 ... ;S WHR=$P(^BTPWP(CMIEN,0),U,9),RDR=$P(^(0),U,10),VISIT=$P(^(0),U,4)
 ... S VALUE=$$LNK(CMIEN,FLD)
 .. I TYPE="T"!(TYPE="C") D
 ... ;I VALUE="" Q
 ... I ACT="D" S VALUE=$$GET1^DIQ(90620,CMIEN_",",FLD,"E")
 ... I ACT'="D" S VALUE=$$GET1^DIQ(90620,CMIEN_",",FLD,"I")
 ... ;S VALUE=$$GET1^DIQ(90620,CMIEN_",",FLD,"I")_$C(28)_$$GET1^DIQ(90620,CMIEN_",",FLD,"E")
 .. I TYPE="W" D
 ... N VAL,CN
 ... D GETS^DIQ(90620,CMIEN_",",FLD,"E","VAL")
 ... S VALUE="",CN=0 F  S CN=$O(VAL(CN)) Q:'CN  S VALUE=VALUE_$S(VALUE]"":$C(10),1:"")_$G(VAL(CN))
 .. I TYPE'="T",TYPE'="C",TYPE'="W" D
 ... I VALUE'="" Q
 ... I TYPE="D" S VALUE=$$GET1^DIQ(90620,CMIEN_",",FLD,"I") S:VALUE]"" VALUE=$$FMTE^BQIUL1(VALUE) Q
 ... I TYPE="M" S VALUE=$$GET1^DIQ(90620,CMIEN_",",FLD,"E")
 .. ;
 .. ;Look for executable code
 .. I EXEC'="" X EXEC
 .. ;
 .. ;Special Handling
 .. ;
 .. I SOURCE="BTPWPREV" S VALUE=$P(TDATA,U,11),VALUE=$S(VALUE'="":"Y"_$C(28)_"YES",1:"N"_$C(28)_"NONE")
 .. I SOURCE="EVIEN" S VALUE=CMIEN
 .. ;
 .. ;Follow-up Recommended
 .. I SOURCE="BTPWFLUN" D
 ... I $P($$FND^BTPWPCLO(CMIEN),U,1)=-1 S ABLE="N",VALUE="" Q
 ... S ABLE="Y"
 .. ;
 .. ;Follow-ups
 .. I SOURCE="BTPWFU"!(SOURCE="BTPWFDUE") S FOLYN=$P(TDATA1,U,11) S ABLE=$S(FOLYN["Y":"Y",1:"N"),VALUE=$S(FOLYN["Y":VALUE,1:"")
 .. I SOURCE="BTPWNTY",$P($$FND^BTPWPCLO(CMIEN),U,1)=-1 S ABLE="N",$P(BTPWX("BTPWNDUE"),U,3)="N"
 .. S BTPWX(SOURCE)=VALUE_U_TYPE_U_ABLE_U_CLFLAG
 ;
 ;Disable necessary field if in an open state
 I $P($G(BTPWX("BTPWSTGE")),U)="O" D
 . ;
 . ;Disable Close Reason
 . S $P(BTPWX("BTPCLREA"),U,3)="N"
 . ;
 . I $P($$FND^BTPWPCLO(CMIEN),U)=-1 D
 .. S $P(BTPWX("BTPWFU"),U,3)="N"
 .. S $P(BTPWX("BTPWFLUN"),U,3)="N",$P(BTPWX("BTPWFLUN"),U,4)="Y"
 .. S $P(BTPWX("BTPWFDUE"),U,3)="N",$P(BTPWX("BTPWFDUE"),U,4)="Y"
 .. S $P(BTPWX("BTPWNDUE"),U,3)="N",$P(BTPWX("BTPWNDUE"),U,4)="Y"
 ;
 ;Disable Fields if in Closed State
 I $P($G(BTPWX("BTPWSTGE")),U)="C" D
 . S $P(BTPWX("BTPWFIND"),U,3)="N"
 . S $P(BTPWX("BTPWFU"),U,3)="N"
 . S $P(BTPWX("BTPWNTY"),U,3)="N"
 . S $P(BTPWX("BTPWRDUE"),U,3)="N",$P(BTPWX("BTPWRDUE"),U,4)="N"
 . S $P(BTPWX("BTPWFLUN"),U,3)="N",$P(BTPWX("BTPWFLUN"),U,4)="N"
 . S $P(BTPWX("BTPWFDUE"),U,3)="N",$P(BTPWX("BTPWFDUE"),U,4)="N"
 . S $P(BTPWX("BTPWNDUE"),U,3)="N",$P(BTPWX("BTPWNDUE"),U,4)="N"
 Q
 ;
LNK(TRIEN,FLD) ; EP - Get links for a tracked event
 NEW RCNN,RCTP,WHR,RDR,VISIT,PRCDT,LINK,RIEN,ACCN,TDATA
 S RCNN=$$GET1^DIQ(90620,TRIEN_",",FLD,"I")
 S RCTP=$$GET1^DIQ(90620,TRIEN_",",FLD,"E")
 S PRCDT=$$GET1^DIQ(90620,TRIEN_",",.03,"I")
 S PRCDT=$$FMTE^BQIUL1(PRCDT)
 S TDATA=^BTPWP(TRIEN,0)
 S WHR=$P(TDATA,U,9),RDR=$P(TDATA,U,10),VISIT=$P(TDATA,U,4)
 S ACCN=$P(TDATA,U,15),RIEN=$P(TDATA,U,5),PREVT=$P(TDATA,U,14)
 I RIEN="" S RIEN=$P($G(^BTPWQ(PREVT,0)),"^",5)
 S LINK=""
 I WHR'="",$P($G(^BWPCD(WHR,0)),U,5)="" S WHR=""
 I WHR'="" S LINK=PRCDT_$C(28)_"WH RECORD"_$C(28)_"W:"_WHR
 I RDR'="" S LINK=PRCDT_$C(28)_RCTP_$C(28)_"R:"_RDR
 I ACCN'="" D
 . I $E(ACCN,1,2)="WH" Q
 . NEW RES
 . S RES=$P($G(^AUPNVLAB(RIEN,0)),U,4)
 . I RES="",$P($G(^AUPNVLAB(RIEN,11)),U,9)'="R" Q
 . S LINK=PRCDT_$C(28)_RCTP_$C(28)_"L:"_RIEN
 ;Q PRCDT_$C(28)_RCTP_$C(28)_"V:"_VISIT
 Q LINK
 ;
QLNK(QRIEN,FLD) ; EP - Get links for a queued event
 NEW RCNN,RCTP,WHR,RDR,VISIT,PRCDT,LINK,QDATA,ACCN,RIEN,DFN
 S RCNN=$$GET1^DIQ(90629,QRIEN_",",FLD,"I")
 S RCTP=$$GET1^DIQ(90629,QRIEN_",",FLD,"E")
 S PRCDT=$$GET1^DIQ(90629,QRIEN_",",.03,"I")
 S DFN=$P(^BTPWQ(QRIEN,0),"^",2)
 S PRCDT=$$FMTE^BQIUL1(PRCDT)
 S QDATA=^BTPWQ(QRIEN,0),FULLR=""
 S WHR=$P(QDATA,U,9),RDR=$P(QDATA,U,10),VISIT=$P(QDATA,U,4),ACCN=$P(QDATA,U,15),RIEN=$P(QDATA,U,5)
 S LINK=""
 I WHR'="",$P($G(^BWPCD(WHR,0)),U,5)="" S WHR=""
 I WHR'="" D
 . NEW DATA
 . D EN^BTPWRWHP(.DATA,WHR)
 . F I=1:1 Q:@DATA@(I)=$C(30)  S FULLR=FULLR_$$STRIP^XLFSTR(@DATA@(I),"^")
 . S LINK=PRCDT_$C(28)_"WH RECORD"_$C(28)_"W:"_WHR_$C(28)_FULLR
 I RDR'="" D
 . NEW DATA
 . D EN^BTPWRRAD(.DATA,DFN,RDR)
 . F I=1:1 Q:@DATA@(I)=$C(30)  S FULLR=FULLR_$$STRIP^XLFSTR(@DATA@(I),"^")
 . S LINK=PRCDT_$C(28)_RCTP_$C(28)_"R:"_RDR_$C(28)_FULLR
 I ACCN'="" D
 . I $E(ACCN,1,2)="WH" Q
 . I $G(^AUPNVLAB(RIEN,0))="" Q
 . NEW RES
 . S RES=$P($G(^AUPNVLAB(RIEN,0)),U,4)
 . NEW DATA
 . D EN^BTPWRLAB(.DATA,DFN,RIEN)
 . F I=1:1 Q:@DATA@(I)=$C(30)  S FULLR=FULLR_$$STRIP^XLFSTR(@DATA@(I),"^")
 . ;I RES="",$P($G(^AUPNVLAB(RIEN,11)),U,9)'="R" 
 . S LINK=PRCDT_$C(28)_RCTP_$C(28)_"L:"_RIEN_$C(28)_FULLR
 Q LINK
 ;
EXEV(QIEN) ;EP - Expanded Event
 NEW TDATA,TIEN,FULLE,RCIEN,RCFILE,FIL,FLD,TAB,LIEN
 S TDATA=^BTPWQ(QIEN,0)
 S TIEN=$P(TDATA,U,14)
 S FULLE="Event obtained from: "_$C(13)_$C(10) D
 . S RCIEN=$P(TDATA,U,5),RCFILE=$P(TDATA,U,6)
 . S FULLE=FULLE_$P(^BTPW(90621.1,RCFILE,0),"^",1)_" - "
 . NEW FIL,FLD
 . S FIL=$P(^BTPW(90621.1,RCFILE,0),"^",2),FLD=$P(^(0),"^",3),TAB=$P(^(0),"^",8)
 . S FULLE=FULLE_$$GET1^DIQ(FIL,RCIEN_",",FLD,"E")
 . S LIEN=$$GET1^DIQ(FIL,RCIEN_",",FLD,"I")
 . I TAB=80!(TAB=80.1)!(TAB=81) D
 . I TAB=80 S FULLE=FULLE_" "_$$ICD9^BQIUL3(LIEN,,4)_$C(13)_$C(10) Q
 . I TAB=80.1 S FULLE=FULLE_" "_$$ICD0^BQIUL3(LIEN,,5)_$C(13)_$C(10) Q
 . I TAB=81 S FULLE=FULLE_" "_$$ICPT^BQIUL3(LIEN,"",3)
 Q FULLE
 ;
FCOMM(QIEN) ;EP - Get Findings Comments
 NEW FIEN,FCOMM
 S FCOMM=""
 S FIEN=0
 F  S FIEN=$O(^BTPWQ(QIEN,4,FIEN)) Q:'FIEN  D
 . S FCOMM=FCOMM_$S(FCOMM]"":" ",1:"")_$G(^BTPWQ(QIEN,4,FIEN,0))
 Q FCOMM