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

MAGUTL03.m

Go to the documentation of this file.
  1. MAGUTL03 ;WOIFO/SG - DATE/TIME UTILITIES ; 3/9/09 12:53pm
  1. ;;3.0;IMAGING;**93**;Dec 02, 2009;Build 163
  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. ;; | |
  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. ; This routine uses the following ICRs:
  1. ;
  1. ; #10038 Read file #40.5 (supported)
  1. ;
  1. Q
  1. ;
  1. ;##### ENSURES THAT THE DATE/TIME IS IN INTERNAL FORMAT
  1. ;
  1. ; X Date/time in internal (FileMan) or external format
  1. ;
  1. ; [%DT] Flags for the ^%DT (see the FileMan Programmer
  1. ; manual for details)
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; -1 Invalid date
  1. ; >0 Date/time in internal FileMan format
  1. ;
  1. DTI(X,%DT) ;
  1. N Y
  1. Q:X?7N.1(1"."1.N) X
  1. S %DT=$TR($G(%DT),"AE") D ^%DT
  1. Q Y
  1. ;
  1. ;##### "NORMALIZES" THE DATE RANGE
  1. ;
  1. ; .FROMDATE( Reference to a local variable that stores the
  1. ; beginning date of the date range. The time part of
  1. ; the value is ignored.
  1. ;
  1. ; After a successful call, this variable contains
  1. ; the internal FileMan value of the date. In case of
  1. ; error(s), the input value is returned.
  1. ;
  1. ; 0) Standard external date value is returned here.
  1. ; In case of error(s), this node is not defined.
  1. ;
  1. ; .TODATE( Reference to a local variable that stores the
  1. ; end date of the date range. The time part of
  1. ; the value is ignored.
  1. ;
  1. ; After a successful call, this variable contains
  1. ; the internal FileMan value of the date. In case of
  1. ; error(s), the input value is returned.
  1. ;
  1. ; 0) Standard external date value is returned here.
  1. ; In case of error(s), this node is not defined.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; 0 Success
  1. ;
  1. ; Notes
  1. ; =====
  1. ;
  1. ; If the FROMDATE is after the TODATE, then the dates are swapped.
  1. ;
  1. DTRANGE(FROMDATE,TODATE) ;
  1. N RC,TMP
  1. ;
  1. ;=== Validate the dates
  1. S RC=0 D I RC<0 K FROMDATE(0),TODATE(0) Q RC
  1. . ;--- Beginning of the date range
  1. . I $G(FROMDATE)'="" D Q:RC<0
  1. . . S TMP=$$DTI(FROMDATE,"TS")
  1. . . I TMP<0 S RC=$$IPVE^MAGUERR("FROMDATE") Q
  1. . . S FROMDATE=TMP\1,FROMDATE(0)=$$FMTE^XLFDT(FROMDATE)
  1. . . Q
  1. . E S FROMDATE=0,FROMDATE(0)=""
  1. . ;--- End of the date range
  1. . I $G(TODATE)'="" D Q:RC<0
  1. . . S TMP=$$DTI(TODATE,"TS")
  1. . . I TMP<0 S RC=$$IPVE^MAGUERR("TODATE") Q
  1. . . S TODATE=TMP\1,TODATE(0)=$$FMTE^XLFDT(TODATE)
  1. . . Q
  1. . E S TODATE=9999999,TODATE(0)=""
  1. . Q
  1. ;
  1. ;=== Swap the dates if necessary
  1. K TMP
  1. M:FROMDATE>TODATE TMP=FROMDATE,FROMDATE=TODATE,TODATE=TMP
  1. ;
  1. ;=== Success
  1. Q 0
  1. ;
  1. ;##### CHECKS IF THE DATE IS A WORKING DAY
  1. ;
  1. ; DATE The date to be checked
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; 0 Weekend or Holiday
  1. ; 1 Working day
  1. ;
  1. WDCHK(DATE) ;
  1. N DOW,MAGMSG
  1. ;--- Return zero if Saturday (6) or Sunday (0)
  1. S DOW=$$DOW^XLFDT(DATE,1)
  1. Q:DOW<0 $$IPVE^MAGUERR("DATE")
  1. Q:'DOW!(DOW>5) 0
  1. ;--- Return 1 if cannot be found in the HOLIDAY file
  1. Q $$FIND1^DIC(40.5,,"QX",DATE\1,"B",,"MAGMSG")'>0
  1. ;
  1. ;##### RETURNS THE NEXT WORKING DAY DATE
  1. ;
  1. ; DATE The source date
  1. ;
  1. ; The function returns the date of the next working day.
  1. ;
  1. WDNEXT(DATE) ;
  1. N DOW,MAGMSG
  1. F D Q:$$FIND1^DIC(40.5,,"QX",DATE,"B",,"MAGMSG")'>0
  1. . S DOW=$$DOW^XLFDT(DATE,1) S:'DOW DOW=7
  1. . ;--- Get the next day and skip a weekend if necessary
  1. . S DATE=$$FMADD^XLFDT(DATE,$S(DOW<5:1,1:8-DOW))
  1. . Q
  1. Q DATE