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

APCLW21.m

Go to the documentation of this file.
APCLW21 ; IHS/CMI/LAB - CALC WEIGHT REPORT ;
 ;;2.0;IHS PCC SUITE;**8,10,11**;MAY 14, 2009;Build 58
 ;
 ;cmi/anch/maw 9/12/2007 code set versioning PN
 ;
START ;EP
 ;calculate 365 days ago and 1095 days ago
 S X1=DT,X2=-365 D C^%DTC S Y=X D DD^%DT S APCL1YR=Y
 S X1=DT,X2=-1095 D C^%DTC S Y=X D DD^%DT S APCL3YR=Y
 S Y=DT D DD^%DT S APCLDT=Y
 S APCLJOB=$J,APCLBTH=$H,(DFN,APCLGRAN)=0
 D XTMP^APCLOSUT("APCLW2","PCC OBESITY/PREVALANCE REPORT")
PROC ;
 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))  ;quit if not in Search Template
 .S Y=DFN D ^AUPNPAT
 .Q:AUPNSEX=""
 .Q:AUPNSEX="U"
 .Q:APCLSEX'="B"&(APCLSEX'=AUPNSEX)  ;quit if want only one sex and this patient isn't that sex
 .Q:AUPNDOB=""
 .S APCLAGE=(AUPNDAYS\365.25)
 .;I $D(APCLAGER),APCLAGE<$P(APCLAGER,"-") Q
 .S APCLCLAS=$$BEN^AUPNPAT(DFN,"C")
 .Q:APCLCLAS=""
 .Q:APCLIBEN=1&(APCLCLAS'="01")
 .;I $D(APCLAGER),APCLAGE>$P(APCLAGER,"-",2) Q
 .S APCLHBD=$S(APCLAGE>19:$$FMTE^XLFDT($$FMADD^XLFDT($P(^DPT(DFN,0),U,3),(19*365))),1:APCL1YR)
 .S APCLBD=$S(APCLAGE>19:APCL3YR,1:APCL1YR) D GETWTHT
 .Q:'$D(APCLGWT)  ;quit if no weights
 .Q:'$D(APCLGHT)  ;quit if no heights
 .K APCLCWT,APCLCHT
 .I APCLAGE>19 D GETRECNT
 .I APCLAGE<20 D GETWHSD
 .Q:'$D(APCLCWT)
 .Q:'$D(APCLCHT)
 .S X2=AUPNDOB,X1=$P(APCLCWT,U,2) D ^%DTC S APCLAGE=(X\365.25) ;recalculate age based on date of weight
 .I $D(APCLAGER),APCLAGE<$P(APCLAGER,"-") Q
 .I $D(APCLAGER),APCLAGE>$P(APCLAGER,"-",2) Q
 .D CALCBMI
 .I $G(APCLBMIR)]"" Q:APCLBMI<$P(APCLBMIR,"-")  Q:APCLBMI>$P(APCLBMIR,"-",2)
 .I APCLRTYP'="S" D SRT
 .I APCLRTYP="S" S (APCLOVR,APCLOBE)="N"
 .;find entry in reference table
 .;S APCLREF=$O(^APCLBMI("H",AUPNSEX,APCLAGE)) Q:APCLREF=""  S APCLREF=$O(^APCLBMI("H",AUPNSEX,APCLREF,"")) Q:APCLREF=""
 .S APCLREF=$O(^APCLBMI("H",AUPNSEX,APCLAGE,0))
 .I 'APCLREF S APCLREF=$O(^APCLBMI("H",AUPNSEX,APCLAGE)) I APCLREF S APCLREF=$O(^APCLBMI("H",AUPNSEX,APCLREF,""))
 .Q:'APCLREF
 .I APCLBMI'<$P(^APCLBMI(APCLREF,0),U,5) S APCLOBE="Y",APCLOVR="N" G 1
 .I APCLBMI'<$P(^APCLBMI(APCLREF,0),U,4) S APCLOVR="Y",APCLOBE="N"
1 .I APCLBMI>$P(^APCLBMI(APCLREF,0),U,7)!(APCLBMI<$P(^APCLBMI(APCLREF,0),U,6)) D:APCLRPT="E" SET Q
 .Q:APCLRPT="E"
 .I APCLRPT="V",APCLOVR="N" Q
 .I APCLRPT="V",APCLOBE="Y" Q
 .I APCLRPT="B",APCLOBE="N" Q
 .I APCLRPT="C",APCLOBE="N",APCLOVR="N" Q
 .D SET
 .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
SRT ;
 S APCLNAME=$P(^DPT(DFN,0),U)
 S APCLHRN=$S($D(^AUPNPAT(DFN,41,DUZ(2),0)):$P(^(0),U,2),1:"NONE")
 S APCLSRT=""
 D @APCLSORT
 S (APCLOVR,APCLOBE)="N"
 Q
B ;
 S APCLSRT=APCLBMI
 Q
P ;
 S APCLSRT=APCLNAME
 Q
A ;
 S APCLSRT=APCLAGE
 Q
