KMPDUTL2 ;OAK/RAK - CM Tools Utility ;6/21/05 10:18
;;3.0;KMPD;;Jan 22, 2009;Build 42
;
DATERNG(KMPUY,KMPUSTR,KMPUEND) ;-- date range
;---------------------------------------------------------------------
; KMPUY..... Value returned in four pieces:
; fmstartdate^fmenddate^ouputstartdate^outputenddate
;
; Piece one and two are the date ranges in fileman format.
; Piece three and four are the same dates in output format:
; dy-Mon-yr
;
; ********
; * NOTE *
; ********
; - The first piece will always be the earliest date entered.
;
; Optional Parameters:
;
; KMPUSTR... If defined, the earliest date that may be selected.
; (must be in fileman format)
;
; KMPUEND... If defined, the latest date that may be selected.
; (must be in fileman format)
;-----------------------------------------------------------------------
;
N DATE1,DATE2,DIR,DIRUT,LINE,X,Y
;
S KMPUY="",KMPUSTR=$G(KMPUSTR),KMPUEND=$G(KMPUEND)
;
RANGE ;-- Ask date ranges
S DIR(0)="DOA^"_$S(KMPUSTR:KMPUSTR,1:"")_":"_$S(KMPUEND:KMPUEND,1:"")_":ET)"
S DIR("A")="Start with Date: "
S:KMPUSTR DIR("B")=$$FMTE^XLFDT(KMPUSTR,2)
S DIR("?")=" "
S DIR("?",1)="Enter the starting date.",LINE=2
; if starting date.
I KMPUSTR D
.S DIR("?",LINE)="Date must not precede "_$$FMTE^XLFDT(KMPUSTR)
.S LINE=LINE+1
; if ending date.
I KMPUEND S DIR("?",LINE)="Date must not follow "_$$FMTE^XLFDT(KMPUEND)
W ! D ^DIR I $D(DIRUT) S KMPUY="" Q
S DATE1=Y
S DIR("A")=" End with Date: "
S:KMPUEND DIR("B")=$$FMTE^XLFDT(KMPUEND,2)
S DIR("?",1)="Enter the ending date."
D ^DIR G:Y="" RANGE I Y="^" S KMPUY="" Q
S DATE2=Y
; Set earliest date into first piece.
S KMPUY=$S(DATE2<DATE1:DATE2,1:DATE1)_U_$S(DATE2>DATE1:DATE2,1:DATE1)
S $P(KMPUY,U,3)=$$FMTE^XLFDT($P(KMPUY,U))
S $P(KMPUY,U,4)=$$FMTE^XLFDT($P(KMPUY,U,2))
Q
;
EMAIL(KMPDSUBJ,KMPDTEXT,KMPDTO) ; check and process errors.
;-----------------------------------------------------------------------
; KMPDSUBJ... Free text - to be included in subject
; KMPDTEXT(). Array containing message text. This must be in a format
; accepted by XMTEXT - TEXT(
; ^TMP($J,"TEXT",
; KMPDTO..... Address for email recipient:
; G.KMP2-RUM@FO-ALBANY.DOMAIN.EXT
; G.KMP4-CMTOOLS@FO-ALBANY.DOMAIN.EXT
; G.CAPACITY,MANAGEMENT@FO-ALBANY.MED.GOV
; If no value is passed the default will be
; G.KMP4-CMTOOLS@FO-ALBANY.DOMAIN.EXT
;
;-----------------------------------------------------------------------
;
Q:$G(KMPDTEXT)=""
S KMPDSUBJ=$S($G(KMPDSUBJ)="":"CM Error",1:KMPDSUBJ)
S KMPDTO=$S($G(KMPDTO)="":"G.KMP4-CMTOOLS@FO-ALBANY.DOMAIN.EXT",1:KMPDTO)
;
N H,I,LN,N,O,SITE,TEXT,TL,XMSUB,X,XMTEXT,XMY,XMZ,Y,Z
;
S TL=$$TESTLAB^KMPDUT1
S SITE=$$SITE^VASITE
S XMSUB=KMPDSUBJ_" at site "_$P(TL,U,2)_$P(SITE,U,3)_" on "_$$FMTE^XLFDT($$DT^XLFDT)
S XMTEXT=KMPDTEXT
S XMY(KMPDTO)=""
D ^XMD
W:'$D(ZTQUEUED) !,"Message #"_$G(XMZ)_" sent..."
;
Q
;
STRSTP(KMPDAPP,KMPDDW,KMPDBP,KMPDSTM) ;-- record start/stop times
;-----------------------------------------------------------------------
; KMPDAPP.... CP application:
; 1 - sagg
; 2 - rum
; 3 - hl7
; 4 - timing
; KMPDDW..... Daily or Weekly
; 1 - daily
; 2 - weekly
; KMPDBP.... Background or Purge
; 1 - background
; 2 - purge
; KMPDSTM.... Start Time in internal fileman format
;
; This api will calculate END time and DELTA time (END-KMPDSTM) and
; store the results in:
; ^XTMP("KMPD","BACKGROUND",KMPDAPP,KMPDDW,KMPDBP,...)
;-----------------------------------------------------------------------
Q:'$G(KMPDAPP)
Q:KMPDAPP<1!(KMPDAPP>4)
Q:'$G(KMPDDW)
Q:KMPDDW<1!(KMPDDW>2)
Q:'$G(KMPDBP)
Q:KMPDBP<1!(KMPDBP>2)
Q:'$G(KMPDSTM)
;
N END,ERROR,FDA,FIELD S END=$$NOW^XLFDT
;
; starting field for daily or background
S FIELD=KMPDAPP+($S(KMPDDW=1:5,1:8)*.01)
; if purge
S:KMPDBP=2 FIELD=FIELD+.07
;
; store start time, end time, and delta
S FDA($J,8973,"1,",FIELD)=KMPDSTM
S FDA($J,8973,"1,",FIELD+.01)=END
S FDA($J,8973,"1,",FIELD+.02)=$$FMDIFF^XLFDT(END,KMPDSTM,3)
;
D FILE^DIE("","FDA($J)","ERROR")
;
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HKMPDUTL2 4576 printed Dec 13, 2024@01:41:18 Page 2
KMPDUTL2 ;OAK/RAK - CM Tools Utility ;6/21/05 10:18
+1 ;;3.0;KMPD;;Jan 22, 2009;Build 42
+2 ;
DATERNG(KMPUY,KMPUSTR,KMPUEND) ;-- date range
+1 ;---------------------------------------------------------------------
+2 ; KMPUY..... Value returned in four pieces:
+3 ; fmstartdate^fmenddate^ouputstartdate^outputenddate
+4 ;
+5 ; Piece one and two are the date ranges in fileman format.
+6 ; Piece three and four are the same dates in output format:
+7 ; dy-Mon-yr
+8 ;
+9 ; ********
+10 ; * NOTE *
+11 ; ********
+12 ; - The first piece will always be the earliest date entered.
+13 ;
+14 ; Optional Parameters:
+15 ;
+16 ; KMPUSTR... If defined, the earliest date that may be selected.
+17 ; (must be in fileman format)
+18 ;
+19 ; KMPUEND... If defined, the latest date that may be selected.
+20 ; (must be in fileman format)
+21 ;-----------------------------------------------------------------------
+22 ;
+23 NEW DATE1,DATE2,DIR,DIRUT,LINE,X,Y
+24 ;
+25 SET KMPUY=""
SET KMPUSTR=$GET(KMPUSTR)
SET KMPUEND=$GET(KMPUEND)
+26 ;
RANGE ;-- Ask date ranges
+1 SET DIR(0)="DOA^"_$SELECT(KMPUSTR:KMPUSTR,1:"")_":"_$SELECT(KMPUEND:KMPUEND,1:"")_":ET)"
+2 SET DIR("A")="Start with Date: "
+3 if KMPUSTR
SET DIR("B")=$$FMTE^XLFDT(KMPUSTR,2)
+4 SET DIR("?")=" "
+5 SET DIR("?",1)="Enter the starting date."
SET LINE=2
+6 ; if starting date.
+7 IF KMPUSTR
Begin DoDot:1
+8 SET DIR("?",LINE)="Date must not precede "_$$FMTE^XLFDT(KMPUSTR)
+9 SET LINE=LINE+1
End DoDot:1
+10 ; if ending date.
+11 IF KMPUEND
SET DIR("?",LINE)="Date must not follow "_$$FMTE^XLFDT(KMPUEND)
+12 WRITE !
DO ^DIR
IF $DATA(DIRUT)
SET KMPUY=""
QUIT
+13 SET DATE1=Y
+14 SET DIR("A")=" End with Date: "
+15 if KMPUEND
SET DIR("B")=$$FMTE^XLFDT(KMPUEND,2)
+16 SET DIR("?",1)="Enter the ending date."
+17 DO ^DIR
if Y=""
GOTO RANGE
IF Y="^"
SET KMPUY=""
QUIT
+18 SET DATE2=Y
+19 ; Set earliest date into first piece.
+20 SET KMPUY=$SELECT(DATE2<DATE1:DATE2,1:DATE1)_U_$SELECT(DATE2>DATE1:DATE2,1:DATE1)
+21 SET $PIECE(KMPUY,U,3)=$$FMTE^XLFDT($PIECE(KMPUY,U))
+22 SET $PIECE(KMPUY,U,4)=$$FMTE^XLFDT($PIECE(KMPUY,U,2))
+23 QUIT
+24 ;
EMAIL(KMPDSUBJ,KMPDTEXT,KMPDTO) ; check and process errors.
+1 ;-----------------------------------------------------------------------
+2 ; KMPDSUBJ... Free text - to be included in subject
+3 ; KMPDTEXT(). Array containing message text. This must be in a format
+4 ; accepted by XMTEXT - TEXT(
+5 ; ^TMP($J,"TEXT",
+6 ; KMPDTO..... Address for email recipient:
+7 ; G.KMP2-RUM@FO-ALBANY.DOMAIN.EXT
+8 ; G.KMP4-CMTOOLS@FO-ALBANY.DOMAIN.EXT
+9 ; G.CAPACITY,MANAGEMENT@FO-ALBANY.MED.GOV
+10 ; If no value is passed the default will be
+11 ; G.KMP4-CMTOOLS@FO-ALBANY.DOMAIN.EXT
+12 ;
+13 ;-----------------------------------------------------------------------
+14 ;
+15 if $GET(KMPDTEXT)=""
QUIT
+16 SET KMPDSUBJ=$SELECT($GET(KMPDSUBJ)="":"CM Error",1:KMPDSUBJ)
+17 SET KMPDTO=$SELECT($GET(KMPDTO)="":"G.KMP4-CMTOOLS@FO-ALBANY.DOMAIN.EXT",1:KMPDTO)
+18 ;
+19 NEW H,I,LN,N,O,SITE,TEXT,TL,XMSUB,X,XMTEXT,XMY,XMZ,Y,Z
+20 ;
+21 SET TL=$$TESTLAB^KMPDUT1
+22 SET SITE=$$SITE^VASITE
+23 SET XMSUB=KMPDSUBJ_" at site "_$PIECE(TL,U,2)_$PIECE(SITE,U,3)_" on "_$$FMTE^XLFDT($$DT^XLFDT)
+24 SET XMTEXT=KMPDTEXT
+25 SET XMY(KMPDTO)=""
+26 DO ^XMD
+27 if '$DATA(ZTQUEUED)
WRITE !,"Message #"_$GET(XMZ)_" sent..."
+28 ;
+29 QUIT
+30 ;
STRSTP(KMPDAPP,KMPDDW,KMPDBP,KMPDSTM) ;-- record start/stop times
+1 ;-----------------------------------------------------------------------
+2 ; KMPDAPP.... CP application:
+3 ; 1 - sagg
+4 ; 2 - rum
+5 ; 3 - hl7
+6 ; 4 - timing
+7 ; KMPDDW..... Daily or Weekly
+8 ; 1 - daily
+9 ; 2 - weekly
+10 ; KMPDBP.... Background or Purge
+11 ; 1 - background
+12 ; 2 - purge
+13 ; KMPDSTM.... Start Time in internal fileman format
+14 ;
+15 ; This api will calculate END time and DELTA time (END-KMPDSTM) and
+16 ; store the results in:
+17 ; ^XTMP("KMPD","BACKGROUND",KMPDAPP,KMPDDW,KMPDBP,...)
+18 ;-----------------------------------------------------------------------
+19 if '$GET(KMPDAPP)
QUIT
+20 if KMPDAPP<1!(KMPDAPP>4)
QUIT
+21 if '$GET(KMPDDW)
QUIT
+22 if KMPDDW<1!(KMPDDW>2)
QUIT
+23 if '$GET(KMPDBP)
QUIT
+24 if KMPDBP<1!(KMPDBP>2)
QUIT
+25 if '$GET(KMPDSTM)
QUIT
+26 ;
+27 NEW END,ERROR,FDA,FIELD
SET END=$$NOW^XLFDT
+28 ;
+29 ; starting field for daily or background
+30 SET FIELD=KMPDAPP+($SELECT(KMPDDW=1:5,1:8)*.01)
+31 ; if purge
+32 if KMPDBP=2
SET FIELD=FIELD+.07
+33 ;
+34 ; store start time, end time, and delta
+35 SET FDA($JOB,8973,"1,",FIELD)=KMPDSTM
+36 SET FDA($JOB,8973,"1,",FIELD+.01)=END
+37 SET FDA($JOB,8973,"1,",FIELD+.02)=$$FMDIFF^XLFDT(END,KMPDSTM,3)
+38 ;
+39 DO FILE^DIE("","FDA($J)","ERROR")
+40 ;
+41 QUIT