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

APCLW61.m

Go to the documentation of this file.
APCLW61 ; IHS/CMI/LAB - CALC WEIGHT REPORT ;
 ;;2.0;IHS PCC SUITE;**4,10,11**;MAY 14, 2009;Build 58
 ;
 ;cmi/anch/maw 9/12/2007 code set versioning PREGDX
 ;
START ;EP
 ;calculate 365 days ago and 1095 days ago
 S APCLJ=$J,APCLH=$H
 S APCLGRAN=0
 D XTMP^APCLOSUT("APCLW6","PCC BMI REPORT")
 ;
PROC ;
 S DFN=0 F  S DFN=$O(^AUPNPAT(DFN)) Q:DFN'=+DFN  D
 .Q:'$D(^DPT(DFN,0))
 .Q:$P(^DPT(DFN,0),U,19)
 .I APCLSEAT="" Q:$$DEMO^APCLUTL(DFN,$G(APCLDEMO))
 .I APCLSEAT]"" Q:'$D(^DIBT(APCLSEAT,1,DFN))
 .I APCLTYPE="P" Q:'$$AGEAP(DFN,APCLBD,APCLED,APCLLOWA,APCLHGHA,APCLBEG)
 .S APCLAGE=$$AGE^AUPNPAT(DFN,$S($G(APCLBEG)="":APCLBD,APCLBEG="B":APCLBD,1:APCLED))
 .I APCLTYPE="P" Q:APCLAGE<APCLLOWA  Q:APCLAGE>APCLHGHA
 .S Y=DFN D ^AUPNPAT
 .Q:AUPNSEX=""
 .Q:AUPNSEX="U"
 .Q:APCLSEX'="B"&(APCLSEX'=AUPNSEX)
 .D GETBMI1
 .I APCLBMI1="" Q  ;no beginning BMI
 .I APCLOB1="" Q  ;no beginning ob/ow
 .D GETBMI2
 .K ^TMP($J,"A")
 .I APCLBMI2="" Q  ;no ending BMI
 .I APCLOB2="" Q  ;no ending ob/ow value
 .I APCLOB1=APCLOB2 Q  ;same beg and end
 .S APCLMOVE=""
 .I APCLOB1<APCLOB2 S APCLMOVE="UP"
 .I APCLOB1>APCLOB2 S APCLMOVE="DOWN"
 .S ^XTMP("APCLW6",APCLJ,APCLH,"PATIENTS",APCLMOVE,APCLAGE,$P(^DPT(DFN,0),U),DFN)=APCLWT1_U_APCLHT1_U_APCLBMI1_U_APCLOB1_U_APCLWT2_U_APCLHT2_U_APCLBMI2_U_APCLOB2
 .S APCLGRAN=APCLGRAN+1
 .Q
 Q
