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

BTPWPTMP.m

Go to the documentation of this file.
BTPWPTMP ;VNGT/HS/ALA-Handle CMET Temporary File ; 04 Feb 2009  2:55 PM
 ;;1.2;CARE MANAGEMENT EVENT TRACKING;;Jul 07, 2017;Build 71
 ;
UPD(DATA,PARMS) ; EP - BTPW UPDATE CMET TEMP
 ; Input Parameters
 ;   STAT  - Status of event N:NOT TRACKED;T:TRACKED
 ;   RDUE  - Findings Due By Date
 ;   RLIST - List of temporary record IENS to be updated
 ;   COMMENT - Event Comment Field
 ;
 NEW UID,II,RESULT,BTI,LIST,BN,BQ,RIEN,CMIEN,STATUS,DUEDT,IEN,COMMENT,STAT,RDUE,RLIST,COM,LN,I,P,CMTVAR
 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^I00010QUEUED_CMET_IEN^I00010TRACKED_CMET_IEN"_$C(30)
 ;
 ;Re-Assemble parameter list if in an array
 S PARMS=$G(PARMS,"")
 I PARMS="" D
 . N LIST,BN
 . S LIST="",BN=""
 . F  S BN=$O(PARMS(BN)) Q:BN=""  S LIST=LIST_PARMS(BN)
 . K PARMS
 . S PARMS=LIST
 ;
 ;Set up incoming variables
 S (STATUS,DUEDT,IEN,COMMENT)=""
 F BQ=1:1:$L(PARMS,$C(28)) D  Q:$G(BMXSEC)'=""
 .N PDATA,NAME,VALUE,BP,BV
 .S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 .S NAME=$P(PDATA,"=",1) Q:NAME=""
 .S VALUE=$P(PDATA,"=",2,99) Q:VALUE=""
 .F BP=1:1:$L(VALUE,$C(29)) S BV=$P(VALUE,$C(29),BP),@NAME=@NAME_$S(BP=1:"",1:$C(29))_BV
 ;
 ;Copy input parameters into original variables used by RPC
 S STAT=STATUS
 S RDUE=DUEDT,RDUE=$$DATE^BQIUL1(RDUE)
 M RLIST=IEN
 ;
 ;Set up comment for processing
 S COMMENT=$G(COMMENT,"")
 S LN=0 F I=1:1:$L(COMMENT,$C(10)) S P=$P(COMMENT,$C(10),I) S LN=LN+1,COM(LN)=P
 I '$D(COM(1)) S CMTVAR="@"
 E  S CMTVAR="COM"
 ;
 ;Assemble List of IENs if in array
 I RLIST="" D
 . S LIST="",BN=""
 . F  S BN=$O(RLIST(BN)) Q:BN=""  S LIST=LIST_RLIST(BN)
 . K RLIST S RLIST=LIST
 ;
 F BTI=1:1 S RIEN=$P(RLIST,$C(29),BTI) Q:RIEN=""  D
 . N CMIEN,BTPUPD,ERROR,RESULT
 . ;
 . ;Dot Structure to process for each event
 . D
 .. I STAT="N" D QHIS,FL Q
 .. I STAT="P" D  Q
 ... I $P(^BTPWQ(RIEN,0),U,8)'="N" Q
 ... D QHIS,FL
 .. I STAT="T" D
 ... D QHIS,FL
 ... D MV
 . ;
 . ;Return one record per event
 . S RESULT=1_U_U_$G(RIEN)_U_$G(CMIEN)
 . I $D(BTPUPD)>0 D FILE^DIE("","BTPUPD","ERROR")
 . I $D(ERROR)>0 S RESULT=-1_U_$G(ERROR("DIERR",1,"TEXT",1))_U_$G(RIEN)_U_$G(CMIEN)
 . S II=II+1,@DATA@(II)=RESULT_$C(30)
 ;
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
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
FL ;EP - Update file
 S BTPUPD(90629,RIEN_",",.08)=STAT
 S BTPUPD(90629,RIEN_",",.11)=$$NOW^XLFDT()
 S BTPUPD(90629,RIEN_",",.12)=$$GET1^DIQ(200,DUZ_",",.01,"E")
 D FILE^DIE("","BTPUPD","ERROR")
 ;
 ;Save comments - if provided
 I $G(CMTVAR)]"" D WP^DIE(90629,RIEN_",",3,"",CMTVAR)
 ;
 Q
 ;
