Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: MAGDSTA5

MAGDSTA5.m

Go to the documentation of this file.
  1. MAGDSTA5 ;WOIFO/PMK - Q/R Retrieve of DICOM images from PACS to VistA ; Mar 08, 2022@08:59:51
  1. ;;3.0;IMAGING;**231,305**;Mar 19, 2002;Build 3
  1. ;; Per VHA Directive 2004-038, this routine should not be modified.
  1. ;; +---------------------------------------------------------------+
  1. ;; | Property of the US Government. |
  1. ;; | No permission to copy or redistribute this software is given. |
  1. ;; | Use of unreleased versions of this software requires the user |
  1. ;; | to execute a written test agreement with the VistA Imaging |
  1. ;; | Development Office of the Department of Veterans Affairs, |
  1. ;; | telephone (301) 734-0100. |
  1. ;; | The Food and Drug Administration classifies this software as |
  1. ;; | a medical device. As such, it may not be changed in any way. |
  1. ;; | Modifications to this software may result in an adulterated |
  1. ;; | medical device under 21CFR820, the use of which is considered |
  1. ;; | to be a violation of US Federal Statutes. |
  1. ;; +---------------------------------------------------------------+
  1. ;;
  1. ;
  1. ; Supported IA #10103 reference $$FMTE^XLFDT function call
  1. ; Controlled Subscription IA #1171 to read RAD/NUC MED REPORTS file (#74)
  1. ;
  1. Q
  1. ;
  1. ; Look for images for completed studies. The status must be either
  1. ; V-VERIFIED or EF-ELECTRONICALY FILED.
  1. ;
  1. MAIN() ; The main loop for the program for Radiology
  1. ; Input Variables
  1. ; SCANMODE ;-- "PATIENT", "DATE", or "NUMBER"
  1. ; DIRECTION ;- 1="ASCENDING" or 0="DESCENDING"
  1. ; BATCHSIZE ;- number of consult & procedure requests to process on this run
  1. ; BEGDATE ;--- begin date for search
  1. ; ENDDATE ;-- end date for search
  1. ; QRSCP ;----- default query/retrieve provider
  1. ; HOURS ;----- 24 character string of Y's and N's indicating active times
  1. ;
  1. N RARPT1,RUNTIME,STOP,X
  1. ;
  1. D HEADER^MAGDSTAA(0)
  1. ;
  1. ; STOP: -1=error, 0=run completed, 1=run stopped
  1. S STOP=$$RADLKUP()
  1. Q STOP
  1. ;
  1. RADLKUP() ; Find the next study to retrieve
  1. N STOP
  1. I SCANMODE="PATIENT" D
  1. . S STOP=$$PATIENT()
  1. . Q
  1. E I SCANMODE="DATE" D
  1. . S STOP=$$DATE()
  1. . Q
  1. E I SCANMODE="NUMBER" D
  1. . S STOP=$$NUMBER()
  1. . Q
  1. E D
  1. . W !!,"*** Illegal SCAN MODE: """,SCANMODE,""""
  1. . S STOP=-1
  1. . Q
  1. Q STOP
  1. ;
  1. PATIENT() ; use ^RARPT "C" xref to find studies for a single patient
  1. ; ^RARPT("C",DFN,RARPT1)=""
  1. N EXAMDATE,RARPT0,RARPT1,RETURN,STATUS,STOP
  1. S STOP=0 ; set to stop the q/r process
  1. S RARPT1=""
  1. F S RARPT1=$O(^RARPT("C",DFN,RARPT1),DIRECTION) Q:'RARPT1 Q:STOP D
  1. . S RARPT0=$G(^RARPT(RARPT1,0))
  1. . S EXAMDATE=$P(RARPT0,"^",3),STATUS=$P(RARPT0,"^",5)
  1. . Q:EXAMDATE<BEGDATE Q:EXAMDATE>ENDDATE
  1. . I STATUS'="V",STATUS'="EF" Q
  1. . S STOP=$$RADLKUP1(RARPT1)
  1. . Q
  1. Q STOP
  1. ;
  1. DATE() ; use ^RARTPT "AA" xref to find studies by verified date
  1. ; ^RARPT("AA",RADTI,RARPT1)=""
  1. N DATEBEG,DATESTOP,DONE,RADTI,RARPT0,RARPT1,RETURN,STATUS,STOP
  1. S STOP=0 ; set to stop the q/r process
  1. D SETDATES(.DATEBEG,.DATESTOP,BEGDATE,ENDDATE,DIRECTION)
  1. S RADTI=DATEBEG,(DONE,RETURN)=0
  1. ; reverse date, opposite sort order
  1. F S RADTI=$O(^RARPT("AA",RADTI),-DIRECTION) Q:'RADTI Q:DONE Q:STOP D
  1. . I DIRECTION=1 S DONE=RADTI<DATESTOP Q:DONE
  1. . E S DONE=RADTI>DATESTOP Q:DONE
  1. . S RARPT1=""
  1. . F S RARPT1=$O(^RARPT("AA",RADTI,RARPT1),DIRECTION) Q:'RARPT1 Q:STOP D
  1. . . S RARPT0=$G(^RARPT(RARPT1,0))
  1. . . S STATUS=$P(RARPT0,"^",5)
  1. . . I STATUS'="V",STATUS'="EF" Q
  1. . . S STOP=$$RADLKUP1(RARPT1)
  1. . . Q
  1. . Q
  1. Q STOP
  1. ;
  1. NUMBER() ; use ^RARPT ien
  1. ; ^RARPT(RARPT1,...
  1. N BATCHSIZE,RARPT0,RARPT1,RETURN,STOP,STATUS,STUDYCNT
  1. S STOP=0 ; set to stop the q/r process
  1. S STUDYCNT=0 ; only count completed (V or EF) studies
  1. S BATCHSIZE=$G(^TMP("MAG",$J,"BATCH Q/R","BATCH SIZE"))
  1. S RARPT1=$G(^TMP("MAG",$J,"BATCH Q/R","REPORT/STUDY IEN"))
  1. S RARPT1=RARPT1-DIRECTION ; Massage value for $O
  1. F S RARPT1=$O(^RARPT(RARPT1),DIRECTION) Q:'RARPT1 Q:STUDYCNT>=BATCHSIZE Q:STOP D
  1. . S RARPT0=$G(^RARPT(RARPT1,0))
  1. . S STATUS=$P(RARPT0,"^",5)
  1. . ; should this study have image?
  1. . I STATUS'="V",STATUS'="EF" Q ; nope
  1. . S STUDYCNT=STUDYCNT+1
  1. . S STOP=$$RADLKUP1(RARPT1)
  1. . Q
  1. Q STOP
  1. ;
  1. RADLKUP1(RARPT1) ; lookup one radiology exam
  1. N ACNUMB,DFN,EXAMDATE,HOSPDIV,MAGIEN,MAGIENLIST,RADPT0,RADTI,RARPT0,RARPT3
  1. ;
  1. S RARPT0=$G(^RARPT(RARPT1,0))
  1. S ACNUMB=$P(RARPT0,"^",1),DFN=$P(RARPT0,"^",2)
  1. S EXAMDATE=$P(RARPT0,"^",3)
  1. ;
  1. ; check DIVISION
  1. S RADTI=$$RADTI(EXAMDATE)
  1. S RADPT0=$G(^RADPT(DFN,"DT",RADTI,0))
  1. S HOSPDIV=$P(RADPT0,"^",3) ; HOSPITAL DIVISION
  1. I $$CHECKDIV^MAGDSTAB()="Y",HOSPDIV'=DIVISION Q 0 ; not the user's division
  1. ;
  1. ; lookup legacy 2005 image group pointers
  1. S RARPT3=0
  1. F S RARPT3=$O(^RARPT(RARPT1,2005,RARPT3)) Q:'RARPT3 D
  1. . S MAGIEN=$G(^RARPT(RARPT1,2005,RARPT3,0))
  1. . S MAGIENLIST(MAGIEN)=""
  1. . Q
  1. Q $$LOOKUP^MAGDSTAA(DFN,EXAMDATE,RARPT1,ACNUMB,.MAGIENLIST)
  1. ;
  1. SETDATES(DATEBEG,DATESTOP,BEGDATE,ENDDATE,DIRECTION) ; get date range
  1. ; get the beginning and ending dates for the FOR loop
  1. ; these are in RARPT reverse date format
  1. ; they are also DIRECTION specific
  1. I DIRECTION=1 D ; ascending direction
  1. . S DATEBEG=$$RADTI(BEGDATE)
  1. . S DATESTOP=$$RADTI(ENDDATE)
  1. . Q
  1. E D ; descending direction
  1. . S DATEBEG=$$RADTI(ENDDATE)
  1. . S DATESTOP=$$RADTI(BEGDATE)
  1. . Q
  1. Q
  1. ;
  1. RADTI(RADTI) ; convert a reverse date to a FM date and vice versa
  1. Q 9999999.9999-RADTI ; 9's complement conversion