MAGDAUDR ;WOIFO/EdM - RPC to fetch a Audit Info ; 03/17/2003  10:30
 ;;3.0;IMAGING;**11**;14-April-2004
 ;; +---------------------------------------------------------------+
 ;; | Property of the US Government.                                |
 ;; | No permission to copy or redistribute this software is given. |
 ;; | Use of unreleased versions of this software requires the user |
 ;; | to execute a written test agreement with the VistA Imaging    |
 ;; | Development Office of the Department of Veterans Affairs,     |
 ;; | telephone (301) 734-0100.                                     |
 ;; |                                                               |
 ;; | The Food and Drug Administration classifies this software as  |
 ;; | a medical device.  As such, it may not be changed in any way. |
 ;; | Modifications to this software may result in an adulterated   |
 ;; | medical device under 21CFR820, the use of which is considered |
 ;; | to be a violation of US Federal Statutes.                     |
 ;; +---------------------------------------------------------------+
 ;;
 Q
 ;
GET1(OUT,LOCATION,TODAY) ; Get the numbers of text-messages per day per purpose
 N COUNT,D2,DATE,I,MSG,N,X
 D:'$D(DT) DT^DICRW
 K OUT S (OUT(0),N)=0,I=100
 S TODAY=+$G(TODAY),DATE=DT
 D:TODAY  I 'TODAY S DATE=0 F  S DATE=$O(^MAGDAUDT(2006.5761,DATE)) Q:'DATE  D
 . Q:'$D(^MAGDAUDT(2006.5761,DATE,1,LOCATION))
 . ; Retrieve one day's statistics
 . S MSG="" F  S MSG=$O(^MAGDAUDT(2006.5761,DATE,1,LOCATION,1,"B",MSG)) Q:MSG=""  D
 . . S D2=$O(^MAGDAUDT(2006.5761,DATE,1,LOCATION,1,"B",MSG,"")) Q:'D2
 . . S X=$G(^MAGDAUDT(2006.5761,DATE,1,LOCATION,1,D2,0))
 . . S COUNT=$P(X,"^",2) Q:'COUNT
 . . S LAST=$P(X,"^",3)
 . . S I=I+1,N=N+1,OUT(I)=DATE_"^"_COUNT_"^"_MSG_"^"_LAST,MSG(MSG)=""
 . . Q
 . Q
 S I=0,MSG="" F  S MSG=$O(MSG(MSG)) Q:MSG=""  D
 . S I=I+1,N=N+1,OUT(I)="^^"_MSG
 . Q
 S OUT(0)=N
 Q
 ;
GET2(OUT,LOCATION,START,STOP) ; Get the numbers of messages per day per instrument
 N COUNT,D2,DATE,I,INSTR,N,X
 D:'$D(DT) DT^DICRW
 K OUT S (OUT(0),N)=0,I=100
 S START=+$G(START)-1,STOP=+$G(STOP)
 S:START<0 START=0
 S:'STOP STOP=9999999
 S DATE=START F  S DATE=$O(^MAGDAUDT(2006.5762,DATE)) Q:'DATE  Q:DATE>STOP  D
 . Q:'$D(^MAGDAUDT(2006.5762,DATE,1,LOCATION))
 . ; Retrieve one day's statistics
 . S INSTR="" F  S INSTR=$O(^MAGDAUDT(2006.5762,DATE,1,LOCATION,1,"B",INSTR)) Q:INSTR=""  D
 . . S D2=$O(^MAGDAUDT(2006.5762,DATE,1,LOCATION,1,"B",INSTR,"")) Q:'D2
 . . S X=$G(^MAGDAUDT(2006.5762,DATE,1,LOCATION,1,D2,0))
 . . S COUNT=$P(X,"^",2) S:$P(X,"^",4)>COUNT COUNT=$P(X,"^",4)
 . . Q:'COUNT
 . . S INSTR(INSTR)=""
 . . S I=I+1,N=N+1,OUT(I)=DATE_"^"_$P(X,"^",2)_"^"_INSTR_"^"_$P(X,"^",3,5)
 . . Q
 . Q
 S I=0,INSTR="" F  S INSTR=$O(INSTR(INSTR)) Q:INSTR=""  D
 . S I=I+1,N=N+1,OUT(I)="^^"_INSTR
 . Q
 S OUT(0)=N
 Q
 ;