MV ;EP - Move procedure into permanent file
 NEW BTDATA,FRIL,DFN,PRCN,VISIT,DIC,DLAYGO,X,PIEN,WHIEN,RARPT,BTPUPD,RCIEN,DTTM
 NEW RTMFRM,TMFRAME,FDUE,FTMFRM,NDUE,NTMFRM,CAT,MATCH,VSDTM,DATE,COMM,FIND,FC
 S BTDATA=^BTPWQ(RIEN,0)
 S PRCN=$P(BTDATA,U,1),DFN=$P(BTDATA,U,2),VISIT=$P(BTDATA,U,4)
 S RCIEN=$P(BTDATA,U,5),FRIL=$P(BTDATA,U,6),DATE=$P(BTDATA,U,7)
 S COMM=$P(BTDATA,U,16)
 S MATCH=$P($G(^BTPWQ(RIEN,1)),U,1),FIND=$P($G(^BTPWQ(RIEN,1)),U,2)
 ;
 ;Pull current date/time
 S DTTM=$$NOW^XLFDT()
 ;
 I $D(^BTPWP("C",DFN,PRCN,VISIT,RCIEN,FRIL)) Q
 ;
 S VSDTM=$P(BTDATA,U,3),WHIEN=$P(BTDATA,U,9),RARPT=$P(BTDATA,U,10),CAT=$P(BTDATA,U,13),ACCN=$P(BTDATA,U,15)
 ;
 I MATCH D
 . S (CMIEN,PIEN)=MATCH
 . D RHIS
 . S BTPUPD(90620,PIEN_",",.13)="@"
 ;
 I 'MATCH S PIEN=$$REC(PRCN),CMIEN=PIEN
 ;
 S BTPUPD(90620,PIEN_",",.02)=DFN,BTPUPD(90620,PIEN_",",.03)=VSDTM
 S BTPUPD(90620,PIEN_",",.04)=VISIT,BTPUPD(90620,PIEN_",",.05)=RCIEN
 S BTPUPD(90620,PIEN_",",.06)=FRIL,BTPUPD(90620,PIEN_",",.07)=DATE
 S BTPUPD(90620,PIEN_",",.09)=WHIEN,BTPUPD(90620,PIEN_",",.1)=RARPT
 S BTPUPD(90620,PIEN_",",.15)=ACCN
 S BTPUPD(90620,PIEN_",",.08)="T",BTPUPD(90620,PIEN_",",1.01)="O"
 S BTPUPD(90620,PIEN_",",.14)=RIEN,BTPUPD(90620,PIEN_",",.16)=COMM
 S BTPUPD(90620,PIEN_",",1.02)=DTTM,BTPUPD(90620,PIEN_",",1.03)=DUZ
 S BTPUPD(90620,PIEN_",",1.09)=BTPUPD(90620,PIEN_",",1.02),BTPUPD(90620,PIEN_",",1.1)=DUZ
 S BTPUPD(90620,PIEN_",",1.05)=RDUE
 S BTPUPD(90629,RIEN_",",.14)=PIEN
 S BTPUPD(90620,PIEN_",",.12)=CAT
 ;
 ;Log History Entries
 ;Save Date Identified First
 N DTIDT,USER
 S DTIDT(90620,PIEN_",",.07)=DATE
 S USER=DUZ,SIEN=$O(^BTPWQ(RIEN,2,0)) I SIEN]"" S USER=$P($G(^BTPWQ(RIEN,2,SIEN,0)),U,3)
 I DATE'="" D RLOG^BTPWHIST(.DTIDT,USER,DATE,"Night Jobs Identified")
 ;
 ;Now Save Status Changes
 D SLOG^BTPWHIST(RIEN,PIEN,DTTM,DUZ,"Status Changes")
 ;
 ;Save Remaining Information
 M DTIDT=BTPUPD K DTIDT(90620,PIEN_",",.07),DTIDT(90620,PIEN_",",.08)
 I $D(DTIDT)>0 D RLOG^BTPWHIST(.DTIDT,DUZ,DTTM,"Event Tracked")
 K DTIDT,USER
 ;End of History Saving Code
 ;
 ; Move Finding
 I FIND'="" D
 . S INTR=$$GET1^DIQ(90620.9,FIND_",",.02,"I")
 . D FND(PIEN)
 . S BTUPD(90620,PIEN_",",1.05)=DT
 . D FILE^DIE("","BTUPD","ERROR")
 ;
 ;File the Information
 D FILE^DIE("","BTPUPD","ERROR")
 I $D(ERROR) Q
 ;
 ;Save Status Comment to Tracked File EVENT COMMENTS field
 D WP^DIE(90620,PIEN_",",4,"","^BTPWQ(RIEN,3)")
 ;
 Q
 ;
