VPRDJ04 ;SLC/MKB -- Appointments,Visits ;6/25/12 16:11
;;1.0;VIRTUAL PATIENT RECORD;**2,5,7**;Sep 01, 2011;Build 3
;;Per VHA Directive 2004-038, this routine should not be modified.
;
; External References DBIA#
; ------------------- -----
; ^AUPNVSIT 2028
; ^DGS(41.1 3796
; ^DIC(42 10039
; ^SC 10040
; ^VA(200 10060
; DIQ 2056
; ICPTCOD 1995
; PXAPI,^TMP("PXKENC",$J 1894
; SDAMA301 4433
; XLFDT 10103
; XLFSTR 10104
; XUAF4 2171
;
; All tags expect DFN, ID, [VPRSTART, VPRSTOP, VPRMAX, VPRTEXT]
;
SDAM1 ; -- appointment ^TMP($J,"SDAMA301",DFN,VPRDT)
N NODE,HLOC,APPT,X,STS,CLS,FAC,SV,PRV
S NODE=$G(^TMP($J,"SDAMA301",DFN,VPRDT))
;
S HLOC=$P(NODE,U,2),X="A;"_VPRDT_";"_+HLOC
I $L($G(ID)),$P(ID,";",1,3)'=X Q
S APPT("localId")=X,APPT("uid")=$$SETUID^VPRUTILS("appointment",DFN,X)
S X=$P(NODE,U,10),APPT("typeCode")=$P(X,";"),APPT("typeName")=$P(X,";",2)
S STS=$P(NODE,U,3),CLS=$S($E(STS)="I":"I",1:"O")
S APPT("dateTime")=$$JSONDT^VPRUTILS(VPRDT)
S:$L($P(NODE,U,6)) APPT("comment")=$P(NODE,U,6)
S:$P(NODE,U,9) APPT("checkIn")=$$JSONDT^VPRUTILS($P(NODE,U,9))
S:$P(NODE,U,11) APPT("checkOut")=$$JSONDT^VPRUTILS($P(NODE,U,11))
I $L(ID,";")>3 S APPT("reasonName")=$P(ID,";",4),PRV=+$P(ID,";",5) ;from SDAM event
S FAC=$$FAC^VPRD(+HLOC) D FACILITY^VPRUTILS(FAC,"APPT") I HLOC D
. S APPT("locationName")=$P(HLOC,";",2)
. S APPT("locationUid")=$$SETUID^VPRUTILS("location",,+HLOC)
. S X=$$AMIS^VPRDVSIT(+$P(NODE,U,13))
. S:$L(X) APPT("stopCodeUid")="urn:va:stop-code:"_$P(X,U),APPT("stopCodeName")=$P(X,U,2)
. S SV=$$GET1^DIQ(44,+HLOC_",",9.5,"I")
. I SV S APPT("service")=$$SERV^VPRDSDAM(SV)
. ;find default provider
. S:'$G(PRV) PRV=+$$GET1^DIQ(44,+HLOC_",",16,"I") I 'PRV D
.. N VPRP,I,FIRST
.. D GETS^DIQ(44,+HLOC_",","2600*","I","VPRP")
.. S FIRST=$O(VPRP(44.1,"")),I=""
.. F S I=$O(VPRP(44.1,I)) Q:I="" I $G(VPRP(44.1,I,.02,"I")) S PRV=$G(VPRP(44.1,I,.01,"I")) Q
.. I 'PRV,FIRST S PRV=$G(VPRP(44.1,FIRST,.01,"I"))
I $G(PRV) S APPT("providers",1,"providerUid")=$$SETUID^VPRUTILS("user",,PRV),APPT("providers",1,"providerName")=$P($G(^VA(200,PRV,0)),U)
I $G(SV) S APPT("summary")="${"_APPT("service")_"}:"_$P(HLOC,";",2)
S APPT("patientClassCode")="urn:va:patient-class:"_$S(CLS="I":"IMP",1:"AMB")
S APPT("patientClassName")=$S(CLS="I":"Inpatient",1:"Ambulatory")
S APPT("categoryCode")="urn:va:encounter-category:OV",APPT("categoryName")="Outpatient Visit"
S APPT("appointmentStatus")=$P(STS,";",2)
D ADD^VPRDJ("APPT","appointment")
Q
;
DGS ; scheduled admissions [from APPOINTM^VPRDJ0]
S VPRA=0 F S VPRA=$O(^DGS(41.1,"B",DFN,VPRA)) Q:VPRA<1 D Q:VPRI'<VPRMAX
. S VPRX=$G(^DGS(41.1,VPRA,0))
. I $L($G(ID)),+$P(ID,";",2)=+$P(VPRX,U,2) D DGS1(VPRA) Q
. Q:$P(VPRX,U,13) Q:$P(VPRX,U,17) ;cancelled or admitted
. S X=$P(VPRX,U,2) Q:X<VPRSTART!(X>VPRSTOP) ;out of date range
. D DGS1(VPRA)
Q
;
DGS1(IFN) ; -- scheduled admission
N ADM,X0,DATE,HLOC,FAC,SV,X
S X0=$G(^DGS(41.1,+$G(IFN),0)) Q:X0="" ;deleted
;
S DATE=+$P(X0,U,2),HLOC=+$G(^DIC(42,+$P(X0,U,8),44))
S X="H;"_DATE,ADM("localId")=X,ADM("uid")=$$SETUID^VPRUTILS("appointment",DFN,X)
S ADM("dateTime")=$$JSONDT^VPRUTILS(DATE)
S FAC=$$FAC^VPRD(+HLOC) D FACILITY^VPRUTILS(FAC,"ADM") I HLOC D
. S HLOC=+HLOC_";"_$P($G(^SC(+HLOC,0)),U)
. S ADM("uid")=ADM("uid")_";"_+HLOC
. S ADM("locationName")=$P(HLOC,";",2)
. S ADM("locationUid")=$$SETUID^VPRUTILS("location",,+HLOC)
. S X=$$GET1^DIQ(44,+HLOC_",",8,"I"),X=$$AMIS^VPRDVSIT(X)
. S:$L(X) ADM("stopCodeUid")="urn:va:stop-code:"_$P(X,U),ADM("stopCodeName")=$P(X,U,2)
. S SV=$$GET1^DIQ(44,+HLOC_",",9.5,"I")
. I SV S ADM("service")=$$SERV^VPRDSDAM(SV)
I $G(SV) S ADM("summary")="${"_ADM("service")_"}:"_$P(HLOC,";",2)
S X=+$P(X0,U,5) I X D
. S ADM("providers",1,"providerUid")=$$SETUID^VPRUTILS("user",,X)
. S ADM("providers",1,"providerName")=$P($G(^VA(200,X,0)),U)
S ADM("patientClassCode")="urn:va:patient-class:IMP",ADM("patientClassName")="Inpatient"
S ADM("categoryCode")="urn:va:encounter-category:AD",ADM("categoryName")="Admission"
S ADM("appointmentStatus")=$S($P(X0,U,17):"ADMITTED",$P(X0,U,13):"CANCELLED",1:"SCHEDULED")
D ADD^VPRDJ("ADM","appointment")
Q
;
VSIT1(ID) ; -- visit
N VST,X0,X15,X,FAC,LOC,CATG,AMIS,INPT,DA
I $G(ID)?1"H"1.N D ADM^VPRDJ04A(ID) Q
D ENCEVENT^PXAPI(ID)
;
S X0=$G(^TMP("PXKENC",$J,ID,"VST",ID,0)),X15=$G(^(150))
Q:$P(X15,U,3)'="P" Q:$P(X0,U,12) ;Q:$P(X0,U,7)="E" ;primary, not historical or child
I $P(X0,U,7)="H" D ADM^VPRDJ04A(ID,+X0) Q
S VST("localId")=ID,VST("uid")=$$SETUID^VPRUTILS("visit",DFN,ID)
S VST("dateTime")=$$JSONDT^VPRUTILS(+X0)
S:$P(X0,U,18) VST("checkOut")=$$JSONDT^VPRUTILS($P(X0,U,18))
S FAC=+$P(X0,U,6),CATG=$P(X0,U,7),LOC=+$P(X0,U,22)
S:FAC X=$$STA^XUAF4(FAC)_U_$P($$NS^XUAF4(FAC),U)
S:'FAC X=$$FAC^VPRD(LOC) D FACILITY^VPRUTILS(X,"VST")
S X=$S(CATG="H":"AD",CATG="C":"CR",CATG="T":"TC",CATG="N":"U",CATG="R":"NH","D^X"[CATG:"O",1:"OV")
S VST("categoryCode")="urn:va:encounter-category:"_X
S VST("categoryName")=$S(X="AD":"Admission",X="CR":"Chart Review",X="TC":"Phone Contact",X="U":"Unknown",X="NH":"Nursing Home",X="O":"Other",1:"Outpatient Visit")
S INPT=$P(X15,U,2) S:INPT="" INPT=$S("H^I^R^D"[CATG:1,1:0)
S X=$$CPT^VPRDVSIT(ID) S:X VST("typeName")=$P($$CPT^ICPTCOD(X),U,3)
I 'X S VST("typeName")=$S('INPT&LOC:$P($G(^SC(LOC,0)),U)_" VISIT",1:$$CATG^VPRDVSIT(CATG))
S VST("patientClassCode")="urn:va:patient-class:"_$S(INPT:"IMP",1:"AMB")
S VST("patientClassName")=$S(INPT:"Inpatient",1:"Ambulatory")
S X=$P(X0,U,8) S:X AMIS=$$AMIS^VPRDVSIT(X) I LOC D
. N L0 S L0=$G(^SC(LOC,0))
. I 'X S AMIS=$$AMIS^VPRDVSIT($P(L0,U,7))
. S VST("locationUid")=$$SETUID^VPRUTILS("location",,+LOC)
. S VST("locationName")=$P(L0,U)
. S X=$$SERV^VPRDVSIT($P(L0,U,20)) Q:X=""
. S:$L(X) VST("service")=X,VST("summary")="${"_VST("service")_"}:"_$P(L0,U)
S:$D(AMIS) VST("stopCodeUid")="urn:va:stop-code:"_$P(AMIS,U),VST("stopCodeName")=$P(AMIS,U,2)
S X=$$POV^VPRDVSIT(ID) I $L(X) D
. N SYS S SYS=$P(X,U,3),SYS=$$LOW^XLFSTR(SYS)
. S VST("reasonUid")=$$SETNCS^VPRUTILS(SYS,$P(X,U)),VST("reasonName")=$P(X,U,2)
; provider(s)
S DA=0 F S DA=$O(^TMP("PXKENC",$J,ID,"PRV",DA)) Q:DA<1 S X0=$G(^(DA,0)) D
. I $P(X0,U,4)="P" D PROV("VST",DA,+X0,"P",1) Q ;primary
. D PROV("VST",DA,+X0,"S") ;secondary
K ^TMP("PXKENC",$J,ID)
; note(s)
D TIU^VPRDJ04A(ID,.VST)
D ADD^VPRDJ("VST","visit")
Q
;
PROV(ARR,I,IEN,ROLE,PRIM) ; -- add providers
S @ARR@("providers",I,"providerUid")=$$SETUID^VPRUTILS("user",,+IEN)
S @ARR@("providers",I,"providerName")=$P($G(^VA(200,+IEN,0)),U)
S @ARR@("providers",I,"role")=ROLE
S:$G(PRIM) @ARR@("providers",I,"primary")="true"
Q
;
NAME(IEN) ; -- Return a string 'name' for the visit
N Y,X0,LOC,DATE
S X0=$G(^AUPNVSIT(+$G(IEN),0)),Y=""
S DATE=+X0,LOC=+$P(X0,U,22) S:LOC LOC=$P($G(^SC(LOC,0)),U)_" "
S Y=LOC_$$FMTE^XLFDT(DATE,"1D") ;Mon DD, YYYY
Q Y
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVPRDJ04 7294 printed Dec 13, 2024@02:44:37 Page 2
VPRDJ04 ;SLC/MKB -- Appointments,Visits ;6/25/12 16:11
+1 ;;1.0;VIRTUAL PATIENT RECORD;**2,5,7**;Sep 01, 2011;Build 3
+2 ;;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
+4 ; External References DBIA#
+5 ; ------------------- -----
+6 ; ^AUPNVSIT 2028
+7 ; ^DGS(41.1 3796
+8 ; ^DIC(42 10039
+9 ; ^SC 10040
+10 ; ^VA(200 10060
+11 ; DIQ 2056
+12 ; ICPTCOD 1995
+13 ; PXAPI,^TMP("PXKENC",$J 1894
+14 ; SDAMA301 4433
+15 ; XLFDT 10103
+16 ; XLFSTR 10104
+17 ; XUAF4 2171
+18 ;
+19 ; All tags expect DFN, ID, [VPRSTART, VPRSTOP, VPRMAX, VPRTEXT]
+20 ;
SDAM1 ; -- appointment ^TMP($J,"SDAMA301",DFN,VPRDT)
+1 NEW NODE,HLOC,APPT,X,STS,CLS,FAC,SV,PRV
+2 SET NODE=$GET(^TMP($JOB,"SDAMA301",DFN,VPRDT))
+3 ;
+4 SET HLOC=$PIECE(NODE,U,2)
SET X="A;"_VPRDT_";"_+HLOC
+5 IF $LENGTH($GET(ID))
IF $PIECE(ID,";",1,3)'=X
QUIT
+6 SET APPT("localId")=X
SET APPT("uid")=$$SETUID^VPRUTILS("appointment",DFN,X)
+7 SET X=$PIECE(NODE,U,10)
SET APPT("typeCode")=$PIECE(X,";")
SET APPT("typeName")=$PIECE(X,";",2)
+8 SET STS=$PIECE(NODE,U,3)
SET CLS=$SELECT($EXTRACT(STS)="I":"I",1:"O")
+9 SET APPT("dateTime")=$$JSONDT^VPRUTILS(VPRDT)
+10 if $LENGTH($PIECE(NODE,U,6))
SET APPT("comment")=$PIECE(NODE,U,6)
+11 if $PIECE(NODE,U,9)
SET APPT("checkIn")=$$JSONDT^VPRUTILS($PIECE(NODE,U,9))
+12 if $PIECE(NODE,U,11)
SET APPT("checkOut")=$$JSONDT^VPRUTILS($PIECE(NODE,U,11))
+13 ;from SDAM event
IF $LENGTH(ID,";")>3
SET APPT("reasonName")=$PIECE(ID,";",4)
SET PRV=+$PIECE(ID,";",5)
+14 SET FAC=$$FAC^VPRD(+HLOC)
DO FACILITY^VPRUTILS(FAC,"APPT")
IF HLOC
Begin DoDot:1
+15 SET APPT("locationName")=$PIECE(HLOC,";",2)
+16 SET APPT("locationUid")=$$SETUID^VPRUTILS("location",,+HLOC)
+17 SET X=$$AMIS^VPRDVSIT(+$PIECE(NODE,U,13))
+18 if $LENGTH(X)
SET APPT("stopCodeUid")="urn:va:stop-code:"_$PIECE(X,U)
SET APPT("stopCodeName")=$PIECE(X,U,2)
+19 SET SV=$$GET1^DIQ(44,+HLOC_",",9.5,"I")
+20 IF SV
SET APPT("service")=$$SERV^VPRDSDAM(SV)
+21 ;find default provider
+22 if '$GET(PRV)
SET PRV=+$$GET1^DIQ(44,+HLOC_",",16,"I")
IF 'PRV
Begin DoDot:2
+23 NEW VPRP,I,FIRST
+24 DO GETS^DIQ(44,+HLOC_",","2600*","I","VPRP")
+25 SET FIRST=$ORDER(VPRP(44.1,""))
SET I=""
+26 FOR
SET I=$ORDER(VPRP(44.1,I))
if I=""
QUIT
IF $GET(VPRP(44.1,I,.02,"I"))
SET PRV=$GET(VPRP(44.1,I,.01,"I"))
QUIT
+27 IF 'PRV
IF FIRST
SET PRV=$GET(VPRP(44.1,FIRST,.01,"I"))
End DoDot:2
End DoDot:1
+28 IF $GET(PRV)
SET APPT("providers",1,"providerUid")=$$SETUID^VPRUTILS("user",,PRV)
SET APPT("providers",1,"providerName")=$PIECE($GET(^VA(200,PRV,0)),U)
+29 IF $GET(SV)
SET APPT("summary")="${"_APPT("service")_"}:"_$PIECE(HLOC,";",2)
+30 SET APPT("patientClassCode")="urn:va:patient-class:"_$SELECT(CLS="I":"IMP",1:"AMB")
+31 SET APPT("patientClassName")=$SELECT(CLS="I":"Inpatient",1:"Ambulatory")
+32 SET APPT("categoryCode")="urn:va:encounter-category:OV"
SET APPT("categoryName")="Outpatient Visit"
+33 SET APPT("appointmentStatus")=$PIECE(STS,";",2)
+34 DO ADD^VPRDJ("APPT","appointment")
+35 QUIT
+36 ;
DGS ; scheduled admissions [from APPOINTM^VPRDJ0]
+1 SET VPRA=0
FOR
SET VPRA=$ORDER(^DGS(41.1,"B",DFN,VPRA))
if VPRA<1
QUIT
Begin DoDot:1
+2 SET VPRX=$GET(^DGS(41.1,VPRA,0))
+3 IF $LENGTH($GET(ID))
IF +$PIECE(ID,";",2)=+$PIECE(VPRX,U,2)
DO DGS1(VPRA)
QUIT
+4 ;cancelled or admitted
if $PIECE(VPRX,U,13)
QUIT
if $PIECE(VPRX,U,17)
QUIT
+5 ;out of date range
SET X=$PIECE(VPRX,U,2)
if X<VPRSTART!(X>VPRSTOP)
QUIT
+6 DO DGS1(VPRA)
End DoDot:1
if VPRI'<VPRMAX
QUIT
+7 QUIT
+8 ;
DGS1(IFN) ; -- scheduled admission
+1 NEW ADM,X0,DATE,HLOC,FAC,SV,X
+2 ;deleted
SET X0=$GET(^DGS(41.1,+$GET(IFN),0))
if X0=""
QUIT
+3 ;
+4 SET DATE=+$PIECE(X0,U,2)
SET HLOC=+$GET(^DIC(42,+$PIECE(X0,U,8),44))
+5 SET X="H;"_DATE
SET ADM("localId")=X
SET ADM("uid")=$$SETUID^VPRUTILS("appointment",DFN,X)
+6 SET ADM("dateTime")=$$JSONDT^VPRUTILS(DATE)
+7 SET FAC=$$FAC^VPRD(+HLOC)
DO FACILITY^VPRUTILS(FAC,"ADM")
IF HLOC
Begin DoDot:1
+8 SET HLOC=+HLOC_";"_$PIECE($GET(^SC(+HLOC,0)),U)
+9 SET ADM("uid")=ADM("uid")_";"_+HLOC
+10 SET ADM("locationName")=$PIECE(HLOC,";",2)
+11 SET ADM("locationUid")=$$SETUID^VPRUTILS("location",,+HLOC)
+12 SET X=$$GET1^DIQ(44,+HLOC_",",8,"I")
SET X=$$AMIS^VPRDVSIT(X)
+13 if $LENGTH(X)
SET ADM("stopCodeUid")="urn:va:stop-code:"_$PIECE(X,U)
SET ADM("stopCodeName")=$PIECE(X,U,2)
+14 SET SV=$$GET1^DIQ(44,+HLOC_",",9.5,"I")
+15 IF SV
SET ADM("service")=$$SERV^VPRDSDAM(SV)
End DoDot:1
+16 IF $GET(SV)
SET ADM("summary")="${"_ADM("service")_"}:"_$PIECE(HLOC,";",2)
+17 SET X=+$PIECE(X0,U,5)
IF X
Begin DoDot:1
+18 SET ADM("providers",1,"providerUid")=$$SETUID^VPRUTILS("user",,X)
+19 SET ADM("providers",1,"providerName")=$PIECE($GET(^VA(200,X,0)),U)
End DoDot:1
+20 SET ADM("patientClassCode")="urn:va:patient-class:IMP"
SET ADM("patientClassName")="Inpatient"
+21 SET ADM("categoryCode")="urn:va:encounter-category:AD"
SET ADM("categoryName")="Admission"
+22 SET ADM("appointmentStatus")=$SELECT($PIECE(X0,U,17):"ADMITTED",$PIECE(X0,U,13):"CANCELLED",1:"SCHEDULED")
+23 DO ADD^VPRDJ("ADM","appointment")
+24 QUIT
+25 ;
VSIT1(ID) ; -- visit
+1 NEW VST,X0,X15,X,FAC,LOC,CATG,AMIS,INPT,DA
+2 IF $GET(ID)?1"H"1.N
DO ADM^VPRDJ04A(ID)
QUIT
+3 DO ENCEVENT^PXAPI(ID)
+4 ;
+5 SET X0=$GET(^TMP("PXKENC",$JOB,ID,"VST",ID,0))
SET X15=$GET(^(150))
+6 ;Q:$P(X0,U,7)="E" ;primary, not historical or child
if $PIECE(X15,U,3)'="P"
QUIT
if $PIECE(X0,U,12)
QUIT
+7 IF $PIECE(X0,U,7)="H"
DO ADM^VPRDJ04A(ID,+X0)
QUIT
+8 SET VST("localId")=ID
SET VST("uid")=$$SETUID^VPRUTILS("visit",DFN,ID)
+9 SET VST("dateTime")=$$JSONDT^VPRUTILS(+X0)
+10 if $PIECE(X0,U,18)
SET VST("checkOut")=$$JSONDT^VPRUTILS($PIECE(X0,U,18))
+11 SET FAC=+$PIECE(X0,U,6)
SET CATG=$PIECE(X0,U,7)
SET LOC=+$PIECE(X0,U,22)
+12 if FAC
SET X=$$STA^XUAF4(FAC)_U_$PIECE($$NS^XUAF4(FAC),U)
+13 if 'FAC
SET X=$$FAC^VPRD(LOC)
DO FACILITY^VPRUTILS(X,"VST")
+14 SET X=$SELECT(CATG="H":"AD",CATG="C":"CR",CATG="T":"TC",CATG="N":"U",CATG="R":"NH","D^X"[CATG:"O",1:"OV")
+15 SET VST("categoryCode")="urn:va:encounter-category:"_X
+16 SET VST("categoryName")=$SELECT(X="AD":"Admission",X="CR":"Chart Review",X="TC":"Phone Contact",X="U":"Unknown",X="NH":"Nursing Home",X="O":"Other",1:"Outpatient Visit")
+17 SET INPT=$PIECE(X15,U,2)
if INPT=""
SET INPT=$SELECT("H^I^R^D"[CATG:1,1:0)
+18 SET X=$$CPT^VPRDVSIT(ID)
if X
SET VST("typeName")=$PIECE($$CPT^ICPTCOD(X),U,3)
+19 IF 'X
SET VST("typeName")=$SELECT('INPT&LOC:$PIECE($GET(^SC(LOC,0)),U)_" VISIT",1:$$CATG^VPRDVSIT(CATG))
+20 SET VST("patientClassCode")="urn:va:patient-class:"_$SELECT(INPT:"IMP",1:"AMB")
+21 SET VST("patientClassName")=$SELECT(INPT:"Inpatient",1:"Ambulatory")
+22 SET X=$PIECE(X0,U,8)
if X
SET AMIS=$$AMIS^VPRDVSIT(X)
IF LOC
Begin DoDot:1
+23 NEW L0
SET L0=$GET(^SC(LOC,0))
+24 IF 'X
SET AMIS=$$AMIS^VPRDVSIT($PIECE(L0,U,7))
+25 SET VST("locationUid")=$$SETUID^VPRUTILS("location",,+LOC)
+26 SET VST("locationName")=$PIECE(L0,U)
+27 SET X=$$SERV^VPRDVSIT($PIECE(L0,U,20))
if X=""
QUIT
+28 if $LENGTH(X)
SET VST("service")=X
SET VST("summary")="${"_VST("service")_"}:"_$PIECE(L0,U)
End DoDot:1
+29 if $DATA(AMIS)
SET VST("stopCodeUid")="urn:va:stop-code:"_$PIECE(AMIS,U)
SET VST("stopCodeName")=$PIECE(AMIS,U,2)
+30 SET X=$$POV^VPRDVSIT(ID)
IF $LENGTH(X)
Begin DoDot:1
+31 NEW SYS
SET SYS=$PIECE(X,U,3)
SET SYS=$$LOW^XLFSTR(SYS)
+32 SET VST("reasonUid")=$$SETNCS^VPRUTILS(SYS,$PIECE(X,U))
SET VST("reasonName")=$PIECE(X,U,2)
End DoDot:1
+33 ; provider(s)
+34 SET DA=0
FOR
SET DA=$ORDER(^TMP("PXKENC",$JOB,ID,"PRV",DA))
if DA<1
QUIT
SET X0=$GET(^(DA,0))
Begin DoDot:1
+35 ;primary
IF $PIECE(X0,U,4)="P"
DO PROV("VST",DA,+X0,"P",1)
QUIT
+36 ;secondary
DO PROV("VST",DA,+X0,"S")
End DoDot:1
+37 KILL ^TMP("PXKENC",$JOB,ID)
+38 ; note(s)
+39 DO TIU^VPRDJ04A(ID,.VST)
+40 DO ADD^VPRDJ("VST","visit")
+41 QUIT
+42 ;
PROV(ARR,I,IEN,ROLE,PRIM) ; -- add providers
+1 SET @ARR@("providers",I,"providerUid")=$$SETUID^VPRUTILS("user",,+IEN)
+2 SET @ARR@("providers",I,"providerName")=$PIECE($GET(^VA(200,+IEN,0)),U)
+3 SET @ARR@("providers",I,"role")=ROLE
+4 if $GET(PRIM)
SET @ARR@("providers",I,"primary")="true"
+5 QUIT
+6 ;
NAME(IEN) ; -- Return a string 'name' for the visit
+1 NEW Y,X0,LOC,DATE
+2 SET X0=$GET(^AUPNVSIT(+$GET(IEN),0))
SET Y=""
+3 SET DATE=+X0
SET LOC=+$PIECE(X0,U,22)
if LOC
SET LOC=$PIECE($GET(^SC(LOC,0)),U)_" "
+4 ;Mon DD, YYYY
SET Y=LOC_$$FMTE^XLFDT(DATE,"1D")
+5 QUIT Y