BGOVMSR ; IHS/BAO/TMD - Manage V MEASUREMENTs ;17-Oct-2013 13:57;DU
;;1.1;BGO COMPONENTS;**1,3,13**;Mar 20, 2007
; Return most recent vitals
; INP = Patient IEN ^ Vital Types ^ Visit IEN
; .RET = List of records of format:
; Type Name [1] ^ Value [2] ^ Date/Time [3] ^ V File IEN [4] ^ Visit IEN [5]
LAST(RET,INP) ;EP
N DFN,TYPE,TYPESET,VIEN,CNT,TYPENM,IDT,IEN,X,DAT,FND,VSIT
K RET
S DFN=+INP
I 'DFN S RET(1)=$$ERR^BGOUTL(1050) Q
S TYPESET=$P(INP,U,2)
S:'$L(TYPESET) TYPESET="HT;WT;TMP;BP;PU;RS;PA"
S TYPESET=";"_TYPESET_";"
S VIEN=$P(INP,U,3)
S (TYPE,CNT)=0
F S TYPE=$O(^AUPNVMSR("AA",DFN,TYPE)) Q:'TYPE D
.S TYPENM=$P($G(^AUTTMSR(TYPE,0)),U)
.Q:TYPENM=""
.Q:TYPESET'[(";"_TYPENM_";")
.S (FND,IDT)=0
.F S IDT=$O(^AUPNVMSR("AA",DFN,TYPE,IDT)) Q:'IDT D Q:FND
..S IEN=0
..F S IEN=$O(^AUPNVMSR("AA",DFN,TYPE,IDT,IEN)) Q:'IEN D Q:FND
...S X=$G(^AUPNVMSR(IEN,0)),DAT=+$G(^(12))
...S VSIT=+$P(X,U,3)
...I VIEN,VSIT'=VIEN Q
...S:'DAT DAT=+$G(^AUPNVSIT(VSIT,0))
...S CNT=CNT+1,FND=1
...S RET(CNT)=TYPENM_U_$P(X,U,4)_U_$$CDT(DAT)_U_IEN_U_VSIT_U_$$ISLOCKED^BEHOENCX(VSIT)
Q
; Returns vital measurements for current visit context in a single string
TIUSTR() ;EP
N X,Y
S X=$$GETVAR^CIANBUTL("ENCOUNTER.ID.ALTERNATEVISITID",,"CONTEXT.ENCOUNTER")
I X="" Q " "
S X=$$VSTR2VIS^BEHOENCX(DFN,X)
I X<1 Q " "
D GET(.X,X_"^1")
Q $G(X)
;
; Return vital measurements for a visit
; INP = Visit IEN ^ Format (0=multiline, 1=single string)
; Returned as:
; Single line format: concatenated string of measurement results
; Multiple line format:
; Type Name [1] ^ Value [2] ^ Date [3] ^ VFile IEN [4] ^ Visit IEN [5] ^
; Encounter Provider Name [6] ^ Visit Locked [7]
GET(RET,INP) ; EP
N VIEN,VFIEN,CNT,FORMAT
K RET
S VIEN=+INP
I 'VIEN S RET(1)=$$ERR^BGOUTL(1002) Q
S FORMAT=$P(INP,U,2)
S (VFIEN,CNT)=0
F S VFIEN=$O(^AUPNVMSR("AD",VIEN,VFIEN)) Q:'VFIEN D
.N X,USR,DAT,TYPE,TYPENM
.S X=$G(^AUPNVMSR(VFIEN,0)),DAT=+$G(^(12)),USR=+$P($G(^(12)),U,4)
.Q:X=""
.S TYPE=+X
.S TYPENM=$P($G(^AUTTMSR(TYPE,0)),U)
.Q:TYPENM=""
.S CNT=CNT+1
.I FORMAT D
..N MSRSTR
..S MSRSTR=TYPENM_":"_$P(X,U,4)
..I TYPENM="WT" S MSRSTR=MSRSTR_" ("_($P(X,U,4)*.45359\1)_" kg)"
..I TYPENM="HT" S MSRSTR=MSRSTR_" ("_($P(X,U,4)*2.54\1)_" cm)"
..I TYPENM="TMP" S MSRSTR=MSRSTR_" ("_(((10*($P(X,U,4)-32/1.8))\1)/10)_" C)"
..S RET(1)=$S(CNT=1:"",1:RET(1)_", ")_MSRSTR
.E D
..N NAME
..S NAME=$P($G(^VA(200,USR,0)),U)
..S:'DAT DAT=+$G(^AUPNVSIT(VIEN,0))
..S RET(CNT)=TYPENM_U_$P(X,U,4)_U_$$CDT(DAT)_U_VFIEN_U_$P(X,U,3)_U_NAME_U_$$ISLOCKED^BEHOENCX(VIEN)
Q
; Format date for display
CDT(X) N Y,TM
Q:'X ""
S Y=$$FMTDATE^BGOUTL(X)
S TM=X#1*10000\1
Q:'TM Y
S TM=TM+10000
Q Y_"@"_$E(TM,2,3)_":"_$E(TM,4,5)
; Return list of vital types
; Return format:
; IEN [1] ^ Abbreviation [2] ^ Name [3] ^ Code [4]
GETTYPES(RET,DUMMY) ;EP
N NAME,CODE,ABBR,REC,CNT,IEN
K RET
S (IEN,CNT)=0
F S IEN=$O(^AUTTMSR(IEN)) Q:'IEN D
.S REC=$G(^AUTTMSR(IEN,0))
.Q:REC=""
.Q:$P(REC,U,4)
.S ABBR=$P(REC,U)
.S NAME=$P(REC,U,2)
.Q:NAME["INACTIVE"
.S CODE=$P(REC,U,3)
.S CNT=CNT+1
.S RET(CNT)=IEN_U_ABBR_U_NAME_U_CODE
Q
; Add/edit V Measurement entry
; INP = Visit IEN [1] ^ V File IEN [2] ^ Type [3] ^ Value [4] ^ Date/Time [5]
SET(RET,INP) ;EP
N VIEN,TYPE,VFIEN,VFNEW,VAL,DAT,FDA,FNUM
S FNUM=$$FNUM
S VIEN=+INP
S RET=$$CHKVISIT^BGOUTL(VIEN)
Q:RET
S VFIEN=$P(INP,U,2)
I VFIEN,$P($G(^AUPNVMSR(VFIEN,12)),U,4),$P(^(12),U,4)'=DUZ S RET=$$ERR^BGOUTL(1086,$P($G(^VA(200,$P(^(12),U,4),0)),U)) Q
S VFNEW='VFIEN
S TYPE=$P(INP,U,3)
S:TYPE'=+TYPE TYPE=$O(^AUTTMSR("B",TYPE,0))
I 'TYPE S RET=$$ERR^BGOUTL(1087) Q
S VAL=$P(INP,U,4)
S DAT=$$CVTDATE^BGOUTL($P(INP,U,5))
I 'VFIEN D Q:'VFIEN
.N FLDS
.S FLDS(.04)=VAL
.D VFNEW^BGOUTL2(.RET,FNUM,TYPE,VIEN,,.FLDS)
.S:RET>0 VFIEN=RET,RET=""
S FDA=$NA(FDA(FNUM,VFIEN_","))
S @FDA@(.01)="`"_TYPE
S @FDA@(.04)=VAL
I VFNEW D
.S @FDA@(1216)="N"
.S @FDA@(1217)="`"_DUZ
S @FDA@(1218)="N"
S @FDA@(1219)="`"_DUZ
S @FDA@(1201)=$S(DAT:DAT,1:"N")
S @FDA@(.07)=$S(DAT:DAT,1:"N")
S @FDA@(1204)="`"_DUZ
S @FDA@(.08)="`"_DUZ
S RET=$$UPDATE^BGOUTL(.FDA,"E")
I RET,VFNEW,$$DELETE^BGOUTL(FNUM,VFIEN)
D:'RET VFEVT^BGOUTL2(FNUM,VFIEN,'VFNEW)
S:'RET RET=VFIEN
Q
; Delete a V Measurement entry
DEL(RET,VFIEN) ;EP
D VFDEL^BGOUTL2(.RET,$$FNUM,VFIEN)
Q
; Return V File #
FNUM() Q 9000010.01
BGOVMSR ; IHS/BAO/TMD - Manage V MEASUREMENTs ;17-Oct-2013 13:57;DU
+1 ;;1.1;BGO COMPONENTS;**1,3,13**;Mar 20, 2007
+2 ; Return most recent vitals
+3 ; INP = Patient IEN ^ Vital Types ^ Visit IEN
+4 ; .RET = List of records of format:
+5 ; Type Name [1] ^ Value [2] ^ Date/Time [3] ^ V File IEN [4] ^ Visit IEN [5]
LAST(RET,INP) ;EP
+1 NEW DFN,TYPE,TYPESET,VIEN,CNT,TYPENM,IDT,IEN,X,DAT,FND,VSIT
+2 KILL RET
+3 SET DFN=+INP
+4 IF 'DFN
SET RET(1)=$$ERR^BGOUTL(1050)
QUIT
+5 SET TYPESET=$PIECE(INP,U,2)
+6 IF '$LENGTH(TYPESET)
SET TYPESET="HT;WT;TMP;BP;PU;RS;PA"
+7 SET TYPESET=";"_TYPESET_";"
+8 SET VIEN=$PIECE(INP,U,3)
+9 SET (TYPE,CNT)=0
+10 FOR
SET TYPE=$ORDER(^AUPNVMSR("AA",DFN,TYPE))
IF 'TYPE
QUIT
Begin DoDot:1
+11 SET TYPENM=$PIECE($GET(^AUTTMSR(TYPE,0)),U)
+12 IF TYPENM=""
QUIT
+13 IF TYPESET'[(";"_TYPENM_";")
QUIT
+14 SET (FND,IDT)=0
+15 FOR
SET IDT=$ORDER(^AUPNVMSR("AA",DFN,TYPE,IDT))
IF 'IDT
QUIT
Begin DoDot:2
+16 SET IEN=0
+17 FOR
SET IEN=$ORDER(^AUPNVMSR("AA",DFN,TYPE,IDT,IEN))
IF 'IEN
QUIT
Begin DoDot:3
+18 SET X=$GET(^AUPNVMSR(IEN,0))
SET DAT=+$GET(^(12))
+19 SET VSIT=+$PIECE(X,U,3)
+20 IF VIEN
IF VSIT'=VIEN
QUIT
+21 IF 'DAT
SET DAT=+$GET(^AUPNVSIT(VSIT,0))
+22 SET CNT=CNT+1
SET FND=1
+23 SET RET(CNT)=TYPENM_U_$PIECE(X,U,4)_U_$$CDT(DAT)_U_IEN_U_VSIT_U_$$ISLOCKED^BEHOENCX(VSIT)
End DoDot:3
IF FND
QUIT
End DoDot:2
IF FND
QUIT
End DoDot:1
+24 QUIT
+25 ; Returns vital measurements for current visit context in a single string
TIUSTR() ;EP
+1 NEW X,Y
+2 SET X=$$GETVAR^CIANBUTL("ENCOUNTER.ID.ALTERNATEVISITID",,"CONTEXT.ENCOUNTER")
+3 IF X=""
QUIT " "
+4 SET X=$$VSTR2VIS^BEHOENCX(DFN,X)
+5 IF X<1
QUIT " "
+6 DO GET(.X,X_"^1")
+7 QUIT $GET(X)
+8 ;
+9 ; Return vital measurements for a visit
+10 ; INP = Visit IEN ^ Format (0=multiline, 1=single string)
+11 ; Returned as:
+12 ; Single line format: concatenated string of measurement results
+13 ; Multiple line format:
+14 ; Type Name [1] ^ Value [2] ^ Date [3] ^ VFile IEN [4] ^ Visit IEN [5] ^
+15 ; Encounter Provider Name [6] ^ Visit Locked [7]
GET(RET,INP) ; EP
+1 NEW VIEN,VFIEN,CNT,FORMAT
+2 KILL RET
+3 SET VIEN=+INP
+4 IF 'VIEN
SET RET(1)=$$ERR^BGOUTL(1002)
QUIT
+5 SET FORMAT=$PIECE(INP,U,2)
+6 SET (VFIEN,CNT)=0
+7 FOR
SET VFIEN=$ORDER(^AUPNVMSR("AD",VIEN,VFIEN))
IF 'VFIEN
QUIT
Begin DoDot:1
+8 NEW X,USR,DAT,TYPE,TYPENM
+9 SET X=$GET(^AUPNVMSR(VFIEN,0))
SET DAT=+$GET(^(12))
SET USR=+$PIECE($GET(^(12)),U,4)
+10 IF X=""
QUIT
+11 SET TYPE=+X
+12 SET TYPENM=$PIECE($GET(^AUTTMSR(TYPE,0)),U)
+13 IF TYPENM=""
QUIT
+14 SET CNT=CNT+1
+15 IF FORMAT
Begin DoDot:2
+16 NEW MSRSTR
+17 SET MSRSTR=TYPENM_":"_$PIECE(X,U,4)
+18 IF TYPENM="WT"
SET MSRSTR=MSRSTR_" ("_($PIECE(X,U,4)*.45359\1)_" kg)"
+19 IF TYPENM="HT"
SET MSRSTR=MSRSTR_" ("_($PIECE(X,U,4)*2.54\1)_" cm)"
+20 IF TYPENM="TMP"
SET MSRSTR=MSRSTR_" ("_(((10*($PIECE(X,U,4)-32/1.8))\1)/10)_" C)"
+21 SET RET(1)=$SELECT(CNT=1:"",1:RET(1)_", ")_MSRSTR
End DoDot:2
+22 IF '$TEST
Begin DoDot:2
+23 NEW NAME
+24 SET NAME=$PIECE($GET(^VA(200,USR,0)),U)
+25 IF 'DAT
SET DAT=+$GET(^AUPNVSIT(VIEN,0))
+26 SET RET(CNT)=TYPENM_U_$PIECE(X,U,4)_U_$$CDT(DAT)_U_VFIEN_U_$PIECE(X,U,3)_U_NAME_U_$$ISLOCKED^BEHOENCX(VIEN)
End DoDot:2
End DoDot:1
+27 QUIT
+28 ; Format date for display
CDT(X) NEW Y,TM
+1 IF 'X
QUIT ""
+2 SET Y=$$FMTDATE^BGOUTL(X)
+3 SET TM=X#1*10000\1
+4 IF 'TM
QUIT Y
+5 SET TM=TM+10000
+6 QUIT Y_"@"_$EXTRACT(TM,2,3)_":"_$EXTRACT(TM,4,5)
+7 ; Return list of vital types
+8 ; Return format:
+9 ; IEN [1] ^ Abbreviation [2] ^ Name [3] ^ Code [4]
GETTYPES(RET,DUMMY) ;EP
+1 NEW NAME,CODE,ABBR,REC,CNT,IEN
+2 KILL RET
+3 SET (IEN,CNT)=0
+4 FOR
SET IEN=$ORDER(^AUTTMSR(IEN))
IF 'IEN
QUIT
Begin DoDot:1
+5 SET REC=$GET(^AUTTMSR(IEN,0))
+6 IF REC=""
QUIT
+7 IF $PIECE(REC,U,4)
QUIT
+8 SET ABBR=$PIECE(REC,U)
+9 SET NAME=$PIECE(REC,U,2)
+10 IF NAME["INACTIVE"
QUIT
+11 SET CODE=$PIECE(REC,U,3)
+12 SET CNT=CNT+1
+13 SET RET(CNT)=IEN_U_ABBR_U_NAME_U_CODE
End DoDot:1
+14 QUIT
+15 ; Add/edit V Measurement entry
+16 ; INP = Visit IEN [1] ^ V File IEN [2] ^ Type [3] ^ Value [4] ^ Date/Time [5]
SET(RET,INP) ;EP
+1 NEW VIEN,TYPE,VFIEN,VFNEW,VAL,DAT,FDA,FNUM
+2 SET FNUM=$$FNUM
+3 SET VIEN=+INP
+4 SET RET=$$CHKVISIT^BGOUTL(VIEN)
+5 IF RET
QUIT
+6 SET VFIEN=$PIECE(INP,U,2)
+7 IF VFIEN
IF $PIECE($GET(^AUPNVMSR(VFIEN,12)),U,4)
IF $PIECE(^(12),U,4)'=DUZ
SET RET=$$ERR^BGOUTL(1086,$PIECE($GET(^VA(200,$PIECE(^(12),U,4),0)),U))
QUIT
+8 SET VFNEW='VFIEN
+9 SET TYPE=$PIECE(INP,U,3)
+10 IF TYPE'=+TYPE
SET TYPE=$ORDER(^AUTTMSR("B",TYPE,0))
+11 IF 'TYPE
SET RET=$$ERR^BGOUTL(1087)
QUIT
+12 SET VAL=$PIECE(INP,U,4)
+13 SET DAT=$$CVTDATE^BGOUTL($PIECE(INP,U,5))
+14 IF 'VFIEN
Begin DoDot:1
+15 NEW FLDS
+16 SET FLDS(.04)=VAL
+17 DO VFNEW^BGOUTL2(.RET,FNUM,TYPE,VIEN,,.FLDS)
+18 IF RET>0
SET VFIEN=RET
SET RET=""
End DoDot:1
IF 'VFIEN
QUIT
+19 SET FDA=$NAME(FDA(FNUM,VFIEN_","))
+20 SET @FDA@(.01)="`"_TYPE
+21 SET @FDA@(.04)=VAL
+22 IF VFNEW
Begin DoDot:1
+23 SET @FDA@(1216)="N"
+24 SET @FDA@(1217)="`"_DUZ
End DoDot:1
+25 SET @FDA@(1218)="N"
+26 SET @FDA@(1219)="`"_DUZ
+27 SET @FDA@(1201)=$SELECT(DAT:DAT,1:"N")
+28 SET @FDA@(.07)=$SELECT(DAT:DAT,1:"N")
+29 SET @FDA@(1204)="`"_DUZ
+30 SET @FDA@(.08)="`"_DUZ
+31 SET RET=$$UPDATE^BGOUTL(.FDA,"E")
+32 IF RET
IF VFNEW
IF $$DELETE^BGOUTL(FNUM,VFIEN)
+33 IF 'RET
DO VFEVT^BGOUTL2(FNUM,VFIEN,'VFNEW)
+34 IF 'RET
SET RET=VFIEN
+35 QUIT
+36 ; Delete a V Measurement entry
DEL(RET,VFIEN) ;EP
+1 DO VFDEL^BGOUTL2(.RET,$$FNUM,VFIEN)
+2 QUIT
+3 ; Return V File #
FNUM() QUIT 9000010.01