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

BEHOVM2.m

Go to the documentation of this file.
BEHOVM2 ;IHS/MSC/MGH - Triage: Vital Measurements ;23-Sep-2014 15:22;DU
 ;;1.1;BEH COMPONENTS;**001004,001005,001007,001009,001010**;Sep 18, 2007
 ;=================================================================
QUAL(RESULT,IEN,QUALS) ;EP Store the vitals qualifiers
 ;Entry data is the IEN of the measurment and the qualifiers separated by ~
 N BEHCNT,BEHERR,BEHFDA,BEHOKAY,BEHVIEN,BEHQUAL,VMSR,FNUM,F2NUM,QUALNAME
 S VMSR=$$VMSR
 S BEHCNT=0
 S FNUM=$S(VMSR:9000010.01,1:120.5)
 S F2NUM=$S(VMSR:9000010.015,1:120.505)
 I VMSR,'$D(^AUPNVMSR(+IEN,0))#2 S RESULT="-1^Vital entry Not Found" Q
 I 'VMSR,'$D(^GMR(120.5,+IEN,0))#2 S RESULT="-1^Vital entry Not Found" Q
 S QUALNAME="" F  S QUALNAME=$O(QUALS(QUALNAME)) Q:QUALNAME=""!(+$G(RESULT)<0)  D
 .;Find the qualifier
 .I +QUALNAME S BEHQUAL=QUALNAME
 .E  S BEHQUAL="" S BEHQUAL=$O(^GMRD(120.52,"B",QUALNAME,BEHQUAL)) I BEHQUAL="" S RESULT="-1^Cannot find qualifier" Q
 .; Is the qualifier already stored?
 .I 'VMSR,$O(^GMR(120.5,IEN,5,"B",BEHQUAL,0))>0 S RESULT="-1"  Q
 .I VMSR,$O(^AUPNVSMR(IEN,5,"B",BEHQUAL,0))>0 S RESULT="-1"  Q
 .; Legitimate Qualifier?
 .I '$D(^GMRD(120.52,BEHQUAL,0)) D  S RESULT=""  Q
 .S BEHCNT=BEHCNT+1
 .; Store the  qualifier
 .K BEHFDA,BEHOKAY,BEHERR
 .S BEHFDA(F2NUM,"+1,"_IEN_",",.01)=BEHQUAL
 .D UPDATE^DIE("","BEHFDA","BEHOKAY","BEHERR")
 .I $D(BEHERR) S RESULT="-1^Unable to store qualifier"
 .E  S RESULT=+$G(BEHOKAY(1))
 Q
PO2(RESULT,IEN,QUALS) ;Store data for O2 Saturation
 N QUAL,QUALNAME,VAL,O2,RESULT,FDA,FNUM,I
 S VAL=""
 S QUALNAME=$P(QUALS,"~",1)
 S QUAL(QUALNAME)=""
 D QUAL^BEHOVM2(.RESULT,IEN,.QUAL)
 S O2=""
 F I=2:1:3 D
 .S VAL=$P(QUALS,"~",I)
 .I VAL'="" S O2=$S(O2="":$P(VAL,";",1)_" "_$P(VAL,";",2),1:O2_" "_$P(VAL,";",1)_" "_$P(VAL,";",2))
 I VAL'="" D
 .S FNUM=9000010.01
 .S FDA=$NA(FDA(FNUM,IEN_","))
 .S @FDA@(1.4)=O2
 .S RESULT=$$UPDATE^BGOUTL(.FDA,"E")
 Q
EIE(RESULT,BEHDATA,TYPE) ; EP Store entered in error data
 ;BEHDATA CONSISTS OF THE FOLLOWING DATA:
 ;FILE IEN^DUZ^REASON
 ;If type=0 it is delete only, if type=1 its an edit
 N BEHFDA,BEHIEN,BEHIENS,BEHERR,FNUM,F2NUM,VMSR,TYPE
 S VMSR=$$VMSR
 S FNUM=$S(VMSR:9000010.01,1:120.5)
 S F2NUM=$S(VMSR:9000010.014,1:120.506)
 I VMSR,'$D(^AUPNVMSR(+BEHDATA,0))#2 S RESULT="ERROR: Record Not Found" Q
 I 'VMSR,'$D(^GMR(120.5,+BEHDATA,0))#2 S RESULT="ERROR: Record Not Found" Q
 S BEHIENS=(+BEHDATA)_","
 S BEHFDA(FNUM,BEHIENS,2)=1
 S BEHFDA(FNUM,BEHIENS,3)=$P(BEHDATA,"^",2)
 S BEHFDA(F2NUM,"+1,"_BEHIENS,.01)=$P(BEHDATA,"^",3)
 D UPDATE^DIE("","BEHFDA","BEHIEN","BEHERR")
 I $D(BEHIEN(1)) S RESULT="OK"
 D VFEVT^BEHOENPC(FNUM,+BEHDATA,1)
 I $D(BEHERR)>0 S RESULT="Unable to process entered in error"
 ;IHS/MSC/MGH EHR 13 See if it is a weight, If so check for BMI on same date and delete
 S CHK=$$GET1^DIQ(9000010.01,+BEHDATA,.01,"I")
 I $$GET1^DIQ(9999999.07,CHK,.01)="WT" D EIE^BEHOVM5(+BEHDATA)
 I $$GET1^DIQ(9999999.07,CHK,.01)="HT" D EIE^BEHOVM5(+BEHDATA)
 Q