RANGE(OUT) ; Get the date-ranges for the various audit files
 N DF,DL,FM,N
 K OUT S N=0
 F FM=2006.5761,2006.5762 D
 . S DF=$O(^MAGDAUDT(FM,0)) S:'DF DF=""
 . S DL=$O(^MAGDAUDT(FM," "),-1) S:'DL DL=""
 . S N=N+1,OUT(N)=FM_"^"_DF_"^"_DL
 . Q
 S N=N+1,OUT(N)="-END-"
 Q
 ;
PURGE(OUT,FM,DATE) ; Purge Audit FIle
 N D0,DATE,DAYS,X
 L +^MAGDAUDT(FM)
 S DAYS=$P($G(^MAGDAUDT(FM,0)),"^",4),OUT=0
 S X=0 F  S X=$O(^MAGDAUDT(FM,X)) Q:'X  Q:X'<DATE  D
 . K ^MAGDAUDT(FM,X)
 . S DAYS=DAYS-1,OUT=OUT+1
 . Q
 S:DAYS<1 DAYS=0
 S $P(^MAGDAUDT(FM,0),"^",4)=DAYS
 L -^MAGDAUDT(FM)
 S OUT=OUT_" day"_$S(OUT=1:"",1:"s")_" purged."
 Q
 ;
COUNT(OUT,LOCATION,MESSAGE) ; update today's count
 N %,D2,%H,%I,TODAY,NOW,X
 I '$G(LOCATION) S OUT="-1,No Location Specified" Q
 I $G(MESSAGE)="" S OUT="-2,No Message Specified" Q
 ;
 D NOW^%DTC S TODAY=X,NOW=%
 S D2=$O(^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,"B",MESSAGE,""))
 D:'D2
 . L +^MAGDAUDT(2006.5761,TODAY)
 . S D2=$O(^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1," "),-1)+1
 . S X=$G(^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,0))
 . S $P(X,"^",2)="2006.576111"
 . S $P(X,"^",3)=D2
 . S $P(X,"^",4)=$P(X,"^",4)+1
 . S ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,0)=LOCATION
 . S ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,0)=X
 . S ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,D2,0)=MESSAGE
 . S ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,"B",MESSAGE,D2)=""
 . L -^MAGDAUDT(2006.5761,TODAY)
 . Q
 S X=$G(^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,D2,0))
 S X=MESSAGE_"^"_($P(X,"^",2)+1)_"^"_NOW
 S ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,D2,0)=X
 S OUT=$P(X,"^",2)
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGDAUDR   4491     printed  Sep 23, 2025@19:35:54                                                                                                                                                                                                    Page 2
MAGDAUDR  ;WOIFO/EdM - RPC to fetch a Audit Info ; 03/17/2003  10:30
 +1       ;;3.0;IMAGING;**11**;14-April-2004
 +2       ;; +---------------------------------------------------------------+
 +3       ;; | Property of the US Government.                                |
 +4       ;; | No permission to copy or redistribute this software is given. |
 +5       ;; | Use of unreleased versions of this software requires the user |
 +6       ;; | to execute a written test agreement with the VistA Imaging    |
 +7       ;; | Development Office of the Department of Veterans Affairs,     |
 +8       ;; | telephone (301) 734-0100.                                     |
 +9       ;; |                                                               |
 +10      ;; | The Food and Drug Administration classifies this software as  |
 +11      ;; | a medical device.  As such, it may not be changed in any way. |
 +12      ;; | Modifications to this software may result in an adulterated   |
 +13      ;; | medical device under 21CFR820, the use of which is considered |
 +14      ;; | to be a violation of US Federal Statutes.                     |
 +15      ;; +---------------------------------------------------------------+
 +16      ;;
 +17       QUIT 
 +18      ;
