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

MAGDIR8R.m

Go to the documentation of this file.
  1. MAGDIR8R ;WOIFO/PMK - Automatic Import Reconciliation Workflow ; 27 Sep 2010 1:00 PM
  1. ;;3.0;IMAGING;**53,49**;Mar 19, 2002;Build 2033;Apr 07, 2011
  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. DISPLAY ;Display a study
  1. N HEADING ;-- title of display
  1. N IEN ;------ internal entry number in DATAFILE
  1. N MACHID ;--- machine id (hostname)
  1. N MODALITY ;- DICOM modality, for counting how many images
  1. N NONE ;----- flag indicating whether or not there are studies
  1. N PNAMEDCM ;- patient name in DICOM format
  1. N SERIEUID ;- DICOM series instance uid
  1. N STUDYUID ;- DICOM study instance uid array
  1. N I,J,K,X
  1. ;
  1. S IOF="#" ; remove this later
  1. ;
  1. S HEADING="DICOM Images that need to be Reconciled and Imported"
  1. S X=$$BUILD()
  1. S NONE=1,MACHID=""
  1. F S MACHID=$O(^TMP("MAG",$J,"IRWF",MACHID)) Q:MACHID="" D
  1. . D DISPLAY1
  1. . D CONTINUE
  1. . Q
  1. I NONE W !!,"No images to correct" D CONTINUE
  1. Q
  1. ;
  1. DISPLAY1 ; Display for one machine
  1. N DATA ;----- data about the entry
  1. D HEADING
  1. S I=0 F S I=$O(^TMP("MAG",$J,"IRWF",MACHID,I)) Q:'I D
  1. . I '$$GETDATA(I,"LIST",.DATA) Q
  1. . S NONE=0 ; there are studies to correct
  1. . I $Y>43 D CONTINUE,HEADING
  1. . W !,$J(I,3),")"
  1. . W ?5,$J(DATA("PID"),14) ; DoD pid is 14 characters: FP/123-45-6789
  1. . W ?20,$E($$NAME(DATA("PNAMEDCM")),1,25)
  1. . W ?47,DATA("ACNUMB"),?64,$$DATE(DATA("STUDYDAT"),"S")
  1. . W ?72
  1. . S MODALITY=""
  1. . F S MODALITY=$O(^TMP("MAG",$J,"IRWF",MACHID,I,"MOD",MODALITY)) Q:MODALITY="" D
  1. . . W " ",MODALITY,"=",^TMP("MAG",$J,"IRWF",MACHID,I,"MOD",MODALITY)
  1. . . Q
  1. . Q
  1. Q
  1. ;
  1. HEADING ; output the heading
  1. N TAB,X
  1. S X=HEADING_" ("_MACHID_")"
  1. S TAB=(80-$L(X))/2
  1. W @IOF,?TAB,X
  1. W !?TAB,$TR($J("",$L(X))," ","-")
  1. W !!," #",?7,"Patient ID",?22,"DICOM Patient Name"
  1. W ?49,"Accession #",?66,"Date",?73,"Images"
  1. W !,"----",?5,"--------------",?20,"-------------------------",?47,"----------------"
  1. W ?64,"--------",?73,"------"
  1. Q
  1. ;
  1. NAME(NAME) ; convert person name from DICOM format to displayable one
  1. N CHAR,I,X
  1. S X=""
  1. F I=1:1:$L(NAME) D
  1. . S CHAR=$E(NAME,I)
  1. . I CHAR="^" D
  1. . . ; the first "^" becomes a comma, while the others become spaces
  1. . . S X=X_$S($F(NAME,"^")=(I+1):",",1:" ")
  1. . . Q
  1. . E S X=X_$E(NAME,I)
  1. Q X
  1. ;
  1. DATE(YYYYMMDD,FORMAT) ; convert date from DICOM format to displayable one
  1. ; FORMAT: B for birthday mm/dd/yyyy, S for short mm/dd/yy, L for long
  1. N M
  1. S FORMAT=$G(FORMAT)
  1. I FORMAT'="B",FORMAT'="S",FORMAT'="L" Q "Wrong format: "_FORMAT
  1. I YYYYMMDD="" Q ""
  1. I YYYYMMDD="<unknown>" Q YYYYMMDD
  1. I FORMAT="B" Q $E(YYYYMMDD,5,6)_"/"_$E(YYYYMMDD,7,8)_"/"_$E(YYYYMMDD,1,4)
  1. I FORMAT="S" Q $E(YYYYMMDD,5,6)_"/"_$E(YYYYMMDD,7,8)_"/"_$E(YYYYMMDD,3,4)
  1. S M=+$E(YYYYMMDD,5,6),M=(3*(M-1))+1
  1. S M=$E("JanFebMarAprMayJunJulAugSepOctNovDec",M,M+2)
  1. Q M_" "_(+$E(YYYYMMDD,7,8))_", "_$E(YYYYMMDD,1,4)
  1. ;
  1. CONTINUE ; prompt
  1. R !!,"Press <Enter> to continue...",X:$G(DTIME,1E5)
  1. Q
  1. ;
  1. BUILD() ;
  1. N COUNT ;---- count of images
  1. N DATA ;----- data about the entry
  1. ;
  1. K ^TMP("MAG",$J,"IRWF")
  1. S COUNT=0
  1. ; prevent update of DATAFILE while someone is starting Importer
  1. L +^MAGD(2006.5752,0):1E9
  1. S IEN=0 F S IEN=$O(^MAGD(2006.5752,IEN)) Q:'IEN D
  1. . S X=$$GETDATA(IEN,"IEN",.DATA)
  1. . S MACHID=DATA("MACHID")
  1. . S MODALITY=DATA("MODALITY")
  1. . S STUDYUID=DATA("STUDYUID")
  1. . S SERIEUID=DATA("SERIEUID")
  1. . S I=$G(STUDYUID(STUDYUID))
  1. . I I="" S (I,COUNT)=COUNT+1,STUDYUID(STUDYUID)=COUNT
  1. . S ^TMP("MAG",$J,"IRWF",MACHID,I,"IEN",SERIEUID,IEN)=""
  1. . S ^(MODALITY)=$G(^TMP("MAG",$J,"IRWF",MACHID,I,"MOD",MODALITY))+1
  1. . Q
  1. L -^MAGD(2006.5752,0)
  1. Q COUNT
  1. ;
  1. GETDATA(I,MODE,DATA) ; get the data from the I-th entry in the DATAFILE
  1. ; if MODE="LIST", then I is the index into the LIST
  1. ; if MODE="IEN", then I is the actual internal entry number
  1. N IEN,J,K,SERIEUID,VARS,X
  1. K DATA Q:'$G(I) 0 Q:'$D(MODE) 0
  1. I MODE="LIST" D
  1. . S SERIEUID=$O(^TMP("MAG",$J,"IRWF",MACHID,I,"IEN",""))
  1. . S IEN=$O(^TMP("MAG",$J,"IRWF",MACHID,I,"IEN",SERIEUID,""))
  1. . Q
  1. E I MODE="IEN" S IEN=I
  1. E Q 0
  1. M X=^MAGD(2006.5752,IEN)
  1. F J=0:1:3 F K=1:1:$L(X(J),"^") I $P(X(J),"^",K)="<unknown>" S $P(X(J),"^",K)=""
  1. S VARS(0)="PNAME^PID^MACHID" ; 0 = patient level
  1. S VARS(1)="STUDYDAT^ACNUMB^STUDYUID" ; 1 = study level
  1. S VARS(2)="MODALITY^SERIEUID" ; 2 = series level
  1. S VARS(3)="FROMPATH^IMAGEUID" ; 3 = instance level
  1. F J=0:1:3 D ; iterate through the levels
  1. . F K=1:1:$L(VARS(J),"^") S DATA($P(VARS(J),"^",K))=$P(X(J),"^",K)
  1. . Q
  1. S DATA("PNAMEDCM")=$TR(DATA("PNAME"),"|","^") K DATA("PNAME")
  1. Q 1
  1. ;
  1. STORE ; store an entry
  1. N I,IEN,PNAME,X
  1. ; patient data
  1. S PNAME=$TR(PNAMEDCM,"^","|")
  1. ; patient data
  1. S X(0)=PNAME_"^"_PID_"^"_MACHID
  1. ; study data
  1. S X(1)=STUDYDAT_"^"_ACNUMB_"^"_STUDYUID
  1. ; series data
  1. S X(2)=MODALITY_"^"_SERIEUID
  1. ; object data
  1. S X(3)=FROMPATH_"^"_IMAGEUID
  1. ;
  1. ; prevent update of DATAFILE while someone is starting Importer
  1. L +^MAGD(2006.5752,0):1E9 ; serialize name generation code
  1. I '$D(^MAGD(2006.5752,0)) S ^MAGD(2006.5752,0)="Importable DICOM Objects^^0^0"
  1. S IEN=$P(^MAGD(2006.5752,0),"^",3)+1
  1. S $P(^MAGD(2006.5752,0),"^",3,4)=IEN_"^"_IEN
  1. M ^MAGD(2006.5752,IEN)=X
  1. L -^MAGD(2006.5752,0)
  1. S ^MAGD(2006.5752,"C",IMAGEUID,IEN)="" ; index by SOP Instance UID
  1. S ^MAGD(2006.5752,"D",MACHID,FROMPATH,IEN)="" ; index by file path
  1. Q
  1. ;
  1. DELETE(IMAGEUID,MACHID,OLDPATH) ; remove an entry
  1. N DUPIEN,RETURN
  1. L +^MAGD(2006.5752,0):1E9 ; serialize name generation code
  1. S RETURN=$$DELETE1(IMAGEUID,MACHID,OLDPATH)
  1. ;
  1. ; check for duplicate SOP Instances and delete them
  1. F S DUPIEN=$O(^MAGD(2006.5752,"C",IMAGEUID,"")) Q:'DUPIEN D
  1. . N MACHID,OLDPATH,RETURN,X
  1. . M X=^MAGD(2006.5752,DUPIEN)
  1. . S MACHID=$P(X(0),"^",3),OLDPATH=$P(X(3),"^",1)
  1. . S RETURN=$$DELETE1(IMAGEUID,MACHID,OLDPATH)
  1. . Q
  1. ;
  1. L -^MAGD(2006.5752,0)
  1. Q RETURN
  1. ;
  1. DELETE1(IMAGEUID,MACHID,OLDPATH) ; remove the single entry
  1. ; Note: ^MAGD(2006.5752,0) must be locked prior to invocation
  1. N EXIST,IEN,X
  1. S IEN=$O(^MAGD(2006.5752,"D",MACHID,OLDPATH,"")) Q:'IEN 0
  1. M X=^MAGD(2006.5752,IEN)
  1. ; image uid's should match (defined as zero for MAGDRPCA call)
  1. I IMAGEUID'=$P(X(3),"^",2) D Q -99
  1. . K I,MSG
  1. . S I=0
  1. . S I=I+1,MSG(I)="IMPORT RECONCILIATION DATABASE FILE DELETION ERROR:"
  1. . S I=I+1,MSG(I)="The DICOM SOP Instance UIDs don't agree."
  1. . S I=I+1,MSG(I)="Current UID: "_IMAGEUID
  1. . S I=I+1,MSG(I)="Previous UID: "_$P(X(3),"^",2)
  1. . S I=I+1,MSG(I)="Dump of File ^MAGD(2006.5752,"_IEN_")"
  1. . S I=I+1,MSG(I)="^MAGD(2006.5752,"_IEN_",0)="_X(0)
  1. . S I=I+1,MSG(I)="^MAGD(2006.5752,"_IEN_",1)="_X(1)
  1. . S I=I+1,MSG(I)="^MAGD(2006.5752,"_IEN_",2)="_X(2)
  1. . S I=I+1,MSG(I)="^MAGD(2006.5752,"_IEN_",3)="_X(3)
  1. . S I=I+1,MSG(I)="Argument 1: "_ARGS
  1. . S I=I+1,MSG(I)="Argument 2: "_ARG2
  1. . D BADERROR^MAGDIRVE($T(+0),"DICOM IMAGE PROCESSING ERROR",.MSG)
  1. . Q
  1. ; remove the entry
  1. S EXIST=$D(^MAGD(2006.5752,IEN))
  1. K ^MAGD(2006.5752,IEN)
  1. K ^MAGD(2006.5752,"C",IMAGEUID,IEN) ; index by SOP Instance UID
  1. K ^MAGD(2006.5752,"D",MACHID,OLDPATH,IEN) ; index by file path
  1. ; Only subtract 1 from #entries, if we're actually deleting one
  1. I EXIST S $P(^(0),"^",4)=$P(^MAGD(2006.5752,0),"^",4)-1
  1. Q 0