source: WorldVistAEHR/trunk/r/OUTPATIENT_PHARMACY-PSO-APSP-HUIP/PSOTPCLP.m@ 1144

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

initial load of WorldVistAEHR

File size: 8.2 KB
Line 
1PSOTPCLP ;BIRM/PDW-PRINT PATIENT LETTERS ;AUG 5,2003
2 ;;7.0;OUTPATIENT PHARMACY;**145,227,233**;DEC 1997;Build 8
3 Q
4PRINT ; select options
5 Q ;placed out of order by patch PSO*7*227
6 K ^TMP($J,"TPBLET"),TMP($J,"TPCLW")
7 D EXIT ;INITIALIZE
8 ;build INST to show incompleted Institutions
9 K INST S DIVDA=0 F S DIVDA=$O(^PS(52.92,DIVDA)) Q:DIVDA'>0 D
10 . S INST(DIVDA)=$$GET1^DIQ(52.92,DIVDA,.01)
11 S XX=$$INSTCHK^PSOTPCL I $G(PSOSTOP) Q
12 K INST S DIVDA=0 F S DIVDA=$O(^PS(52.92,DIVDA)) Q:DIVDA'>0 D
13 . Q:$$CHKINST^PSOTPCL(DIVDA)
14 . S INST(DIVDA)=$$GET1^DIQ(52.92,DIVDA,.01)
15 K PARAM,PATLST
16 K DIR S DIR(0)="SO^A:Print all letters that have not printed;P:Print letter by a patient or multiple patients;I:Print by institution (all, one, or a selection)" D ^DIR
17 I Y="A" S PARAM("SORT")="I",PATLST="",PARAM("LP")="N" G DEVICE
18 I Y="P" G PATIENT
19 I Y="I" G DIVISION
20 W !,"None Selected - Quitting",! H 3
21 G EXIT
22PATIENT ; print by patients
23 S PARAM("SORT")="P",PARAM("LP")="B"
24 D PATSEL ; build PATLST("patient name")=DFN
25 G:($D(PATLST)<10) EXIT
26 G DEVICE
27DIVISION ;print by division
28 K DIR S DIR(0)="SO^N:Letters NOT Printed;P:Letters Printed;B:Both"
29 D ^DIR Q:"NPB"'[Y
30 S PARAM("LP")=Y
31 S PARAM("SORT")="I"
32 K INST D SEL^PSOTPCL
33 I ($D(INST)<10) W !,"No Selection Made - Quitting",! H 3 G EXIT
34 G DEVICE
35PATSEL ; Select one or more patients
36 K PATLST
37 S DIC="^PS(52.91,",DIC(0)="AEQM",DIC("W")="D DSPPAT^PSOTPCLP(+Y)"
38 F S DIC("W")="D DSPPAT^PSOTPCLP(+Y)" D ^DIC Q:Y'>0 S DFN=+Y,PTNM=$$GET1^DIQ(52.91,DFN,.01),PATLST(PTNM,DFN)="" D
39 . ;test death date
40 . S XX=$$GET1^DIQ(2,DFN,.351) I XX'="" D Q
41 .. W !!,"Sorry, ",PTNM," died ",XX,!
42 .. K PATLST(PTNM,DFN) H 3
43 . ;test expired date
44 . S EXPDTI=$$GET1^DIQ(52.91,DFN,2,"I")
45 . I EXPDTI,DT>EXPDTI D
46 .. S EXPDT=$$GET1^DIQ(52.91,+DFN,2)
47 .. W !,"Sorry, ",PTNM,"'s eligibility expired ",EXPDT,! K PATLST(PTNM,DFN)
48 . ;check divisions required data
49 . S DIVDA=$$GET1^DIQ(52.91,DFN,7,"I")
50 . S XX=$$CHKINST^PSOTPCL(DIVDA) I XX D
51 .. W !!,"Sorry, ",$$GET1^DIQ(52.91,DFN,7)," is missing required fields.",!!
52 .. K PATLST(PTNM,DFN)
53 ;
54LST I ($D(PATLST)<10) W !,"No Patients Selected - Quitting",! H 3 S PATLST="" Q
55 W !!,"You have selected:",!
56 S PATNM="" F I=1:1 S PATNM=$O(PATLST(PATNM)) Q:'$L(PATNM) S DFN=0 F S DFN=$O(PATLST(PATNM,DFN)) Q:DFN'>0 W !,PATNM D DSPPAT(DFN) I '(I#20) D D ^DIR I X["^" Q
57 .K DIR S DIR(0)="E",DIR("A")="<cr> - Continue ""^"" - Stop Display"
58 ;
59 W ! K DIR S DIR(0)="Y",DIR("A")="Is the above correct ",DIR("B")="YES" D ^DIR
60 I 'Y G PATSEL
61 Q
62DSPPAT(DFN) ; Display Division and expire date
63 N DIVNM,EXPDT,PRTDT
64 S DIVNM=$$GET1^DIQ(52.91,DFN,7) W ?32,$E(DIVNM,1,15)
65 S EXPDT=$$GET1^DIQ(52.91,DFN,2,"I")
66 I EXPDT S EXPDT=$$FMTE^XLFDT(EXPDT,"2D") W ?50,"Inact ",EXPDT
67 S PRTDT=$$GET1^DIQ(52.91,DFN,11,"I")
68 I PRTDT S PRTDT=$$FMTE^XLFDT(PRTDT,"2D") W ?66,"Prt ",PRTDT
69 Q
70DEVICE ;
71 W !,"Queueing is recommended",!
72 S %ZIS="Q" D ^%ZIS
73 Q:POP
74 I $D(IO("Q")) D K ZTSK G EXIT
75 . S (PATLST,INST,PARAM)=""
76 . S ZTRTN="DEQUE^PSOTPCLP",ZTDESC="TPB PRINT PATIENT LETTERS"
77 . F XX="PATLST*","INST*","PARAM*" S ZTSAVE(XX)=""
78 . ;W ! ZW ZTRTN,ZTDESC,PATLST,INST,PARAM,ZTSAVE
79 . D ^%ZTLOAD
80 . I $G(ZTSK) W !!,"Tasked with "_ZTSK
81 ; (code falls through if not queued)
82DEQUE ; DEQUE/PRINT LETTERS
83 K ^TMP($J,"TPBLET")
84 I PARAM("SORT")="P" G SORTPAT
85 S DIVDA=0 F S DIVDA=$O(INST(DIVDA)) Q:DIVDA'>0 D
86 . S DFN=0 F S DFN=$O(^PS(52.91,"AC",DIVDA,DFN)) Q:DFN'>0 D
87 .. S PTNM=$$GET1^DIQ(52.91,DFN,.01)
88 .. S EXPDTI=$P(^PS(52.91,DFN,0),"^",3),LTPDTI=$P(^(0),"^",12)
89 .. Q:EXPDTI
90 .. Q:$L($$GET1^DIQ(2,DFN,.351))
91 .. I PARAM("LP")="N",LTPDTI Q
92 .. I PARAM("LP")="P",'LTPDTI Q
93 .. S ^TMP($J,"TPBLET",DIVDA,PTNM,DFN)=""
94 G PRTLET
95SORTPAT ; sort by patient
96 K ^TMP($J,"TPBLET")
97 S PTNM="" F S PTNM=$O(PATLST(PTNM)) Q:PTNM="" D
98 . S DFN=0 F S DFN=$O(PATLST(PTNM,DFN)) Q:DFN'>0 D
99 .. S DA0=^PS(52.91,DFN,0),EXPDTI=$P(DA0,"^",3),LTPDTI=$P(DA0,"^",12),DIVDA=$P(DA0,"^",8)
100 .. Q:EXPDTI
101 .. I PARAM("LP")="N",LTPDTI Q
102 .. I PARAM("LP")="P",'LTPDTI Q
103 .. S ^TMP($J,"TPBLET",DIVDA,PTNM,DFN)=""
104 G PRTLET
105 Q
106PRTLET ; pull DIVDAs and DFNs from ^TMP($J,"TPBLET",
107 D LOADTMP^PSOTPCLW ; load letter body into TMP
108 K DIVCNT
109 S DIVDA=0 F S DIVDA=$O(^TMP($J,"TPBLET",DIVDA)) Q:DIVDA'>0 D
110 . S XX=$$CHKINST^PSOTPCL(DIVDA) I XX S DIVCNT(DIVDA)=0 Q
111 . D DIV ;GETDIV(DIVDA) ;load institution/parent data for print
112 . S PTNM="" F S PTNM=$O(^TMP($J,"TPBLET",DIVDA,PTNM)) Q:PTNM="" D
113 .. S DFN=0
114 .. F S DFN=$O(^TMP($J,"TPBLET",DIVDA,PTNM,DFN)) Q:DFN'>0 D
115 ... S DIVCNT(DIVDA)=$G(DIVCNT(DIVDA))+1
116 ... D LETTER(DFN)
117 ... S $P(^PS(52.91,DFN,0),U,12)=DT ;set print date
118 ; summary of printing
119 S Y=DT D D^DIQ S SRDT=Y
120 W @IOF,!!,?10,"SUMMARY of TPB LETTER PRINTING ",SRDT
121 W !!
122 I '$D(DIVCNT) W !!,"NO DATA TO PRINT",!! G EXIT
123 S DIVDA=0 F S DIVDA=$O(DIVCNT(DIVDA)) Q:DIVDA'>0 D
124 . W !,?5,$$GET1^DIQ(52.92,DIVDA,.01),?40,DIVCNT(DIVDA)
125 W !
126 G EXIT
127 ;
128LETTER(DFN) ; print letter , division variables information must be present
129 U IO
130 D GETPAT(DFN)
131 I EXPDT,EXPDT'>DT Q ; patient inactive on printing date
132 D HEADER
133 F LN=1:1 Q:'$D(^TMP($J,"TPCLW","P1",LN)) W !,^(LN)
134 W ?30,"PHARMACY SERVICE",!,?30,DIVNM
135 I $L(MADD1) D I 1
136 . W !,?30,MADD1
137 . W:$L(MADD2) !,?30,MADD2
138 . W !,?30,MCITY,", ",MSTATE," ",MZIP
139 E W !,?30,ADD1 D
140 . W:$L(ADD2) !,?30,ADD2
141 . W !,?30,CITY,", ",STATE," ",ZIP
142 F LN=1:1 Q:'$D(^TMP($J,"TPCLW","P2",LN)) W !,^(LN)
143 W " ",PHN1 W:$L(PHN2) ", or ",PHN2 W ".",!
144 F LN=1:1 Q:'$D(^TMP($J,"TPCLW","P3",LN)) W:LN>1 ! W ^(LN)
145 W !!!!,?4,SIG1 W:$L(SIG2) !,?4,SIG2 W:$L(SIG3) !,?4,SIG3
146 W !
147 Q
148GETPAT(DFN) ;GET PATIENT DATA
149 K PTNM,EXPDT,SRANAME,TITLE,SRNM,PTSTATE,VADM,VAPA
150 S PTNM=$$GET1^DIQ(52.91,DFN,.01),EXPDT=$$GET1^DIQ(52.91,DFN,2,"I")
151 ;I EXPDT,DT'>EXPDT Q
152 D DEM^VADPT,ADD^VADPT
153 S PTLNM=$P(PTNM,","),PTXNM=$P(PTNM,",")
154 S SRANAME=$P(VADM(1),"^"),X=$P(SRANAME,","),Y=$E(X)_$TR($E(X,2,$L(X)),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")
155 S TITLE=$S($P(VADM(5),"^")="F":"Ms. ",1:"Mr. "),SRANAME=TITLE_Y
156 S Y=DT D D^DIQ S SRDT=Y
157 S SEX=$P(VADM(5),"^")
158 S SRNM=$P(VADM(1),",",2)_" "_$P(VADM(1),",")
159 S PADD1=$G(VAPA(1)),PADD2=$G(VAPA(2)),PADD3=$G(VAPA(3))
160 S PCITY=$G(VAPA(4)),PTSTATE=$P($G(VAPA(5)),U,2),PZIP=$G(VAPA(6))
161 N PSOBADR,PSOTEMP
162 S PSOBADR=$$BADADR^DGUTL3(DFN) I PSOBADR S PSOTEMP=$$CHKTEMP^PSOBAI(DFN) D
163 .I 'PSOTEMP S PADD1="** BAD ADDRESS INDICATED **",PADD2="",PADD3="",PCITY="",PSTATE="",PZIP=""
164CCADD ; Get Confidential Correspondence Address if one is active
165 ; and has the category "all other".
166 ;
167 ; See if CC address exists
168 I '$G(VAPA(12)) Q
169 ; code to check the CC category in the variable array VAPA(22)
170 ; check catagories
171 S XX=0 F CC=1,2,5 I $P($G(VAPA(22,CC)),U,3)="Y" S XX=1
172 Q:'XX
173 S SRCCADD=1
174 S:$G(VAPA(17)) PTSTATE=$P(^DIC(5,$P(VAPA(17),"^"),0),"^",2)
175 S PADD1=$G(VAPA(13)),PADD2=$G(VAPA(14)),PADD3=$G(VAPA(15))
176 S PCITY=$G(VAPA(16)),PTSTAT=$P(VAPA(17),U,2),PZIP=$P(VAPA(18),U,2)
177 Q
178HEADER ; print letter header
179 U IO
180 W @IOF
181 W !!,?(80-$L(DIVNM))\2,DIVNM
182 W !,?(80-$L(ADD1))\2,ADD1
183 W:$L(ADD2) !,?(80-$L(ADD2))\2,ADD2
184 S XX=CITY_", "_STATE_" "_ZIP
185 W !,?(80-$L(XX))\2,XX
186 F Y=$Y:1:10 W !
187 W !,?4,SRNM,?65,SRDT,!,?4,PADD1 I PADD2'="" W !,?4,PADD2 I PADD3'="" W !,?4,VAPA(3)
188 W:PCITY'="" !,?4,PCITY_", "_PTSTATE_" "_PZIP W !!!
189 Q
190DIV D GETDIV(DIVDA)
191 I $L(PARDIV) S DIVDA2=$$GET1^DIQ(52.92,DIVDA,.02,"I") D GETDIV(DIVDA2)
192 Q
193GETDIV(DIVDA) ; GET DIVISIONAL DATA
194 K DIVNM,PARDIV,PHN1,PHN2,ADD1,ADD2,CITY,ZIP,STATE,MADD1,MADD2,MCITY,MZIP,SIG1,SIG2,SIG3
195 ;
196 F FLDX="DIVNM^.01","PARDIV^.02","PHN1^.03","PHN2^.04","ADD1^.05","ADD2^.06","CITY^.07","ZIP^.08","STATE^.09" D GET1(52.92,DIVDA,FLDX)
197 ;
198 F FLDX="MADD1^1.01","MADD2^1.02","MCITY^1.03","MSTATE^1.04","MZIP^1.05","SIG1^2.01","SIG2^2.02","SIG3^2.03" D GET1(52.92,DIVDA,FLDX)
199 ;
200 Q
201GET1(FILE,FLIEN,FLDX) ; "Variable^FLD" load variable = FILE,FLD
202 N VAR S VAR=$P(FLDX,"^"),FLD=$P(FLDX,"^",2),@VAR=$$GET1^DIQ(FILE,FLIEN,FLD)
203 Q
204EXIT ;
205 D ^%ZISC
206 I $G(ZTSK) D KILL^%ZTLOAD
207 K ADD1,ADD2,CHK,CITY,DIV,DIVCNT,DIVDA,DIVDA2,DIVNM,DIVX
208 K EXPDT,EXPDTI,FAC,FDA,FLD,FLDX,FILE,FLD,FLDX,FLIEN
209 K I,INST,LN,LOCDA,LTPDTI,MADD1,MADD2,MCITY,MZIP,PAR,PARAM
210 K PARDIV,PATLST,PATNM,PHN1,PHN2,POP,PRTDT,PSOSTOP,PTLNM,PTNM
211 K PTSTATE,PTXNM,SEX,SIG1,SIG2,SIG3,SRNAME,SRDT,STATE,TITLE
212 K VADM,VAPA,VAR,XFLD,XX,YFLD,YY,ZIP,ZTDESC
213 K ^TMP($J,"TPBLET"),^TMP($J,"TPCLW")
214 Q
215LOAD K PATLST S DFN=0 F S DFN=$O(^PS(52.91,DFN)) Q:DFN'>0 S PATLST($$GET1^DIQ(52.91,DFN,.01))=DFN
216 Q
Note: See TracBrowser for help on using the repository browser.