QHIS ; EP - Build queue history record
 NEW FDA,PSTAT,PUSR,PDTM,DIC,DA,DIE,X,IENS
 ;
 S PSTAT=$P(^BTPWQ(RIEN,0),U,8)
 S PUSR=$P(^BTPWQ(RIEN,0),U,12)
 S PDTM=$P(^BTPWQ(RIEN,0),U,11)
 ;
 S DIC(0)="L",DA(1)=RIEN,DIC="^BTPWQ("_DA(1)_",2,",DIE=DIC
 I $G(^BTPWQ(DA(1),2,0))="" S ^BTPWQ(DA(1),2,0)="^90629.02D^^"
 S X=$$NOW^XLFDT()
 K DO,DD D FILE^DICN S DA=+Y I DA=-1 Q
 ;
 S IENS=$$IENS^DILF(.DA)
 S FDA(90629.02,IENS,.02)=PSTAT
 S FDA(90629.02,IENS,.03)=PUSR
 S FDA(90629.02,IENS,.04)=PDTM
 ;
 D FILE^DIE("","FDA","ERROR")
 ;
 ;Save Status Comment to History
 D WP^DIE(90629.02,IENS,1,"","^BTPWQ(RIEN,3)")
 Q
 ;
RHIS ; EP - Build tracked history record
 NEW FDA,PSTATE,PUSR,PDTM,PCREAS,DIC,DA,DIE,X,IENS
 ;
 S PSTATE=$P($G(^BTPWP(PIEN,1)),U,1)
 S PUSR=$P($G(^BTPWP(PIEN,1)),U,3),PUSR=$$GET1^DIQ(200,PUSR_",",.01,"E")
 S PDTM=$P($G(^BTPWP(PIEN,1)),U,2)
 S PCREAS=$P($G(^BTPWP(PIEN,1)),U,4)
 ;
 S DIC(0)="L",DA(1)=PIEN,DIC="^BTPWP("_DA(1)_",2,",DIE=DIC
 I $G(^BTPWP(DA(1),2,0))="" S ^BTPWP(DA(1),2,0)="^90620.02D^^"
 S X=$$NOW^XLFDT()
 K DO,DD D FILE^DICN S DA=+Y I DA=-1 Q
 ;
 S IENS=$$IENS^DILF(.DA)
 S FDA(90620.02,IENS,.02)=PSTATE
 S FDA(90620.02,IENS,.03)=PUSR
 S FDA(90620.02,IENS,.04)=PDTM
 S FDA(90620.02,IENS,.05)=PCREAS
 D FILE^DIE("","FDA","ERROR")
 ;
 ;Save State Comment to History
 D WP^DIE(90620.02,IENS,1,"","^BTPWP(PIEN,3)")
 Q
 ;
REC(PRCN) ;EP - Create a new record
 NEW DIC,DLAYGO,X,Y
 S DIC="^BTPWP(",DIC(0)="LMNZ",DLAYGO=90620,DIC("P")=DLAYGO
 S X=PRCN
 K DO,DD D FILE^DICN
 Q +Y
 ;
FND(CMIEN) ;EP - Add a Finding
 S BTPFNDTM=$$NOW^XLFDT()
 D FND^BTPWPWRS
 NEW DA,IENS
 S DA(1)=CMIEN,DA=EVIEN,IENS=$$IENS^DILF(.DA)
 S BTUPD(90620.01,IENS,.02)=FIND
 S BTUPD(90620.01,IENS,.03)=INTR
 S BTUPD(90620.01,IENS,.04)=$$NOW^XLFDT()
 S BTUPD(90620.01,IENS,.05)=DUZ
 D FILE^DIE("","BTUPD","ERROR")
 D WP^DIE(90620.01,IENS,1,"","^BTPWQ(RIEN,4)")
 Q