MAGVAG04 ;WOIFO/NST - Utilities for RPC calls ; 13 Feb 2012 4:21 PM
 ;;3.0;IMAGING;**118**;Mar 19, 2002;Build 4525;May 01, 2013
 ;; Per VHA Directive 2004-038, this routine should not be modified.
 ;; +---------------------------------------------------------------+
 ;; | 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
 ;
 ;*****  Get artifact values with key list from ARTIFACT file (#2006.916)
 ;       ARTIFACT KEYLIST file (#2006.913) and ARTIFACT INSTANCE file (#2006.918)
 ;       and Artifact Retention Policies (#2006.921)
 ;       and Artifact Retention Policies Fulfillment (#2006.922)
 ;       by IEN
 ;       
 ; Input Parameters
 ; ================
 ; 
 ; IEN = Artifact IEN
 ; CNT = populate MAGRY starting with node CNT 
 ; FLAGS = To identify the type of detail to return
 ; 
 ;        I = Include Artifact Instance records
 ;        R = Include Artifact Retention Policies 
 ;            and Artifact Retention Policies Fulfillment
 ;  
 ; Return Values
 ; =============
 ; if error MAGRY(0) = Failure status ^ Error message^
 ; if success MAGRY(0) = Success status
 ;            MAGRY(1..n) XML based result in format
 ;              <artifact
 ;                id=""
 ;                token=""
 ;                size=""
 ;                keyListFK=""
 ;                createdDateTime=""
 ;                lastAccessDateTime=""
 ;                crc="">
 ;                <keys>
 ;                  <key kvalue="" klevel="" />
 ;                   ...
 ;                  <key kvalue="" klevel="" />
 ;                </keys>
 ;               <artifact Instances>
 ;                <artifact Instance>
 ;                ....
 ;                <artifact Instance>
 ;                </artifact Instances>
 ;                <artifact Retention policy>
 ;                 <artifact Retention policy fulfillments>
 ;                   <artifact Retention policy fulfillment>
 ;                   ...
 ;                   <artifact Retention policy fulfillment>
 ;                   ...
 ;                 </artifact Retention policy fulfillments>
 ;                </artifact Retention policy>                
 ;              </artifact>              
 ;  
GAFTBYID(MAGRY,IEN,CNT,FLAGS) ; 
 K MAGRY
 I IEN="" S MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"IEN is required." Q
 ; 
 N I,X,OUT,ERR,MAGRESA
 N FILE,FILENM,FLDFKID
 N IENS
 N FLDSARR,FLDSARRW,FIELDS
 N KLFILE,KLFKID,KEYS,KLFLDID,KLIEN
 N TMPARR
 N QT
 S QT=$C(34) ; "
 S FILE=2006.916     ; ARTIFACT file number
 S FILENM=$TR($$GETFILNM^MAGVAF01(FILE)," ")  ; File name without blanks
 S FIELDS=$$GETFLDS^MAGVAF01(.FLDSARR,.FLDSARRW,FILE) ; ARTIFACT file fields names
 S FLDFKID=$$GETFLDID^MAGVAF01(FILE,"KEYLIST")  ; KEYLIST field number 
 ;
 S IENS=IEN_","
 D GETS^DIQ(FILE,IENS,FIELDS,"I","OUT","ERR")  ; get ARTIFACT record values
 I $D(ERR("DIERR")) D  Q
 . D MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
 . S MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting values: "_MAGRESA(1) Q  ; Error getting the values
 . Q
 ;
 S CNT=CNT+1,MAGRY(CNT)="<"_FILENM
 S CNT=CNT+1,MAGRY(CNT)="PK="_QT_IEN_QT
 S I=""
 F  S I=$O(OUT(FILE,IENS,I)) Q:I=""  D
 . I $$ISFLDDT^MAGVAF01(FILE,I) S X=$$FM2IDF^MAGVAF01(OUT(FILE,IENS,I,"I"))  ; the field is Date type - convert to IDF format
 . E  S X=OUT(FILE,IENS,I,"I")
 . S CNT=CNT+1,MAGRY(CNT)=$TR(FLDSARR(I)," /\<>&%")_"="_QT_X_QT  ; need to check for date format
 . Q
 S MAGRY(CNT)=MAGRY(CNT)_" >"
 ;
 ; Get the KEYLIST values
 S KLFILE=2006.913   ; KEYLIST file number
 S KLFLDID=$$GETFLDID^MAGVAF01(KLFILE,"KEY")  ; KEYLIST field number 
 ; KEYLIST is optional in ARTIFACT file (#2006.916) so check for blank
 S KLIEN=$S(OUT(FILE,IENS,FLDFKID,"I")="":"",1:OUT(FILE,IENS,FLDFKID,"I")_",")
 D GETMVAL^MAGVAF03(.KEYS,KLFILE,KLFLDID,OUT(FILE,IENS,FLDFKID,"I")_",") ; KEY LIST file KLFILE, field KEY KLFKID
 I '$$ISOK^MAGVAF02(KEYS(0)) D  Q  ; error found - quit 
 . K MAGRY
 . S MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting artifact " Q  ; Error getting the values
 . Q
 K KEYS(0)  ; delete zero node record - it is for information only
 S CNT=$$APP2ARR^MAGVAF04(.MAGRY,.KEYS)  ; Append KEYLIST to result
 ;
 K ERR,TMPARR
 S ERR=0
 I FLAGS["I" D  ; Get Artifact Instance 
 . D GETAINST^MAGVAG04(.TMPARR,IEN)
 . I '$$ISOK^MAGVAF02(TMPARR(0)) D
 . . K MAGRY
 . . S MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting artifact instance " ; Error getting the values
 . . S ERR=1
 . . Q
 . I ERR Q  ; error found - quit 
 . K TMPARR(0)  ; delete zero node record - it is for information only
 . S CNT=$$APP2ARR^MAGVAF04(.MAGRY,.TMPARR) ; Append Artifact instances to result
 . Q
 I ERR Q
 ;
 K ERR,TMPARR
 S ERR=0
 I FLAGS["R" D  ; Get Artifact Retention Policies & Artifact Retention Policies Fulfillment 
 . D GETARP^MAGVAG04(.TMPARR,IEN)
 . I '$$ISOK^MAGVAF02(TMPARR(0)) D
 . . K MAGRY
 . . S MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting artifact instance " ; Error getting the values
 . . S ERR=1
 . . Q
 . I ERR Q  ; error found - quit 
 . K TMPARR(0)  ; delete zero node record - it is for information only
 . S CNT=$$APP2ARR^MAGVAF04(.MAGRY,.TMPARR) ; Append Artifact Retention Policies  to result
 . Q
 I ERR Q
 ;
 S CNT=CNT+1,MAGRY(CNT)="</"_FILENM_">"
 S MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_CNT
 Q FILENM
 ;
 ; ----- Get Artifact Instance from ARTIFACT INSTANCE  file (#2006.918)
 ;       by Artifact IEN in XML based format
 ;       
 ; Input Parameters
 ; ================
 ; IEN = Artifact IEN
 ; 
 ; Return Values
 ; =============
 ; if error MAGRY(0) = Failure status ^ Error message^
 ; if success MAGRY(0) = Success status
 ; MAGRY(1..n) XML based result in format
 ;   <artifact Instances>
 ;     <artifact Instance>
 ;     ...
 ;     <artifact Instance>
 ;   </artifact Instances>
 ;
GETAINST(MAGRY,IEN) ;
 N FILE,IENS
 S FILE=2006.918
 S IENS=""
 D GXMLBYID^MAGVAF03(.MAGRY,FILE,IENS,IEN,1)
 Q
 ;
 ; ----- Get Artifact Retention Policy file (#2006.921)
 ;       & Artifact Retention Policy Fulfillment file (#2006.922)
 ;       by Artifact IEN in XML based format
 ;
 ; Input Parameters
 ; ================
 ; VAL = Artifact IEN
 ; 
 ; Return Values
 ; =============
 ; if error MAGRY(0) = Failure status ^ Error message^
 ; if success MAGRY(0) = Success status
 ;            MAGRY(1..n) XML based result in format
 ;            <artifactRetentionpolicys>
 ;             <artifactRetentionpolicy>
 ;              <artifactRetention policyfulfillments>
 ;                <artifactRetentionpolicyfulfillment>
 ;                   ...
 ;                <artifactRetentionpolicyfulfillment>
 ;                 ...
 ;               </artifactRetention policy fulfillments>
 ;             </artifactRetentionpolicy>
 ;             ...
 ;            <artifactRetentionpolicys>
 ; 
GETARP(MAGRY,VAL) ;
 N FILE,FIELDS,FLDSARR,FLDSARRW,FILENM
 N TMPARR,OUT,ERR,MAGRESA
 N I,J,X,IENS,ERRFLG,CNT
 N QT,RESDEL
 K MAGRY
 S RESDEL=$$RESDEL^MAGVAF02()
 S QT=$C(34) ; "
 S FILE=2006.921  ; Artifact Retention Policy
 S FILENM=$TR($$GETFILNM^MAGVAF01(FILE)," ") ; File name without blank
 S FIELDS=$$GETFLDS^MAGVAF01(.FLDSARR,.FLDSARRW,FILE,"I") ; file fields names
 S IENS=""
 D FIND^DIC(FILE,IENS,"@;"_FIELDS,"BQX",VAL,"","","","","OUT","ERR")
 I $D(ERR("DIERR")) D  Q
 . D MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
 . S MAGRY(0)=$$FAILED^MAGVAF02()_RESDEL_"Error getting values: "_MAGRESA(1) Q  ; Error getting the list
 . Q
 ; Output the data
 S CNT=0
 S CNT=CNT+1,MAGRY(CNT)="<"_FILENM_"S>"
 S I=""  ; IENs
 S J=""  ; Fields in the file
 S ERRFLG=0
 F  Q:ERRFLG  S I=$O(OUT("DILIST","ID",I)) Q:I=""  D
 . S CNT=CNT+1,MAGRY(CNT)="<"_FILENM
 . S CNT=CNT+1,MAGRY(CNT)="PK="_QT_OUT("DILIST",2,I)_QT
 . S J=""
 . F  S J=$O(OUT("DILIST","ID",I,J)) Q:J=""  D
 . . S X=OUT("DILIST","ID",I,J)
 . . I $$ISFLDDT^MAGVAF01(FILE,J) S X=$$FM2IDF^MAGVAF01(X)  ; the field is Date type - convert to IDF format
 . . S CNT=CNT+1,MAGRY(CNT)=$TR(FLDSARR(J)," /\<>&%")_"="_QT_X_QT
 . . Q
 . S MAGRY(CNT)=MAGRY(CNT)_" >"
 . ; Get Retention Policy Fulfillment
 . K TMPARR
 . D GXMLBYID^MAGVAF03(.TMPARR,2006.922,"",OUT("DILIST",2,I),1)
 . I '$$ISOK^MAGVAF02(TMPARR(0)) D  Q  ; error found - quit 
 . . K MAGRY
 . . S MAGRY(0)=$$FAILED^MAGVAF02()_RESDEL_"Error getting artifact " Q  ; Error getting the values
 . . S ERRFLG=1
 . . Q
 . K TMPARR(0)  ; delete zero node record - it is for information only
 . S CNT=$$APP2ARR^MAGVAF04(.MAGRY,.TMPARR)  ; Append Retention Policy Fulfillment to result
 . S CNT=CNT+1,MAGRY(CNT)="</"_FILENM_" >"
 . Q
 S CNT=CNT+1,MAGRY(CNT)="</"_FILENM_"S>"
 S MAGRY(0)=$$OK^MAGVAF02()_RESDEL_RESDEL_CNT
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGVAG04   9651     printed  Sep 23, 2025@19:45:42                                                                                                                                                                                                    Page 2
MAGVAG04  ;WOIFO/NST - Utilities for RPC calls ; 13 Feb 2012 4:21 PM
 +1       ;;3.0;IMAGING;**118**;Mar 19, 2002;Build 4525;May 01, 2013
 +2       ;; Per VHA Directive 2004-038, this routine should not be modified.
 +3       ;; +---------------------------------------------------------------+
 +4       ;; | Property of the US Government.                                |
 +5       ;; | No permission to copy or redistribute this software is given. |
 +6       ;; | Use of unreleased versions of this software requires the user |
 +7       ;; | to execute a written test agreement with the VistA Imaging    |
 +8       ;; | Development Office of the Department of Veterans Affairs,     |
 +9       ;; | telephone (301) 734-0100.                                     |
 +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      ;
 +19      ;*****  Get artifact values with key list from ARTIFACT file (#2006.916)
 +20      ;       ARTIFACT KEYLIST file (#2006.913) and ARTIFACT INSTANCE file (#2006.918)
 +21      ;       and Artifact Retention Policies (#2006.921)
 +22      ;       and Artifact Retention Policies Fulfillment (#2006.922)
 +23      ;       by IEN
 +24      ;       
 +25      ; Input Parameters
 +26      ; ================
 +27      ; 
 +28      ; IEN = Artifact IEN
 +29      ; CNT = populate MAGRY starting with node CNT 
 +30      ; FLAGS = To identify the type of detail to return
 +31      ; 
 +32      ;        I = Include Artifact Instance records
 +33      ;        R = Include Artifact Retention Policies 
 +34      ;            and Artifact Retention Policies Fulfillment
 +35      ;  
 +36      ; Return Values
 +37      ; =============
 +38      ; if error MAGRY(0) = Failure status ^ Error message^
 +39      ; if success MAGRY(0) = Success status
 +40      ;            MAGRY(1..n) XML based result in format
 +41      ;              <artifact
 +42      ;                id=""
 +43      ;                token=""
 +44      ;                size=""
 +45      ;                keyListFK=""
 +46      ;                createdDateTime=""
 +47      ;                lastAccessDateTime=""
 +48      ;                crc="">
 +49      ;                <keys>
 +50      ;                  <key kvalue="" klevel="" />
 +51      ;                   ...
 +52      ;                  <key kvalue="" klevel="" />
 +53      ;                </keys>
 +54      ;               <artifact Instances>
 +55      ;                <artifact Instance>
 +56      ;                ....
 +57      ;                <artifact Instance>
 +58      ;                </artifact Instances>
 +59      ;                <artifact Retention policy>
 +60      ;                 <artifact Retention policy fulfillments>
 +61      ;                   <artifact Retention policy fulfillment>
 +62      ;                   ...
 +63      ;                   <artifact Retention policy fulfillment>
 +64      ;                   ...
 +65      ;                 </artifact Retention policy fulfillments>
 +66      ;                </artifact Retention policy>                
 +67      ;              </artifact>              
 +68      ;  
GAFTBYID(MAGRY,IEN,CNT,FLAGS) ; 
 +1        KILL MAGRY
 +2        IF IEN=""
               SET MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"IEN is required."
               QUIT 
 +3       ; 
 +4        NEW I,X,OUT,ERR,MAGRESA
 +5        NEW FILE,FILENM,FLDFKID
 +6        NEW IENS
 +7        NEW FLDSARR,FLDSARRW,FIELDS
 +8        NEW KLFILE,KLFKID,KEYS,KLFLDID,KLIEN
 +9        NEW TMPARR
 +10       NEW QT
 +11      ; "
           SET QT=$CHAR(34)
 +12      ; ARTIFACT file number
           SET FILE=2006.916
 +13      ; File name without blanks
           SET FILENM=$TRANSLATE($$GETFILNM^MAGVAF01(FILE)," ")
 +14      ; ARTIFACT file fields names
           SET FIELDS=$$GETFLDS^MAGVAF01(.FLDSARR,.FLDSARRW,FILE)
 +15      ; KEYLIST field number 
           SET FLDFKID=$$GETFLDID^MAGVAF01(FILE,"KEYLIST")
 +16      ;
 +17       SET IENS=IEN_","
 +18      ; get ARTIFACT record values
           DO GETS^DIQ(FILE,IENS,FIELDS,"I","OUT","ERR")
 +19       IF $DATA(ERR("DIERR"))
               Begin DoDot:1
 +20               DO MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
 +21      ; Error getting the values
                   SET MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting values: "_MAGRESA(1)
                   QUIT 
 +22               QUIT 
               End DoDot:1
               QUIT 
 +23      ;
 +24       SET CNT=CNT+1
           SET MAGRY(CNT)="<"_FILENM
 +25       SET CNT=CNT+1
           SET MAGRY(CNT)="PK="_QT_IEN_QT
 +26       SET I=""
 +27       FOR 
               SET I=$ORDER(OUT(FILE,IENS,I))
               if I=""
                   QUIT 
               Begin DoDot:1
 +28      ; the field is Date type - convert to IDF format
                   IF $$ISFLDDT^MAGVAF01(FILE,I)
                       SET X=$$FM2IDF^MAGVAF01(OUT(FILE,IENS,I,"I"))
 +29              IF '$TEST
                       SET X=OUT(FILE,IENS,I,"I")
 +30      ; need to check for date format
                   SET CNT=CNT+1
                   SET MAGRY(CNT)=$TRANSLATE(FLDSARR(I)," /\<>&%")_"="_QT_X_QT
 +31               QUIT 
               End DoDot:1
 +32       SET MAGRY(CNT)=MAGRY(CNT)_" >"
 +33      ;
 +34      ; Get the KEYLIST values
 +35      ; KEYLIST file number
           SET KLFILE=2006.913
 +36      ; KEYLIST field number 
           SET KLFLDID=$$GETFLDID^MAGVAF01(KLFILE,"KEY")
 +37      ; KEYLIST is optional in ARTIFACT file (#2006.916) so check for blank
 +38       SET KLIEN=$SELECT(OUT(FILE,IENS,FLDFKID,"I")="":"",1:OUT(FILE,IENS,FLDFKID,"I")_",")
 +39      ; KEY LIST file KLFILE, field KEY KLFKID
           DO GETMVAL^MAGVAF03(.KEYS,KLFILE,KLFLDID,OUT(FILE,IENS,FLDFKID,"I")_",")
 +40      ; error found - quit 
           IF '$$ISOK^MAGVAF02(KEYS(0))
               Begin DoDot:1
 +41               KILL MAGRY
 +42      ; Error getting the values
                   SET MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting artifact "
                   QUIT 
 +43               QUIT 
               End DoDot:1
               QUIT 
 +44      ; delete zero node record - it is for information only
           KILL KEYS(0)
 +45      ; Append KEYLIST to result
           SET CNT=$$APP2ARR^MAGVAF04(.MAGRY,.KEYS)
 +46      ;
 +47       KILL ERR,TMPARR
 +48       SET ERR=0
 +49      ; Get Artifact Instance 
           IF FLAGS["I"
               Begin DoDot:1
 +50               DO GETAINST^MAGVAG04(.TMPARR,IEN)
 +51               IF '$$ISOK^MAGVAF02(TMPARR(0))
                       Begin DoDot:2
 +52                       KILL MAGRY
 +53      ; Error getting the values
                           SET MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting artifact instance "
 +54                       SET ERR=1
 +55                       QUIT 
                       End DoDot:2
 +56      ; error found - quit 
                   IF ERR
                       QUIT 
 +57      ; delete zero node record - it is for information only
                   KILL TMPARR(0)
 +58      ; Append Artifact instances to result
                   SET CNT=$$APP2ARR^MAGVAF04(.MAGRY,.TMPARR)
 +59               QUIT 
               End DoDot:1
 +60       IF ERR
               QUIT 
 +61      ;
 +62       KILL ERR,TMPARR
 +63       SET ERR=0
 +64      ; Get Artifact Retention Policies & Artifact Retention Policies Fulfillment 
           IF FLAGS["R"
               Begin DoDot:1
 +65               DO GETARP^MAGVAG04(.TMPARR,IEN)
 +66               IF '$$ISOK^MAGVAF02(TMPARR(0))
                       Begin DoDot:2
 +67                       KILL MAGRY
 +68      ; Error getting the values
                           SET MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting artifact instance "
 +69                       SET ERR=1
 +70                       QUIT 
                       End DoDot:2
 +71      ; error found - quit 
                   IF ERR
                       QUIT 
 +72      ; delete zero node record - it is for information only
                   KILL TMPARR(0)
 +73      ; Append Artifact Retention Policies  to result
                   SET CNT=$$APP2ARR^MAGVAF04(.MAGRY,.TMPARR)
 +74               QUIT 
               End DoDot:1
 +75       IF ERR
               QUIT 
 +76      ;
 +77       SET CNT=CNT+1
           SET MAGRY(CNT)="</"_FILENM_">"
 +78       SET MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_CNT
 +79       QUIT FILENM
 +80      ;
 +81      ; ----- Get Artifact Instance from ARTIFACT INSTANCE  file (#2006.918)
 +82      ;       by Artifact IEN in XML based format
 +83      ;       
 +84      ; Input Parameters
 +85      ; ================
 +86      ; IEN = Artifact IEN
 +87      ; 
 +88      ; Return Values
 +89      ; =============
 +90      ; if error MAGRY(0) = Failure status ^ Error message^
 +91      ; if success MAGRY(0) = Success status
 +92      ; MAGRY(1..n) XML based result in format
 +93      ;   <artifact Instances>
 +94      ;     <artifact Instance>
 +95      ;     ...
 +96      ;     <artifact Instance>
 +97      ;   </artifact Instances>
 +98      ;
GETAINST(MAGRY,IEN) ;
 +1        NEW FILE,IENS
 +2        SET FILE=2006.918
 +3        SET IENS=""
 +4        DO GXMLBYID^MAGVAF03(.MAGRY,FILE,IENS,IEN,1)
 +5        QUIT 
 +6       ;
 +7       ; ----- Get Artifact Retention Policy file (#2006.921)
 +8       ;       & Artifact Retention Policy Fulfillment file (#2006.922)
 +9       ;       by Artifact IEN in XML based format
 +10      ;
 +11      ; Input Parameters
 +12      ; ================
 +13      ; VAL = Artifact IEN
 +14      ; 
 +15      ; Return Values
 +16      ; =============
 +17      ; if error MAGRY(0) = Failure status ^ Error message^
 +18      ; if success MAGRY(0) = Success status
 +19      ;            MAGRY(1..n) XML based result in format
 +20      ;            <artifactRetentionpolicys>
 +21      ;             <artifactRetentionpolicy>
 +22      ;              <artifactRetention policyfulfillments>
 +23      ;                <artifactRetentionpolicyfulfillment>
 +24      ;                   ...
 +25      ;                <artifactRetentionpolicyfulfillment>
 +26      ;                 ...
 +27      ;               </artifactRetention policy fulfillments>
 +28      ;             </artifactRetentionpolicy>
 +29      ;             ...
 +30      ;            <artifactRetentionpolicys>
 +31      ; 
GETARP(MAGRY,VAL) ;
 +1        NEW FILE,FIELDS,FLDSARR,FLDSARRW,FILENM
 +2        NEW TMPARR,OUT,ERR,MAGRESA
 +3        NEW I,J,X,IENS,ERRFLG,CNT
 +4        NEW QT,RESDEL
 +5        KILL MAGRY
 +6        SET RESDEL=$$RESDEL^MAGVAF02()
 +7       ; "
           SET QT=$CHAR(34)
 +8       ; Artifact Retention Policy
           SET FILE=2006.921
 +9       ; File name without blank
           SET FILENM=$TRANSLATE($$GETFILNM^MAGVAF01(FILE)," ")
 +10      ; file fields names
           SET FIELDS=$$GETFLDS^MAGVAF01(.FLDSARR,.FLDSARRW,FILE,"I")
 +11       SET IENS=""
 +12       DO FIND^DIC(FILE,IENS,"@;"_FIELDS,"BQX",VAL,"","","","","OUT","ERR")
 +13       IF $DATA(ERR("DIERR"))
               Begin DoDot:1
 +14               DO MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
 +15      ; Error getting the list
                   SET MAGRY(0)=$$FAILED^MAGVAF02()_RESDEL_"Error getting values: "_MAGRESA(1)
                   QUIT 
 +16               QUIT 
               End DoDot:1
               QUIT 
 +17      ; Output the data
 +18       SET CNT=0
 +19       SET CNT=CNT+1
           SET MAGRY(CNT)="<"_FILENM_"S>"
 +20      ; IENs
           SET I=""
 +21      ; Fields in the file
           SET J=""
 +22       SET ERRFLG=0
 +23       FOR 
               if ERRFLG
                   QUIT 
               SET I=$ORDER(OUT("DILIST","ID",I))
               if I=""
                   QUIT 
               Begin DoDot:1
 +24               SET CNT=CNT+1
                   SET MAGRY(CNT)="<"_FILENM
 +25               SET CNT=CNT+1
                   SET MAGRY(CNT)="PK="_QT_OUT("DILIST",2,I)_QT
 +26               SET J=""
 +27               FOR 
                       SET J=$ORDER(OUT("DILIST","ID",I,J))
                       if J=""
                           QUIT 
                       Begin DoDot:2
 +28                       SET X=OUT("DILIST","ID",I,J)
 +29      ; the field is Date type - convert to IDF format
                           IF $$ISFLDDT^MAGVAF01(FILE,J)
                               SET X=$$FM2IDF^MAGVAF01(X)
 +30                       SET CNT=CNT+1
                           SET MAGRY(CNT)=$TRANSLATE(FLDSARR(J)," /\<>&%")_"="_QT_X_QT
 +31                       QUIT 
                       End DoDot:2
 +32               SET MAGRY(CNT)=MAGRY(CNT)_" >"
 +33      ; Get Retention Policy Fulfillment
 +34               KILL TMPARR
 +35               DO GXMLBYID^MAGVAF03(.TMPARR,2006.922,"",OUT("DILIST",2,I),1)
 +36      ; error found - quit 
                   IF '$$ISOK^MAGVAF02(TMPARR(0))
                       Begin DoDot:2
 +37                       KILL MAGRY
 +38      ; Error getting the values
                           SET MAGRY(0)=$$FAILED^MAGVAF02()_RESDEL_"Error getting artifact "
                           QUIT 
 +39                       SET ERRFLG=1
 +40                       QUIT 
                       End DoDot:2
                       QUIT 
 +41      ; delete zero node record - it is for information only
                   KILL TMPARR(0)
 +42      ; Append Retention Policy Fulfillment to result
                   SET CNT=$$APP2ARR^MAGVAF04(.MAGRY,.TMPARR)
 +43               SET CNT=CNT+1
                   SET MAGRY(CNT)="</"_FILENM_" >"
 +44               QUIT 
               End DoDot:1
 +45       SET CNT=CNT+1
           SET MAGRY(CNT)="</"_FILENM_"S>"
 +46       SET MAGRY(0)=$$OK^MAGVAF02()_RESDEL_RESDEL_CNT
 +47       QUIT