ORBSMART ;SLC/JMH - SMART NOTIFICATIONS; Oct 4, 2022@11:23
;;3.0;ORDER ENTRY/RESULTS REPORTING;**377,498,593**;Dec 17, 1997;Build 6
;
; Reference to EN^PXRMGEV in ICR #6772
; Reference to ALERTDAT^XQALBUTL in ICR #2788
; Reference to GETUSER1^XQALDATA in ICR #4834
; Reference to GETPAT2^XQALDATA in ICR #4834
;
INSMALRT(ORY,ORAID) ;set what alert is being processed for smart
S ^TMP("ORSMART CURRENT ALERT",$J)=ORAID
Q
;
OUSMALRT(ORY,ORAID) ;clear what alert is being processed for smart
K ^TMP("ORSMART CURRENT ALERT",$J)
Q
;
EN(ORY,ORDATA) ;
N DATA
I $D(ORDATA("DATA",100.9)) D
.D CLEAR(.ORY,.ORDATA)
.S ORY(1)=1
I $D(ORDATA("DATA",100.97)) D
.S DATA("PATIENT")=ORDATA("DFN")
.S DATA("TITLE")=$G(ORDATA("DATA",100.97,"+1,",5))
.S DATA("WHO")=DUZ
.S DATA("WHEN")=$G(ORDATA("DATA",100.97,"+1,",2))
.S DATA("BODY",1)=$G(ORDATA("DATA",100.97,"+1,",6))
.D SCHALRT^ORB3UTL(.DATA)
.S ORY(1)=1
Q
;
CLEAR(ORY,ORDATA) ;Clear SMART alert
S ORY(1)=1
;
N ACTION,ISDEFER,ORBY,ORINPUT,ORNOTIEN,ORDFN,ORRESULT,STATUS,ORXDATA
;ORNOTIEN=84;85
S ORDFN=ORDATA("DFN")
;S ORNOTIEN=$G(ORDATA("DATA",100.9,"+1,",.01))
;S ISDEFER=$G(ORDATA("DATA",100.9,"+1,","DATE"))
;ACTION=CLEAR PROVIDER (ALL INSTANCE OF NOT IEN FOR CURRENT USER)
;ACTION=CLEAR ALL (ALL INSTANCE OF NOT IEN FOR ALL USER)
;ACTION=CLEAR ONE (CLEAR ONLY THIS ALERT XQAID)
;ACTION="REEVALUATE REMINDER BEFORE CLEAR"
;S ACTION=$G(ORDATA("DATA",100.9,"+1,","ACTION"))
;see if there is a data piece we should match for delete
S ORXDATA=$G(ORDATA("DATA",100.9,"MASTER ID"))
I ORXDATA="" S ORXDATA="+1,"
S ACTION=$G(ORDATA("DATA",100.9,ORXDATA,"ACTION"))
S ORNOTIEN=$G(ORDATA("DATA",100.9,ORXDATA,.01))
I ACTION="CLEAR PROVIDER" D CLRPROV(ORNOTIEN,ORDFN)
I ACTION="CLEAR ALL" D CLRALL(ORNOTIEN,ORDFN)
I ACTION="CLEAR ONE" D CLRONE(ORXDATA)
Q
;
CLRPROV(ORNOT,ORDFN) ;clear all alerts for notification ORNOT for patient ORDFN for the current user DUZ
N ORPALERTS,ORI,ORNOTX,ORBY
D PALERTS(ORDFN,"ORPALERTS")
Q:'$D(ORPALERTS)
S ORI=0,ORNOTX="" F S ORI=ORI+1 S ORNOTX=$P(ORNOT,";",ORI) Q:'$L(ORNOTX) D
.N ORJ S ORJ=0 F S ORJ=$O(ORPALERTS(ORNOTX,ORJ)) Q:$L(ORJ)<1 D
..K ORBY D DEL^ORB3FUP1(.ORBY,ORJ,1)
Q
;
CLRALL(ORNOT,ORDFN) ;clear all alerts for notification ORNOT for patient ORDFN for all users
N ORPALERTS,ORI,ORNOTX,ORBY
D PALERTS(ORDFN,"ORPALERTS")
Q:'$D(ORPALERTS)
S ORI=0,ORNOTX="" F S ORI=ORI+1 S ORNOTX=$P(ORNOT,";",ORI) Q:'$L(ORNOTX) D
.N ORJ S ORJ=0 F S ORJ=$O(ORPALERTS(ORNOTX,ORJ)) Q:$L(ORJ)<1 D
..K ORBY D DEL^ORB3FUP1(.ORBY,ORJ,0)
Q
;
CLRONE(ORDATA) ;clear only the alert matching ORDATA
N ORBY
D DEL^ORB3FUP1(.ORBY,ORDATA,0)
Q
;
;REM(PAT,NAME) ;
;N DEFARR,FIEVAL,NODE,RIEN,RNAME,RSTAT
;S RIEN=$O(^PXD(811.9,"B",NAME,"")) I +RIEN=0 Q 0
;S NODE=$G(^PXD(811.9,RIEN,0))
;S RNAME=$S($P(NODE,U,3)'="":$P(NODE,U,3),1:$P(NODE,U))
;D DEF^PXRMLDR(RIEN,.DEFARR)
;K FIEVAL
;D EVAL^PXRM(PAT,.DEFARR,5,1,.FIEVAL,DT)
;S RSTAT=$P($G(^TMP("PXRHM",$J,RIEN,RNAME)),U)
;Q RSTAT
;
SMALERTS(ORDFN,ORDUZ,ORGLOB) ;
N ORY
K @ORGLOB
D GETUSER1^XQALDATA("ORY",ORDUZ)
N ORI S ORI=0 F S ORI=$O(ORY(ORI)) Q:'ORI D
.Q:($P($P(ORY(ORI),U,2),",",2)'=ORDFN)
.I $G(ORALL)!($$ISSMIEN($P($P($P(ORY(ORI),U,2),",",3),";"))) D
..N ORBDATA D GETDATA^ORWORB(.ORBDATA,$P(ORY(ORI),U,2))
..S @ORGLOB@($P($P($P(ORY(ORI),U,2),",",3),";"),$P(ORY(ORI),U,2),"DATA")=ORBDATA
..N ORBD2 D ALERTDAT^XQALBUTL($P(ORY(ORI),U,2),"ORBD2")
..S @ORGLOB@($P($P($P(ORY(ORI),U,2),",",3),";"),$P(ORY(ORI),U,2),"DATE")=$G(ORBD2(.02))
Q
;
PALERTS(ORDFN,ORGLOB) ;
N ORY
K @ORGLOB
D GETPAT2^XQALDATA("ORY",ORDFN,1,1000)
N ORI S ORI=0 F S ORI=$O(ORY(ORI)) Q:'ORI D
.Q:($P($P(ORY(ORI),U,2),",",2)'=ORDFN)
.I $G(ORALL)!($$ISSMIEN($P($P($P(ORY(ORI),U,2),",",3),";"))) D
..S @ORGLOB@($P($P($P(ORY(ORI),U,2),",",3),";"),$P(ORY(ORI),U,2))=""
Q
;
UHASNOT(ORDFN,ORDUZ,ORNOT) ; returns 1 if user ORDUZ has notification ORNOT for patient ORDFN
N ORRET,ORALERTS,ORI
S ORRET=0
D SMALERTS(ORDFN,ORDUZ,"ORALERTS")
I $D(ORALERTS(ORNOT)) S ORRET=1
Q ORRET
;
PHASNOT(ORDFN,ORNOT) ; returns 1 patient ORDUZ has a notification ORNOT
N ORRET,ORALERTS,ORI
S ORRET=0
D PALERTS(ORDFN,"ORALERTS")
I $D(ORALERTS(ORNOT)) S ORRET=1
Q ORRET
;
SMIENS(ORY) ;
N I
S I=0
F S I=$O(^ORD(100.9,I)) Q:'I D
.I +$G(^ORD(100.9,I,6)) S ORY(I)=1
Q
;
ISSMIEN(ORIEN) ;
I +$G(^ORD(100.9,ORIEN,6)) Q 1
Q 0
;
ISSMNOT(ORY,ORIEN) ;
S ORY=$$ISSMIEN(ORIEN)
Q
NCIMGNOT(ORDFN) ;Fire SMART NON-CRITICAL IMAGING RES alert
N ORNOTNM,ORNOTIEN
S ORNOTNM="SMART NON-CRITICAL IMAGING RES"
S ORNOTIEN=$$GETNOTID(ORNOTNM)
I '$$PHASNOT(ORDFN,ORNOTIEN) D EN^ORB3(ORNOTIEN,ORDFN,"","","","SMART,")
Q
;
GETRMLST(ORLST,ORLNM,OVER,RETDATA) ;Get a list of patients from Reminder call
N ORRMIN,ORY,ORTNM
S ORTNM="ORRM LIST"
K ^TMP($J,ORTNM)
S ORRMIN("SUB")=ORTNM
S ORRMIN("LR",ORLNM)=ORLNM_U_DT_U_DT_U_0_U_$G(OVER,1)_U_RETDATA
D EN^PXRMGEV(.ORY,.ORRMIN)
N ORI S ORI=0 F S ORI=$O(^TMP($J,ORTNM,ORLNM,ORI)) Q:'ORI D
.S ORLST(ORI)=""
.I RETDATA M ORLST(ORI,"DATA")=^TMP($J,ORTNM,ORLNM,ORI,"DATA")
K ^TMP($J,ORTNM)
Q
;
HOOK(ORN,ORBDFN,ORNUM,ORBADUZ,ORBPMSG,ORBPDATA) ;
N ORRET,ORI,USER,SMARARR S (ORRET,ORI)=0
F S ORI=$O(^ORD(100.9,"E",ORN,ORI)) Q:'ORI D
.N ORJ S ORJ=$O(^ORD(100.9,"E",ORN,ORI,"")) Q:'ORJ
.;get DEPENDENT LOGIC. If no logic then go ahead with replacement. otherwise run logic to determine if should replace
.N ORLOG S ORLOG=$G(^ORD(100.9,ORI,7,ORJ,1))
.N ORFIRE,ORNEWMSG S ORFIRE=1,ORNEWMSG=$G(ORBPMSG)
.I $L(ORLOG) X ORLOG ; if ORLOG code is set run it and it will set ORFIRE to either 0 or 1
.I ORFIRE D
..S USER=0 F S USER=$O(ORBADUZ(USER)) Q:USER'>0 D
...I $$SMARTON(USER,ORI) S SMARARR(USER)=""
..S USER=0 F S USER=$O(SMARARR(USER)) Q:USER'>0 D
...K ORBADUZ(USER)
..D EN^ORB3(ORI,ORBDFN,$G(ORNUM),.SMARARR,$G(ORNEWMSG),$G(ORBPDATA))
..;W !,"FIRING ",ORI," IN PLACE OF ",ORN," FOR MESSAGE '",ORBPMSG,"'"
..I $P($G(^ORD(100.9,ORI,7,ORJ,0)),U,2)="1",'$D(ORBADUZ) S ORRET=1
Q ORRET
;
GETNOTID(ORNOTNM) ;Get the OE/RR NOTIFICATIONS File IEN for the notification name
I '$L(ORNOTNM) Q ""
Q $O(^ORD(100.9,"B",ORNOTNM,0))
;
GENERATE ;generate the smart alerts
;I $$SCHCALL("XBIMGPND^ORBSMART","DAILY") D XBIMGPND
Q
;
SCHCALL(ORRTN,ORSCH) ;Return 1 if ORRTN should be run now, 0 if not.
;Based on the schedule passed in ORSCH
;if it returns 1 it will set a log that the call is made also
N ORGLOB,ORRET
S ORGLOB="OR SCHCALL",ORRET=1
S ^XTMP(ORGLOB,0)=$$FMADD^XLFDT($$NOW^XLFDT,60)_U_$$NOW^XLFDT
I $D(^XTMP(ORGLOB,ORRTN)) D
.I ORSCH="DAILY" D ;check if ORRTN has been called today
..N ORCALL S ORCALL=$G(^XTMP(ORGLOB,ORRTN),0)
..N ORCALLDT S ORCALLDT=$P(ORCALL,".",1)
..I ORCALLDT=DT S ORRET=0
;
I ORRET S ^XTMP(ORGLOB,ORRTN)=$$NOW^XLFDT
Q ORRET
NIGHTLY ;nightly task to generate smart alerts
N ORNOW
S ORNOW=DT
I ORNOW>$P($G(^XTMP("ORBSMART GENERATE",0)),U,2) D
. D GENERATE
. S ^XTMP("ORBSMART GENERATE",0)=$$FMADD^XLFDT(ORNOW,1)_U_ORNOW_"SMART ALERT GENERATION"
Q
;
SMINSTDT() ;get SMART install date
N ORRSLT,ORNUM,ORY
S ORY=0,ORNUM=$$INSTALDT^XPDUTL("OR*3.0*377",.ORRSLT)
I ORNUM>0 S ORY=+$O(ORRSLT("?"),-1)
Q ORY
;
SMARTON(USER,NOTIEN) ;
N TMP,RESULT
S RESULT=0
I $$GET^XPAR("ALL","ORB PROCESSING FLAG","`"_NOTIEN,"Q")="E" S RESULT=1
Q RESULT
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HORBSMART 7512 printed Oct 16, 2024@18:28:17 Page 2
ORBSMART ;SLC/JMH - SMART NOTIFICATIONS; Oct 4, 2022@11:23
+1 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**377,498,593**;Dec 17, 1997;Build 6
+2 ;
+3 ; Reference to EN^PXRMGEV in ICR #6772
+4 ; Reference to ALERTDAT^XQALBUTL in ICR #2788
+5 ; Reference to GETUSER1^XQALDATA in ICR #4834
+6 ; Reference to GETPAT2^XQALDATA in ICR #4834
+7 ;
INSMALRT(ORY,ORAID) ;set what alert is being processed for smart
+1 SET ^TMP("ORSMART CURRENT ALERT",$JOB)=ORAID
+2 QUIT
+3 ;
OUSMALRT(ORY,ORAID) ;clear what alert is being processed for smart
+1 KILL ^TMP("ORSMART CURRENT ALERT",$JOB)
+2 QUIT
+3 ;
EN(ORY,ORDATA) ;
+1 NEW DATA
+2 IF $DATA(ORDATA("DATA",100.9))
Begin DoDot:1
+3 DO CLEAR(.ORY,.ORDATA)
+4 SET ORY(1)=1
End DoDot:1
+5 IF $DATA(ORDATA("DATA",100.97))
Begin DoDot:1
+6 SET DATA("PATIENT")=ORDATA("DFN")
+7 SET DATA("TITLE")=$GET(ORDATA("DATA",100.97,"+1,",5))
+8 SET DATA("WHO")=DUZ
+9 SET DATA("WHEN")=$GET(ORDATA("DATA",100.97,"+1,",2))
+10 SET DATA("BODY",1)=$GET(ORDATA("DATA",100.97,"+1,",6))
+11 DO SCHALRT^ORB3UTL(.DATA)
+12 SET ORY(1)=1
End DoDot:1
+13 QUIT
+14 ;
CLEAR(ORY,ORDATA) ;Clear SMART alert
+1 SET ORY(1)=1
+2 ;
+3 NEW ACTION,ISDEFER,ORBY,ORINPUT,ORNOTIEN,ORDFN,ORRESULT,STATUS,ORXDATA
+4 ;ORNOTIEN=84;85
+5 SET ORDFN=ORDATA("DFN")
+6 ;S ORNOTIEN=$G(ORDATA("DATA",100.9,"+1,",.01))
+7 ;S ISDEFER=$G(ORDATA("DATA",100.9,"+1,","DATE"))
+8 ;ACTION=CLEAR PROVIDER (ALL INSTANCE OF NOT IEN FOR CURRENT USER)
+9 ;ACTION=CLEAR ALL (ALL INSTANCE OF NOT IEN FOR ALL USER)
+10 ;ACTION=CLEAR ONE (CLEAR ONLY THIS ALERT XQAID)
+11 ;ACTION="REEVALUATE REMINDER BEFORE CLEAR"
+12 ;S ACTION=$G(ORDATA("DATA",100.9,"+1,","ACTION"))
+13 ;see if there is a data piece we should match for delete
+14 SET ORXDATA=$GET(ORDATA("DATA",100.9,"MASTER ID"))
+15 IF ORXDATA=""
SET ORXDATA="+1,"
+16 SET ACTION=$GET(ORDATA("DATA",100.9,ORXDATA,"ACTION"))
+17 SET ORNOTIEN=$GET(ORDATA("DATA",100.9,ORXDATA,.01))
+18 IF ACTION="CLEAR PROVIDER"
DO CLRPROV(ORNOTIEN,ORDFN)
+19 IF ACTION="CLEAR ALL"
DO CLRALL(ORNOTIEN,ORDFN)
+20 IF ACTION="CLEAR ONE"
DO CLRONE(ORXDATA)
+21 QUIT
+22 ;
CLRPROV(ORNOT,ORDFN) ;clear all alerts for notification ORNOT for patient ORDFN for the current user DUZ
+1 NEW ORPALERTS,ORI,ORNOTX,ORBY
+2 DO PALERTS(ORDFN,"ORPALERTS")
+3 if '$DATA(ORPALERTS)
QUIT
+4 SET ORI=0
SET ORNOTX=""
FOR
SET ORI=ORI+1
SET ORNOTX=$PIECE(ORNOT,";",ORI)
if '$LENGTH(ORNOTX)
QUIT
Begin DoDot:1
+5 NEW ORJ
SET ORJ=0
FOR
SET ORJ=$ORDER(ORPALERTS(ORNOTX,ORJ))
if $LENGTH(ORJ)<1
QUIT
Begin DoDot:2
+6 KILL ORBY
DO DEL^ORB3FUP1(.ORBY,ORJ,1)
End DoDot:2
End DoDot:1
+7 QUIT
+8 ;
CLRALL(ORNOT,ORDFN) ;clear all alerts for notification ORNOT for patient ORDFN for all users
+1 NEW ORPALERTS,ORI,ORNOTX,ORBY
+2 DO PALERTS(ORDFN,"ORPALERTS")
+3 if '$DATA(ORPALERTS)
QUIT
+4 SET ORI=0
SET ORNOTX=""
FOR
SET ORI=ORI+1
SET ORNOTX=$PIECE(ORNOT,";",ORI)
if '$LENGTH(ORNOTX)
QUIT
Begin DoDot:1
+5 NEW ORJ
SET ORJ=0
FOR
SET ORJ=$ORDER(ORPALERTS(ORNOTX,ORJ))
if $LENGTH(ORJ)<1
QUIT
Begin DoDot:2
+6 KILL ORBY
DO DEL^ORB3FUP1(.ORBY,ORJ,0)
End DoDot:2
End DoDot:1
+7 QUIT
+8 ;
CLRONE(ORDATA) ;clear only the alert matching ORDATA
+1 NEW ORBY
+2 DO DEL^ORB3FUP1(.ORBY,ORDATA,0)
+3 QUIT
+4 ;
+5 ;REM(PAT,NAME) ;
+6 ;N DEFARR,FIEVAL,NODE,RIEN,RNAME,RSTAT
+7 ;S RIEN=$O(^PXD(811.9,"B",NAME,"")) I +RIEN=0 Q 0
+8 ;S NODE=$G(^PXD(811.9,RIEN,0))
+9 ;S RNAME=$S($P(NODE,U,3)'="":$P(NODE,U,3),1:$P(NODE,U))
+10 ;D DEF^PXRMLDR(RIEN,.DEFARR)
+11 ;K FIEVAL
+12 ;D EVAL^PXRM(PAT,.DEFARR,5,1,.FIEVAL,DT)
+13 ;S RSTAT=$P($G(^TMP("PXRHM",$J,RIEN,RNAME)),U)
+14 ;Q RSTAT
+15 ;
SMALERTS(ORDFN,ORDUZ,ORGLOB) ;
+1 NEW ORY
+2 KILL @ORGLOB
+3 DO GETUSER1^XQALDATA("ORY",ORDUZ)
+4 NEW ORI
SET ORI=0
FOR
SET ORI=$ORDER(ORY(ORI))
if 'ORI
QUIT
Begin DoDot:1
+5 if ($PIECE($PIECE(ORY(ORI),U,2),",",2)'=ORDFN)
QUIT
+6 IF $GET(ORALL)!($$ISSMIEN($PIECE($PIECE($PIECE(ORY(ORI),U,2),",",3),";")))
Begin DoDot:2
+7 NEW ORBDATA
DO GETDATA^ORWORB(.ORBDATA,$PIECE(ORY(ORI),U,2))
+8 SET @ORGLOB@($PIECE($PIECE($PIECE(ORY(ORI),U,2),",",3),";"),$PIECE(ORY(ORI),U,2),"DATA")=ORBDATA
+9 NEW ORBD2
DO ALERTDAT^XQALBUTL($PIECE(ORY(ORI),U,2),"ORBD2")
+10 SET @ORGLOB@($PIECE($PIECE($PIECE(ORY(ORI),U,2),",",3),";"),$PIECE(ORY(ORI),U,2),"DATE")=$GET(ORBD2(.02))
End DoDot:2
End DoDot:1
+11 QUIT
+12 ;
PALERTS(ORDFN,ORGLOB) ;
+1 NEW ORY
+2 KILL @ORGLOB
+3 DO GETPAT2^XQALDATA("ORY",ORDFN,1,1000)
+4 NEW ORI
SET ORI=0
FOR
SET ORI=$ORDER(ORY(ORI))
if 'ORI
QUIT
Begin DoDot:1
+5 if ($PIECE($PIECE(ORY(ORI),U,2),",",2)'=ORDFN)
QUIT
+6 IF $GET(ORALL)!($$ISSMIEN($PIECE($PIECE($PIECE(ORY(ORI),U,2),",",3),";")))
Begin DoDot:2
+7 SET @ORGLOB@($PIECE($PIECE($PIECE(ORY(ORI),U,2),",",3),";"),$PIECE(ORY(ORI),U,2))=""
End DoDot:2
End DoDot:1
+8 QUIT
+9 ;
UHASNOT(ORDFN,ORDUZ,ORNOT) ; returns 1 if user ORDUZ has notification ORNOT for patient ORDFN
+1 NEW ORRET,ORALERTS,ORI
+2 SET ORRET=0
+3 DO SMALERTS(ORDFN,ORDUZ,"ORALERTS")
+4 IF $DATA(ORALERTS(ORNOT))
SET ORRET=1
+5 QUIT ORRET
+6 ;
PHASNOT(ORDFN,ORNOT) ; returns 1 patient ORDUZ has a notification ORNOT
+1 NEW ORRET,ORALERTS,ORI
+2 SET ORRET=0
+3 DO PALERTS(ORDFN,"ORALERTS")
+4 IF $DATA(ORALERTS(ORNOT))
SET ORRET=1
+5 QUIT ORRET
+6 ;
SMIENS(ORY) ;
+1 NEW I
+2 SET I=0
+3 FOR
SET I=$ORDER(^ORD(100.9,I))
if 'I
QUIT
Begin DoDot:1
+4 IF +$GET(^ORD(100.9,I,6))
SET ORY(I)=1
End DoDot:1
+5 QUIT
+6 ;
ISSMIEN(ORIEN) ;
+1 IF +$GET(^ORD(100.9,ORIEN,6))
QUIT 1
+2 QUIT 0
+3 ;
ISSMNOT(ORY,ORIEN) ;
+1 SET ORY=$$ISSMIEN(ORIEN)
+2 QUIT
NCIMGNOT(ORDFN) ;Fire SMART NON-CRITICAL IMAGING RES alert
+1 NEW ORNOTNM,ORNOTIEN
+2 SET ORNOTNM="SMART NON-CRITICAL IMAGING RES"
+3 SET ORNOTIEN=$$GETNOTID(ORNOTNM)
+4 IF '$$PHASNOT(ORDFN,ORNOTIEN)
DO EN^ORB3(ORNOTIEN,ORDFN,"","","","SMART,")
+5 QUIT
+6 ;
GETRMLST(ORLST,ORLNM,OVER,RETDATA) ;Get a list of patients from Reminder call
+1 NEW ORRMIN,ORY,ORTNM
+2 SET ORTNM="ORRM LIST"
+3 KILL ^TMP($JOB,ORTNM)
+4 SET ORRMIN("SUB")=ORTNM
+5 SET ORRMIN("LR",ORLNM)=ORLNM_U_DT_U_DT_U_0_U_$GET(OVER,1)_U_RETDATA
+6 DO EN^PXRMGEV(.ORY,.ORRMIN)
+7 NEW ORI
SET ORI=0
FOR
SET ORI=$ORDER(^TMP($JOB,ORTNM,ORLNM,ORI))
if 'ORI
QUIT
Begin DoDot:1
+8 SET ORLST(ORI)=""
+9 IF RETDATA
MERGE ORLST(ORI,"DATA")=^TMP($JOB,ORTNM,ORLNM,ORI,"DATA")
End DoDot:1
+10 KILL ^TMP($JOB,ORTNM)
+11 QUIT
+12 ;
HOOK(ORN,ORBDFN,ORNUM,ORBADUZ,ORBPMSG,ORBPDATA) ;
+1 NEW ORRET,ORI,USER,SMARARR
SET (ORRET,ORI)=0
+2 FOR
SET ORI=$ORDER(^ORD(100.9,"E",ORN,ORI))
if 'ORI
QUIT
Begin DoDot:1
+3 NEW ORJ
SET ORJ=$ORDER(^ORD(100.9,"E",ORN,ORI,""))
if 'ORJ
QUIT
+4 ;get DEPENDENT LOGIC. If no logic then go ahead with replacement. otherwise run logic to determine if should replace
+5 NEW ORLOG
SET ORLOG=$GET(^ORD(100.9,ORI,7,ORJ,1))
+6 NEW ORFIRE,ORNEWMSG
SET ORFIRE=1
SET ORNEWMSG=$GET(ORBPMSG)
+7 ; if ORLOG code is set run it and it will set ORFIRE to either 0 or 1
IF $LENGTH(ORLOG)
XECUTE ORLOG
+8 IF ORFIRE
Begin DoDot:2
+9 SET USER=0
FOR
SET USER=$ORDER(ORBADUZ(USER))
if USER'>0
QUIT
Begin DoDot:3
+10 IF $$SMARTON(USER,ORI)
SET SMARARR(USER)=""
End DoDot:3
+11 SET USER=0
FOR
SET USER=$ORDER(SMARARR(USER))
if USER'>0
QUIT
Begin DoDot:3
+12 KILL ORBADUZ(USER)
End DoDot:3
+13 DO EN^ORB3(ORI,ORBDFN,$GET(ORNUM),.SMARARR,$GET(ORNEWMSG),$GET(ORBPDATA))
+14 ;W !,"FIRING ",ORI," IN PLACE OF ",ORN," FOR MESSAGE '",ORBPMSG,"'"
+15 IF $PIECE($GET(^ORD(100.9,ORI,7,ORJ,0)),U,2)="1"
IF '$DATA(ORBADUZ)
SET ORRET=1
End DoDot:2
End DoDot:1
+16 QUIT ORRET
+17 ;
GETNOTID(ORNOTNM) ;Get the OE/RR NOTIFICATIONS File IEN for the notification name
+1 IF '$LENGTH(ORNOTNM)
QUIT ""
+2 QUIT $ORDER(^ORD(100.9,"B",ORNOTNM,0))
+3 ;
GENERATE ;generate the smart alerts
+1 ;I $$SCHCALL("XBIMGPND^ORBSMART","DAILY") D XBIMGPND
+2 QUIT
+3 ;
SCHCALL(ORRTN,ORSCH) ;Return 1 if ORRTN should be run now, 0 if not.
+1 ;Based on the schedule passed in ORSCH
+2 ;if it returns 1 it will set a log that the call is made also
+3 NEW ORGLOB,ORRET
+4 SET ORGLOB="OR SCHCALL"
SET ORRET=1
+5 SET ^XTMP(ORGLOB,0)=$$FMADD^XLFDT($$NOW^XLFDT,60)_U_$$NOW^XLFDT
+6 IF $DATA(^XTMP(ORGLOB,ORRTN))
Begin DoDot:1
+7 ;check if ORRTN has been called today
IF ORSCH="DAILY"
Begin DoDot:2
+8 NEW ORCALL
SET ORCALL=$GET(^XTMP(ORGLOB,ORRTN),0)
+9 NEW ORCALLDT
SET ORCALLDT=$PIECE(ORCALL,".",1)
+10 IF ORCALLDT=DT
SET ORRET=0
End DoDot:2
End DoDot:1
+11 ;
+12 IF ORRET
SET ^XTMP(ORGLOB,ORRTN)=$$NOW^XLFDT
+13 QUIT ORRET
NIGHTLY ;nightly task to generate smart alerts
+1 NEW ORNOW
+2 SET ORNOW=DT
+3 IF ORNOW>$PIECE($GET(^XTMP("ORBSMART GENERATE",0)),U,2)
Begin DoDot:1
+4 DO GENERATE
+5 SET ^XTMP("ORBSMART GENERATE",0)=$$FMADD^XLFDT(ORNOW,1)_U_ORNOW_"SMART ALERT GENERATION"
End DoDot:1
+6 QUIT
+7 ;
SMINSTDT() ;get SMART install date
+1 NEW ORRSLT,ORNUM,ORY
+2 SET ORY=0
SET ORNUM=$$INSTALDT^XPDUTL("OR*3.0*377",.ORRSLT)
+3 IF ORNUM>0
SET ORY=+$ORDER(ORRSLT("?"),-1)
+4 QUIT ORY
+5 ;
SMARTON(USER,NOTIEN) ;
+1 NEW TMP,RESULT
+2 SET RESULT=0
+3 IF $$GET^XPAR("ALL","ORB PROCESSING FLAG","`"_NOTIEN,"Q")="E"
SET RESULT=1
+4 QUIT RESULT
+5 ;