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

BTIUPCC6.m

Go to the documentation of this file.
BTIUPCC6 ; IHS/ITSC/LJF - IHS PCC OBJECTS ;15-Dec-2015 15:40;DU
 ;;1.0;TEXT INTEGRATION UTILITIES;**1006,1012,1013,1015,1015,1016**;NOV 04, 2004;Build 10
BMI(DFN,TIUCAP,NUM) ;EP -- returns BMI based on last ht and wt
 ; TIUCAP=1 if caption with measurement name is to be returned
 N VTWT,VTHT,RSWT,RSHT,BMI,WTDT,RMAX,X,IDT,HNUM,START,END,WNUM,IDATE,RCNT,DATE,WTDT,RESULT,LINE,APCHMDT
 ;S VTWT=$$VTYPE("WT"),VTHT=$$VTYPE("HT")
 S TIUCAP=$G(TIUCAP)
 S VTWT=$$VTYPE("BMI")
 K ^TMP("BTIUVM",$J),^TMP("BTIUPCC",$J)
 I '$D(NUM) S NUM=1
 S WNUM=NUM+2,HNUM=NUM+10,RMAX=NUM
 S START=DT+1,END=0
 S:START<END X=START,START=END,END=X
 S START=9999999-$S(START#1:START,1:START+.9),END=9999999-END
 S RCNT=0,IDT=START
 ;PCTILE=+G(PCTILE)
 ;D BLDXRF(VTWT,NUM),BLDXRF(VTHT,NUM)
 D BLDXRF(VTWT,NUM)
 F  Q:'IDT!(RCNT=RMAX)  D
 .S VIEN=$C(1)
 .F  S VIEN=$O(^TMP("BTIUVM",$J,VTWT,IDT,VIEN),-1) Q:'VIEN  D  Q:RCNT=RMAX
 ..D GETMSR(VIEN,.BMI,.DATE,.LOC,.ENTERBY)
 ..;IHS/MSC/MGH Save the wt date to use if the ht isn't too old patch 4
 ..;S WTDT=DATE
 ..;S RSHT=$$FNDHT(IDT)
 ..;Q:'RSHT
 ..;S RSWT=RSWT*.45359,RSHT=RSHT*.0254,RSHT=RSHT*RSHT,BMI=+$J(RSWT/RSHT,0,2)
 ..;S:PCTILE BMI=$$BMIPCT(BMI,DFN,DATE)
 ..;Q:'BMI
 ..S RESULT(IDT)=$J(BMI,5,2),RCNT=RCNT+1
 ..;S DATE=WTDT
 .S IDT=$O(^TMP("BTIUVM",$J,VTWT,IDT))
 S CNT=0
 S IDATE="" F  S IDATE=$O(RESULT(IDATE)) Q:IDATE=""!(CNT>NUM)  D
 .S BMI=$G(RESULT(IDATE))
 .S DATE=9999999-IDATE
 .I $$PREG^BTIUPCC6(DFN,"",VIEN)=1 S BMI=BMI_"*"
 .S DATE=$$FMTE^XLFDT(DATE)
 .S CNT=CNT+1
 .S LINE=BMI_" ("_$P(DATE,"@",1)_")"
 .I TIUCAP S Y=$S(CNT=1:"BMI:",1:$$SP(4)) S LINE=Y_" "_LINE
 .S ^TMP("BTIUPCC",$J,CNT,0)=LINE
 I '$D(^TMP("BTIUPCC",$J)) Q "No bmi stored"
 Q "~@^TMP(""BTIUPCC"",$J)"
FNDHT(IDT) ;Find closest height before weight
 N VIEN,RESULT,DOB,SEX,TAGE,X2,X1,SX
 S VIEN=$O(^TMP("BTIUVM",$J,VTHT,IDT,""))
 I 'VIEN D
 .;IHS/MSC/MGH Added in HS logic for lookback days for ht. Patch 4
 .N ID1,ID2,GOOD
 .S DOB=$P(^DPT(DFN,0),U,3),X2=DOB,X1=DT D ^%DTC S TAGE=X
 .S ID1=$O(^TMP("BTIUVM",$J,VTHT,IDT),-1),ID2=$O(^TMP("BTIUVM",$J,VTHT,IDT))
 .I ID1 D
 ..S X1=$P(ID1,".",1),X2=$P(IDT,".",1)
 ..I X1=X2 S ID2=ID1
 .I ID2 D
 ..S X1=9999999-(ID2\1)
 ..S APCHMDT=$$FMDIFF^XLFDT(X1,DOB,1)
 ..S X1=9999999-(IDT\1),X2=9999999-ID2
 ..S X=$$FMDIFF^XLFDT(X1,X2,1)
 ..I ((X>90)&(APCHMDT<1096))!((X>180)&(APCHMDT<4381))!((X>365)&(APCHMDT<6571))!((APCHMDT<6571)&(TAGE>6571)) S ID2=""
 ..S:ID2 VIEN=$O(^TMP("BTIUVM",$J,VTHT,ID2,""))
 D:VIEN GETMSR(VIEN,.RESULT)
 Q $G(RESULT)
GETMSR(VIEN,RESULT,DATE,LOC,ENTERBY) ;
 N X,X12
 S X=$G(^AUPNVMSR(VIEN,0)),X12=$G(^(12))
 S DATE=+X12,ENTERBY=+$P(X12,U,4)
 S RESULT=$$TRIM^XLFSTR($P(X,U,4)),X=+$P(X,U,3)
 S X=$G(^AUPNVSIT(X,0))
 S:'DATE DATE=+X
 S LOC=+$P(X,U,22),DATE(0)=DATE*10000\1/10000
 Q
 ; Build temp xref for measurement type
BLDXRF(VTYP,VNUM) ;
 N X,Y,Z,CNT
 S X=0
 K ^TMP("BTIUVM",$J,VTYP)
 S CNT=0
 F  S X=$O(^AUPNVMSR("AA",DFN,VTYP,X)),VIEN=0 Q:'X!(CNT>VNUM)  D
 .F  S VIEN=$O(^AUPNVMSR("AA",DFN,VTYP,X,VIEN)) Q:'VIEN  D
 ..S Z=$G(^AUPNVMSR(VIEN,0)),Y=+$G(^(12)),Y=$S(Y:9999999-Y,1:X)
 ..Q:+Z'=VTYP
 ..Q:$P(Z,U,2)'=DFN
 ..S CNT=CNT+1
 ..S ^TMP("BTIUVM",$J,VTYP,Y,VIEN)=""
 Q
VTYPE(X,VMSR) ;
 N FNUM
 S:'$D(VMSR) VMSR=$$VMSR
 S FNUM=$S(VMSR:9999999.07,1:120.51)
 Q +$$FIND1^DIC(FNUM,"","X",$$UP^XLFSTR(X),"B^"_$S(VMSR:"D",1:"APCE^C"))
PREG(DFN,VIEN,VMIEN) ;Determine if BMI is for pregnant patient
 ;Patch 1015 went back to using the ATX API after changes made
 N DOB,X1,X1,TAGE,POV,CODE,TAX,RET,ARRAY
 S RET=0
 S VMIEN=$G(VMIEN),VIEN=$G(VIEN)
 I $$GET1^DIQ(2,DFN,.02,"I")'="F" Q RET    ;Wrong sex
 S TAGE=$$GET1^DIQ(2,DFN,.033)
 I TAGE<10!(TAGE>50) Q RET             ;Wrong age
 ;Find POVs on this visit and check if they are pregnancy POVs
 I VIEN="" D
 .S VIEN=$$GET1^DIQ(9000010.01,VMIEN,.03,"I")
 I '+VIEN Q RET
 S TAX=$O(^ATXAX("B","BQI PREGNANCY DXS",0))
 S POV="" F  S POV=$O(^AUPNVPOV("AD",VIEN,POV)) Q:POV=""!(RET=1)  D
 .S CODE=$$GET1^DIQ(9000010.07,POV,.01,"I")
 .I CODE="" Q
 .S RET=$$ICD^ATXAPI(CODE,TAX,9)
 Q RET
EXAMCMT(DFN,TARGET,CODE) ; Returns the last exam with comments
 NEW EXAM,DATE,RESULT,N,SUB,CNT,MAXLEN,COMM,TXT2,SUBCOUNT,SUBLINE
 K @TARGET
 S MAXLEN=60,CNT=0
 S SUB=$S($L(CODE)=2:"C",1:"B")  ;was code or name sent
 S EXAM=$O(^AUTTEXAM(SUB,CODE,0)) I EXAM="" Q ""
 S DATE=$O(^AUPNVXAM("AA",+$G(DFN),EXAM,0)) I DATE="" Q "None Found"
 S RESULT="Date: "_$$FMTE^XLFDT(9999999-DATE,"D")
 S N=$O(^AUPNVXAM("AA",DFN,EXAM,DATE,0)) I 'N Q RESULT_" Results: No Results"
 S CNT=CNT+1
 S @TARGET@(CNT,0)=RESULT_" Results: "_$$GET1^DIQ(9000010.13,N,.04)
 S COMM=$$GET1^DIQ(9000010.13,N,81101)
 I $L(COMM)>MAXLEN D
 .S TXT2=$$WRAP^TIULS(COMM,MAXLEN)
 .F SUBCOUNT=1:1 S SUBLINE=$P(TXT2,"|",SUBCOUNT) Q:SUBLINE=""  D ADD2(SUBLINE)
 E  D ADD2(COMM)
 Q "~@"_$NA(@TARGET)
 ;
ADD2(TXT) ;
 S CNT=CNT+1
 S @TARGET@(CNT,0)=TXT
 Q
 ; Returns true if V file is used for vital measurements
VMSR() Q ''$$GET^XPAR("ALL","BEHOVM USE VMSR")
PAD(DATA,LENGTH) ; -- SUBRTN to pad length of data
 Q $E(DATA_$$REPEAT^XLFSTR(" ",LENGTH),1,LENGTH)
 ;
SP(NUM) ; -- SUBRTN to pad spaces
 Q $$PAD(" ",NUM)