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

BTPWBTAD.m

Go to the documentation of this file.
BTPWBTAD ;VNGT/HS/ALA-Update Batch Processing ; 05 Nov 2009  3:18 PM
 ;;1.0;CARE MANAGEMENT EVENT TRACKING;;Feb 07, 2011
 ;
 ;
UPD(DATA,TYPE,RIEN,PARMS) ; EP -- BTPW UPDATE BATCH PROCESS
 ; Input
 ;  TYPE  = "Q" from Queued list, "T" from Tracked List
 ;  RIEN  = Record IEN
 ;  PARMS = Filing parameters
 ;
 NEW UID,II,RESULT,BTPWPRC,BTPWSTGE,CHIEN,CMIEN,NAME,VALUE,VFIEN,PDATA,BQ,BTPWWP
 NEW BTPWDFN,BTPWFNTR,BTPWINFD,BTPWPCLR,BTPWPFLD,BTPWPFND,BTPWPFOL,BTPWPNOT
 NEW BTPFLND,BTPFNDTM,BTPWPNTD,BTPWDTA,FDUE,NDUE,RDUE,STAT,OTYPE
 NEW EXEC,FIELD,FILE,IENS,NAME,PDATA,PFIEN,PIEN,PTYP,VALUE,X,Y,DTTM
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BTPWPTMP",UID))
 K @DATA
 ;
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BTPWPTMP D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 S @DATA@(II)="I00010RESULT^T01024MSG^I00010CMET_IEN"_$C(30)
 ;
 ;Pull current date/time
 S DTTM=$$NOW^XLFDT()
 ;
 S PARMS=$G(PARMS,"")
 I PARMS="" D
 . N BN,LIST
 . S LIST="",BN=""
 . F  S BN=$O(PARMS(BN)) Q:BN=""  S LIST=LIST_PARMS(BN)
 . K PARMS
 . S PARMS=LIST
 ;
 ; If from queued list, need to move over into Tracked Event file
 S OTYPE=TYPE
 I TYPE="Q" D
 . S STAT="T"
 . ; Queue history record
 . D QHIS^BTPWPTMP
 . ;
 . ; File update
 . D FL^BTPWPTMP
 . ; Move record into Tracked Event file
 . S RDUE="",FDUE="",NDUE=""
 . D MV^BTPWPTMP
 . ;
 . ;Make sure CMIEN is defined
 . S CMIEN=$P($G(^BTPWQ(RIEN,0)),U,14)
 ;
 I TYPE="T" D
 . ; If batch processing from tracked events, move the history
 . S CMIEN=RIEN,RIEN=$P(^BTPWP(CMIEN,0),U,14)
 . NEW PIEN
 . S PIEN=CMIEN
 ;
 S VFIEN=$O(^BQI(90506.3,"B","CMET Batch Process",""))
 I VFIEN="" S BMXSEC="RPC Call Failed: CMET Batch Process Definition does not exist." Q
 S FILE=$P(^BQI(90506.3,VFIEN,0),U,2),IENS=CMIEN_","
 ;
 F BQ=1:1:$L(PARMS,$C(28)) D  Q:$G(BMXSEC)'=""
 . S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1),VALUE=$P(PDATA,"=",2,99)
 . I VALUE="" S VALUE="@"
 . ;I VALUE="" Q
 . S PFIEN=$O(^BQI(90506.3,VFIEN,10,"AC",NAME,""))
 . I PFIEN="" S BMXSEC=NAME_" not a valid parameter for this update" Q
 . S PTYP=$P($G(^BQI(90506.3,VFIEN,10,PFIEN,1)),U,1)
 . I PTYP="D" S VALUE=$$DATE^BQIUL1(VALUE)
 . I PTYP="C" D
 .. S CHIEN=$O(^BQI(90506.3,VFIEN,10,PFIEN,5,"B",VALUE,"")) I CHIEN="" Q
 .. S VALUE=$P(^BQI(90506.3,VFIEN,10,PFIEN,5,CHIEN,0),U,2)
 . ;
 . ;Word Processing Field
 . I PTYP="W" D  Q
 .. N FIELD,LN,I,P
 .. S FIELD=$P($G(^BQI(90506.3,VFIEN,10,PFIEN,3)),U,1) Q:FIELD=""
 .. I VALUE="@" S BTPWDTA(FILE,IENS,FIELD)="@" Q
 .. F LN=1:1:$L(VALUE,$C(10)) S P=$P(VALUE,$C(10),LN) S BTPWWP(FIELD,LN)=P
 . ;
 . S @NAME=VALUE
 ;
 S BTPWPRC=$P(^BTPWP(CMIEN,0),U,1),BTPWINFD=$G(BTPWPFLD)
 D PREP(BTPWPRC)
 I BTPWINFD="" S BTPWPFLD=$P(^BTPWP(CMIEN,0),U,3),BTPWPFLD=$$FLDUE^BTPWPUTL(BTPWPRC,BTPWPFLD,"")
 I BTPWINFD'="" S BTPWPFLD=$P(^BTPWP(CMIEN,0),U,3),BTPWPFLD=$$FLDUE^BTPWPUTL(BTPWPRC,BTPWPFLD,"",BTPWINFD)
 ;
 F BQ=1:1:$L(PARMS,$C(28)) D  Q:$G(BMXSEC)'=""
 . S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1)
 . S PFIEN=$O(^BQI(90506.3,VFIEN,10,"AC",NAME,""))
 . I PFIEN="" S BMXSEC=NAME_" not a valid parameter for this update" Q
 . S FIELD=$P($G(^BQI(90506.3,VFIEN,10,PFIEN,3)),U,1)
 . S PTYP=$P($G(^BQI(90506.3,VFIEN,10,PFIEN,1)),U,1) Q:PTYP="W"
 . S EXEC=$G(^BQI(90506.3,VFIEN,10,PFIEN,7))
 . I EXEC'="" X EXEC Q
 . I FIELD="" Q
 . S BTPWDTA(FILE,IENS,FIELD)=@NAME
 ;
 ; Set the due by dates
 S BTPWDTA(90620,CMIEN_",",1.05)=DT,BTPWDTA(90620,CMIEN_",",1.06)=DT,BTPWDTA(90620,CMIEN_",",1.07)=DT
 ;
 ; Set the Follow-up Needed field
 S BTPWDTA(90620,CMIEN_",",1.11)="Y"
 ;
 ;S BTPWDTA(90620,CMIEN_",",1.09)=$$NOW^XLFDT(),BTPWDTA(90620,CMIEN_",",1.1)=DUZ
 ;
 D FND
 D NOT
 D FOL
 ;
 ;File WP fields
 I $D(BTPWWP) D
 . N FIELD,WPVAR
 . S WPVAR="COM"
 . S FIELD="" F  S FIELD=$O(BTPWWP(FIELD)) Q:FIELD=""  D
 .. N COM
 .. M COM=BTPWWP(FIELD)
 .. ;
 .. ;Log History Entry
 .. D WLOG^BTPWHIST(.COM,"90620:"_FIELD,IENS,DUZ,DTTM,"Event Update")
 .. ;
 .. ;Save WP field
 .. D WP^DIE(90620,IENS,FIELD,"",WPVAR)
 ;
 S RESULT=1_U
 I $D(ERROR)>0 S RESULT=-1_U
 K ERROR
 ;
 ;Log History Entry
 I $D(BTPWDTA)>0 D RLOG^BTPWHIST(.BTPWDTA,DUZ,DTTM,"Event Update")
 ;
 ;File information
 I $D(BTPWDTA)>0 D FILE^DIE("","BTPWDTA","ERROR")
 I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR",1,"TEXT",1))
 I $P(RESULT,U,1)'=-1 S RESULT=1_U_U_$G(CMIEN)
 S II=II+1,@DATA@(II)=RESULT_$C(30)
 ;
