EDPVIT ;SLC/MKB -- Vitals utilities ;4/25/12 12:51pm
;;2.0;EMERGENCY DEPARTMENT;;May 2, 2012;Build 103
;
GET(DFN,BEG,END) ; -- Return vitals measurements from BEG to END
D XML^EDPX("<Vitals dfn="""_$G(DFN)_""" >")
;D XML^EDPX("<Vitals>")
S DFN=+$G(DFN) I DFN<1 D ERR("Missing or invalid patient DFN") D XML^EDPX("</Vitals>") Q
N LOG,GMRVSTR,IDT,TYPE,IEN,REC,EDPX,LAST,X
S LOG=+$O(^EDP(230,"APA",DFN,0))
S:'$G(END) END=9999999 I '$G(BEG) D
. I LOG S BEG=+$P($G(^EDP(230,LOG,0)),U,8) ;Time In
. E S BEG=$$FMADD^XLFDT($$NOW^XLFDT,-1) ;Last 24 hours
S GMRVSTR="BP;T;R;P;HT;WT;PN",GMRVSTR(0)=BEG_U_END_"^9999999^1"
K ^UTILITY($J,"GMRVD") D EN1^GMRVUT0
; ^UTILITY($J,"GMRVD",IDT,TYPE,IEN) = $P(^GMR(120.5,IEN,0),U,1,9)_
; ^ Qual1 ^ Qual2 ^ * ^ metric ^ BMI ^ L/Min ^ SuppO2% ^ all qual's
S IDT="A" F S IDT=$O(^UTILITY($J,"GMRVD",IDT),-1) Q:IDT<1 D
. K EDPX S EDPX("time")=9999999-IDT
. S TYPE="" F S TYPE=$O(^UTILITY($J,"GMRVD",IDT,TYPE)) Q:TYPE="" D
.. S IEN=$O(^UTILITY($J,"GMRVD",IDT,TYPE,0)),REC=$G(^(IEN))
.. S EDPX(TYPE)=$P(REC,U,8),LAST=9999999-IDT
. ; EDPX("error")="false" ;for now
. D XML^EDPX($$XMLA^EDPX("vital",.EDPX))
GETQ ;end
D XML^EDPX("</Vitals>")
S X=$G(^EDP(230,LOG,7)) I X D ;schedule
. K EDPX S EDPX("frequency")=$P(X,U),EDPX("frequencyUnits")="mins"
. ;S:$P(X,U,2) EDPX("duration")=$P(X,U,2),EDPX("durationUnits")="mins"
. S:$G(LAST) EDPX("lastUpdated")=LAST
. D XML^EDPX($$XMLA^EDPX("schedule",.EDPX))
Q
;
PUT(DFN,DATA) ; -- Save new measurement
N I,NM,VAL,TIME,LOC,TYPE,X,ERROR
S DFN=+$G(DFN) I DFN<1 D ERR("Missing or invalid patient DFN") Q
F I=1:1:$L(DATA,"^") D ;parse
. S X=$P(DATA,U,I),NM=$P(X,"="),VAL=$P(X,"=",2)
. S:$L(NM) DATA($$UP^XLFSTR(NM))=VAL
S TIME=$G(DATA("TIME")),ERROR=$G(DATA("ERROR"))
I TIME<1 D ERR("Missing or invalid time") Q
I ERROR="true" D G PUTQ
. ;mark all values at TIME as Entered in Error
S LOC=$$DFLTLOC^EDPLPCE(DFN)
I LOC<1 D ERR("Missing default ED Hospital Location") Q
F TYPE="BP","T","R","P","HT","WT","PN" S X=$G(DATA(TYPE)) I X D
. N IEN,DATA,EDPY
. S IEN=+$O(^GMRD(120.51,"C",TYPE,0))
. S DATA=TIME_U_DFN_U_IEN_";"_X_U_LOC_U_DUZ
. D EN1^GMVDCSAV(.EDPY,DATA) ;IA #4815
PUTQ ;return new list
D GET(DFN)
Q
;
ERR(MSG) ; -- Return error node
I +MSG S MSG=$$MSG^EDPX(MSG)
N X S X="<error msg='"_MSG_"' />"
D XML^EDPX(X)
Q
;
LAST(DFN) ; -- Return time that vitals were last taken
N Y,IDX
S IDX=$Q(^GMR(120.5,"AA",DFN)),Y=""
I $P(IDX,",",3)=DFN S Y=9999999-+$P(IDX,",",5)
Q Y
;
; -- Worksheet calls:
;
READ(CTXT) ; -- return current vitals in XML
D XML^EDPX("<vitals>")
N DFN,LOG,BEG,END,GMRVSTR,IDT,TYPE,IEN,REC,EDPX,LAST,X,EDPBMI,Q
S DFN=+$G(CTXT("dfn")),LOG=+$G(CTXT("log"))
I DFN<1 D ERR("Missing or invalid patient DFN") G RQ
S END=9999999 D
. I LOG S BEG=+$P($G(^EDP(230,LOG,0)),U,8) ;Time In
. E S BEG=$$FMADD^XLFDT($$NOW^XLFDT,-1) ;Last 24 hours
S GMRVSTR="BP;T;R;P;HT;WT;CVP;CG;PO2;PN",GMRVSTR(0)=BEG_U_END_"^9999999^1"
K ^UTILITY($J,"GMRVD") D EN1^GMRVUT0
; ^UTILITY($J,"GMRVD",IDT,TYPE,IEN) = $P(^GMR(120.5,IEN,0),U,1,9)_
; ^ Qual1 ^ Qual2 ^ * ^ metric ^ BMI ^ L/Min ^ SuppO2% ^ all qual's
S IDT="A" F S IDT=$O(^UTILITY($J,"GMRVD",IDT),-1) Q:IDT<1 D
. D XML^EDPX("<vital>")
. S LAST=9999999-IDT
. S TYPE="" F S TYPE=$O(^UTILITY($J,"GMRVD",IDT,TYPE)) Q:TYPE="" D
.. S IEN=$O(^UTILITY($J,"GMRVD",IDT,TYPE,0)),REC=$G(^(IEN)) K EDPX
.. S EDPX("id")=IEN,EDPX("time")=LAST,EDPX("ussValue")=$P(REC,U,8)
.. S EDPX("name")=TYPE I TYPE="WT",$P(REC,U,14) S EDPBMI=IEN_U_$P(REC,U,14)
.. S X=$S(TYPE="T":"F",TYPE="HT":"in",TYPE="WT":"lb",TYPE="CVP":"cmH2O",TYPE="CG":"in",1:"")
.. S:$L(X) EDPX("ussUnits")=X I $L($P(REC,U,13)) D
... S X=$S(TYPE="T":"C",TYPE="HT":"cm",TYPE="WT":"kg",TYPE="CVP":"mmHg",TYPE="CG":"cm",1:"")
... S EDPX("metricValue")=$P(REC,U,13) S:$L(X) EDPX("metricUnits")=X
.. S EDPX("abnormal")=$S($L($P(REC,U,12)):"true",1:"false")
.. I '$L($P(REC,U,17)) D XML^EDPX($$XMLA^EDPX("vitalMsmt",.EDPX)) Q
.. ;Qualifiers
.. D XML^EDPX($$XMLA^EDPX("vitalMsmt",.EDPX,""))
.. D XML^EDPX("<qualifiers>") S X=$P(REC,U,17)
.. F I=1:1:$L(X,";") S Q=$P(X,";",I) D XML^EDPX("<qualifier value="""_Q_""" />")
.. D XML^EDPX("</qualifiers>")
.. D XML^EDPX("</vitalMsmt>")
. I $G(EDPBMI) D K EDPBMI
.. K EDPX S EDPX("id")=+EDPBMI_"BMI",EDPX("time")=LAST
.. S EDPX("ussValue")=$P(EDPBMI,U,2),EDPX("name")="BMI"
.. D XML^EDPX($$XMLA^EDPX("vitalMsmt",.EDPX))
. D XML^EDPX("</vital>")
RQ ;end
D XML^EDPX("</vitals>")
S X=$G(^EDP(230,LOG,7)) I X D ;schedule
. K EDPX S EDPX("frequency")=$P(X,U),EDPX("frequencyUnits")="mins"
. S EDPX("repeatVitals")=$S($P(X,U,2):"true",1:"false")
. S:$G(LAST) EDPX("lastUpdated")=LAST
. D XML^EDPX($$XMLA^EDPX("schedule",.EDPX))
Q
;
SAVE(ARRAY) ; -- process incoming Vitals XML array
N DFN,LOG,ADD,DEL,SCH,EDPI,LOC,TIME,ID,X1,X2
S DFN=+$G(ARRAY("context",1,"/dfn")) ;?!?
I DFN<1 D ERR("Missing or invalid patient DFN") Q
S LOG=+$G(ARRAY("context",1,"/log")) ;?!?
; entered in error
M DEL=ARRAY("removeVitals",1,"vitalMsmt")
F EDPI=1:1 S ID=$G(DEL(EDPI,"/id")) Q:ID="" D
. N DATA,EDPRES S DATA=ID_U_DUZ_U_$G(DEL(EDPI,"/reason"))
. D ERROR^GMVUTL1(.EDPRES,DATA)
; add a new measurement
M ADD=ARRAY("addVital",1,"vitalMsmt")
S LOC=$$DFLTLOC^EDPLPCE(DFN),TIME=$$NOW^XLFDT
I LOC<1 D ERR("Missing default ED Hospital Location") Q
F EDPI=1:1 S TYPE=$G(ADD(EDPI,"/name")) Q:TYPE="" D
. N IEN,DATA,EDPY,X
. S X=$G(ADD(EDPI,"/value")) Q:'$L(X)
. ;ck /units, convert if necessary ??
. S IEN=+$O(^GMRD(120.51,"C",TYPE,0))
. S DATA=TIME_U_DFN_U_IEN_";"_X_U_LOC_U_DUZ
. D EN1^GMVDCSAV(.EDPY,DATA) ;IA #4815
; save frequency
M SCH=ARRAY("schedule",1) I $D(SCH),LOG D
. S X1=+$G(SCH("/frequency")) ;ck units?
. S X2=$S($G(SCH("/repeatVitals"))="true":1,1:0)
. S ^EDP(230,LOG,7)=X1_U_X2
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HEDPVIT 5941 printed Oct 16, 2024@17:53:20 Page 2
EDPVIT ;SLC/MKB -- Vitals utilities ;4/25/12 12:51pm
+1 ;;2.0;EMERGENCY DEPARTMENT;;May 2, 2012;Build 103
+2 ;
GET(DFN,BEG,END) ; -- Return vitals measurements from BEG to END
+1 DO XML^EDPX("<Vitals dfn="""_$GET(DFN)_""" >")
+2 ;D XML^EDPX("<Vitals>")
+3 SET DFN=+$GET(DFN)
IF DFN<1
DO ERR("Missing or invalid patient DFN")
DO XML^EDPX("</Vitals>")
QUIT
+4 NEW LOG,GMRVSTR,IDT,TYPE,IEN,REC,EDPX,LAST,X
+5 SET LOG=+$ORDER(^EDP(230,"APA",DFN,0))
+6 if '$GET(END)
SET END=9999999
IF '$GET(BEG)
Begin DoDot:1
+7 ;Time In
IF LOG
SET BEG=+$PIECE($GET(^EDP(230,LOG,0)),U,8)
+8 ;Last 24 hours
IF '$TEST
SET BEG=$$FMADD^XLFDT($$NOW^XLFDT,-1)
End DoDot:1
+9 SET GMRVSTR="BP;T;R;P;HT;WT;PN"
SET GMRVSTR(0)=BEG_U_END_"^9999999^1"
+10 KILL ^UTILITY($JOB,"GMRVD")
DO EN1^GMRVUT0
+11 ; ^UTILITY($J,"GMRVD",IDT,TYPE,IEN) = $P(^GMR(120.5,IEN,0),U,1,9)_
+12 ; ^ Qual1 ^ Qual2 ^ * ^ metric ^ BMI ^ L/Min ^ SuppO2% ^ all qual's
+13 SET IDT="A"
FOR
SET IDT=$ORDER(^UTILITY($JOB,"GMRVD",IDT),-1)
if IDT<1
QUIT
Begin DoDot:1
+14 KILL EDPX
SET EDPX("time")=9999999-IDT
+15 SET TYPE=""
FOR
SET TYPE=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE))
if TYPE=""
QUIT
Begin DoDot:2
+16 SET IEN=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE,0))
SET REC=$GET(^(IEN))
+17 SET EDPX(TYPE)=$PIECE(REC,U,8)
SET LAST=9999999-IDT
End DoDot:2
+18 ; EDPX("error")="false" ;for now
+19 DO XML^EDPX($$XMLA^EDPX("vital",.EDPX))
End DoDot:1
GETQ ;end
+1 DO XML^EDPX("</Vitals>")
+2 ;schedule
SET X=$GET(^EDP(230,LOG,7))
IF X
Begin DoDot:1
+3 KILL EDPX
SET EDPX("frequency")=$PIECE(X,U)
SET EDPX("frequencyUnits")="mins"
+4 ;S:$P(X,U,2) EDPX("duration")=$P(X,U,2),EDPX("durationUnits")="mins"
+5 if $GET(LAST)
SET EDPX("lastUpdated")=LAST
+6 DO XML^EDPX($$XMLA^EDPX("schedule",.EDPX))
End DoDot:1
+7 QUIT
+8 ;
PUT(DFN,DATA) ; -- Save new measurement
+1 NEW I,NM,VAL,TIME,LOC,TYPE,X,ERROR
+2 SET DFN=+$GET(DFN)
IF DFN<1
DO ERR("Missing or invalid patient DFN")
QUIT
+3 ;parse
FOR I=1:1:$LENGTH(DATA,"^")
Begin DoDot:1
+4 SET X=$PIECE(DATA,U,I)
SET NM=$PIECE(X,"=")
SET VAL=$PIECE(X,"=",2)
+5 if $LENGTH(NM)
SET DATA($$UP^XLFSTR(NM))=VAL
End DoDot:1
+6 SET TIME=$GET(DATA("TIME"))
SET ERROR=$GET(DATA("ERROR"))
+7 IF TIME<1
DO ERR("Missing or invalid time")
QUIT
+8 IF ERROR="true"
Begin DoDot:1
+9 ;mark all values at TIME as Entered in Error
End DoDot:1
GOTO PUTQ
+10 SET LOC=$$DFLTLOC^EDPLPCE(DFN)
+11 IF LOC<1
DO ERR("Missing default ED Hospital Location")
QUIT
+12 FOR TYPE="BP","T","R","P","HT","WT","PN"
SET X=$GET(DATA(TYPE))
IF X
Begin DoDot:1
+13 NEW IEN,DATA,EDPY
+14 SET IEN=+$ORDER(^GMRD(120.51,"C",TYPE,0))
+15 SET DATA=TIME_U_DFN_U_IEN_";"_X_U_LOC_U_DUZ
+16 ;IA #4815
DO EN1^GMVDCSAV(.EDPY,DATA)
End DoDot:1
PUTQ ;return new list
+1 DO GET(DFN)
+2 QUIT
+3 ;
ERR(MSG) ; -- Return error node
+1 IF +MSG
SET MSG=$$MSG^EDPX(MSG)
+2 NEW X
SET X="<error msg='"_MSG_"' />"
+3 DO XML^EDPX(X)
+4 QUIT
+5 ;
LAST(DFN) ; -- Return time that vitals were last taken
+1 NEW Y,IDX
+2 SET IDX=$QUERY(^GMR(120.5,"AA",DFN))
SET Y=""
+3 IF $PIECE(IDX,",",3)=DFN
SET Y=9999999-+$PIECE(IDX,",",5)
+4 QUIT Y
+5 ;
+6 ; -- Worksheet calls:
+7 ;
READ(CTXT) ; -- return current vitals in XML
+1 DO XML^EDPX("<vitals>")
+2 NEW DFN,LOG,BEG,END,GMRVSTR,IDT,TYPE,IEN,REC,EDPX,LAST,X,EDPBMI,Q
+3 SET DFN=+$GET(CTXT("dfn"))
SET LOG=+$GET(CTXT("log"))
+4 IF DFN<1
DO ERR("Missing or invalid patient DFN")
GOTO RQ
+5 SET END=9999999
Begin DoDot:1
+6 ;Time In
IF LOG
SET BEG=+$PIECE($GET(^EDP(230,LOG,0)),U,8)
+7 ;Last 24 hours
IF '$TEST
SET BEG=$$FMADD^XLFDT($$NOW^XLFDT,-1)
End DoDot:1
+8 SET GMRVSTR="BP;T;R;P;HT;WT;CVP;CG;PO2;PN"
SET GMRVSTR(0)=BEG_U_END_"^9999999^1"
+9 KILL ^UTILITY($JOB,"GMRVD")
DO EN1^GMRVUT0
+10 ; ^UTILITY($J,"GMRVD",IDT,TYPE,IEN) = $P(^GMR(120.5,IEN,0),U,1,9)_
+11 ; ^ Qual1 ^ Qual2 ^ * ^ metric ^ BMI ^ L/Min ^ SuppO2% ^ all qual's
+12 SET IDT="A"
FOR
SET IDT=$ORDER(^UTILITY($JOB,"GMRVD",IDT),-1)
if IDT<1
QUIT
Begin DoDot:1
+13 DO XML^EDPX("<vital>")
+14 SET LAST=9999999-IDT
+15 SET TYPE=""
FOR
SET TYPE=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE))
if TYPE=""
QUIT
Begin DoDot:2
+16 SET IEN=$ORDER(^UTILITY($JOB,"GMRVD",IDT,TYPE,0))
SET REC=$GET(^(IEN))
KILL EDPX
+17 SET EDPX("id")=IEN
SET EDPX("time")=LAST
SET EDPX("ussValue")=$PIECE(REC,U,8)
+18 SET EDPX("name")=TYPE
IF TYPE="WT"
IF $PIECE(REC,U,14)
SET EDPBMI=IEN_U_$PIECE(REC,U,14)
+19 SET X=$SELECT(TYPE="T":"F",TYPE="HT":"in",TYPE="WT":"lb",TYPE="CVP":"cmH2O",TYPE="CG":"in",1:"")
+20 if $LENGTH(X)
SET EDPX("ussUnits")=X
IF $LENGTH($PIECE(REC,U,13))
Begin DoDot:3
+21 SET X=$SELECT(TYPE="T":"C",TYPE="HT":"cm",TYPE="WT":"kg",TYPE="CVP":"mmHg",TYPE="CG":"cm",1:"")
+22 SET EDPX("metricValue")=$PIECE(REC,U,13)
if $LENGTH(X)
SET EDPX("metricUnits")=X
End DoDot:3
+23 SET EDPX("abnormal")=$SELECT($LENGTH($PIECE(REC,U,12)):"true",1:"false")
+24 IF '$LENGTH($PIECE(REC,U,17))
DO XML^EDPX($$XMLA^EDPX("vitalMsmt",.EDPX))
QUIT
+25 ;Qualifiers
+26 DO XML^EDPX($$XMLA^EDPX("vitalMsmt",.EDPX,""))
+27 DO XML^EDPX("<qualifiers>")
SET X=$PIECE(REC,U,17)
+28 FOR I=1:1:$LENGTH(X,";")
SET Q=$PIECE(X,";",I)
DO XML^EDPX("<qualifier value="""_Q_""" />")
+29 DO XML^EDPX("</qualifiers>")
+30 DO XML^EDPX("</vitalMsmt>")
End DoDot:2
+31 IF $GET(EDPBMI)
Begin DoDot:2
+32 KILL EDPX
SET EDPX("id")=+EDPBMI_"BMI"
SET EDPX("time")=LAST
+33 SET EDPX("ussValue")=$PIECE(EDPBMI,U,2)
SET EDPX("name")="BMI"
+34 DO XML^EDPX($$XMLA^EDPX("vitalMsmt",.EDPX))
End DoDot:2
KILL EDPBMI
+35 DO XML^EDPX("</vital>")
End DoDot:1
RQ ;end
+1 DO XML^EDPX("</vitals>")
+2 ;schedule
SET X=$GET(^EDP(230,LOG,7))
IF X
Begin DoDot:1
+3 KILL EDPX
SET EDPX("frequency")=$PIECE(X,U)
SET EDPX("frequencyUnits")="mins"
+4 SET EDPX("repeatVitals")=$SELECT($PIECE(X,U,2):"true",1:"false")
+5 if $GET(LAST)
SET EDPX("lastUpdated")=LAST
+6 DO XML^EDPX($$XMLA^EDPX("schedule",.EDPX))
End DoDot:1
+7 QUIT
+8 ;
SAVE(ARRAY) ; -- process incoming Vitals XML array
+1 NEW DFN,LOG,ADD,DEL,SCH,EDPI,LOC,TIME,ID,X1,X2
+2 ;?!?
SET DFN=+$GET(ARRAY("context",1,"/dfn"))
+3 IF DFN<1
DO ERR("Missing or invalid patient DFN")
QUIT
+4 ;?!?
SET LOG=+$GET(ARRAY("context",1,"/log"))
+5 ; entered in error
+6 MERGE DEL=ARRAY("removeVitals",1,"vitalMsmt")
+7 FOR EDPI=1:1
SET ID=$GET(DEL(EDPI,"/id"))
if ID=""
QUIT
Begin DoDot:1
+8 NEW DATA,EDPRES
SET DATA=ID_U_DUZ_U_$GET(DEL(EDPI,"/reason"))
+9 DO ERROR^GMVUTL1(.EDPRES,DATA)
End DoDot:1
+10 ; add a new measurement
+11 MERGE ADD=ARRAY("addVital",1,"vitalMsmt")
+12 SET LOC=$$DFLTLOC^EDPLPCE(DFN)
SET TIME=$$NOW^XLFDT
+13 IF LOC<1
DO ERR("Missing default ED Hospital Location")
QUIT
+14 FOR EDPI=1:1
SET TYPE=$GET(ADD(EDPI,"/name"))
if TYPE=""
QUIT
Begin DoDot:1
+15 NEW IEN,DATA,EDPY,X
+16 SET X=$GET(ADD(EDPI,"/value"))
if '$LENGTH(X)
QUIT
+17 ;ck /units, convert if necessary ??
+18 SET IEN=+$ORDER(^GMRD(120.51,"C",TYPE,0))
+19 SET DATA=TIME_U_DFN_U_IEN_";"_X_U_LOC_U_DUZ
+20 ;IA #4815
DO EN1^GMVDCSAV(.EDPY,DATA)
End DoDot:1
+21 ; save frequency
+22 MERGE SCH=ARRAY("schedule",1)
IF $DATA(SCH)
IF LOG
Begin DoDot:1
+23 ;ck units?
SET X1=+$GET(SCH("/frequency"))
+24 SET X2=$SELECT($GET(SCH("/repeatVitals"))="true":1,1:0)
+25 SET ^EDP(230,LOG,7)=X1_U_X2
End DoDot:1
+26 QUIT