VPRDGMPL ;SLC/MKB -- Problem extract ;8/2/11 15:29
;;1.0;VIRTUAL PATIENT RECORD;**1,2,4,5**;Sep 01, 2011;Build 21
;;Per VHA Directive 2004-038, this routine should not be modified.
;
; External References DBIA#
; ------------------- -----
; ^AUPNPROB 5703
; ^DPT 10035
; ^VA(200 10060
; ^WV(790.05 5772
; %DT 10003
; DIQ 2056
; GMPLUTL2 2741
; SDUTL3 1252
; XLFDT 10103
; XUAF4 2171
;
; ------------ Get problems from VistA ------------
;
EN(DFN,BEG,END,MAX,IFN) ; -- find patient's problems
N VPRSTS,VPRPROB,VPRN,VPRITM,VPRCNT,X
;
; get one problem
I $G(IFN)="790.05" D WV(.VPRITM,1),XML(.VPRITM):$D(VPRITM) Q
I $G(IFN) D EN1(IFN,.VPRITM),XML(.VPRITM) Q
;
; get all patient problems
S DFN=+$G(DFN) Q:DFN<1
S BEG=$G(BEG,1410101),END=$G(END,4141015),MAX=$G(MAX,9999),VPRCNT=0
S VPRSTS=$G(FILTER("status")) ;default = all problems
D LIST^GMPLUTL2(.VPRPROB,DFN,VPRSTS)
S VPRN=0 F S VPRN=$O(VPRPROB(VPRN)) Q:(VPRN<1)!(VPRCNT'<MAX) D
. S X=$P(VPRPROB(VPRN),U,5) I X,(X<BEG)!(X>END) Q ;onset
. S X=+VPRPROB(VPRN) K VPRITM ;ien
. D EN1(X,.VPRITM),XML(.VPRITM)
. S VPRCNT=VPRCNT+1
I $P($G(^DPT(DFN,0)),U,2)="F" D WV(.VPRITM),XML(.VPRITM):$D(VPRITM)
Q
;
EN1(ID,PROB) ; -- return a problem in PROB("attribute")=value
N VPRL,X,I,J K PROB
S ID=+$G(ID) Q:ID<1 ;invalid ien
D DETAIL^GMPLUTL2(ID,.VPRL) Q:'$D(VPRL) ;doesn't exist
S PROB("id")=ID,PROB("name")=$G(VPRL("NARRATIVE"))
S PROB("icd")=$G(VPRL("DIAGNOSIS")),PROB("codingSystem")=$G(VPRL("CSYS"),"ICD")
F I="SCTC","SCTD","SCTT","ICDD" S X=$G(VPRL(I)) S:$L(X) PROB($$LOW^XLFSTR(I))=X
S X=$G(VPRL("STATUS")) S:$L(X) PROB("status")=$E(X)_U_X
S X=$G(VPRL("HISTORY")) S:$L(X) PROB("history")=$E(X)_U_X
S X=$G(VPRL("PRIORITY")) S:$L(X) PROB("acuity")=$E(X)_U_X
; get internal form of dates via FM instead of DETAIL
S X=$$GET1^DIQ(9000011,ID_",",.03,"I") S:X PROB("updated")=X
S X=$$GET1^DIQ(9000011,ID_",",.08,"I") S:X PROB("entered")=X
S X=$$GET1^DIQ(9000011,ID_",",.13,"I") S:X PROB("onset")=X
S X=$$GET1^DIQ(9000011,ID_",",1.07,"I") S:X PROB("resolved")=X
S X=$E($G(VPRL("CONDITION")))
S:X="P" PROB("unverified")=0,PROB("removed")=0
S:X="T" PROB("unverified")=1,PROB("removed")=0
S:X="H" PROB("unverified")=0,PROB("removed")=1
S X=$G(VPRL("SC")),X=$S(X="YES":1,X="NO":0,1:"")
S:$L(X) PROB("sc")=X I $G(VPRL("EXPOSURE")) D ;ao^rad^pgulf^hnc^mst^cv
. S I=0 F S I=$O(VPRL("EXPOSURE",I)) Q:I<1 D
.. S X=$G(VPRL("EXPOSURE",I))
.. S PROB("exposure",I)=$$EXP(X)
S X=$G(VPRL("PROVIDER")) S:$L(X) PROB("provider")=$$GET1^DIQ(9000011,ID_",",1.05,"I")_U_X
S X=$G(VPRL("SERVICE")) S:$L(X) PROB("service")=X
S X=$G(VPRL("CLINIC")) S:$L(X) PROB("location")=X
S X=+$G(VPRL("FACILITY"))
S:X PROB("facility")=$$STA^XUAF4(X)_U_$P($$NS^XUAF4(X),U)
I 'X S PROB("facility")=$$FAC^VPRD ;local stn#^name
CMT ; comments
Q:'$G(VPRL("COMMENT"))
S I=0 F S I=$O(VPRL("COMMENT",I)) Q:I<1 D
. S X=$G(VPRL("COMMENT",I))
. S PROB("comment",I)=$$DATE($P(X,U))_U_$P(X,U,2,3)
. ; = date ^ name of author ^ text
Q
;
WV(PROB,UPD) ; -- return a pregnancy log entry in PROB("attribute")=value
N I,X0,Y K PROB
S I=$O(^WV(790.05,"C",DFN,""),-1) Q:'I ;last entry
S X0=$G(^WV(790.05,I,0)),Y=0
; status=YES, future due date (allow past 14 days)
I $P(X0,U,3),$P(X0,U,4)'<$$FMADD^XLFDT(DT,-14) S Y=1
I 'Y,'$G(UPD) Q
; continue if pregnant, or update requested
S PROB("id")="790.05",PROB("entered")=+X0
S PROB("name")="Pregnancy",PROB("icd")="V22.2"
S PROB("icdd")="PREGNANT STATE, INCIDENTAL"
S PROB("codingSystem")="ICD"
S PROB("sctc")="77386006",PROB("sctt")="Patient currently pregnant (finding)"
; PROB("problemType")=64572001 ;HITSP/Condition
S PROB("status")=$S(Y:"A^ACTIVE",1:"I^INACTIVE")
S PROB("resolved")=$P(X0,U,4) ;due date
S PROB("provider")=$$OUTPTPR^SDUTL3(DFN) ;primary care
S PROB("facility")=$$FAC^VPRD
Q
;
DATE(X) ; -- Return internal form of date X
N %DT,Y
S %DT="" D ^%DT S:Y<1 Y=X
Q Y
;
VA200(X) ; -- Return ien of New Person X
N Y S Y=$S($L($G(X)):+$O(^VA(200,"B",X,0)),1:"")
Q Y
;
EXP(X) ; -- Return code for exposure name X
N Y S Y="",X=$E($G(X))
I X="A" S Y="AO" ;agent orange
I X="R" S Y="IR" ;ionizing radiation
I X="E" S Y="PG" ;persian gulf
I X="H" S Y="HNC" ;head/neck cancer
I X="M" S Y="MST" ;military sexual trauma
I X="C" S Y="CV" ;combat vet
I X="S" S Y="SHAD"
Q Y
;
; ------------ Return data to middle tier ------------
;
XML(PROB) ; -- Return patient problem as XML in @VPR@(I)
N ATT,I,X,Y,P,TAG
D ADD("<problem>") S VPRTOTL=$G(VPRTOTL)+1
S ATT="" F S ATT=$O(PROB(ATT)) Q:ATT="" D D:$L(Y) ADD(Y)
. I ATT="exposure" D S Y="" Q
.. S Y="<exposures>" D ADD(Y)
.. S I=0 F S I=$O(PROB(ATT,I)) Q:I<1 S X=$G(PROB(ATT,I)) S:$L(X) Y="<exposure value='"_X_"' />" D ADD(Y)
.. D ADD("</exposures>")
. I ATT="comment" D S Y="" Q
.. D ADD("<comments>")
.. S I=0 F S I=$O(PROB(ATT,I)) Q:I<1 S X=$G(PROB(ATT,I)) D
... S Y="<comment id='"_I
... S:$L($P(X,U,1)) Y=Y_"' entered='"_$P(X,U)
... S:$L($P(X,U,2)) Y=Y_"' enteredBy='"_$$ESC^VPRD($P(X,U,2))
... S:$L($P(X,U,3)) Y=Y_"' commentText='"_$$ESC^VPRD($P(X,U,3))
... S Y=Y_"' />" D ADD(Y)
.. D ADD("</comments>")
. S X=$G(PROB(ATT)),Y="" Q:'$L(X)
. I X'["^" S Y="<"_ATT_" value='"_$$ESC^VPRD(X)_"' />" Q
. I $L(X)>1 D S Y=""
.. S Y="<"_ATT_" "
.. 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^VPRD($P(X,U,P))_"' "
.. S Y=Y_"/>" D ADD(Y)
D ADD("</problem>")
Q
;
ADD(X) ; Add a line @VPR@(n)=X
S VPRI=$G(VPRI)+1
S @VPR@(VPRI)=X
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVPRDGMPL 5918 printed Dec 13, 2024@02:44:25 Page 2
VPRDGMPL ;SLC/MKB -- Problem extract ;8/2/11 15:29
+1 ;;1.0;VIRTUAL PATIENT RECORD;**1,2,4,5**;Sep 01, 2011;Build 21
+2 ;;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
+4 ; External References DBIA#
+5 ; ------------------- -----
+6 ; ^AUPNPROB 5703
+7 ; ^DPT 10035
+8 ; ^VA(200 10060
+9 ; ^WV(790.05 5772
+10 ; %DT 10003
+11 ; DIQ 2056
+12 ; GMPLUTL2 2741
+13 ; SDUTL3 1252
+14 ; XLFDT 10103
+15 ; XUAF4 2171
+16 ;
+17 ; ------------ Get problems from VistA ------------
+18 ;
EN(DFN,BEG,END,MAX,IFN) ; -- find patient's problems
+1 NEW VPRSTS,VPRPROB,VPRN,VPRITM,VPRCNT,X
+2 ;
+3 ; get one problem
+4 IF $GET(IFN)="790.05"
DO WV(.VPRITM,1)
if $DATA(VPRITM)
DO XML(.VPRITM)
QUIT
+5 IF $GET(IFN)
DO EN1(IFN,.VPRITM)
DO XML(.VPRITM)
QUIT
+6 ;
+7 ; get all patient problems
+8 SET DFN=+$GET(DFN)
if DFN<1
QUIT
+9 SET BEG=$GET(BEG,1410101)
SET END=$GET(END,4141015)
SET MAX=$GET(MAX,9999)
SET VPRCNT=0
+10 ;default = all problems
SET VPRSTS=$GET(FILTER("status"))
+11 DO LIST^GMPLUTL2(.VPRPROB,DFN,VPRSTS)
+12 SET VPRN=0
FOR
SET VPRN=$ORDER(VPRPROB(VPRN))
if (VPRN<1)!(VPRCNT'<MAX)
QUIT
Begin DoDot:1
+13 ;onset
SET X=$PIECE(VPRPROB(VPRN),U,5)
IF X
IF (X<BEG)!(X>END)
QUIT
+14 ;ien
SET X=+VPRPROB(VPRN)
KILL VPRITM
+15 DO EN1(X,.VPRITM)
DO XML(.VPRITM)
+16 SET VPRCNT=VPRCNT+1
End DoDot:1
+17 IF $PIECE($GET(^DPT(DFN,0)),U,2)="F"
DO WV(.VPRITM)
if $DATA(VPRITM)
DO XML(.VPRITM)
+18 QUIT
+19 ;
EN1(ID,PROB) ; -- return a problem in PROB("attribute")=value
+1 NEW VPRL,X,I,J
KILL PROB
+2 ;invalid ien
SET ID=+$GET(ID)
if ID<1
QUIT
+3 ;doesn't exist
DO DETAIL^GMPLUTL2(ID,.VPRL)
if '$DATA(VPRL)
QUIT
+4 SET PROB("id")=ID
SET PROB("name")=$GET(VPRL("NARRATIVE"))
+5 SET PROB("icd")=$GET(VPRL("DIAGNOSIS"))
SET PROB("codingSystem")=$GET(VPRL("CSYS"),"ICD")
+6 FOR I="SCTC","SCTD","SCTT","ICDD"
SET X=$GET(VPRL(I))
if $LENGTH(X)
SET PROB($$LOW^XLFSTR(I))=X
+7 SET X=$GET(VPRL("STATUS"))
if $LENGTH(X)
SET PROB("status")=$EXTRACT(X)_U_X
+8 SET X=$GET(VPRL("HISTORY"))
if $LENGTH(X)
SET PROB("history")=$EXTRACT(X)_U_X
+9 SET X=$GET(VPRL("PRIORITY"))
if $LENGTH(X)
SET PROB("acuity")=$EXTRACT(X)_U_X
+10 ; get internal form of dates via FM instead of DETAIL
+11 SET X=$$GET1^DIQ(9000011,ID_",",.03,"I")
if X
SET PROB("updated")=X
+12 SET X=$$GET1^DIQ(9000011,ID_",",.08,"I")
if X
SET PROB("entered")=X
+13 SET X=$$GET1^DIQ(9000011,ID_",",.13,"I")
if X
SET PROB("onset")=X
+14 SET X=$$GET1^DIQ(9000011,ID_",",1.07,"I")
if X
SET PROB("resolved")=X
+15 SET X=$EXTRACT($GET(VPRL("CONDITION")))
+16 if X="P"
SET PROB("unverified")=0
SET PROB("removed")=0
+17 if X="T"
SET PROB("unverified")=1
SET PROB("removed")=0
+18 if X="H"
SET PROB("unverified")=0
SET PROB("removed")=1
+19 SET X=$GET(VPRL("SC"))
SET X=$SELECT(X="YES":1,X="NO":0,1:"")
+20 ;ao^rad^pgulf^hnc^mst^cv
if $LENGTH(X)
SET PROB("sc")=X
IF $GET(VPRL("EXPOSURE"))
Begin DoDot:1
+21 SET I=0
FOR
SET I=$ORDER(VPRL("EXPOSURE",I))
if I<1
QUIT
Begin DoDot:2
+22 SET X=$GET(VPRL("EXPOSURE",I))
+23 SET PROB("exposure",I)=$$EXP(X)
End DoDot:2
End DoDot:1
+24 SET X=$GET(VPRL("PROVIDER"))
if $LENGTH(X)
SET PROB("provider")=$$GET1^DIQ(9000011,ID_",",1.05,"I")_U_X
+25 SET X=$GET(VPRL("SERVICE"))
if $LENGTH(X)
SET PROB("service")=X
+26 SET X=$GET(VPRL("CLINIC"))
if $LENGTH(X)
SET PROB("location")=X
+27 SET X=+$GET(VPRL("FACILITY"))
+28 if X
SET PROB("facility")=$$STA^XUAF4(X)_U_$PIECE($$NS^XUAF4(X),U)
+29 ;local stn#^name
IF 'X
SET PROB("facility")=$$FAC^VPRD
CMT ; comments
+1 if '$GET(VPRL("COMMENT"))
QUIT
+2 SET I=0
FOR
SET I=$ORDER(VPRL("COMMENT",I))
if I<1
QUIT
Begin DoDot:1
+3 SET X=$GET(VPRL("COMMENT",I))
+4 SET PROB("comment",I)=$$DATE($PIECE(X,U))_U_$PIECE(X,U,2,3)
+5 ; = date ^ name of author ^ text
End DoDot:1
+6 QUIT
+7 ;
WV(PROB,UPD) ; -- return a pregnancy log entry in PROB("attribute")=value
+1 NEW I,X0,Y
KILL PROB
+2 ;last entry
SET I=$ORDER(^WV(790.05,"C",DFN,""),-1)
if 'I
QUIT
+3 SET X0=$GET(^WV(790.05,I,0))
SET Y=0
+4 ; status=YES, future due date (allow past 14 days)
+5 IF $PIECE(X0,U,3)
IF $PIECE(X0,U,4)'<$$FMADD^XLFDT(DT,-14)
SET Y=1
+6 IF 'Y
IF '$GET(UPD)
QUIT
+7 ; continue if pregnant, or update requested
+8 SET PROB("id")="790.05"
SET PROB("entered")=+X0
+9 SET PROB("name")="Pregnancy"
SET PROB("icd")="V22.2"
+10 SET PROB("icdd")="PREGNANT STATE, INCIDENTAL"
+11 SET PROB("codingSystem")="ICD"
+12 SET PROB("sctc")="77386006"
SET PROB("sctt")="Patient currently pregnant (finding)"
+13 ; PROB("problemType")=64572001 ;HITSP/Condition
+14 SET PROB("status")=$SELECT(Y:"A^ACTIVE",1:"I^INACTIVE")
+15 ;due date
SET PROB("resolved")=$PIECE(X0,U,4)
+16 ;primary care
SET PROB("provider")=$$OUTPTPR^SDUTL3(DFN)
+17 SET PROB("facility")=$$FAC^VPRD
+18 QUIT
+19 ;
DATE(X) ; -- Return internal form of date X
+1 NEW %DT,Y
+2 SET %DT=""
DO ^%DT
if Y<1
SET Y=X
+3 QUIT Y
+4 ;
VA200(X) ; -- Return ien of New Person X
+1 NEW Y
SET Y=$SELECT($LENGTH($GET(X)):+$ORDER(^VA(200,"B",X,0)),1:"")
+2 QUIT Y
+3 ;
EXP(X) ; -- Return code for exposure name X
+1 NEW Y
SET Y=""
SET X=$EXTRACT($GET(X))
+2 ;agent orange
IF X="A"
SET Y="AO"
+3 ;ionizing radiation
IF X="R"
SET Y="IR"
+4 ;persian gulf
IF X="E"
SET Y="PG"
+5 ;head/neck cancer
IF X="H"
SET Y="HNC"
+6 ;military sexual trauma
IF X="M"
SET Y="MST"
+7 ;combat vet
IF X="C"
SET Y="CV"
+8 IF X="S"
SET Y="SHAD"
+9 QUIT Y
+10 ;
+11 ; ------------ Return data to middle tier ------------
+12 ;
XML(PROB) ; -- Return patient problem as XML in @VPR@(I)
+1 NEW ATT,I,X,Y,P,TAG
+2 DO ADD("<problem>")
SET VPRTOTL=$GET(VPRTOTL)+1
+3 SET ATT=""
FOR
SET ATT=$ORDER(PROB(ATT))
if ATT=""
QUIT
Begin DoDot:1
+4 IF ATT="exposure"
Begin DoDot:2
+5 SET Y="<exposures>"
DO ADD(Y)
+6 SET I=0
FOR
SET I=$ORDER(PROB(ATT,I))
if I<1
QUIT
SET X=$GET(PROB(ATT,I))
if $LENGTH(X)
SET Y="<exposure value='"_X_"' />"
DO ADD(Y)
+7 DO ADD("</exposures>")
End DoDot:2
SET Y=""
QUIT
+8 IF ATT="comment"
Begin DoDot:2
+9 DO ADD("<comments>")
+10 SET I=0
FOR
SET I=$ORDER(PROB(ATT,I))
if I<1
QUIT
SET X=$GET(PROB(ATT,I))
Begin DoDot:3
+11 SET Y="<comment id='"_I
+12 if $LENGTH($PIECE(X,U,1))
SET Y=Y_"' entered='"_$PIECE(X,U)
+13 if $LENGTH($PIECE(X,U,2))
SET Y=Y_"' enteredBy='"_$$ESC^VPRD($PIECE(X,U,2))
+14 if $LENGTH($PIECE(X,U,3))
SET Y=Y_"' commentText='"_$$ESC^VPRD($PIECE(X,U,3))
+15 SET Y=Y_"' />"
DO ADD(Y)
End DoDot:3
+16 DO ADD("</comments>")
End DoDot:2
SET Y=""
QUIT
+17 SET X=$GET(PROB(ATT))
SET Y=""
if '$LENGTH(X)
QUIT
+18 IF X'["^"
SET Y="<"_ATT_" value='"_$$ESC^VPRD(X)_"' />"
QUIT
+19 IF $LENGTH(X)>1
Begin DoDot:2
+20 SET Y="<"_ATT_" "
+21 FOR P=1:1
SET TAG=$PIECE("code^name^Z",U,P)
if TAG="Z"
QUIT
IF $LENGTH($PIECE(X,U,P))
SET Y=Y_TAG_"='"_$$ESC^VPRD($PIECE(X,U,P))_"' "
+22 SET Y=Y_"/>"
DO ADD(Y)
End DoDot:2
SET Y=""
End DoDot:1
if $LENGTH(Y)
DO ADD(Y)
+23 DO ADD("</problem>")
+24 QUIT
+25 ;
ADD(X) ; Add a line @VPR@(n)=X
+1 SET VPRI=$GET(VPRI)+1
+2 SET @VPR@(VPRI)=X
+3 QUIT