DONE ;
 D UNL^BTPWLOCK(OTYPE,RIEN)
 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
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
FND ; Create Finding record
 NEW DA,DIC,DLAYGO,IENS,BTUPD,X,DIC,DA,DLAYGO
 I $G(BTPFNDTM)="" S BTPFNDTM=$$NOW^XLFDT()
 I $G(BTPFLND)="" S BTPFLND="Y"
 S DA(1)=CMIEN,X=BTPFNDTM
 S DIC="^BTPWP("_DA(1)_",10,",DIC(0)="LMNZ",DLAYGO=90620.01,DIC("P")=DLAYGO
 K DO,DD D FILE^DICN
 S DA=+Y
 S IENS=$$IENS^DILF(.DA)
 S BTUPD(90620.01,IENS,.02)=BTPWPFND
 S BTUPD(90620.01,IENS,.03)=BTPWFNTR
 S BTUPD(90620.01,IENS,.04)=$$NOW^XLFDT()
 S BTUPD(90620.01,IENS,.05)=DUZ
 S BTUPD(90620.01,IENS,.07)=BTPWPFOL
 ;
 ;Log History Entry
 I $D(BTUPD)>0 D RLOG^BTPWHIST(.BTUPD,DUZ,DTTM,"Event Update")
 ;
 ;File information
 D FILE^DIE("","BTUPD","ERROR")
 Q
 ;
FOL ; Create Followup record
 NEW X,DIC,DA,Y,DIE,IENS
 I $G(BTPWPFOL)=""!($G(BTPWPFLD)="") Q
 I $G(BTPWPFLD)="" S X=$$NOW^XLFDT()
 I $G(BTPWPFLD)'="" S X=BTPWPFLD
 S DA(1)=CMIEN
 S DIC(0)="L",DIC="^BTPWP("_DA(1)_",12,",DIE=DIC
 I $G(^BTPWP(DA(1),2,0))="" S ^BTPWP(DA(1),12,0)="^90620.012D^^"
 K DO,DD D FILE^DICN S DA=+Y I DA=-1 Q
 S IENS=$$IENS^DILF(.DA)
 ;
 S BTPWDTA(90620.012,IENS,.02)=BTPWPFOL
 S BTPWDTA(90620.012,IENS,.03)=$$NOW^XLFDT()
 S BTPWDTA(90620.012,IENS,.04)=DUZ
 S BTPWDTA(90620.012,IENS,.05)=$$DATE^BQIUL1(BTPWPFLD)
 S BTPWDTA(90620.012,IENS,.06)=$$FUT(BTPWPFOL,BTPWPFLD)
 Q
 ;
