source: ccr/trunk/p/CCRUTIL.m@ 159

Last change on this file since 159 was 149, checked in by George Lilly, 16 years ago

removed extra spaces at the beginning of lines

File size: 5.4 KB
Line 
1CCRUTIL ;CCRCCD/SMH - Various Utilites for generating the CCR/CCD;06/15/08
2 ;;0.1;CCRCCD;;Jun 15, 2008;
3 ;Copyright 2008 WorldVistA. Licensed under the terms of the GNU
4 ;General Public License See attached copy of the License.
5 ;
6 ;This program is free software; you can redistribute it and/or modify
7 ;it under the terms of the GNU General Public License as published by
8 ;the Free Software Foundation; either version 2 of the License, or
9 ;(at your option) any later version.
10 ;
11 ;This program is distributed in the hope that it will be useful,
12 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;GNU General Public License for more details.
15 ;
16 ;You should have received a copy of the GNU General Public License along
17 ;with this program; if not, write to the Free Software Foundation, Inc.,
18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20 W "No Entry at Top!"
21 Q
22 ;
23FMDTOUTC(DATE,FORMAT) ; Convert Fileman Date to UTC Date Format; PUBLIC; Extrinsic
24 ; FORMAT is Format of Date. Can be either D (Day) or DT (Date and Time)
25 ; If not passed, or passed incorrectly, it's assumed that it is D.
26 ; FM Date format is "YYYMMDD.HHMMSS" HHMMSS may not be supplied.
27 ; UTC date is formatted as follows: YYYY-MM-DDThh:mm:ss_offsetfromUTC
28 ; UTC, Year, Month, Day, Hours, Minutes, Seconds, Time offset (obtained from Mailman Site Parameters)
29 N UTC,Y,M,D,H,MM,S,OFF
30 S Y=1700+$E(DATE,1,3)
31 S M=$E(DATE,4,5)
32 S D=$E(DATE,6,7)
33 S H=$E(DATE,9,10)
34 I $L(H)=1 S H="0"_H
35 S MM=$E(DATE,11,12)
36 I $L(MM)=1 S MM="0"_MM
37 S S=$E(DATE,13,14)
38 I $L(S)=1 S S="0"_S
39 S OFF=$$TZ^XLFDT ; See Kernel Manual for documentation.
40 ; If H, MM and S are empty, it means that the FM date didn't supply the time.
41 ; In this case, set H, MM and S to "00"
42 ; S:('$L(H)&'$L(MM)&'$L(S)) (H,MM,S)="00" ; IF ONLY SOME ARE MISSING?
43 S:'$L(H) H="00"
44 S:'$L(MM) MM="00"
45 S:'$L(S) S="00"
46 S UTC=Y_"-"_M_"-"_D_"T"_H_":"_MM_$S(S="":":00",1:":"_S)_OFF ; Skip's code to fix hanging colon if no seconds
47 I $L($G(FORMAT)),FORMAT="DT" Q UTC ; Date with time.
48 E Q $P(UTC,"T")
49 ;
50SORTDT(V1,V2,ORDR) ; DATE SORT ARRAY AND RETURN INDEX IN V1 AND COUNT
51 ; AS EXTRINSIC ORDR IS 1 OR -1 FOR FORWARD OR REVERSE
52 ; DATE AND TIME ORDER. DEFAULT IS FORWARD
53 ; V2 IS AN ARRAY OF DATES IN FILEMAN FORMAT
54 ; V1 IS RETURNS INDIRECT INDEXES OF V2 IN REVERSE DATE ORDER
55 ; SO V2(V1(X)) WILL RETURN THE DATES IN DATE/TIME ORDER
56 ; THE COUNT OF THE DATES IS RETURNED AS AN EXTRINSIC
57 ; BOTH V1 AND V2 ARE PASSED BY REFERENCE
58 N VSRT ; TEMP FOR HASHING DATES
59 N ZI,ZJ,ZTMP,ZCNT,ZP1,ZP2
60 S ZCNT=0 ; COUNTING NUMBER OF DATES
61 S ZTMP="" ;
62 F ZI=0:0 D Q:$O(V2(ZTMP))="" ; FOR EACH DATE IN THE ARRAY
63 . S ZCNT=ZCNT+1 ; INCREMENT THE COUNT
64 . S ZTMP=$O(V2(ZTMP)) ; NEXT DATE
65 . I $D(V2(ZTMP)) D ; IF THE DATE EXISTS
66 . . S ZP1=$P(V2(ZTMP),".",1) ; THE DATE PIECE
67 . . S ZP2=$P(V2(ZTMP),".",2) ; THE TIME PIECE
68 . . S VSRT(ZP1,ZP2_"00000"_ZCNT)=ZCNT ; HASH ON DATE AND TIME
69 . . ; S VSRT($P(V2(ZTMP),U,4)_"000000"_ZCNT)=ZCNT ; PULL DATE
70 . I DEBUG W "ZTMP=",ZTMP," "
71 S V1(0)=ZCNT ; ARRAYS ARE THE SAME SIZE
72 ; I DEBUG ZWR V2
73 ; I DEBUG ZWR VSRT
74 N ZD,ZT ; DATA AND TIME ITERATORS
75 N ZDONE ; DONE FLAG
76 S (ZD,ZT)=""
77 S ZDONE=0
78 N UORDR ; ORDER TO USE 1=FORWARD -1=REVERSE
79 S UORDR=ORDR ; DIRECTION TO SORT
80 I ORDR="" S UORDR=1
81 N ZZCNT S ZZCNT=0 ; ANOTHER COUNTER
82 F ZI=0:0 D Q:ZDONE ; VISIT THE ARRAY IN DATE ORDER
83 . S ZD=$O(VSRT(ZD),UORDR) ; NEXT DATE
84 . I ZD="" S ZDONE=1
85 . I 'ZDONE D ; MORE DATES
86 . . S ZT="" ; WANT FIRST TIME FOR THIS DATE
87 . . F ZJ=0:0 D Q:$O(VSRT(ZD,ZT),UORDR)="" ; LOOP THROUGH ALL TIMES
88 . . . S ZT=$O(VSRT(ZD,ZT),UORDR) ; NEXT TIME
89 . . . S ZZCNT=ZZCNT+1 ; INCREMENT COUNTER
90 . . . S V1(ZZCNT)=VSRT(ZD,ZT) ; PULL OUT THE INDEX
91 Q ZCNT
92 ;
93SORTDT2(V1,V2,ORDR) ; REWRITE TO USE 3 INSTEAD OF 2 LVLS OF INDEX
94 ; AND $Q INSTEAD OF $O
95 ; DATE SORT ARRAY AND RETURN INDEX IN V1 AND COUNT
96 ; AS EXTRINSIC ORDR IS 1 OR -1 FOR FORWARD OR REVERSE
97 ; DATE AND TIME ORDER. DEFAULT IS FORWARD
98 ; V2 IS AN ARRAY OF DATES IN FILEMAN FORMAT
99 ; V1 IS RETURNS INDIRECT INDEXES OF V2 IN REVERSE DATE ORDER
100 ; SO V2(V1(X)) WILL RETURN THE DATES IN DATE/TIME ORDER
101 ; THE COUNT OF THE DATES IS RETURNED AS AN EXTRINSIC
102 ; BOTH V1 AND V2 ARE PASSED BY REFERENCE
103 N VSRT ; TEMP FOR HASHING DATES
104 N ZI,ZJ,ZTMP,ZCNT,ZP1,ZP2
105 S ZCNT=0 ; COUNTING NUMBER OF DATES
106 S ZTMP="" ;
107 F ZI=0:0 D Q:$O(V2(ZTMP))="" ; FOR EACH DATE IN THE ARRAY
108 . S ZCNT=ZCNT+1 ; INCREMENT THE COUNT
109 . S ZTMP=$O(V2(ZTMP)) ; NEXT DATE
110 . I $D(V2(ZTMP)) D ; IF THE DATE EXISTS
111 . . S ZP1=$P(V2(ZTMP),".",1) ; THE DATE PIECE
112 . . S ZP2=$P(V2(ZTMP),".",2) ; THE TIME PIECE
113 . . S VSRT(ZP1,ZP2,ZCNT)=ZCNT ; HASH ON DATE AND TIME
114 . I DEBUG W "ZTMP=",ZTMP," "
115 S V1(0)=ZCNT ; ARRAYS ARE THE SAME SIZE
116 ; I DEBUG ZWR V2
117 ; I DEBUG ZWR VSRT
118 N ZD,ZT ; DATA AND TIME ITERATORS
119 N ZDONE ; DONE FLAG
120 S (ZD,ZT)=""
121 S ZDONE=0
122 N UORDR ; ORDER TO USE 1=FORWARD -1=REVERSE
123 S UORDR=ORDR ; DIRECTION TO SORT
124 I ORDR="" S UORDR=1
125 N ZZCNT S ZZCNT=0 ; ANOTHER COUNTER
126 F ZI=0:0 D Q:ZDONE ; VISIT THE ARRAY IN DATE ORDER
127 . S ZD=$O(VSRT(ZD),UORDR) ; NEXT DATE fix this
128 . I ZD="" S ZDONE=1
129 . I 'ZDONE D ; MORE DATES
130 . . S ZT="" ; WANT FIRST TIME FOR THIS DATE
131 . . F ZJ=0:0 D Q:$O(VSRT(ZD,ZT),UORDR)="" ; LOOP THROUGH ALL TIMES
132 . . . S ZT=$O(VSRT(ZD,ZT),UORDR) ; NEXT TIME
133 . . . S ZZCNT=ZZCNT+1 ; INCREMENT COUNTER
134 . . . S V1(ZZCNT)=VSRT(ZD,ZT) ; PULL OUT THE INDEX
135 Q ZCNT
136 ;
Note: See TracBrowser for help on using the repository browser.