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

MAGGSQI.m

Go to the documentation of this file.
  1. MAGGSQI ;WOIFO/GEK/SG - Image Integrity Checker ; 18 Jul 2013 5:15 PM
  1. ;;3.0;IMAGING;**8,93,138**;Mar 19, 2002;Build 5380;Sep 03, 2013
  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. RPT(MAGRY,CT,LASTIEN) ; Run the check for the last CT entries in Image file.
  1. N I,J,MAGX,ERRCT,ACTCT,TYPECT,MAGSTART,MAGPUR
  1. K ^XTMP("MAGCHK")
  1. S LASTIEN=$G(LASTIEN)
  1. ; See DOCU^MAGCRPT for documenation on this global
  1. D NOW^%DTC S MAGSTART=%
  1. S X1=%,X2=60 D C^%DTC S MAGPUR=X K X,X1,X2
  1. ;Set purge, create and purge date
  1. S $P(^XTMP("MAGCHK",$J,0),"^",1)=MAGPUR,$P(^(0),"^",2)=MAGSTART
  1. S $P(^XTMP("MAGCHK",$J,0),"^",5)=MAGSTART
  1. ;Set description
  1. S $P(^XTMP("MAGCHK",$J,0),"^",3)="Imaging Scan DB"
  1. ;Set status to active
  1. S $P(^XTMP("MAGCHK",$J,0),"^",4)="ACTIVE"
  1. S MAGRY(0)="0^Checking..."
  1. S I="A"
  1. S CT=$G(CT,5000),ERRCT=0,ACTCT=0
  1. F S I=$O(^MAG(2005,I),-1) Q:CT<1 Q:'I Q:I<LASTIEN D
  1. . Q:$$ISDEL^MAGGI11(I)
  1. . S CT=CT-1,ACTCT=ACTCT+1
  1. . I '(ACTCT#1000) I IO(0)=IO U IO W "."
  1. . K MAGX
  1. . D CHK(.MAGX,I)
  1. . I +MAGX(0)'=1 S ERRCT=ERRCT+1 D
  1. . . S ^XTMP("MAGCHK",$J,+MAGX(0),I)=MAGX(0)
  1. . . S ^XTMP("MAGCHK",$J,"B",$P(MAGX(0),"^",2),I)=""
  1. . . S TYPECT($P(MAGX(0),"^",2))=$G(TYPECT($P(MAGX(0),"^",2)))+1
  1. I 'ERRCT S MAGRY(0)="0^All Okay"
  1. I ERRCT S MAGRY(0)=ERRCT_"^Errors of "_ACTCT_" Images Checked."
  1. S I="" F S I=$O(TYPECT(I)) Q:I="" D
  1. . S MAGRY($O(MAGRY(""),-1)+1)=TYPECT(I)_"^"_I
  1. ;Set status to complete
  1. S $P(^XTMP("MAGCHK",$J,0),"^",4)="COMPLETE"
  1. ;Set end time
  1. D NOW^%DTC
  1. S $P(^XTMP("MAGCHK",$J,0),"^",6)=%
  1. ;Set total number of entries checked
  1. S $P(^XTMP("MAGCHK",$J,0),"^",8)=ACTCT
  1. Q
  1. CHK(MAGRY,MAGIEN) ;
  1. ;
  1. N ERR,MAGDFN,MAGPK,MAGPKDA,MAGPKIP,MAGPKDA1,Y,I,MAGISGRP,MAGRPIEN
  1. N MAGN2,MAGN0,MAGPDFIL,MAGRCT,MAGN100,MAGZ,VALID
  1. S MAGRCT=0,MAGISGRP=0
  1. S MAGRY(0)="0^Error during Image Integrity Check !"
  1. ;
  1. I $$ISDEL^MAGGI11(MAGIEN,.ERR) S MAGRY(0)="1^Deleted Image" Q
  1. I ERR<0 D Q:ERR<0
  1. . I +ERR=-43 D Q
  1. . . S ERR=0,I=$O(MAGRY(""),-1)+1
  1. . . S MAGRY(I)="2^Image IEN exists, and is Deleted !"
  1. . . Q
  1. . S MAGRY(0)="0^Invalid Image pointer"
  1. . Q
  1. ;
  1. S MAGN0=$G(^MAG(2005,MAGIEN,0))
  1. S MAGN2=$G(^MAG(2005,MAGIEN,2))
  1. S MAGN100=$G(^MAG(2005,MAGIEN,100))
  1. ;
  1. I $O(^MAG(2005,MAGIEN,1,0))!($P(MAGN0,U,6)=11) S MAGISGRP=1
  1. I MAGISGRP,'$O(^MAG(2005,MAGIEN,1,0)) S MAGRY(0)="0^Group of 0 images" Q
  1. ;
  1. S MAGPK=$P(MAGN2,U,6)
  1. S MAGPKDA=$P(MAGN2,U,7)
  1. S MAGPKIP=$P(MAGN2,U,8)
  1. S MAGPKDA1=$P(MAGN2,U,10)
  1. S MAGDFN=$P(MAGN0,U,7)
  1. ;
  1. ; If this image is a member of a group, compare some fields against the Group entry.
  1. I +$P(MAGN0,U,10) S MAGRPIEN=$P(MAGN0,U,10) D Q
  1. . ; Check the DFN's Quit if they don't match
  1. . I $P($G(^MAG(2005,MAGRPIEN,0)),U,7)'=MAGDFN S MAGRY(0)="0^Patient pointer mismatch between Image Group and Image" Q
  1. . ; if image has data in parent fields, Quit if not same as Group entry.
  1. . I +MAGPK,($P(MAGN2,U,6,7)'=$P($G(^MAG(2005,MAGRPIEN,2)),U,6,7)) S MAGRY(MAGRCT)="0^Pointer Mismatch in Group" Q
  1. . ;Have a check that assures that the Group has this image in it's multiple
  1. . ; ? Do we want to do this when we have the Grp entry, for each of its members. ?
  1. . S (I,VALID)=0 F S I=$O(^MAG(2005,MAGRPIEN,1,I)) Q:'I D Q:VALID
  1. . . I +^MAG(2005,MAGRPIEN,1,I,0)=MAGIEN S VALID=1
  1. . I VALID S MAGRY(MAGRCT)="1^Valid Group image."
  1. . E S MAGRY(MAGRCT)="0^Pointer Missing in Group entries."
  1. ;
  1. ; In current scheme of things, image points to Package or a Descriptive Categroy
  1. ; So we can make the following assumption, but maybe not for long.
  1. I 'MAGPK,+MAGN100 S MAGRY(MAGRCT)="1^Image Category" Q
  1. I 'MAGPK,($P(MAGN0,U,6)=18) S MAGRY(MAGRCT)="1^Patient Photo" Q
  1. ;
  1. ; Old images Didn't require Parent Pointer,Parent root, Parent Image Pointer
  1. ;I 'MAGPK S MAGRY(0)="0^Missing the Parent file pointer" Q
  1. ;I 'MAGPKDA S MAGRY(0)="0^Missing the Parent root pointer" Q
  1. ;I 'MAGPKIP S MAGRY(0)="0^Missing the Parent image pointer" Q
  1. ;
  1. ; Surgery reports
  1. I (MAGPK=130) D Q
  1. . ; Patch. if MAGPK exists, but not a MAGPKDA
  1. . I 'MAGPKDA S MAGRY(0)="0^Missing the Parent root pointer" Q
  1. . I 'MAGPKIP S MAGRY(0)="0^Missing the Parent image pointer" Q
  1. . I '$D(^SRF(MAGPKDA,0)) S MAGRY(0)="0^Invalid Image pointer to associated package report entry" Q
  1. . I '$D(^SRF(MAGPKDA,2005,MAGPKIP,0)) S MAGRY="0^Invalid Image pointer in associated package file" Q
  1. . I '(MAGDFN=$P(^SRF(MAGPKDA,0),U,1)) S MAGRY(0)="0^Image and associated report have different patient pointers" Q
  1. . I '(MAGIEN=+$G(^SRF(MAGPKDA,2005,MAGPKIP,0))) S MAGRY(0)="0^Associated report does not point back to Image" Q
  1. . S MAGRY(0)="1^Okay"
  1. ;
  1. ; TIU documents;
  1. I MAGPK=8925 D Q
  1. . ; Patch. if MAGPK exists, but not a MAGPKDA
  1. . I 'MAGPKDA S MAGRY(0)="0^Missing the Parent root pointer" Q
  1. . I 'MAGPKIP S MAGRY(0)="0^Missing the Parent image pointer" Q
  1. . I '$D(^TIU(8925,MAGPKDA,0)) S MAGRY(0)="0^Invalid Image pointer to associated package report entry" Q
  1. . I '$D(^TIU(8925.91,MAGPKIP,0)) S MAGRY(0)="0^Invalid Image pointer in associated package file" Q
  1. . I '(MAGDFN=$P($G(^TIU(8925,MAGPKDA,0)),U,2)) S MAGRY(0)="0^Image and associated report have different patient pointers" Q
  1. . S MAGZ=MAGPKDA_"^"_MAGIEN
  1. . I '(MAGZ=$G(^TIU(8925.91,MAGPKIP,0))) S MAGRY(0)="0^Associated report does not point back to Image" Q
  1. . S MAGRY(0)="1^Okay"
  1. ;
  1. ; Medicine reports
  1. I ((MAGPK>689.999)&(MAGPK<703)) D Q
  1. . ; Patch. if MAGPK exists, but not a MAGPKDA
  1. . I 'MAGPKDA S MAGRY(0)="0^Missing the Parent root pointer" Q
  1. . I '$D(^MCAR(MAGPK,MAGPKDA,0)) S MAGRY(0)="0^Invalid Image pointer to associated package report entry" Q
  1. . I MAGPKIP I '$D(^MCAR(MAGPK,MAGPKDA,2005,MAGPKIP,0)) S MAGRY(0)="0^Invalid Image pointer in associated package file" Q
  1. . I '(MAGDFN=$P($G(^MCAR(MAGPK,MAGPKDA,0)),U,2)) S MAGRY(0)="0^Image and associated report have different patient pointers" Q
  1. . ;I '(MAGIEN=+^MCAR(MAGPK,MAGPKDA,2005,MAGPKIP,0)) S MAGRY(0)="0^Associated report does not point back to Image" Q
  1. . I '$D(^MCAR(MAGPK,MAGPKDA,2005,"B",MAGIEN)) S MAGRY(0)="0^Associated report does not point back to Image" Q
  1. . S MAGRY(0)="1^Okay"
  1. . ;
  1. . ; S MCFILE=+$P($P(^MCAR(697.2,PSIEN,0),U,2),"(",2)
  1. . ; S PATFLD=$O(^DD(MCFILE,"B","MEDICAL PATIENT",""))
  1. . ; S:PATFLD="" PATFLD=1
  1. . ;
  1. . ; S TMP=$P($P(^DD(MCFILE,PATFLD,0),U,4),";",2)
  1. . ; Q $S(DFN'=$P(^MCAR(MCFILE,MCIEN,0),U,TMP):"O^Image and associated report have different patient pointers",1:"1")
  1. ;
  1. ; Radiology reports
  1. I MAGPK=74 D Q
  1. . ; Patch. if MAGPK exists, but not a MAGPKDA
  1. . I 'MAGPKDA S MAGRY(0)="0^Missing the Parent root pointer" Q
  1. . I '$D(^RARPT(MAGPKDA,0)) S MAGRY(0)="0^Invalid Image pointer to associated package report entry" Q
  1. . I MAGPKIP I '$D(^RARPT(MAGPKDA,2005,MAGPKIP,0)) S MAGRY(0)="0^Invalid Image pointer in associated package file" Q
  1. . ;
  1. . I '(MAGDFN=$P($G(^RARPT(MAGPKDA,0)),U,2)) S MAGRY(0)="0^Image and associated report have different patient pointers" Q
  1. . ;I '(MAGIEN=+$G(^RARPT(MAGPKDA,2005,MAGPKIP,0))) S MAGRY(0)="0^Associated report does not point back to Image" Q
  1. . I '$D(^RARPT(MAGPKDA,2005,"B",MAGIEN)) S MAGRY(0)="0^Associated report does not point back to Image" Q
  1. . S MAGRY(0)="1^Okay"
  1. ;
  1. ; Laboratory reports
  1. I (MAGPK>62.999)&(MAGPK<64) D Q
  1. . ;I $P(^MAG(2005.03,MAGTMPRT,0),"^",4)=63
  1. . S MAGRY(0)="1^Lab image not checked "
  1. . ;D @$S(MAGTMPRT=63:"AU",MAGTMPRT=63.2:"AU",1:"LAB") Q
  1. ;
  1. ; DICOM temporary file for consults and anatomic pathology
  1. I (MAGPK=2006.5838)!(MAGPK=2006.5839) D Q
  1. . S MAGRY(0)="1^DICOM temp image not checked "
  1. . Q
  1. ;
  1. S MAGRY(0)="2^Images only point to Patient."
  1. Q
  1. CHKGRPCH(CHKY,GRPIEN,GRPDFN,GRPCH) ; Check the child of a Group.
  1. ; i.e. an IEN in the "1" node of the Group.
  1. ; Can't just check the IEN by calling CHK. It might be okay that way.
  1. ; Have to compare it to Groups IEN, and DFN
  1. N CHN0
  1. S CHN0=$G(^MAG(2005,GRPCH,0)) I '$L(CHN0) S CHKY="0^Invalid Image pointer" Q
  1. I $P(CHN0,U,7)'=GRPDFN S CHKY="0^Patient Mismatch in Group member:"_GRPCH Q
  1. I $P(CHN0,U,10)'=GRPIEN S CHKY="0^Pointer Mismatch in Group member:"_GRPCH Q
  1. S CHKY="1^Okay Group Image"
  1. Q