NOT ; Create Notification record
 NEW X,DA,DIC,IENS,DIE,Y,ABR
 ;
 I BTPWPNOT="" Q
 ;
 I $G(BTPWPNTD)="" S BTPWPNTD=$$DT^XLFDT()
 S X=BTPWPNTD,DA(1)=CMIEN
 S DIC(0)="L",DIC="^BTPWP("_DA(1)_",11,",DIE=DIC
 I $G(^BTPWP(DA(1),2,0))="" S ^BTPWP(DA(1),11,0)="^90620.011D^^"
 K DO,DD D FILE^DICN S DA=+Y I DA=-1 Q
 S IENS=$$IENS^DILF(.DA)
 ;
 S BTPWDTA(90620.011,IENS,.02)=BTPWPNOT
 S BTPWDTA(90620.011,IENS,.03)=$$NOW^XLFDT()
 S BTPWDTA(90620.011,IENS,.04)=DUZ
 S BTPWDTA(90620.011,IENS,.05)=$G(TIUDA)
 S BTPWDTA(90620.011,IENS,.11)=$G(BTPWVIEN)
 Q
 ;
FUT(BTPWPFOL,BTPWPFLD) ;EP - Create future followup record
 N BTPWDFN,PIEN,BTUPD
 S BTPWDFN=$P(^BTPWP(CMIEN,0),U,2)
 S PIEN=$$REC^BTPWPTMP(BTPWPFOL)
 S BTUPD(90620,PIEN_",",.02)=BTPWDFN,BTUPD(90620,PIEN_",",.11)=CMIEN
 S BTUPD(90620,PIEN_",",1.03)=DUZ,BTUPD(90620,PIEN_",",.13)=BTPWPFLD
 S BTUPD(90620,PIEN_",",1.01)="F",BTUPD(90620,PIEN_",",1.02)=$$NOW^XLFDT()
 S BTUPD(90620,PIEN_",",1.1)=DUZ,BTUPD(90620,PIEN_",",1.09)=BTUPD(90620,PIEN_",",1.02)
 S BTUPD(90620,PIEN_",",.12)=$$GET1^DIQ(90620,CMIEN_",",.12,"I")
 S BTUPD(90620,PIEN_",",.16)=$$GET1^DIQ(9000001,BTPWDFN_",",1117,"I")
 ;
 ;Log History Entry
 I $D(BTUPD)>0 D RLOG^BTPWHIST(.BTUPD,DUZ,DTTM,"Event Update")
 ;
 ;File information
 D FILE^DIE("","BTUPD","ERROR")
 Q PIEN
 ;
PREP(BTPWPRC) ;EP -- Prepare variables
 NEW IEN,VALUE,SOURCE
 S IEN="",VALUE=""
 S IEN=$O(^BTPW(90628,1,2,"B",BTPWPRC,IEN))
 I IEN="" S BMXSEC="RPC Failed: This procedure is not on file for batch events" Q
 S SOURCE="BTPWPFND",TYPE="T",VALUE=$P($G(^BTPW(90628,1,2,IEN,1)),U,1) D
 . S @SOURCE=VALUE D ARAY(SOURCE)
 S SOURCE="BTPWFNTR" D
 . NEW IIEN
 . S IIEN=$O(^BTPW(90621,BTPWPRC,6,"B",BTPWPFND,"")) I IIEN="" Q
 . S VALUE=$P(^BTPW(90621,BTPWPRC,6,IIEN,0),U,2)
 . S @SOURCE=VALUE D ARAY(SOURCE)
 ; For followup event, same as selected event
 S SOURCE="BTPWPFOL",VALUE=BTPWPRC,@SOURCE=VALUE D ARAY(SOURCE)
 ; For close reason, Event Complete = 1
 S SOURCE="BTPWPCLR",VALUE=1,@SOURCE=VALUE D ARAY(SOURCE)
 S SOURCE="BTPWSTGE",VALUE="C",@SOURCE=VALUE D ARAY(SOURCE)
 Q
 ;
ARAY(NAME) ; EP
 NEW PFIEN,FIELD,EXEC
 S PFIEN=$O(^BQI(90506.3,VFIEN,10,"AC",NAME,""))
 I PFIEN="" Q
 S FIELD=$P($G(^BQI(90506.3,VFIEN,10,PFIEN,3)),U,1)
 S EXEC=$G(^BQI(90506.3,VFIEN,10,PFIEN,7))
 I EXEC'="" X EXEC Q
 I FIELD="" Q
 S BTPWDTA(FILE,IENS,FIELD)=@NAME
 Q