MAGDQR32 ;WOIFO/MLH - UID query return logic for C-FIND ; 30 Dec 2011 4:09 PM
 ;;3.0;IMAGING;**118**;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
 ;
UIDOLD(IMAGE,REQ,RESULT,MAGDUZ,PAT,SSN,ACC,SID,UID,FD,LD) ; Generate response data to pat name / SSN query - called from MAGDQR02
 N X,P,V,MAGD0,MAGD1,MAGD2
 I $G(MAGDUZ)="" D ERR^MAGDQRUE("No Imaging user defined for this query"),ERRSAV^MAGDQRUE Q
 I $G(RESULT)="" D ERR^MAGDQRUE("No results set to save to"),ERRSAV^MAGDQRUE Q
 I '$G(IMAGE) D ERR^MAGDQRUE("Invalid IMAGE file pointer: '"_$G(IMAGE)_"'"),ERRSAV^MAGDQRUE Q
 S X=$G(^MAG(2005,IMAGE,0)),P=+$P(X,"^",7)
 I $G(PAT)+$G(SSN),P,'$D(^TMP("MAG",$J,"QR",11,P)) Q
 S X=$G(^MAG(2005,IMAGE,2))
 S V=$P(X,"^",5),FD=$G(FD),LD=$G(LD) I V,(FD&(V<FD))!(LD&(V>LD)) Q  ; UNIT TEST!!
 S V=$P(X,"^",6)
 ; Radiology Image
 I V=74 D  Q  ; Radiology Image
 . S X=$G(^RARPT(+$P(X,"^",7),0)) ; IA # 1171
 . S MAGD0=$P(X,"^",2),MAGD1=9999999.9999-$P(X,"^",3),V=$P(X,"^",4)
 . S MAGD2=$O(^RADPT(MAGD0,"DT",MAGD1,"P","B",V,"")) ; IA # 1172
 . I $G(ACC)+$G(SID),'$D(^TMP("MAG",$J,"QR",12,"R^"_MAGD0_"^"_MAGD1_"^"_MAGD2)) Q  ; UNIT TEST!!
 . D RESULT^MAGDQR03("R",.REQ,RESULT,IMAGE,MAGDUZ,MAGD0,MAGD1,MAGD2)
 . Q
 ; Consult Image
 I (V=8925)!(V=2006.5839) D RESULT^MAGDQR03("C",.REQ,RESULT,IMAGE,MAGDUZ,P,0,0) Q
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGDQR32   2315     printed  Sep 23, 2025@19:37:17                                                                                                                                                                                                    Page 2
MAGDQR32  ;WOIFO/MLH - UID query return logic for C-FIND ; 30 Dec 2011 4:09 PM
 +1       ;;3.0;IMAGING;**118**;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      ;
UIDOLD(IMAGE,REQ,RESULT,MAGDUZ,PAT,SSN,ACC,SID,UID,FD,LD) ; Generate response data to pat name / SSN query - called from MAGDQR02
 +1        NEW X,P,V,MAGD0,MAGD1,MAGD2
 +2        IF $GET(MAGDUZ)=""
               DO ERR^MAGDQRUE("No Imaging user defined for this query")
               DO ERRSAV^MAGDQRUE
               QUIT 
 +3        IF $GET(RESULT)=""
               DO ERR^MAGDQRUE("No results set to save to")
               DO ERRSAV^MAGDQRUE
               QUIT 
 +4        IF '$GET(IMAGE)
               DO ERR^MAGDQRUE("Invalid IMAGE file pointer: '"_$GET(IMAGE)_"'")
               DO ERRSAV^MAGDQRUE
               QUIT 
 +5        SET X=$GET(^MAG(2005,IMAGE,0))
           SET P=+$PIECE(X,"^",7)
 +6        IF $GET(PAT)+$GET(SSN)
               IF P
                   IF '$DATA(^TMP("MAG",$JOB,"QR",11,P))
                       QUIT 
 +7        SET X=$GET(^MAG(2005,IMAGE,2))
 +8       ; UNIT TEST!!
           SET V=$PIECE(X,"^",5)
           SET FD=$GET(FD)
           SET LD=$GET(LD)
           IF V
               IF (FD&(V<FD))!(LD&(V>LD))
                   QUIT 
 +9        SET V=$PIECE(X,"^",6)
 +10      ; Radiology Image
 +11      ; Radiology Image
           IF V=74
               Begin DoDot:1
 +12      ; IA # 1171
                   SET X=$GET(^RARPT(+$PIECE(X,"^",7),0))
 +13               SET MAGD0=$PIECE(X,"^",2)
                   SET MAGD1=9999999.9999-$PIECE(X,"^",3)
                   SET V=$PIECE(X,"^",4)
 +14      ; IA # 1172
                   SET MAGD2=$ORDER(^RADPT(MAGD0,"DT",MAGD1,"P","B",V,""))
 +15      ; UNIT TEST!!
                   IF $GET(ACC)+$GET(SID)
                       IF '$DATA(^TMP("MAG",$JOB,"QR",12,"R^"_MAGD0_"^"_MAGD1_"^"_MAGD2))
                           QUIT 
 +16               DO RESULT^MAGDQR03("R",.REQ,RESULT,IMAGE,MAGDUZ,MAGD0,MAGD1,MAGD2)
 +17               QUIT 
               End DoDot:1
               QUIT 
 +18      ; Consult Image
 +19       IF (V=8925)!(V=2006.5839)
               DO RESULT^MAGDQR03("C",.REQ,RESULT,IMAGE,MAGDUZ,P,0,0)
               QUIT 
 +20       QUIT