GETCATS(RESULTS,VIT,LONG) ;EP Given a vital sign, return the categories for this VM and the default
 N BEHCAT,BEHQUAL,ID,ABB,VMSR,Y,CNT
 S RESULTS=$$TMPGBL
 S LONG=$G(LONG,0)
 S CNT=0
 S VMSR=$$VMSR
 S FNUM=$S(VMSR:9999999.07,1:120.51)
 S ID="" S ID=$O(^BEHOVM(90460.01,"B",VIT,ID))
 I ID="" S @RESULTS@(1)="No vital in BEH MEASUREMENT CONTROL FILE" Q
 S ABB=$P($G(^BEHOVM(90460.01,ID,0)),U,7) I ABB="" S @RESULTS@(1)="No abbreviation for vital in BEH MEASURMENT CONTROL FILE" Q
 I VMSR S IEN="" S IEN=$O(^AUTTMSR("B",ABB,IEN)) I IEN="" S @RESULTS@(1)="Unable to find MEASUREMENT TYPE in file" Q
 I 'VMSR S IEN="" S IEN=$O(^GMRD(120.51,"C",ABB,IEN)) I IEN="" S @RESULTS@(1)="Unable to find MEASUREMENT TYPE in file" Q
 ;Get all the qualifiers for this category
 I LONG D
 .F BEHCAT=0:0 S BEHCAT=$O(^GMRD(120.52,"AA",IEN,BEHCAT)) Q:'BEHCAT  D
 ..S CNT=CNT+1,@RESULTS@(CNT)="C"_U_BEHCAT_U_$P(^GMRD(120.53,BEHCAT,0),U)
 ..S BEHQUAL="",X="" F  S X=$O(^GMRD(120.52,"AA",IEN,BEHCAT,X)) Q:X=""  D
 ...S CNT=CNT+1
 ...S @RESULTS@(CNT)="Q"_U_$O(^GMRD(120.52,"AA",IEN,BEHCAT,X,0))_U_X
 ..;S Y=$O(@RESULTS@("").-1)+1
 ..;S @RESULTS@(Y)=BEHCAT
 E  D
 .F BEHCAT=0:0 S BEHCAT=$O(^GMRD(120.52,"AA",IEN,BEHCAT)) Q:'BEHCAT  D
 ..S BEHQUAL="",X="" F  S X=$O(^GMRD(120.52,"AA",IEN,BEHCAT,X)) Q:X=""  D
 ...S BEHQUAL=BEHQUAL_$S(BEHQUAL]"":"~",1:"")_X
 ..S Y=$O(@RESULTS@(""),-1)+1
 ..S @RESULTS@(Y)=BEHCAT_U_$P(^GMRD(120.53,BEHCAT,0),U)_U_BEHQUAL
 Q
QRYBMI(PCTILE) ;Moved from BEHOVM for space
 N VTWT,VTHT,RSWT,RSHT,BMI,WTDT
 S VTWT=$$VTYPE^BEHOVM("WT"),VTHT=$$VTYPE^BEHOVM("HT"),PCTILE=+$G(PCTILE)
 I 'VMSR D GMRBMI(PCTILE) Q
 D BLDXRF^BEHOVM(VTWT),BLDXRF^BEHOVM(VTHT)
 F  Q:'IDT!(RCNT=RMAX)  D
 .S VIEN=$C(1)
 .F  S VIEN=$O(^TMP("BEHOVM",$J,VTWT,IDT,VIEN),-1) Q:'VIEN  D  Q:RCNT=RMAX
 ..D GETMSR^BEHOVM(VIEN,.RSWT,.DATE,.LOC,.ENTERBY)
 ..;IHS/MSC/MGH Save the wt date to use if the ht isn't too old patch 4
 ..S QUALIF=""
 ..S WTDT=DATE
 ..S RSHT=$$FNDHT(IDT)
 ..Q:'RSHT
 ..S QUALIF=""
 ..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(VUNT)=BMI,RCNT=RCNT+1
 ..S DATE=WTDT
 ..D CALLBCK^BEHOVM
 .S IDT=$O(^TMP("BEHOVM",$J,VTWT,IDT))
 K ^TMP("BEHOVM",$J)
 Q
