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

NHINVIT.m

Go to the documentation of this file.
  1. NHINVIT ;SLC/MKB -- Vitals extract
  1. ;;1.0;NHIN;**1**;Oct 25, 2010;Build 11
  1. ;
  1. ; External References DBIA#
  1. ; ------------------- -----
  1. ; ^SC 10040
  1. ; ^VA(200 10060
  1. ; DIC 2051
  1. ; DIQ 2056
  1. ; GMRVUT0,^UTILITY($J,"GMRVD") 1446
  1. ; GMVPXRM 3647
  1. ;
  1. ; ------------ Get vitals from VistA ------------
  1. ;
  1. EN(DFN,BEG,END,MAX,IFN) ; -- find patient's vitals
  1. N NHITM,NHIPRM,GMRVSTR,IDT,TYPE,VIT,CNT,X0,X,Y,I,N
  1. S DFN=+$G(DFN) Q:DFN<1
  1. ;
  1. ; get one measurement
  1. I $G(IFN) D EN1(IFN,.NHITM),XML(.NHITM) Q
  1. ;
  1. ; get all measurements
  1. S BEG=$G(BEG,1410101),END=$G(END,9999998),MAX=$G(MAX,999999)
  1. S GMRVSTR="BP;T;R;P;HT;WT;CVP;CG;PO2;PN",GMRVSTR(0)=BEG_U_END_U_MAX_"^1"
  1. K ^UTILITY($J,"GMRVD") D EN1^GMRVUT0
  1. S (IDT,CNT)=0 F S IDT=$O(^UTILITY($J,"GMRVD",IDT)) Q:IDT<1 D Q:CNT'<MAX
  1. . K VIT S VIT("taken")=9999999-IDT,CNT=CNT+1,N=0
  1. . S TYPE="" F S TYPE=$O(^UTILITY($J,"GMRVD",IDT,TYPE)) Q:TYPE="" D
  1. .. N NAME,VUID,RESULT,UNIT,MRES,MUNT,HIGH,LOW,QUAL
  1. .. S IFN=+$O(^UTILITY($J,"GMRVD",IDT,TYPE,0)),X0=$G(^(IFN))
  1. .. S X=+$P(X0,U,3),NAME=$$GET1^DIQ(120.5,IFN_",",.03)
  1. .. S VUID=$$VUID^NHINV(X,120.51),RESULT=$P(X0,U,8)
  1. .. S UNIT=$S(TYPE="T":"F",TYPE="HT":"in",TYPE="WT":"lb",TYPE="CVP":"cmH2O",TYPE="CG":"in",1:"")
  1. .. S (MRES,MUNT)="" I $L($P(X0,U,13)) D
  1. ... S X=$S(TYPE="T":"C",TYPE="HT":"cm",TYPE="WT":"kg",TYPE="CG":"cm",1:"")
  1. ... S MRES=$P(X0,U,13) S:$L(X) MUNT=X
  1. .. S X=$$RANGE(TYPE),(HIGH,LOW)="" I $L(X) S HIGH=$P(X,U),LOW=$P(X,U,2)
  1. .. S N=N+1,VIT("measurement",N)=IFN_U_VUID_U_NAME_U_RESULT_U_UNIT_U_MRES_U_MUNT_U_HIGH_U_LOW
  1. .. S QUAL=$P(X0,U,17) I $L(QUAL) F I=1:1:$L(QUAL,";") D
  1. ... S X=$P(QUAL,";",I),Y=$$FIND1^DIC(120.52,,"QX",X)
  1. ... I Y S VIT("measurement",N,"qualifier",I)=X_U_$$VUID^NHINV(Y,120.52)
  1. . S VIT("entered")=$P($G(X0),U,4) ;use last one
  1. . S X=+$P($G(X0),U,5) S:X VIT("location")=$$LOC(X)
  1. . S VIT("facility")=$$FAC^NHINV(X)
  1. . D XML(.VIT)
  1. K ^UTILITY($J,"GMRVD")
  1. Q
  1. ;
  1. EN1(ID,VIT) ; -- return a vital/measurement in VIT("attribute")
  1. K VIT S ID=+$G(ID) Q:ID<1 ;invalid ien
  1. N NHY,DFN,TYPE,X,Y,NAME,VUID,RESULT,UNIT,MRES,MUNT,HIGH,LOW,I
  1. D EN^GMVPXRM(.NHY,ID,"B")
  1. S DFN=+$G(NHY(2)) Q:DFN<1
  1. S TYPE=$$GET1^DIQ(120.51,+NHY(3)_",",1)
  1. S VIT("facility")=$$FAC^NHINV(+NHY(5)),VIT("location")=NHY(5)
  1. S NAME=$P(NHY(3),U,2),VUID=$$VUID^NHINV(+NHY(3),120.51)
  1. S X=$P(NHY(7),U,2),RESULT=X,(UNIT,MRES,MUNT)=""
  1. I TYPE="T" S UNIT="F",MUNT="C" S MRES=$J(X-32*5/9,0,1) ; EN1^GMRVUTL
  1. I TYPE="HT" S UNIT="in",MUNT="cm" S MRES=$J(2.54*X,0,2) ; EN2^GMRVUTL
  1. I TYPE="WT" S UNIT="lb",MUNT="kg" S MRES=$J(X/2.2,0,2) ; EN3^GMRVUTL
  1. I TYPE="CG" S UNIT="in",MUNT="cm" S MRES=$J(2.54*X,0,2)
  1. I TYPE="CVP" S UNIT="cmH2O"
  1. S VIT("taken")=+NHY(1),VIT("entered")=+NHY(4),(HIGH,LOW)=""
  1. S X=$$RANGE(TYPE) I $L(X) S HIGH=$P(X,U),LOW=$P(X,U,2)
  1. S VIT("measurement",1)=ID_U_VUID_U_NAME_U_RESULT_U_UNIT_U_MRES_U_MUNT_U_HIGH_U_LOW
  1. S I=0 F S I=$O(NHY(12,I)) Q:I<1 S X=$G(NHY(12,I)),VIT("measurement",1,"qualifier",I)=$P(X,U,2)_U_$$VUID^NHINV(+X,120.52)
  1. I $G(NHY(9)) D ;entered in error/reasons
  1. . S I=0 F S I=$O(NHY(11,I)) Q:I<1 S VIT("removed",I)=$P(NHY(11,I),U,2)
  1. Q
  1. ;
  1. USER(X) ; -- Return ien^name for person# X
  1. N Y S X=+$G(X)
  1. S Y=$S(X:X_U_$P($G(^VA(200,X,0)),U),1:"^")
  1. Q Y
  1. ;
  1. LOC(X) ; -- Return ien^name for hospital location X
  1. N Y S X=+$G(X)
  1. S Y=$S(X:X_U_$P($G(^SC(X,0)),U),1:"^")
  1. Q Y
  1. ;
  1. RANGE(TYPE) ; -- return high^low range of values for TYPE
  1. N Y S Y="" I '$D(NHIPRM) D ;get parameter values
  1. . N VAL D GETS^DIQ(120.57,"1,","5:7","","VAL")
  1. . M NHIPRM=VAL(120.57,"1,")
  1. I TYPE="T" S Y=$G(NHIPRM(5.1))_U_$G(NHIPRM(5.2))
  1. I TYPE="P" S Y=$G(NHIPRM(5.3))_U_$G(NHIPRM(5.4))
  1. I TYPE="R" S Y=$G(NHIPRM(5.5))_U_$G(NHIPRM(5.6))
  1. I TYPE="CVP" S Y=$G(NHIPRM(6.1))_U_$G(NHIPRM(6.2))
  1. I TYPE="PO2" S Y="100^"_$G(NHIPRM(6.3))
  1. I TYPE="BP" D
  1. . S Y=$G(NHIPRM(5.7))_"/"_$G(NHIPRM(5.71))_U
  1. . S Y=Y_$G(NHIPRM(5.8))_"/"_$G(NHIPRM(5.81))
  1. Q Y
  1. ;
  1. ; ------------ Return data to middle tier ------------
  1. ;
  1. NAME(X) ; -- Return name of measurement type X for XML element
  1. N Y S X=$G(X),Y=""
  1. S Y=$S(X="BP":"bloodPressure",X="T":"temperature",X="R":"respiration",X="P":"pulse",X="HT":"height",X="WT":"weight",X="CVP":"centralVenousPressure",X="CG":"circumferenceGirth",X="PO2":"pulseOximetry",X="PN":"pain",1:"")
  1. Q Y
  1. ;
  1. XML(VIT) ; -- Return vital measurement as XML in @NHIN@(#)
  1. N ATT,X,Y,I,J,P,NAMES,TAG
  1. D ADD("<vital>") S NHINTOTL=$G(NHINTOTL)+1
  1. S ATT="" F S ATT=$O(VIT(ATT)) Q:ATT="" D
  1. . I ATT="measurement" D Q
  1. .. D ADD("<measurements>")
  1. .. S NAMES="id^vuid^name^value^units^metricValue^metricUnits^high^low^Z"
  1. .. S I=0 F S I=$O(VIT(ATT,I)) Q:I<1 D
  1. ... S X=$G(VIT(ATT,I)),Y="<"_ATT_" "
  1. ... F P=1:1 S TAG=$P(NAMES,U,P) Q:TAG="Z" I $L($P(X,U,P)) S Y=Y_TAG_"='"_$$ESC^NHINV($P(X,U,P))_"' "
  1. ... I '$D(VIT(ATT,I,"qualifier")) S Y=Y_"/>" D ADD(Y) Q
  1. ... S Y=Y_">" D ADD(Y),ADD("<qualifiers>")
  1. ... S J=0 F S J=$O(VIT(ATT,I,"qualifier",J)) Q:J<1 D
  1. .... S Y="<qualifier ",X=$G(VIT(ATT,I,"qualifier",J))
  1. .... F P=1:1 S TAG=$P("name^vuid^Z",U,P) Q:TAG="Z" I $L($P(X,U,P)) S Y=Y_TAG_"='"_$$ESC^NHINV($P(X,U,P))_"' "
  1. .... S Y=Y_"/>" D ADD(Y)
  1. ... D ADD("</qualifiers>"),ADD("</measurement>")
  1. .. D ADD("</measurements>")
  1. . I ATT="removed" D Q
  1. .. D ADD("<removed>")
  1. .. S I=0 F S I=$O(VIT(ATT,I)) Q:I<1 S Y="<reason value='"_$G(VIT(ATT,I))_"' />" D ADD(Y)
  1. .. D ADD("</removed>")
  1. . S X=$G(VIT(ATT)),Y="" Q:'$L(X)
  1. . I X'["^" S Y="<"_ATT_" value='"_$$ESC^NHINV(X)_"' />" D ADD(Y) Q
  1. . I $L(X)>1 D
  1. .. S Y="<"_ATT_" "
  1. .. F P=1:1 S TAG=$P("code^name^Z",U,P) Q:TAG="Z" I $L($P(X,U,P)) S Y=Y_TAG_"='"_$$ESC^NHINV($P(X,U,P))_"' "
  1. .. S Y=Y_"/>" D ADD(Y)
  1. D ADD("</vital>")
  1. Q
  1. ;
  1. ADD(X) ; Add a line @NHIN@(n)=X
  1. S NHINI=$G(NHINI)+1
  1. S @NHIN@(NHINI)=X
  1. Q