1 | DILIBF ;SFISC/STAFF-LIBRARY OF FUNCTIONS ;9:03 AM 9 Jan 2001
|
---|
2 | ;;22.0;VA FileMan;**48,71**;Mar 30, 1999
|
---|
3 | ;Per VHA Directive 10-93-142, this routine should not be modified.
|
---|
4 | HTFM(%H,%F) ;$H to FM
|
---|
5 | N X,%,%Y,%M,%D S:'$D(%F) %F=0
|
---|
6 | S:%H[",0" %H=%H-1_",86400"
|
---|
7 | S %=(%H>21608)+(%H>94657)+%H-.1,%Y=%\365.25+141,%=%#365.25\1
|
---|
8 | S %D=%+306#(%Y#4=0+365)#153#61#31+1,%M=%-%D\29+1
|
---|
9 | S X=%Y_"00"+%M_"00"+%D,%=$P(%H,",",2)
|
---|
10 | S %=%#60/100+(%#3600\60)/100+(%\3600)/100
|
---|
11 | S:%&('%F) X=X_% Q X
|
---|
12 | ;
|
---|
13 | FMTH(X,%F) ;FM to $H
|
---|
14 | N %Y,%H S:'$D(%F) %F=0 D H S:%F %H=+%H Q %H
|
---|
15 | H ;
|
---|
16 | N %,%M,%D,%T I X<1410000 S %H=0,%Y=-1 Q
|
---|
17 | S %Y=$E(X,1,3),%M=$E(X,4,5),%D=$E(X,6,7)
|
---|
18 | S %T=$E(X_0,9,10)*60+$E(X_"000",11,12)*60+$E(X_"00000",13,14)
|
---|
19 | N DILEAP D
|
---|
20 | . N Y S Y=%Y+1700 S:%M<3 Y=Y-1
|
---|
21 | . S DILEAP=(Y\4)-(Y\100)+(Y\400)-446 Q
|
---|
22 | S %H=$P("^31^59^90^120^151^181^212^243^273^304^334","^",%M)+%D
|
---|
23 | S %='%M!'%D,%Y=%Y-141
|
---|
24 | S %H=%H+(%Y*365)+DILEAP+%
|
---|
25 | S:%T=86400 %H=%H+1,%T=0
|
---|
26 | S %H=%H_","_%T
|
---|
27 | S %Y=$S(%:-1,1:%H+4#7)
|
---|
28 | Q
|
---|
29 | ;
|
---|
30 | HTE(%H,%F) ;$H to external
|
---|
31 | Q:%H'>0 %H N Y,%T,%R S %F=$G(%F) S Y=$$HTFM(%H,0) G T2
|
---|
32 | FMTE(Y,%F) ;FM to external
|
---|
33 | Q:'$G(Y) $G(Y) S %F=$G(%F) Q:($G(DUZ("LANG"))>1) $$OUT^DIALOGU(Y,"FMTE",%F)
|
---|
34 | N %T,%R
|
---|
35 | T2 S %T="."_$E($P(Y,".",2)_"000000",1,7) D @("F"_$S(%F<1:1,%F>7:1,1:+%F\1)) Q %R
|
---|
36 | DOW(X,Y) ;Day of Week
|
---|
37 | N %Y,%M,%D,%H,%T D H I $G(Y) Q %Y
|
---|
38 | Q $P("Sun^Mon^Tues^Wednes^Thurs^Fri^Satur","^",%Y+1)_"day"
|
---|
39 | ;
|
---|
40 | FMDIFF(X1,X2,X3) ;FM diff in two dates in days if x3=1 seconds if x3=2.
|
---|
41 | N %H,%Y,X S:'$D(X3) X3=1 S X=X1 D H S X1=+%H,X1(1)=$P(%H,",",2),X=X2 D H
|
---|
42 | D2 S X=(X1-%H) S:X3>1 X=X*86400+(X1(1)-$P(%H,",",2))
|
---|
43 | I X3=3 D
|
---|
44 | . S %=X,X=""
|
---|
45 | . I %'<86400 S X=(%\86400)
|
---|
46 | . I %<0 S:(-%)'<86400 X=(%\86400) S %=-%
|
---|
47 | . S:%#86400 X=X_" "_(%#86400\3600)_":"_$E(%#3600\60+100,2,3)_":"_$E(%#60+100,2,3)
|
---|
48 | . Q
|
---|
49 | Q X
|
---|
50 | HDIFF(X1,X2,X3) ;$H diff in two dates, X3 same as FMDIFF.
|
---|
51 | N X,%H,%T S:'$D(X3) X3=1 S X1(1)=$P(X1,",",2),X1=+X1,%H=X2
|
---|
52 | G D2
|
---|
53 | HADD(X,D,H,M,S) ;Add to $H date
|
---|
54 | N %H,%T S %H=+X,%T=$P(X,",",2) D A2 Q %H_","_%T
|
---|
55 | A2 S %H=%H+$G(D),%T=%T+($G(H)*3600)+($G(M)*60)+$G(S)
|
---|
56 | S:%T'<86400 %H=%H+(%T\86400),%T=%T#86400 S:%T<0 %H=%H+(%T\86400)-1,%T=%T#86400
|
---|
57 | Q
|
---|
58 | FMADD(X,D,H,M,S) ;Add to FM date
|
---|
59 | N %H,%T S %H=$$FMTH(X,0),%T=$P(%H,",",2) D A2 Q $$HTFM(%H_","_%T)
|
---|
60 | CONVQQ(X) ; CONVERT SINGLE TO DOUBLE QUOTES IN STRING X
|
---|
61 | N Q,F S Q=""""
|
---|
62 | F F=0:0 S F=$F(X,Q,F) Q:F=0 S X=$E(X,1,F-2)_Q_Q_$E(X,F,256),F=F+1
|
---|
63 | Q X
|
---|
64 | CONVQ(X) ; CONVERT DOUBLE TO SINGLE QUOTES IN STRING X
|
---|
65 | N Q,F,D S Q="""",D=""""""
|
---|
66 | F F=0:0 S F=$F(X,D,F) Q:F=0 S X=$E(X,1,F-3)_Q_$E(X,F,256),F=F-1
|
---|
67 | Q X
|
---|
68 | QUOTE(X) ; PUT QUOTES AROUND STRING
|
---|
69 | S X=""""_$G(X)_"""" Q X
|
---|
70 | FNO(X) ; gets a subfile's top level file number
|
---|
71 | N Y S X=+X
|
---|
72 | I $G(^DIC(X,0))]"" Q X
|
---|
73 | F S Y=+$G(^DD(X,0,"UP")) D Q:'$D(X)!(Y'>0)
|
---|
74 | . I $G(^DIC(Y,0))]"" K X Q
|
---|
75 | . S X=Y
|
---|
76 | . Q
|
---|
77 | Q Y
|
---|
78 | GLO(Z) ; gets the file number from a global root
|
---|
79 | I '$D(@(Z_"0)"))#2 Q 0
|
---|
80 | N Y
|
---|
81 | S Y=+$P($G(@(Z_"0)")),U,2)
|
---|
82 | Q $$FNO(+Y)
|
---|
83 | UP(X) ; convert string X to uppercase
|
---|
84 | I X?.UNP Q X
|
---|
85 | N A,B,C S C=""
|
---|
86 | F A=1:1:$L(X) S B=$E(X,A) S C=C_$S(B?1L:$C($A(B)-32),1:B)
|
---|
87 | Q C
|
---|
88 | ROUEXIST(X) ; Execute routine existence test
|
---|
89 | G:X="" QRER I '$D(DISYS) N DISYS D OS^DII
|
---|
90 | I $G(^%ZOSF("TEST"))]"" X ^("TEST") Q $T
|
---|
91 | I $G(^DD("OS",DISYS,18))]"" X ^(18) Q $T
|
---|
92 | QRER Q 0
|
---|
93 | F5 ;
|
---|
94 | F1 S %R=$P($S(%F'["U":$T(M),1:$T(MU))," ",$S($E(Y,4,5):$E(Y,4,5)+2,1:0))_$S($E(Y,4,5):" ",1:"")_$S($E(Y,6,7):$S((%F\1'=5):$E(Y,6,7),1:+$E(Y,6,7))_$E(", ",1,1+(%F\1'=5)),1:"")_($E(Y,1,3)+1700)
|
---|
95 | TM Q:%T'>0!(%F["D")
|
---|
96 | I %F'["P" S %R=%R_$S(%F\1'=6:"@",1:" @ ")_$E(%T,2,3)_":"_$E(%T,4,5)_$S($E(%T,6,7)!(%F["S"):":"_$E(%T,6,7),1:$S(%F\1'=6:"",1:" "))
|
---|
97 | I %F["P" S %R=%R_" "_$S($E(%T,2,3)>12:$E(%T,2,3)-12,1:+$E(%T,2,3))_":"_$E(%T,4,5)_$S($E(%T,6,7)!(%F["S"):":"_$E(%T,6,7),1:"")_$S($E(%T,2,5)\1200=1:" pm",1:" am")
|
---|
98 | Q
|
---|
99 | M ;; Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
|
---|
100 | MU ;; JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
|
---|
101 | F2 S %R=+$E(Y,4,5)_"/"_(+$E(Y,6,7))_"/"_$E(Y,2,3)
|
---|
102 | G TM
|
---|
103 | F3 S %R=+$E(Y,6,7)_"/"_(+$E(Y,4,5))_"/"_$E(Y,2,3)
|
---|
104 | G TM
|
---|
105 | F4 S %R=$E(Y,2,3)_"/"_$E(Y,4,5)_"/"_$E(Y,6,7)
|
---|
106 | G TM
|
---|
107 | F6 S %R=$S($E(Y,4,5):$E(Y,4,5)_"-",1:"")_$S($E(Y,6,7):$E(Y,6,7)_"-",1:"")_(1700+$E(Y,1,3))
|
---|
108 | G TM
|
---|
109 | F7 S %R=$S($E(Y,4,5):+$E(Y,4,5)_"-",1:"")_$S($E(Y,6,7):+$E(Y,6,7)_"-",1:"")_(1700+$E(Y,1,3))
|
---|
110 | G TM
|
---|
111 | ;
|
---|
112 | HKERR(DIFILE,DIIENS,DIFLD,DIHOOK) ;
|
---|
113 | N DIEXT
|
---|
114 | S DIEXT("FILE")=$G(DIFILE)
|
---|
115 | S DIEXT("FIELD")=$G(DIFLD)
|
---|
116 | S DIEXT("IENS")=$G(DIIENS)
|
---|
117 | S DIEXT(1)=$G(DIHOOK)
|
---|
118 | D BLD^DIALOG(120,DIHOOK,.DIEXT)
|
---|
119 | Q
|
---|
120 | ;
|
---|
121 | FILENUM(DIGREF) ; Return file/subfile number from open global reference
|
---|
122 | Q:$G(DIGREF)'?1"^".1"%"1U.UN1"(".E ""
|
---|
123 | N DIGR,X,DIFILE S DIFILE=""
|
---|
124 | S DIFILE=$$FNUM1(DIC) Q:DIFILE'="" DIFILE
|
---|
125 | I $E(DIGREF,1,8)="^DIC(.2," Q .2
|
---|
126 | S DIGREF=$$CREF^DILF(DIGREF),DIGREF=$NA(@DIGREF),DIGREF=$$OREF^DILF(DIGREF)
|
---|
127 | S DIFILE="" D I DIFILE="" Q ""
|
---|
128 | . S DIGR=DIGREF N DISUBS S DISUBS=$QL($$CREF^DILF(DIGR)) Q:'DISUBS
|
---|
129 | . F DISUBS=DISUBS-1:-1 Q:DISUBS'>-1 D Q:DIFILE'=""
|
---|
130 | . . I DISUBS S DIGR=$P(DIGR,",",1,DISUBS)_"," S DIFILE=$$FNUM1(DIGR) Q
|
---|
131 | . . S DIGR=$P(DIGR,"(")_"(" Q:DIGR="^DIC(" S DIFILE=$$FNUM1(DIGR) Q
|
---|
132 | . Q
|
---|
133 | S X=$P(DIGREF,DIGR,2,99) I X="" Q DIFILE
|
---|
134 | N I,J,K,Q S Q=""""
|
---|
135 | F I=2:2 S J=$P(X,",",I) Q:J="" D Q:DIFILE=""
|
---|
136 | . I $E(J)=Q S J=$P(J,Q,2)
|
---|
137 | . S K=$O(^DD(DIFILE,"GL",J,0,0)) I 'K S DIFILE="" Q
|
---|
138 | . S DIFILE=+$P($G(^DD(DIFILE,K,0)),U,2) Q
|
---|
139 | Q DIFILE
|
---|
140 | ;
|
---|
141 | FNUM1(DIGR) ; Return file number for file 0, or from 0 node of data
|
---|
142 | ; DIGR is the open global reference
|
---|
143 | N DIFILE
|
---|
144 | I $E(DIGR,1,4)="^DD(",$P(DIGR,"(",2) D I $D(DIFILE) Q DIFILE
|
---|
145 | . I $L(DIGR,",")=2 S DIFILE=0 Q
|
---|
146 | . I $L(DIGR,",")'=4 Q
|
---|
147 | . N % S %=$P(DIGR,",",3)
|
---|
148 | . I %=11 S DIFILE=.2 Q
|
---|
149 | . S:%=20 DIFILE=.3 Q
|
---|
150 | S DIFILE=+$P($G(@(DIGR_"0)")),U,2)
|
---|
151 | I DIFILE,$G(^DIC(DIFILE,0,"GL"))=DIGR Q DIFILE
|
---|
152 | Q ""
|
---|
153 | ;
|
---|