Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: BGPD30

BGPD30.m

Go to the documentation of this file.
BGPD30 ; IHS/CMI/LAB - indicator 30 ;
 ;;7.0;IHS CLINICAL REPORTING;;JAN 24, 2007
 ;
I30 ;EP ;EP - indicator 30
 ;Q:'$D(BGPIND(26))
 S BGPSEX=$P(^DPT(DFN,0),U,2),BGPSEX=$S(BGPSEX="M":1,1:2)
 I BGPAGEB>11&(BGPAGEB<18) D
 .D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),2,BGPSEX,1)
 .S BGPP=$$TOBACCO(DFN,BGPEDATE)
 .I BGPP]"" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),4,BGPSEX,1)
 .I BGPP["CURRENT" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),6,BGPSEX,1)
 .I BGPP["SMOKER IN HOME" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),8,BGPSEX,1)
 .I $D(BGPLIST(26)),BGPTIME=1 S ^XTMP("BGPD",BGPJ,BGPH,"LIST",26,$S($P($G(^AUPNPAT(DFN,11)),U,18)]"":$P(^AUPNPAT(DFN,11),U,18),1:"UNKNOWN"),$P(^DPT(DFN,0),U,2),BGPAGEE,DFN)=BGPP
 I BGPAGEB>17&(BGPAGEB<35) D
 .D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),3,BGPSEX,1)
 .S BGPP=$$TOBACCO(DFN,BGPEDATE)
 .I BGPP]"" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),5,BGPSEX,1)
 .I BGPP["CURRENT" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),7,BGPSEX,1)
 .I BGPP["SMOKER IN HOME" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),9,BGPSEX,1)
 .I $D(BGPLIST(26)),BGPTIME=1 S ^XTMP("BGPD",BGPJ,BGPH,"LIST",26,$S($P($G(^AUPNPAT(DFN,11)),U,18)]"":$P(^AUPNPAT(DFN,11),U,18),1:"UNKNOWN"),$P(^DPT(DFN,0),U,2),BGPAGEE,DFN)=BGPP
 I BGPAGEB>34&(BGPAGEB<55) D
 .D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),11,BGPSEX,1)
 .S BGPP=$$TOBACCO(DFN,BGPEDATE)
 .I BGPP]"" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),12,BGPSEX,1)
 .I BGPP["CURRENT" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),13,BGPSEX,1)
 .I BGPP["SMOKER IN HOME" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),14,BGPSEX,1)
 .I $D(BGPLIST(26)),BGPTIME=1 S ^XTMP("BGPD",BGPJ,BGPH,"LIST",26,$S($P($G(^AUPNPAT(DFN,11)),U,18)]"":$P(^AUPNPAT(DFN,11),U,18),1:"UNKNOWN"),$P(^DPT(DFN,0),U,2),BGPAGEE,DFN)=BGPP
 I BGPAGEB>54 D
 .D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),15,BGPSEX,1)
 .S BGPP=$$TOBACCO(DFN,BGPEDATE)
 .I BGPP]"" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),16,BGPSEX,1)
 .I BGPP["CURRENT" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),17,BGPSEX,1)
 .I BGPP["SMOKER IN HOME" D SAGE(BGPRPT,$S(BGPTIME=1:19,BGPTIME=0:49,BGPTIME=8:89,1:999),18,BGPSEX,1)
 .I $D(BGPLIST(26)),BGPTIME=1 S ^XTMP("BGPD",BGPJ,BGPH,"LIST",26,$S($P($G(^AUPNPAT(DFN,11)),U,18)]"":$P(^AUPNPAT(DFN,11),U,18),1:"UNKNOWN"),$P(^DPT(DFN,0),U,2),BGPAGEE,DFN)=BGPP
 Q
SAGE(R,N,P,S,V) ;set age into file
 I 'V Q  ;no value
 NEW X,Y
 S X=$P($G(^BGPD(R,N)),U,P)
 S $P(X,"!",S)=$P(X,"!",S)+V
 S $P(^BGPD(R,N),U,P)=X
 Q
S(R,N,P,V) ;
 I 'V Q  ;no value to add
 S $P(^BGPD(R,N),U,P)=$P($G(^BGPD(R,N)),U,P)+V
 Q
 ;
TOBACCO(P,EDATE) ;EP
 ;get last health factor in date range from V Health Factors
 ;if none, check health status and check date
 I '$G(P) Q ""
 NEW BGPTOB,BGP,X,E
 K BGPTOB
 D TOBACCO1
 I $D(BGPTOB) Q BGPTOB
 D TOBACCO0
 I $D(BGPTOB) Q BGPTOB
 Q ""
TOBACCO1 ;check for tobacco documented in health factors
 K BGPTOB S BGPTOB=$$LASTHF(P,"TOBACCO",EDATE)
 Q
TOBACCO0 ;lookup in health status
 S (X,Y)=0 F  S X=$O(^AUPNHF("AA",P,X)) Q:X'=+X!(Y)  I $$VAL^XBDIQ1(9999999.64,X,.03)="TOBACCO" S Y=X
 Q:'Y
 S E=$O(^AUPNHF("AA",P,Y,E)) Q:'E
 I (9999999-E)>EDATE Q  ;documented after time frame
 S Y=$P(^AUTTHF(Y,0),U)
 I Y["NON" S BGPTOB="NEVER USED" Q
 I Y["SMOKE FREE HOME" S BGPTOB="NEVER USED" Q
 I Y["PREVIOUS" S BGPTOB="PAST USE" Q
 I Y="SMOKER IN HOME" S BGPTOB="SMOKER IN HOME" Q
 S BGPTOB="CURRENT USER"
 Q
 ;
LASTHF(P,C,EDATE) ;EP - get last factor in category C for patient P
 I '$G(P) Q ""
 I $G(C)="" Q ""
 I $G(F)="" S F=""
 S C=$O(^AUTTHF("B",C,0)) ;ien of category passed
 I '$G(C) Q ""
 NEW H,D,O S H=0 K O
 F  S H=$O(^AUTTHF("AC",C,H))  Q:'+H  D
 .  Q:'$D(^AUPNVHF("AA",P,H))
 .  S D="" F  S D=$O(^AUPNVHF("AA",P,H,D)) Q:D'=+D  D
 .. Q:(9999999-D)>EDATE  ;after time frame
 ..  S O(D)=$O(^AUPNVHF("AA",P,H,D,""))
 .  Q
 S D=$O(O(0))
 I D="" Q D
 Q $$VAL^XBDIQ1(9000010.23,O(D),.01)
 ;
 ;;