source: WorldVistAEHR/trunk/r/OUTPATIENT_PHARMACY-PSO-APSP-HUIP/PSOSIGTX.m@ 1742

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

initial load of WorldVistAEHR

File size: 9.5 KB
Line 
1PSOSIGTX ;BIR/RTR-Utility to calculate quantity ;6/04/00
2 ;;7.0;OUTPATIENT PHARMACY;**46**;DEC 1997
3 ;External reference to PS(51 supported by DBIA 2224
4 ;External reference to PS(51.1 supported by DBIA 2225
5 ;
6EN(PSOSIGX) ;
7 N VARIABLE
8 Q
9SCH ;SCH = schedule entered SCHEX = expanded schedule
10 N SQFLAG,SCLOOP,SCLP,SCLPS,SCLHOLD,SCIN,SODL,SST
11 K SCHEX S SQFLAG=0
12 I $G(SCH)="" S SCHEX="" Q
13 I SCH[""""!($A(SCH)=45)!(SCH?.E1C.E)!($L(SCH," ")>3)!($L(SCH)>20)!($L(SCH)<1) K SCH Q
14 F SCLOOP=0:0 S SCLOOP=$O(^PS(51.1,"B",SCH,SCLOOP)) Q:'SCLOOP!(SQFLAG) I $P($G(^PS(51.1,SCLOOP,0)),"^",8)'="" S SCHEX=$P($G(^(0)),"^",8),SQFLAG=1
15 Q:SQFLAG
16 I $P($G(^PS(51,"A",SCH)),"^")'="" S SCHEX=$P(^(SCH),"^") Q
17 S SCLOOP=0 F SCLP=1:1:$L(SCH) S SCLPS=$E(SCH,SCLP) I SCLPS=" " S SCLOOP=SCLOOP+1
18 I SCLOOP=0 S SCHEX=SCH Q
19 S SCLOOP=SCLOOP+1
20 K SCLHOLD F SCIN=1:1:SCLOOP S (SODL,SCLHOLD(SCIN))=$P(SCH," ",SCIN) D
21 .Q:$G(SODL)=""
22 .S SQFLAG=0 F SST=0:0 S SST=$O(^PS(51.1,"B",SODL,SST)) Q:'SST!($G(SQFLAG)) I $P($G(^PS(51.1,SST,0)),"^",8)'="" S SCLHOLD(SCIN)=$P($G(^(0)),"^",8),SQFLAG=1
23 .Q:$G(SQFLAG)
24 .I $P($G(^PS(51,"A",SODL)),"^")'="" S SCLHOLD(SCIN)=$P(^(SODL),"^")
25 S SCHEX="",SQFLAG=0 F SST=1:1:SCLOOP S SCHEX=SCHEX_$S($G(SQFLAG):" ",1:"")_$G(SCLHOLD(SST)),SQFLAG=1
26 Q
27QTY(PSOQX) ;
28 N QDOSE
29QTYCP ;CPRS qty call comes through here
30 N PSQQUIT,QTSH,PSQ,PSQMIN,PSQMINZ,PSOQRND,PSOLOWER,PSOLOWX,PSOLOWXL,PSOLOWST
31 K PSOFRQ S PSQQUIT=0
32 I '$G(PSOCPRQT) S QDOSE=0 F PSQ=0:0 S PSQ=$O(PSOQX("DOSE",PSQ)) Q:'PSQ S QDOSE=PSQ S:'$G(PSOQX("DOSE ORDERED",PSQ)) PSQQUIT=1
33 ;Q:PSQQUIT!('QDOSE)
34 I '$G(PSOCPRQT) Q:PSQQUIT
35 Q:'$G(PSOQX("DAYS SUPPLY"))
36 Q:'$G(QDOSE)
37 G:QDOSE>1 COMP
38TOP ;One Dose for complex and/then
39 N PSOQDUR
40 Q:'$G(PSOQX("DOSE ORDERED",PSQDOSE))
41 Q:'$G(PSOQX("DAYS SUPPLY"))&('$G(PSOQX("DURATION",PSQDOSE)))
42 S PSOLOWER=0
43 I $G(PSOQX("DURATION",PSQDOSE)) D
44 .S PSOLOWX=$L(PSOQX("DURATION",PSQDOSE))
45 .S PSOQDUR=$G(PSOQX("DURATION",PSQDOSE))
46 .S PSOLOWXL=$S($E(PSOQDUR,PSOLOWX)="M":1,$E(PSOQDUR,PSOLOWX)="H":60,$E(PSOQDUR,PSOLOWX)="S":.01666,$E(PSOQDUR,PSOLOWX)="W":10080,$E(PSOQDUR,PSOLOWX)="L":43200,1:1440)
47 .S PSOLOWER=PSOLOWXL*(+$G(PSOQX("DURATION",PSQDOSE)))
48 I $G(PSOLOWER),$G(PSOLOWER)>PSODSMXX Q
49 S PSOLOWX=$G(PSODSMXX)
50 Q:'$G(PSOLOWER)&('$G(PSOLOWX))
51 S QTSH=$G(PSOQX("SCHEDULE",PSQDOSE)) D QTS Q:PSQQUIT!('$G(PSOFRQ))
52 S PSOLOWST=$S('$G(PSOLOWER):$G(PSOLOWX),'$G(PSOLOWX):$G(PSOLOWER),$G(PSOLOWER)>$G(PSOLOWX):$G(PSOLOWX),$G(PSOLOWX)>$G(PSOLOWER):$G(PSOLOWER),$G(PSOLOWX)=$G(PSOLOWER):$G(PSOLOWER),1:0)
53 Q:'$G(PSOLOWST)
54 Q:PSOLOWST'>0
55 S PSQMIN=+$G(PSOLOWST)
56 S PSQMINZ=PSQMIN/PSOFRQ
57 S PSOQRND=PSQMINZ*+$G(PSOQX("DOSE ORDERED",PSQDOSE)) Q:'PSOQRND
58 S PSODSMXX=PSODSMXX-PSQMIN
59 Q:PSODSMXX<0
60 D ROUND G QEND
61 Q
62COMP ;COMPLEX DOSE HERE - ANDS AND THENS
63 ;N PSOQAND,PSQL,PSQMNL,PSQMNLX,PSODUTOT,PSODUDIF,PSODUMIS,PSODUREP,PSQ1,PSODUX,PSODUXX,PSODSMIN
64 ;PSODUTOT = TOTAL OF ALL DURATIONS
65 ;PSODUDIF = DIFF. OF DURATION VS DAYS SUPPLY
66 ;PSODUMIS = # OF SEQUENCES MISSING A DURATION IF >1 CAN'T DEFAULT
67 ;PSODUREP = SEQUENCE # THAT IS MISSING DURATION
68 ;PSODSMIN = MINUTES OF DAYS SUPPLY
69 ;PSODSAME = FLAG THAT TELL IF DURATIONS ARE THE SAME
70 ;PSODURT = DURATION MINUTES FOR COMPARE
71 ;S (PSODUTOT,PSODUDIF,PSODUMIS,PSODUREP,PSODSMIN,PSOQAND)=0
72 ;F PSQL=1:1:QDOSE S:$G(PSOQX("CONJUNCTION",PSQL))["A" PSOQAND=1 Q:PSOQAND
73 ;I $G(PSOQTHEN) G COMP^PSOSIGTX
74 N PSQHOLDX,PSQFLAG,PSQMINLP,PSQMINAR,PSODSMXX,PSOTFLAG,PSODSDEC,PSORNDXX,PSOATQUT,PSQDOSE,PSQDOSEX,PSOQZ,PSOQZX S (PSORNDXX,PSOATQUT,PSODSDEC,PSOTFLAG)=0,PSQDOSE=0,PSQDOSEX=QDOSE
75 I '$D(PSOQX("CONJUNCTION",PSQDOSEX)) S PSOQX("CONJUNCTION",PSQDOSEX)="A",PSOTFLAG=1
76 S (PSODSMIN,PSODSMXX)=1440*+$G(PSOQX("DAYS SUPPLY"))
77 F S PSQDOSE=$O(PSOQX("CONJUNCTION",PSQDOSE)) Q:$G(PSOATQUT)!($G(PSQDOSE)="") I $G(PSOQX("CONJUNCTION",PSQDOSE))["T"!(PSQDOSE=PSQDOSEX) S PSOATQUT=1 D
78 .;I 1 DO TOP ELSE DO BELOW, SET BEGINNIG AND END COUNTERS, USE THOSE ON LOOPS BELOW, OR THE SINGLE NUMBER FOR UP TOP (CHANGE 1'S TO NUMBERS)
79 .I '$G(PSOQZ) S PSOQZ=1
80 .I PSQDOSE-PSOQZ=0 D TOP S PSOQZ=PSQDOSE+1 Q
81 .D BOT
82 .S PSOQZ=PSQDOSE+1
83 ;SET LAST CONJUNCTION, MAKE SURE IT'S NOT PASSED IN FROM cprs
84 I $G(PSOTFLAG) K PSOQX("CONJUNCTION",PSQDOSEX)
85 I PSOATQUT K PSOQX("QTY") Q
86 I $G(PSOQX("QTY")) D ROUNDF
87 Q
88BOT ;
89 N PSODUMSS,PSODSAME,PSODURT S (PSODUMSS,PSODSAME,PSODURT,PSODUMIS,PSOQRND,PSODUTOT)=0
90 F PSQ1=PSOQZ:1:PSQDOSE D
91 .I '$G(PSOQX("DURATION",PSQ1)) S PSODUMIS=PSODUMIS+1,PSODUREP=PSQ1 Q
92 .S PSODUX=$L(PSOQX("DURATION",PSQ1))
93 .S PSODUMSS=1
94 .S PSODUXX=$S($E(PSOQX("DURATION",PSQ1),PSODUX)="M":1,$E(PSOQX("DURATION",PSQ1),PSODUX)="H":60,$E(PSOQX("DURATION",PSQ1),PSODUX)="S":.01666,$E(PSOQX("DURATION",PSQ1),PSODUX)="W":10080,$E(PSOQX("DURATION",PSQ1),PSODUX)="L":43200,1:1440)
95 .S PSODUTOT=PSODUTOT+(PSODUXX*(+$G(PSOQX("DURATION",PSQ1))))
96 .I '$G(PSODSAME),$G(PSODURT),PSODURT'=(PSODUXX*(+$G(PSOQX("DURATION",PSQ1)))) S PSODSAME=1
97 .S PSODURT=(PSODUXX*(+$G(PSOQX("DURATION",PSQ1))))
98 ;I PSODUMIS,PSODSAME G QEND ; missing durations, and other durations are all not the same
99 I '$G(PSOQX("DAYS SUPPLY")) G QEND ; missing Days Supply
100 ;S PSODSMIN=1440*+$G(PSOQX("DAYS SUPPLY"))
101 I PSODUMIS,PSODSAME G QEND ; Missing Durations, other are different
102 I 'PSODUMIS,PSODSAME,$G(PSODUTOT)>PSODSMIN G QEND ; Every sequence has a duration, some are different, and the total is greater than Days Supply
103 I 'PSODSAME,PSODURT>PSODSMIN G QEND ; All have a duration, and it's the same, but it's greater than Days Supply, or Missing Durations with other duration the same but greater than Days Supply
104 ;I $G(PSODSMIN),$G(PSODSMIN)<$G(PSODUTOT) G QEND
105 ;I '$G(PSODUMIS),$G(PSODSMIN),$G(PSODUTOT)>$G(PSODSMIN) G QEND ; no missing durations, but total durations are greater than days supply
106 ;I $G(PSODUMIS),$G(PSODSMIN),$G(PSODSMIN)'>$G(PSODUTOT) G QEND ; 1 missing duration, and total of other durations are not less than days supply
107 ;I '$G(PSODSMIN),$G(PSODUMIS) G QEND ; no days supply, m;issing a duration
108 I $G(PSODUMIS),PSODUMSS S PSODUDIF=$G(PSODSMIN)-$G(PSODUTOT)
109 K PSQMINAR F PSQ=PSOQZ:1:PSQDOSE D Q:$G(PSQQUIT)
110 .I '$G(PSOQX("DOSE ORDERED",PSQ))!($G(PSOQX("SCHEDULE",PSQ))="") S PSQQUIT=1 Q
111 .S QTSH=$G(PSOQX("SCHEDULE",PSQ)) D QTS S:'$G(PSOFRQ) PSQQUIT=1 Q:$G(PSQQUIT)
112 .I $G(PSOQX("DURATION",PSQ)) S PSQMNL=$L(PSOQX("DURATION",PSQ)) D
113 ..S PSQMNLX=$S($E(PSOQX("DURATION",PSQ),PSQMNL)="M":1,$E(PSOQX("DURATION",PSQ),PSQMNL)="H":60,$E(PSOQX("DURATION",PSQ),PSQMNL)="S":.01666,$E(PSOQX("DURATION",PSQ),PSQMNL)="W":10080,$E(PSOQX("DURATION",PSQ),PSQMNL)="L":43200,1:1440)
114 ..S PSQMIN=PSQMNLX*(+$G(PSOQX("DURATION",PSQ)))
115 ..I $G(PSQMIN) S PSQMINAR(PSQ)=PSQMIN
116 .I '$G(PSOQX("DURATION",PSQ)) S PSQMIN=$S($G(PSODURT)&('$G(PSODSAME)):$G(PSODURT),1:$G(PSODSMXX)) I PSQMIN S PSQMINAR(PSQ)=PSQMIN
117 .S PSQMINZ=PSQMIN/PSOFRQ
118 .S PSOQRND=$S('$G(PSOQRND):PSQMINZ*+$G(PSOQX("DOSE ORDERED",PSQ)),1:$G(PSOQRND)+(PSQMINZ*+$G(PSOQX("DOSE ORDERED",PSQ))))
119 .;S PSODSMXX=PSODSMXX-PSQMIN
120 S (PSQFLAG,PSQHOLDX)=0 S PSQMINLP="" F S PSQMINLP=$O(PSQMINAR(PSQMINLP)) Q:PSQMINLP="" S:$G(PSQHOLDX)&($G(PSQHOLDX)'=$G(PSQMINAR(PSQMINLP))) PSQFLAG=1 S PSQHOLDX=$G(PSQMINAR(PSQMINLP))
121 I $G(PSQFLAG) S PSQMINLP="" F S PSQMINLP=$O(PSQMINAR(PSQMINLP)) Q:PSQMINLP="" I $G(PSQMINAR(PSQMINLP)) S PSODSMXX=PSODSMXX-PSQMINAR(PSQMINLP)
122 I '$G(PSQFLAG) S PSQMINLP="" F S PSQMINLP=$O(PSQMINAR(PSQMINLP)) Q:PSQMINLP=""!($G(PSQFLAG)) I $G(PSQMINAR(PSQMINLP)) S PSODSMXX=PSODSMXX-PSQMINAR(PSQMINLP),PSQFLAG=1
123 K PSQMINAR,PSQFLAG
124 I PSODSMXX<0 G QEND
125 I $G(PSQQUIT) G QEND
126 I $G(PSOQRND) D ROUND
127 G QEND
128QTS ;Find frequency
129 ;QTSH = SHCEDULE
130 ;either return PSOFRQ for frequency or PSSQUIT for no frequency
131 N SQTFLAG,SQQT,ZZQT,ZZQ,ZZQQ,ZQHOLD,QGLFLAG,PZQT,ZDL,ZZQX
132 K PSOFRQ
133 S (QGLFLAG,ZZQX)=0
134 I $G(QTSH)="" S PSQQUIT=1 Q
135 S SQTFLAG=0 F SQQT=0:0 S SQQT=$O(^PS(51.1,"B",QTSH,SQQT)) Q:'SQQT!($G(SQTFLAG)) I $P($G(^PS(51.1,SQQT,0)),"^",3) S PSOFRQ=$P($G(^(0)),"^",3),SQTFLAG=1
136 Q:SQTFLAG
137 F SQQT=0:0 S SQQT=$O(^PS(51,"B",QTSH,SQQT)) Q:'SQQT!($G(SQTFLAG)) I $P($G(^PS(51,SQQT,0)),"^",8) S PSOFRQ=$P($G(^(0)),"^",8),SQTFLAG=1
138 Q:SQTFLAG
139 S ZZQT=0 F ZZQ=1:1:$L(QTSH) S ZZQQ=$E(QTSH,ZZQ) I ZZQQ=" " S ZZQT=ZZQT+1
140 I 'ZZQT S PSQQUIT=1 Q
141 S ZZQT=ZZQT+1
142 K ZQHOLD S QGLFLAG=0 F PZQT=1:1:ZZQT S (ZDL,ZQHOLD)=$P(QTSH," ",PZQT) D
143 .Q:$G(ZDL)=""
144 .S ZZQX=0 F SQQT=0:0 S SQQT=$O(^PS(51.1,"B",ZDL,SQQT)) Q:'SQQT!($G(ZZQX)) I $P($G(^PS(51.1,SQQT,0)),"^",3) S PSOFRQ=$P($G(^(0)),"^",3),ZZQX=1,QGLFLAG=QGLFLAG+1
145 .Q:ZZQX
146 .S ZZQX=0 F SQQT=0:0 S SQQT=$O(^PS(51,"B",ZDL,SQQT)) Q:'SQQT!($G(ZZQX)) I $P($G(^PS(51,SQQT,0)),"^",8) S PSOFRQ=$P($G(^(0)),"^",8),ZZQX=1,QGLFLAG=QGLFLAG+1
147 I $G(QGLFLAG)>1 K PSOFRQ
148 I '$G(PSOFRQ) S PSQQUIT=1
149 Q
150QEND ;
151 K PSOFRQ
152 Q
153ROUND ;
154 Q:'$G(PSOQRND)
155 S PSOQX("QTY")=$G(PSOQX("QTY"))+$G(PSOQRND)
156 S PSOATQUT=0
157 Q
158ROUNDF ;
159 I PSOQX("QTY")'["." Q
160 S PSOQX("QTY")=$P(PSOQX("QTY"),".")+1
161 Q
162DAY(DATE) ;First 5 digits of FileMan date
163 N X
164 I DATE'?5N Q -1
165 S X=$E(DATE,4,5) I X<1!(X>12) Q -1
166 S X=DATE+1+(X=12*88)_"01"
167 Q $E($$FMADD^XLFDT(X,-1),6,7)
168 ;
169QTYX(PSOQX) ;
170 N PSOQLP,PSOQLN,PSOQAR,PSOCPRQT,QDOSE,QDOSEX S PSOCPRQT=1 F PSOQLP=0:0 S PSOQLP=$O(PSOQX("DURATION",PSOQLP)) Q:'PSOQLP D
171 .S PSOQAR("DURATION",PSOQLP)=$G(PSOQX("DURATION",PSOQLP))
172 .I $E(PSOQX("DURATION",PSOQLP))?1A S PSOQLN=$L(PSOQX("DURATION",PSOQLP)) S PSOQX("DURATION",PSOQLP)=$E(PSOQX("DURATION",PSOQLP),2,PSOQLN)_$E(PSOQX("DURATION",PSOQLP))
173 S QDOSE=0 F QDOSEX=0:0 S QDOSEX=$O(PSOQX("DOSE ORDERED",QDOSEX)) Q:'QDOSEX S QDOSE=QDOSE+1
174 I '$G(PSOQX("QTY")) D QTYCP G QPASS
175 D QTYCP^PSOSIGDS
176QPASS F PSOQLP=0:0 S PSOQLP=$O(PSOQAR("DURATION",PSOQLP)) Q:'PSOQLP D
177 .S PSOQX("DURATION",PSOQLP)=$G(PSOQAR("DURATION",PSOQLP))
178 K PSOCPRQT
179 Q
180DAYS(PSOQX) ;Entry point for Days Supply calc for PSO
181 ;Kill days supply here
182 Q:'$G(PSOQX("QTY"))
183 D QTYOPS^PSOSIGDS
184 Q
Note: See TracBrowser for help on using the repository browser.