GETBMI1 ;
 ;TABLE ALL VISITS CHRONOLOGICALLY FROM BEGINNING DATE
 S APCLBMI1="",APCLOB1=""
 K ^TMP($J,"A")
 S A="^TMP($J,""A"",",B=DFN_"^ALL VISITS;DURING "_$$FMTE^XLFDT(APCLBD)_"-"_$$FMTE^XLFDT(APCLED),E=$$START1^APCLDF(B,A)
 I '$D(^TMP($J,"A",1)) Q
 S (APCLX,G)=0 F  S APCLX=$O(^TMP($J,"A",APCLX)) Q:APCLX'=+APCLX!(APCLBMI1]"")  S APCLV=$P(^TMP($J,"A",APCLX),U,5) D
 .Q:'$D(^AUPNVSIT(APCLV,0))
 .Q:'$P(^AUPNVSIT(APCLV,0),U,9)
 .Q:$P(^AUPNVSIT(APCLV,0),U,11)
 .Q:$$PREGDX(APCLV)  ;quit if pregnant on this visit
 .S APCLWT1=$$WT(APCLV)
 .Q:$P(APCLWT1,U)=""  ;no weight on this visit
 .;got a weight so get a height
 .S APCLHT1=$$HT(DFN,APCLV,$$AGE^AUPNPAT(DFN,$P($P(^AUPNVSIT(APCLV,0),U),".")),$P(APCLWT1,U,2))
 .Q:$P(APCLHT1,U)=""
 .Q:$P(APCLHT1,U)="?"
 .S APCLCHT=$P(APCLHT1,U),APCLCWT=$P(APCLWT1,U) D CALCBMI
 .S APCLBMI1=APCLBMI
 .S APCLOB1=""
 .;find entry in reference table
 .S APCLREF=$O(^APCLBMI("H",AUPNSEX,$$AGE^AUPNPAT(DFN,$P($P(^AUPNVSIT(APCLV,0),U),".")),0))
 .I 'APCLREF S APCLREF=$O(^APCLBMI("H",AUPNSEX,$$AGE^AUPNPAT(DFN,$P($P(^AUPNVSIT(APCLV,0),U),".")))) I APCLREF S APCLREF=$O(^APCLBMI("H",AUPNSEX,APCLREF,""))
 .Q:'APCLREF
 .;I APCLBMI1>$P(^APCLBMI(APCLREF,0),U,7)!(APCLBMI1<$P(^APCLBMI(APCLREF,0),U,6)) S APCLOB1="" Q
 .I APCLBMI1'<$P(^APCLBMI(APCLREF,0),U,4),APCLBMI1<$P(^APCLBMI(APCLREF,0),U,5) S APCLOB1=2 Q
 .I APCLBMI1'<$P(^APCLBMI(APCLREF,0),U,5) S APCLOB1=3 Q
 .S APCLOB1=1
 .Q
 Q
GETBMI2 ;
 ;TABLE ALL VISITS CHRONOLOGICALLY FROM BEGINNING DATE
 S APCLBMI2="",APCLOB2=""
 ;K ^TMP($J,"A")
 ;S A="^TMP($J,""A"",",B=DFN_"^ALL VISITS;DURING "_$$FMTE^XLFDT(APCLBD)_"-"_$$FMTE^XLFDT(APCLED),E=$$START1^APCLDF(B,A)
 ;I '$D(^TMP($J,"A",1)) Q
 S G=0,APCLX="A" F  S APCLX=$O(^TMP($J,"A",APCLX),-1) Q:APCLX'=+APCLX!(APCLBMI2]"")  S APCLV=$P(^TMP($J,"A",APCLX),U,5) D
 .Q:'$D(^AUPNVSIT(APCLV,0))
 .Q:'$P(^AUPNVSIT(APCLV,0),U,9)
 .Q:$P(^AUPNVSIT(APCLV,0),U,11)
 .Q:$$PREGDX(APCLV)  ;quit if pregnant on this visit
 .S APCLWT2=$$WT(APCLV)
 .Q:$P(APCLWT2,U)=""  ;no weight on this visit
 .;got a weight so get a height
 .S APCLHT2=$$HT(DFN,APCLV,$$AGE^AUPNPAT(DFN,$P($P(^AUPNVSIT(APCLV,0),U),".")),$P(APCLWT2,U,2))
 .Q:$P(APCLHT2,U)=""
 .Q:$P(APCLHT2,U)="?"
 .S APCLCHT=$P(APCLHT2,U),APCLCWT=$P(APCLWT2,U) D CALCBMI
 .S APCLBMI2=APCLBMI
 .S APCLOB2=""
 .;find entry in reference table
 .S APCLREF=$O(^APCLBMI("H",AUPNSEX,$$AGE^AUPNPAT(DFN,$P($P(^AUPNVSIT(APCLV,0),U),".")),0))
 .I 'APCLREF S APCLREF=$O(^APCLBMI("H",AUPNSEX,$$AGE^AUPNPAT(DFN,$P($P(^AUPNVSIT(APCLV,0),U),".")))) I APCLREF S APCLREF=$O(^APCLBMI("H",AUPNSEX,APCLREF,""))
 .Q:'APCLREF
 .;I APCLBMI2>$P(^APCLBMI(APCLREF,0),U,7)!(APCLBMI2<$P(^APCLBMI(APCLREF,0),U,6)) S APCLOB2="" Q
 .I APCLBMI2'<$P(^APCLBMI(APCLREF,0),U,4),APCLBMI2<$P(^APCLBMI(APCLREF,0),U,5) S APCLOB2=2 Q
 .I APCLBMI2'<$P(^APCLBMI(APCLREF,0),U,5) S APCLOB2=3 Q
 .S APCLOB2=1
 .Q
 Q
