source: FOIAVistA/trunk/r/SCHEDULING-SD-SC/SCRPW71.m@ 1608

Last change on this file since 1608 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 7.8 KB
Line 
1SCRPW71 ;BP-CIOFO/KEITH - Clinic appointment availability extract (cont.) ; 14 May 99 9:19 PM
2 ;;5.3;Scheduling;**192**;AUG 13, 1993
3 ;
4CLINIC(SC,SDFMT,SDSTRTDT,MAXDT,MAX,SDPAST) ;Evaluate a clinic
5 ;Input: SC=clinic ifn
6 ;Input: SDFMT='S' for totals only, 'D' for detail and totals
7 ;Input: SDSTRTDT=begin date for data extraction
8 ;Input: MAXDT=end date for data extraction
9 ;Input: MAX=number of days in date range
10 ;Input: SDPAST='0' for future dates, '1' for past dates
11 ;Output: # of slots found^maximum capacity^error condition (1=success,-1=failure)^comment (if failure) or sort value (if success)
12 N SC0,SDCP,X1,X2,X,%H,SDIV
13 S SC0=$G(^SC(SC,0)) Q:$P(SC0,U,3)'="C" "0^0^-1^Not a clinic location type"
14 Q:$P(SC0,U,17)="Y" "0^0^-1^Clinic defined as non-count"
15 Q:'$$CPAIR(SC0,.SDCP) "0^0^-1^Not a valid primary clinic Stop Code"
16 S X2=$P($G(^SC(SC,"SDP")),U,2) I X2 S X1=DT D C^%DTC S:X<MAXDT MAXDT=X
17 Q:'$$ACTC(SC,SDSTRTDT,MAXDT) "0^0^-1^Clinic is inactivated during these dates"
18 S SDIV=$$DIV(SC0) Q:'$L(SDIV) "0^0^-1^Invalid division number"
19 D SPAT(SC,SDSTRTDT,MAXDT)
20 Q $$CCNT(SC,MAX,SDCP,SDFMT,SDSTRTDT,SDIV,SDPAST)_"^1^"_SDCP_U_SC
21 ;
22DIV(SC0) ;Get facility division name and number
23 ;Input: SC0=hospital location zeroeth node
24 N SDIV S SDIV=$P(SC0,U,15)
25 Q:SDIV>0 $P($$SITE^VASITE(,SDIV),U,2,3)
26 Q $P($$SITE^VASITE(),U,2,3)
27 ;
28CPAIR(SC0,SDCP) ;Validate primary stop code, get credit pair
29 ;Input: SC0=zeroeth node of HOSPITAL LOCATION record
30 ;Input: SDCP=variable to return clinic credit pair (pass by reference)
31 ;Output: 1=success, 0=invalid primary stop code
32 N SDSSC
33 S SDCP=$P($G(^DIC(40.7,+$P(SC0,U,7),0)),U,2),SDCP=$S(SDCP<100:0,SDCP>999:0,1:SDCP)
34 Q:SDCP'>0 0
35 S SDSSC=$P($G(^DIC(40.7,+$P(SC0,U,18),0)),U,2),SDCP=SDCP_$S(SDSSC<100:"000",SDSSC>999:"000",1:SDSSC)
36 Q 1
37 ;
38ACTC(SC,SDSTRTDT,MAXDT) ;Determine if clinic is active during date range
39 ;Input: SC=clinic ifn
40 ;Input: SDSTRTDT=begin date for evaluation (TODAY+1)
41 ;Input: MAXDT=maximum date in the future to evaluate (end date)
42 ;Output: 1=active, 0=inactive during entire date range
43 N SDIN,SDRE,X1,X2,X,%H
44 S SDIN=$G(^SC(SC,"I")),SDRE=$P(SDIN,U,2),SDIN=$P(SDIN,U)
45 Q:SDIN<1 1 Q:SDIN>SDSTRTDT 1
46 I SDRE,SDRE'>MAXDT Q 1
47 Q 0
48 ;
49SPAT(SC,SDSTRTDT,ENDATE,SDS) ;Set patterns into ^TMP (modified clone of OVR^SDAUT1)
50 ;Input: SC=clinic ifn
51 ;Input: SDSTRTDT=start date for gathering patterns
52 ;Input: ENDATE=date in future to evaluate to
53 ;Input: SDS=array namespace subscript value (optional)
54 ;Output: array of clinic current availability patterns in
55 ; ^TMP(SDS,$J,clinic_ifn,"ST",date,1)
56 ;
57 S SDS=$G(SDS) S:'$L(SDS) SDS="SDTMP" K ^TMP(SDS,$J)
58 N SI,SDIN,SDRE,SDSOH,X,X1,X2,SM,I,D,J,Y,SS,DAY
59 S SDIN=$G(^SC(SC,"I")),SDRE=$P(SDIN,U,2),SDIN=$P(SDIN,U)
60 S DAY="SU^MO^TU^WE^TH^FR^SA"
61 S SI=$P($G(^SC(SC,"SL")),U,6),SI=$S(SI<3:4,1:SI)
62 S SDSOH=$S('$D(^SC(SC,"SL")):0,$P(^SC(SC,"SL"),"^",8)']"":0,1:1)
63 S SDIN=$G(SDIN),X=SDSTRTDT
64EN1 S:$O(^SC(SC,"T",0))>X X=$O(^SC(SC,"T",0))
65 S Y=$$DOW^XLFDT(X,1),I=Y+32,SM=X,D=Y D WM
66 K J F Y=0:1:6 I $D(^SC(+SC,"T"_Y)) S J(Y)=""
67 I '$D(J) D Q
68 .S D=SDSTRTDT-1 F S D=$O(^SC(SC,"ST",D)) Q:'D!(D>ENDATE) D
69 ..S X=$G(^SC(SC,"ST",D,1)) S:$L(X) ^TMP(SDS,$J,SC,"ST",D,1)=X Q
70 .Q
71X1 Q:X>ENDATE S X1=X\100_28
72 I '$$ACTIVE(X,SDIN,SDRE) S X1=X,X2=1 D C^%DTC G X1
73W S X=X\1
74 I $D(^SC(+SC,"ST",X,1)) S ^TMP(SDS,$J,SC,"ST",X,1)=^SC(+SC,"ST",X,1) G W1
75 I '$D(^SC(SC,"ST",X,1)) S Y=D#7 G L:'$D(J(Y)),H:$D(^HOLIDAY(X))&('SDSOH) S SS=$O(^SC(SC,"T"_Y,X)) G L:SS<1,L:^SC(SC,"T"_Y,SS,1)="" D
76 .S ^TMP(SDS,$J,SC,"ST",X\1,1)=$P(DAY,U,Y+1)_" "_$E(X,6,7)_$J("",SI+SI-6)_^SC(SC,"T"_Y,SS,1) Q
77W1 D WM:X>SM
78L Q:X>ENDATE S X=X+1,D=D+1 G W:X'>X1 S X2=X-X1 D C^%DTC G X1
79 ;
80H S ^TMP(SDS,$J,SC,"ST",X,1)=" "_$E(X,6,7)_" "_$P(^(X,0),U,2) G W1
81 ;
82WM S SM=$S($E(X,4,5)[12:$E(X,1,3)+1_"01",1:$E(X,1,3)_$E(X,4,5)+1)_"00" Q
83 ;
84ACTIVE(X,SDIN,SDRE) ;Determine if the clinic is active on a given date
85 ;Input: X=date to be examined
86 ;Input: SDIN=clinic inactive date
87 ;Input: SDRE=clinic reactivate date
88 ;Output: '1'=active, '0'=inactive
89 Q:'SDIN 1 Q:X<SDIN 1 Q:'SDRE 0 Q:X<SDRE 0 Q 1
90 ;
91INIT ;Initialize array for counting patterns
92 K SD N SDI
93 S SD="123456789jklmnopqrstuvwxyz"
94 F I=1:1:26 S SD($E(SD,I))=I
95 Q
96 ;
97CCNT(SC,MAX,SDCP,SDFMT,SDSTRTDT,SDIV,SDPAST) ;Count clinic availability and capacity
98 ;Input: SC=clinic ifn
99 ;Input: MAX=maximum days to evaluate availability
100 ;Input: SDCP=credit pair
101 ;Input: SDFMT=report format
102 ;Input: SDSTRTDT=begin date of report
103 ;Input: SDIV=clinic division number
104 ;Input: SDPAST='0' for future dates, '1' for past dates
105 ;Output: total # of open slots found^maximum capacity
106 ;Output: Creates an array of:
107 ; ^TMP("SD",$J,SDIV,SDCP)=open slots^maximum capacity^encounters
108 ; ^TMP("SD",$J,SDIV,SDCP,SC)=open slots^maximum capacity^encounters
109 ; ^TMP("SD",$J,SDIV,SDCP,SC,sub)=slots~capacity~encounters^slots~capacity~encounters ... etc. (up to 12 slots~capacity~encounters values)
110 ; where 'sub' is a number 0 to nnn, 'sub' * 12 + "^" $PIECE where the data
111 ; is stored equals the day which that data represents.
112 ;
113 N SDTOE
114 S SDTOE=U_$P($G(^TMP("SD",$J,SDIV,SDCP,SC)),U,3) S:$L(SDTOE)=1 SDTOE=""
115 Q:'$D(^TMP("SDTMP",$J)) "0^0"_SDTOE
116 D:'$D(^TMP("SD",$J,SDIV,SDCP,SC)) ARRINI(SDCP,SC,MAX,SDPAST)
117 N SDDAY,SDI,SDPATT,SDTSL,SDSL,SDTCAP,SDCAP,SDY
118 S X1=SDSTRTDT,X2=-1 D C^%DTC S SDY=X
119 S (SDTSL,SDTCAP)=0 F SDI=1:1:MAX D
120 .S (SDSL,SDCAP)=0,X1=SDY,X2=SDI D C^%DTC S SDDAY=X
121 .;Count open slots
122 .S SDPATT=$E($G(^TMP("SDTMP",$J,SC,"ST",SDDAY,1)),6,999)
123 .I SDPATT["[" D
124 ..S SDSL=$$PCT(SDPATT),SDTSL=SDTSL+SDSL
125 ..;Count maximum slots
126 ..N X,%H,%T,%Y,SDDW,SDMPDT
127 ..S SDCAP=0
128 ..S SDPATT=$E($G(^SC(SC,"OST",SDDAY,1)),6,999) I $L(SDPATT) S SDCAP=$$PCT(SDPATT),SDTCAP=SDTCAP+SDCAP Q:SDCAP
129 ..S X=SDDAY D H^%DTC S SDDW="T"_%Y,SDMPDT=$O(^SC(SC,SDDW,SDDAY))
130 ..S SDPATT=$G(^SC(SC,SDDW,+SDMPDT,1)),SDCAP=$$PCT(SDPATT),SDTCAP=SDTCAP+SDCAP
131 ..Q
132 .D:SDFMT="D" ARRSET(SDCP,SC,SDI,SDSL,SDCAP) Q
133 S $P(^TMP("SD",$J,SDIV,SDCP),U)=$P(^TMP("SD",$J,SDIV,SDCP),U)+SDTSL
134 S $P(^TMP("SD",$J,SDIV,SDCP),U,2)=$P(^TMP("SD",$J,SDIV,SDCP),U,2)+SDTCAP
135 S $P(^TMP("SD",$J,SDIV,SDCP,SC),U)=$P(^TMP("SD",$J,SDIV,SDCP,SC),U)+SDTSL
136 S $P(^TMP("SD",$J,SDIV,SDCP,SC),U,2)=$P(^TMP("SD",$J,SDIV,SDCP,SC),U,2)+SDTCAP
137 I SDPAST D
138 .S $P(^TMP("SD",$J,SDIV,SDCP),U,3)=$P(^TMP("SD",$J,SDIV,SDCP),U,3)+0
139 .S $P(^TMP("SD",$J,SDIV,SDCP,SC),U,3)=$P(^TMP("SD",$J,SDIV,SDCP,SC),U,3)+0 Q
140 Q SDTSL_U_SDTCAP_SDTOE
141 ;
142PCT(SDPATT) ;Pattern count
143 ;Input: SDPATT=pattern to evaluate
144 Q:SDPATT'["[" 0
145 N X,I S X=0
146 S SDPATT=$TR(SDPATT," |[]","")
147 F I=1:1:$L(SDPATT) S X=X+$G(SD($E(SDPATT,I)))
148 Q X
149 ;
150ARRINI(SDCP,SC,MAX,SDPAST) ;Initialize array for counts
151 ;Input: SDCP=credit pair
152 ;Input: SC=clinic ifn
153 ;Input: MAX=maximum days to report
154 ;Input: SDPAST='0' for future dates, '1' for past dates
155 N SDI,SDX,SDY,SDS,SDP
156 S SDY="0~0" S:SDPAST SDY=SDY_"~0"
157 S SDX="" F SDI=1:1:(2+SDPAST) S $P(SDX,U,SDI)=0
158 S:'$D(^TMP("SD",$J,SDIV,SDCP)) ^TMP("SD",$J,SDIV,SDCP)=SDX
159 S ^TMP("SD",$J,SDIV,SDCP,SC)=SDX Q:SDFMT'="D"
160 F SDI=0:1:(MAX-1\12) S ^TMP("SD",$J,SDIV,SDCP,SC,SDI)=""
161 F SDI=1:1:MAX D
162 .S SDS=SDI-1\12,SDP=SDI#12 S:SDP=0 SDP=12
163 .S $P(^TMP("SD",$J,SDIV,SDCP,SC,SDS),U,SDP)=SDY
164 .Q
165 Q
166 ;
167ARRSET(SDCP,SC,SDI,SDSL,SDCAP) ;Set daily counts into array
168 ;Input: SDCP=credit pair
169 ;Input: SC=clinic ifn
170 ;Input: SDI=number of days from report date
171 ;Input: SDSL=number of open slots for day SDI
172 ;Input: SDCAP=maximum slots for day SDI
173 N SDS,SDP,SDX
174 S SDS=SDI-1\12,SDP=SDI#12 S:SDP=0 SDP=12
175 S SDX=$P(^TMP("SD",$J,SDIV,SDCP,SC,SDS),U,SDP)
176 S $P(SDX,"~")=$P(SDX,"~")+SDSL
177 S $P(SDX,"~",2)=$P(SDX,"~",2)+SDCAP
178 I $G(SDPAST),$P(SDX,"~",3)="" S $P(SDX,"~",3)=0
179 S $P(^TMP("SD",$J,SDIV,SDCP,SC,SDS),U,SDP)=SDX
180 Q
181 ;
182PCNT(X) ;Count open slots in a pattern
183 ;Input: X=^SC(SC,"ST",SDT,1) node
184 ;Output: number of open slots in a single date pattern
185 N I,CT
186 S CT=0 Q:X'["[" CT
187 S X=$E(X,6,999),X=$TR(X,"|[] ","")
188 F I=1:1:$L(X) S CT=CT+$G(SD($E(X,I)))
189 Q CT
Note: See TracBrowser for help on using the repository browser.