MAGNAN03 ;WOIFO/NST - Get image annotations ; 10 Apr 2018 3:59 PM
;;3.0;IMAGING;**185,197**;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 image annotations by CPRS context or Image IEN
;
; RPC: MAGN ANNOT GET IMAGE ANNOT
;
; Input Parameters
; ================
;
; DATA - ContextID in format
; e.g. 'RPT^CPRS^29027^RA^79029185.9998-1'
; or
; RPT^CPRS^4658^TIU^2243408^^^^^^^^1
; or
; ^ ^ ^MAG^10454
;
; Return Values
; =============
;
; if error MAGRY(0) = 0 ^Error message^
; if success MAGRY(0) = 1
; MAGRY(1..n) = NEXT_CONTEXTID | CONTEXTID | 0 or 1 |
; NEXT_IMAGE | IMAGE IEN
; images in format defined in RPC [MAGJ STUDY_DATA] or
; [MAG ANNOT GET IMAGE DETAIL], [MAG ANNOT GET IMAGE]
;
IMAGEL(MAGRY,DATA) ;RPC [MAGN ANNOT GET IMAGE ANNOT]
N MAGNCNT,MAGNX,RARPT
N $ETRAP,$ESTACK S $ETRAP="D AERRA^MAGGTERR"
S MAGRY=$NA(^TMP("MAGNTRAI",$J))
K @MAGRY
S @MAGRY@(0)=0
S MAGNCNT=0
S MAGNX=$P(DATA,"^",4)
I MAGNX="RA" D Q
. D GRAANNCX(MAGRY,MAGNCNT,DATA) ; get RAD annotations
. Q
;
I MAGNX="TIU" D Q
. D GTUIANN(MAGRY,MAGNCNT,DATA) ; Get TIU annotations
. Q
;
I MAGNX="MAG" D Q
. D GMAGANN(MAGRY,MAGNCNT,DATA) ; Get TIU annotations
. Q
;
S MAGNCNT=MAGNCNT+1
S @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_DATA_"|0|"_"Invalid ContextId Type"
S @MAGRY@(0)=1
Q
;
GRAANNCX(MAGRY,MAGNCNT,MAGNCXT) ; Get RAD annotations by CPRS Context ID
N MAGX,MAGNRPT,DATA
;
S MAGNRPT=$$GRARPT(MAGNCXT) ; Get RA Report IEN by CPRS Context
S MAGNCNT=MAGNCNT+1
S @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_MAGNCXT_"|"_MAGNRPT_"|RAD"
I MAGNRPT'>0 Q
;
; e.g. MAGNCXT=RPT^CPRS^29027^RA^79029185.9998-1
; See MAGJEX3
; MAGX--TXID ^ DFN ^ DTI ^ CNI ^ RARPT ^ MAGIEN ^ PSDETAIL
S $P(MAGX,"^",1)=3 ; TXID Key and Interp Images
S $P(MAGX,"^",2)=$P(MAGNCXT,"^",3) ; DFN
S $P(MAGX,"^",3)=$P($P(MAGNCXT,"^",5),"-",1)
S $P(MAGX,"^",4)=$P($P(MAGNCXT,"^",5),"-",2)
S $P(MAGX,"^",5)=MAGNRPT ; Report IEN
S $P(MAGX,"^",7)=1 ; PSDETAIL
;
D GRAANN(MAGRY,.MAGNCNT,MAGNCXT,MAGX)
;
; Get Clinical Annotations
D GIMGRARP(.DATA,MAGNRPT)
D GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA)
Q
;
GRAANNRP(MAGRY,MAGNCNT,MAGNCXT,MAGNRPT) ; Get RAD annotations by RA Report
N MAGX
;
S MAGNCNT=MAGNCNT+1
S @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_MAGNCXT_"|"_MAGNRPT_"|RAD"
I MAGNRPT'>0 Q
;
; e.g. MAGNCXT=^^^MAG^10454
; See MAGJEX3
; MAGX--TXID ^ DFN ^ DTI ^ CNI ^ RARPT ^ MAGIEN ^ PSDETAIL
S $P(MAGX,"^",1)=3 ; TXID Key and Interp Images
S $P(MAGX,"^",2)="" ; DFN
S $P(MAGX,"^",3)=""
S $P(MAGX,"^",4)=""
S $P(MAGX,"^",5)=MAGNRPT ; Report IEN
S $P(MAGX,"^",7)=1 ; PSDETAIL
;
D GRAANN(MAGRY,.MAGNCNT,MAGNCXT,MAGX)
Q
;
GRAANN(MAGRY,MAGNCNT,MAGNCXT,MAGX) ; Get Radiology study annotations
N J,MAGOUT
;
D RPCIN^MAGJEX3(.MAGOUT,MAGX)
S @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_MAGNCXT_"|"_@MAGOUT@(0)_"|RAD"
S J=0
F S J=$O(@MAGOUT@(J)) Q:'J D
. S MAGNCNT=MAGNCNT+1
. S @MAGRY@(MAGNCNT)=@MAGOUT@(J)
. Q
K @MAGOUT
S @MAGRY@(0)=1
Q
;
GTUIANN(MAGRY,MAGNCNT,MAGNCXT) ;Get TIU annotations
N DATA,MAGNTIU
;
S MAGNTIU=$P(MAGNCXT,"^",5)
D IMAGES^MAGGNTI(.DATA,MAGNTIU) ; Get all images for TIU
;
D GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA) ;Get annotations for image IEN
;
Q
;
GMAGANN(MAGRY,MAGNCNT,MAGNCXT) ; Get study annotations by image ien
N DATA,MAGIEN,MAGROOT,MAGD0
;
S MAGIEN=$P(MAGNCXT,"^",5)
S MAGROOT=$$GET1^DIQ(2005,MAGIEN,16)
S MAGD0=$$GET1^DIQ(2005,MAGIEN,17)
;
I MAGROOT="TIU" D Q
. D IMAGES^MAGGNTI(.DATA,MAGD0) ; Get all images for TIU
. D GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA) ;Get annotations for image IEN
. Q
;
I MAGROOT="RADIOLOGY" D Q
. D GRAANNRP(MAGRY,MAGNCNT,MAGNCXT,MAGD0)
. ; Try to get images in case of Capture (Clinical) annotation
. D IMAGES(.DATA,MAGIEN) ; Get Images by Group image IEN
. D GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA) ;Get annotations for image IEN
. Q
;
I MAGROOT="" D ; No report
. D IMAGES(.DATA,MAGIEN) ; Get Images by Group image IEN
. D GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA) ;Get annotations for image IEN
. Q
Q
;
GRARPT(DATA) ; Get RA Report IEN by CPRS Context
N DFN,ENT,INVDTTM,INVDT,INVTM,RARPT
S DFN=+$P(DATA,U,3)
S ENT=+$P($P(DATA,U,5),"-",2)
S INVDTTM=$P($P(DATA,U,5),"-",1)
S INVDT=$P(INVDTTM,".",1)
S INVTM=$P(INVDTTM,".",2)
F Q:($L(INVDT)<8) S INVDT=$E(INVDT,2,$L(INVDT))
S INVDTTM=INVDT_"."_INVTM
S RARPT=0
I '$D(^RADPT(DFN,"DT",INVDTTM,"P",ENT,0)) Q "0^INVALID Data : Attempt to access Exam failed."
S RARPT=$P(^RADPT(DFN,"DT",INVDTTM,"P",ENT,0),U,17)
I 'RARPT Q "0^No Report for selected Exam"
I $P($G(^RARPT(RARPT,0)),U,2)'=DFN Q "-2^Patient Mismatch. Radiology File"
Q RARPT
;
GIENANN(MAGRY,MAGNCNT,MAGNCXT,DATA) ;Get annotations for image IEN
; MAGRY = Output array
; MAGNCNT = initial output counter
; MAGNCXT = Context ID
; DATA(0) = Result output
; DATA(1..n) = Image IEN
;
N J,I,MAGIEN,MAGNTIU,MAGOUT
;
I '$D(DATA(0)) Q ; no data to report
S MAGNCNT=MAGNCNT+1
S @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_MAGNCXT_"|"_DATA(0)_"|CLN"
I 'DATA(0) Q ; Error quit
;
S I=0
F S I=$O(DATA(I)) Q:'I D
. S MAGIEN=$P(DATA(I),"^",2)
. K MAGOUT
. ;P122 handles only one type of annotation (Clinic or VistARAD), but not on both
. I '$D(^MAG(2005.002,MAGIEN,0)) Q ; VistA Rad annotations are present. Quit. We need only Clinic
. D GETD^MAGSANNO(.MAGOUT,MAGIEN) ; Get annotation details by image IEN
. S MAGNCNT=MAGNCNT+1
. S @MAGRY@(MAGNCNT)="NEXT_IMAGE|"_MAGIEN_"|"_MAGOUT(0)
. I 'MAGOUT(0) Q ; Error, get next one
. S J=0
. F S J=$O(MAGOUT(J)) Q:'J D
. . S MAGNCNT=MAGNCNT+1
. . S @MAGRY@(MAGNCNT)=MAGOUT(J)
. . Q
. Q
S @MAGRY@(0)=1
Q
;
IMAGES(DATA,MAGIEN) ; Get all Images for a Group Image IEN
N GROUP
S GROUP=$$ISGRP^MAGGI11(MAGIEN)
S DATA(0)=1 ; Set result to okay
I GROUP D Q
. N NO,CH
. S NO=0
. F S NO=$O(^MAG(2005,MAGIEN,1,NO)) Q:'NO D
. . S CH=+$G(^MAG(2005,MAGIEN,1,NO,0))
. . Q:'CH
. . S $P(DATA(NO),"^",2)=CH
. Q
S $P(DATA(1),"^",2)=MAGIEN
Q
;
GIMGRARP(DATA,RARPT) ; Get list of images by radiology report
; RARPT -- Radiology report IEN
; and returns a list in DATA(1..n).
;
N GROUPS,OUT,REQDFN
;
N CT,OI,IGCT,MAGIEN1,MAGQI,MAGX
K MAGZRY
S IGCT=+$P($G(^RARPT(RARPT,2005,0)),U,4)
; Quit if no images for RARPT
I IGCT=0 Q
;
; Check all Image entries in RARPT 2005 NODE. for Patient match Pointer match, from both
; RARPT end, and Imaging end.
S MAGQI=1
S OI=0,CT=1 F S OI=$O(^RARPT(RARPT,2005,OI)) Q:'OI D Q:(MAGQI<1)
. S MAGIEN1=$P(^RARPT(RARPT,2005,OI,0),U)
. ; Assure magdfn = rarpt dfn
. I $P($G(^RARPT(RARPT,0)),U,2)'=$P($G(^MAG(2005,MAGIEN1,0)),U,7) S MAGQI="-2^Patient Mismatch. Radiology Report" Q
. ; Assure magien1 is pointing to this rarpt
. I $P($G(^MAG(2005,MAGIEN1,2)),U,7)'=RARPT S MAGQI="-2^Pointer Mismatch. Radiology Report" Q
. ; Now run the Imaging integrity check
. D CHK^MAGGSQI(.MAGX,MAGIEN1) I 'MAGX(0) S MAGQI="-2^"_$P(MAGX(0),U,2,99) Q
;
I MAGQI<1 S DATA(0)=MAGQI Q ; Integrity error
S CT=0
;
S OI=0,CT=1 F S OI=$O(^RARPT(RARPT,2005,OI)) Q:'OI D
. S MAGIEN1=$P(^RARPT(RARPT,2005,OI,0),U) S $P(DATA(OI),"^",2)=MAGIEN1
. Q
S DATA(0)=1 ; okay result
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGNAN03 8541 printed Nov 22, 2024@17:17:18 Page 2
MAGNAN03 ;WOIFO/NST - Get image annotations ; 10 Apr 2018 3:59 PM
+1 ;;3.0;IMAGING;**185,197**;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 image annotations by CPRS context or Image IEN
+20 ;
+21 ; RPC: MAGN ANNOT GET IMAGE ANNOT
+22 ;
+23 ; Input Parameters
+24 ; ================
+25 ;
+26 ; DATA - ContextID in format
+27 ; e.g. 'RPT^CPRS^29027^RA^79029185.9998-1'
+28 ; or
+29 ; RPT^CPRS^4658^TIU^2243408^^^^^^^^1
+30 ; or
+31 ; ^ ^ ^MAG^10454
+32 ;
+33 ; Return Values
+34 ; =============
+35 ;
+36 ; if error MAGRY(0) = 0 ^Error message^
+37 ; if success MAGRY(0) = 1
+38 ; MAGRY(1..n) = NEXT_CONTEXTID | CONTEXTID | 0 or 1 |
+39 ; NEXT_IMAGE | IMAGE IEN
+40 ; images in format defined in RPC [MAGJ STUDY_DATA] or
+41 ; [MAG ANNOT GET IMAGE DETAIL], [MAG ANNOT GET IMAGE]
+42 ;
IMAGEL(MAGRY,DATA) ;RPC [MAGN ANNOT GET IMAGE ANNOT]
+1 NEW MAGNCNT,MAGNX,RARPT
+2 NEW $ETRAP,$ESTACK
SET $ETRAP="D AERRA^MAGGTERR"
+3 SET MAGRY=$NAME(^TMP("MAGNTRAI",$JOB))
+4 KILL @MAGRY
+5 SET @MAGRY@(0)=0
+6 SET MAGNCNT=0
+7 SET MAGNX=$PIECE(DATA,"^",4)
+8 IF MAGNX="RA"
Begin DoDot:1
+9 ; get RAD annotations
DO GRAANNCX(MAGRY,MAGNCNT,DATA)
+10 QUIT
End DoDot:1
QUIT
+11 ;
+12 IF MAGNX="TIU"
Begin DoDot:1
+13 ; Get TIU annotations
DO GTUIANN(MAGRY,MAGNCNT,DATA)
+14 QUIT
End DoDot:1
QUIT
+15 ;
+16 IF MAGNX="MAG"
Begin DoDot:1
+17 ; Get TIU annotations
DO GMAGANN(MAGRY,MAGNCNT,DATA)
+18 QUIT
End DoDot:1
QUIT
+19 ;
+20 SET MAGNCNT=MAGNCNT+1
+21 SET @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_DATA_"|0|"_"Invalid ContextId Type"
+22 SET @MAGRY@(0)=1
+23 QUIT
+24 ;
GRAANNCX(MAGRY,MAGNCNT,MAGNCXT) ; Get RAD annotations by CPRS Context ID
+1 NEW MAGX,MAGNRPT,DATA
+2 ;
+3 ; Get RA Report IEN by CPRS Context
SET MAGNRPT=$$GRARPT(MAGNCXT)
+4 SET MAGNCNT=MAGNCNT+1
+5 SET @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_MAGNCXT_"|"_MAGNRPT_"|RAD"
+6 IF MAGNRPT'>0
QUIT
+7 ;
+8 ; e.g. MAGNCXT=RPT^CPRS^29027^RA^79029185.9998-1
+9 ; See MAGJEX3
+10 ; MAGX--TXID ^ DFN ^ DTI ^ CNI ^ RARPT ^ MAGIEN ^ PSDETAIL
+11 ; TXID Key and Interp Images
SET $PIECE(MAGX,"^",1)=3
+12 ; DFN
SET $PIECE(MAGX,"^",2)=$PIECE(MAGNCXT,"^",3)
+13 SET $PIECE(MAGX,"^",3)=$PIECE($PIECE(MAGNCXT,"^",5),"-",1)
+14 SET $PIECE(MAGX,"^",4)=$PIECE($PIECE(MAGNCXT,"^",5),"-",2)
+15 ; Report IEN
SET $PIECE(MAGX,"^",5)=MAGNRPT
+16 ; PSDETAIL
SET $PIECE(MAGX,"^",7)=1
+17 ;
+18 DO GRAANN(MAGRY,.MAGNCNT,MAGNCXT,MAGX)
+19 ;
+20 ; Get Clinical Annotations
+21 DO GIMGRARP(.DATA,MAGNRPT)
+22 DO GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA)
+23 QUIT
+24 ;
GRAANNRP(MAGRY,MAGNCNT,MAGNCXT,MAGNRPT) ; Get RAD annotations by RA Report
+1 NEW MAGX
+2 ;
+3 SET MAGNCNT=MAGNCNT+1
+4 SET @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_MAGNCXT_"|"_MAGNRPT_"|RAD"
+5 IF MAGNRPT'>0
QUIT
+6 ;
+7 ; e.g. MAGNCXT=^^^MAG^10454
+8 ; See MAGJEX3
+9 ; MAGX--TXID ^ DFN ^ DTI ^ CNI ^ RARPT ^ MAGIEN ^ PSDETAIL
+10 ; TXID Key and Interp Images
SET $PIECE(MAGX,"^",1)=3
+11 ; DFN
SET $PIECE(MAGX,"^",2)=""
+12 SET $PIECE(MAGX,"^",3)=""
+13 SET $PIECE(MAGX,"^",4)=""
+14 ; Report IEN
SET $PIECE(MAGX,"^",5)=MAGNRPT
+15 ; PSDETAIL
SET $PIECE(MAGX,"^",7)=1
+16 ;
+17 DO GRAANN(MAGRY,.MAGNCNT,MAGNCXT,MAGX)
+18 QUIT
+19 ;
GRAANN(MAGRY,MAGNCNT,MAGNCXT,MAGX) ; Get Radiology study annotations
+1 NEW J,MAGOUT
+2 ;
+3 DO RPCIN^MAGJEX3(.MAGOUT,MAGX)
+4 SET @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_MAGNCXT_"|"_@MAGOUT@(0)_"|RAD"
+5 SET J=0
+6 FOR
SET J=$ORDER(@MAGOUT@(J))
if 'J
QUIT
Begin DoDot:1
+7 SET MAGNCNT=MAGNCNT+1
+8 SET @MAGRY@(MAGNCNT)=@MAGOUT@(J)
+9 QUIT
End DoDot:1
+10 KILL @MAGOUT
+11 SET @MAGRY@(0)=1
+12 QUIT
+13 ;
GTUIANN(MAGRY,MAGNCNT,MAGNCXT) ;Get TIU annotations
+1 NEW DATA,MAGNTIU
+2 ;
+3 SET MAGNTIU=$PIECE(MAGNCXT,"^",5)
+4 ; Get all images for TIU
DO IMAGES^MAGGNTI(.DATA,MAGNTIU)
+5 ;
+6 ;Get annotations for image IEN
DO GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA)
+7 ;
+8 QUIT
+9 ;
GMAGANN(MAGRY,MAGNCNT,MAGNCXT) ; Get study annotations by image ien
+1 NEW DATA,MAGIEN,MAGROOT,MAGD0
+2 ;
+3 SET MAGIEN=$PIECE(MAGNCXT,"^",5)
+4 SET MAGROOT=$$GET1^DIQ(2005,MAGIEN,16)
+5 SET MAGD0=$$GET1^DIQ(2005,MAGIEN,17)
+6 ;
+7 IF MAGROOT="TIU"
Begin DoDot:1
+8 ; Get all images for TIU
DO IMAGES^MAGGNTI(.DATA,MAGD0)
+9 ;Get annotations for image IEN
DO GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA)
+10 QUIT
End DoDot:1
QUIT
+11 ;
+12 IF MAGROOT="RADIOLOGY"
Begin DoDot:1
+13 DO GRAANNRP(MAGRY,MAGNCNT,MAGNCXT,MAGD0)
+14 ; Try to get images in case of Capture (Clinical) annotation
+15 ; Get Images by Group image IEN
DO IMAGES(.DATA,MAGIEN)
+16 ;Get annotations for image IEN
DO GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA)
+17 QUIT
End DoDot:1
QUIT
+18 ;
+19 ; No report
IF MAGROOT=""
Begin DoDot:1
+20 ; Get Images by Group image IEN
DO IMAGES(.DATA,MAGIEN)
+21 ;Get annotations for image IEN
DO GIENANN(MAGRY,.MAGNCNT,MAGNCXT,.DATA)
+22 QUIT
End DoDot:1
+23 QUIT
+24 ;
GRARPT(DATA) ; Get RA Report IEN by CPRS Context
+1 NEW DFN,ENT,INVDTTM,INVDT,INVTM,RARPT
+2 SET DFN=+$PIECE(DATA,U,3)
+3 SET ENT=+$PIECE($PIECE(DATA,U,5),"-",2)
+4 SET INVDTTM=$PIECE($PIECE(DATA,U,5),"-",1)
+5 SET INVDT=$PIECE(INVDTTM,".",1)
+6 SET INVTM=$PIECE(INVDTTM,".",2)
+7 FOR
if ($LENGTH(INVDT)<8)
QUIT
SET INVDT=$EXTRACT(INVDT,2,$LENGTH(INVDT))
+8 SET INVDTTM=INVDT_"."_INVTM
+9 SET RARPT=0
+10 IF '$DATA(^RADPT(DFN,"DT",INVDTTM,"P",ENT,0))
QUIT "0^INVALID Data : Attempt to access Exam failed."
+11 SET RARPT=$PIECE(^RADPT(DFN,"DT",INVDTTM,"P",ENT,0),U,17)
+12 IF 'RARPT
QUIT "0^No Report for selected Exam"
+13 IF $PIECE($GET(^RARPT(RARPT,0)),U,2)'=DFN
QUIT "-2^Patient Mismatch. Radiology File"
+14 QUIT RARPT
+15 ;
GIENANN(MAGRY,MAGNCNT,MAGNCXT,DATA) ;Get annotations for image IEN
+1 ; MAGRY = Output array
+2 ; MAGNCNT = initial output counter
+3 ; MAGNCXT = Context ID
+4 ; DATA(0) = Result output
+5 ; DATA(1..n) = Image IEN
+6 ;
+7 NEW J,I,MAGIEN,MAGNTIU,MAGOUT
+8 ;
+9 ; no data to report
IF '$DATA(DATA(0))
QUIT
+10 SET MAGNCNT=MAGNCNT+1
+11 SET @MAGRY@(MAGNCNT)="NEXT_CONTEXTID|"_MAGNCXT_"|"_DATA(0)_"|CLN"
+12 ; Error quit
IF 'DATA(0)
QUIT
+13 ;
+14 SET I=0
+15 FOR
SET I=$ORDER(DATA(I))
if 'I
QUIT
Begin DoDot:1
+16 SET MAGIEN=$PIECE(DATA(I),"^",2)
+17 KILL MAGOUT
+18 ;P122 handles only one type of annotation (Clinic or VistARAD), but not on both
+19 ; VistA Rad annotations are present. Quit. We need only Clinic
IF '$DATA(^MAG(2005.002,MAGIEN,0))
QUIT
+20 ; Get annotation details by image IEN
DO GETD^MAGSANNO(.MAGOUT,MAGIEN)
+21 SET MAGNCNT=MAGNCNT+1
+22 SET @MAGRY@(MAGNCNT)="NEXT_IMAGE|"_MAGIEN_"|"_MAGOUT(0)
+23 ; Error, get next one
IF 'MAGOUT(0)
QUIT
+24 SET J=0
+25 FOR
SET J=$ORDER(MAGOUT(J))
if 'J
QUIT
Begin DoDot:2
+26 SET MAGNCNT=MAGNCNT+1
+27 SET @MAGRY@(MAGNCNT)=MAGOUT(J)
+28 QUIT
End DoDot:2
+29 QUIT
End DoDot:1
+30 SET @MAGRY@(0)=1
+31 QUIT
+32 ;
IMAGES(DATA,MAGIEN) ; Get all Images for a Group Image IEN
+1 NEW GROUP
+2 SET GROUP=$$ISGRP^MAGGI11(MAGIEN)
+3 ; Set result to okay
SET DATA(0)=1
+4 IF GROUP
Begin DoDot:1
+5 NEW NO,CH
+6 SET NO=0
+7 FOR
SET NO=$ORDER(^MAG(2005,MAGIEN,1,NO))
if 'NO
QUIT
Begin DoDot:2
+8 SET CH=+$GET(^MAG(2005,MAGIEN,1,NO,0))
+9 if 'CH
QUIT
+10 SET $PIECE(DATA(NO),"^",2)=CH
End DoDot:2
+11 QUIT
End DoDot:1
QUIT
+12 SET $PIECE(DATA(1),"^",2)=MAGIEN
+13 QUIT
+14 ;
GIMGRARP(DATA,RARPT) ; Get list of images by radiology report
+1 ; RARPT -- Radiology report IEN
+2 ; and returns a list in DATA(1..n).
+3 ;
+4 NEW GROUPS,OUT,REQDFN
+5 ;
+6 NEW CT,OI,IGCT,MAGIEN1,MAGQI,MAGX
+7 KILL MAGZRY
+8 SET IGCT=+$PIECE($GET(^RARPT(RARPT,2005,0)),U,4)
+9 ; Quit if no images for RARPT
+10 IF IGCT=0
QUIT
+11 ;
+12 ; Check all Image entries in RARPT 2005 NODE. for Patient match Pointer match, from both
+13 ; RARPT end, and Imaging end.
+14 SET MAGQI=1
+15 SET OI=0
SET CT=1
FOR
SET OI=$ORDER(^RARPT(RARPT,2005,OI))
if 'OI
QUIT
Begin DoDot:1
+16 SET MAGIEN1=$PIECE(^RARPT(RARPT,2005,OI,0),U)
+17 ; Assure magdfn = rarpt dfn
+18 IF $PIECE($GET(^RARPT(RARPT,0)),U,2)'=$PIECE($GET(^MAG(2005,MAGIEN1,0)),U,7)
SET MAGQI="-2^Patient Mismatch. Radiology Report"
QUIT
+19 ; Assure magien1 is pointing to this rarpt
+20 IF $PIECE($GET(^MAG(2005,MAGIEN1,2)),U,7)'=RARPT
SET MAGQI="-2^Pointer Mismatch. Radiology Report"
QUIT
+21 ; Now run the Imaging integrity check
+22 DO CHK^MAGGSQI(.MAGX,MAGIEN1)
IF 'MAGX(0)
SET MAGQI="-2^"_$PIECE(MAGX(0),U,2,99)
QUIT
End DoDot:1
if (MAGQI<1)
QUIT
+23 ;
+24 ; Integrity error
IF MAGQI<1
SET DATA(0)=MAGQI
QUIT
+25 SET CT=0
+26 ;
+27 SET OI=0
SET CT=1
FOR
SET OI=$ORDER(^RARPT(RARPT,2005,OI))
if 'OI
QUIT
Begin DoDot:1
+28 SET MAGIEN1=$PIECE(^RARPT(RARPT,2005,OI,0),U)
SET $PIECE(DATA(OI),"^",2)=MAGIEN1
+29 QUIT
End DoDot:1
+30 ; okay result
SET DATA(0)=1
+31 QUIT