VAFHLPV1 ;ALB/CM/ESD HL7 PV1 SEGMENT BUILDING ;06/08/00
;;5.3;Registration;**94,106,151,298,617**;Aug 13, 1993
;
;This routine will build an HL7 PV1 segment for an inpatient or
;outpatient event depending on the entry point used.
;Use IN for inpatient
;Use OUT for outpatient
;
IN(DFN,VAFHDT,VAFSTR,IEN,PIVOT,SETID,VAFDIAG) ;
N RESULT
S RESULT=$$EN^VAFHAPV1(DFN,VAFHDT,VAFSTR,IEN,PIVOT,SETID,.VAFDIAG)
Q $G(RESULT)
;
OUT(DFN,EVT,EVDTS,VPTR,STRP,NUMP) ;
;DFN - Patient File
;EVT - event number from pivot file
;EVDTS - event date/time in FileMan format
;VPTR - variable pointer
;STRP - string of fields (if null - required fields, if "A" - supported
;fields, or string of fields seperated by commas")
;NUMP - ID # (optional)
;
N ERR
I '$D(NUMP) S NUMP=1
S ERR=$$OPV1^VAFHCPV($G(DFN),$G(EVT),$G(EVDTS),$G(VPTR),$G(STRP),NUMP)
Q ERR
KVAR ;
K VAFHLPV1
Q
;
EN(VAFENC,VAFDENC,VAFSTR,VAFNUM,VAFHLQ,VAFHLFS) ;
; Entry point for Ambulatory Care Database Project
;
; Entry point to return the HL7 PV1 (Patient Visit) segment
;
; Input: VAFENC - Outpatient Encounter IEN (pointer to Outpatient
; Encounter file #409.68)
;
; VAFDENC - Deleted Outpatient Encounter IEN (pointer to
; Deleted Outpatient Encounter file #409.74)
;
; VAFSTR - String of fields requested separated by commas
;
; VAFNUM - Set ID (sequential number - default=1)
;
; VAFHLQ - Optional HL7 null variable. If not there, use
; default HL7 variable.
;
; VAFHLFS - Optional HL7 field separator. If not there, use
; default HL7 variable.
;
; Output: String containing desired components of the PV1 segment
;
; NOTE: Data for the PV1 segment will be retrieved from either the
; Outpatient Encounter file (#409.68) or Deleted Outpatient
; Encounter (#409.74) based on the pointer parameter passed in.
;
;06/08/2000 ACS - AMBCARE PV1 CHANGES:
; 1. SET UP HL7 DEFAULT VARIABLES AT BEGINNING OF SUBROUTINE.
; 2. VALIDATE EXISTENCE OF AMBCARE ENCOUNTER.
; 3. ALWAYS RETURN PATIENT CLASS IN SEGMENT.
;
;
N VAFAPTYP,VAFCLIN,VAFDAT,VAFDFN,VAFFLG,VAFNODE,VAFNODE1,VAFORIG,VAFPTCL,VAFY,X,VAINVENC,VAFPSTAT,VAFPIN
;
; - If VAFHLQ or VAFHLFS aren't passed in, use default HL7 variables.
S VAFHLQ=$S($D(VAFHLQ):VAFHLQ,1:$G(HLQ)),VAFHLFS=$S($D(VAFHLFS):VAFHLFS,1:$G(HLFS))
;
;- Sequential Number
S $P(VAFY,VAFHLFS,1)=$S($G(VAFNUM):VAFNUM,1:1)
;
S VAFPTCL="O" ; Patient Class = Outpatient
;
;- Set patient class in segment
S $P(VAFY,VAFHLFS,2)=VAFPTCL
;
;- If encounter or variable string missing, pass back incomplete segment
I ($G(VAFENC)=""&($G(VAFDENC)=""))!($G(VAFSTR)="") G ENQ
;
; - If regular encounter doesn't exist, pass back incomplete segment
I $G(VAFENC) D G:$G(VAINVENC) ENQ
. I '$D(^SCE($G(VAFENC))) S VAINVENC=1
;
; - If deleted encounter doesn't exist, pass back incomplete segment
I $G(VAFDENC) D G:$G(VAINVENC) ENQ
. I '$D(^SD(409.74,$G(VAFDENC))) S VAINVENC=1
;
S VAFENC=+$G(VAFENC),VAFDENC=+$G(VAFDENC)
S $P(VAFY,VAFHLFS,50)="",VAFSTR=","_VAFSTR_","
;
; - Set flag to indicate whether Outpatient Encounter ("E") or Deleted
; Outpatient Encounter ("D").
S VAFFLG=$S(VAFENC:"E",1:"D")
;
I VAFFLG="E" S VAFNODE=$$SCE^DGSDU(VAFENC)
;
; - VAFNODE1 = old encounter zero node for deleted encounter
I VAFFLG="D" D
. S VAFNODE=$G(^SD(409.74,VAFDENC,0))
. S VAFNODE1=$G(^SD(409.74,VAFDENC,1))
;
;- Reset patient class/status if Inpatient
S VAFPSTAT=$$INPATENC^SCDXUTL($S(VAFFLG="E":VAFENC,1:VAFDENC),$S(VAFFLG="E":1,1:2))
I VAFPSTAT S VAFPTCL="I" S $P(VAFY,VAFHLFS,2)=VAFPTCL
;
;- Purpose of Visit
I VAFSTR[",4," D
. S VAFDAT=$P(VAFNODE,"^"),VAFDFN=$P(VAFNODE,"^",2)
. S VAFCLIN=$S(VAFFLG="E":$P(VAFNODE,"^",4),1:$P(VAFNODE1,"^",4))
. S VAFAPTYP=$S(VAFFLG="E":$P(VAFNODE,"^",10),1:$P(VAFNODE1,"^",10))
. S X=$$POV^SCDXUTL0(VAFDFN,VAFDAT,VAFCLIN,VAFAPTYP)
. I X="" D
.. S VAFORIG=$S(VAFFLG="E":$P(VAFNODE,"^",8),1:$P(VAFNODE1,"^",8))
.. S X=$S(VAFORIG=2:"04"_$S($L(VAFAPTYP)=1:"0"_VAFAPTYP,1:VAFAPTYP),VAFORIG=3:"02"_$S($L(VAFAPTYP)=1:"0"_VAFAPTYP,1:VAFAPTYP),1:"")
. S $P(VAFY,VAFHLFS,4)=$S(X]"":X,1:VAFHLQ)
;
;- Location of Visit
I VAFSTR[",14," D
. S VAFCLIN=$S(VAFFLG="E":$P(VAFNODE,"^",4),1:$P(VAFNODE1,"^",4))
. S X=$P($G(^SC(+VAFCLIN,0)),"^",19),X=$S(X="Y":1,X="N":6,1:"")
. I X="" S VAFORIG=$S(VAFFLG="E":$P(VAFNODE,"^",8),1:$P(VAFNODE1,"^",8)),X=$S(VAFORIG=2!(VAFORIG=3):1,1:"")
. S $P(VAFY,VAFHLFS,14)=$S(X]"":X,1:VAFHLQ)
;
;- Outpatient Encounter IEN (not passed for deleted outpat encounter)
I VAFSTR[",19," S $P(VAFY,VAFHLFS,19)=$S(VAFFLG="E":VAFENC,1:VAFHLQ)
;
;- Facility Number and Suffix
I VAFSTR[",39," D
. ; add division parameter to $$SITE^VASITE call ; abr
. S X=$S(VAFFLG="E":$$SITE^VASITE($P(VAFNODE,"^"),$P(VAFNODE,"^",11)),1:$$SITE^VASITE($P(VAFNODE1,"^"),$P(VAFNODE1,"^",11)))
. S X=$P(X,"^",3)
. S $P(VAFY,VAFHLFS,39)=$S(X]"":X,1:VAFHLQ)
;
;- Encounter Date/Time for Outpatients & Admission Date for Inpatients
I VAFSTR[",44," D
. N DFN,VAIN
. S VAFPIN=0
. I VAFPSTAT S VAFPIN=$S(VAFFLG="E":$P(VAFNODE,"^",2),1:$P(VAFNODE1,"^",2)) I VAFPIN S DFN=VAFPIN D INP^VADPT S X=$P(VAIN(7),"^") I 'X S VAFPIN=0
. I 'VAFPIN S X=$S(VAFFLG="E":$P(VAFNODE,"^"),1:$P(VAFNODE1,"^"))
. S X=$$HLDATE^HLFNC(X)
. S $P(VAFY,VAFHLFS,44)=$S(X]"":X,1:VAFHLQ)
;
;- Unique Identifier (PCE)
I VAFSTR[",50," D
. S X=$S(VAFFLG="E":$P(VAFNODE,"^",20),1:$P(VAFNODE1,"^",20))
. S $P(VAFY,VAFHLFS,50)=$S(X]"":X,1:VAFHLQ)
;
ENQ Q "PV1"_VAFHLFS_$G(VAFY)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVAFHLPV1 5774 printed Dec 13, 2024@03:03:10 Page 2
VAFHLPV1 ;ALB/CM/ESD HL7 PV1 SEGMENT BUILDING ;06/08/00
+1 ;;5.3;Registration;**94,106,151,298,617**;Aug 13, 1993
+2 ;
+3 ;This routine will build an HL7 PV1 segment for an inpatient or
+4 ;outpatient event depending on the entry point used.
+5 ;Use IN for inpatient
+6 ;Use OUT for outpatient
+7 ;
IN(DFN,VAFHDT,VAFSTR,IEN,PIVOT,SETID,VAFDIAG) ;
+1 NEW RESULT
+2 SET RESULT=$$EN^VAFHAPV1(DFN,VAFHDT,VAFSTR,IEN,PIVOT,SETID,.VAFDIAG)
+3 QUIT $GET(RESULT)
+4 ;
OUT(DFN,EVT,EVDTS,VPTR,STRP,NUMP) ;
+1 ;DFN - Patient File
+2 ;EVT - event number from pivot file
+3 ;EVDTS - event date/time in FileMan format
+4 ;VPTR - variable pointer
+5 ;STRP - string of fields (if null - required fields, if "A" - supported
+6 ;fields, or string of fields seperated by commas")
+7 ;NUMP - ID # (optional)
+8 ;
+9 NEW ERR
+10 IF '$DATA(NUMP)
SET NUMP=1
+11 SET ERR=$$OPV1^VAFHCPV($GET(DFN),$GET(EVT),$GET(EVDTS),$GET(VPTR),$GET(STRP),NUMP)
+12 QUIT ERR
KVAR ;
+1 KILL VAFHLPV1
+2 QUIT
+3 ;
EN(VAFENC,VAFDENC,VAFSTR,VAFNUM,VAFHLQ,VAFHLFS) ;
+1 ; Entry point for Ambulatory Care Database Project
+2 ;
+3 ; Entry point to return the HL7 PV1 (Patient Visit) segment
+4 ;
+5 ; Input: VAFENC - Outpatient Encounter IEN (pointer to Outpatient
+6 ; Encounter file #409.68)
+7 ;
+8 ; VAFDENC - Deleted Outpatient Encounter IEN (pointer to
+9 ; Deleted Outpatient Encounter file #409.74)
+10 ;
+11 ; VAFSTR - String of fields requested separated by commas
+12 ;
+13 ; VAFNUM - Set ID (sequential number - default=1)
+14 ;
+15 ; VAFHLQ - Optional HL7 null variable. If not there, use
+16 ; default HL7 variable.
+17 ;
+18 ; VAFHLFS - Optional HL7 field separator. If not there, use
+19 ; default HL7 variable.
+20 ;
+21 ; Output: String containing desired components of the PV1 segment
+22 ;
+23 ; NOTE: Data for the PV1 segment will be retrieved from either the
+24 ; Outpatient Encounter file (#409.68) or Deleted Outpatient
+25 ; Encounter (#409.74) based on the pointer parameter passed in.
+26 ;
+27 ;06/08/2000 ACS - AMBCARE PV1 CHANGES:
+28 ; 1. SET UP HL7 DEFAULT VARIABLES AT BEGINNING OF SUBROUTINE.
+29 ; 2. VALIDATE EXISTENCE OF AMBCARE ENCOUNTER.
+30 ; 3. ALWAYS RETURN PATIENT CLASS IN SEGMENT.
+31 ;
+32 ;
+33 NEW VAFAPTYP,VAFCLIN,VAFDAT,VAFDFN,VAFFLG,VAFNODE,VAFNODE1,VAFORIG,VAFPTCL,VAFY,X,VAINVENC,VAFPSTAT,VAFPIN
+34 ;
+35 ; - If VAFHLQ or VAFHLFS aren't passed in, use default HL7 variables.
+36 SET VAFHLQ=$SELECT($DATA(VAFHLQ):VAFHLQ,1:$GET(HLQ))
SET VAFHLFS=$SELECT($DATA(VAFHLFS):VAFHLFS,1:$GET(HLFS))
+37 ;
+38 ;- Sequential Number
+39 SET $PIECE(VAFY,VAFHLFS,1)=$SELECT($GET(VAFNUM):VAFNUM,1:1)
+40 ;
+41 ; Patient Class = Outpatient
SET VAFPTCL="O"
+42 ;
+43 ;- Set patient class in segment
+44 SET $PIECE(VAFY,VAFHLFS,2)=VAFPTCL
+45 ;
+46 ;- If encounter or variable string missing, pass back incomplete segment
+47 IF ($GET(VAFENC)=""&($GET(VAFDENC)=""))!($GET(VAFSTR)="")
GOTO ENQ
+48 ;
+49 ; - If regular encounter doesn't exist, pass back incomplete segment
+50 IF $GET(VAFENC)
Begin DoDot:1
+51 IF '$DATA(^SCE($GET(VAFENC)))
SET VAINVENC=1
End DoDot:1
if $GET(VAINVENC)
GOTO ENQ
+52 ;
+53 ; - If deleted encounter doesn't exist, pass back incomplete segment
+54 IF $GET(VAFDENC)
Begin DoDot:1
+55 IF '$DATA(^SD(409.74,$GET(VAFDENC)))
SET VAINVENC=1
End DoDot:1
if $GET(VAINVENC)
GOTO ENQ
+56 ;
+57 SET VAFENC=+$GET(VAFENC)
SET VAFDENC=+$GET(VAFDENC)
+58 SET $PIECE(VAFY,VAFHLFS,50)=""
SET VAFSTR=","_VAFSTR_","
+59 ;
+60 ; - Set flag to indicate whether Outpatient Encounter ("E") or Deleted
+61 ; Outpatient Encounter ("D").
+62 SET VAFFLG=$SELECT(VAFENC:"E",1:"D")
+63 ;
+64 IF VAFFLG="E"
SET VAFNODE=$$SCE^DGSDU(VAFENC)
+65 ;
+66 ; - VAFNODE1 = old encounter zero node for deleted encounter
+67 IF VAFFLG="D"
Begin DoDot:1
+68 SET VAFNODE=$GET(^SD(409.74,VAFDENC,0))
+69 SET VAFNODE1=$GET(^SD(409.74,VAFDENC,1))
End DoDot:1
+70 ;
+71 ;- Reset patient class/status if Inpatient
+72 SET VAFPSTAT=$$INPATENC^SCDXUTL($SELECT(VAFFLG="E":VAFENC,1:VAFDENC),$SELECT(VAFFLG="E":1,1:2))
+73 IF VAFPSTAT
SET VAFPTCL="I"
SET $PIECE(VAFY,VAFHLFS,2)=VAFPTCL
+74 ;
+75 ;- Purpose of Visit
+76 IF VAFSTR[",4,"
Begin DoDot:1
+77 SET VAFDAT=$PIECE(VAFNODE,"^")
SET VAFDFN=$PIECE(VAFNODE,"^",2)
+78 SET VAFCLIN=$SELECT(VAFFLG="E":$PIECE(VAFNODE,"^",4),1:$PIECE(VAFNODE1,"^",4))
+79 SET VAFAPTYP=$SELECT(VAFFLG="E":$PIECE(VAFNODE,"^",10),1:$PIECE(VAFNODE1,"^",10))
+80 SET X=$$POV^SCDXUTL0(VAFDFN,VAFDAT,VAFCLIN,VAFAPTYP)
+81 IF X=""
Begin DoDot:2
+82 SET VAFORIG=$SELECT(VAFFLG="E":$PIECE(VAFNODE,"^",8),1:$PIECE(VAFNODE1,"^",8))
+83 SET X=$SELECT(VAFORIG=2:"04"_$SELECT($LENGTH(VAFAPTYP)=1:"0"_VAFAPTYP,1:VAFAPTYP),VAFORIG=3:"02"_$SELECT($LENGTH(VAFAPTYP)=1:"0"_VAFAPTYP,1:VAFAPTYP),1:"")
End DoDot:2
+84 SET $PIECE(VAFY,VAFHLFS,4)=$SELECT(X]"":X,1:VAFHLQ)
End DoDot:1
+85 ;
+86 ;- Location of Visit
+87 IF VAFSTR[",14,"
Begin DoDot:1
+88 SET VAFCLIN=$SELECT(VAFFLG="E":$PIECE(VAFNODE,"^",4),1:$PIECE(VAFNODE1,"^",4))
+89 SET X=$PIECE($GET(^SC(+VAFCLIN,0)),"^",19)
SET X=$SELECT(X="Y":1,X="N":6,1:"")
+90 IF X=""
SET VAFORIG=$SELECT(VAFFLG="E":$PIECE(VAFNODE,"^",8),1:$PIECE(VAFNODE1,"^",8))
SET X=$SELECT(VAFORIG=2!(VAFORIG=3):1,1:"")
+91 SET $PIECE(VAFY,VAFHLFS,14)=$SELECT(X]"":X,1:VAFHLQ)
End DoDot:1
+92 ;
+93 ;- Outpatient Encounter IEN (not passed for deleted outpat encounter)
+94 IF VAFSTR[",19,"
SET $PIECE(VAFY,VAFHLFS,19)=$SELECT(VAFFLG="E":VAFENC,1:VAFHLQ)
+95 ;
+96 ;- Facility Number and Suffix
+97 IF VAFSTR[",39,"
Begin DoDot:1
+98 ; add division parameter to $$SITE^VASITE call ; abr
+99 SET X=$SELECT(VAFFLG="E":$$SITE^VASITE($PIECE(VAFNODE,"^"),$PIECE(VAFNODE,"^",11)),1:$$SITE^VASITE($PIECE(VAFNODE1,"^"),$PIECE(VAFNODE1,"^",11)))
+100 SET X=$PIECE(X,"^",3)
+101 SET $PIECE(VAFY,VAFHLFS,39)=$SELECT(X]"":X,1:VAFHLQ)
End DoDot:1
+102 ;
+103 ;- Encounter Date/Time for Outpatients & Admission Date for Inpatients
+104 IF VAFSTR[",44,"
Begin DoDot:1
+105 NEW DFN,VAIN
+106 SET VAFPIN=0
+107 IF VAFPSTAT
SET VAFPIN=$SELECT(VAFFLG="E":$PIECE(VAFNODE,"^",2),1:$PIECE(VAFNODE1,"^",2))
IF VAFPIN
SET DFN=VAFPIN
DO INP^VADPT
SET X=$PIECE(VAIN(7),"^")
IF 'X
SET VAFPIN=0
+108 IF 'VAFPIN
SET X=$SELECT(VAFFLG="E":$PIECE(VAFNODE,"^"),1:$PIECE(VAFNODE1,"^"))
+109 SET X=$$HLDATE^HLFNC(X)
+110 SET $PIECE(VAFY,VAFHLFS,44)=$SELECT(X]"":X,1:VAFHLQ)
End DoDot:1
+111 ;
+112 ;- Unique Identifier (PCE)
+113 IF VAFSTR[",50,"
Begin DoDot:1
+114 SET X=$SELECT(VAFFLG="E":$PIECE(VAFNODE,"^",20),1:$PIECE(VAFNODE1,"^",20))
+115 SET $PIECE(VAFY,VAFHLFS,50)=$SELECT(X]"":X,1:VAFHLQ)
End DoDot:1
+116 ;
ENQ QUIT "PV1"_VAFHLFS_$GET(VAFY)