ORRCVIT ;SLC/MKB - Vitals utilities ; 25 Jul 2003 9:31 AM
;;1.0;CARE MANAGEMENT;;Jul 15, 2003
;
; ID = "VIT:"_PatientID_;_MeasurementDate everywhere below
;
LIST(ORY,DFN,SDATE,EDATE,VALS) ; -- Return MAX sets of measurements for DFN
; in @ORY@(#) = Item=ID^^MeasurementDate in HL7 format, and if VALS
; = Data=Vital^Value^Unit^MetricValue^Unit^BMI^SuppO2^CriticalFlag^Qualifiers
; RPC = ORRC VITALS BY PATIENT
N ORN,GMRVSTR,CNT,IDT,VDT,TYPE,IFN,DATA,X K ^UTILITY($J,"GMRVD")
S SDATE=$$HL7TFM^XLFDT($G(SDATE)),EDATE=$$HL7TFM^XLFDT($G(EDATE))
S DFN=+$G(DFN),MAX=$S(SDATE&EDATE:100,1:5)
I $G(EDATE),$L(EDATE,".")<2 S EDATE=EDATE_".2359"
S GMRVSTR="BP;T;R;P;HT;WT;CVP;CG;PO2;PN",GMRVSTR(0)=SDATE_U_EDATE_U_MAX_"^1"
D EN1^GMRVUT0 S ORY=$NA(^TMP($J,"ORRCVIT")),(ORN,CNT)=0 K @ORY
S IDT=0 F S IDT=$O(^UTILITY($J,"GMRVD",IDT)) Q:IDT<1 D Q:CNT'<MAX
. S VDT=9999999-IDT,CNT=CNT+1
. S ORN=ORN+1,@ORY@(ORN)="Item=VIT:"_DFN_";"_VDT_U_U_VDT Q:'$G(VALS)
. S TYPE="" F S TYPE=$O(^UTILITY($J,"GMRVD",IDT,TYPE)) Q:TYPE="" D
.. S IFN=0 F S IFN=$O(^UTILITY($J,"GMRVD",IDT,TYPE,IFN)) Q:IFN<1 S X=$G(^(IFN)) D
... D @TYPE ;return DATA w/relevant pieces
... S ORN=ORN+1,@ORY@(ORN)="Data="_DATA
K ^UTILITY($J,"GMRVD")
Q
;
DETAIL(ORY,VITAL) ; -- Return details of VITALs
; where VITAL(#) = ID
; in @ORY@(#) = Item=ID^^MeasurementDate in HL7 format
; = Data=Vital^Value^Unit^MetricValue^Unit^BMI^SuppO2^CriticalFlag^Qualifiers
; RPC = ORRC VITALS BY ID
N GMRVSTR,DFN,STRT,STOP,ORN,ORI,ID,IDT,VDT,TYPE,IFN,DATA,X
K ^UTILITY($J,"GMRVD") D RANGE
S GMRVSTR="BP;T;R;P;HT;WT;CVP;CG;PO2;PN",GMRVSTR(0)=STRT_U_STOP_"^100^1"
D EN1^GMRVUT0 S ORY=$NA(^TMP($J,"ORRCVIT")),ORN=0 K @ORY
S ORI=0 F S ORI=$O(VITAL(ORI)) Q:ORI<1 S ID=$G(VITAL(ORI)) D
. S VDT=$P(ID,";",2),IDT=9999999-VDT
. S ORN=ORN+1,@ORY@(ORN)="Item="_ID_U_U_VDT
. S TYPE="" F S TYPE=$O(^UTILITY($J,"GMRVD",IDT,TYPE)) Q:TYPE="" D
.. S IFN=0 F S IFN=$O(^UTILITY($J,"GMRVD",IDT,TYPE,IFN)) Q:IFN<1 S X=$G(^(IFN)) D
... D @TYPE ;return DATA w/relevant pieces
... S ORN=ORN+1,@ORY@(ORN)="Data="_DATA
K ^UTILITY($J,"GMRVD")
Q
;
RANGE ; -- Get STRT,STOP,DFN from VITALs
N ORI,ID,VDT S (STRT,STOP)=""
S ORI=0 F S ORI=$O(VITAL(ORI)) Q:ORI<1 S ID=$G(VITAL(ORI)) D
. S DFN=+$P(ID,":",2),VDT=$P(ID,";",2)
. I $S('$L(STRT):1,VDT<STRT:1,1:0) S STRT=VDT
. I $S('$L(STOP):1,VDT>STOP:1,1:0) S STOP=VDT
Q
;
; Return formatted DATA string from X:
;
BP ; -- Blood Pressure = B/P^value^^^^^^[*]^Q1;..;Qn
S DATA="B/P^"_$P(X,U,8)_"^^^^^^"_$P(X,U,12)_U_$P(X,U,17)
Q
T ; -- Temperature = Temp.^value^F^metric^C^^^[*]^Q1;..;Qn
S DATA="Temp.^"_$P(X,U,8)_"^F^"_$P(X,U,13)_"^C^^^"_$P(X,U,12)_U_$P(X,U,17)
Q
R ; -- Respiration = Resp.^value^^^^^^[*]^Q1;..;Qn
S DATA="Resp.^"_$P(X,U,8)_"^^^^^^"_$P(X,U,12)_U_$P(X,U,17)
Q
P ; -- Pulse = Pulse^value^^^^^^[*]^Q1;..;Qn
S DATA="Pulse^"_$P(X,U,8)_"^^^^^^"_$P(X,U,12)_U_$P(X,U,17)
Q
HT ; -- Height = Ht.^value^in^metric^cm^^^[*]^Q1;..;Qn
S DATA="Ht.^"_$P(X,U,8)_"^in^"_$P(X,U,13)_"^cm^^^"_$P(X,U,12)_U_$P(X,U,17)
Q
WT ; -- Weight = Wt.^value^lb^metric^kg^BodyMassIndex^^[*]^Q1;..;Qn
S DATA="Wt.^"_$P(X,U,8)_"^lb^"_$P(X,U,13)_"^kg^"_$P(X,U,14)_U_U_$P(X,U,12)_U_$P(X,U,17)
Q
CVP ; -- CenVenPress = CVP^value^cmH2O^^^^^[*]^Q1;..;Qn
S DATA="CVP^"_$P(X,U,8)_"^cmH2O^^^^^"_$P(X,U,12)_U_$P(X,U,17)
Q
CG ; -- Circm/Girth = C/G^value^in^metric^cm^^^[*]^Q1;..;Qn
S DATA="C/G^"_$P(X,U,8)_"^in^"_$P(X,U,13)_"^cm^^^"_$P(X,U,12)_U_$P(X,U,17)
Q
PO2 ; -- PulseOx = Pulse Ox^value^^^^^l/min of supplemental O2^[*]^Q1;..;Qn
S DATA="Pulse Ox^"_$P(X,U,8)_"^^^^^"_$P(X,U,15)_U_$P(X,U,12)_U_$P(X,U,17)
Q
PN ; -- Pain = Pain^value^^^^^^[*]^Q1;..;Qn
S DATA="Pain^"_$P(X,U,8)_"^^^^^^"_$P(X,U,12)_U_$P(X,U,17)
Q
;
IDS(ORY,DFN,SDATE,EDATE) ; --Return recent measurement IDs for DFN
; in @ORY@(DFN) = #sets ^ 1 if any are critical
; @ORY@(DFN,ID) = * if critical, else null
; [from ORRCDPT1]
N GMRVSTR,MAX,CNT,ABN,IDT,VDT,X
S ORY=$NA(^TMP($J,"ORRCVIT")) K @ORY,^UTILITY($J,"GMRVD")
S DFN=+$G(DFN),MAX=$S($G(SDATE)&$G(EDATE):100,1:5)
I $G(EDATE),$L(EDATE,".")<2 S EDATE=EDATE_".2359" ;end of day
S GMRVSTR="BP;T;R;P;HT;WT;CVP;CG;PO2;PN",GMRVSTR(0)=$G(SDATE)_U_$G(EDATE)_U_MAX_"^1"
D EN1^GMRVUT0 S CNT=0,ABN=""
S IDT=0 F S IDT=$O(^UTILITY($J,"GMRVD",IDT)) Q:IDT<1 D Q:CNT'<MAX
. S VDT=9999999-IDT,CNT=CNT+1,X=$$ABN(IDT)
. S @ORY@(DFN,"VIT:"_DFN_";"_VDT)=X S:$L(X) ABN=1
S:CNT @ORY@(DFN)=CNT_U_ABN
K ^UTILITY($J,"GMRVD")
Q
;
ABN(IDT) ; -- Return * if any value from measurement set is critical, else null
N Y,TYPE,IFN S Y=""
S TYPE="" F S TYPE=$O(^UTILITY($J,"GMRVD",IDT,TYPE)) Q:TYPE="" D
. S IFN=0 F S IFN=$O(^UTILITY($J,"GMRVD",IDT,TYPE,IFN)) Q:IFN<1 S:$G(^(IFN))["*" Y="*"
Q Y
ORRCVIT ;SLC/MKB - Vitals utilities ; 25 Jul 2003 9:31 AM
+1 ;;1.0;CARE MANAGEMENT;;Jul 15, 2003
+2 ;
+3 ; ID = "VIT:"_PatientID_;_MeasurementDate everywhere below
+4 ;
LIST(ORY,DFN,SDATE,EDATE,VALS) ; -- Return MAX sets of measurements for DFN
+1 ; in @ORY@(#) = Item=ID^^MeasurementDate in HL7 format, and if VALS
+2 ; = Data=Vital^Value^Unit^MetricValue^Unit^BMI^SuppO2^CriticalFlag^Qualifiers
+3 ; RPC = ORRC VITALS BY PATIENT
+4 NEW ORN,GMRVSTR,CNT,IDT,VDT,TYPE,IFN,DATA,X
KILL ^UTILITY($JOB,"GMRVD")
+5 SET SDATE=$$HL7TFM^XLFDT($GET(SDATE))
SET EDATE=$$HL7TFM^XLFDT($GET(EDATE))
+6 SET DFN=+$GET(DFN)
SET MAX=$SELECT(SDATE&EDATE:100,1:5)
+7 IF $GET(EDATE)
IF $LENGTH(EDATE,".")<2
SET EDATE=EDATE_".2359"
+8 SET GMRVSTR="BP;T;R;P;HT;WT;CVP;CG;PO2;PN"
SET GMRVSTR(0)=SDATE_U_EDATE_U_MAX_"^1"
+9 DO EN1^GMRVUT0
SET ORY=$NAME(^TMP($JOB,"ORRCVIT"))
SET (ORN,CNT)=0
KILL @ORY
+10 SET IDT=0
FOR
SET IDT=$ORDER(^UTILITY($JOB,"GMRVD",IDT))
IF IDT<1
QUIT
Begin DoDot:1
+11 SET VDT=9999999-IDT
SET CNT=CNT+1
+12 SET ORN=ORN+1
SET @ORY@(ORN)="Item=VIT:"_DFN_";"_VDT_U_U_VDT
IF '$GET(VALS)
QUIT
+13 SET TYPE=""
FOR
SET TYPE=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE))
IF TYPE=""
QUIT
Begin DoDot:2
+14 SET IFN=0
FOR
SET IFN=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE,IFN))
IF IFN<1
QUIT
SET X=$GET(^(IFN))
Begin DoDot:3
+15 ;return DATA w/relevant pieces
DO @TYPE
+16 SET ORN=ORN+1
SET @ORY@(ORN)="Data="_DATA
End DoDot:3
End DoDot:2
End DoDot:1
IF CNT'<MAX
QUIT
+17 KILL ^UTILITY($JOB,"GMRVD")
+18 QUIT
+19 ;
DETAIL(ORY,VITAL) ; -- Return details of VITALs
+1 ; where VITAL(#) = ID
+2 ; in @ORY@(#) = Item=ID^^MeasurementDate in HL7 format
+3 ; = Data=Vital^Value^Unit^MetricValue^Unit^BMI^SuppO2^CriticalFlag^Qualifiers
+4 ; RPC = ORRC VITALS BY ID
+5 NEW GMRVSTR,DFN,STRT,STOP,ORN,ORI,ID,IDT,VDT,TYPE,IFN,DATA,X
+6 KILL ^UTILITY($JOB,"GMRVD")
DO RANGE
+7 SET GMRVSTR="BP;T;R;P;HT;WT;CVP;CG;PO2;PN"
SET GMRVSTR(0)=STRT_U_STOP_"^100^1"
+8 DO EN1^GMRVUT0
SET ORY=$NAME(^TMP($JOB,"ORRCVIT"))
SET ORN=0
KILL @ORY
+9 SET ORI=0
FOR
SET ORI=$ORDER(VITAL(ORI))
IF ORI<1
QUIT
SET ID=$GET(VITAL(ORI))
Begin DoDot:1
+10 SET VDT=$PIECE(ID,";",2)
SET IDT=9999999-VDT
+11 SET ORN=ORN+1
SET @ORY@(ORN)="Item="_ID_U_U_VDT
+12 SET TYPE=""
FOR
SET TYPE=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE))
IF TYPE=""
QUIT
Begin DoDot:2
+13 SET IFN=0
FOR
SET IFN=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE,IFN))
IF IFN<1
QUIT
SET X=$GET(^(IFN))
Begin DoDot:3
+14 ;return DATA w/relevant pieces
DO @TYPE
+15 SET ORN=ORN+1
SET @ORY@(ORN)="Data="_DATA
End DoDot:3
End DoDot:2
End DoDot:1
+16 KILL ^UTILITY($JOB,"GMRVD")
+17 QUIT
+18 ;
RANGE ; -- Get STRT,STOP,DFN from VITALs
+1 NEW ORI,ID,VDT
SET (STRT,STOP)=""
+2 SET ORI=0
FOR
SET ORI=$ORDER(VITAL(ORI))
IF ORI<1
QUIT
SET ID=$GET(VITAL(ORI))
Begin DoDot:1
+3 SET DFN=+$PIECE(ID,":",2)
SET VDT=$PIECE(ID,";",2)
+4 IF $SELECT('$LENGTH(STRT):1,VDT<STRT:1,1:0)
SET STRT=VDT
+5 IF $SELECT('$LENGTH(STOP):1,VDT>STOP:1,1:0)
SET STOP=VDT
End DoDot:1
+6 QUIT
+7 ;
+8 ; Return formatted DATA string from X:
+9 ;
BP ; -- Blood Pressure = B/P^value^^^^^^[*]^Q1;..;Qn
+1 SET DATA="B/P^"_$PIECE(X,U,8)_"^^^^^^"_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
T ; -- Temperature = Temp.^value^F^metric^C^^^[*]^Q1;..;Qn
+1 SET DATA="Temp.^"_$PIECE(X,U,8)_"^F^"_$PIECE(X,U,13)_"^C^^^"_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
R ; -- Respiration = Resp.^value^^^^^^[*]^Q1;..;Qn
+1 SET DATA="Resp.^"_$PIECE(X,U,8)_"^^^^^^"_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
P ; -- Pulse = Pulse^value^^^^^^[*]^Q1;..;Qn
+1 SET DATA="Pulse^"_$PIECE(X,U,8)_"^^^^^^"_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
HT ; -- Height = Ht.^value^in^metric^cm^^^[*]^Q1;..;Qn
+1 SET DATA="Ht.^"_$PIECE(X,U,8)_"^in^"_$PIECE(X,U,13)_"^cm^^^"_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
WT ; -- Weight = Wt.^value^lb^metric^kg^BodyMassIndex^^[*]^Q1;..;Qn
+1 SET DATA="Wt.^"_$PIECE(X,U,8)_"^lb^"_$PIECE(X,U,13)_"^kg^"_$PIECE(X,U,14)_U_U_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
CVP ; -- CenVenPress = CVP^value^cmH2O^^^^^[*]^Q1;..;Qn
+1 SET DATA="CVP^"_$PIECE(X,U,8)_"^cmH2O^^^^^"_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
CG ; -- Circm/Girth = C/G^value^in^metric^cm^^^[*]^Q1;..;Qn
+1 SET DATA="C/G^"_$PIECE(X,U,8)_"^in^"_$PIECE(X,U,13)_"^cm^^^"_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
PO2 ; -- PulseOx = Pulse Ox^value^^^^^l/min of supplemental O2^[*]^Q1;..;Qn
+1 SET DATA="Pulse Ox^"_$PIECE(X,U,8)_"^^^^^"_$PIECE(X,U,15)_U_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
PN ; -- Pain = Pain^value^^^^^^[*]^Q1;..;Qn
+1 SET DATA="Pain^"_$PIECE(X,U,8)_"^^^^^^"_$PIECE(X,U,12)_U_$PIECE(X,U,17)
+2 QUIT
+3 ;
IDS(ORY,DFN,SDATE,EDATE) ; --Return recent measurement IDs for DFN
+1 ; in @ORY@(DFN) = #sets ^ 1 if any are critical
+2 ; @ORY@(DFN,ID) = * if critical, else null
+3 ; [from ORRCDPT1]
+4 NEW GMRVSTR,MAX,CNT,ABN,IDT,VDT,X
+5 SET ORY=$NAME(^TMP($JOB,"ORRCVIT"))
KILL @ORY,^UTILITY($JOB,"GMRVD")
+6 SET DFN=+$GET(DFN)
SET MAX=$SELECT($GET(SDATE)&$GET(EDATE):100,1:5)
+7 ;end of day
IF $GET(EDATE)
IF $LENGTH(EDATE,".")<2
SET EDATE=EDATE_".2359"
+8 SET GMRVSTR="BP;T;R;P;HT;WT;CVP;CG;PO2;PN"
SET GMRVSTR(0)=$GET(SDATE)_U_$GET(EDATE)_U_MAX_"^1"
+9 DO EN1^GMRVUT0
SET CNT=0
SET ABN=""
+10 SET IDT=0
FOR
SET IDT=$ORDER(^UTILITY($JOB,"GMRVD",IDT))
IF IDT<1
QUIT
Begin DoDot:1
+11 SET VDT=9999999-IDT
SET CNT=CNT+1
SET X=$$ABN(IDT)
+12 SET @ORY@(DFN,"VIT:"_DFN_";"_VDT)=X
IF $LENGTH(X)
SET ABN=1
End DoDot:1
IF CNT'<MAX
QUIT
+13 IF CNT
SET @ORY@(DFN)=CNT_U_ABN
+14 KILL ^UTILITY($JOB,"GMRVD")
+15 QUIT
+16 ;
ABN(IDT) ; -- Return * if any value from measurement set is critical, else null
+1 NEW Y,TYPE,IFN
SET Y=""
+2 SET TYPE=""
FOR
SET TYPE=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE))
IF TYPE=""
QUIT
Begin DoDot:1
+3 SET IFN=0
FOR
SET IFN=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE,IFN))
IF IFN<1
QUIT
IF $GET(^(IFN))["*"
SET Y="*"
End DoDot:1
+4 QUIT Y