SET ;set for each age
 I APCLRTYP="S" S ^DIBT(APCLSTMP,1,DFN)="",APCLGRAN=APCLGRAN+1 Q
 S ^XTMP("APCLW2",APCLJOB,APCLBTH,"PATS",APCLSRT,DFN)=APCLNAME_U_APCLHRN_U_$P(APCLCHT,U)_U_$P(APCLCWT,U)_U_$P(APCLCWT,U,2)_U_APCLAGE_U_AUPNSEX_U_APCLBMI_U_APCLOVR_U_APCLOBE
 S APCLGRAN=APCLGRAN+1
 Q
CALCBMI ;calculate BMI value
 ;S APCLMWT=APCLCWT/2.21,APCLMHT=APCLCHT*.025,APCLBMI=APCLMWT/(APCLMHT*APCLMHT)
 S APCLMWT=APCLCWT*.45359,APCLMHT=APCLCHT*.0254,APCLBMI=APCLMWT/(APCLMHT*APCLMHT)
 Q
GETWTHT ;
 K APCLGHT,APCLGWT
 S APCLY="APCLGWT(",APCLX=DFN_"^ALL MEASUREMENT WT;DURING "_APCLBD_"-"_APCLDT S APCLER=$$START1^APCLDF(APCLX,APCLY)
 S X=0 F  S X=$O(APCLGWT(X)) Q:X'=+X  I '$P(APCLGWT(X),U,2) K APCLGWT(X)
 S APCLY="APCLGHT(",APCLX=DFN_"^ALL MEASUREMENT HT;DURING "_APCLHBD_"-"_APCLDT S APCLER=$$START1^APCLDF(APCLX,APCLY)
 S X=0 F  S X=$O(APCLGHT(X)) Q:X'=+X  I '$P(APCLGHT(X),U,2) K APCLGHT(X)
PN ;kill off those that have prenatal code as dx
 ;S X=0 F  S X=$O(APCLGWT(X)) Q:X'=+X  S V=$P(APCLGWT(X),U,5),P=0 F  S P=$O(^AUPNVPOV("AD",V,P)) Q:P'=+P  S D=$P(^ICD9($P(^AUPNVPOV(P,0),U),0),U) D  ;cmi/anch/maw 9/12/2007 orig line
 S X=0 F  S X=$O(APCLGWT(X)) Q:X'=+X  S V=$P(APCLGWT(X),U,5),P=0 F  S P=$O(^AUPNVPOV("AD",V,P)) Q:P'=+P  S D=$P($$ICDDX^ICDEX($P(^AUPNVPOV(P,0),U)),U,1) D  ;cmi/anch/maw 9/12/2007 csv
 .I $$ICD^AUPNVUTL(D,$O(^ATXAX("B","BGP PREGNANCY DIAGNOSES 2",0)),9) K APCLGWT(X) Q
 .Q
 ;S X=0 F  S X=$O(APCLGHT(X)) Q:X'=+X  S V=$P(APCLGHT(X),U,5),P=0 F  S P=$O(^AUPNVPOV("AD",V,P)) Q:P'=+P  S D=$P(^ICD9($P(^AUPNVPOV(P,0),U),0),U) D  ;cmi/anch/maw 9/12/2007 orig line
 S X=0 F  S X=$O(APCLGHT(X)) Q:X'=+X  S V=$P(APCLGHT(X),U,5),P=0 F  S P=$O(^AUPNVPOV("AD",V,P)) Q:P'=+P  S D=$P($$ICDDX^ICDEX($P(^AUPNVPOV(P,0),U)),U,1) D  ;cmi/anch/maw 9/12/2007 csv
 .I $$ICD^AUPNVUTL(D,$O(^ATXAX("B","BGP PREGNANCY DIAGNOSES 2",0)),9) K APCLGHT(X) Q
 .Q
RO ;set up by date
 K APCLROWT,APCLROHT
 S X=0 F  S X=$O(APCLGWT(X)) Q:X'=+X  S APCLROWT($P(APCLGWT(X),U))=X
 S X=0 F  S X=$O(APCLGHT(X)) Q:X'=+X  S APCLROHT($P(APCLGHT(X),U))=X
 Q
 ;
GETWHSD ;check for height and weight on same date
 ;reverse $O THRU APCLROWT & CHECK APCLROHT
 S X=9999999 F  S X=$O(APCLROWT(X),-1) Q:X=""!($D(APCLCHT))  I $D(APCLROHT(X)) S APCLCHT=$P(APCLGHT(APCLROHT(X)),U,2)_U_X,APCLCWT=$P(APCLGWT(APCLROWT(X)),U,2)_U_X
 Q
GETRECNT ;get most recent in 3 yrs
 S X=9999999,X=$O(APCLROWT(X),-1) Q:X=""  S APCLCWT=$P(APCLGWT(APCLROWT(X)),U,2)_U_X
 S X=9999999,X=$O(APCLROHT(X),-1) Q:X=""  S APCLCHT=$P(APCLGHT(APCLROHT(X)),U,2)_U_X
 Q