FNDHT(IDT) ;Find closest height before weight
 N VIEN,RESULT,DOB,SEX,TAGE,X,X2,X1,SX,APCHMDT,IDT2
 S VIEN=$O(^TMP("BEHOVM",$J,VTHT,IDT,""))
 I 'VIEN D
 .;IHS/MSC/MGH Added in HS logic for lookback days for ht. Patch 4
 .;Only allowed to look forward for the same date as the wt. Otherwise,
 .N ID1,ID2
 .S IDT2=9999999-IDT
 .S TAGE=$$PTAGE^BGOUTL(DFN,IDT2)
 .S DOB=$P(^DPT(DFN,0),U,3),SEX=$P(^DPT(DFN,0),U,2),SX=$S(SEX="M":2,SEX="F":3,1:"")
 .;X2=DOB,X1=DT D ^%DTC S TAGE=X
 .S ID1=$O(^TMP("BEHOVM",$J,VTHT,IDT),-1),ID2=$O(^TMP("BEHOVM",$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("BEHOVM",$J,VTHT,ID2,""))
 D:VIEN GETMSR^BEHOVM(VIEN,.RESULT)
 Q $G(RESULT)
 ; Compute BMI percentile
BMIPCT(BMI,DFN,DATE) ;
 N PCT,VAL,LP,DIF,DAT,X1,X2
 D PCTILE^BEHOVM("PCT",$$VCTL^BEHOVM("BMI"),DFN,DATE,DATE)
 S DIF=9999999
 F LP=0:0 S LP=$O(PCT(LP)) Q:'LP  D
 .S X1=PCT(LP),DAT=$P(X1,U,2),VAL(DAT,$P(X1,U,3))=$P(X1,U)
DD .S X1=$$FMDIFF^XLFDT(DATE,DAT),X1=$S(X1<0:-X1,1:X1)
 .S:X1<DIF DIF=X1,DIF(0)=DAT
 Q:DIF>30 0
 S DAT=DIF(0)
 Q:$D(VAL(DAT,BMI)) VAL(DAT,BMI)
 S X1=$O(VAL(DAT,BMI),-1),X2=$O(VAL(DAT,BMI))
 Q +$J($S('X1:1,'X2:100,1:(BMI-X1)/(X2-X1)*(VAL(DAT,X2)-VAL(DAT,X1))+VAL(DAT,X1)),0,1)
 ;RPC entry point to get units for a vital
 ;Input=vital measurement by name
 ;Return value = US unit^LO^HI^Metric unit^LO^HI
VUNITS(RET,VIT) ;EP
 Q:VIT=""
 S RET=""
 N VCTL
 S VCTL="" S VCTL=$O(^BEHOVM(90460.01,"B",VIT,VCTL))
 I VCTL="" Q "Unable to find vital "_VIT
 S RET=$$UNITS^BEHOVM(.VUNT)
 Q RET
TMPGBL(X) ;EP
 K ^TMP("BEHV"_$G(X),$J) Q $NA(^($J))
 ; Returns true if V file is used for vital measurements
VMSR() Q ''$$GET^XPAR("ALL","BEHOVM USE VMSR")
GMRBMI(PCTILE) ;Get BMI for sites using GMRV vitals
 N GBMI,QUALIFY,BMI
 S IDT=START,XREF="AA",VTYP=VTWT,QUALIFY=""
 F  S IDT=$O(^GMR(120.5,XREF,DFN,VTYP,IDT)) Q:'IDT!(RCNT=RMAX)  D
 .S VIEN=$C(1)
 .F  S VIEN=$O(^GMR(120.5,XREF,DFN,VTYP,IDT,VIEN),-1) Q:'VIEN  D  Q:RCNT=RMAX
 ..Q:$P($G(^GMR(120.5,VIEN,2)),U)  S X=$G(^(0))
 ..Q:$P(X,U,2)'=DFN
 ..Q:$P(X,U,3)'=VTYP
 ..I VSIT,+$G(^GMR(120.5,VIEN,9000010))'=VSIT Q
 ..S GBMI(2)=$$TRIM^XLFSTR($P(X,U,8)),DATE=+X,LOC=+$P(X,U,5)
 ..S GBMI(1)=DATE
 ..S WTDT=DATE,DATE(0)=DATE*10000\1/10000
 ..D CALBMI^GMRVBMI(.GBMI)
 ..I $D(GBMI)>10 D
 ...S BMI=GBMI
 ...S:PCTILE BMI=$$BMIPCT(BMI,DFN,DATE)
 ..E  S BMI=0
 ..Q:'BMI
 ..S RESULT(VUNT)=BMI,RCNT=RCNT+1
 ..S DATE=WTDT
 ..D CALLBCK^BEHOVM
 Q
GETCATP(RESULTS,VIEN) ;EP Given a vital sign and an IEN, return the categories for this VM and the default
 N BEHCAT,BEHQUAL,ID,ABB,VMSR,Y,CNT,FNUM2,CHK,QUALIEN
 S RESULTS=$$TMPGBL
 S CNT=0
 S VMSR=$$VMSR
 ;Get results for this IEN
 I VMSR D
 .S IEN=$P($G(^AUPNVMSR(VIEN,0)),U,1)
 .S QUALS=0 F  S QUALS=$O(^AUPNVMSR(VIEN,5,QUALS)) Q:'+QUALS  D
 ..S QUALIEN($P($G(^AUPNVMSR(VIEN,5,QUALS,0)),U,1))=""
 I 'VMSR D
 .S IEN=$P($G(^GMR(120.5,VIEN,0)),U,3)
 .S QUALS=0 F  S QUALS=$O(^GMR(120.5,VIEN,5,QUALS)) Q:QUALS=""  D
 ..S QUALIEN($P($G(^GMR(120.5,VIEN,5,QUALS,0)),U,1))=""
 ;Get all the qualifiers for this category
 F BEHCAT=0:0 S BEHCAT=$O(^GMRD(120.52,"AA",IEN,BEHCAT)) Q:'BEHCAT  D
 .S CNT=CNT+1,@RESULTS@(CNT)="C"_U_BEHCAT_U_$P(^GMRD(120.53,BEHCAT,0),U)
 .S BEHQUAL="",X="" F  S X=$O(^GMRD(120.52,"AA",IEN,BEHCAT,X)) Q:X=""  D
 ..S CNT=CNT+1
 ..S CHK=$O(^GMRD(120.52,"AA",IEN,BEHCAT,X,0))
 ..S @RESULTS@(CNT)="Q"_U_CHK_U_X
 ..I $D(QUALIEN(CHK)) S @RESULTS@(CNT)="Q"_U_CHK_U_X_U_1
 Q
PCTILE(DATA,VCTL,DFN,START,END,METRIC) ;EP  Moved from BEHOVM
 N I,X,DOB,SEX,AGE,L,M,S,P,D,Z,ID,V,C
 S METRIC=+$G(METRIC),X=$G(^DPT(+DFN,0)),SEX=$P(X,U,2),DOB=$P(X,U,3)
 Q:'$L(SEX)!'DOB
 S:METRIC<0 METRIC=$$DEFUNIT^BEHOVM(VCTL)
 S START=$$FMDIFF^XLFDT(START,DOB)/30-1
 S END=$$FMDIFF^XLFDT(END,DOB)/30+1
 S (I,C)=0
 F  S I=$O(^BEHOVM(90460.01,VCTL,3,I)) Q:'I  S X=^(I,0) D
 .S AGE=+$P(X,";",2)
 .Q:AGE<START!(AGE>END)!($P(X,";")'=SEX)
 .S L=$P(X,";",3),M=$P(X,";",4),S=$P(X,";",5),D=$$FMADD^XLFDT(DOB,AGE*30)
 .F P=2:1:10 D
 ..S ID=$P("3^5^10^25^50^75^85^90^95^97",U,P)  ;Added 85 in p11
 ..S Z=$P("-1.881^-1.645^-1.282^-0.674^0^0.674^1.036^1.282^1.645^1.881",U,P)
 ..I L S V=L*S*Z+1**(1/L)*M
 ..E  S V=2.71828183**(S*Z)*M
 ..S C=C+1,@DATA@(C)=ID_U_D_U_$S(METRIC:V,1:$$CONVERT^BEHOVM(V,1,0))
 Q