MAGVSTDY ;WOIFO/RRB,MAT - Read a DICOM image file ;  5 Apr 2013 12:55 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
 ;+++++ Lookup the patient/study for an imaging service.
 ;
 ;   [RPC: MAGV STUDY LOOKUP]
 ;   
 ;   Calls LOOKUP^MAGVORDR
 ;
 ; Inputs
 ; ======
 ;
 ;   RADATA     Variable to contain the string to return.
 ;   CASENUMB   Day-Case/Accession Number (RAD package)
 ;   IMGSVC     Imaging Service (RAD, CON)
 ;   PNAMEDCM   DICOM Header (0010,0010) Patient Name
 ;   PIDDCM      "     "     (0010,0020)  "      ID
 ;   PDOBDCM     "     "     (0010,0030)  "      Date of Birth
 ;   PSEXDCM     "     "     (0010,0040)  "      Sex
 ;   [PICNDCM]   "     "        ????      "      Integration Control Number
 ; 
 ; Output
 ; ======
 ;           ----From MAGVORDR----  --From PIDCHECK--
 ;           Error     Success      Error    Success
 ;    "~"-1  -1        0
 ;       -2  Errmsg1   DFN
 ;       -3   ---      Site ID
 ;       -4   ---      ---------->  n<1      0
 ;       -5   ---      ---------->  Errmsg2  PID OK
 ;
 ;    Errmsg1______   If_____________
 ;  
 ;    -1~BAD CASE #     RAD and Null RADPTx
 ;                      RAD - Null Exam Status pointer
 ;                      RAD - Null Exam Status
 ;    -1~NO CASE #      RAD,CON - Exam Status = CANCELLED
 ;                      RAD,CON - no patient demographic file pointer
 ;                      CON - incomplete consult study
 ;
