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

MAGGI12.m

Go to the documentation of this file.
  1. MAGGI12 ;WOIFO/GEK/SG/JSL - IMAGE FILE API (PROPERTIES) ; 1/13/09 11:20am
  1. ;;3.0;IMAGING;**93,94,122,138**;Mar 19, 2002;Build 5380;Sep 03, 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. ;##### RETURNS IEN OF THE GROUP PARENT FOR THE IMAGE
  1. ;
  1. ; IEN Internal Entry Number of the image record
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; 0 Image is not a member of a group
  1. ; >0 IEN of the group parent
  1. ;
  1. ; Notes
  1. ; =====
  1. ;
  1. ; For a deleted image, the function returns the IEN of the group
  1. ; that the image belonged to before it was marked as deleted.
  1. ;
  1. GRPIEN(IEN) ; Returns IEN of the Group parent for the Image.
  1. N ERR,NODE
  1. S NODE=$$NODE^MAGGI11(IEN,.ERR)
  1. I NODE="" D STORE^MAGUERR(ERR) Q ERR
  1. Q +$P($G(@NODE@(0)),U,10) ; GROUP PARENT (14)
  1. ;
  1. ;##### ALLOCATES A NEW RECORD IN THE IMAGE FILE (#2005) AND LOCKS IT
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; >0 IEN for the new record in the IMAGE file (#2005)
  1. ;
  1. ; Notes
  1. ; =====
  1. ;
  1. ; The placeholder for the new record (^MAG(2005,IEN) node) is LOCKed
  1. ; by this function. It is responsibility of the caller to unlock the
  1. ; record after it is created or the record creation is canceled.
  1. ;
  1. NEWIEN() ;
  1. N DIEN,IEN,NEWIEN,NODE
  1. S NEWIEN=0
  1. ;---
  1. F D Q:NEWIEN
  1. . S IEN=$O(^MAG(2005," "),-1)+1
  1. . ;--- Check the IMAGE AUDIT file for a deleted image
  1. . S DIEN=$O(^MAG(2005.1," "),-1)+1
  1. . S:DIEN>IEN IEN=DIEN
  1. . ;--- If the record already exists, skip it
  1. . S NODE=$NA(^MAG(2005,IEN)) Q:$D(@NODE)
  1. . ;--- Lock the placeholder in order to make sure that nobody
  1. . ;--- else is trying to allocate it at the same time.
  1. . D LOCK^DILF(NODE) E Q
  1. . ;--- Double check that the record has not been created after the
  1. . ;--- previous $D() check and the LOCK command (a race condition)
  1. . I $D(@NODE) L -@NODE Q
  1. . ;--- Success
  1. . S NEWIEN=IEN
  1. . Q
  1. ;---
  1. Q NEWIEN
  1. ;
  1. ;##### RETURNS THE PARENT DATA (SUB)FILE REFERENCE
  1. ;
  1. ; IEN Internal Entry Number of the image record
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; 0 Image does not have a parent file reference
  1. ; >0 Parent data file reference (file/subfile number and
  1. ; IEN in the PARENT DATA FILE file (#2005.03) at the
  1. ; same time).
  1. ;
  1. PARFILE(IEN) ;
  1. N ERR,NODE,PARENTFILE,PFN0
  1. S NODE=$$NODE^MAGGI11(IEN,.ERR)
  1. I NODE="" D STORE^MAGUERR(ERR) Q ERR
  1. ;--- Check if the image record has a parent data file reference
  1. S PARENTFILE=$P($G(@NODE@(2)),U,6) ; PARENT DATA FILE# (16)
  1. Q:PARENTFILE="" 0
  1. ;--- Check if the pointer to the PARENT DATA FILE
  1. ;--- file (#2005.03) is valid
  1. S PFN0=$G(^MAG(2005.03,PARENTFILE,0))
  1. Q:PFN0="" $$ERROR^MAGUERR(-34,,IEN,PARENTFILE)
  1. ;--- Check if file descriptor has a value in FILE POINTER field (.04)
  1. Q:$P(PFN0,U,4)="" $$ERROR^MAGUERR(-35,,PARENTFILE)
  1. ;--- Return the reference
  1. Q PARENTFILE
  1. ;
  1. ;##### RETURNS STATUS OF THE IMAGE
  1. ;
  1. ; IEN Internal Entry Number of the image record
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; "" Status is not defined
  1. ; >0 Image status
  1. ; ^01: Status code (internal value)
  1. ; ^02: Description (external value)
  1. ;
  1. STATUS(IEN) ;
  1. N ERR,STATUS
  1. S STATUS=$$IMGST^MAGGI11(IEN,.ERR)
  1. D:ERR<0 STORE^MAGUERR(ERR)
  1. Q $S(STATUS>0:STATUS,ERR<0:ERR,1:"")
  1. ;
  1. ;##### RETURNS THE VIEWABLE STATUS OF THE IMAGE
  1. ;
  1. ; IEN IEN of the image record in the file #2005
  1. ;
  1. ; [FLAGS] Flags that control execution (can be combined):
  1. ;
  1. ; Q Perform the integrity checks
  1. ;
  1. ; [.MESSAGES] Reference to a local array for messages returned
  1. ; by the image data checks. A node in this array is
  1. ; defined only if the result value contains the
  1. ; corresponding subscript value (e.g. the "Q" node is
  1. ; defined only if integrity checks fail and the result
  1. ; contains "Q").
  1. ;
  1. ; MESSAGES(
  1. ;
  1. ; "Q") Message returned by the integrity checks.
  1. ;
  1. ; "R") Message returned by the Radiology report checks
  1. ; (reserved but not implemented)
  1. ;
  1. ; "S") Message regarding the image status.
  1. ;
  1. ; "T") Message returned by the TIU note checks.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; "" Image can be viewed
  1. ; ... One or more characters that indicate why
  1. ; the image cannot be viewed "as usual":
  1. ;
  1. ; D Deleted image
  1. ; Q Questionable integrity
  1. ; R Problem with the Radiology report
  1. ; (reserved but not implemented)
  1. ; S Check the value of the STATUS field
  1. ; T Can't view the TIU note
  1. ;
  1. VIEWSTAT(IEN,FLAGS,MESSAGES) ;
  1. N MAGCF,MAGVS
  1. K MESSAGES S MAGVS="",MAGCF=$G(FLAGS)
  1. D
  1. . N BUF,ERR,GRPIEN,NODE,STATUS
  1. . ;--- Validate IEN and get the image status
  1. . S STATUS=$$IMGST^MAGGI11(IEN,.ERR)
  1. . S NODE=$$NODE^MAGGI11(IEN)
  1. . ;--- Force the integrity check in case of error(s)
  1. . I (ERR<0)!(NODE="") S MAGCF=MAGCF_"Q" Q
  1. . ; gek/ P94t7 if IEN is in a group, we also mark child as "T" if Grp is "T"
  1. . S GRPIEN=+$P($G(@NODE@(0)),U,10)
  1. . I GRPIEN D
  1. . . N GBUF,GNODE
  1. . . S GNODE=$$NODE^MAGGI11(GRPIEN)
  1. . . S GBUF=$G(@GNODE@(2))
  1. . . D:+$P(GBUF,U,6)=8925
  1. . . . N IEN,TMP
  1. . . . S IEN=+$P(GBUF,U,7) Q:'IEN
  1. . . . S TMP=$$CANDO^TIULP(IEN,"VIEW") ;IA#2322
  1. . . . S:'TMP MAGVS=MAGVS_"T",MESSAGES("T")=$P(TMP,U,2)
  1. . . . Q
  1. . . Q
  1. . I MAGVS["T" Q
  1. . ; gek/ p94t7 __ Done changes
  1. . ;--- Check the image status
  1. . D:STATUS'<10
  1. . . I +STATUS=12 S MAGVS=MAGVS_"D" Q
  1. . . ;Patch 140 Status of 13 will continue and MESSAGES("S") will have reason
  1. . . S MAGVS=MAGVS_"S"
  1. . . S MESSAGES("S")=$$MSG^MAGUERR(-33,,$P(STATUS,U,2))
  1. . . Q
  1. . ;--- Check if the TIU note can be viewed
  1. . S BUF=$G(@NODE@(2))
  1. . D:+$P(BUF,U,6)=8925
  1. . . N IEN,TMP S IEN=+$P(BUF,U,7) Q:'IEN
  1. . . S TMP=$$CANDO^TIULP(IEN,"VIEW") ;IA#2322
  1. . . S:'TMP MAGVS=MAGVS_"T",MESSAGES("T")=$P(TMP,U,2)
  1. . . Q
  1. . ;--- Check the status of the group if necessary
  1. . I MAGVS'["D",MAGVS'["S" D
  1. . . S GRPIEN=$P($G(@NODE@(0)),U,10) Q:GRPIEN'>0 ; GROUP PARENT
  1. . . S STATUS=$$IMGST^MAGGI11(GRPIEN) Q:STATUS<10
  1. . . ;--- Force the integrity check if the existing
  1. . . ;--- image entry belongs to a deleted group.
  1. . . I +STATUS=12 S MAGCF=MAGCF_"Q" Q
  1. . . ;--- Extend the "non-viewable" group status to the image
  1. . . S MAGVS=MAGVS_"S"
  1. . . S MESSAGES("S")=$$MSG^MAGUERR(-33,,$P(STATUS,U,2))
  1. . . Q
  1. . Q
  1. ;
  1. ;--- Radiology report
  1. ; Reserved but not implemented
  1. ;
  1. ;--- Questionable integrity
  1. D:MAGCF["Q"
  1. . N MAGQI
  1. . D CHK^MAGGSQI(.MAGQI,IEN)
  1. . S:'$G(MAGQI(0)) MAGVS=MAGVS_"Q",MESSAGES("Q")=$P(MAGQI(0),U,2)
  1. . Q
  1. ;
  1. ;---
  1. Q MAGVS
  1. ;+++++ ANNSTAT *******
  1. ; Determine if this image can be annotated.
  1. ; *** INPUT Parameters
  1. ;
  1. ; VSTCODE : The Image 'View Status' numeric code.
  1. ; if this isn't sent as a parameter, it is computed.
  1. ;
  1. ; MAGIEN : Image IEN (^MAG(2005))
  1. ;
  1. ; *** OUTPUT Parameters (optional)
  1. ; DESC : Text Reason for the result;
  1. ;
  1. ; Result Values
  1. ; --------------------------
  1. ; RESULT of this call is a numeric value
  1. ; 0 : success, image can be annotated.
  1. ;
  1. ; Values of STATUS field (113) that are okay.
  1. ; 1 : Viewable (RESULT will be changed to 0)
  1. ; 2 : QA Reviewed (RESULT will be changed to 0)
  1. ;
  1. ;
  1. ; Values of STATUS field (113)
  1. ; that will block Annotation.
  1. ; 10 : Image capture is in progress, (Future for groups.)
  1. ; 11 : Image Needs Review
  1. ; 12 : Image is Deleted.
  1. ; 13 : Image Never Existed. ;p130
  1. ;
  1. ; Values of Image "View Status" that will block Annotation
  1. ; ("View Status" is a computed value, not an IMAGE Field)
  1. ; 21 : Image has Questionable Integrity issues.
  1. ; 22 : User cannot "VIEW" the associated TIU Note.
  1. ; due to TIU Business Rules
  1. ; 23 : Image is not Viewable by Radiology Rule (Future )
  1. ;
  1. ; Values of other codes specific for blocked Annotation
  1. ; 30 : User Cannot "MAKE ADDENDUM" to the associated TIU Note.
  1. ; due to TIU Business Rules
  1. ; 31 : Image in Rescinded.
  1. ;
  1. ;
  1. ANNSTAT(MAGIEN,VSTCODE,DESC) ;Annotation Status
  1. N ANCODE,FLG,STI,VSTCD,TIUIEN,AMND,MSG,X,X2,GRPIEN
  1. ;
  1. S ANCODE=$G(VSTCODE)
  1. S DESC=""
  1. I ANCODE="" D
  1. . ; compute View Status Code if not sent.
  1. . ; QI Check already done in MAGAII ;S FLG="Q"
  1. . S FLG=""
  1. . S VSTCD=$$VIEWSTAT(MAGIEN,FLG,.MSG)
  1. . ; example of Result from $$VIEWSTAT
  1. . ; "" : success , viewable
  1. . ; "QT" : a Text String if not viewable
  1. . ;
  1. . ; -MSG- : is an array of reasons for failure, each letter
  1. . ; of Result is node of array i.e. MSG("Q")="..."
  1. . ; MSG("T")="..."
  1. . ; for this call ANNSTAT, we will just get first entry
  1. . ;
  1. . ;if the View Status Code (VSTCD) is not "", return it's text in MSG
  1. . I VSTCD]"" S X=$O(MSG("")) S DESC=$G(MSG(X))
  1. . S STI=+$P($G(^MAG(2005,MAGIEN,100)),"^",8) ; STATUS (113)
  1. . ;--- Now get View Status Numeric value
  1. . S ANCODE=$$VSTCODE^MAGGAII(VSTCD,STI)
  1. . Q
  1. ;
  1. ; if the View Status Code > 9 then user cannot view the image, so
  1. ; we won't let user annotate the image.
  1. ; and will get a generic description of the code, if DESC is still ""
  1. I (ANCODE>9) S DESC=$S(DESC="":$$VSTTEXT(ANCODE),1:DESC) Q ANCODE
  1. ; if Image is attached to TIU Note, we check TIU Business Rules.
  1. S GRPIEN=$P($G(^MAG(2005,MAGIEN,0)),U,10),GRPIEN=$S(+GRPIEN:GRPIEN,1:MAGIEN)
  1. S X2=$G(^MAG(2005,GRPIEN,2))
  1. I $P(X2,"^",6)=8925 D
  1. . S TIUIEN=$P(X2,"^",7)
  1. . ; If we don't have a pointer to 8925, that is DB corruption
  1. . ; This would probably already be caught,
  1. . ; but check in case. VIEWSTAT wasn't run prior to this call.
  1. . I 'TIUIEN S ANCODE=21,DESC="Invalid pointer to TIU Package ("_TIUIEN_")" Q
  1. . S AMND=$$CANDO^TIULP(TIUIEN,"MAKE ADDENDUM") ;IA#2322
  1. . ; Example of result from TIULP
  1. . ; 0^ You may not ADDEND this UNSIGNED PRIMARY CARE.
  1. . ; 1
  1. . I 'AMND S ANCODE=30,DESC=$P(AMND,"^",2)
  1. . Q
  1. ; if ANCODE > 9 then TIU Business rule says no Annotation.
  1. I (ANCODE>9) S DESC=$S(DESC="":$$VSTTEXT(ANCODE),1:DESC) Q ANCODE
  1. ;
  1. I $P($G(^MAG(2005,MAGIEN,100)),"^",12)=1 D
  1. . ; Image is Rescinded
  1. . S ANCODE=31
  1. . Q
  1. ; if ANCODE > 9 then Image is rescinded and stop Annotation.
  1. I (ANCODE>9) S DESC=$$VSTTEXT(ANCODE) Q ANCODE
  1. ; If we get here, Image can be annotated.
  1. ; - not changing to 0. Status here is 1 or 2 for viewable.
  1. ;S DESC="Image can be annotated."
  1. ; Send exact numeric code. Delphi understands < 10 is viewable
  1. ; and can be annotated.
  1. S DESC=$$VSTTEXT(ANCODE)
  1. Q ANCODE
  1. ;
  1. ; ##### VSTTEXT returns a Description of the Status Code.
  1. ;
  1. ; CODE is the numeric code for the Annotation Status.
  1. ; This is based on Status, Viewable Status, and
  1. ; two new return values for Annotation Status.
  1. ;
  1. VSTTEXT(CODE) ;Description for Annotation Status
  1. N I,DONE,STR
  1. S (I,DONE)=0
  1. F D Q:DONE
  1. . S I=I+1
  1. . S STR=$T(DATA+I)
  1. . I $P(STR,";",3)=CODE S DESC=$P(STR,";",4),DONE=1
  1. . I $P(STR,";",3)="END" S DESC=$P(STR,";",4)_CODE,DONE=1
  1. . Q
  1. Q DESC
  1. ; ##### DATA Table for Image Status, View Status, Annotation Status.
  1. ;
  1. ; the Code is in Piece 3, and the Description is in Piece 4.
  1. ;
  1. ; Image STATUS field (113)
  1. ; Codes 0..12 are the Status Codes from field 113
  1. ;
  1. ; Viewable Status and Annotation Status are computed values,
  1. ; based on, but not equal to STATUS (113)
  1. ; they depend on TIU Business Rules, QI Of image, User Keys.
  1. ; The Codes are computed in other functions. Description of the
  1. ; code is returned from this table.
  1. ;
  1. ; Codes 21..23 are the Viewable Status Codes. (computed value)
  1. ; Codes 30..31 are Annotation Status Codes.
  1. DATA ;
  1. ;;0;Image is Viewable;
  1. ;;1;Image is Viewable.;
  1. ;;2;Image is QA Reviewed.;
  1. ;
  1. ;;10;Image capture is in progress.; (Future for groups.)
  1. ;;11;Image needs review.;
  1. ;;12;Image is deleted.;
  1. ;;13;Image Never Existed.; << p130 for images that didn't exist.
  1. ;
  1. ;;21;Image has Questionable Integrity issues.;
  1. ;;22;User cannot 'View' the associated TIU note. TIU Business Rule.;
  1. ;;23;Image is not Viewable by Radiology Rule.; (future)
  1. ;
  1. ;;30;User cannot 'Make Addendum' to the associated TIU Note. TIU Business Rule.;
  1. ;;31;Image is Rescinded.;
  1. ;;END;User cannot Annotate the Image. Unknown CODE: ;
  1. Q