Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: MAGVAKL1

MAGVAKL1.m

Go to the documentation of this file.
  1. 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
  1. ;; Per VHA Directive 2004-038, this routine should not be modified.
  1. ;; +---------------------------------------------------------------+
  1. ;; | Property of the US Government. |
  1. ;; | No permission to copy or redistribute this software is given. |
  1. ;; | Use of unreleased versions of this software requires the user |
  1. ;; | to execute a written test agreement with the VistA Imaging |
  1. ;; | Development Office of the Department of Veterans Affairs, |
  1. ;; | telephone (301) 734-0100. |
  1. ;; | The Food and Drug Administration classifies this software as |
  1. ;; | a medical device. As such, it may not be changed in any way. |
  1. ;; | Modifications to this software may result in an adulterated |
  1. ;; | medical device under 21CFR820, the use of which is considered |
  1. ;; | to be a violation of US Federal Statutes. |
  1. ;; +---------------------------------------------------------------+
  1. ;;
  1. Q
  1. ;
  1. ;***** Return a KEY IEN that meets the keys provided
  1. ;
  1. ; Input parameters
  1. ; ================
  1. ; KLIST(1) = First level Key
  1. ; KLIST(2) = Second level Key
  1. ; ...
  1. ; KLIST(N) = N-th level Key
  1. ; The assumption is that we will get the full keys list
  1. ; so we should find only one KEY IEN or we will not find any
  1. ;
  1. ; Return Value
  1. ; ============
  1. ;
  1. ; if no key list IEN found returns 0
  1. ; if key list found returns IEN of the ARTIFACT KEYLIST file (#2006.913) record
  1. ;
  1. GETKLIEN(KLIST) ;
  1. N RES
  1. D FINDKEYS^MAGVAKL1(.RES,.KLIST)
  1. I '$$ISOK^MAGVAF02(RES(0)) Q 0 ; Error found
  1. Q $O(RES(0)) ; get the IEN. It should be only one IEN
  1. ;
  1. ;***** Return a key list IEN that meet the keys provided
  1. ; It creates a new record in ARTIFACT KEYLIST file (#2006.913) if the key list is not found
  1. ;
  1. ; Input parameters
  1. ; ================
  1. ; KLIST(1) = First level Key
  1. ; KLIST(2) = Second level Key
  1. ; ...
  1. ; KLIST(N) = N-th level Key
  1. ; The assumption is that we will get the full keys list
  1. ; so we should find only one KEY IEN or we will not find any
  1. ;
  1. ; Return Values
  1. ; =============
  1. ;
  1. ; if error MAGRY = Failure status^Error message
  1. ; if success MAGRY = Success status^^IEN of the record in ARTIFACT KEYLIST file (#2006.913)
  1. ;
  1. GETKLFK(MAGRY,KLIST) ;
  1. ; if KLIST is empty just return success and set the IEN to ""
  1. ; Key list is optional in ARTIFACT file (#2006.916) that's why empty key list is OK
  1. ; ADDKL^MAGVAKL1 reports error if KLIST is empty
  1. K MAGRY
  1. I $O(KLIST(""))="" S MAGRY=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_"" Q
  1. ; try to find or create a new key list record
  1. D ADDKL^MAGVAKL1(.MAGRY,.KLIST)
  1. Q
  1. ;
  1. ;***** Return a list with all keys IENS in ARTIFACT KEYLIST file (#2006.913)
  1. ; that meet the keys provided
  1. ;
  1. ; RPC: MAGVA FIND KEYLIST
  1. ;
  1. ; Input Parameters
  1. ; ===============
  1. ; KLIST(1) = First Key
  1. ; KLIST(2) = Second Key
  1. ; ...
  1. ; KLIST(N) = N-th Key
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY(0) = Failure status ^ Error message^
  1. ; if success MAGRY(0) = Success status
  1. ; MAGRY(n) = IEN of the record in ARTIFACT KEYLIST file (#2006.913) that matches the request
  1. ; n same as IEN
  1. ;
  1. FINDKEYS(MAGRY,KLIST) ; RPC [MAGVA FIND KEYLIST]
  1. N KEY,KEYSIEN,COUNT,LEVEL,FOUND
  1. K MAGRY
  1. ; Search for keys using IDXKEYS index by DEPTH and KEY.
  1. ; Store the KEYIEN into array and count the number
  1. ; of hits by KEYSIEN
  1. S COUNT=0 ; How many individual KEYS are requested
  1. S LEVEL=""
  1. F S LEVEL=$O(KLIST(LEVEL)) Q:LEVEL="" D
  1. . S KEY=KLIST(LEVEL)
  1. . S COUNT=COUNT+1
  1. . S KEYSIEN=""
  1. . F S KEYSIEN=$O(^MAGV(2006.913,"IDXKEYS",LEVEL,KEY,KEYSIEN)) Q:KEYSIEN="" D
  1. . . S FOUND(KEYSIEN)=$G(FOUND(KEYSIEN))+1
  1. . . Q
  1. . Q
  1. ; Check for any KEYSIEN that has as many hits as requested number of keys
  1. S KEYSIEN=""
  1. F S KEYSIEN=$O(FOUND(KEYSIEN)) Q:KEYSIEN="" D
  1. . I FOUND(KEYSIEN)=COUNT S MAGRY(KEYSIEN)=KEYSIEN
  1. . Q
  1. S MAGRY(0)=$$OK^MAGVAF02()
  1. Q
  1. ;
  1. ;***** Add new KEY PAIRS to ARTIFACT KEYLIST file (#2006.913)
  1. ; RPC: MAGVA ADD KEYLIST
  1. ;
  1. ; Input Parameters
  1. ; ================
  1. ; KLIST(1) = First level Key
  1. ; KLIST(2) = Second level Key
  1. ; ...
  1. ; KLIST(N) = N-th level Key
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY = Failure status^Error
  1. ; if success MAGRY = Success status^^IEN - IEN of the added record
  1. ;
  1. ADDKL(MAGRY,KLIST) ; RPC [MAGVA ADD KEYLIST]
  1. ;
  1. K MAGRY
  1. ; Quit error if key list is empty
  1. I $O(KLIST(""))="" S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"KEYLIST is empty" Q
  1. ;
  1. N DEPTH,I,IENS,IEN,MAGDA,MAGNFDA,MAGNIEN,MAGNXE,ERR
  1. S IEN=+$$GETKLIEN^MAGVAKL1(.KLIST)
  1. I IEN S MAGRY=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_IEN Q ; The Key list is already on file
  1. ; The Key List is not found. Add a new record to save all values
  1. S I=""
  1. S DEPTH=0
  1. F S I=$O(KLIST(I)) Q:I="" S DEPTH=DEPTH+1
  1. ;
  1. S MAGNFDA(2006.913,"+1,",.01)=DEPTH
  1. D UPDATE^DIE("","MAGNFDA","MAGNIEN","MAGNXE")
  1. I $D(MAGNXE("DIERR","E")) S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error adding a key list" Q
  1. ;
  1. S MAGDA=MAGNIEN(1)
  1. S IENS="+1,"_MAGDA_","
  1. S ERR=0
  1. S I=""
  1. F S I=$O(KLIST(I)) Q:I="" D Q:ERR
  1. . K MAGNFDA,MAGNIEN,MAGNXE
  1. . S MAGNFDA(2006.9132,IENS,.01)=KLIST(I)
  1. . S MAGNFDA(2006.9132,IENS,2)=I
  1. . D UPDATE^DIE("","MAGNFDA","MAGNIEN","MAGNXE")
  1. . I $D(MAGNXE("DIERR","E")) D
  1. . . N DIK,DA
  1. . . S ERR=1
  1. . . S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error adding a new key pair."
  1. . . ; clean up data
  1. . . S DA=MAGDA
  1. . . S DIK=$$GETFILGL^MAGVAF01(2006.913)
  1. . . D ^DIK
  1. . . Q
  1. . Q
  1. I ERR Q ; Exit the routine. MAGRY is set already
  1. S MAGRY=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_MAGDA
  1. Q
  1. ;
  1. ;***** Returns a key list by IEN in ARTIFACT KEYLIST file (#2006.913)
  1. ; RPC: MAGVA GET KEYLIST
  1. ;
  1. ; Input Parameters
  1. ; ================
  1. ; MAGDA = IEN in ARTIFACT KEYLIST file (#2006.913)
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY(0) = Failure status^Error message
  1. ; if success
  1. ; MAGRY(0) = Success status^^Number of key list depth
  1. ; MAGRY(1) = Level one Key
  1. ; MAGRY(2) = Level two Key
  1. ; ...
  1. ; MAGRY(N) = Level N-th Key
  1. ;
  1. GETKL(MAGRY,MAGDA) ; RPC [MAGVA GET KEYLIST]
  1. N OUT,ERR,MAGRESA
  1. N I,CNT,X
  1. K MAGRY
  1. ; --- .01 KLEVEL; 2 KVALUE
  1. D LIST^DIC(2006.9132,","_MAGDA_",","@;.01;2","P","","","","","","","OUT","ERR")
  1. I $D(ERR("DIERR")) D Q
  1. . D MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
  1. . S MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting the list: "_MAGRESA(1) Q ; Error getting the list
  1. S I=0
  1. S CNT=0
  1. F S I=$O(OUT("DILIST",I)) Q:'+I D
  1. . S X=OUT("DILIST",I,0)
  1. . S CNT=CNT+1
  1. . S MAGRY($P(X,"^",3))=$P(X,"^",2)
  1. . Q
  1. S MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_CNT
  1. Q
  1. ;
  1. ;***** Delete a record in ARTIFACT KEYLIST file (#2006.913) by IEN
  1. ; RPC: MAGVA DELETE KEYLIST
  1. ;
  1. ; Input Parameters
  1. ; ================
  1. ; MAGDA = IEN in ARTIFACT KEYLIST file (#2006.913)
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY = Failure status ^ Error message^
  1. ; if success MAGRY = Success status
  1. ;
  1. DELKL(MAGRY,MAGDA) ; RPC [MAGVA DELETE KEYLIST]
  1. N DIK,DA
  1. S DA=MAGDA
  1. S DIK=$$GETFILGL^MAGVAF01(2006.913)
  1. D ^DIK
  1. S MAGRY=$$OK^MAGVAF02()
  1. Q