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

VAFCQRY3.m

Go to the documentation of this file.
VAFCQRY3 ;ALB/CMC,CKN,KUM - CONT TO BLD PID 2.4 SEGMENT ;7/4/18 4:45PM
 ;;5.3;Registration;**575,707,754,944,941,1121**;Aug 13, 1993;Build 14
 ;Per VHA Directive 2004-038, this routine should not be modified.
 ;
 ; *941* #858271 - Sending Residential Address Fields 
 ;
CONT(DFN,APID,PID,HL,HLES,SARY,SEQ,ERROR,REP,COMP,SSN,VAFCMN) ; continue to bld pid segment
ADDR ;had to split routine
 N LVL1,LNGTH1
 S LVL1=0
 S LNGTH1=0
 I $D(SARY(11))!(SEQ="ALL") S APID(12)="" D
 .I $D(^DPT(DFN,0)) D
 ..;address info
 ..N COUNTY K HL7STRG
 ..S HL7STRG=$$GET1^DIQ(2,DFN_",",.111) D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES)
 ..S $P(APID(12),COMP)=HL7STRG I $P(APID(12),COMP)="" S $P(APID(12),COMP)=HL("Q") K HL7STRG
 ..K HL7STRG S HL7STRG=$$GET1^DIQ(2,DFN_",",.112) D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) ;**707 add HL7TXT call
 ..S $P(APID(12),COMP,2)=HL7STRG I $P(APID(12),COMP,2)="" S $P(APID(12),COMP,2)=HL("Q")
 ..K HL7STRG S HL7STRG=$$GET1^DIQ(2,DFN_",",.113) D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) ;**707 add HL7TXT call
 ..S $P(APID(12),COMP,8)=HL7STRG I $P(APID(12),COMP,8)="" S $P(APID(12),COMP,8)=HL("Q")
 ..K HL7STRG
 ..; **707 changes to include foreign address
 ..N CNTRY S CNTRY=$$GET1^DIQ(2,DFN_",",.1173) ;RETURN EXTERNAL VALUE from country code file #779.004 field .01
 ..I CNTRY="US" S CNTRY="USA"
 ..S HL7STRG=$$GET1^DIQ(2,DFN_",",.114) D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S $P(APID(12),COMP,3)=HL7STRG  I $P(APID(12),COMP,3)="" S $P(APID(12),COMP,3)=HL("Q")
 ..I CNTRY=""!(CNTRY="USA") D
 ...;have USA address
 ...S STATEIEN=$$GET1^DIQ(2,DFN_",",.115,"I") S $P(APID(12),COMP,4)=$$GET1^DIQ(5,+STATEIEN_",",1)
 ...I $P(APID(12),COMP,4)="" S $P(APID(12),COMP,4)=HL("Q")
 ...S $P(APID(12),COMP,5)=$$GET1^DIQ(2,DFN_",",.1112) I $P(APID(12),COMP,5)="" S $P(APID(12),COMP,5)=HL("Q")
 ...S $P(APID(12),COMP,6)=CNTRY I CNTRY="" S $P(APID(12),COMP,6)=HL("Q") ;country
 ..I CNTRY'="",(CNTRY'="USA") D
 ...;Check for foreign address fields
 ...S $P(APID(12),COMP,4)=$P($G(^DPT(DFN,.11)),"^",8) I $P(APID(12),COMP,4)="" S $P(APID(12),COMP,4)=HL("Q") ;province
 ...S $P(APID(12),COMP,5)=$P($G(^DPT(DFN,.11)),"^",9) I $P(APID(12),COMP,5)="" S $P(APID(12),COMP,5)=HL("Q") ;postal code
 ...S $P(APID(12),COMP,6)=CNTRY I CNTRY="" S $P(APID(12),COMP,6)=HL("Q") ;COUNTRY
 ...; ***707 end of code
 ..S $P(APID(12),COMP,7)="P"
