source: FOIAVistA/trunk/r/INPATIENT_MEDICATIONS-PSJ-PSIV-PSG--PSGW/PSGMAR0.m@ 1169

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

initial load of FOIAVistA 6/30/08 version

File size: 9.1 KB
Line 
1PSGMAR0 ;BIR/CML3-GATHERS INFO FOR 24 HOUR MAR ;14 Oct 98 / 4:28 PM
2 ;;5.0; INPATIENT MEDICATIONS ;**8,15,20,111,145**;16 DEC 97;Build 17
3 ;
4 ; Reference to ^PS(55 supported by DBIA #2191.
5 ; Reference to ^PS(59.7 supported by DBIA #2181.
6 ; Reference to CUR^FHORD7 supported by DBIA #2019.
7ENQ ;
8 S PSGMSORT=$P($G(^PS(59.7,1,26)),U,4)
9 K ^TMP($J) D NOW^%DTC S PSGDT=%,PSGMARWN="",PSJACNWP=1 D @("G"_PSGSS) I $D(^TMP($J))<10 U IO W:$Y @IOF W !!,"(No data found for 24 hour MAR run.)"
10 ;
11 ;
12DONE ;
13 K PSGMFOR
14 Q
15 ;
16GG ; find individual wards in this ward group
17 F PSGMARWD=0:0 S PSGMARWD=$O(^PS(57.5,"AC",PSGMARWG,PSGMARWD)) Q:'PSGMARWD D GW
18 Q
19 ;
20GW ; find patients in each ward
21 I $D(^DIC(42,PSGMARWD,0)),$P(^(0),"^")]"" S PSGMARWN=$P(^(0),"^")
22 E Q
23 ;
24 I 'PSGMARWG S PSGMARWG=+$O(^PS(57.5,"AB",PSGMARWD,0))
25 F PSGP=0:0 S PSGP=$O(^DPT("CN",PSGMARWN,PSGP)) Q:'PSGP D PSJAC2^PSJAC(1),DTSET:'$P(PSGMARDT,".",2) D GPI
26 Q
27 ;
28GP ; go thru selected patients
29 F PSGP=0:0 S PSGP=$O(PSGPAT(PSGP)) Q:'PSGP D PSJAC2^PSJAC(1),DTSET:'$P(PSGMARDT,".",2) D GPI
30 Q
31 ;
32GL S CL="" F S CL=$O(^PS(57.8,"AD",CG,CL)) Q:CL="" D GC
33 Q
34GC S PSGAPWDN=$S($D(^SC(CL,0)):$P(^(0),"^"),1:"")
35 D DTSET:'$P(PSGMARDT,".",2)
36 ;DEM 04/19/2006 - PSGCAD = User selected start date/time minus .0001
37 S PSGCAD=PSGPLS-.0001
38 F S PSGCAD=$O(^PS(55,"AIVC",PSGCAD)) Q:PSGCAD="" D ;DEM 04/19/2006 - Index by order stop date/time.
39 . S PSGP=0
40 . F S PSGP=$O(^PS(55,"AIVC",PSGCAD,CL,PSGP)) Q:PSGP="" D PSJAC2^PSJAC(1),DTSET:'$P(PSGMARDT,".",2) D GPI ;DEM 04/19/2006 - Removed S PSJPWDN="C!"_CL D GPI. Want to rollup patients non-clinic orders under patients location.
41 ;DEM 04/19/2006 - PSGCAD = User selected start date/time minus .0001
42 S PSGCAD=PSGPLS-.0001
43 F S PSGCAD=$O(^PS(55,"AUDC",PSGCAD)) Q:PSGCAD="" D ;DEM 04/19/2006 - Index by order stop date/time.
44 . S PSGP=0
45 . F S PSGP=$O(^PS(55,"AUDC",PSGCAD,CL,PSGP)) Q:PSGP="" D PSJAC2^PSJAC(1),DTSET:'$P(PSGMARDT,".",2) D GPI ;DEM 04/19/2006 - Removed S PSJPWDN="C!"_CL D GPI. Want to rollup patients non-clinic orders under patients location.
46 Q
47GPI ; get patient info
48 ; PSGTMALL=1(sort by all team), PSGTM=1(individual team(S) selected).
49 S TM="" S:PSGSS="P"!(PSGSS="C")!(PSGSS="L") PSGMARWN=$S(PSJPWDN]"":PSJPWDN,1:"NOT FOUND")
50 S:PSJPRB="" PSJPRB="zz"
51 S:"GPCL"[PSGSS!('$G(PSGTM)&'$G(PSGTMALL)) TM="zz"
52 S:$G(TM)="" TM=$S(PSJPRB="zz":0,1:+$O(^PS(57.7,"AWRT",PSGMARWD,PSJPRB,0))),TM=$S('TM:"zz",'$D(^PS(57.7,PSGMARWD,1,TM,0)):TM,$P(^(0),"^")]"":$P(^(0),"^"),1:TM)
53 Q:'$G(PSGTMALL)&$G(PSGTM)&'$D(PSGTM(TM))
54 S PPN=$E($P(PSGP(0),"^"),1,15)_"^"_PSGP
55 N SUB1,SUB2 S:PSGRBPPN="P" SUB1=PPN,SUB2=PSJPRB S:PSGRBPPN="R" SUB1=PSJPRB,SUB2=PPN
56 I PSGMARB=1 D SPN Q
57 I PSGMTYPE[1 F XTYPE=2:1:6 D @XTYPE
58 I PSGMTYPE'[1 F XTYPE=2:1:6 D:PSGMTYPE[XTYPE @XTYPE
59 N PSGMAR24 ;DEM 04/19/2006 - 24 Hour MAR flag for call to shared routine ^PSGMMAR5 (24 Hour MAR Reports and 7 Day/14 Day MAR Reports both call ^PSGMMAR5).
60 S PSGMAR24=1
61 D ^PSGMMAR5
62 K PSGMAR24
63 D:$S(PSGSS["P"!(PSGSS="C")!(PSGSS="L"):$D(^TMP($J,PPN)),1:$D(^TMP($J,TM,PSGMARWN,SUB1,SUB2))) SPN
64 Q
65 ;
662 ;Loop thru UD orders
67 ;DEM 04/19/2006
68 ; Location variable PSGMARWC added to correctly rollup orders
69 ; under location. The location can change if the UD order is
70 ; assoicated with a clinic location. If the location changes
71 ; under the aforementioned scenario, then PSGMARWC preserves
72 ; the original value and is used to restore location to it's
73 ; original value.
74 ;
75 N PSGMARWC
76 S PSGMARWC=PSGMARWN ;DEM 04/19/2006 - Preserve original value of patients location. If location is changed, then restore to original value after call to ORSET.
77 F PST="C","O","OC","P","R" F PSGMARED=PSGPLS-.0001:0 S PSGMARED=$O(^PS(55,PSGP,5,"AU",PST,PSGMARED)) Q:'PSGMARED F PSGMARO=0:0 S PSGMARO=$O(^PS(55,PSGP,5,"AU",PST,PSGMARED,PSGMARO)) Q:'PSGMARO D ORSET S:PSGMARWN'=PSGMARWC PSGMARWN=PSGMARWC
78 S PST="S" D ^PSGMIV
79 Q
803 ;Loop thru IV orders that are Piggy back and Syringes types.
81 F PST="P","S" D ^PSGMIV
82 Q
834 ;Loop thru IV orders(Additives).
84 S PST="A" D ^PSGMIV
85 Q
865 ;Loop thru IV orders(Hyperal).
87 S PST="H" D ^PSGMIV
88 Q
896 ;Loop thru IV order(Chemo).
90 S PST="C" D ^PSGMIV
91 Q
92 ;
93 ; PSGMFOR is set to bypass "fill on request" when call ^PSGPL0.
94ORSET ; order record set
95 S PSGMFOR="",ND2=$G(^PS(55,PSGP,5,PSGMARO,2)),(SD,X)=$P($P(ND2,"^",2),".") Q:X>PSGPLF S FD=$P($P(ND2,"^",4),"."),T=$P(ND2,"^",6)
96 ;
97 S A=$G(^PS(55,PSGP,5,PSGMARO,8)) I $P(A,"^")]"" S PSGMARWN="C!"_$P(A,"^") I $G(SUB1)]"",$G(SUB2)]"",'$D(^TMP($J,TM,PSGMARWN,SUB1,SUB2)) D SPN
98 ;
99 NEW MARX D DRGDISP^PSJLMUT1(PSGP,+PSGMARO_"U",20,0,.MARX,1)
100 S DRG=MARX(1)_U_PSGMARO_"U",QST=$S(PST="C"!(PST="O"):PST,PST="OC":"OA",PST="P":"OP",$P(ND2,"^")["PRN":"OR",1:"CR")
101 ;
102 S X="" I "OB"]QST,$P(ND2,U)'["@",$P(ND2,U,2)'>PSGPLS,$P(ND2,U,4)'<PSGPLF,$P(ND2,U,5),$P(ND2,U,6)<1441,$P(ND2,U,6)'="D" S X=$P(ND2,U,5),PSGPLC=1
103 E I "OB"]QST S PSGPLO=PSGMARO K PSGMAR D ^PSGPL0 S (Q,X)="" F QX=0:0 S Q=$O(PSGMAR(Q)) Q:Q="" S X=X_$E("0",2-$L(Q))_Q_"-"
104 S X=$S(QST["C"!(QST["O"):$P(ND2,"^",5),1:"")_"^"_X
105 ;
106 ;
107 ;DAM 5-01-07 Add next line to include non-IV meds when printing by PATIENT and choosing to print "ALL MEDS"
108 I PSGSS="P" S ^TMP($J,PPN,PSGMARWN,$S(+PSGMSORT:$E(QST,1),1:QST),DRG)=X Q
109 ;
110 ;DAM 5-01-07 Add check to see if user wants to include ward orders when printing by CLINIC GROUP
111 I PSGSS="L" Q:((PSGINWDG="")&(PSGMARWN'["C!")) S ^TMP($J,PPN,PSGMARWN,$S(+PSGMSORT:$E(QST,1),1:QST),DRG)=X Q
112 ;
113 ;DAM 5-01-07 Add check to see if user wants to include ward orders when printing by CLINIC
114 I PSGSS="C" Q:((PSGINWD="")&(PSGMARWN'["C!")) I ((PSGMARWN[PSGCLNC)!(PSGMARWN'["C!")) D Q
115 . S ^TMP($J,PPN,PSGMARWN,$S(+PSGMSORT:$E(QST,1),1:QST),DRG)=X
116 Q:(PSGSS="L")!(PSGSS="C")
117 ;
118 ; DAM 5-01-07 Add check to see if user wants to include clinic orders when printing by WARD GROUP
119 I PSGSS="G" Q:((PSGINCLG="")&(PSGMARWN["C!")) S ^TMP($J,TM,PSGMARWN,SUB1,SUB2,$S(+PSGMSORT:$E(QST,1),1:QST),DRG)=X
120 ;
121 ;DAM 5-01-07 Add check to see if user wants to include clinic orders when printing by WARD.
122 I (PSGSS="W") Q:((PSGINCL="")&(PSGMARWN["C!")) S ^TMP($J,TM,PSGMARWN,SUB1,SUB2,$S(+PSGMSORT:$E(QST,1),1:QST),DRG)=X
123 ;
124 ;DAM 5-01-07 Add an XTMP global to swap location and patient name in the subscripts when printing MAR by WARD/PATIENT or WARD GROUP.
125 N PSGDEM S PSGDEM=X ;transfer contents of patient drug information contained in "X" above to a new variable temporarily
126 S PSGREP="PSGM_"_$J
127 S X1=DT,X2=1 D C^%DTC K %,%H,%T
128 S ^XTMP(PSGREP,0)=X_U_DT
129 I PSGRBPPN="P",PSGSS="W" Q:((PSGINCL="")&(PSGMARWN["C!")) D ;Construct XTMP global for printing by WARD
130 . S ^XTMP(PSGREP,TM,SUB1,PSGMARWN,SUB2,$S(+PSGMSORT:$E(QST,1),1:QST),DRG)=PSGDEM
131 I PSGRBPPN="P",PSGSS="G" Q:((PSGINCLG="")&(PSGMARWN["C!")) D ;Construct XTMP global for printing by WARD GROUP
132 . S ^XTMP(PSGREP,TM,SUB1,PSGMARWN,SUB2,$S(+PSGMSORT:$E(QST,1),1:QST),DRG)=PSGDEM
133 S X=PSGDEM ;transfer contents of patient drug information contained in PSGDEM back to X
134 ;End DAM modifications 5-01-07
135 Q
136 ;
137SPN ; set patient node
138 D DIET
139 S X=$P(PSGP(0),U)_U_$E($P(PSJPDOB,U,2),1,10)_";"_PSJPAGE_U_VA("PID")_U_PSJPDX_U_PSJPWT_U_PSJPWTD_U_PSJPHT_U_PSJPHTD_U_$P(PSJPAD,U,2)_U_$P(PSJPTD,U,2)_U_$P(PSJPSEX,U,2)_U_PSJPWD_U_PSGPLS_U_PSGPLF_U_PSGMARSD_U_PSGMARFD_U_PSGMARSP_U_PSGMARFP
140 I PSGSS="P"!(PSGSS="C")!(PSGSS="L") S ^TMP($J,PPN)=X_U_PSGMARWN_U_PSJPRB Q
141 ;
142 ;
143 ;DAM 5-01-07 Add check to see if user wants to include clinic orders when printing by ward.
144 I PSGSS="W" Q:((PSGINCL="")&(PSGMARWN["C!")) S ^TMP($J,TM,PSGMARWN,SUB1,SUB2)=X
145 ;
146 ;DAM 5-01-07 Add check to see if user wants to include clinic orders when printing by ward group.
147 I PSGSS="G" Q:((PSGINCLG="")&(PSGMARWN["C!")) S ^TMP($J,TM,PSGMARWN,SUB1,SUB2)=X
148 ;
149 ;DAM 5-01-07 Add an XTMP global to reverse location and patient name in the subscripts when printing MAR by WARD/PATIENT or WARD GROUP.
150 N PSGDEM S PSGDEM=X ;transfer contents of patient demographics contained in "X" above to a new variable temporarily
151 S PSGREP="PSGM_"_$J
152 S X1=DT,X2=1 D C^%DTC K %,%H,%T
153 S ^XTMP(PSGREP,0)=X_U_DT
154 I PSGRBPPN="P",PSGSS="W" Q:((PSGINCL="")&(PSGMARWN["C!")) D ;Construct XTMP global for printing by WARD
155 . S ^XTMP(PSGREP,TM,SUB1,PSGMARWN,SUB2)=PSGDEM
156 I PSGRBPPN="P",PSGSS="G" Q:((PSGINCLG="")&(PSGMARWN["C!")) D ;Construct XTMP global for printing by WARD GROUP
157 . S ^XTMP(PSGREP,TM,SUB1,PSGMARWN,SUB2)=PSGDEM
158 S X=PSGDEM ;transfer contents of patient demographics contained in PSGDEM back to X
159 ;End DAM modifications 3-7-07
160 Q
161DIET ; Include abbr. diet label if indicated in the Site par.
162 NEW ADM,DFN,PSJMPAR K PSJDIET
163 S PSJMPAR=$G(^PS(59.7,1,26))
164 Q:'$P(PSJMPAR,U,3)
165 S DFN=PSGP,ADM=$G(^DPT("CN",PSGMARWN,DFN))
166 I +ADM D CUR^FHORD7 S PSJDIET=Y
167 Q
168 ;
169DTSET ;
170 S (PSGPLS,PSGPLF)=PSGMARDT
171 S PSJSYSW=$O(^PS(59.6,"B",+$G(PSJPWD),0))
172 S:PSJSYSW PSJSYSW0=$G(^PS(59.6,PSJSYSW,0))
173 I $D(PSJSYSW0),$P(PSJSYSW0,"^",8) S ST=$P(PSJSYSW0,"^",8),FT=$P(PSJSYSW0,"^",9)
174 E S ST="0001",FT=24
175SET S PSGMARSD=$E(ST,1,2),PSGMARFD=$E(FT,1,2) S:'PSGMARSD PSGMARSD="01" S PSGMARFD=$S(+PSGMARSD=1:24,PSGMARSD=PSGMARFD:PSGMARSD-1,1:PSGMARFD) S:$L(PSGMARFD)<2 PSGMARFD=0_PSGMARFD
176 I ST>1 S X1=$P(PSGPLF,"."),X2=1 D C^%DTC S PSGPLF=X
177 S PSGPLS=+(PSGPLS_"."_ST),PSGPLF=+(PSGPLF_"."_FT)
178 S PSGMARSP=$$ENDTC2^PSGMI(PSGPLS),PSGMARFP=$$ENDTC2^PSGMI(PSGPLF)
179 Q
Note: See TracBrowser for help on using the repository browser.