BQINOTF ;PRXM/HC/ALA-ICARE NOTIFICATIONS ; 27 Jun 2006 3:01 PM
;;2.5;ICARE MANAGEMENT SYSTEM;**2**;May 24, 2016;Build 14
;
Q
;
UPD(OWNR,PLIEN,MSG) ;EP - Update notifications
;
I $G(OWNR)="" Q
I $G(PLIEN)="" Q
;
NEW SHRDZ,ERROR,SHAXCS,SHSTDT,SHENDT
;
S SHRDZ=0
F S SHRDZ=$O(^BQICARE(OWNR,1,PLIEN,30,SHRDZ)) Q:'SHRDZ D
. I SHRDZ'=DUZ D
.. S SHAXCS=$P(^BQICARE(OWNR,1,PLIEN,30,SHRDZ,0),U,2)
.. S SHSTDT=$P(^BQICARE(OWNR,1,PLIEN,30,SHRDZ,0),U,3)
.. S SHENDT=$P(^BQICARE(OWNR,1,PLIEN,30,SHRDZ,0),U,4)
.. I SHSTDT'>DT,((SHENDT'<DT)!(SHENDT="")),SHAXCS'="I" D FIL(SHRDZ,MSG)
;
I $G(OWNR)'=$G(DUZ) D FIL(OWNR,MSG)
Q
;
ADD(DATA,RECIP,SUBJ,BODY,SENT) ;EP -- BQI ADD NOTIFICATION
;Description
; RPC Call to add notifications
;Input
; RECIP - Recipients of message
; SUBJ - Subject of message
; BODY - Body of message (not in use yet)
; SENT - If background job sent the notification
NEW UID,II,KK,ERROR,NDZ,NTDFTM,RESULT
S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
S DATA=$NA(^TMP("BQINOTF",UID))
K @DATA
;
S II=0,RESULT=1,SENT=$G(SENT,"")
NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQINOTF D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
S @DATA@(II)="I00010RESULT"_$C(30)
;
S NTDFTM=$$NOW^XLFDT()
F KK=1:1 S NDZ=$P(RECIP,$C(28),KK) Q:NDZ="" D FIL(NDZ,SUBJ,.BODY,SENT)
;
I $G(RECIP)="" D FIL(DUZ,SUBJ,.BODY,SENT)
;
I $D(ERROR) S RESULT=-1
S II=II+1,@DATA@(II)=RESULT_$C(30)
S II=II+1,@DATA@(II)=$C(31)
Q
;
FIL(NDZ,TMSG,BODY,SENT) ;EP - Notify users
;Input parameters
; NDZ - IEN of person receiving notification
; TMSG - Subject of message
; BODY - Body of message (not being set at this time)
; SENT - will be 1 if sent by background job
;
NEW NTDFTM,DLOG,LYR
S NTDFTM=$$NOW^XLFDT()
;
; If person hasn't signed onto iCare in over a year, quit
I $G(^BQICARE(NDZ,0))="" K ^BQICARE(NDZ) Q
S DLOG=$P(^BQICARE(NDZ,0),U,6)\1,LYR=$$DATE^BQIUL1("T-365")
I DLOG<LYR Q
;
I $G(^BQICARE(NDZ,3,0))="" S ^BQICARE(NDZ,3,0)="^90505.12D^^"
NEW DA,IENS,X,DIC,ERROR
S DA(1)=NDZ,X=NTDFTM,DIC(0)="L",DIC="^BQICARE("_DA(1)_",3,"
K DO,DD D FILE^DICN
S DA=+Y I DA<0 Q
S IENS=$$IENS^DILF(.DA)
S BQINOTE(90505.12,IENS,.02)=$S($G(SENT)=1:"",1:DUZ)
S BQINOTE(90505.12,IENS,.03)="N"
S BQINOTE(90505.12,IENS,.04)=$G(TMSG)
D FILE^DIE("","BQINOTE","ERROR")
K BQINOTE
I $D(BODY)>1 D WP^DIE(90505.12,IENS,1,"","BODY","ERROR")
I $G(BODY)["^TMP" D WP^DIE(90505.12,IENS,1,"",BODY,"ERROR")
; Raise event to user that a new notification has been created
I '$D(ERROR) D EVENT^BMXMEVN("BQI NOTIFICATION RECEIVED",NDZ_"~"_$G(TMSG))
Q
;
RET(DATA,FAKE) ; EP -- BQI GET NOTIFICATIONS
; Return notifications for a user
;
NEW UID,II,NDATA,NTFN
S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
S DATA=$NA(^TMP("BQINOTF",UID))
K @DATA
;
S II=0
NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQINOTF D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
;
S @DATA@(II)="I00010NOTF_IEN^D00015NOTIFICATION_DATETIME^T00035FROM_WHOM^T00003STATUS^T00231SUBJECT^T01024BODY"_$C(30)
;
S NTFN=0
F S NTFN=$O(^BQICARE(DUZ,3,NTFN)) Q:'NTFN D
. S II=II+1
. S NDATA=^BQICARE(DUZ,3,NTFN,0)
. NEW DA,IENS,NSTAT
. S DA(1)=DUZ,DA=NTFN,IENS=$$IENS^DILF(.DA)
. S NSTAT=$$GET1^DIQ(90505.12,IENS,.03,"E")
. NEW BN,BODY
. S BODY="",BN=0
. F S BN=$O(^BQICARE(DUZ,3,NTFN,1,BN)) Q:'BN D
.. S BODY=BODY_" "_^BQICARE(DUZ,3,NTFN,1,BN,0)
. ;S BODY=$$TKO^BQIUL1(BODY,$C(10))
. S BODY=$E(BODY,2,$L(BODY))
. S @DATA@(II)=NTFN_"^"_$$FMTE^BQIUL1($P(NDATA,U,1))_"^"_$$GET1^DIQ(200,$P(NDATA,U,2)_",",.01,"E")_"^"_NSTAT_"^"_$P(NDATA,U,4)_"^"_BODY_$C(30)
;
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
;
MOD(DATA,NIEN,STAT) ;EP -- BQI UPDATE NOTIFICATION STATUS
; Modify the status of a notification
NEW UID,II,DA,IENS,RESULT
S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
S DATA=$NA(^TMP("BQINOTF",UID))
K @DATA
;
I $G(NIEN)="" S BMXSEC="No notification record passed in." Q
S II=0,RESULT=1
NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQINOTF D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
S @DATA@(II)="I00010RESULT"_$C(30)
;
S DA(1)=DUZ,DA=NIEN,IENS=$$IENS^DILF(.DA)
S BQNUPD(90505.12,IENS,.03)=$G(STAT)
D FILE^DIE("E","BQNUPD","ERROR")
K BQNUPD
I $D(ERROR) S RESULT=-1
S II=II+1,@DATA@(II)=RESULT_$C(30)
S II=II+1,@DATA@(II)=$C(31)
Q
;
CLR(DATA,NIEN) ;EP -- BQI CLEAR NOTIFICATIONS
; Clear notifications for user
NEW UID,II,NTFN,DIK,DA
S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
S DATA=$NA(^TMP("BQINOTF",UID))
K @DATA
;
S II=0
NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQINOTF D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
S @DATA@(II)="I00010RESULT"_$C(30)
;
; If a particular notification IEN sent, just delete that one
; If no IEN, delete all notifications
I $G(NIEN)="" S NTFN=0 F S NTFN=$O(^BQICARE(DUZ,3,NTFN)) Q:'NTFN D DEL
I $G(NIEN)'="" S NTFN=NIEN D DEL
;
S RESULT=1
S II=II+1,@DATA@(II)=RESULT_$C(30)
S II=II+1,@DATA@(II)=$C(31)
Q
;
DEL ; Delete the notification
S DA(1)=DUZ,DA=NTFN,DIK="^BQICARE("_DA(1)_",3,"
D ^DIK
Q
;
DUP(USR,SUBJECT,DATE) ;EP - Check for a duplicate message
NEW MSN,OK,QFL
S MSN=0,OK=1,QFL=0
F S MSN=$O(^BQICARE(USR,3,MSN)) Q:'MSN D Q:QFL
. I $P(^BQICARE(USR,3,MSN,0),U,4)=SUBJECT,$P(^(0),U,1)\1=DATE S OK=0,QFL=1
Q OK
BQINOTF ;PRXM/HC/ALA-ICARE NOTIFICATIONS ; 27 Jun 2006 3:01 PM
+1 ;;2.5;ICARE MANAGEMENT SYSTEM;**2**;May 24, 2016;Build 14
+2 ;
+3 QUIT
+4 ;
UPD(OWNR,PLIEN,MSG) ;EP - Update notifications
+1 ;
+2 IF $GET(OWNR)=""
QUIT
+3 IF $GET(PLIEN)=""
QUIT
+4 ;
+5 NEW SHRDZ,ERROR,SHAXCS,SHSTDT,SHENDT
+6 ;
+7 SET SHRDZ=0
+8 FOR
SET SHRDZ=$ORDER(^BQICARE(OWNR,1,PLIEN,30,SHRDZ))
IF 'SHRDZ
QUIT
Begin DoDot:1
+9 IF SHRDZ'=DUZ
Begin DoDot:2
+10 SET SHAXCS=$PIECE(^BQICARE(OWNR,1,PLIEN,30,SHRDZ,0),U,2)
+11 SET SHSTDT=$PIECE(^BQICARE(OWNR,1,PLIEN,30,SHRDZ,0),U,3)
+12 SET SHENDT=$PIECE(^BQICARE(OWNR,1,PLIEN,30,SHRDZ,0),U,4)
+13 IF SHSTDT'>DT
IF ((SHENDT'<DT)!(SHENDT=""))
IF SHAXCS'="I"
DO FIL(SHRDZ,MSG)
End DoDot:2
End DoDot:1
+14 ;
+15 IF $GET(OWNR)'=$GET(DUZ)
DO FIL(OWNR,MSG)
+16 QUIT
+17 ;
ADD(DATA,RECIP,SUBJ,BODY,SENT) ;EP -- BQI ADD NOTIFICATION
+1 ;Description
+2 ; RPC Call to add notifications
+3 ;Input
+4 ; RECIP - Recipients of message
+5 ; SUBJ - Subject of message
+6 ; BODY - Body of message (not in use yet)
+7 ; SENT - If background job sent the notification
+8 NEW UID,II,KK,ERROR,NDZ,NTDFTM,RESULT
+9 SET UID=$SELECT($GET(ZTSK):"Z"_ZTSK,1:$JOB)
+10 SET DATA=$NAME(^TMP("BQINOTF",UID))
+11 KILL @DATA
+12 ;
+13 SET II=0
SET RESULT=1
SET SENT=$GET(SENT,"")
+14 ; SAC 2006 2.2.3.3.2
NEW $ESTACK,$ETRAP
SET $ETRAP="D ERR^BQINOTF D UNWIND^%ZTER"
+15 SET @DATA@(II)="I00010RESULT"_$CHAR(30)
+16 ;
+17 SET NTDFTM=$$NOW^XLFDT()
+18 FOR KK=1:1
SET NDZ=$PIECE(RECIP,$CHAR(28),KK)
IF NDZ=""
QUIT
DO FIL(NDZ,SUBJ,.BODY,SENT)
+19 ;
+20 IF $GET(RECIP)=""
DO FIL(DUZ,SUBJ,.BODY,SENT)
+21 ;
+22 IF $DATA(ERROR)
SET RESULT=-1
+23 SET II=II+1
SET @DATA@(II)=RESULT_$CHAR(30)
+24 SET II=II+1
SET @DATA@(II)=$CHAR(31)
+25 QUIT
+26 ;
FIL(NDZ,TMSG,BODY,SENT) ;EP - Notify users
+1 ;Input parameters
+2 ; NDZ - IEN of person receiving notification
+3 ; TMSG - Subject of message
+4 ; BODY - Body of message (not being set at this time)
+5 ; SENT - will be 1 if sent by background job
+6 ;
+7 NEW NTDFTM,DLOG,LYR
+8 SET NTDFTM=$$NOW^XLFDT()
+9 ;
+10 ; If person hasn't signed onto iCare in over a year, quit
+11 IF $GET(^BQICARE(NDZ,0))=""
KILL ^BQICARE(NDZ)
QUIT
+12 SET DLOG=$PIECE(^BQICARE(NDZ,0),U,6)\1
SET LYR=$$DATE^BQIUL1("T-365")
+13 IF DLOG<LYR
QUIT
+14 ;
+15 IF $GET(^BQICARE(NDZ,3,0))=""
SET ^BQICARE(NDZ,3,0)="^90505.12D^^"
+16 NEW DA,IENS,X,DIC,ERROR
+17 SET DA(1)=NDZ
SET X=NTDFTM
SET DIC(0)="L"
SET DIC="^BQICARE("_DA(1)_",3,"
+18 KILL DO,DD
DO FILE^DICN
+19 SET DA=+Y
IF DA<0
QUIT
+20 SET IENS=$$IENS^DILF(.DA)
+21 SET BQINOTE(90505.12,IENS,.02)=$SELECT($GET(SENT)=1:"",1:DUZ)
+22 SET BQINOTE(90505.12,IENS,.03)="N"
+23 SET BQINOTE(90505.12,IENS,.04)=$GET(TMSG)
+24 DO FILE^DIE("","BQINOTE","ERROR")
+25 KILL BQINOTE
+26 IF $DATA(BODY)>1
DO WP^DIE(90505.12,IENS,1,"","BODY","ERROR")
+27 IF $GET(BODY)["^TMP"
DO WP^DIE(90505.12,IENS,1,"",BODY,"ERROR")
+28 ; Raise event to user that a new notification has been created
+29 IF '$DATA(ERROR)
DO EVENT^BMXMEVN("BQI NOTIFICATION RECEIVED",NDZ_"~"_$GET(TMSG))
+30 QUIT
+31 ;
RET(DATA,FAKE) ; EP -- BQI GET NOTIFICATIONS
+1 ; Return notifications for a user
+2 ;
+3 NEW UID,II,NDATA,NTFN
+4 SET UID=$SELECT($GET(ZTSK):"Z"_ZTSK,1:$JOB)
+5 SET DATA=$NAME(^TMP("BQINOTF",UID))
+6 KILL @DATA
+7 ;
+8 SET II=0
+9 ; SAC 2006 2.2.3.3.2
NEW $ESTACK,$ETRAP
SET $ETRAP="D ERR^BQINOTF D UNWIND^%ZTER"
+10 ;
+11 SET @DATA@(II)="I00010NOTF_IEN^D00015NOTIFICATION_DATETIME^T00035FROM_WHOM^T00003STATUS^T00231SUBJECT^T01024BODY"_$CHAR(30)
+12 ;
+13 SET NTFN=0
+14 FOR
SET NTFN=$ORDER(^BQICARE(DUZ,3,NTFN))
IF 'NTFN
QUIT
Begin DoDot:1
+15 SET II=II+1
+16 SET NDATA=^BQICARE(DUZ,3,NTFN,0)
+17 NEW DA,IENS,NSTAT
+18 SET DA(1)=DUZ
SET DA=NTFN
SET IENS=$$IENS^DILF(.DA)
+19 SET NSTAT=$$GET1^DIQ(90505.12,IENS,.03,"E")
+20 NEW BN,BODY
+21 SET BODY=""
SET BN=0
+22 FOR
SET BN=$ORDER(^BQICARE(DUZ,3,NTFN,1,BN))
IF 'BN
QUIT
Begin DoDot:2
+23 SET BODY=BODY_" "_^BQICARE(DUZ,3,NTFN,1,BN,0)
End DoDot:2
+24 ;S BODY=$$TKO^BQIUL1(BODY,$C(10))
+25 SET BODY=$EXTRACT(BODY,2,$LENGTH(BODY))
+26 SET @DATA@(II)=NTFN_"^"_$$FMTE^BQIUL1($PIECE(NDATA,U,1))_"^"_$$GET1^DIQ(200,$PIECE(NDATA,U,2)_",",.01,"E")_"^"_NSTAT_"^"_$PIECE(NDATA,U,4)_"^"_BODY_$CHAR(30)
End DoDot:1
+27 ;
+28 SET II=II+1
SET @DATA@(II)=$CHAR(31)
+29 QUIT
+30 ;
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 ;
MOD(DATA,NIEN,STAT) ;EP -- BQI UPDATE NOTIFICATION STATUS
+1 ; Modify the status of a notification
+2 NEW UID,II,DA,IENS,RESULT
+3 SET UID=$SELECT($GET(ZTSK):"Z"_ZTSK,1:$JOB)
+4 SET DATA=$NAME(^TMP("BQINOTF",UID))
+5 KILL @DATA
+6 ;
+7 IF $GET(NIEN)=""
SET BMXSEC="No notification record passed in."
QUIT
+8 SET II=0
SET RESULT=1
+9 ; SAC 2006 2.2.3.3.2
NEW $ESTACK,$ETRAP
SET $ETRAP="D ERR^BQINOTF D UNWIND^%ZTER"
+10 SET @DATA@(II)="I00010RESULT"_$CHAR(30)
+11 ;
+12 SET DA(1)=DUZ
SET DA=NIEN
SET IENS=$$IENS^DILF(.DA)
+13 SET BQNUPD(90505.12,IENS,.03)=$GET(STAT)
+14 DO FILE^DIE("E","BQNUPD","ERROR")
+15 KILL BQNUPD
+16 IF $DATA(ERROR)
SET RESULT=-1
+17 SET II=II+1
SET @DATA@(II)=RESULT_$CHAR(30)
+18 SET II=II+1
SET @DATA@(II)=$CHAR(31)
+19 QUIT
+20 ;
CLR(DATA,NIEN) ;EP -- BQI CLEAR NOTIFICATIONS
+1 ; Clear notifications for user
+2 NEW UID,II,NTFN,DIK,DA
+3 SET UID=$SELECT($GET(ZTSK):"Z"_ZTSK,1:$JOB)
+4 SET DATA=$NAME(^TMP("BQINOTF",UID))
+5 KILL @DATA
+6 ;
+7 SET II=0
+8 ; SAC 2006 2.2.3.3.2
NEW $ESTACK,$ETRAP
SET $ETRAP="D ERR^BQINOTF D UNWIND^%ZTER"
+9 SET @DATA@(II)="I00010RESULT"_$CHAR(30)
+10 ;
+11 ; If a particular notification IEN sent, just delete that one
+12 ; If no IEN, delete all notifications
+13 IF $GET(NIEN)=""
SET NTFN=0
FOR
SET NTFN=$ORDER(^BQICARE(DUZ,3,NTFN))
IF 'NTFN
QUIT
DO DEL
+14 IF $GET(NIEN)'=""
SET NTFN=NIEN
DO DEL
+15 ;
+16 SET RESULT=1
+17 SET II=II+1
SET @DATA@(II)=RESULT_$CHAR(30)
+18 SET II=II+1
SET @DATA@(II)=$CHAR(31)
+19 QUIT
+20 ;
DEL ; Delete the notification
+1 SET DA(1)=DUZ
SET DA=NTFN
SET DIK="^BQICARE("_DA(1)_",3,"
+2 DO ^DIK
+3 QUIT
+4 ;
DUP(USR,SUBJECT,DATE) ;EP - Check for a duplicate message
+1 NEW MSN,OK,QFL
+2 SET MSN=0
SET OK=1
SET QFL=0
+3 FOR
SET MSN=$ORDER(^BQICARE(USR,3,MSN))
IF 'MSN
QUIT
Begin DoDot:1
+4 IF $PIECE(^BQICARE(USR,3,MSN,0),U,4)=SUBJECT
IF $PIECE(^(0),U,1)\1=DATE
SET OK=0
SET QFL=1
End DoDot:1
IF QFL
QUIT
+5 QUIT OK