MAGJUPD2 ;WIRMFO/JHC VistaRad RPCs-Update PS & KEY Img ; 14 July 2004 10:05 AM
;;3.0;IMAGING;**18,76,101**;Nov 06, 2009;Build 50
;;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
ERR N ERR S ERR=$$EC^%ZOSV S @MAGGRY@(0)="0^4~"_ERR
D @^%ZOSF("ERRTN")
Q:$Q 1 Q
;
SAVKPS(RARPT,INTERPFL,DATA,REPLY) ; Save study data: Key/Interpretation Images & Pres. State
; RARPT--exam pointer
; INTERPFL--1/0; 1=This is associated with a Rad Interpretation; Optional
; DATA--array of input data; see structure at end of routine
; REPLY--return string
N PSTRAK,IDATA,IMGCT,PSTOT,PSLINCT,PSKILCT,KEYCT,INTCT,STUDY,LINE,NEWIMG,NEWPS
N IMGREF,IMGIEN,PSIEN,SAVOP,STIEN,TYPE,IMG,ICT,NEWIMG,INITSTDY,SEQNUM
S INTERPFL=+$G(INTERPFL)
S NEWIMG=0,NEWPS=0,IMGIEN="",PSIEN="",SEQNUM=0
S (IMGCT,PSTOT,PSLINCT,KEYCT,INTCT,PSKILCT)=0
S IMGREF="",SAVOP="NOOP"
I '$D(TIMESTMP) N TIMESTMP S TIMESTMP=$$NOW^XLFDT()
; 1st, process input in DATA
S IDATA=""
F S IDATA=$O(DATA(IDATA)) Q:IDATA="" S LINE=DATA(IDATA) I LINE]"" D
. I LINE="*IMAGE" S NEWIMG=1 Q
. I LINE="*PS" S NEWPS=1 Q
. I $E(LINE,1,4)="*END" S (NEWIMG,NEWPS)=0 Q
. I NEWIMG D IMGINIT(LINE) S NEWIMG=0 Q ; Init storage for this Image
. I NEWPS D PSINIT(LINE) S NEWPS=0 Q ; Init storage for a PS
. D @(SAVOP_"(LINE)")
; Now update the Study node info
S INITSTDY=$S(INTERPFL:"INIT_STUDY",1:"")
S STIEN=$$STUDYID("",RARPT,1,INITSTDY)
I $D(PSTRAK) S IMG="" D ; Update key imgs in Study node
. F S IMG=$O(PSTRAK(IMG)) Q:'IMG S NEWIMG=1,TYPE="" D
. . F S TYPE=$O(PSTRAK(IMG,TYPE)) Q:TYPE="" D
. . . F ICT=1:1:PSTRAK(IMG,TYPE,0) D SAVKIMG(IMG,PSTRAK(IMG,TYPE,ICT),TYPE,NEWIMG) S NEWIMG=0
SAVKPSZ ;
I IMGCT!PSTOT!PSLINCT!KEYCT!INTCT S REPLY="1~Saved: "_KEYCT_" Key Image"_$S(KEYCT-1:"s",1:"")_"; "_INTCT_" Interp Image"_$S(INTCT-1:"s",1:"")_"; "
I S REPLY=REPLY_PSLINCT_" PS line"_$S(PSLINCT-1:"s",1:"")_" for "_PSTOT_" PS"_$S(PSTOT-1:"s",1:"")_" for "_IMGCT_" Image"_$S(IMGCT-1:"s.",1:".")
I S:PSKILCT REPLY=REPLY_" Deleted: "_PSKILCT_" PS record"_$S(PSKILCT-1:"s",1:"")_"."
E I PSKILCT S REPLY="1~Deleted: "_PSKILCT_" PS record"_$S(PSKILCT-1:"s",1:"")_"."
E S REPLY="0~No Key Image/PS data was stored or deleted."
Q
;
NOOP(X) Q ; do nothing/ skip erroneous input
;
IMGINIT(LINE) ; Init storage space for an image ; inits some vars for the SAVE loop
N IEN
S IMGIEN="",IMGREF=""
S IEN=$P(LINE,U)
I IEN,$D(^MAG(2005,IEN,0)),'$D(^(1))
E G IMGINITZ
S IMGIEN=IEN
S IMGREF=$NA(^MAG(2005,IMGIEN)) ; indirect ref used in psinit & savps
S IMGCT=IMGCT+1
IMGINITZ Q
;
PSINIT(LINE) ; Init storage space for a Presentation State ; inits some vars for SAVE loop
; input = PS_UID ^ UID Type (KEY, INT) ^ "DELETE"
; if peice 3 ="DELETE" then the PS data is deleted
N IEN,UID,TYPE,DELETE
S UID=$P(LINE,U),X=$P(LINE,U,2),DELETE=($P(LINE,U,3)="DELETE"),TYPE=$S(X="KEY":"K",X="INTERP":"I",1:"")
I UID="" G PSINITZ
I INTERPFL,(TYPE'="K"),(TYPE'="U") S TYPE="I" ; just in case...
L +@IMGREF@(210,0):5
E Q
S IEN=$O(@IMGREF@(210,"B",UID,""))
I 'IEN D ; Allocate node
. S X=$G(@IMGREF@(210,0)) I X="" S X="^2005.05A^^",^(0)=X
. S IEN=$P(X,U,3)+1,T=$P(X,U,4)+1,$P(X,U,3)=IEN,$P(X,U,4)=T
. S @IMGREF@(210,0)=X,@IMGREF@(210,"B",UID,IEN)=""
S PSIEN=IEN
I DELETE,PSIEN D ; delete this PS
. S PSKILCT=PSKILCT+1
. K @IMGREF@(210,PSIEN),@IMGREF@(210,"B",UID,PSIEN)
. S T=$O(@IMGREF@(210,9999),-1)
. I 'T K @IMGREF@(210) Q ; no more PSs!
. N XD S XD=$G(@IMGREF@(210,0))
. S $P(XD,U,3)=T,T=$P(XD,U,4) S:T T=T-1 S $P(XD,U,4)=T
. S @IMGREF@(210,0)=XD
E D ; init PS node for storage; PSTRAK keeps data for later update to STUDY file
. S @IMGREF@(210,PSIEN,0)=UID_U_TYPE_U_DUZ_U_TIMESTMP
. I "KI"[TYPE S SEQNUM=SEQNUM+1,T=$G(PSTRAK(IMGIEN,TYPE,0))+1,PSTRAK(IMGIEN,TYPE,0)=T,PSTRAK(IMGIEN,TYPE,T)=UID_U_SEQNUM
. K @IMGREF@(210,PSIEN,1) ; init Data & Keys
. S @IMGREF@(210,PSIEN,1,0)="^2005.51^0_U_0"
L -@IMGREF@(210,0)
S SAVOP="SAVPS" ; indirect label reference for use in SAVE loop
I DELETE S SAVOP="NOOP"
S PSTOT=PSTOT+1-DELETE
PSINITZ Q
;
SAVPS(LINE) ; Save a line of PS data
; input = line of free-text data
N PSCT,PSCTRL
L +(@IMGREF@(210,PSIEN)):5
S PSCTRL=$G(@IMGREF@(210,PSIEN,1,0))
S PSCT=+$P(PSCTRL,U,4)+1
S @IMGREF@(210,PSIEN,1,PSCT,0)=LINE
S $P(PSCTRL,U,3,4)=PSCT_U_PSCT
S @IMGREF@(210,PSIEN,1,0)=PSCTRL
L -(@IMGREF@(210,PSIEN))
S PSLINCT=PSLINCT+1
Q
;
SAVKIMG(IMGIEN,UIDSEQ,TYPE,NEWIMG) ; store a Key image & Interp images w/ PS refs in study node
;
N STIEN,KIEN,STUDYREF,UID,SEQNUM
I 'IMGIEN G SAVKIMGZ
S STIEN=$$STUDYID(IMGIEN,"",0)
I 'STIEN G SAVKIMGZ ; should never happen
S STUDYREF=$NA(^MAG(2005.001,STIEN))
S UID=$P(UIDSEQ,U),SEQNUM=$P(UIDSEQ,U,2)
S KIEN=$O(@STUDYREF@(1,"B",IMGIEN,""))
I 'KIEN D
. L +@STUDYREF@(1,0):5
. S X=$G(@STUDYREF@(1,0)) I X="" S X="^2005.031P^^",^(0)=X
. S KIEN=$P(X,U,3)+1,T=$P(X,U,4)+1,$P(X,U,3)=KIEN,$P(X,U,4)=T
. S @STUDYREF@(1,0)=X,@STUDYREF@(1,"B",IMGIEN,KIEN)=""
. L -@STUDYREF@(1,0)
E D
. I 'NEWIMG Q
. K @STUDYREF@(1,KIEN,1) ; init ps data if updating existing img
. S @STUDYREF@(1,KIEN,1,0)="^2005.311^0_U_0"
S $P(@STUDYREF@(1,KIEN,0),U)=IMGIEN
; store the PS UID
I UID]"" D
. N IEN S IEN=$O(@STUDYREF@(1,KIEN,1,"B",UID,""))
. I 'IEN D
. . L +@STUDYREF@(1,KIEN,1,0):5
. . S X=$G(@STUDYREF@(1,KIEN,1,0)) I X="" S X="^2005.311^^",^(0)=X
. . S IEN=$P(X,U,3)+1,T=$P(X,U,4)+1,$P(X,U,3)=IEN,$P(X,U,4)=T
. . S @STUDYREF@(1,KIEN,1,0)=X,@STUDYREF@(1,KIEN,1,"B",UID,IEN)=""
. . L -@STUDYREF@(1,KIEN,1,0)
. S @STUDYREF@(1,KIEN,1,IEN,0)=UID_U_TYPE_U_SEQNUM
S KEYCT=KEYCT+(TYPE="K"),INTCT=INTCT+(TYPE="I")
SAVKIMGZ Q
;
STUDYID(IEN,RARPT,READONLY,INITSTDY) ; return Study_IEN for input ImgIEN or RARPT
; initialize Study node if INITSTDY is indicated (optional)
; Either IEN or RARPT must be supplied; if both supplied, only RARPT is used
; if READONLY is false, then create "STUDY" node if undefined
; <*> Note: this routine is hard-coded for RADIOLOGY image data only (Parent file=74)
N STIEN,X,T,STDYINIT
S STIEN="" ; init return value
S IEN=$G(IEN),RARPT=$G(RARPT)
S:'$D(READONLY) READONLY=1
S INITSTDY=$G(INITSTDY)
I IEN,'RARPT S RARPT=$$GETRPT(IEN)
I 'RARPT G STUDYIDZ
I $D(^MAG(2005.001,"ASTUDY",74,RARPT)) S STIEN=$O(^(RARPT,"")) D
. I INITSTDY="INIT_STUDY" K ^MAG(2005.001,STIEN,1) ; init for Key/Interp PS updates (full replacement)
E D:'READONLY ; create Study structure
. L +^MAG(2005.001,0):5
. S X=^MAG(2005.001,0),STIEN=$P(X,U,3)+1,T=$P(X,U,4)+1,$P(X,U,3)=STIEN,$P(X,U,4)=T,^(0)=X
. L -^MAG(2005.001,0)
. S ^MAG(2005.001,STIEN,0)=RARPT_U_74,^MAG(2005.001,"ASTUDY",74,RARPT,STIEN)="",^MAG(2005.001,"B",RARPT,STIEN)=""
;
STUDYIDZ Q:$Q STIEN Q
;
GETRPT(IEN) ; return rarpt for input imgien
N IENGRP,X,RARPT
S RARPT=""
I IEN D
. I $D(^MAG(2005,IEN,1)) S IENGRP=IEN
. E S IENGRP=$P(^MAG(2005,IEN,0),U,10)
. I IENGRP S X=$G(^MAG(2005,IENGRP,2)) I $P(X,U,6)=74 S RARPT=$P(X,U,7)
. I RARPT,$D(^RARPT(RARPT,2005))
. E S RARPT="" ; no Rad report node!
Q:$Q RARPT Q
;
;Structure of PS/PSTRAK data In:
; *IMAGE
; IEN^
; *PS
; UID^[KEY/INTERP/USER]
; 1: N Lines of PS data follow
; *END_PS
; *PS
; UID^[KEY/INTERP/USER]
; 1: N Lines of PS data follow
; *END_PS
; *END_IMAGE
; *IMAGE
; ... etc.
; *END_IMAGE
; *END
END ;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGJUPD2 8454 printed Dec 13, 2024@02:06:58 Page 2
MAGJUPD2 ;WIRMFO/JHC VistaRad RPCs-Update PS & KEY Img ; 14 July 2004 10:05 AM
+1 ;;3.0;IMAGING;**18,76,101**;Nov 06, 2009;Build 50
+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 ;; | |
+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
ERR NEW ERR
SET ERR=$$EC^%ZOSV
SET @MAGGRY@(0)="0^4~"_ERR
+1 DO @^%ZOSF("ERRTN")
+2 if $QUIT
QUIT 1
QUIT
+3 ;
SAVKPS(RARPT,INTERPFL,DATA,REPLY) ; Save study data: Key/Interpretation Images & Pres. State
+1 ; RARPT--exam pointer
+2 ; INTERPFL--1/0; 1=This is associated with a Rad Interpretation; Optional
+3 ; DATA--array of input data; see structure at end of routine
+4 ; REPLY--return string
+5 NEW PSTRAK,IDATA,IMGCT,PSTOT,PSLINCT,PSKILCT,KEYCT,INTCT,STUDY,LINE,NEWIMG,NEWPS
+6 NEW IMGREF,IMGIEN,PSIEN,SAVOP,STIEN,TYPE,IMG,ICT,NEWIMG,INITSTDY,SEQNUM
+7 SET INTERPFL=+$GET(INTERPFL)
+8 SET NEWIMG=0
SET NEWPS=0
SET IMGIEN=""
SET PSIEN=""
SET SEQNUM=0
+9 SET (IMGCT,PSTOT,PSLINCT,KEYCT,INTCT,PSKILCT)=0
+10 SET IMGREF=""
SET SAVOP="NOOP"
+11 IF '$DATA(TIMESTMP)
NEW TIMESTMP
SET TIMESTMP=$$NOW^XLFDT()
+12 ; 1st, process input in DATA
+13 SET IDATA=""
+14 FOR
SET IDATA=$ORDER(DATA(IDATA))
if IDATA=""
QUIT
SET LINE=DATA(IDATA)
IF LINE]""
Begin DoDot:1
+15 IF LINE="*IMAGE"
SET NEWIMG=1
QUIT
+16 IF LINE="*PS"
SET NEWPS=1
QUIT
+17 IF $EXTRACT(LINE,1,4)="*END"
SET (NEWIMG,NEWPS)=0
QUIT
+18 ; Init storage for this Image
IF NEWIMG
DO IMGINIT(LINE)
SET NEWIMG=0
QUIT
+19 ; Init storage for a PS
IF NEWPS
DO PSINIT(LINE)
SET NEWPS=0
QUIT
+20 DO @(SAVOP_"(LINE)")
End DoDot:1
+21 ; Now update the Study node info
+22 SET INITSTDY=$SELECT(INTERPFL:"INIT_STUDY",1:"")
+23 SET STIEN=$$STUDYID("",RARPT,1,INITSTDY)
+24 ; Update key imgs in Study node
IF $DATA(PSTRAK)
SET IMG=""
Begin DoDot:1
+25 FOR
SET IMG=$ORDER(PSTRAK(IMG))
if 'IMG
QUIT
SET NEWIMG=1
SET TYPE=""
Begin DoDot:2
+26 FOR
SET TYPE=$ORDER(PSTRAK(IMG,TYPE))
if TYPE=""
QUIT
Begin DoDot:3
+27 FOR ICT=1:1:PSTRAK(IMG,TYPE,0)
DO SAVKIMG(IMG,PSTRAK(IMG,TYPE,ICT),TYPE,NEWIMG)
SET NEWIMG=0
End DoDot:3
End DoDot:2
End DoDot:1
SAVKPSZ ;
+1 IF IMGCT!PSTOT!PSLINCT!KEYCT!INTCT
SET REPLY="1~Saved: "_KEYCT_" Key Image"_$SELECT(KEYCT-1:"s",1:"")_"; "_INTCT_" Interp Image"_$SELECT(INTCT-1:"s",1:"")_"; "
+2 IF $TEST
SET REPLY=REPLY_PSLINCT_" PS line"_$SELECT(PSLINCT-1:"s",1:"")_" for "_PSTOT_" PS"_$SELECT(PSTOT-1:"s",1:"")_" for "_IMGCT_" Image"_$SELECT(IMGCT-1:"s.",1:".")
+3 IF $TEST
if PSKILCT
SET REPLY=REPLY_" Deleted: "_PSKILCT_" PS record"_$SELECT(PSKILCT-1:"s",1:"")_"."
+4 IF '$TEST
IF PSKILCT
SET REPLY="1~Deleted: "_PSKILCT_" PS record"_$SELECT(PSKILCT-1:"s",1:"")_"."
+5 IF '$TEST
SET REPLY="0~No Key Image/PS data was stored or deleted."
+6 QUIT
+7 ;
NOOP(X) ; do nothing/ skip erroneous input
QUIT
+1 ;
IMGINIT(LINE) ; Init storage space for an image ; inits some vars for the SAVE loop
+1 NEW IEN
+2 SET IMGIEN=""
SET IMGREF=""
+3 SET IEN=$PIECE(LINE,U)
+4 IF IEN
IF $DATA(^MAG(2005,IEN,0))
IF '$DATA(^(1))
+5 IF '$TEST
GOTO IMGINITZ
+6 SET IMGIEN=IEN
+7 ; indirect ref used in psinit & savps
SET IMGREF=$NAME(^MAG(2005,IMGIEN))
+8 SET IMGCT=IMGCT+1
IMGINITZ QUIT
+1 ;
PSINIT(LINE) ; Init storage space for a Presentation State ; inits some vars for SAVE loop
+1 ; input = PS_UID ^ UID Type (KEY, INT) ^ "DELETE"
+2 ; if peice 3 ="DELETE" then the PS data is deleted
+3 NEW IEN,UID,TYPE,DELETE
+4 SET UID=$PIECE(LINE,U)
SET X=$PIECE(LINE,U,2)
SET DELETE=($PIECE(LINE,U,3)="DELETE")
SET TYPE=$SELECT(X="KEY":"K",X="INTERP":"I",1:"")
+5 IF UID=""
GOTO PSINITZ
+6 ; just in case...
IF INTERPFL
IF (TYPE'="K")
IF (TYPE'="U")
SET TYPE="I"
+7 LOCK +@IMGREF@(210,0):5
+8 IF '$TEST
QUIT
+9 SET IEN=$ORDER(@IMGREF@(210,"B",UID,""))
+10 ; Allocate node
IF 'IEN
Begin DoDot:1
+11 SET X=$GET(@IMGREF@(210,0))
IF X=""
SET X="^2005.05A^^"
SET ^(0)=X
+12 SET IEN=$PIECE(X,U,3)+1
SET T=$PIECE(X,U,4)+1
SET $PIECE(X,U,3)=IEN
SET $PIECE(X,U,4)=T
+13 SET @IMGREF@(210,0)=X
SET @IMGREF@(210,"B",UID,IEN)=""
End DoDot:1
+14 SET PSIEN=IEN
+15 ; delete this PS
IF DELETE
IF PSIEN
Begin DoDot:1
+16 SET PSKILCT=PSKILCT+1
+17 KILL @IMGREF@(210,PSIEN),@IMGREF@(210,"B",UID,PSIEN)
+18 SET T=$ORDER(@IMGREF@(210,9999),-1)
+19 ; no more PSs!
IF 'T
KILL @IMGREF@(210)
QUIT
+20 NEW XD
SET XD=$GET(@IMGREF@(210,0))
+21 SET $PIECE(XD,U,3)=T
SET T=$PIECE(XD,U,4)
if T
SET T=T-1
SET $PIECE(XD,U,4)=T
+22 SET @IMGREF@(210,0)=XD
End DoDot:1
+23 ; init PS node for storage; PSTRAK keeps data for later update to STUDY file
IF '$TEST
Begin DoDot:1
+24 SET @IMGREF@(210,PSIEN,0)=UID_U_TYPE_U_DUZ_U_TIMESTMP
+25 IF "KI"[TYPE
SET SEQNUM=SEQNUM+1
SET T=$GET(PSTRAK(IMGIEN,TYPE,0))+1
SET PSTRAK(IMGIEN,TYPE,0)=T
SET PSTRAK(IMGIEN,TYPE,T)=UID_U_SEQNUM
+26 ; init Data & Keys
KILL @IMGREF@(210,PSIEN,1)
+27 SET @IMGREF@(210,PSIEN,1,0)="^2005.51^0_U_0"
End DoDot:1
+28 LOCK -@IMGREF@(210,0)
+29 ; indirect label reference for use in SAVE loop
SET SAVOP="SAVPS"
+30 IF DELETE
SET SAVOP="NOOP"
+31 SET PSTOT=PSTOT+1-DELETE
PSINITZ QUIT
+1 ;
SAVPS(LINE) ; Save a line of PS data
+1 ; input = line of free-text data
+2 NEW PSCT,PSCTRL
+3 LOCK +(@IMGREF@(210,PSIEN)):5
+4 SET PSCTRL=$GET(@IMGREF@(210,PSIEN,1,0))
+5 SET PSCT=+$PIECE(PSCTRL,U,4)+1
+6 SET @IMGREF@(210,PSIEN,1,PSCT,0)=LINE
+7 SET $PIECE(PSCTRL,U,3,4)=PSCT_U_PSCT
+8 SET @IMGREF@(210,PSIEN,1,0)=PSCTRL
+9 LOCK -(@IMGREF@(210,PSIEN))
+10 SET PSLINCT=PSLINCT+1
+11 QUIT
+12 ;
SAVKIMG(IMGIEN,UIDSEQ,TYPE,NEWIMG) ; store a Key image & Interp images w/ PS refs in study node
+1 ;
+2 NEW STIEN,KIEN,STUDYREF,UID,SEQNUM
+3 IF 'IMGIEN
GOTO SAVKIMGZ
+4 SET STIEN=$$STUDYID(IMGIEN,"",0)
+5 ; should never happen
IF 'STIEN
GOTO SAVKIMGZ
+6 SET STUDYREF=$NAME(^MAG(2005.001,STIEN))
+7 SET UID=$PIECE(UIDSEQ,U)
SET SEQNUM=$PIECE(UIDSEQ,U,2)
+8 SET KIEN=$ORDER(@STUDYREF@(1,"B",IMGIEN,""))
+9 IF 'KIEN
Begin DoDot:1
+10 LOCK +@STUDYREF@(1,0):5
+11 SET X=$GET(@STUDYREF@(1,0))
IF X=""
SET X="^2005.031P^^"
SET ^(0)=X
+12 SET KIEN=$PIECE(X,U,3)+1
SET T=$PIECE(X,U,4)+1
SET $PIECE(X,U,3)=KIEN
SET $PIECE(X,U,4)=T
+13 SET @STUDYREF@(1,0)=X
SET @STUDYREF@(1,"B",IMGIEN,KIEN)=""
+14 LOCK -@STUDYREF@(1,0)
End DoDot:1
+15 IF '$TEST
Begin DoDot:1
+16 IF 'NEWIMG
QUIT
+17 ; init ps data if updating existing img
KILL @STUDYREF@(1,KIEN,1)
+18 SET @STUDYREF@(1,KIEN,1,0)="^2005.311^0_U_0"
End DoDot:1
+19 SET $PIECE(@STUDYREF@(1,KIEN,0),U)=IMGIEN
+20 ; store the PS UID
+21 IF UID]""
Begin DoDot:1
+22 NEW IEN
SET IEN=$ORDER(@STUDYREF@(1,KIEN,1,"B",UID,""))
+23 IF 'IEN
Begin DoDot:2
+24 LOCK +@STUDYREF@(1,KIEN,1,0):5
+25 SET X=$GET(@STUDYREF@(1,KIEN,1,0))
IF X=""
SET X="^2005.311^^"
SET ^(0)=X
+26 SET IEN=$PIECE(X,U,3)+1
SET T=$PIECE(X,U,4)+1
SET $PIECE(X,U,3)=IEN
SET $PIECE(X,U,4)=T
+27 SET @STUDYREF@(1,KIEN,1,0)=X
SET @STUDYREF@(1,KIEN,1,"B",UID,IEN)=""
+28 LOCK -@STUDYREF@(1,KIEN,1,0)
End DoDot:2
+29 SET @STUDYREF@(1,KIEN,1,IEN,0)=UID_U_TYPE_U_SEQNUM
End DoDot:1
+30 SET KEYCT=KEYCT+(TYPE="K")
SET INTCT=INTCT+(TYPE="I")
SAVKIMGZ QUIT
+1 ;
STUDYID(IEN,RARPT,READONLY,INITSTDY) ; return Study_IEN for input ImgIEN or RARPT
+1 ; initialize Study node if INITSTDY is indicated (optional)
+2 ; Either IEN or RARPT must be supplied; if both supplied, only RARPT is used
+3 ; if READONLY is false, then create "STUDY" node if undefined
+4 ; <*> Note: this routine is hard-coded for RADIOLOGY image data only (Parent file=74)
+5 NEW STIEN,X,T,STDYINIT
+6 ; init return value
SET STIEN=""
+7 SET IEN=$GET(IEN)
SET RARPT=$GET(RARPT)
+8 if '$DATA(READONLY)
SET READONLY=1
+9 SET INITSTDY=$GET(INITSTDY)
+10 IF IEN
IF 'RARPT
SET RARPT=$$GETRPT(IEN)
+11 IF 'RARPT
GOTO STUDYIDZ
+12 IF $DATA(^MAG(2005.001,"ASTUDY",74,RARPT))
SET STIEN=$ORDER(^(RARPT,""))
Begin DoDot:1
+13 ; init for Key/Interp PS updates (full replacement)
IF INITSTDY="INIT_STUDY"
KILL ^MAG(2005.001,STIEN,1)
End DoDot:1
+14 ; create Study structure
IF '$TEST
if 'READONLY
Begin DoDot:1
+15 LOCK +^MAG(2005.001,0):5
+16 SET X=^MAG(2005.001,0)
SET STIEN=$PIECE(X,U,3)+1
SET T=$PIECE(X,U,4)+1
SET $PIECE(X,U,3)=STIEN
SET $PIECE(X,U,4)=T
SET ^(0)=X
+17 LOCK -^MAG(2005.001,0)
+18 SET ^MAG(2005.001,STIEN,0)=RARPT_U_74
SET ^MAG(2005.001,"ASTUDY",74,RARPT,STIEN)=""
SET ^MAG(2005.001,"B",RARPT,STIEN)=""
End DoDot:1
+19 ;
STUDYIDZ if $QUIT
QUIT STIEN
QUIT
+1 ;
GETRPT(IEN) ; return rarpt for input imgien
+1 NEW IENGRP,X,RARPT
+2 SET RARPT=""
+3 IF IEN
Begin DoDot:1
+4 IF $DATA(^MAG(2005,IEN,1))
SET IENGRP=IEN
+5 IF '$TEST
SET IENGRP=$PIECE(^MAG(2005,IEN,0),U,10)
+6 IF IENGRP
SET X=$GET(^MAG(2005,IENGRP,2))
IF $PIECE(X,U,6)=74
SET RARPT=$PIECE(X,U,7)
+7 IF RARPT
IF $DATA(^RARPT(RARPT,2005))
+8 ; no Rad report node!
IF '$TEST
SET RARPT=""
End DoDot:1
+9 if $QUIT
QUIT RARPT
QUIT
+10 ;
+11 ;Structure of PS/PSTRAK data In:
+12 ; *IMAGE
+13 ; IEN^
+14 ; *PS
+15 ; UID^[KEY/INTERP/USER]
+16 ; 1: N Lines of PS data follow
+17 ; *END_PS
+18 ; *PS
+19 ; UID^[KEY/INTERP/USER]
+20 ; 1: N Lines of PS data follow
+21 ; *END_PS
+22 ; *END_IMAGE
+23 ; *IMAGE
+24 ; ... etc.
+25 ; *END_IMAGE
+26 ; *END
END ;