source: WorldVistAEHR/trunk/r/SCHEDULING-SD-SC/SCRPW72.m@ 846

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

initial load of WorldVistAEHR

File size: 9.2 KB
RevLine 
[613]1SCRPW72 ;BP-CIOFO/KEITH,ESW - Clinic appointment availability extract (cont.) ; 5/23/03 12:16pm
2 ;;5.3;Scheduling;**192,206,223,241,249,291**;AUG 13, 1993
3 ;
4START ;Gather data for printed report
5 N SDCP,SC,SCNA,SDI,SDOUT,SDPAST,SDXM,MAX,X1,X2,X,SDIOM,SDFOOT
6 I $E(IOST)="C" D WAIT^DICD
7 S (SDOUT,SDI)=0,SDIOM=$G(IOM,80)
8 S SDPAST=SDBDT'>DT S:SDPAST SDIOM=130
9 D HINI^SCRPW76,FOOT^SCRPW77(.SDFOOT)
10 K ^TMP("SD",$J),^TMP("SDS",$J),^TMP("SDTMP",$J),^TMP("SDTOT",$J)
11 I $G(SDREPORT(4)) K ^TMP("SDPLIST",$J)
12 I $G(SDREPORT(5)) D
13 .N CC F CC="SDIPLST","SDIP","SDORD" K ^TMP(CC,$J)
14 D INIT^SCRPW71 S SDCOL=$S(SDPAST:0,1:(SDIOM-58\2))
15 S X1=SDEDT,X2=SDBDT D ^%DTC S MAX=X+1
16 I SDPAST I '$G(SDREPORT(5)) D OE(SDBDT,SDEDT,MAX,0) Q:SDOUT ;get outpt. enc. workload
17 G:SDOUT EXIT^SCRPW74
18 I $G(SDFMT)="D"!($G(SDFMTS)="CP") D
19 .I $G(SDREPORT(5)) D CA(.SDSORT) Q
20 .D @SDSORT
21 I $G(SDFMT)="S"&($G(SDFMTS)'="CP") S SC=0 F S SC=$O(^SC(SC)) Q:'SC!SDOUT D
22 .S SDI=SDI+1 I SDI#25=0 D STOP Q:SDOUT
23 .S SC0=$G(^SC(SC,0)) Q:'$$DIV(+$P(SC0,U,15))
24 .S SDX=$$CLINIC^SCRPW71(SC,SDFMT,SDBDT,SDEDT,MAX,SDPAST)
25 G:SDOUT EXIT^SCRPW74
26 S SDMD=$O(^TMP("SD",$J,"")),SDMD=$O(^TMP("SD",$J,SDMD)),SDMD=$L(SDMD)
27 I SDPAST D NAVA^SCRPW75(SDBDT,SDEDT,SDEX) ;get next available wait times
28 G:SDOUT EXIT^SCRPW74
29 D ORD
30 I $E(IOST)="C" D END^SCRPW50
31 S SDREPORT=0 F S SDREPORT=$O(SDREPORT(SDREPORT)) Q:SDOUT!'SDREPORT D
32 .I SDREPORT(SDREPORT) S SDPAGE=1 D PRT^SCRPW73(0,SDREPORT)
33 G EXIT^SCRPW74
34 ;
35ORD ;Build list to order clinic output
36 S SDIV="" F S SDIV=$O(^TMP("SD",$J,SDIV)) Q:SDIV=""!SDOUT D
37 .S SDCP=0 F S SDCP=$O(^TMP("SD",$J,SDIV,SDCP)) Q:'SDCP!SDOUT D
38 ..S SC=0 F S SC=$O(^TMP("SD",$J,SDIV,SDCP,SC)) Q:'SC!SDOUT D
39 ...S SCNA=$P($G(^SC(SC,0)),U) S:'$L(SCNA) SCNA="UNKNOWN"
40 ...S ^TMP("SDS",$J,SDCP,SCNA,SC)=""
41 Q
42 ;
43OE(SDBDT,SDEDT,MAX,SDEX) ;Count clinic workload
44 ;Input: SDBDT=begin date
45 ;Input: SDEDT=end date
46 ;Input: MAX=number of days in date range
47 ;Input: SDEX='0' for user report, '1' for Austin extract
48 N SDT,SDOE,SDOE0,SDCT,SDCP,SDQUIT,SDAY,DFN
49 S (SDQUIT,SDCT)=0,SDT=SDBDT
50 F S SDT=$O(^SCE("B",SDT)) Q:'SDT!(SDT>SDEDT)!SDOUT D
51 .S SDOE=0 F S SDOE=$O(^SCE("B",SDT,SDOE)) Q:'SDOE!SDOUT D
52 ..S SDCT=SDCT+1 I SDCT#1000=0 D STOP Q:SDOUT
53 ..S SDOE0=$$GETOE^SDOE(SDOE) Q:$P(SDOE0,U,6) Q:$P(SDOE0,U,12)=12
54 ..S DFN=$P(SDOE0,U,2) Q:'DFN
55 ..Q:$E($P($G(^DPT(DFN,0)),U,9),1,5)="00000" ;exclude test patients
56 ..S SC=$P(SDOE0,U,4) Q:'SC Q:'$$DIV(+$P(SDOE0,U,11))
57 ..S SC0=$G(^SC(SC,0)) Q:'$L($P(SC0,U))
58 ..Q:$P(SC0,U,17)="Y" Q:'$$CPAIR^SCRPW71(SC0,.SDCP)
59 ..I 'SDEX,$D(SDSORT) S SDQUIT=0 D Q:SDQUIT
60 ...I SDSORT="CL"!(SDSORT="CA"),'$D(SDSORT($P(SC0,U))) S SDQUIT=1 Q
61 ...I SDSORT="CP",'$D(SDSORT(SDCP)) S SDQUIT=1
62 ..S SDIV=$$DIV^SCRPW71(SC0) Q:'$L(SDIV)
63 ..I '$D(^TMP("SD",$J,SDIV,SDCP,SC)) D ARRINI^SCRPW71(SDCP,SC,MAX,SDPAST)
64 ..S $P(^TMP("SD",$J,SDIV,SDCP),U,3)=$P(^TMP("SD",$J,SDIV,SDCP),U,3)+1
65 ..S $P(^TMP("SD",$J,SDIV,SDCP,SC),U,3)=$P(^TMP("SD",$J,SDIV,SDCP,SC),U,3)+1
66 ..Q:SDFMT'="D" S X1=$P(SDT,"."),X2=SDBDT D ^%DTC S SDAY=X+1
67 ..D ARRSET(SDCP,SC,SDAY) Q
68 Q
69 ;
70ARRSET(SDCP,SC,SDI) ;Set daily counts into array
71 ;Input: SDCP=credit pair
72 ;Input: SC=clinic ifn
73 ;Input: SDI=number of days from report date
74 N SDS,SDP,SDX
75 S SDS=SDI-1\12,SDP=SDI#12 S:SDP=0 SDP=12
76 S SDX=$P(^TMP("SD",$J,SDIV,SDCP,SC,SDS),U,SDP)
77 S:'$L(SDX) SDX="0~0~0"
78 S $P(SDX,"~",3)=$P(SDX,"~",3)+1
79 S $P(^TMP("SD",$J,SDIV,SDCP,SC,SDS),U,SDP)=SDX
80 Q
81 ;
82DIV(SDIV) ;Evaluate division
83 Q:'SDDIV 1 Q $D(SDDIV(SDIV))
84 ;
85CA(SORT) ;Evaluate list of clinics for selected patient
86 N SDCNAM,SC0,SDIV,XX,DFN,SDIV,SDCP,SDPNAME S SDI=0
87 F XX=1:1:$G(SDPAT) S DFN=+^TMP("SDPAT",SDJN,XX),SDPNAME=$P(^(XX),U,2) D
88 .N SDDT S SDDT=SDBDT-1+.9999999 ; DATE/TIME APPT SCHEDULED
89 .F S SDDT=$O(^DPT(DFN,"S",SDDT)) Q:'SDDT!(SDDT>SDEDT) D
90 ..S SDI=SDI+1 I SDI#10=0 D STOP Q:SDOUT
91 ..S SC=+^DPT(DFN,"S",SDDT,0),SC0=$G(^SC(SC,0)) I '$$DIV(+$P(SC0,U,15)) Q
92 ..Q:$P(SC0,U,17)="Y" ;non-count clinic
93 ..S SDIV=$$DIV^SCRPW71(SC0)
94 ..I '$$CPAIR^SCRPW71(SC0,.SDCP) Q
95 ..I $G(SORT)="CP",'$D(SORT(SDCP)) Q ;selection by credit pairs
96 ..I $G(SORT)="CL",'$D(SORT($P(SC0,U))) Q ; selection by list of clinics
97 ..I $G(SDREPORT(5)) S ^TMP("SDIPLST",$J,DFN,SC)="",^TMP("SDIP",$J,$P(SDIV,U,2),SC)=SDCP_U_$P(SDIV,U),^TMP("SDORD",$J,SDPNAME,DFN)=""
98 ..S SDX=$$CLINIC^SCRPW71(SC,SDFMT,SDBDT,SDEDT,MAX,SDPAST)
99 Q
100CL ;Evaluate list of clinics
101 N SDCNAM,SC0,SDIV S SDI=0
102 S SDCNAM="" F S SDCNAM=$O(SDSORT(SDCNAM)) Q:SDCNAM=""!SDOUT D
103 .S SDI=SDI+1 I SDI#10=0 D STOP Q:SDOUT
104 .S SC=SDSORT(SDCNAM),SC0=$G(^SC(SC,0)) Q:'$$DIV(+$P(SC0,U,15))
105 .I $G(SDREPORT(4)) S ^TMP("SDPLIST",$J,SC)=""
106 .S SDX=$$CLINIC^SCRPW71(SC,SDFMT,SDBDT,SDEDT,MAX,SDPAST)
107 .I $P(SDX,U,3)=-1 D
108 ..S SDIV=$$DIV^SCRPW71(SC0)
109 ..S:$L(SDIV) $P(^TMP("SD",$J,SDIV,SDCNAM),U,3)=$P(SDX,U,3,4) Q
110 Q
111 ;
112CP ;Evaluate list of credit pairs
113 N SDCCP,SC,SC0 S SC=0
114 F S SC=$O(^SC(SC)) Q:'SC!SDOUT D
115 .S SC0=$G(^SC(SC,0)) Q:'$$DIV(+$P(SC0,U,15))
116 .Q:'$$CPAIR^SCRPW71(SC0,.SDCCP)!'$D(SDSORT(SDCCP))
117 .I $G(SDREPORT(4)) S ^TMP("SDPLIST",$J,SC)=""
118 .S SDX=$$CLINIC^SCRPW71(SC,SDFMT,SDBDT,SDEDT,MAX,SDPAST)
119 Q
120 ;
121CNAME(SC) ;Massage clinic name
122 N SDX
123 ;Default name value
124 S SDX=$P($G(^SC(SC,0)),U) Q:'$L(SDX) "UNKNOWN"
125 ;Remove extract formatting characters
126 S SDX=$TR(SDX,"#$^~|")
127 ;Uppercase name value
128 S SDX=$TR(SDX,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
129 Q SDX
130 ;
131SORT(SDSORT) ;Gather sort values for detailed report
132 ;Input: SDSORT=sort category (pass by reference)
133 ;Output: '1' if selection(s) made, '0' otherwise
134 ; SDSORT(clinic name)=clinic ifn
135 ; (or)
136 ; SDSORT(credit pair)=credit pair
137 ;
138 N SDSX S SDSX="S"_SDSORT
139 I SDSORT="CA" Q 1
140 D @SDSX Q $D(SDSORT)>1
141 ;
142SCL ;Select clinics for detail
143 N DIC,SDQUIT S (SDQUIT,SDOUT)=0
144 S DIC="^SC(",DIC(0)="AEMQ",DIC("A")="Select CLINIC: ",DIC("S")="I $P(^(0),U,3)=""C"""
145 W ! F Q:SDOUT!SDQUIT D
146 .D ^DIC I $D(DTOUT)!$D(DUOUT) S SDOUT=1 Q
147 .I X="" S SDQUIT=1 Q
148 .I Y>0,$L($P(Y,U,2)) S SDSORT($P(Y,U,2))=+Y
149 Q
150 ;
151SCP ;Get credit pairs for detail
152 N DIR,SDQUIT S (SDQUIT,SDOUT)=0
153 S DIR(0)="NO:101000:999000:0",DIR("A")="Select clinic DSS credit pair"
154 S DIR("?",1)="Specify a six digit number that represents the primary and secondary stop"
155 S DIR("?",2)="code of clinics you wish to evaluate. For clinics that do not have a"
156 S DIR("?",3)="secondary stop code, enter ""000"" as the second half of the credit pair"
157 S DIR("?")="(eg. ""323000"")."
158 W ! F Q:SDOUT!SDQUIT D
159 .D ^DIR I $D(DTOUT)!$D(DUOUT) S SDOUT=1 Q
160 .I X="" S SDQUIT=1 Q
161 .I '$$VCP(Y) W " Invalid credit pair!" Q
162 .S SDSORT(Y)=Y
163 Q
164 ;
165VCP(Y) ;Validate credit pair
166 ;Input: Y=credit pair
167 ;Output: '1' if valid, '0' otherwise
168 Q:Y'?6N 0
169 Q:'$D(^DIC(40.7,"C",$E(Y,1,3))) 0
170 Q:$E(Y,4,6)="000" 1
171 Q:'$D(^DIC(40.7,"C",$E(Y,4,6))) 0
172 Q 1
173 ;
174STOP ;Check for stop task request
175 S:$D(ZTQUEUED) (SDOUT,ZTSTOP)=$S($$S^%ZTLOAD:1,1:0) Q
176 ;
177ADDL(SDZ) ;Format additional data
178 ;Input: SDZ=addl. data from ^TMP("SDNAVB",^J,SDCP,SC)
179 ;
180 N SDI,SDX S SDX=""
181 F SDI=1:1:7 S SDX=SDX_$S(SDI=5:"^",1:"~")_+$P(SDZ,U,SDI)
182 Q SDX
183 ;
184EXTRACT ;Gather data for extract
185 N SDBEG,SDEND,SDTIME,SDCP,SDX,SDY,SC,SCNA,SDI,SDFMT,SDOUT,SDXM,SDIOM,SDFOOT
186 N SDEXDT,MAX,X1,X2,X S SDIOM=$G(IOM,80)
187 F SDI=1,2,3 S SDREPORT(SDI)=1
188 S (SDOUT,SDCOL)=0,SDFMT="D",SDBEG=$H,SDEXDT=DT D INIT^SCRPW71
189 K ^TMP("SD",$J),^TMP("SDS",$J),^TMP("SDTMP",$J),^TMP("SDXM",$J)
190 S X1=SDEDT,X2=SDBDT D ^%DTC S MAX=X+1
191 D HINI^SCRPW76,FOOT^SCRPW77(.SDFOOT)
192 ;
193 ;Get encounter workload
194 I SDPAST D OE(SDBDT,SDEDT_.9999,MAX,1) ;encounter workload
195 ;
196 ;Get clinic availability data
197 S SC=0 F S SC=$O(^SC(SC)) Q:'SC S SC0=$G(^SC(SC,0)) D
198 .S SDX=$$CLINIC^SCRPW71(SC,SDFMT,SDBDT,SDEDT,MAX,SDPAST)
199 ;
200 ;Get next available wait times
201 S SDMD=$O(^TMP("SD",$J,"")),SDMD=$O(^TMP("SD",$J,SDMD)),SDMD=$L(SDMD)
202 I SDPAST D NAVA^SCRPW75(SDBDT,SDEDT_.9999,1) ;next ava. wait times
203 ;
204 ;Order by clinic, send extract data to Austin
205 D ORD,TXXM^SCRPW70 K ^TMP("SDXM",$J)
206 ;
207 ;Send summary bulletin to mail group
208 S SDFMT="S",SDEND=$H,SDTIME=$$TIME(SDBEG,SDEND)
209 S SDBEG=$$HTE^XLFDT(SDBEG),SDEND=$$HTE^XLFDT(SDEND)
210 S SDY="*** Clinic Appointment "_$S(SDPAST:"Utilization",1:"Availability")_" Extract ***"
211 S SDXM=1,SDX="",$E(SDX,(79-$L(SDY)\2))=SDY D XMTX^SCRPW73(SDX)
212 D XMTX^SCRPW73(" ")
213 D XMTX^SCRPW73(" For date range: "_SDPBDT_" to "_SDPEDT)
214 D XMTX^SCRPW73(" Extract start time: "_SDBEG)
215 D XMTX^SCRPW73(" Extract end time: "_SDEND)
216 D XMTX^SCRPW73(" Extract run time: "_SDTIME)
217 D XMTX^SCRPW73(" Task number: "_$G(ZTSK))
218 F SDI=1:1:4 D XMTX^SCRPW73("")
219 D PRT^SCRPW73(SDXM,1),EXXM^SCRPW70("G.SC CLINIC WAIT TIME")
220 I SDPAST F SDI=2,3 D
221 .K ^TMP("SDXM",$J) S SDXM=1
222 .D PRT^SCRPW73(SDXM,SDI),EXXM^SCRPW70("G.SC CLINIC WAIT TIME")
223 G EXIT^SCRPW74
224 ;
225TIME(SDBEG,SDEND) ;Calculate length of run time
226 ;Input: SDBEG=start time in $H format
227 ;Input: SDEND=end time in $H format
228 ;Output: text formatted string with # days, hours, minutes and seconds
229 N X,Y
230 S SDEND=$P(SDEND,",")-$P(SDBEG,",")*86400+$P(SDEND,",",2)
231 S SDBEG=$P(SDBEG,",",2),X=SDEND-SDBEG,Y("D")=X\86400
232 S X=X#86400,Y("H")=X\3600,X=X#3600,Y("M")=X\60,Y("S")=X#60
233 S Y("D")=$S('Y("D"):"",1:Y("D")_" day"_$S(Y("D")=1:"",1:"s")_", ")
234 S Y("H")=Y("H")_" hour"_$S(Y("H")=1:"",1:"s")_", "
235 S Y("M")=Y("M")_" minute"_$S(Y("M")=1:"",1:"s")_", "
236 S Y("S")=Y("S")_" second"_$S(Y("S")=1:"",1:"s")
237 Q Y("D")_Y("H")_Y("M")_Y("S")
Note: See TracBrowser for help on using the repository browser.