MAGNGMR ;WOIFO/NST - Imaging interface to Consult RPC Calls etc. ; 11 Feb 2011 8:36 AM
;;3.0;IMAGING;**106**;Mar 19, 2002;Build 2002;Feb 28, 2011
;; 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
;
;***** Add a consult and image pointers to
; Unread/Read List file (#2006.5849)
; and
; DICOM GMRC TEMP LIST file (#2006.5839)
;
; RPC:MAG3 TELEREADER READ/UNRD ADD
;
; Input Parameters
; ================
; MAGDA is an image IEN in IMAGE file (#2005) - ^MAG(2005,MAGDA)
; MAGCNT is count of new images captured
; MAGRIEN is a request/consult IEN in REQUEST/CONSULTATION file (#123)
;
; Return Values
; =============
; if error MAGRY = The first "^" piece is zero if error occurs. The second piece is an error message
; if success MAGRY = The first "^" piece is one and the second is update message
;
FILE(MAGRY,MAGDA,MAGCNT,MAGRIEN) ;RPC [MAG3 TELEREADER READ/UNRD ADD]
;
; The routine is called from GUI after the group is captured
N D0,X,MAGI
N MAGNFDA,MAGNIEN,MAGNXE,MAGRESA
N RESULT,MAGFND,MAGGRP
N $ETRAP,$ESTACK S $ETRAP="D ERR^MAGGTERR"
;
S MAGRY="0^Filing Image Pointer Failed"
;
; Get a Group IEN
S MAGGRP=$$GRPIEN^MAGGI12(MAGDA)
I MAGGRP<0 S MAGRY="0^Error getting Group IEN" Q ; Error getting Group IEN
I MAGGRP=0 S MAGGRP=MAGDA ; Single Image or the group IEN itself
;
; add the consult to the Consult Unread List, if necessary
D ADD^MAGDTR03(.RESULT,MAGRIEN,"I",MAGCNT) ; add if "ON IMAGE" is set
;
I 'RESULT S MAGRY="1^Skipped filing image pointer" Q ; Do not add it to file #2006.5839
;
S MAGI="",MAGFND=0
F S MAGI=$O(^MAG(2006.5839,"C",123,MAGRIEN,MAGI)) Q:'MAGI D Q:MAGFND
. S:MAGGRP=$P(^MAG(2006.5839,MAGI,0),"^",3) MAGFND=1
. Q
;
I MAGFND S MAGRY="1^Image pointer filed previously" Q ; No need to add it to file #2006.5839
;
; Update DICOM GMRC TEMP LIST counters
;
S MAGNFDA(2006.5839,"+1,",.01)=123 ; REQUEST/CONSULTATION file (#123)
S MAGNFDA(2006.5839,"+1,",2)=MAGRIEN ; IEN in file #123
S MAGNFDA(2006.5839,"+1,",3)=MAGGRP ; IEN in IMAGE file (#2005)
D UPDATE^DIE("S","MAGNFDA","MAGNIEN","MAGNXE")
I $D(MAGNXE("DIERR","E")) D Q
. D MSG^DIALOG("A",.MAGRESA,245,5,"MAGNXE")
. S MAGRY="0^"_MAGRESA(1)
. Q
;
; Set the Parent fields in the Image File for the group
S $P(^MAG(2005,MAGGRP,2),U,6,8)=2006.5839_U_MAGRIEN_U_""
; Save the PARENT ASSOCIATION Date/Time
D LINKDT^MAGGTU6(.X,MAGGRP)
;
; Set Parent fields for the children
S MAGI=0
F S MAGI=$O(^MAG(2005,MAGGRP,1,MAGI)) Q:'MAGI D
. S D0=$P($G(^MAG(2005,MAGGRP,1,MAGI,0)),U,1) ; Get IEN of the child
. Q:'D0 ; IEN is missing
. S $P(^MAG(2005,D0,2),U,6,8)=2006.5839_U_MAGRIEN_U_""
. D LINKDT^MAGGTU6(.X,D0)
. Q
;
; DONE.
S MAGRY="1^Image pointer filed successfully"
Q
;
;***** Return not completed consults for a patient where
; consult request "To Service" is setup in TELEREADER ACQUISITION SERVICE file (#2006.5841)
; RPC: MAG3 TELEREADER CONSULT LIST
;
; Input Parameters
; ================
; DFN - Patient ID
;
; Return Values
; =============
; if error found during execution
; MAGRY(0) = "0^Error getting consult list"
; if success
; MAGRY(0) = "1^#CNT" - where #CNT is a number of records returned
; MAGRY(1) = "Consult ID^Consult Request Date^Service^Procedure^Sending Provider^Status"
; MAGRY(2..n) = "^" delimited string with values of the fields listed in MAGRY(1)
;
CONSLIST(MAGRY,DFN) ;RPC [MAG3 TELEREADER CONSULT LIST]
;
N I,SRVC,PROC,STAT,DAT,X,CNT
N RES
N CONIEN,IENS,OUT,DOCNAME
N EXCLCONS
;
N $ETRAP,$ESTACK S $ETRAP="D ERRA^MAGGTERR"
;
; Exclude consult with statuses
S EXCLCONS("DISCONTINUED")=""
S EXCLCONS("COMPLETE")=""
S EXCLCONS("HOLD")=""
S EXCLCONS("FLAGGED")=""
S EXCLCONS("EXPIRED")=""
S EXCLCONS("DELAYED")=""
S EXCLCONS("UNRELEASED")=""
S EXCLCONS("DISCONTINUED/EDIT")=""
S EXCLCONS("CANCELLED")=""
S EXCLCONS("LAPSED")=""
;
K MAGRY
S MAGRY(0)="0^Error"
;
I +DFN'>0 S MAGRY(0)="0^Not a valid Patient ID" Q ; no patient number provided
;
K ^TMP("GMRCR",$J,"CS") ; clean up the temp list before the consult call
D OER^GMRCSLM1(DFN,"","","","",1) ; IA #2740
S CNT=1
S I=0
F S I=$O(^TMP("GMRCR",$J,"CS",I)) Q:+I'>0 D
. S X=$G(^TMP("GMRCR",$J,"CS",I,0))
. S CONIEN=$P(X,U,1) ; consult IEN
. Q:CONIEN'>0 ; Quit if no consult found
. Q:'$$FINDLIST^MAGDTR01(CONIEN) ; skip the Consult/Procedure - the TO Service is not in TELEREADER ACQUISITION SERVICE file (#2006.5841)
. S STAT=$P(X,U,3) ; consult status
. Q:STAT=""
. Q:$D(EXCLCONS(STAT)) ; skip consults with status in EXCLCONS array
. S SRVC=$P(X,U,4) ; REQUEST SERVICES
. S DAT=$P(X,U,2) ; date of consult
. S PROC=$S($P(X,U,5)="Consult":"",1:$P(X,U,5)) ; procedure
. S IENS=CONIEN_","
. K OUT
. D GETS^DIQ(123,IENS,10,"","OUT") ; Get SENDING PROVIDER for a consult
. S DOCNAME=$G(OUT(123,IENS,10)) ; requested physician name
. S CNT=CNT+1
. S MAGRY(CNT)=CONIEN_U_DAT_U_SRVC_U_PROC_U_DOCNAME_U_STAT
. Q
K ^TMP("GMRCR",$J,"CS") ; clean up the temp list from the consult call
S MAGRY(0)="1^"_(CNT-1)
S MAGRY(1)="Consult ID^Consult Request Date^Service^Procedure^Sending Provider^Status"
K RES
Q
;
;***** Returns a new TELEREADER DICOM Study, Series or SOP Instance UID
;
; RPC: MAG3 TELEREADER DICOM UID
;
; Input Parameters
; ================
; MAGPARAM - array with input values
; MAGPARAM("TYPE")= Type UID - "STUDY", "SERIES", "SOP"
; MAGPARAM("ACNUM")= Accession number - Patient consult ID
; MAGPARAM("DFN")= Patient DFN
;
; Return Values
; =============
; if error found during execution
; MAGRY = "0^Error message"
; if success
; MAGRY = "1^UID
;
;
GETUID(MAGRY,MAGPARAM) ; RPC [MAG3 TELEREADER DICOM UID]
N UID,SITE,SITEIEN
N MAGTYPE,MAGACNUM,MAGDFN
N RESULT,TYPENUM
N ERR,DONE
;
N $ETRAP,$ESTACK S $ETRAP="D ERR^MAGGTERR"
;
S MAGTYPE=$G(MAGPARAM("TYPE"))
S MAGACNUM=$G(MAGPARAM("ACNUM"))
S MAGDFN=$G(MAGPARAM("DFN"))
S MAGRY="0^Error creating UID"
;
I (MAGTYPE'="STUDY"),(MAGTYPE'="SERIES"),(MAGTYPE'="SOP") S MAGRY="0^Unknow TYPE parameter:"_MAGTYPE Q
S TYPENUM=$S(MAGTYPE="STUDY":"106.4",MAGTYPE="SERIES":"106.7",1:"106.8")
;
; Get the Study UID for the consult if one already exists
S RESULT=""
I MAGTYPE="STUDY" D I RESULT'="" S MAGRY="1^"_RESULT Q
. Q:(MAGACNUM="")!(MAGDFN="") ; Generate a new Study UID. Accession number or DFN is not provided
. S RESULT=$$GSTUID^MAGNGMR(MAGACNUM,MAGDFN)
. Q
;
S SITEIEN=$G(DUZ(2))
S:SITEIEN="" SITEIEN=$$KSP^XUPARAM("INST") ; IA #2541 Get Default Station IEN
S SITE=$P($$NS^XUAF4(SITEIEN),U,2) ; IA #2171 Get Station Number
; Generate a new UID and check for dupes
S (ERR,DONE)=0
F D Q:ERR!DONE
. D NEWUID^MAGNUID1(.MAGRY,SITE,TYPENUM,"") ; Get a new UID
. I 'MAGRY S ERR=1 Q ; Error during UID generation
. S UID=$P(MAGRY,"^",2) ; Set the UID
. ; Check for Dupes
. I $$ISDUP^MAGNUID2(MAGTYPE,UID) Q ; generate a new one
. S DONE=1
. Q
Q ; MAGRY is set when a new UID is generated
;
;+++++ Returns Study UID for accession number
;
; ACCNUM - Consult/Procedure Accession number
; DFN - Patient ID
;
GSTUID(ACCNUM,DFN) ; Check if a study UID exist for accession number (ACCNUM) and patient (DFN)
; Study UID is stored in image group level in IMAGE file (#2005)
N RESULT
N MAGIEN ; IEN in DICOM GMRC TEMP LIST file (#2006.5839)
N MAGDA,MAGGRP
; Get the image IEN in IMAGE file (#2005)
S MAGIEN=$O(^MAG(2006.5839,"C",123,ACCNUM,"")) ; Get IEN for the consult in file #2006.5839
I MAGIEN="" Q "" ; Cannot find Study UID
S MAGGRP=$P(^MAG(2006.5839,MAGIEN,0),U,3) ; IEN in IMAGE file (#2005)
I '$$ISGRP^MAGGI11(MAGGRP) D
. S MAGGRP=$$GRPIEN^MAGGI12(MAGGRP) ; Get the group IEN
. Q
I MAGGRP'>0 Q "" ; It is not a group. Cannot get Study UID from a single image
I $P(^MAG(2005,MAGGRP,0),U,7)'=DFN Q "" ; the patient of the group is not the same. Quit blank
S RESULT=$P(^MAG(2005,MAGGRP,"PACS"),U,1) ; Get Study UID
Q RESULT
;
;***** Generates DICOM Series Number
;
; RPC: MAG3 TELEREADER DICOM SER NUM
;
; Input Parameters
; ================
; N/A
;
; Return Values
; =============
; if error found during execution
; MAGRY = "0^Error message"
; if success
; MAGRY = "1^DICOM Series Number
;
;
GETSRNUM(MAGRY) ; RPC [MAG3 TELEREADER DICOM SER NUM]
N H,M,S,TIME,DATE,DH,X
S MAGRY="0^Error creating Series Number"
; can't use D NOW^XLFDT to set DH because it is incorrect at midnight
S DH=$H
S DATE=$$HTFM^XLFDT(DH,1)+17000000
S DATE=$E(DATE,5,8) ; Strip the year. Just get MMDD because of size limitation in DICOM standard
S X=$P(DH,",",2)
S H=X\3600,M=X\60#60,S=X#60
S TIME=H*100+M*100+S
S TIME=$E("000000",1,6-$L(TIME))_TIME ; Pad the time
S MAGRY="1^"_DATE_TIME
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGNGMR 10031 printed Nov 22, 2024@17:17:21 Page 2
MAGNGMR ;WOIFO/NST - Imaging interface to Consult RPC Calls etc. ; 11 Feb 2011 8:36 AM
+1 ;;3.0;IMAGING;**106**;Mar 19, 2002;Build 2002;Feb 28, 2011
+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 ;***** Add a consult and image pointers to
+20 ; Unread/Read List file (#2006.5849)
+21 ; and
+22 ; DICOM GMRC TEMP LIST file (#2006.5839)
+23 ;
+24 ; RPC:MAG3 TELEREADER READ/UNRD ADD
+25 ;
+26 ; Input Parameters
+27 ; ================
+28 ; MAGDA is an image IEN in IMAGE file (#2005) - ^MAG(2005,MAGDA)
+29 ; MAGCNT is count of new images captured
+30 ; MAGRIEN is a request/consult IEN in REQUEST/CONSULTATION file (#123)
+31 ;
+32 ; Return Values
+33 ; =============
+34 ; if error MAGRY = The first "^" piece is zero if error occurs. The second piece is an error message
+35 ; if success MAGRY = The first "^" piece is one and the second is update message
+36 ;
FILE(MAGRY,MAGDA,MAGCNT,MAGRIEN) ;RPC [MAG3 TELEREADER READ/UNRD ADD]
+1 ;
+2 ; The routine is called from GUI after the group is captured
+3 NEW D0,X,MAGI
+4 NEW MAGNFDA,MAGNIEN,MAGNXE,MAGRESA
+5 NEW RESULT,MAGFND,MAGGRP
+6 NEW $ETRAP,$ESTACK
SET $ETRAP="D ERR^MAGGTERR"
+7 ;
+8 SET MAGRY="0^Filing Image Pointer Failed"
+9 ;
+10 ; Get a Group IEN
+11 SET MAGGRP=$$GRPIEN^MAGGI12(MAGDA)
+12 ; Error getting Group IEN
IF MAGGRP<0
SET MAGRY="0^Error getting Group IEN"
QUIT
+13 ; Single Image or the group IEN itself
IF MAGGRP=0
SET MAGGRP=MAGDA
+14 ;
+15 ; add the consult to the Consult Unread List, if necessary
+16 ; add if "ON IMAGE" is set
DO ADD^MAGDTR03(.RESULT,MAGRIEN,"I",MAGCNT)
+17 ;
+18 ; Do not add it to file #2006.5839
IF 'RESULT
SET MAGRY="1^Skipped filing image pointer"
QUIT
+19 ;
+20 SET MAGI=""
SET MAGFND=0
+21 FOR
SET MAGI=$ORDER(^MAG(2006.5839,"C",123,MAGRIEN,MAGI))
if 'MAGI
QUIT
Begin DoDot:1
+22 if MAGGRP=$PIECE(^MAG(2006.5839,MAGI,0),"^",3)
SET MAGFND=1
+23 QUIT
End DoDot:1
if MAGFND
QUIT
+24 ;
+25 ; No need to add it to file #2006.5839
IF MAGFND
SET MAGRY="1^Image pointer filed previously"
QUIT
+26 ;
+27 ; Update DICOM GMRC TEMP LIST counters
+28 ;
+29 ; REQUEST/CONSULTATION file (#123)
SET MAGNFDA(2006.5839,"+1,",.01)=123
+30 ; IEN in file #123
SET MAGNFDA(2006.5839,"+1,",2)=MAGRIEN
+31 ; IEN in IMAGE file (#2005)
SET MAGNFDA(2006.5839,"+1,",3)=MAGGRP
+32 DO UPDATE^DIE("S","MAGNFDA","MAGNIEN","MAGNXE")
+33 IF $DATA(MAGNXE("DIERR","E"))
Begin DoDot:1
+34 DO MSG^DIALOG("A",.MAGRESA,245,5,"MAGNXE")
+35 SET MAGRY="0^"_MAGRESA(1)
+36 QUIT
End DoDot:1
QUIT
+37 ;
+38 ; Set the Parent fields in the Image File for the group
+39 SET $PIECE(^MAG(2005,MAGGRP,2),U,6,8)=2006.5839_U_MAGRIEN_U_""
+40 ; Save the PARENT ASSOCIATION Date/Time
+41 DO LINKDT^MAGGTU6(.X,MAGGRP)
+42 ;
+43 ; Set Parent fields for the children
+44 SET MAGI=0
+45 FOR
SET MAGI=$ORDER(^MAG(2005,MAGGRP,1,MAGI))
if 'MAGI
QUIT
Begin DoDot:1
+46 ; Get IEN of the child
SET D0=$PIECE($GET(^MAG(2005,MAGGRP,1,MAGI,0)),U,1)
+47 ; IEN is missing
if 'D0
QUIT
+48 SET $PIECE(^MAG(2005,D0,2),U,6,8)=2006.5839_U_MAGRIEN_U_""
+49 DO LINKDT^MAGGTU6(.X,D0)
+50 QUIT
End DoDot:1
+51 ;
+52 ; DONE.
+53 SET MAGRY="1^Image pointer filed successfully"
+54 QUIT
+55 ;
+56 ;***** Return not completed consults for a patient where
+57 ; consult request "To Service" is setup in TELEREADER ACQUISITION SERVICE file (#2006.5841)
+58 ; RPC: MAG3 TELEREADER CONSULT LIST
+59 ;
+60 ; Input Parameters
+61 ; ================
+62 ; DFN - Patient ID
+63 ;
+64 ; Return Values
+65 ; =============
+66 ; if error found during execution
+67 ; MAGRY(0) = "0^Error getting consult list"
+68 ; if success
+69 ; MAGRY(0) = "1^#CNT" - where #CNT is a number of records returned
+70 ; MAGRY(1) = "Consult ID^Consult Request Date^Service^Procedure^Sending Provider^Status"
+71 ; MAGRY(2..n) = "^" delimited string with values of the fields listed in MAGRY(1)
+72 ;
CONSLIST(MAGRY,DFN) ;RPC [MAG3 TELEREADER CONSULT LIST]
+1 ;
+2 NEW I,SRVC,PROC,STAT,DAT,X,CNT
+3 NEW RES
+4 NEW CONIEN,IENS,OUT,DOCNAME
+5 NEW EXCLCONS
+6 ;
+7 NEW $ETRAP,$ESTACK
SET $ETRAP="D ERRA^MAGGTERR"
+8 ;
+9 ; Exclude consult with statuses
+10 SET EXCLCONS("DISCONTINUED")=""
+11 SET EXCLCONS("COMPLETE")=""
+12 SET EXCLCONS("HOLD")=""
+13 SET EXCLCONS("FLAGGED")=""
+14 SET EXCLCONS("EXPIRED")=""
+15 SET EXCLCONS("DELAYED")=""
+16 SET EXCLCONS("UNRELEASED")=""
+17 SET EXCLCONS("DISCONTINUED/EDIT")=""
+18 SET EXCLCONS("CANCELLED")=""
+19 SET EXCLCONS("LAPSED")=""
+20 ;
+21 KILL MAGRY
+22 SET MAGRY(0)="0^Error"
+23 ;
+24 ; no patient number provided
IF +DFN'>0
SET MAGRY(0)="0^Not a valid Patient ID"
QUIT
+25 ;
+26 ; clean up the temp list before the consult call
KILL ^TMP("GMRCR",$JOB,"CS")
+27 ; IA #2740
DO OER^GMRCSLM1(DFN,"","","","",1)
+28 SET CNT=1
+29 SET I=0
+30 FOR
SET I=$ORDER(^TMP("GMRCR",$JOB,"CS",I))
if +I'>0
QUIT
Begin DoDot:1
+31 SET X=$GET(^TMP("GMRCR",$JOB,"CS",I,0))
+32 ; consult IEN
SET CONIEN=$PIECE(X,U,1)
+33 ; Quit if no consult found
if CONIEN'>0
QUIT
+34 ; skip the Consult/Procedure - the TO Service is not in TELEREADER ACQUISITION SERVICE file (#2006.5841)
if '$$FINDLIST^MAGDTR01(CONIEN)
QUIT
+35 ; consult status
SET STAT=$PIECE(X,U,3)
+36 if STAT=""
QUIT
+37 ; skip consults with status in EXCLCONS array
if $DATA(EXCLCONS(STAT))
QUIT
+38 ; REQUEST SERVICES
SET SRVC=$PIECE(X,U,4)
+39 ; date of consult
SET DAT=$PIECE(X,U,2)
+40 ; procedure
SET PROC=$SELECT($PIECE(X,U,5)="Consult":"",1:$PIECE(X,U,5))
+41 SET IENS=CONIEN_","
+42 KILL OUT
+43 ; Get SENDING PROVIDER for a consult
DO GETS^DIQ(123,IENS,10,"","OUT")
+44 ; requested physician name
SET DOCNAME=$GET(OUT(123,IENS,10))
+45 SET CNT=CNT+1
+46 SET MAGRY(CNT)=CONIEN_U_DAT_U_SRVC_U_PROC_U_DOCNAME_U_STAT
+47 QUIT
End DoDot:1
+48 ; clean up the temp list from the consult call
KILL ^TMP("GMRCR",$JOB,"CS")
+49 SET MAGRY(0)="1^"_(CNT-1)
+50 SET MAGRY(1)="Consult ID^Consult Request Date^Service^Procedure^Sending Provider^Status"
+51 KILL RES
+52 QUIT
+53 ;
+54 ;***** Returns a new TELEREADER DICOM Study, Series or SOP Instance UID
+55 ;
+56 ; RPC: MAG3 TELEREADER DICOM UID
+57 ;
+58 ; Input Parameters
+59 ; ================
+60 ; MAGPARAM - array with input values
+61 ; MAGPARAM("TYPE")= Type UID - "STUDY", "SERIES", "SOP"
+62 ; MAGPARAM("ACNUM")= Accession number - Patient consult ID
+63 ; MAGPARAM("DFN")= Patient DFN
+64 ;
+65 ; Return Values
+66 ; =============
+67 ; if error found during execution
+68 ; MAGRY = "0^Error message"
+69 ; if success
+70 ; MAGRY = "1^UID
+71 ;
+72 ;
GETUID(MAGRY,MAGPARAM) ; RPC [MAG3 TELEREADER DICOM UID]
+1 NEW UID,SITE,SITEIEN
+2 NEW MAGTYPE,MAGACNUM,MAGDFN
+3 NEW RESULT,TYPENUM
+4 NEW ERR,DONE
+5 ;
+6 NEW $ETRAP,$ESTACK
SET $ETRAP="D ERR^MAGGTERR"
+7 ;
+8 SET MAGTYPE=$GET(MAGPARAM("TYPE"))
+9 SET MAGACNUM=$GET(MAGPARAM("ACNUM"))
+10 SET MAGDFN=$GET(MAGPARAM("DFN"))
+11 SET MAGRY="0^Error creating UID"
+12 ;
+13 IF (MAGTYPE'="STUDY")
IF (MAGTYPE'="SERIES")
IF (MAGTYPE'="SOP")
SET MAGRY="0^Unknow TYPE parameter:"_MAGTYPE
QUIT
+14 SET TYPENUM=$SELECT(MAGTYPE="STUDY":"106.4",MAGTYPE="SERIES":"106.7",1:"106.8")
+15 ;
+16 ; Get the Study UID for the consult if one already exists
+17 SET RESULT=""
+18 IF MAGTYPE="STUDY"
Begin DoDot:1
+19 ; Generate a new Study UID. Accession number or DFN is not provided
if (MAGACNUM="")!(MAGDFN="")
QUIT
+20 SET RESULT=$$GSTUID^MAGNGMR(MAGACNUM,MAGDFN)
+21 QUIT
End DoDot:1
IF RESULT'=""
SET MAGRY="1^"_RESULT
QUIT
+22 ;
+23 SET SITEIEN=$GET(DUZ(2))
+24 ; IA #2541 Get Default Station IEN
if SITEIEN=""
SET SITEIEN=$$KSP^XUPARAM("INST")
+25 ; IA #2171 Get Station Number
SET SITE=$PIECE($$NS^XUAF4(SITEIEN),U,2)
+26 ; Generate a new UID and check for dupes
+27 SET (ERR,DONE)=0
+28 FOR
Begin DoDot:1
+29 ; Get a new UID
DO NEWUID^MAGNUID1(.MAGRY,SITE,TYPENUM,"")
+30 ; Error during UID generation
IF 'MAGRY
SET ERR=1
QUIT
+31 ; Set the UID
SET UID=$PIECE(MAGRY,"^",2)
+32 ; Check for Dupes
+33 ; generate a new one
IF $$ISDUP^MAGNUID2(MAGTYPE,UID)
QUIT
+34 SET DONE=1
+35 QUIT
End DoDot:1
if ERR!DONE
QUIT
+36 ; MAGRY is set when a new UID is generated
QUIT
+37 ;
+38 ;+++++ Returns Study UID for accession number
+39 ;
+40 ; ACCNUM - Consult/Procedure Accession number
+41 ; DFN - Patient ID
+42 ;
GSTUID(ACCNUM,DFN) ; Check if a study UID exist for accession number (ACCNUM) and patient (DFN)
+1 ; Study UID is stored in image group level in IMAGE file (#2005)
+2 NEW RESULT
+3 ; IEN in DICOM GMRC TEMP LIST file (#2006.5839)
NEW MAGIEN
+4 NEW MAGDA,MAGGRP
+5 ; Get the image IEN in IMAGE file (#2005)
+6 ; Get IEN for the consult in file #2006.5839
SET MAGIEN=$ORDER(^MAG(2006.5839,"C",123,ACCNUM,""))
+7 ; Cannot find Study UID
IF MAGIEN=""
QUIT ""
+8 ; IEN in IMAGE file (#2005)
SET MAGGRP=$PIECE(^MAG(2006.5839,MAGIEN,0),U,3)
+9 IF '$$ISGRP^MAGGI11(MAGGRP)
Begin DoDot:1
+10 ; Get the group IEN
SET MAGGRP=$$GRPIEN^MAGGI12(MAGGRP)
+11 QUIT
End DoDot:1
+12 ; It is not a group. Cannot get Study UID from a single image
IF MAGGRP'>0
QUIT ""
+13 ; the patient of the group is not the same. Quit blank
IF $PIECE(^MAG(2005,MAGGRP,0),U,7)'=DFN
QUIT ""
+14 ; Get Study UID
SET RESULT=$PIECE(^MAG(2005,MAGGRP,"PACS"),U,1)
+15 QUIT RESULT
+16 ;
+17 ;***** Generates DICOM Series Number
+18 ;
+19 ; RPC: MAG3 TELEREADER DICOM SER NUM
+20 ;
+21 ; Input Parameters
+22 ; ================
+23 ; N/A
+24 ;
+25 ; Return Values
+26 ; =============
+27 ; if error found during execution
+28 ; MAGRY = "0^Error message"
+29 ; if success
+30 ; MAGRY = "1^DICOM Series Number
+31 ;
+32 ;
GETSRNUM(MAGRY) ; RPC [MAG3 TELEREADER DICOM SER NUM]
+1 NEW H,M,S,TIME,DATE,DH,X
+2 SET MAGRY="0^Error creating Series Number"
+3 ; can't use D NOW^XLFDT to set DH because it is incorrect at midnight
+4 SET DH=$HOROLOG
+5 SET DATE=$$HTFM^XLFDT(DH,1)+17000000
+6 ; Strip the year. Just get MMDD because of size limitation in DICOM standard
SET DATE=$EXTRACT(DATE,5,8)
+7 SET X=$PIECE(DH,",",2)
+8 SET H=X\3600
SET M=X\60#60
SET S=X#60
+9 SET TIME=H*100+M*100+S
+10 ; Pad the time
SET TIME=$EXTRACT("000000",1,6-$LENGTH(TIME))_TIME
+11 SET MAGRY="1^"_DATE_TIME
+12 QUIT