GET1(OUT,LOCATION,TODAY) ; Get the numbers of text-messages per day per purpose
 +1        NEW COUNT,D2,DATE,I,MSG,N,X
 +2        if '$DATA(DT)
               DO DT^DICRW
 +3        KILL OUT
           SET (OUT(0),N)=0
           SET I=100
 +4        SET TODAY=+$GET(TODAY)
           SET DATE=DT
 +5        if TODAY
               Begin DoDot:1
 +6                if '$DATA(^MAGDAUDT(2006.5761,DATE,1,LOCATION))
                       QUIT 
 +7       ; Retrieve one day's statistics
 +8                SET MSG=""
                   FOR 
                       SET MSG=$ORDER(^MAGDAUDT(2006.5761,DATE,1,LOCATION,1,"B",MSG))
                       if MSG=""
                           QUIT 
                       Begin DoDot:2
 +9                        SET D2=$ORDER(^MAGDAUDT(2006.5761,DATE,1,LOCATION,1,"B",MSG,""))
                           if 'D2
                               QUIT 
 +10                       SET X=$GET(^MAGDAUDT(2006.5761,DATE,1,LOCATION,1,D2,0))
 +11                       SET COUNT=$PIECE(X,"^",2)
                           if 'COUNT
                               QUIT 
 +12                       SET LAST=$PIECE(X,"^",3)
 +13                       SET I=I+1
                           SET N=N+1
                           SET OUT(I)=DATE_"^"_COUNT_"^"_MSG_"^"_LAST
                           SET MSG(MSG)=""
 +14                       QUIT 
                       End DoDot:2
 +15               QUIT 
               End DoDot:1
           IF 'TODAY
               SET DATE=0
               FOR 
                   SET DATE=$ORDER(^MAGDAUDT(2006.5761,DATE))
                   if 'DATE
                       QUIT 
                   Begin DoDot:1
                   End DoDot:1
 +16       SET I=0
           SET MSG=""
           FOR 
               SET MSG=$ORDER(MSG(MSG))
               if MSG=""
                   QUIT 
               Begin DoDot:1
 +17               SET I=I+1
                   SET N=N+1
                   SET OUT(I)="^^"_MSG
 +18               QUIT 
               End DoDot:1
 +19       SET OUT(0)=N
 +20       QUIT 
 +21      ;
GET2(OUT,LOCATION,START,STOP) ; Get the numbers of messages per day per instrument
 +1        NEW COUNT,D2,DATE,I,INSTR,N,X
 +2        if '$DATA(DT)
               DO DT^DICRW
 +3        KILL OUT
           SET (OUT(0),N)=0
           SET I=100
 +4        SET START=+$GET(START)-1
           SET STOP=+$GET(STOP)
 +5        if START<0
               SET START=0
 +6        if 'STOP
               SET STOP=9999999
 +7        SET DATE=START
           FOR 
               SET DATE=$ORDER(^MAGDAUDT(2006.5762,DATE))
               if 'DATE
                   QUIT 
               if DATE>STOP
                   QUIT 
               Begin DoDot:1
 +8                if '$DATA(^MAGDAUDT(2006.5762,DATE,1,LOCATION))
                       QUIT 
 +9       ; Retrieve one day's statistics
 +10               SET INSTR=""
                   FOR 
                       SET INSTR=$ORDER(^MAGDAUDT(2006.5762,DATE,1,LOCATION,1,"B",INSTR))
                       if INSTR=""
                           QUIT 
                       Begin DoDot:2
 +11                       SET D2=$ORDER(^MAGDAUDT(2006.5762,DATE,1,LOCATION,1,"B",INSTR,""))
                           if 'D2
                               QUIT 
 +12                       SET X=$GET(^MAGDAUDT(2006.5762,DATE,1,LOCATION,1,D2,0))
 +13                       SET COUNT=$PIECE(X,"^",2)
                           if $PIECE(X,"^",4)>COUNT
                               SET COUNT=$PIECE(X,"^",4)
 +14                       if 'COUNT
                               QUIT 
 +15                       SET INSTR(INSTR)=""
 +16                       SET I=I+1
                           SET N=N+1
                           SET OUT(I)=DATE_"^"_$PIECE(X,"^",2)_"^"_INSTR_"^"_$PIECE(X,"^",3,5)
 +17                       QUIT 
                       End DoDot:2
 +18               QUIT 
               End DoDot:1
 +19       SET I=0
           SET INSTR=""
           FOR 
               SET INSTR=$ORDER(INSTR(INSTR))
               if INSTR=""
                   QUIT 
               Begin DoDot:1
 +20               SET I=I+1
                   SET N=N+1
                   SET OUT(I)="^^"_INSTR
 +21               QUIT 
               End DoDot:1
 +22       SET OUT(0)=N
 +23       QUIT 
 +24      ;