WT(V) ;return wt on this visit
 NEW X,M,W
 S W="",D=""
 S M=$O(^AUTTMSR("B","WT",0))
 S X=0 F  S X=$O(^AUPNVMSR("AD",V,X)) Q:X'=+X  I '$P($G(^AUPNVMSR(X,2)),U,1) S Z=$P(^AUPNVMSR(X,0),U) I Z=M S W=$P(^AUPNVMSR(X,0),U,4),D=$P($P(^AUPNVSIT(V,0),U),".")
 Q W_U_D
HT(P,V,AGE,DATE) ;return wt on this visit
 NEW X,M,W,APCLY,APCLX,BD,ED
 S W="",D=""
 S M=$O(^AUTTMSR("B","HT",0))
 I AGE<19 D  Q W_U_D
 .S W=""
 .;call data fetcher to get ht on DATE-DATE
 .K APCLG S (W,D)=""
 .S APCLY="APCLG(",APCLX=P_"^LAST MEASUREMENT HT;DURING "_DATE_"-"_DATE S APCLER=$$START1^APCLDF(APCLX,APCLY)
 .I $D(APCLG(1)) S W=$P(APCLG(1),U,2),D=$P(APCLG(1),U)
 .Q
 K APCLG S (W,D)=""
 I AGE>18,AGE<50 D  Q W_U_D
 .S BD=$$FMADD^XLFDT(DATE,-(3*365))
 .S ED=DATE
 .S APCLY="APCLG(",APCLX=P_"^LAST MEASUREMENT HT;DURING "_BD_"-"_ED S APCLER=$$START1^APCLDF(APCLX,APCLY)
 .I $D(APCLG(1)) S W=$P(APCLG(1),U,2),D=$P(APCLG(1),U)
 .Q
 K APCLG S (W,D)=""
 S BD=$$FMADD^XLFDT(DATE,-365)
 S ED=DATE
 S APCLY="APCLG(",APCLX=P_"^LAST MEASUREMENT HT;DURING "_BD_"-"_ED S APCLER=$$START1^APCLDF(APCLX,APCLY)
 I $D(APCLG(1)) S W=$P(APCLG(1),U,2),D=$P(APCLG(1),U)
 Q W_U_D
PREGDX(V) ;
 NEW P,D,G
 S G=0
 S P=0 F  S P=$O(^AUPNVPOV("AD",V,P)) Q:P'=+P!(G)  S D=$P(^AUPNVPOV(P,0),U) D  ;cmi/anch/maw 9/12/2007 csv
 .I $$ICD^AUPNVUTL(D,$O(^ATXAX("B","BGP PREGNANCY DIAGNOSES 2",0)),9) S G=1
 .Q
 Q G
CALCBMI ;calculate BMI value
 S APCLMWT=APCLCWT*.45359,APCLMHT=APCLCHT*.0254,APCLBMI=APCLMWT/(APCLMHT*APCLMHT)
 Q
EOJ ;
 K APCL1YR,APCL3YR,APCLA,APCLBD,APCLMGI,APCLCHT,APCLCWT,APCLGHT,APCLGWT,APCLROWT,APCLROHT,APCLER,APCLMHT,APCLMWT,APCLX,APCLY,APCLNN,APCLREF
 K AUPNPAT,AUPNDOB,AUPNSEX,AUPNDAYS,AUPNDOD
 K DFN,X,Y,V,A,D,I,J,Z
 Q
AGEAP(P,BD,ED,LOW,HIGH,TP) ;
 I '$G(P) Q ""
 S A=$$AGE^AUPNPAT(P,$S(TP="B":BD,1:ED))
 I A<LOW Q 0
 I A>HIGH Q 0
 Q 1