BADADDR ..;BAD ADDRESS INDICATOR (if present overwrite the "P" ermanent type with the Bad Address type
 ..I $D(^DPT(DFN,.11)) N BADADR S BADADR=$P(^DPT(DFN,.11),"^",16) I BADADR'="" S $P(APID(12),COMP,7)="VAB"_BADADR
 ..S COUNTY=$$GET1^DIQ(2,DFN_",",.117) I COUNTY="" S COUNTY=HL("Q") ;**648 add COUNTY Code to PID-11, retained in PID-12 also
 ..S $P(APID(12),COMP,9)=COUNTY ;county code
 ..;place of birth information
 ..S CITY=$$GET1^DIQ(2,DFN_",",.092) S HL7STRG=CITY D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S CITY=HL7STRG D
 ...N X,POBPROV,POBCONT
 ...I $G(CITY)'="" S $P(X,COMP,3)=CITY
 ...I $G(CITY)="" S $P(X,COMP,3)=HL("Q")
 ...; Story 513045 (elz) use pob provence if it's there vs state
 ...S STATEIEN=$$GET1^DIQ(2,DFN_",",.093,"I"),STATE=$$GET1^DIQ(5,+STATEIEN_",",1),POBPROV=$$GET1^DIQ(2,DFN_",",.0932,"E") D
 ....I $L(POBPROV) S HL7STRG=POBPROV D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S $P(X,COMP,4)=HL7STRG
 ....I $G(STATE)'="",'$L(POBPROV) S $P(X,COMP,4)=STATE
 ....I $G(STATE)="",'$L(POBPROV) S $P(X,COMP,4)=HL("Q")
 ...; Story 513045 (elz) include pob country
 ...S POBCONT=$$GET1^DIQ(2,DFN_",",.0931) D
 ....I POBCONT="US" S POBCONT="USA"
 ....I POBCONT'="" S $P(X,COMP,6)=POBCONT
 ....I POBCONT="" S $P(X,COMP,6)=HL("Q")
 ... S $P(X,COMP,7)="N",APID(12)=$G(APID(12))_REP_X
CONF .;CONFIDENTIAL ADDRESS
 .I $D(^DPT(DFN,.141)) N CNFADD S CNFADD=$$GET1^DIQ(2,DFN_",",.14105) D
 ..N LINE1,LINE2,LINE3,STATEIEN,STATE,CNTRY,ZIP,LVL,LNGTH,NXT,CNFEND,CNFSTRT,SUBCOMP,CNTY,CITY
 ..S SUBCOMP=$E(HL("ECH"),4)
 ..S LINE1=$$GET1^DIQ(2,DFN_",",.1411) S HL7STRG=LINE1 D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S LINE1=HL7STRG
 ..S LINE2=$$GET1^DIQ(2,DFN_",",.1412) S HL7STRG=LINE2 D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S LINE2=HL7STRG
 ..S LINE3=$$GET1^DIQ(2,DFN_",",.1413) S HL7STRG=LINE3 D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S LINE3=HL7STRG
 ..S CNFSTRT=$$FMTHL7^XLFDT($$GET1^DIQ(2,DFN_",",.1417,"I")),CNFEND=$$FMTHL7^XLFDT($$GET1^DIQ(2,DFN_",",.1418,"I"))
 ..S CITY=$$GET1^DIQ(2,DFN_",",.1414) S HL7STRG=CITY D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S CITY=HL7STRG
 ..S CNTRY=$$GET1^DIQ(2,DFN_",",.14116)
 ..;if foriegn address
 ..I CNTRY=""!(CNTRY="USA")!(CNTRY="US") S:CNTRY="US" CNTRY="USA" S STATEIEN=$$GET1^DIQ(2,DFN_",",.1415,"I") S STATE=$$GET1^DIQ(5,+STATEIEN_",",1),CNTY=$$GET1^DIQ(2,DFN_",",.14111),ZIP=$$GET1^DIQ(2,DFN_",",.1416)
 ..E  S STATE=$$GET1^DIQ(2,DFN_",",.14114),ZIP=$$GET1^DIQ(2,DFN_",",.14115)  ;if USA address or null assume USA address
 ..S LVL=0,LNGTH=$L(APID(12))
 ..I $D(^DPT(DFN,.14,0)) N CNFTYP S CNFTYP=0 F  S CNFTYP=$O(^DPT(DFN,.14,CNFTYP)) Q:'CNFTYP  N CNFTYPA S CNFTYPA=$P(^DPT(DFN,.14,CNFTYP,0),"^",2) I CNFTYPA="Y" S CNFTYPA=$P(^DPT(DFN,.14,CNFTYP,0),"^") D
 ...S NXT=""
 ...S $P(NXT,COMP)=$S(LINE1'="":LINE1,1:HL("Q"))
 ...S $P(NXT,COMP,2)=$S(LINE2'="":LINE2,1:HL("Q"))
 ...S $P(NXT,COMP,8)=$S(LINE3'="":LINE3,1:HL("Q"))
 ...S $P(NXT,COMP,3)=$S(CITY'="":CITY,1:HL("Q"))
 ...S $P(NXT,COMP,4)=$S($G(STATE)'="":STATE,1:HL("Q"))
 ...S $P(NXT,COMP,5)=$S(ZIP'="":ZIP,1:HL("Q"))
 ...S $P(NXT,COMP,6)=$S(CNTRY'="":CNTRY,1:HL("Q"))
 ...S $P(NXT,COMP,7)=$S(CNFTYPA=1:"VACAE",CNFTYPA=2:"VACAA",CNFTYPA=3:"VACAC",CNFTYPA=4:"VACAM",CNFTYPA=5:"VACAO",1:HL("Q"))
 ...S $P(NXT,COMP,9)=$S($G(CNTY)'="":CNTY,1:HL("Q"))
 ...S $P(NXT,COMP,12)=CNFSTRT_SUBCOMP_CNFEND
 ...S NXT=REP_NXT
 ...I LVL=0 D
 ....I $L(APID(12)_NXT)'>244 S APID(12)=APID(12)_NXT Q
 ....I $L(APID(12)_NXT)>244 S LVL=1 S LNGTH=244-$L(APID(12)),APID(12)=APID(12)_$E(NXT,1,LNGTH) S LNGTH=LNGTH+1,NXT=$E(NXT,LNGTH,$L(NXT))
 ...I LVL>0 D
 ....I $L($G(APID(12,LVL))_NXT)'>245 S APID(12,LVL)=$G(APID(12,LVL))_NXT Q
 ....I $L($G(APID(12,LVL))_NXT)>245 S LNGTH=244-$L(APID(12,LVL)),APID(12,LVL)=APID(12,LVL)_$E(NXT,1,LNGTH) S LNGTH=LNGTH+1,NXT=$E(NXT,LNGTH,$L(NXT)) S LVL=LVL+1 S APID(12,LVL)=NXT
 ..S LVL1=LVL
 ..S LNGTH1=LNGTH
RESI .;KUM - 941 - TRANSMIT RESIDENTIAL ADDRESS
 .;jam; patch 941 - get current option and include RES Address in PID if not ambulatory care transmit
 .N XQOPT
 .D OP^XQCHK
 .I $D(^DPT(DFN,.115)),$P(XQOPT,"^",1)'["SCDX AMBCAR" D 
 ..N RESADD,LVL,LNGTH,RESDTA
 ..S RESDTA=0
 ..N LINE1,LINE2,LINE3,STATEIEN,STATE,CNTRY,ZIP,LVL,LNGTH,NXT,NXT1,RESEND,RESSTRT,SUBCOMP,CNTY,CITY
 ..S SUBCOMP=$E(HL("ECH"),4)
 ..S LINE1=$$GET1^DIQ(2,DFN_",",.1151) S HL7STRG=LINE1 D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S LINE1=HL7STRG
 ..S LINE2=$$GET1^DIQ(2,DFN_",",.1152) S HL7STRG=LINE2 D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S LINE2=HL7STRG
 ..S LINE3=$$GET1^DIQ(2,DFN_",",.1153) S HL7STRG=LINE3 D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S LINE3=HL7STRG
 ..;S RESSTRT=$$FMTHL7^XLFDT($$GET1^DIQ(2,DFN_",",.1161,"I")),RESEND=$$FMTHL7^XLFDT($$GET1^DIQ(2,DFN_",",.1162,"I"))
 ..S CITY=$$GET1^DIQ(2,DFN_",",.1154) S HL7STRG=CITY D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S CITY=HL7STRG
 ..S CNTRY=$$GET1^DIQ(2,DFN_",",.11573)
 ..;if foriegn address
 ..I CNTRY=""!(CNTRY="USA")!(CNTRY="US") S:CNTRY="US" CNTRY="USA" S STATEIEN=$$GET1^DIQ(2,DFN_",",.1155,"I") S STATE=$$GET1^DIQ(5,+STATEIEN_",",1),CNTY=$$GET1^DIQ(2,DFN_",",.1157),ZIP=$$GET1^DIQ(2,DFN_",",.1156)
 ..E  S STATE=$$GET1^DIQ(2,DFN_",",.11571),ZIP=$$GET1^DIQ(2,DFN_",",.11572)  ;if USA address or null assume USA address
 ..I '$G(LNGTH1) S LNGTH1=0
 ..S LNGTH=LNGTH1
 ..S LVL=LVL1
 ..S NXT=""
 ..I ($G(LINE1)'="")!($G(LINE2)'="")!($G(LINE3)'="")!($G(CITY)'="")!($G(STATE)'="")!($G(ZIP)'="")!($G(CNTRY)'="")!($G(CNTY)'="") S RESDTA=1
 ..S $P(NXT,COMP)=$S(LINE1'="":LINE1,1:HL("Q"))
 ..S $P(NXT,COMP,2)=$S(LINE2'="":LINE2,1:HL("Q"))
 ..S $P(NXT,COMP,8)=$S(LINE3'="":LINE3,1:HL("Q"))
 ..S $P(NXT,COMP,3)=$S(CITY'="":CITY,1:HL("Q"))
 ..S $P(NXT,COMP,4)=$S($G(STATE)'="":STATE,1:HL("Q"))
 ..S $P(NXT,COMP,5)=$S(ZIP'="":ZIP,1:HL("Q"))
 ..S $P(NXT,COMP,6)=$S(CNTRY'="":CNTRY,1:HL("Q"))
 ..S $P(NXT,COMP,7)="R"
 ..S $P(NXT,COMP,9)=$S($G(CNTY)'="":CNTY,1:HL("Q"))
 ..;S $P(NXT,COMP,10)=HL("Q")
 ..;S $P(NXT,COMP,12)=RESSTRT_SUBCOMP_RESEND
 ..S NXT=REP_NXT
 ..I RESDTA D
 ...I LVL=0 D
 ....I $L(APID(12)_NXT)'>244 S APID(12)=APID(12)_NXT Q
 ....I $L(APID(12)_NXT)>244 S LVL=1 S LNGTH=244-$L(APID(12)),APID(12)=APID(12)_$E(NXT,1,LNGTH) S LNGTH=LNGTH+1,NXT=$E(NXT,LNGTH,$L(NXT))
 ...I LVL>0 D
 ....I $L($G(APID(12,LVL))_NXT)'>245 S APID(12,LVL)=$G(APID(12,LVL))_NXT Q
 ....I $L($G(APID(12,LVL))_NXT)>245 S LNGTH=244-$L(APID(12,LVL)),APID(12,LVL)=APID(12,LVL)_$E(NXT,1,LNGTH) S LNGTH=LNGTH+1,NXT=$E(NXT,LNGTH,$L(NXT)) S LVL=LVL+1 S APID(12,LVL)=NXT
 I $D(SARY(12))!(SEQ="ALL") S APID(13)=$$GET1^DIQ(2,DFN_",",.117) I APID(13)="" S APID(13)=HL("Q")  ;county code **648 backwards compatibility only
PHONE I $D(SARY(13))!($D(SARY(14)))!(SEQ="ALL") D
 .;**707 change PID-13 to have home and work phones, cell, pager and e-mail address with the components ; **754 add confidential phone number to PID-13
 .N PHONEN,HNUM,WNUM,EMAIL,CELL,PAGER,CONFNUM,DGEXT,DGEXT2,DGCNTRY,DGAREA,DGPH ;**754
 .S PHONEN=$G(^DPT(DFN,.13))
 .; **707 change to ensure that null doesn't end up for any of these fields cmc 12/7/06
 .; **DG*5.3*1121 accommodate country code, area code, phone number, extension in pieces 5 to 8 in each phone number component
 .;S HNUM=$P(PHONEN,"^") I HNUM'="" S HNUM=$$HLPHONE^HLFNC(HNUM) I HNUM'="" S HL7STRG=HNUM D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S HNUM=HL7STRG_COMP_"PRN"_COMP_"PH"
 .S HNUM=$P(PHONEN,"^") I HNUM'="" D 
 ..;S HL7STRG=HNUM
 ..S HL7STRG=$TR(HNUM,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
 ..D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S DGEXT="" S DGEXT2="" S DGCNTRY="" S DGAREA="" S DGPH=""
 ..S DGEXT=$P(HL7STRG,"X",2)
 ..S DGEXT=$$CONVPHAN(DGEXT)
 ..S DGEXT2=$$GET1^DIQ(2,DFN_",",.13211)
 ..S DGEXT2=$$CONVPHAN(DGEXT2)
 ..I DGEXT2'="" S DGEXT=DGEXT2
 ..S DGEXT=$E(DGEXT,1,6)
 ..S DGCNTRY=$$GET1^DIQ(2,DFN_",",.1327,"I")
 ..S DGCNTRY=$$CONVPHAN(DGCNTRY)
 ..I $G(DGCNTRY)="" S DGCNTRY=1
 ..S DGPH=$P(HL7STRG,"X",1)
 ..S DGPH=$$CONVPHAN(DGPH)
 ..S DGAREA=$E(DGPH,1,3)
 ..S DGPH=$E(DGPH,4,10)
 ..I DGPH="" S DGEXT="" S DGCNTRY="" S DGAREA=""
 ..S HNUM=HL7STRG_COMP_"PRN"_COMP_"PH"_COMP_COMP_DGCNTRY_COMP_DGAREA_COMP_DGPH_COMP_DGEXT
 .;S WNUM=$P(PHONEN,"^",2) I WNUM'="" S WNUM=$$HLPHONE^HLFNC(WNUM) I WNUM'="" S HL7STRG=WNUM D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S WNUM=HL7STRG_COMP_"WPN"_COMP_"PH"
 .S WNUM=$P(PHONEN,"^",2) I WNUM'="" D
 ..;S HL7STRG=WNUM
 ..S HL7STRG=$TR(WNUM,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
 ..D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S DGEXT="" S DGEXT2="" S DGCNTRY="" S DGAREA="" S DGPH=""
 ..S DGEXT=$P(HL7STRG,"X",2)
 ..S DGEXT=$$CONVPHAN(DGEXT)
 ..S DGEXT2=$$GET1^DIQ(2,DFN_",",.13213)
 ..S DGEXT2=$$CONVPHAN(DGEXT2)
 ..I DGEXT2'="" S DGEXT=DGEXT2
 ..S DGEXT=$E(DGEXT,1,6)
 ..S DGCNTRY=$$GET1^DIQ(2,DFN_",",.1329,"I")
 ..S DGCNTRY=$$CONVPHAN(DGCNTRY)
 ..I $G(DGCNTRY)="" S DGCNTRY=1
 ..S DGPH=$P(HL7STRG,"X",1)
 ..S DGPH=$$CONVPHAN(DGPH)
 ..S DGAREA=$E(DGPH,1,3)
 ..S DGPH=$E(DGPH,4,10)
 ..I DGPH="" S DGEXT="" S DGCNTRY="" S DGAREA=""
 ..S WNUM=HL7STRG_COMP_"WPN"_COMP_"PH"_COMP_COMP_DGCNTRY_COMP_DGAREA_COMP_DGPH_COMP_DGEXT
 .;S CELL=$P(PHONEN,"^",4) I CELL'="" S CELL=$$HLPHONE^HLFNC(CELL) I CELL'="" S HL7STRG=CELL D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S CELL=HL7STRG_COMP_"ORN"_COMP_"CP"
 .S CELL=$P(PHONEN,"^",4) I CELL'="" D
 ..;S HL7STRG=CELL
 ..S HL7STRG=$TR(CELL,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
 ..D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S DGEXT="" S DGEXT2="" S DGCNTRY="" S DGAREA="" S DGPH=""
 ..S DGEXT=$P(HL7STRG,"X",2)
 ..S DGEXT=$$CONVPHAN(DGEXT)
 ..S DGEXT2=$$GET1^DIQ(2,DFN_",",.13212)
 ..S DGEXT2=$$CONVPHAN(DGEXT2)
 ..I DGEXT2'="" S DGEXT=DGEXT2
 ..S DGEXT=$E(DGEXT,1,6)
 ..S DGCNTRY=$$GET1^DIQ(2,DFN_",",.1328,"I")
 ..S DGCNTRY=$$CONVPHAN(DGCNTRY)
 ..I $G(DGCNTRY)="" S DGCNTRY=1
 ..S DGPH=$P(HL7STRG,"X",1)
 ..S DGPH=$$CONVPHAN(DGPH)
 ..S DGAREA=$E(DGPH,1,3)
 ..S DGPH=$E(DGPH,4,10)
 ..I DGPH="" S DGEXT="" S DGCNTRY="" S DGAREA=""
 ..S CELL=HL7STRG_COMP_"ORN"_COMP_"CP"_COMP_COMP_DGCNTRY_COMP_DGAREA_COMP_DGPH_COMP_DGEXT
 .S PAGER=$P(PHONEN,"^",5) I PAGER'="" S PAGER=$$HLPHONE^HLFNC(PAGER) I PAGER'="" S HL7STRG=PAGER D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S PAGER=HL7STRG_COMP_"BPN"_COMP_"BP"
 .S EMAIL=$P(PHONEN,"^",3) I EMAIL'="" S HL7STRG=EMAIL D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S EMAIL=COMP_"NET"_COMP_"INTERNET"_COMP_HL7STRG
 .;S CONFNUM=$P(PHONEN,"^",15) I CONFNUM'="" S CONFNUM=$$HLPHONE^HLFNC(CONFNUM) I CONFNUM'="" S HL7STRG=CONFNUM D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S CONFNUM=HL7STRG_COMP_"VACPN"_COMP_"PH" ;**574
 .S CONFNUM=$P(PHONEN,"^",15) I CONFNUM'="" D
 ..;S HL7STRG=CONFNUM
 ..S HL7STRG=$TR(CONFNUM,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
 ..D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S DGEXT="" S DGEXT2="" S DGCNTRY="" S DGAREA="" S DGPH=""
 ..S DGEXT=$P(HL7STRG,"X",2)
 ..S DGEXT=$$CONVPHAN(DGEXT)
 ..S DGEXT2=$$GET1^DIQ(2,DFN_",",.13214)
 ..S DGEXT2=$$CONVPHAN(DGEXT2)
 ..I DGEXT2'="" S DGEXT=DGEXT2
 ..S DGEXT=$E(DGEXT,1,6)
 ..S DGCNTRY=$$GET1^DIQ(2,DFN_",",.13201,"I")
 ..S DGCNTRY=$$CONVPHAN(DGCNTRY)
 ..I $G(DGCNTRY)="" S DGCNTRY=1
 ..S DGPH=$P(HL7STRG,"X",1)
 ..S DGPH=$$CONVPHAN(DGPH)
 ..S DGAREA=$E(DGPH,1,3)
 ..S DGPH=$E(DGPH,4,10)
 ..I DGPH="" S DGEXT="" S DGCNTRY="" S DGAREA=""
 ..S CONFNUM=HL7STRG_COMP_"VACPN"_COMP_"PH"_COMP_COMP_DGCNTRY_COMP_DGAREA_COMP_DGPH_COMP_DGEXT
 .; DG*5.3*1121 - End of changes
 .I HNUM'="" S APID(14)=HNUM
 .I WNUM'="",APID(14)'="" S APID(14)=APID(14)_REP_WNUM
 .I WNUM'="",APID(14)="" S APID(14)=WNUM
 .I CELL'="",APID(14)'="" S APID(14)=APID(14)_REP_CELL
 .I CELL'="",APID(14)="" S APID(14)=CELL
 .I PAGER'="",APID(14)'="" S APID(14)=APID(14)_REP_PAGER
 .I PAGER'="",APID(14)="" S APID(14)=PAGER
 .I EMAIL'="",APID(14)'="" S APID(14)=APID(14)_REP_EMAIL
 .I EMAIL'="",APID(14)="" S APID(14)=EMAIL
 .I CONFNUM'="",APID(14)'="" S APID(14)=APID(14)_REP_CONFNUM ;**754
 .I CONFNUM'="",APID(14)="" S APID(14)=CONFNUM ;**754
 .I APID(14)="" S APID(14)=HL("Q")
 I $D(SARY(14))!(SEQ="ALL") N WNUM S WNUM=$P($G(^DPT(DFN,.13)),"^",2) S WNUM=$$HLPHONE^HLFNC(WNUM) S HL7STRG=WNUM D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S APID(15)=HL7STRG I APID(15)="" S APID(15)=HL("Q")
 ;**707 keep work# in PID-14 for backwards compatability but should use PID-13 to get work#
 I $D(SARY(19))!(SEQ="ALL") S APID(20)=SSN  ;ssn passed in PID-3
 I $D(SARY(23))!(SEQ="ALL") D
 .S CITY=$$GET1^DIQ(2,DFN_",",.092) S HL7STRG=CITY D HL7TXT^VAFCQRY1(.HL7STRG,.HL,HLES) S CITY=HL7STRG
 .S STATEIEN=$$GET1^DIQ(2,DFN_",",.093,"I") S STATE=$$GET1^DIQ(5,+STATEIEN_",",1) D
 .I CITY'=""&(STATE'="") S APID(24)=CITY_" "_STATE  ;place of birth (not used) use PID-11 with an 'N' instead
 .I CITY=""&(STATE="") S APID(24)=HL("Q")
 D CONT^VAFCQRY4(DFN,.APID,.PID,.HL,HLES,.SARY,SEQ,.ERROR,REP,COMP)
 ;**707 had to break routine
 Q
 ;
CONVPHAN(PH) ;Convert Alpha Phone number to Numeric
 S PH=$TR(PH," )(/#\-~`!@#$%^&*'|<>?,.+=_abcdefghijklmnopqrstvuwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ","")
 Q PH
 ;