source: FOIAVistA/trunk/r/DIETETICS-FH/FHMTK7.m@ 1504

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

initial load of FOIAVistA 6/30/08 version

File size: 9.4 KB
Line 
1FHMTK7 ; HISC/NCA - Update Diet Restrictions ;12/6/00 15:14
2 ;;5.5;DIETETICS;**5**;Jan 28, 2005;Build 53
3 ; Update the Diet Restrictions For All Inpatients
4 ; 11/14/05 -P5- added standing order & SF for outpatients.
5 R !!,"Update All Diet Related Information for Patients? Y // ",X:DTIME Q:'$T!(X["^")
6 S:X="" X="Y" D TR^FH I $P("YES",X,1)'="",$P("NO",X,1)'="" W *7,!," Answer YES or NO" G FHMTK7
7 S ANS=X?1"Y".E Q:'ANS
8 F W1=0:0 S W1=$O(^FHPT("AW",W1)) Q:W1'>0 F FHDFN=0:0 S FHDFN=$O(^FHPT("AW",W1,FHDFN)) Q:FHDFN<1 S ADM=$G(^FHPT("AW",W1,FHDFN)) D:ADM PAT,STORD,SFMENU ;P30
9 D SOO ;update so for outpatient
10 D SFO ;update sf for outpt.
11 Q
12STORD ;Update Standing orders for a patient, P30
13 D SO^FHMTK8
14 Q
15SFMENU ;Update SF Menu for a patient, P30
16 D SF^FHMTK8
17 Q
18PAT ; Update Restrictions for a patient
19 S FHORD=$P($G(^FHPT(FHDFN,"A",ADM,0)),"^",2) I FHORD<1 S DPAT="" G UPD
20 S Z=$G(^FHPT(FHDFN,"A",ADM,"DI",FHORD,0)),FHOR=$P(Z,"^",2,6) I "^^^^"[FHOR S DPAT="" G UPD
21 S DPAT=$O(^FH(111.1,"AB",FHOR,0)) G:DPAT="" UPD
22 Q:'$D(^TMP($J,+DPAT))
23 ;
24UPD ; Update Pattern
25 S (COM,PP)=""
26 F SP=0:0 S SP=$O(^FHPT(FHDFN,"P",SP)) Q:SP<1 S M2=$G(^(SP,0)) I $P(M2,"^",4)="Y" D
27 .S FP=+M2 I $D(^FH(111.1,+DPAT,"RES","B",FP)) Q
28 .D PURG Q
29 F R1=0:0 S R1=$O(^FH(111.1,+DPAT,"RES",R1)) Q:R1<1 S M2=$G(^(R1,0)),FP=+M2 I FP D
30 .S SP=$O(^FHPT(FHDFN,"P","B",FP,0)) I 'SP D ADD Q
31 .I $P($G(^FHPT(FHDFN,"P",SP,0)),"^",2)=$P(M2,"^",2) Q
32 .D CHG Q
33 G FIL
34CHG ; Change the Diet Restrictions
35 S MEAL=$P(M2,"^",2)
36 I $P($G(^FHPT(FHDFN,"P",SP,0)),"^",4)="Y" S M2=MEAL G CHG1 ;diet related
37 Q:MEAL=""
38 S M1=$P($G(^FHPT(FHDFN,"P",SP,0)),"^",2) Q:M1="" S:M1="A" M1="BNE"
39 S M2="" F LP=1:1:$L(MEAL) I M1'[$E(MEAL,LP) S M2=M2_$E(MEAL,LP)
40 Q:M2=""
41 S M1=M1_M2,M2="" S:M1["B" M2="B" S:M1["N" M2=M2_"N" S:M1["E" M2=M2_"E"
42CHG1 S $P(^FHPT(FHDFN,"P",SP,0),"^",2)=M2
43 S PP=" Mod 1 "_$P(^FH(115.2,+FP,0),"^",1)_" ("_M2_")"_" (D)" D SET
44 Q
45ADD ; Add the Diet Restriction
46 S MEAL=$P($G(M2),"^",2) Q:MEAL=""
47 K DIC,DD,DO S DIC="^FHPT(FHDFN,""P"",",DIC(0)="L",DLAYGO=115,DA(1)=FHDFN,X=+FP
48A1 L +^FHPT(FHDFN,"P",0)
49 I '$D(^FHPT(FHDFN,"P",0)) S ^FHPT(FHDFN,"P",0)="^115.09PA^^"
50 S NUM=$P(^FHPT(FHDFN,"P",0),"^",3)+1
51 S $P(^FHPT(FHDFN,"P",0),"^",3)=NUM
52 L -^FHPT(FHDFN,"P",0) I $D(^FHPT(FHDFN,"P",NUM,0)) G A1
53 S DINUM=NUM D FILE^DICN S SP=+Y K DIC,DLAYGO,DINUM
54 S $P(^FHPT(FHDFN,"P",+SP,0),"^",2,4)=MEAL_"^^Y",PP=" Add 1 "_$P(^FH(115.2,+FP,0),"^",1)_" ("_$P(FP,"^",2)_")"_" (D)" D SET
55 Q
56PURG ; Purge the Old Restrictions
57 S M1=$P($G(^FHPT(FHDFN,"P",SP,0)),"^",2) Q:M1="" S:M1="A" M1="BNE"
58 K DIK S DA(1)=FHDFN,DA=+SP,DIK="^FHPT("_DA(1)_",""P""," D ^DIK K DIK,DA S PP=" Del 1 "_$P(^FH(115.2,+FP,0),"^",1)_" ("_M1_")"_" (D)" D SET Q
59SET I $L(COM)+$L(PP)>120 S EVT="P^O^^"_$E(COM,2,999) D ^FHORX S COM=""
60 S COM=COM_PP
61 Q
62FIL ; File the Event
63 I COM'="" S EVT="P^O^^"_$E(COM,2,999) D ^FHORX
64 Q
65 ;
66SOO ;OUT SO
67 S FHCNT=0 K ^TMP("FH",$J)
68 F FHDFN=0:0 S FHDFN=$O(^FHPT("OP",FHDFN)) Q:FHDFN'>0 S FHSTADT="" F FHADAT=DT-1:0 S FHADAT=$O(^FHPT(FHDFN,"OP","B",FHADAT)) Q:FHADAT'>0 D
69 .I FHSTADT="" S DTP=FHADAT D DTP^FH S FHSTADT=DTP
70 .F FHADM=0:0 S FHADM=$O(^FHPT(FHDFN,"OP","B",FHADAT,FHADM)) Q:FHADM'>0 D
71 ..S FHSOP=$G(^FHPT(FHDFN,"OP",FHADM,0))
72 ..Q:$P(FHSOP,U,15)="C"
73 ..K FHDT,FHCSO
74 ..S FHDT=$$CURDT(FHDFN,FHADM)
75 ..Q:'$G(FHDT)
76 ..I FHDT'<0 Q:'$D(^TMP($J,+FHDT))
77 ..D CHKSO
78ADEV F FHDFN=0:0 S FHDFN=$O(^TMP("FH",$J,FHDFN)) Q:FHDFN'>0 F FHACT="C","O" F FHML="B","N","E" D
79 .S FHSO="" S FHSO=$O(^TMP("FH",$J,FHDFN,FHACT,FHML,FHSO)) Q:FHSO="" D
80 ..S FHDATA=^TMP("FH",$J,FHDFN,FHACT,FHML,FHSO)
81 ..S FHTXT=$P(FHDATA,U,1)_$P(FHDATA,U,2)
82 ..I $P(FHDATA,U,2)'=$P(FHDATA,U,3) S FHTXT=FHTXT_" to "_$P(FHDATA,U,3)
83 ..D OPFILE^FHORX
84 K ^TMP("FH",$J)
85 Q
86 ;
87CHKSO ;compares SO
88 K FHML,FH,FHSO,FH1,FH2
89 S FHML=$P(FHSOP,U,4)
90 F FH1=0:0 S FH1=$O(^FH(111.1,FHDT,FHML_"S",FH1)) Q:FH1'>0 D
91 .S FHDIPAT=^FH(111.1,FHDT,FHML_"S",FH1,0)
92 .S FHCSO("N",$P(FHDIPAT,U,1))=FHML_"^"_^FH(111.1,FHDT,FHML_"S",FH1,0)
93 ;
94 F FHI=0:0 S FHI=$O(^FHPT(FHDFN,"OP",FHADM,"SP",FHI)) Q:FHI'>0 D
95 .S FHS1=$G(^FHPT(FHDFN,"OP",FHADM,"SP",FHI,0))
96 .Q:$P(FHS1,U,6)'=""
97 .I $P(FHS1,"^",9)="Y" S FHCNT=FHCNT+1,FHCSO("C",FHI)=FHS1
98 F FH2=0:0 S FH2=$O(FHCSO("C",FH2)) Q:FH2'>0 D
99 . Q:$P(FHCSO("C",FH2),"^",3)'=FHML ;diff meal
100 . S FHSOIEN=$P(FHCSO("C",FH2),U,2)
101 . I $D(FHCSO("N",FHSOIEN)) D
102 .. I $P(FHCSO("C",FH2),"^",8)'=$P(FHCSO("N",FHSOIEN),"^",3) D
103 ... S FHCSO("U",FH2)=FHCSO("C",FH2),$P(FHCSO("U",FH2),"^",8)=$P(FHCSO("N",FHSOIEN),"^",3)
104 ... K FHCSO("N",FHSOIEN),FHCSO("C",FH2) Q
105 I $D(FHCSO) D UPDTSO(FHDFN,FHADM,.FHCSO) Q
106 Q
107 ;
108UPDTSO(FHDFN,FHADM,FHUCSO) ;update SO
109 N FHNOW,FH,FHNEW
110 I '$D(ADM) N ADM S ADM=FHADM
111 D NOW^%DTC S FHNOW=%
112 I '$D(DUZ) W !,"Unknown user" Q
113 F FH=0:0 S FH=$O(FHUCSO("C",FH)) Q:FH'>0 D
114 . D CANCSO
115 F FH=0:0 S FH=$O(FHUCSO("U",FH)) Q:FH'>0 D
116 . D CANCSO
117 . S FHNEW=$$ADDSO(FHDFN,FHADM,$P(FHUCSO("U",FH),"^",3),$P(FHUCSO("U",FH),"^",2),$P(FHUCSO("U",FH),"^",8))
118 F FH=0:0 S FH=$O(FHUCSO("N",FH)) Q:FH'>0 D
119 . S FHNEW=$$ADDSO(FHDFN,FHADM,$P(FHUCSO("N",FH),"^",1),$P(FHUCSO("N",FH),"^",2),$P(FHUCSO("N",FH),"^",3))
120 Q
121 ;
122CANCSO ;cancel SO
123 S FHLOCN="",FHLOC=$P($G(^FHPT(FHDFN,"OP",FHADM,0)),U,3) I $G(FHLOC) S FHLOCN=$P($G(^FH(119.6,FHLOC,0)),U,1)
124 S $P(^FHPT(FHDFN,"OP",FHADM,"SP",FH,0),"^",6,7)=FHNOW_"^"_DUZ
125 S FHSODAT=$G(^FHPT(FHDFN,"OP",FHADM,"SP",FH,0)),FHSO=$P(FHSODAT,U,2),FHML=$P(FHSODAT,U,3),FHN=$P(FHSODAT,U,8)
126 K ^FHPT("ASPO",FHDFN,FHADM,FH)
127 S DTP=$P($G(^FHPT(FHDFN,"OP",FHADM,0)),U,1) D DTP^FH
128 S FHACT="C",FHTXT="Outpatient Standing Order: "_FHN_" "_$P($G(^FH(118.3,FHSO,0)),U,1)_" ("_FHML_") , "_FHLOCN_", Cancelled "
129 S ^TMP("FH",$J,FHDFN,"C",FHML,$P($G(^FH(118.3,FHSO,0)),U,1))=FHTXT_U_FHSTADT_U_DTP
130 Q
131 ;
132ADDSO(FHDFN,FHADM,FHML,FHSO,FHN) ;
133 N FHX,FH
134 S FHLOCN="",FHLOC=$P($G(^FHPT(FHDFN,"OP",FHADM,0)),U,3) I $G(FHLOC) S FHLOCN=$P($G(^FH(119.6,FHLOC,0)),U,1)
135 S FH=0
136AGN L +^FHPT(FHDFN,"OP",FHADM,"SP",0)
137 I '$D(^FHPT(FHDFN,"OP",FHADM,"SP",0)) S ^FHPT(FHDFN,"OP",FHADM,"SP",0)="^115.1626^^"
138 S FHX=^FHPT(FHDFN,"OP",FHADM,"SP",0),FH=$P(FHX,"^",3)+1,^(0)=$P(FHX,"^",1,2)_"^"_FH_"^"_($P(FHX,"^",4)+1)
139 L -^FHPT(FHDFN,"OP",FHADM,"SP",0)
140 G:$D(^FHPT(FHDFN,"OP",FHADM,"SP",FH)) AGN
141 S ^FHPT(FHDFN,"OP",FHADM,"SP",FH,0)=FH_"^"_FHSO_"^"_FHML_"^"_FHNOW_"^"_DUZ_"^^^"_FHN_"^Y",^FHPT("ASPO",FHDFN,FHADM,FH)=""
142 S DTP=$P($G(^FHPT(FHDFN,"OP",FHADM,0)),U,1) D DTP^FH
143 S FHACT="O",FHTXT="Outpatient Standing Order: "_FHN_" "_$P($G(^FH(118.3,FHSO,0)),U,1)_" ("_FHML_") , "_FHLOCN_", "
144 S ^TMP("FH",$J,FHDFN,"O",FHML,$P($G(^FH(118.3,FHSO,0)),U,1))=FHTXT_U_FHSTADT_U_DTP
145 Q FH
146 ;
147SFO ;out SFs
148 S FHCNT=0 K ^TMP("FH",$J)
149 F FHDFN=0:0 S FHDFN=$O(^FHPT("OP",FHDFN)) Q:FHDFN'>0 S FHSTADT="" F FHADAT=DT-1:0 S FHADAT=$O(^FHPT(FHDFN,"OP","B",FHADAT)) Q:FHADAT'>0 D
150 .I FHSTADT="" S DTP=FHADAT D DTP^FH S FHSTADT=DTP
151 .F FHADM=0:0 S FHADM=$O(^FHPT(FHDFN,"OP","B",FHADAT,FHADM)) Q:FHADM'>0 D
152 ..S FHSOP=$G(^FHPT(FHDFN,"OP",FHADM,0))
153 ..Q:$P(FHSOP,U,15)="C"
154 ..K FHDT,FHCSO
155 ..S FHDT=$$CURDT(FHDFN,FHADM)
156 ..Q:'$G(FHDT)
157 ..I FHDT'<0 Q:'$D(^TMP($J,+FHDT))
158 ..D DOSF(FHDFN,FHADM)
159 D ADEV
160 Q
161DOSF(FHDFN,FHADM) ;check/update SF
162 N FHDSF,FH,FHPSF
163 S FH=$$CURDT(FHDFN,FHADM)
164 I FH'<0 Q:'$D(^TMP($J,+FH))
165 S FHDSF=$P($G(^FH(111.1,FH,0)),"^",8)
166 S FHPSF("N")=$P($G(^FHPT(FHDFN,"OP",FHADM,"SF",0)),U,3)
167 S FHPSF("E")=$S(FHPSF("N")="":1,1:0)
168 S:FHPSF("E")=1 FHPSF("N")=$P($G(^FHPT(FHDFN,"OP",FHADM,"SF",0)),"^",3)
169 S FHPSF=$G(^FHPT(FHDFN,"OP",FHADM,"SF",+FHPSF("N"),0))
170 S FHPSF("C")=$S($P(FHPSF,"^",32)="":0,1:1)
171 Q:+$P(FHPSF,"^",4)=1
172 I $P(FHPSF,"^",34)'="Y" Q:FHDSF=""
173 I FHPSF("E")=1 Q:FHDSF=""
174 D UPDSF(FHDFN,FHADM,FHDSF,.FHPSF)
175 Q
176 ;
177UPDSF(FHDFN,FHADM,FHSF,FHPSF) ;
178 N FHX,FHNO,FHPNO,FHPNN,FHNOW,FHN3
179 D NOW^%DTC S FHNOW=%
180 S DTP=$P($G(^FHPT(FHDFN,"OP",FHADM,0)),U,1) D DTP^FH
181 I '$D(ADM) N ADM S ADM=FHADM
182 I '$D(DUZ) W !,"Unknown user" Q
183 S FHSFDAT=$G(^FHPT(FHDFN,"OP",FHADM,0))
184 S FHML=$P(FHSFDAT,U,4),FHLOCN=""
185 S FHLOC=$P(FHSFDAT,U,3) S:FHLOC FHLOCN=$P($G(^FH(119.6,FHLOC,0)),U,1)
186 I FHSF="" S FHN3=+FHPSF("N") D:FHN3>0 CANCSF Q
187 S FHPNO=$G(^FH(118.1,+FHSF,1)) Q:FHPNO=""
188 G:+FHPSF("N")=0!(FHPSF("C")=1) CONT
189 G:+$P(FHPSF,"^",4)'=+FHSF CONT
190 Q:$P(FHPSF,"^",5,29)=FHPNO
191CONT S FHPNN="^"_FHNOW_"^"_DUZ_"^"_FHSF_"^"_FHPNO
192 ;
193TRYSF L +^FHPT(FHDFN,"OP",FHADM,"SF",0)
194 I '$D(^FHPT(FHDFN,"OP",FHADM,"SF",0)) S ^FHPT(FHDFN,"OP",FHADM,"SF",0)="^115.1627^^"
195 S FHX=^FHPT(FHDFN,"OP",FHADM,"SF",0),FHN3=+$P(FHX,"^",3),FHNO=FHN3+1,^(0)=$P(FHX,"^",1,2)_"^"_FHNO_"^"_($P(FHX,"^",4)+1)
196 L -^FHPT(FHDFN,"OP",FHADM,"SF",0) I $D(^FHPT(FHDFN,"OP",FHADM,"SF",FHNO)) G TRYSF
197 S ^FHPT(FHDFN,"OP",FHADM,"SF",FHNO,0)=FHNO_"^"_$P(FHPNN,"^",2,99)
198 I FHN3,$D(^FHPT(FHDFN,"OP",FHADM,"SF",FHN3,0)),'$P(^(0),U,32) D CANCSF
199 S:FHNO $P(^FHPT(FHDFN,"OP",FHADM,"SF",FHNO,0),"^",30,31)=FHNOW_"^"_DUZ
200 S:FHNO $P(^FHPT(FHDFN,"OP",FHADM,"SF",FHNO,0),"^",34)="Y"
201 S FHACT="O",FHTXT="Outpatient Supplemental Feeding: "_$P($G(^FH(118.1,+FHSF,0)),U,1)_" ("_FHML_") , "_FHLOCN_", "
202 S ^TMP("FH",$J,FHDFN,"O",FHML,$P($G(^FH(118.1,FHSF,0)),U,1))=FHTXT_U_FHSTADT_U_DTP
203 Q
204CANCSF I FHN3'=0&(FHPSF("C")=0) D
205 . S $P(^FHPT(FHDFN,"OP",FHADM,"SF",FHN3,0),"^",32,33)=FHNOW_"^"_DUZ
206 . S $P(^FHPT(FHDFN,"OP",FHADM,0),"^",7)=""
207 . S FHACT="C",FHTXT="Outpatient Supplemental Feeding: "_$P($G(^FH(118.1,+FHN3,0)),U,1)_" ("_FHML_") , "_FHLOCN_", Cancelled "
208 . S ^TMP("FH",$J,FHDFN,"C",FHML,$P($G(^FH(118.1,FHN3,0)),U,1))=FHTXT_U_FHSTADT_U_DTP
209 Q
210 ;
211CURDT(FHDFN,FHADM) ;get current patient's diet pattern ien of 111.1
212 N FHDT,FHOR
213 S FHOR="",FHDT=$P($G(^FHPT(FHDFN,"OP",FHADM,0)),"^",2)
214 I FHDT="" S FHOR=$P($G(^FHPT(FHDFN,"OP",FHADM,0)),U,7,11)
215 I FHOR'["^" S FHOR=FHDT_"^^^^"
216 S FHDT=$O(^FH(111.1,"AB",FHOR,0)) Q:FHDT="" -1 ;doesn't exist
217 Q FHDT
Note: See TracBrowser for help on using the repository browser.