MAGVAKL1 ;WOIFO/NST - Key List File Utilities ; 20 Feb 2012 3:56 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
;
;***** Return a KEY IEN that meets the keys provided
;
; Input parameters
; ================
; KLIST(1) = First level Key
; KLIST(2) = Second level Key
; ...
; KLIST(N) = N-th level Key
; The assumption is that we will get the full keys list
; so we should find only one KEY IEN or we will not find any
;
; Return Value
; ============
;
; if no key list IEN found returns 0
; if key list found returns IEN of the ARTIFACT KEYLIST file (#2006.913) record
;
GETKLIEN(KLIST) ;
N RES
D FINDKEYS^MAGVAKL1(.RES,.KLIST)
I '$$ISOK^MAGVAF02(RES(0)) Q 0 ; Error found
Q $O(RES(0)) ; get the IEN. It should be only one IEN
;
;***** Return a key list IEN that meet the keys provided
; It creates a new record in ARTIFACT KEYLIST file (#2006.913) if the key list is not found
;
; Input parameters
; ================
; KLIST(1) = First level Key
; KLIST(2) = Second level Key
; ...
; KLIST(N) = N-th level Key
; The assumption is that we will get the full keys list
; so we should find only one KEY IEN or we will not find any
;
; Return Values
; =============
;
; if error MAGRY = Failure status^Error message
; if success MAGRY = Success status^^IEN of the record in ARTIFACT KEYLIST file (#2006.913)
;
GETKLFK(MAGRY,KLIST) ;
; if KLIST is empty just return success and set the IEN to ""
; Key list is optional in ARTIFACT file (#2006.916) that's why empty key list is OK
; ADDKL^MAGVAKL1 reports error if KLIST is empty
K MAGRY
I $O(KLIST(""))="" S MAGRY=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_"" Q
; try to find or create a new key list record
D ADDKL^MAGVAKL1(.MAGRY,.KLIST)
Q
;
;***** Return a list with all keys IENS in ARTIFACT KEYLIST file (#2006.913)
; that meet the keys provided
;
; RPC: MAGVA FIND KEYLIST
;
; Input Parameters
; ===============
; KLIST(1) = First Key
; KLIST(2) = Second Key
; ...
; KLIST(N) = N-th Key
;
; Return Values
; =============
; if error MAGRY(0) = Failure status ^ Error message^
; if success MAGRY(0) = Success status
; MAGRY(n) = IEN of the record in ARTIFACT KEYLIST file (#2006.913) that matches the request
; n same as IEN
;
FINDKEYS(MAGRY,KLIST) ; RPC [MAGVA FIND KEYLIST]
N KEY,KEYSIEN,COUNT,LEVEL,FOUND
K MAGRY
; Search for keys using IDXKEYS index by DEPTH and KEY.
; Store the KEYIEN into array and count the number
; of hits by KEYSIEN
S COUNT=0 ; How many individual KEYS are requested
S LEVEL=""
F S LEVEL=$O(KLIST(LEVEL)) Q:LEVEL="" D
. S KEY=KLIST(LEVEL)
. S COUNT=COUNT+1
. S KEYSIEN=""
. F S KEYSIEN=$O(^MAGV(2006.913,"IDXKEYS",LEVEL,KEY,KEYSIEN)) Q:KEYSIEN="" D
. . S FOUND(KEYSIEN)=$G(FOUND(KEYSIEN))+1
. . Q
. Q
; Check for any KEYSIEN that has as many hits as requested number of keys
S KEYSIEN=""
F S KEYSIEN=$O(FOUND(KEYSIEN)) Q:KEYSIEN="" D
. I FOUND(KEYSIEN)=COUNT S MAGRY(KEYSIEN)=KEYSIEN
. Q
S MAGRY(0)=$$OK^MAGVAF02()
Q
;
;***** Add new KEY PAIRS to ARTIFACT KEYLIST file (#2006.913)
; RPC: MAGVA ADD KEYLIST
;
; Input Parameters
; ================
; KLIST(1) = First level Key
; KLIST(2) = Second level Key
; ...
; KLIST(N) = N-th level Key
;
; Return Values
; =============
; if error MAGRY = Failure status^Error
; if success MAGRY = Success status^^IEN - IEN of the added record
;
ADDKL(MAGRY,KLIST) ; RPC [MAGVA ADD KEYLIST]
;
K MAGRY
; Quit error if key list is empty
I $O(KLIST(""))="" S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"KEYLIST is empty" Q
;
N DEPTH,I,IENS,IEN,MAGDA,MAGNFDA,MAGNIEN,MAGNXE,ERR
S IEN=+$$GETKLIEN^MAGVAKL1(.KLIST)
I IEN S MAGRY=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_IEN Q ; The Key list is already on file
; The Key List is not found. Add a new record to save all values
S I=""
S DEPTH=0
F S I=$O(KLIST(I)) Q:I="" S DEPTH=DEPTH+1
;
S MAGNFDA(2006.913,"+1,",.01)=DEPTH
D UPDATE^DIE("","MAGNFDA","MAGNIEN","MAGNXE")
I $D(MAGNXE("DIERR","E")) S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error adding a key list" Q
;
S MAGDA=MAGNIEN(1)
S IENS="+1,"_MAGDA_","
S ERR=0
S I=""
F S I=$O(KLIST(I)) Q:I="" D Q:ERR
. K MAGNFDA,MAGNIEN,MAGNXE
. S MAGNFDA(2006.9132,IENS,.01)=KLIST(I)
. S MAGNFDA(2006.9132,IENS,2)=I
. D UPDATE^DIE("","MAGNFDA","MAGNIEN","MAGNXE")
. I $D(MAGNXE("DIERR","E")) D
. . N DIK,DA
. . S ERR=1
. . S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error adding a new key pair."
. . ; clean up data
. . S DA=MAGDA
. . S DIK=$$GETFILGL^MAGVAF01(2006.913)
. . D ^DIK
. . Q
. Q
I ERR Q ; Exit the routine. MAGRY is set already
S MAGRY=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_MAGDA
Q
;
;***** Returns a key list by IEN in ARTIFACT KEYLIST file (#2006.913)
; RPC: MAGVA GET KEYLIST
;
; Input Parameters
; ================
; MAGDA = IEN in ARTIFACT KEYLIST file (#2006.913)
;
; Return Values
; =============
; if error MAGRY(0) = Failure status^Error message
; if success
; MAGRY(0) = Success status^^Number of key list depth
; MAGRY(1) = Level one Key
; MAGRY(2) = Level two Key
; ...
; MAGRY(N) = Level N-th Key
;
GETKL(MAGRY,MAGDA) ; RPC [MAGVA GET KEYLIST]
N OUT,ERR,MAGRESA
N I,CNT,X
K MAGRY
; --- .01 KLEVEL; 2 KVALUE
D LIST^DIC(2006.9132,","_MAGDA_",","@;.01;2","P","","","","","","","OUT","ERR")
I $D(ERR("DIERR")) D Q
. D MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
. S MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting the list: "_MAGRESA(1) Q ; Error getting the list
S I=0
S CNT=0
F S I=$O(OUT("DILIST",I)) Q:'+I D
. S X=OUT("DILIST",I,0)
. S CNT=CNT+1
. S MAGRY($P(X,"^",3))=$P(X,"^",2)
. Q
S MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_CNT
Q
;
;***** Delete a record in ARTIFACT KEYLIST file (#2006.913) by IEN
; RPC: MAGVA DELETE KEYLIST
;
; Input Parameters
; ================
; MAGDA = IEN in ARTIFACT KEYLIST file (#2006.913)
;
; Return Values
; =============
; if error MAGRY = Failure status ^ Error message^
; if success MAGRY = Success status
;
DELKL(MAGRY,MAGDA) ; RPC [MAGVA DELETE KEYLIST]
N DIK,DA
S DA=MAGDA
S DIK=$$GETFILGL^MAGVAF01(2006.913)
D ^DIK
S MAGRY=$$OK^MAGVAF02()
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGVAKL1 7559 printed Nov 22, 2024@17:19:32 Page 2
MAGVAKL1 ;WOIFO/NST - Key List File Utilities ; 20 Feb 2012 3:56 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 ;***** Return a KEY IEN that meets the keys provided
+20 ;
+21 ; Input parameters
+22 ; ================
+23 ; KLIST(1) = First level Key
+24 ; KLIST(2) = Second level Key
+25 ; ...
+26 ; KLIST(N) = N-th level Key
+27 ; The assumption is that we will get the full keys list
+28 ; so we should find only one KEY IEN or we will not find any
+29 ;
+30 ; Return Value
+31 ; ============
+32 ;
+33 ; if no key list IEN found returns 0
+34 ; if key list found returns IEN of the ARTIFACT KEYLIST file (#2006.913) record
+35 ;
GETKLIEN(KLIST) ;
+1 NEW RES
+2 DO FINDKEYS^MAGVAKL1(.RES,.KLIST)
+3 ; Error found
IF '$$ISOK^MAGVAF02(RES(0))
QUIT 0
+4 ; get the IEN. It should be only one IEN
QUIT $ORDER(RES(0))
+5 ;
+6 ;***** Return a key list IEN that meet the keys provided
+7 ; It creates a new record in ARTIFACT KEYLIST file (#2006.913) if the key list is not found
+8 ;
+9 ; Input parameters
+10 ; ================
+11 ; KLIST(1) = First level Key
+12 ; KLIST(2) = Second level Key
+13 ; ...
+14 ; KLIST(N) = N-th level Key
+15 ; The assumption is that we will get the full keys list
+16 ; so we should find only one KEY IEN or we will not find any
+17 ;
+18 ; Return Values
+19 ; =============
+20 ;
+21 ; if error MAGRY = Failure status^Error message
+22 ; if success MAGRY = Success status^^IEN of the record in ARTIFACT KEYLIST file (#2006.913)
+23 ;
GETKLFK(MAGRY,KLIST) ;
+1 ; if KLIST is empty just return success and set the IEN to ""
+2 ; Key list is optional in ARTIFACT file (#2006.916) that's why empty key list is OK
+3 ; ADDKL^MAGVAKL1 reports error if KLIST is empty
+4 KILL MAGRY
+5 IF $ORDER(KLIST(""))=""
SET MAGRY=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_""
QUIT
+6 ; try to find or create a new key list record
+7 DO ADDKL^MAGVAKL1(.MAGRY,.KLIST)
+8 QUIT
+9 ;
+10 ;***** Return a list with all keys IENS in ARTIFACT KEYLIST file (#2006.913)
+11 ; that meet the keys provided
+12 ;
+13 ; RPC: MAGVA FIND KEYLIST
+14 ;
+15 ; Input Parameters
+16 ; ===============
+17 ; KLIST(1) = First Key
+18 ; KLIST(2) = Second Key
+19 ; ...
+20 ; KLIST(N) = N-th Key
+21 ;
+22 ; Return Values
+23 ; =============
+24 ; if error MAGRY(0) = Failure status ^ Error message^
+25 ; if success MAGRY(0) = Success status
+26 ; MAGRY(n) = IEN of the record in ARTIFACT KEYLIST file (#2006.913) that matches the request
+27 ; n same as IEN
+28 ;
FINDKEYS(MAGRY,KLIST) ; RPC [MAGVA FIND KEYLIST]
+1 NEW KEY,KEYSIEN,COUNT,LEVEL,FOUND
+2 KILL MAGRY
+3 ; Search for keys using IDXKEYS index by DEPTH and KEY.
+4 ; Store the KEYIEN into array and count the number
+5 ; of hits by KEYSIEN
+6 ; How many individual KEYS are requested
SET COUNT=0
+7 SET LEVEL=""
+8 FOR
SET LEVEL=$ORDER(KLIST(LEVEL))
if LEVEL=""
QUIT
Begin DoDot:1
+9 SET KEY=KLIST(LEVEL)
+10 SET COUNT=COUNT+1
+11 SET KEYSIEN=""
+12 FOR
SET KEYSIEN=$ORDER(^MAGV(2006.913,"IDXKEYS",LEVEL,KEY,KEYSIEN))
if KEYSIEN=""
QUIT
Begin DoDot:2
+13 SET FOUND(KEYSIEN)=$GET(FOUND(KEYSIEN))+1
+14 QUIT
End DoDot:2
+15 QUIT
End DoDot:1
+16 ; Check for any KEYSIEN that has as many hits as requested number of keys
+17 SET KEYSIEN=""
+18 FOR
SET KEYSIEN=$ORDER(FOUND(KEYSIEN))
if KEYSIEN=""
QUIT
Begin DoDot:1
+19 IF FOUND(KEYSIEN)=COUNT
SET MAGRY(KEYSIEN)=KEYSIEN
+20 QUIT
End DoDot:1
+21 SET MAGRY(0)=$$OK^MAGVAF02()
+22 QUIT
+23 ;
+24 ;***** Add new KEY PAIRS to ARTIFACT KEYLIST file (#2006.913)
+25 ; RPC: MAGVA ADD KEYLIST
+26 ;
+27 ; Input Parameters
+28 ; ================
+29 ; KLIST(1) = First level Key
+30 ; KLIST(2) = Second level Key
+31 ; ...
+32 ; KLIST(N) = N-th level Key
+33 ;
+34 ; Return Values
+35 ; =============
+36 ; if error MAGRY = Failure status^Error
+37 ; if success MAGRY = Success status^^IEN - IEN of the added record
+38 ;
ADDKL(MAGRY,KLIST) ; RPC [MAGVA ADD KEYLIST]
+1 ;
+2 KILL MAGRY
+3 ; Quit error if key list is empty
+4 IF $ORDER(KLIST(""))=""
SET MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"KEYLIST is empty"
QUIT
+5 ;
+6 NEW DEPTH,I,IENS,IEN,MAGDA,MAGNFDA,MAGNIEN,MAGNXE,ERR
+7 SET IEN=+$$GETKLIEN^MAGVAKL1(.KLIST)
+8 ; The Key list is already on file
IF IEN
SET MAGRY=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_IEN
QUIT
+9 ; The Key List is not found. Add a new record to save all values
+10 SET I=""
+11 SET DEPTH=0
+12 FOR
SET I=$ORDER(KLIST(I))
if I=""
QUIT
SET DEPTH=DEPTH+1
+13 ;
+14 SET MAGNFDA(2006.913,"+1,",.01)=DEPTH
+15 DO UPDATE^DIE("","MAGNFDA","MAGNIEN","MAGNXE")
+16 IF $DATA(MAGNXE("DIERR","E"))
SET MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error adding a key list"
QUIT
+17 ;
+18 SET MAGDA=MAGNIEN(1)
+19 SET IENS="+1,"_MAGDA_","
+20 SET ERR=0
+21 SET I=""
+22 FOR
SET I=$ORDER(KLIST(I))
if I=""
QUIT
Begin DoDot:1
+23 KILL MAGNFDA,MAGNIEN,MAGNXE
+24 SET MAGNFDA(2006.9132,IENS,.01)=KLIST(I)
+25 SET MAGNFDA(2006.9132,IENS,2)=I
+26 DO UPDATE^DIE("","MAGNFDA","MAGNIEN","MAGNXE")
+27 IF $DATA(MAGNXE("DIERR","E"))
Begin DoDot:2
+28 NEW DIK,DA
+29 SET ERR=1
+30 SET MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error adding a new key pair."
+31 ; clean up data
+32 SET DA=MAGDA
+33 SET DIK=$$GETFILGL^MAGVAF01(2006.913)
+34 DO ^DIK
+35 QUIT
End DoDot:2
+36 QUIT
End DoDot:1
if ERR
QUIT
+37 ; Exit the routine. MAGRY is set already
IF ERR
QUIT
+38 SET MAGRY=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_MAGDA
+39 QUIT
+40 ;
+41 ;***** Returns a key list by IEN in ARTIFACT KEYLIST file (#2006.913)
+42 ; RPC: MAGVA GET KEYLIST
+43 ;
+44 ; Input Parameters
+45 ; ================
+46 ; MAGDA = IEN in ARTIFACT KEYLIST file (#2006.913)
+47 ;
+48 ; Return Values
+49 ; =============
+50 ; if error MAGRY(0) = Failure status^Error message
+51 ; if success
+52 ; MAGRY(0) = Success status^^Number of key list depth
+53 ; MAGRY(1) = Level one Key
+54 ; MAGRY(2) = Level two Key
+55 ; ...
+56 ; MAGRY(N) = Level N-th Key
+57 ;
GETKL(MAGRY,MAGDA) ; RPC [MAGVA GET KEYLIST]
+1 NEW OUT,ERR,MAGRESA
+2 NEW I,CNT,X
+3 KILL MAGRY
+4 ; --- .01 KLEVEL; 2 KVALUE
+5 DO LIST^DIC(2006.9132,","_MAGDA_",","@;.01;2","P","","","","","","","OUT","ERR")
+6 IF $DATA(ERR("DIERR"))
Begin DoDot:1
+7 DO MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
+8 ; Error getting the list
SET MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting the list: "_MAGRESA(1)
QUIT
End DoDot:1
QUIT
+9 SET I=0
+10 SET CNT=0
+11 FOR
SET I=$ORDER(OUT("DILIST",I))
if '+I
QUIT
Begin DoDot:1
+12 SET X=OUT("DILIST",I,0)
+13 SET CNT=CNT+1
+14 SET MAGRY($PIECE(X,"^",3))=$PIECE(X,"^",2)
+15 QUIT
End DoDot:1
+16 SET MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_CNT
+17 QUIT
+18 ;
+19 ;***** Delete a record in ARTIFACT KEYLIST file (#2006.913) by IEN
+20 ; RPC: MAGVA DELETE KEYLIST
+21 ;
+22 ; Input Parameters
+23 ; ================
+24 ; MAGDA = IEN in ARTIFACT KEYLIST file (#2006.913)
+25 ;
+26 ; Return Values
+27 ; =============
+28 ; if error MAGRY = Failure status ^ Error message^
+29 ; if success MAGRY = Success status
+30 ;
DELKL(MAGRY,MAGDA) ; RPC [MAGVA DELETE KEYLIST]
+1 NEW DIK,DA
+2 SET DA=MAGDA
+3 SET DIK=$$GETFILGL^MAGVAF01(2006.913)
+4 DO ^DIK
+5 SET MAGRY=$$OK^MAGVAF02()
+6 QUIT