MAGGTID ;WOIFO/SRR/RED/SAF/GEK/SG/JSL/NST - Deletion of Images and Pointers ;
;;3.0;IMAGING;**8,59,93,118,150,138,167**;Mar 19, 2002;Build 30;Dec 19, 2016
;;
;; 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
;
IMAGEDEL(MAGGRY,MAGIEN,MAGGRPDF,REASON) ;RPC [MAGG IMAGE DELETE]
; Call to Delete Image entry from Image file ^MAG(2005
; MAGIEN Image IEN ^ SYSDEL flag
; MAGGRPDF group delete flag 1 = group delete allowed
; SYSDEL Flag that forces delete, even if no KEY
;
N IEN,Y,RY
; 1 in 3rd piece means : DELETE the Image File Also.
S MAGGRPDF=+$G(MAGGRPDF),REASON=$G(REASON),IEN=+MAGIEN
L +^MAG(2005,IEN):4
E S MAGGRY(0)="Image ID# "_IEN_" is Locked. Delete is Canceled" Q
D DELETE(.MAGGRY,MAGIEN,1,MAGGRPDF,REASON)
L -^MAG(2005,IEN)
Q
DELETE(RY,MAGIEN,DF,GRPDF,REASON) ;RPC [MAGQ DIK] Entry point for silent call
;RY=Return Array RY(0)="1^SUCCESS"
; RY(0)="0^reason for failure"
; ;NOT RETURNING LIST AT THIS TIME
; ( RY(1)..RY(n)= IEN's of deleted images.)
;MAGIEN=Image entry number to be deleted
; if MAGIEN has a 2nd piece = 1 then we force delete, don't test
; for MAG DELETE KEY
; if MAGIEN has a 3rd piece, it's an Xtra PRocessing Flag ;P150
; Patch 129 Capture and Patch 135 Import API Now send this flag. ;P150
;DF=Delete file flag - 1=delete the Image file
; - 0=don't delete the image file
;
S REASON=$G(REASON) I REASON="" S REASON="Unknown reason"
S RY(0)="0^Image Delete Failed, reason unknown."
I '$D(MAGSYS) D
. N Y
. D GETENV^%ZOSV ; IA # 10097
. S MAGSYS=$P(Y,"^",2)
. Q
N MAGERR,SYSDEL,Z,GRPDEL,MAGACN
N XPRC,NOIMG ; P150
S XPRC=$$UP^XLFSTR($P(MAGIEN,U,3)) ;P150 The new $p(,,3) says there is XtraPRocessing.
S SYSDEL=+$P(MAGIEN,U,2),MAGIEN=+MAGIEN
S NOIMG=$S(XPRC="NOIMAGE":1,1:0) ; P150
I NOIMG D NOIMAGE(MAGIEN) ;P150
; Check the business rules for deleting an image
I 'NOIMG D DELETE^MAGSIMBR(.RY,MAGIEN,SYSDEL) I +RY(0)=0 Q ;150 put 'NOIMG
; a couple tests of privilege and valid IEN
I '$D(^MAG(2005,MAGIEN,0)) D Q
. S RY(0)="0^Image entry doesn't exist in image file"
I +$O(^MAG(2005,MAGIEN,1,0)),+$G(GRPDF)=0 D Q
. S RY(0)="0^Deleting a Group is not allowed."
I +$O(^MAG(2005,MAGIEN,1,0)),+$G(GRPDF)'=0 D Q
. N MAGGRP S MAGGRP=MAGIEN N MAGIEN,MAGX,MAGOK,MAGFAIL
. S MAGX=0,MAGOK=0,MAGFAIL=0
. S GRPDEL=1 ; we are deleting a group - used in DELGRP entry
. F S MAGX=$O(^MAG(2005,MAGGRP,1,MAGX)) Q:'MAGX D
. . S MAGIEN=$P($G(^MAG(2005,MAGGRP,1,MAGX,0)),"^") D DEL1IMG
. . I +RY(0) S Z=+$O(RY(""),-1),RY(Z)=RY(Z)_"^"_RY(0),MAGOK=MAGOK+1
. . E S Z=+$O(RY(""),-1)+1,RY(Z)=MAGIEN_"^"_RY(0),MAGFAIL=MAGFAIL+1
. . Q
. I +MAGFAIL=0 S RY(0)="1^Deletion of Group #"_MAGGRP_" was successful.^"_MAGOK_"^0"
. E S RY(0)="0^Error deleting child image(s). Group Not Deleted.^"_MAGOK_"^"_MAGFAIL
. I (+MAGFAIL=0),$G(MAGACN)'="" D ; No errors and Accession number exists
. . N SSEP,OUT
. . S SSEP=$$STATSEP^MAGVRS41
. . D DELNEW^MAGVD008(.OUT,MAGACN,REASON) ; Delete studies in P34 data structure by accession number
. . I OUT<0 S RY(0)="0^Deletion of Group #"_MAGGRP_" was successful but failed in New: "_$P(OUT,SSEP,2)
. . Q
. Q
; Ok lets start
; lets delete the parent pointers first.
DEL1IMG ;
N DELMSG,Z,MAGDFN
D DELPAR^MAGSDEL2
I $G(MAGERR) S RY(0)="0^Error: Deleting Specialty Pointers. Image Not Deleted. "_DELMSG Q
;
; Now delete image record & xref's
; if this Image is member of group DELGRP will delete those pointers
; and delete the Group, if this is only image in it.
S MAGDFN=$P($G(^MAG(2005,MAGIEN,0)),"^",7) ; Moved here from below. DELGRP needs MAGDFN now.
D DELGRP
I $G(MAGERR) S RY(0)="0^Error deleting Group Pointers." Q
;
; write the deleted by, delete reason, and delete date to the file.
; P150 If NOIMAGE, SetDel was already called.
I 'NOIMG D SETDEL(MAGIEN,REASON) ;P150 NOIMG
;
; save the Image record to the archive before we delete it.
D ARCHIVE(MAGIEN)
;
; Now let's set the Queue to delete the Image File, if Flag is set
I $G(DF) D DELFILE
;
; we're having "APPXDT" crossref left around, lets delete it first.
S X=MAGDFN,DA=MAGIEN D KILPPXD^MAGUXRF
;
; now lets delete the image.
K DIK,DA,DA(1),DA(2),DIC,DR,DIE,DIR S DIK="^MAG(2005,",DA=MAGIEN
D ^DIK
S Z=+$O(RY(""),-1)+1,RY(Z)=MAGIEN
; we were having problems with "AC" so lets check to make sure.
I $D(^MAG(2005,"AC",MAGDFN,MAGIEN)) K ^MAG(2005,"AC",MAGDFN,MAGIEN)
; log it.
S X=$S(NOIMG:"NOIMAGE",1:"DELETE") ; P150 NOIMG
D ENTRY^MAGLOG(X,$G(DUZ),$G(MAGIEN),"PARENT:"_$G(MAGSTORE),$G(MAGDFN),1) ;P150
S X=$S(NOIMG:"NOIMAGE^",1:"DEL^") ; 150 NOIMG
S X=X_$G(MAGDFN)_"^"_$G(MAGIEN) ; 150 use X instead of "DEL^"
D ACTION^MAGGTAU(X,"1")
; The 140 cross reference of 2005.1 has set the Status to 12, here we change it to 13 ;P150
I NOIMG D SETSTAT(MAGIEN,13) ;P150
S RY(0)="1^Deletion of Image was Successful." ;P150
; P150 Put above line back in. Code below is new for 118.
I '$G(GRPDEL),$G(MAGACN)'="" D ; If we delete a single image in a group and ACN is defined
. N SSEP,OUT
. S SSEP=$$STATSEP^MAGVRS41
. D DELNEW^MAGVD008(.OUT,MAGACN,REASON) ; Delete studies in P34 data structure by accession number
. I OUT<0 S RY(0)="0^Deletion of Image in Legacy was Successful but failed in New: "_$P(OUT,SSEP,2)
. E S RY(0)="1^Deletion of Image was Successful."
. Q
Q
NOIMAGE(MAGNOT) ; P150 Whole function is new. This is called when No Image exists.
; Clear the Fields #2, #2.1 and 102 This is the Abstract, Full and BIG
; pointers to the Image Share (Image Network Drive) ( Tier1 )
; Set Status and Status Reason
; Set SysDel and GrpDel Flags to allow deleting in all instances.
N MAGNFDA,MAGGXE,MAGERR,REASDESC,REASDA,MAGDA
S REASDESC="Image Never Existed"
S REASDA=$O(^MAG(2005.88,"B",REASDESC,""))
D SETDEL(MAGNOT,REASDESC) ; Set the Delete Fields.
;
S MAGDA=MAGNOT
S MAGNOT=MAGNOT_","
S MAGNFDA(2005,MAGNOT,2)="@" ;
S MAGNFDA(2005,MAGNOT,2.1)="@"
S MAGNFDA(2005,MAGNOT,102)="@"
S MAGNFDA(2005,MAGNOT,113)=13
S MAGNFDA(2005,MAGNOT,113.3)=REASDA
;;;;;;;
D UPDATE^DIE("","MAGNFDA","","MAGGXE")
; ? ? If Error during UPdate.. Delete the entry.
I $D(DIERR) D S RY=MAGERR Q
. D RTRNERR(.MAGERR)
. S DA=MAGDA,DIK="^MAG(2005," D ^DIK
. K DA,DIC,DIK
. D CLEAN^DILF
Q
RTRNERR(ETXT) ; There was error from UPDATE^DIE quit with error text
; P150 this function put in to keep NOIMAGE same
S ETXT="0^ERROR "_MAGGXE("DIERR",1,"TEXT",1)
Q
DELGRP ;del grp ptrs and check to see if this is the last image in the group
N MAGGRP,MAGX,MAGQUIT,MAGIFNS,Z
S MAGGRP=$P($G(^MAG(2005,MAGIEN,0)),"^",10)
Q:'$G(MAGGRP)
K DIK,DA,DA(1),DA(2),DIC,DR,DIE,DIR
S MAGX=0,MAGQUIT=0
F S MAGX=$O(^MAG(2005,MAGGRP,1,MAGX)) Q:'MAGX D Q:MAGQUIT
. I +^MAG(2005,MAGGRP,1,MAGX,0)=MAGIEN D
. . S DIK="^MAG(2005,MAGGRP,1,",DA(1)=MAGGRP,DA=MAGX D ^DIK S MAGQUIT=1
. . ;added DA(1) needed for xref deletion of dicom series
. I $O(^MAG(2005,MAGGRP,1,0))="" D
. . I $P($G(^MAG(2005,MAGGRP,2)),"^",6) D
. . . ;report is on group - need to delete it
. . . S MAGIFNS=MAGIEN,MAGIEN=MAGGRP
. . . D DELPAR^MAGSDEL2
. . . S MAGIEN=MAGIFNS
. . I '$D(MAGERR) D
. . . I $T(^MAGVD003)'="" D ; This check needs to be removed after release of patch 118
. . . . N OUT
. . . . D GETACN^MAGVD003(.OUT,MAGGRP) ; Get accession number for this group first
. . . . S MAGACN=$S($$ISOK^MAGVAF02(OUT):$$GETVAL^MAGVAF02(OUT),1:"")
. . . . Q
. . . D SETDEL(MAGGRP,REASON),ARCHIVE(MAGGRP) S DIK="^MAG(2005,",DA=MAGGRP D ^DIK
. . . ; Log the Deletion of The Group Header to ^MAG(2006.95, and ^MAG(2006.82
. . . D ENTRY^MAGLOG("DELETE",$G(DUZ),$G(MAGGRP),"PARENT:"_$G(MAGSTORE),$G(MAGDFN),1,"Group Header deleted")
. . . S X="DEL^"_$G(MAGDFN)_"^"_$G(MAGGRP)
. . . D ACTION^MAGGTAU(X,"1")
. . . S Z=+$O(RY(""),-1)+1,RY(Z)=MAGGRP_"^1^Deletion of Group was Successful."
. . . Q
. . Q
. Q
Q
SETDEL(MAGIEN,REASON) ; set deletion fields
N DA,DR,DIE,X
;N %H
;S %H=$H D YMD^%DTC
S X=$$NOW^XLFDT
; gek - changed 3 slash to 4 slash. to stop FM question marks. ??
S DR="30////"_DUZ_";30.1////"_X_";30.2////"_REASON
S DIE="2005",DA=MAGIEN D ^DIE
Q
;
SETSTAT(MAGIEN,STAT) ; p150 new function. Set STATUS fields
N DA,DR,DIE
; 4 slash. to stop FM question marks. ??
S DR="113////"_STAT
S DIE="2005.1",DA=MAGIEN D ^DIE
Q
ARCHIVE(MAGARCIE) ;save image data before deletion
N DA,DIK,MAGCNT,MAGLAST,SUB,TMP,%X,%Y
S MAGCNT=$P(^MAG(2005.1,0),U,4)+1
S %X="^MAG(2005,"_MAGARCIE_",",%Y="^MAG(2005.1,"_MAGARCIE_","
D %XY^%RCR
;--- GEK 9/29/00 Fix the 3rd piece to be last IEN in file.
S MAGLAST=$O(^MAG(2005.1,"A"),-1)
S $P(^MAG(2005.1,0),U,4)=MAGCNT
I '($P(^MAG(2005.1,0),U,3)=MAGLAST) S $P(^MAG(2005.1,0),U,3)=MAGLAST
;
;--- Fix subfile numbers in the headers of the multiples (MAG*3*93).
; IF DEFINITIONS OF MULTIPLES OF THE IMAGE AUDIT FILE (#2005.1)
; CHANGE OR NEW MULTIPLES ARE ADDED, THE FOLLOWING CODE MUST BE
;--- CHECKED AND UPDATED IF NECESSARY!
;
F SUB="1^2005.14P","4^2005.1106DA","5^2005.11PA","6^2005.1111A","99^2005.199D" D
. S TMP=$P(SUB,U) Q:'($D(^MAG(2005.1,MAGARCIE,TMP,0))#2)
. S $P(^MAG(2005.1,MAGARCIE,TMP,0),U,2)=$P(SUB,U,2)
. Q
;
;--- Create cross-reference entries for the entry
S DA=MAGARCIE
S DIK="^MAG(2005.1," D IX1^DIK
Q
DELFILE ;Delete image file on server if exists
;gek 3/21/2003 Changed to stop using FullRes Path for Abs,Big
; and only Delete .TXT and Alternates if Full is being deleted.
N X0,X1,X2,ALTEXT,ALTPATH,MAGXX,XBIG,MAGFILE2
N MAGPLC ; DBI - SEB 9/20/2002
; MAGIEN IS ASSUMED TO BE DEFINED.
; MAGXX - This is IEN in ^MAG(2005, MAGFILEB Expects this to be defined.
; MAGPLC - "Place" of Full Res Image.
; ALTEXT - Extension of the Alternate image file.
; ALTPATH - Full path of Alternate image file.
S X0=^MAG(2005,MAGIEN,0)
;delete Full Res if one exists on Magnetic
I $P(X0,U,3) D
. S MAGXX=MAGIEN
. S MAGPLC=$$DA2PLC^MAGBAPIP(MAGIEN,"F")
. D VSTNOCP^MAGFILEB
. S X=$$DELETE^MAGBAPI(MAGFILE2,MAGPLC)
. ;Delete any other ALTernate files. ( TXT)
. ;gek 3/31/03 Since ALT files are (for now) always on same server as Full
. ; We only attempt to delete them here (If we have a path to FullRes on Magnetic)
. S X2=0
. F S X2=$O(^MAG(2006.1,MAGPLC,2,X2)) Q:'X2 D
. . S ALTEXT=$P(^MAG(2006.1,MAGPLC,2,X2,0),"^",1) ;CR1023
. . S ALTPATH=MAGFILE2,$P(ALTPATH,".",$L(ALTPATH,"."))=ALTEXT ;CR1023 for FQDN issue
. . S X=$$DELETE^MAGBAPI(ALTPATH,MAGPLC)
. Q
;
;delete image abstract if one exists on Magnetic
I $P(X0,U,4) D
. S MAGXX=MAGIEN
. D ABSNOCP^MAGFILEB
. S X=$$DELETE^MAGBAPI(MAGFILE2,$$DA2PLC^MAGBAPIP(MAGIEN,"A")) ; DBI - SEB 9/20/2002
;
;delete the big file if one exists on Magnetic
S XBIG=$G(^MAG(2005,MAGIEN,"FBIG"))
I $P(XBIG,U) D
. S MAGXX=MAGIEN
. D BIGNOCP^MAGFILEB
. S X=$$DELETE^MAGBAPI(MAGFILE2,$$DA2PLC^MAGBAPIP(MAGIEN,"B")) ; DBI - SEB 9/20/2002
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGGTID 12141 printed Dec 13, 2024@02:03:01 Page 2
MAGGTID ;WOIFO/SRR/RED/SAF/GEK/SG/JSL/NST - Deletion of Images and Pointers ;
+1 ;;3.0;IMAGING;**8,59,93,118,150,138,167**;Mar 19, 2002;Build 30;Dec 19, 2016
+2 ;;
+3 ;; Per VHA Directive 2004-038, this routine should not be modified.
+4 ;; +---------------------------------------------------------------+
+5 ;; | Property of the US Government. |
+6 ;; | No permission to copy or redistribute this software is given. |
+7 ;; | Use of unreleased versions of this software requires the user |
+8 ;; | to execute a written test agreement with the VistA Imaging |
+9 ;; | Development Office of the Department of Veterans Affairs, |
+10 ;; | telephone (301) 734-0100. |
+11 ;; | The Food and Drug Administration classifies this software as |
+12 ;; | a medical device. As such, it may not be changed in any way. |
+13 ;; | Modifications to this software may result in an adulterated |
+14 ;; | medical device under 21CFR820, the use of which is considered |
+15 ;; | to be a violation of US Federal Statutes. |
+16 ;; +---------------------------------------------------------------+
+17 ;;
+18 QUIT
+19 ;
IMAGEDEL(MAGGRY,MAGIEN,MAGGRPDF,REASON) ;RPC [MAGG IMAGE DELETE]
+1 ; Call to Delete Image entry from Image file ^MAG(2005
+2 ; MAGIEN Image IEN ^ SYSDEL flag
+3 ; MAGGRPDF group delete flag 1 = group delete allowed
+4 ; SYSDEL Flag that forces delete, even if no KEY
+5 ;
+6 NEW IEN,Y,RY
+7 ; 1 in 3rd piece means : DELETE the Image File Also.
+8 SET MAGGRPDF=+$GET(MAGGRPDF)
SET REASON=$GET(REASON)
SET IEN=+MAGIEN
+9 LOCK +^MAG(2005,IEN):4
+10 IF '$TEST
SET MAGGRY(0)="Image ID# "_IEN_" is Locked. Delete is Canceled"
QUIT
+11 DO DELETE(.MAGGRY,MAGIEN,1,MAGGRPDF,REASON)
+12 LOCK -^MAG(2005,IEN)
+13 QUIT
DELETE(RY,MAGIEN,DF,GRPDF,REASON) ;RPC [MAGQ DIK] Entry point for silent call
+1 ;RY=Return Array RY(0)="1^SUCCESS"
+2 ; RY(0)="0^reason for failure"
+3 ; ;NOT RETURNING LIST AT THIS TIME
+4 ; ( RY(1)..RY(n)= IEN's of deleted images.)
+5 ;MAGIEN=Image entry number to be deleted
+6 ; if MAGIEN has a 2nd piece = 1 then we force delete, don't test
+7 ; for MAG DELETE KEY
+8 ; if MAGIEN has a 3rd piece, it's an Xtra PRocessing Flag ;P150
+9 ; Patch 129 Capture and Patch 135 Import API Now send this flag. ;P150
+10 ;DF=Delete file flag - 1=delete the Image file
+11 ; - 0=don't delete the image file
+12 ;
+13 SET REASON=$GET(REASON)
IF REASON=""
SET REASON="Unknown reason"
+14 SET RY(0)="0^Image Delete Failed, reason unknown."
+15 IF '$DATA(MAGSYS)
Begin DoDot:1
+16 NEW Y
+17 ; IA # 10097
DO GETENV^%ZOSV
+18 SET MAGSYS=$PIECE(Y,"^",2)
+19 QUIT
End DoDot:1
+20 NEW MAGERR,SYSDEL,Z,GRPDEL,MAGACN
+21 ; P150
NEW XPRC,NOIMG
+22 ;P150 The new $p(,,3) says there is XtraPRocessing.
SET XPRC=$$UP^XLFSTR($PIECE(MAGIEN,U,3))
+23 SET SYSDEL=+$PIECE(MAGIEN,U,2)
SET MAGIEN=+MAGIEN
+24 ; P150
SET NOIMG=$SELECT(XPRC="NOIMAGE":1,1:0)
+25 ;P150
IF NOIMG
DO NOIMAGE(MAGIEN)
+26 ; Check the business rules for deleting an image
+27 ;150 put 'NOIMG
IF 'NOIMG
DO DELETE^MAGSIMBR(.RY,MAGIEN,SYSDEL)
IF +RY(0)=0
QUIT
+28 ; a couple tests of privilege and valid IEN
+29 IF '$DATA(^MAG(2005,MAGIEN,0))
Begin DoDot:1
+30 SET RY(0)="0^Image entry doesn't exist in image file"
End DoDot:1
QUIT
+31 IF +$ORDER(^MAG(2005,MAGIEN,1,0))
IF +$GET(GRPDF)=0
Begin DoDot:1
+32 SET RY(0)="0^Deleting a Group is not allowed."
End DoDot:1
QUIT
+33 IF +$ORDER(^MAG(2005,MAGIEN,1,0))
IF +$GET(GRPDF)'=0
Begin DoDot:1
+34 NEW MAGGRP
SET MAGGRP=MAGIEN
NEW MAGIEN,MAGX,MAGOK,MAGFAIL
+35 SET MAGX=0
SET MAGOK=0
SET MAGFAIL=0
+36 ; we are deleting a group - used in DELGRP entry
SET GRPDEL=1
+37 FOR
SET MAGX=$ORDER(^MAG(2005,MAGGRP,1,MAGX))
if 'MAGX
QUIT
Begin DoDot:2
+38 SET MAGIEN=$PIECE($GET(^MAG(2005,MAGGRP,1,MAGX,0)),"^")
DO DEL1IMG
+39 IF +RY(0)
SET Z=+$ORDER(RY(""),-1)
SET RY(Z)=RY(Z)_"^"_RY(0)
SET MAGOK=MAGOK+1
+40 IF '$TEST
SET Z=+$ORDER(RY(""),-1)+1
SET RY(Z)=MAGIEN_"^"_RY(0)
SET MAGFAIL=MAGFAIL+1
+41 QUIT
End DoDot:2
+42 IF +MAGFAIL=0
SET RY(0)="1^Deletion of Group #"_MAGGRP_" was successful.^"_MAGOK_"^0"
+43 IF '$TEST
SET RY(0)="0^Error deleting child image(s). Group Not Deleted.^"_MAGOK_"^"_MAGFAIL
+44 ; No errors and Accession number exists
IF (+MAGFAIL=0)
IF $GET(MAGACN)'=""
Begin DoDot:2
+45 NEW SSEP,OUT
+46 SET SSEP=$$STATSEP^MAGVRS41
+47 ; Delete studies in P34 data structure by accession number
DO DELNEW^MAGVD008(.OUT,MAGACN,REASON)
+48 IF OUT<0
SET RY(0)="0^Deletion of Group #"_MAGGRP_" was successful but failed in New: "_$PIECE(OUT,SSEP,2)
+49 QUIT
End DoDot:2
+50 QUIT
End DoDot:1
QUIT
+51 ; Ok lets start
+52 ; lets delete the parent pointers first.
DEL1IMG ;
+1 NEW DELMSG,Z,MAGDFN
+2 DO DELPAR^MAGSDEL2
+3 IF $GET(MAGERR)
SET RY(0)="0^Error: Deleting Specialty Pointers. Image Not Deleted. "_DELMSG
QUIT
+4 ;
+5 ; Now delete image record & xref's
+6 ; if this Image is member of group DELGRP will delete those pointers
+7 ; and delete the Group, if this is only image in it.
+8 ; Moved here from below. DELGRP needs MAGDFN now.
SET MAGDFN=$PIECE($GET(^MAG(2005,MAGIEN,0)),"^",7)
+9 DO DELGRP
+10 IF $GET(MAGERR)
SET RY(0)="0^Error deleting Group Pointers."
QUIT
+11 ;
+12 ; write the deleted by, delete reason, and delete date to the file.
+13 ; P150 If NOIMAGE, SetDel was already called.
+14 ;P150 NOIMG
IF 'NOIMG
DO SETDEL(MAGIEN,REASON)
+15 ;
+16 ; save the Image record to the archive before we delete it.
+17 DO ARCHIVE(MAGIEN)
+18 ;
+19 ; Now let's set the Queue to delete the Image File, if Flag is set
+20 IF $GET(DF)
DO DELFILE
+21 ;
+22 ; we're having "APPXDT" crossref left around, lets delete it first.
+23 SET X=MAGDFN
SET DA=MAGIEN
DO KILPPXD^MAGUXRF
+24 ;
+25 ; now lets delete the image.
+26 KILL DIK,DA,DA(1),DA(2),DIC,DR,DIE,DIR
SET DIK="^MAG(2005,"
SET DA=MAGIEN
+27 DO ^DIK
+28 SET Z=+$ORDER(RY(""),-1)+1
SET RY(Z)=MAGIEN
+29 ; we were having problems with "AC" so lets check to make sure.
+30 IF $DATA(^MAG(2005,"AC",MAGDFN,MAGIEN))
KILL ^MAG(2005,"AC",MAGDFN,MAGIEN)
+31 ; log it.
+32 ; P150 NOIMG
SET X=$SELECT(NOIMG:"NOIMAGE",1:"DELETE")
+33 ;P150
DO ENTRY^MAGLOG(X,$GET(DUZ),$GET(MAGIEN),"PARENT:"_$GET(MAGSTORE),$GET(MAGDFN),1)
+34 ; 150 NOIMG
SET X=$SELECT(NOIMG:"NOIMAGE^",1:"DEL^")
+35 ; 150 use X instead of "DEL^"
SET X=X_$GET(MAGDFN)_"^"_$GET(MAGIEN)
+36 DO ACTION^MAGGTAU(X,"1")
+37 ; The 140 cross reference of 2005.1 has set the Status to 12, here we change it to 13 ;P150
+38 ;P150
IF NOIMG
DO SETSTAT(MAGIEN,13)
+39 ;P150
SET RY(0)="1^Deletion of Image was Successful."
+40 ; P150 Put above line back in. Code below is new for 118.
+41 ; If we delete a single image in a group and ACN is defined
IF '$GET(GRPDEL)
IF $GET(MAGACN)'=""
Begin DoDot:1
+42 NEW SSEP,OUT
+43 SET SSEP=$$STATSEP^MAGVRS41
+44 ; Delete studies in P34 data structure by accession number
DO DELNEW^MAGVD008(.OUT,MAGACN,REASON)
+45 IF OUT<0
SET RY(0)="0^Deletion of Image in Legacy was Successful but failed in New: "_$PIECE(OUT,SSEP,2)
+46 IF '$TEST
SET RY(0)="1^Deletion of Image was Successful."
+47 QUIT
End DoDot:1
+48 QUIT
NOIMAGE(MAGNOT) ; P150 Whole function is new. This is called when No Image exists.
+1 ; Clear the Fields #2, #2.1 and 102 This is the Abstract, Full and BIG
+2 ; pointers to the Image Share (Image Network Drive) ( Tier1 )
+3 ; Set Status and Status Reason
+4 ; Set SysDel and GrpDel Flags to allow deleting in all instances.
+5 NEW MAGNFDA,MAGGXE,MAGERR,REASDESC,REASDA,MAGDA
+6 SET REASDESC="Image Never Existed"
+7 SET REASDA=$ORDER(^MAG(2005.88,"B",REASDESC,""))
+8 ; Set the Delete Fields.
DO SETDEL(MAGNOT,REASDESC)
+9 ;
+10 SET MAGDA=MAGNOT
+11 SET MAGNOT=MAGNOT_","
+12 ;
SET MAGNFDA(2005,MAGNOT,2)="@"
+13 SET MAGNFDA(2005,MAGNOT,2.1)="@"
+14 SET MAGNFDA(2005,MAGNOT,102)="@"
+15 SET MAGNFDA(2005,MAGNOT,113)=13
+16 SET MAGNFDA(2005,MAGNOT,113.3)=REASDA
+17 ;;;;;;;
+18 DO UPDATE^DIE("","MAGNFDA","","MAGGXE")
+19 ; ? ? If Error during UPdate.. Delete the entry.
+20 IF $DATA(DIERR)
Begin DoDot:1
+21 DO RTRNERR(.MAGERR)
+22 SET DA=MAGDA
SET DIK="^MAG(2005,"
DO ^DIK
+23 KILL DA,DIC,DIK
+24 DO CLEAN^DILF
End DoDot:1
SET RY=MAGERR
QUIT
+25 QUIT
RTRNERR(ETXT) ; There was error from UPDATE^DIE quit with error text
+1 ; P150 this function put in to keep NOIMAGE same
+2 SET ETXT="0^ERROR "_MAGGXE("DIERR",1,"TEXT",1)
+3 QUIT
DELGRP ;del grp ptrs and check to see if this is the last image in the group
+1 NEW MAGGRP,MAGX,MAGQUIT,MAGIFNS,Z
+2 SET MAGGRP=$PIECE($GET(^MAG(2005,MAGIEN,0)),"^",10)
+3 if '$GET(MAGGRP)
QUIT
+4 KILL DIK,DA,DA(1),DA(2),DIC,DR,DIE,DIR
+5 SET MAGX=0
SET MAGQUIT=0
+6 FOR
SET MAGX=$ORDER(^MAG(2005,MAGGRP,1,MAGX))
if 'MAGX
QUIT
Begin DoDot:1
+7 IF +^MAG(2005,MAGGRP,1,MAGX,0)=MAGIEN
Begin DoDot:2
+8 SET DIK="^MAG(2005,MAGGRP,1,"
SET DA(1)=MAGGRP
SET DA=MAGX
DO ^DIK
SET MAGQUIT=1
+9 ;added DA(1) needed for xref deletion of dicom series
End DoDot:2
+10 IF $ORDER(^MAG(2005,MAGGRP,1,0))=""
Begin DoDot:2
+11 IF $PIECE($GET(^MAG(2005,MAGGRP,2)),"^",6)
Begin DoDot:3
+12 ;report is on group - need to delete it
+13 SET MAGIFNS=MAGIEN
SET MAGIEN=MAGGRP
+14 DO DELPAR^MAGSDEL2
+15 SET MAGIEN=MAGIFNS
End DoDot:3
+16 IF '$DATA(MAGERR)
Begin DoDot:3
+17 ; This check needs to be removed after release of patch 118
IF $TEXT(^MAGVD003)'=""
Begin DoDot:4
+18 NEW OUT
+19 ; Get accession number for this group first
DO GETACN^MAGVD003(.OUT,MAGGRP)
+20 SET MAGACN=$SELECT($$ISOK^MAGVAF02(OUT):$$GETVAL^MAGVAF02(OUT),1:"")
+21 QUIT
End DoDot:4
+22 DO SETDEL(MAGGRP,REASON)
DO ARCHIVE(MAGGRP)
SET DIK="^MAG(2005,"
SET DA=MAGGRP
DO ^DIK
+23 ; Log the Deletion of The Group Header to ^MAG(2006.95, and ^MAG(2006.82
+24 DO ENTRY^MAGLOG("DELETE",$GET(DUZ),$GET(MAGGRP),"PARENT:"_$GET(MAGSTORE),$GET(MAGDFN),1,"Group Header deleted")
+25 SET X="DEL^"_$GET(MAGDFN)_"^"_$GET(MAGGRP)
+26 DO ACTION^MAGGTAU(X,"1")
+27 SET Z=+$ORDER(RY(""),-1)+1
SET RY(Z)=MAGGRP_"^1^Deletion of Group was Successful."
+28 QUIT
End DoDot:3
+29 QUIT
End DoDot:2
+30 QUIT
End DoDot:1
if MAGQUIT
QUIT
+31 QUIT
SETDEL(MAGIEN,REASON) ; set deletion fields
+1 NEW DA,DR,DIE,X
+2 ;N %H
+3 ;S %H=$H D YMD^%DTC
+4 SET X=$$NOW^XLFDT
+5 ; gek - changed 3 slash to 4 slash. to stop FM question marks. ??
+6 SET DR="30////"_DUZ_";30.1////"_X_";30.2////"_REASON
+7 SET DIE="2005"
SET DA=MAGIEN
DO ^DIE
+8 QUIT
+9 ;
SETSTAT(MAGIEN,STAT) ; p150 new function. Set STATUS fields
+1 NEW DA,DR,DIE
+2 ; 4 slash. to stop FM question marks. ??
+3 SET DR="113////"_STAT
+4 SET DIE="2005.1"
SET DA=MAGIEN
DO ^DIE
+5 QUIT
ARCHIVE(MAGARCIE) ;save image data before deletion
+1 NEW DA,DIK,MAGCNT,MAGLAST,SUB,TMP,%X,%Y
+2 SET MAGCNT=$PIECE(^MAG(2005.1,0),U,4)+1
+3 SET %X="^MAG(2005,"_MAGARCIE_","
SET %Y="^MAG(2005.1,"_MAGARCIE_","
+4 DO %XY^%RCR
+5 ;--- GEK 9/29/00 Fix the 3rd piece to be last IEN in file.
+6 SET MAGLAST=$ORDER(^MAG(2005.1,"A"),-1)
+7 SET $PIECE(^MAG(2005.1,0),U,4)=MAGCNT
+8 IF '($PIECE(^MAG(2005.1,0),U,3)=MAGLAST)
SET $PIECE(^MAG(2005.1,0),U,3)=MAGLAST
+9 ;
+10 ;--- Fix subfile numbers in the headers of the multiples (MAG*3*93).
+11 ; IF DEFINITIONS OF MULTIPLES OF THE IMAGE AUDIT FILE (#2005.1)
+12 ; CHANGE OR NEW MULTIPLES ARE ADDED, THE FOLLOWING CODE MUST BE
+13 ;--- CHECKED AND UPDATED IF NECESSARY!
+14 ;
+15 FOR SUB="1^2005.14P","4^2005.1106DA","5^2005.11PA","6^2005.1111A","99^2005.199D"
Begin DoDot:1
+16 SET TMP=$PIECE(SUB,U)
if '($DATA(^MAG(2005.1,MAGARCIE,TMP,0))#2)
QUIT
+17 SET $PIECE(^MAG(2005.1,MAGARCIE,TMP,0),U,2)=$PIECE(SUB,U,2)
+18 QUIT
End DoDot:1
+19 ;
+20 ;--- Create cross-reference entries for the entry
+21 SET DA=MAGARCIE
+22 SET DIK="^MAG(2005.1,"
DO IX1^DIK
+23 QUIT
DELFILE ;Delete image file on server if exists
+1 ;gek 3/21/2003 Changed to stop using FullRes Path for Abs,Big
+2 ; and only Delete .TXT and Alternates if Full is being deleted.
+3 NEW X0,X1,X2,ALTEXT,ALTPATH,MAGXX,XBIG,MAGFILE2
+4 ; DBI - SEB 9/20/2002
NEW MAGPLC
+5 ; MAGIEN IS ASSUMED TO BE DEFINED.
+6 ; MAGXX - This is IEN in ^MAG(2005, MAGFILEB Expects this to be defined.
+7 ; MAGPLC - "Place" of Full Res Image.
+8 ; ALTEXT - Extension of the Alternate image file.
+9 ; ALTPATH - Full path of Alternate image file.
+10 SET X0=^MAG(2005,MAGIEN,0)
+11 ;delete Full Res if one exists on Magnetic
+12 IF $PIECE(X0,U,3)
Begin DoDot:1
+13 SET MAGXX=MAGIEN
+14 SET MAGPLC=$$DA2PLC^MAGBAPIP(MAGIEN,"F")
+15 DO VSTNOCP^MAGFILEB
+16 SET X=$$DELETE^MAGBAPI(MAGFILE2,MAGPLC)
+17 ;Delete any other ALTernate files. ( TXT)
+18 ;gek 3/31/03 Since ALT files are (for now) always on same server as Full
+19 ; We only attempt to delete them here (If we have a path to FullRes on Magnetic)
+20 SET X2=0
+21 FOR
SET X2=$ORDER(^MAG(2006.1,MAGPLC,2,X2))
if 'X2
QUIT
Begin DoDot:2
+22 ;CR1023
SET ALTEXT=$PIECE(^MAG(2006.1,MAGPLC,2,X2,0),"^",1)
+23 ;CR1023 for FQDN issue
SET ALTPATH=MAGFILE2
SET $PIECE(ALTPATH,".",$LENGTH(ALTPATH,"."))=ALTEXT
+24 SET X=$$DELETE^MAGBAPI(ALTPATH,MAGPLC)
End DoDot:2
+25 QUIT
End DoDot:1
+26 ;
+27 ;delete image abstract if one exists on Magnetic
+28 IF $PIECE(X0,U,4)
Begin DoDot:1
+29 SET MAGXX=MAGIEN
+30 DO ABSNOCP^MAGFILEB
+31 ; DBI - SEB 9/20/2002
SET X=$$DELETE^MAGBAPI(MAGFILE2,$$DA2PLC^MAGBAPIP(MAGIEN,"A"))
End DoDot:1
+32 ;
+33 ;delete the big file if one exists on Magnetic
+34 SET XBIG=$GET(^MAG(2005,MAGIEN,"FBIG"))
+35 IF $PIECE(XBIG,U)
Begin DoDot:1
+36 SET MAGXX=MAGIEN
+37 DO BIGNOCP^MAGFILEB
+38 ; DBI - SEB 9/20/2002
SET X=$$DELETE^MAGBAPI(MAGFILE2,$$DA2PLC^MAGBAPIP(MAGIEN,"B"))
End DoDot:1
+39 QUIT