RANGE(OUT) ; Get the date-ranges for the various audit files
 +1        NEW DF,DL,FM,N
 +2        KILL OUT
           SET N=0
 +3        FOR FM=2006.5761,2006.5762
               Begin DoDot:1
 +4                SET DF=$ORDER(^MAGDAUDT(FM,0))
                   if 'DF
                       SET DF=""
 +5                SET DL=$ORDER(^MAGDAUDT(FM," "),-1)
                   if 'DL
                       SET DL=""
 +6                SET N=N+1
                   SET OUT(N)=FM_"^"_DF_"^"_DL
 +7                QUIT 
               End DoDot:1
 +8        SET N=N+1
           SET OUT(N)="-END-"
 +9        QUIT 
 +10      ;
PURGE(OUT,FM,DATE) ; Purge Audit FIle
 +1        NEW D0,DATE,DAYS,X
 +2        LOCK +^MAGDAUDT(FM)
 +3        SET DAYS=$PIECE($GET(^MAGDAUDT(FM,0)),"^",4)
           SET OUT=0
 +4        SET X=0
           FOR 
               SET X=$ORDER(^MAGDAUDT(FM,X))
               if 'X
                   QUIT 
               if X'<DATE
                   QUIT 
               Begin DoDot:1
 +5                KILL ^MAGDAUDT(FM,X)
 +6                SET DAYS=DAYS-1
                   SET OUT=OUT+1
 +7                QUIT 
               End DoDot:1
 +8        if DAYS<1
               SET DAYS=0
 +9        SET $PIECE(^MAGDAUDT(FM,0),"^",4)=DAYS
 +10       LOCK -^MAGDAUDT(FM)
 +11       SET OUT=OUT_" day"_$SELECT(OUT=1:"",1:"s")_" purged."
 +12       QUIT 
 +13      ;
COUNT(OUT,LOCATION,MESSAGE) ; update today's count
 +1        NEW %,D2,%H,%I,TODAY,NOW,X
 +2        IF '$GET(LOCATION)
               SET OUT="-1,No Location Specified"
               QUIT 
 +3        IF $GET(MESSAGE)=""
               SET OUT="-2,No Message Specified"
               QUIT 
 +4       ;
 +5        DO NOW^%DTC
           SET TODAY=X
           SET NOW=%
 +6        SET D2=$ORDER(^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,"B",MESSAGE,""))
 +7        if 'D2
               Begin DoDot:1
 +8                LOCK +^MAGDAUDT(2006.5761,TODAY)
 +9                SET D2=$ORDER(^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1," "),-1)+1
 +10               SET X=$GET(^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,0))
 +11               SET $PIECE(X,"^",2)="2006.576111"
 +12               SET $PIECE(X,"^",3)=D2
 +13               SET $PIECE(X,"^",4)=$PIECE(X,"^",4)+1
 +14               SET ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,0)=LOCATION
 +15               SET ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,0)=X
 +16               SET ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,D2,0)=MESSAGE
 +17               SET ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,"B",MESSAGE,D2)=""
 +18               LOCK -^MAGDAUDT(2006.5761,TODAY)
 +19               QUIT 
               End DoDot:1
 +20       SET X=$GET(^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,D2,0))
 +21       SET X=MESSAGE_"^"_($PIECE(X,"^",2)+1)_"^"_NOW
 +22       SET ^MAGDAUDT(2006.5761,TODAY,1,LOCATION,1,D2,0)=X
 +23       SET OUT=$PIECE(X,"^",2)
 +24       QUIT