LOOKUP(RADATA,CASENUMB,IMGSVC,PNAMEDCM,PIDDCM,PDOBDCM,PSEXDCM,PICNDCM) ;
 ;
 S PICNDCM=$G(PICNDCM)
 ;
 ;--- Lookup DFN, SITE. Quit if -1, Else RADATA="0~"_DFN_"~"_SITE.
 S RADATA=$$LOOKUP^MAGVORDR(CASENUMB,IMGSVC)
 Q:+RADATA=-1
 ;
 ; Look up and compare Patient Data associated with the CASENUM
 N DFN S DFN=$P(RADATA,"~",2)
 S RADATA=RADATA_"~"_$$PIDCHECK(DFN,PNAMEDCM,PIDDCM,PDOBDCM,PSEXDCM,PICNDCM)
 Q
 ;+++++  Wrap call to PIDCHECK^MAGDIR8A() and change delimiter.
 ;   
 ;   Internal entry point called by tag LOOKUP.
 ;   Lookup patient demographics by DFN to validate DICOM header values.
 ;
 ; Inputs
 ; ======
 ; 
 ;   DFN     IEN in the RAD/NUC MED PATIENT File (#70)
 ;
 ;   Other parameters as described at tag LOOKUP.
 ;
 ; Output
 ; ======
 ; 
 ;   If found & match:  0~PID OK
 ;   On error:          n<0~ERRMSG
 ; 
 ; Notes
 ; =====
 ;
 ;   PIDCHECK^MAGDIR8A expects:
 ; 
 ;     PID        As passed to MAGDIR8 by the gateway. Here it is
 ;                  set to PIDDCM.
 ;     CASENUMB
 ;     [INSTLOC]  Instrument Location: A Site ID from the gateway's
 ;                  INSTRUMENT DICTIONARY: ^MAGDICOM(2006.581,IEN, "^"-5
 ;                  used by DEM^MAGSPID.
 ;
PIDCHECK(DFN,PNAMEDCM,PIDDCM,PDOBDCM,PSEXDCM,PICNDCM) ;
 ;
 ;--- Initialize additional expected variables.
 N FIRSTDCM,LASTDCM,MIDCM,PNAMEVAH
 N PID S PID=PIDDCM
 ;--- Next line check & transform copied from READFILE+27^MAGDIR6B.
 I $$ISIHS^MAGSPID() S PID=+PID ; P123 strip off leading zero(s)
 N RETURN
 S RETURN=$$PIDCHECK^MAGDIR8A()
 S RETURN=$S(RETURN=0:"0~PID OK",1:$TR(RETURN,",","~"))
 Q RETURN
 ;
 ; MAGVSTDY
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGVSTDY   4135     printed  Sep 23, 2025@19:46:52                                                                                                                                                                                                    Page 2
MAGVSTDY  ;WOIFO/RRB,MAT - Read a DICOM image file ;  5 Apr 2013 12:55 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      ;
 +18       QUIT 
 +19      ;+++++ Lookup the patient/study for an imaging service.
 +20      ;
 +21      ;   [RPC: MAGV STUDY LOOKUP]
 +22      ;   
 +23      ;   Calls LOOKUP^MAGVORDR
 +24      ;
 +25      ; Inputs
 +26      ; ======
 +27      ;
 +28      ;   RADATA     Variable to contain the string to return.
 +29      ;   CASENUMB   Day-Case/Accession Number (RAD package)
 +30      ;   IMGSVC     Imaging Service (RAD, CON)
 +31      ;   PNAMEDCM   DICOM Header (0010,0010) Patient Name
 +32      ;   PIDDCM      "     "     (0010,0020)  "      ID
 +33      ;   PDOBDCM     "     "     (0010,0030)  "      Date of Birth
 +34      ;   PSEXDCM     "     "     (0010,0040)  "      Sex
 +35      ;   [PICNDCM]   "     "        ????      "      Integration Control Number
 +36      ; 
 +37      ; Output
 +38      ; ======
 +39      ;           ----From MAGVORDR----  --From PIDCHECK--
 +40      ;           Error     Success      Error    Success
 +41      ;    "~"-1  -1        0
 +42      ;       -2  Errmsg1   DFN
 +43      ;       -3   ---      Site ID
 +44      ;       -4   ---      ---------->  n<1      0
 +45      ;       -5   ---      ---------->  Errmsg2  PID OK
 +46      ;
 +47      ;    Errmsg1______   If_____________
 +48      ;  
 +49      ;    -1~BAD CASE #     RAD and Null RADPTx
 +50      ;                      RAD - Null Exam Status pointer
 +51      ;                      RAD - Null Exam Status
 +52      ;    -1~NO CASE #      RAD,CON - Exam Status = CANCELLED
 +53      ;                      RAD,CON - no patient demographic file pointer
 +54      ;                      CON - incomplete consult study
 +55      ;
LOOKUP(RADATA,CASENUMB,IMGSVC,PNAMEDCM,PIDDCM,PDOBDCM,PSEXDCM,PICNDCM) ;
 +1       ;
 +2        SET PICNDCM=$GET(PICNDCM)
 +3       ;
 +4       ;--- Lookup DFN, SITE. Quit if -1, Else RADATA="0~"_DFN_"~"_SITE.
 +5        SET RADATA=$$LOOKUP^MAGVORDR(CASENUMB,IMGSVC)
 +6        if +RADATA=-1
               QUIT 
 +7       ;
 +8       ; Look up and compare Patient Data associated with the CASENUM
 +9        NEW DFN
           SET DFN=$PIECE(RADATA,"~",2)
 +10       SET RADATA=RADATA_"~"_$$PIDCHECK(DFN,PNAMEDCM,PIDDCM,PDOBDCM,PSEXDCM,PICNDCM)
 +11       QUIT 
 +12      ;+++++  Wrap call to PIDCHECK^MAGDIR8A() and change delimiter.
 +13      ;   
 +14      ;   Internal entry point called by tag LOOKUP.
 +15      ;   Lookup patient demographics by DFN to validate DICOM header values.
 +16      ;
 +17      ; Inputs
 +18      ; ======
 +19      ; 
 +20      ;   DFN     IEN in the RAD/NUC MED PATIENT File (#70)
 +21      ;
 +22      ;   Other parameters as described at tag LOOKUP.
 +23      ;
 +24      ; Output
 +25      ; ======
 +26      ; 
 +27      ;   If found & match:  0~PID OK
 +28      ;   On error:          n<0~ERRMSG
 +29      ; 
 +30      ; Notes
 +31      ; =====
 +32      ;
 +33      ;   PIDCHECK^MAGDIR8A expects:
 +34      ; 
 +35      ;     PID        As passed to MAGDIR8 by the gateway. Here it is
 +36      ;                  set to PIDDCM.
 +37      ;     CASENUMB
 +38      ;     [INSTLOC]  Instrument Location: A Site ID from the gateway's
 +39      ;                  INSTRUMENT DICTIONARY: ^MAGDICOM(2006.581,IEN, "^"-5
 +40      ;                  used by DEM^MAGSPID.
 +41      ;
PIDCHECK(DFN,PNAMEDCM,PIDDCM,PDOBDCM,PSEXDCM,PICNDCM) ;
 +1       ;
 +2       ;--- Initialize additional expected variables.
 +3        NEW FIRSTDCM,LASTDCM,MIDCM,PNAMEVAH
 +4        NEW PID
           SET PID=PIDDCM
 +5       ;--- Next line check & transform copied from READFILE+27^MAGDIR6B.
 +6       ; P123 strip off leading zero(s)
           IF $$ISIHS^MAGSPID()
               SET PID=+PID
 +7        NEW RETURN
 +8        SET RETURN=$$PIDCHECK^MAGDIR8A()
 +9        SET RETURN=$SELECT(RETURN=0:"0~PID OK",1:$TRANSLATE(RETURN,",","~"))
 +10       QUIT RETURN
 +11      ;
 +12      ; MAGVSTDY