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

BADEHLI.m

Go to the documentation of this file.
BADEHLI ;IHS/MSC/MGH/PLS - Insurance or Dental Interface ;08-May-2009 20:54;PLS
 ;;1.0;DENTAL/EDR INTERFACE;**1**;AUG 22, 2011
 ;; Modified IHS/MSC/AMF 11/23/10 More descriptive alert messages, N for BHS variables
 ;=====================================================================================;
INS ;Entry point - Create the Insurance segment
 N CNT,INSARRAY,DGNAME,IN1,IN2
 ;IHS/MSC/AMF 1/4/2011 Newed BHS variables
 N BHSCOV,BHSDTL,BHSDTN,BHSDTS,BHSEDN,BHSI,BHSIDN,BHSINS,BHSITB,BHSJ,BHSN,BHSNM,BHSP,BHSPDN,BHSUFF,BHSXDT,BHSQ
 S CNT=0
 D MAID,MCARE,THIRD,RR
 I 'CNT D
 .D CRTNULL   ;force creation of empty IN1/IN2 segments
 Q
MAID ;See if the patient is on MEDICAID
 K BHSITB
 S BHSPDN=0 F  S BHSPDN=$O(^AUPNMCD("B",DFN,BHSPDN)) Q:BHSPDN=""  D BMAID
 S BHSI=0 F  S BHSI=$O(BHSITB(BHSI)) Q:BHSI=""  D
 .S BHSJ=$O(BHSITB(BHSI,0))
 .S BHSP=BHSITB(BHSI,BHSJ)
 .S BHSPDN=$P(BHSP,";",1),BHSEDN=$P(BHSP,";",2)
 .D DMAID
MAIDX K BHSCOV,BHSDTL,BHSDTN,BHSDTS,BHSEDN,BHSI,BHSIDN,BHSINS,BHSJ,BHSN,BHSPDN,BHSUFF,Y,BHSXDT,BHSNM,BHSP,BHSQ
 Q
BMAID Q:'$D(^AUPNMCD(BHSPDN))
 S BHSEDN=0 F  S BHSEDN=$O(^AUPNMCD(BHSPDN,11,BHSEDN)) Q:'BHSEDN  D
 .S BHSP=$G(^AUPNMCD(BHSPDN,11,BHSEDN,0))
 .S BHSI=$P(^AUPNMCD(BHSPDN,0),U,4)_"-"_$P(BHSP,U,3)
 .S BHSJ=9999999-$P(BHSP,U,1)
 .S BHSITB(BHSI,BHSJ)=BHSPDN_";"_BHSEDN
 Q
DMAID ;
 N INS,ADDR,PHONE,POLICY
 S BHSNM=$G(^AUPNMCD(BHSPDN,11,BHSEDN,0))
 ;-- add set of exp date variable, quit if not current
 S (BHSXDT,X)=$P(BHSNM,U,2)
 S:BHSXDT="" BHSXDT=9999999
 Q:BHSXDT<$$DT^XLFDT()
 S CNT=CNT+1
 D SET^BADEHL1(.ARY,"IN1",0)
 D SET^BADEHL1(.ARY,CNT,1)
 S BHSN=$G(^AUPNMCD(BHSPDN,0))
 S INSCO=+$P(BHSN,U,2)
 D SET^BADEHL1(.ARY,INSCO,2)    ;Insurer IEN
 D SET^BADEHL1(.ARY,INSCO,3)     ;Insurer IEN
 S BHSINS=$$GET1^DIQ(9999999.18,INSCO,.01)
 S BHSINS=$S($L(BHSINS):BHSINS,1:"???")
 D SET^BADEHL1(.ARY,BHSINS,4)           ;Insurance company name
 ;Get data on the insurer
 S INS=$G(^AUTNINS(INSCO,0))
 D MSCINS
 ;Get the eligibility and expiration dates
 S X=$$HLDATE^HLFNC($P(BHSNM,U,1))
 D SET^BADEHL1(.ARY,X,12)
 S X=$$HLDATE^HLFNC($P(BHSNM,U,2))
 D SET^BADEHL1(.ARY,X,13)
 S X=$$VAL^XBDIQ1(9000004,BHSPDN,.11)
 ;D SET^BADEHL1(.ARY,X,15)         ;Plan type
 ;Name of insured
 S X=$$HLNAME^HLFNC($$GET1^DIQ(9000004,BHSPDN,2101),HLECH) ;was .05
 F LP=1:1:$L(X,$E(HLECH)) S VAL=$P(X,$E(HLECH),LP) D
 .D SET^BADEHL1(.ARY,VAL,16,LP)
 D SET^BADEHL1(.ARY,$$GETREL($P(BHSN,U,6)),17)  ;Relationship to patient
 D SET^BADEHL1(.ARY,$$HLDATE^HLFNC($$GET1^DIQ(9000004,BHSPDN,2102,"I")),18)  ;Medicaid Eligible DOB
 S POLICY=+$P(BHSN,U,9)
 ;Policy Holder's Address
 S POLICY=$G(^AUPN3PPH(POLICY,0))
 I $L(POLICY) D
 .D SET^BADEHL1(.ARY,$P(POLICY,U,9),19,1)  ; Street Address
 .D SET^BADEHL1(.ARY,$P(POLICY,U,11),19,3) ; City
 .S BADEPOLP=$P(POLICY,U,12)  ;SAIC/FJE FIX STATE POINTER 08/22/2011
 .D SET^BADEHL1(.ARY,$$GET1^DIQ(5,$$GET1^DIQ(9000003.1,+BADEPOLP,.12,"I"),1),19,4)  ; State Abbrev
 .D SET^BADEHL1(.ARY,$P(POLICY,U,13),19,5)  ; Zip
 ; IN1-36 is left blank
 D SET^BADEHL1(.ARY,$$GET1^DIQ(9000004,BHSPDN,.07,"I"),43)  ; Gender of Insured
 D SET^BADEHL1(.ARY,$P(BHSNM,U,3),47)  ;Coverage Type
 D SET^BADEHL1(.ARY,$P(BHSN,U,3),49) ; Insured's Medicaid ID number
 S IN1=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^BADEHL1(DFN,"Can't create IN1. "_ERR) ;IHS/MSC/AMF 11/23/10 More descriptive alert
 ;Setup the IN2 segment
 D IN2(INSCO,POLICY,$P(BHSN,U,3))
 Q
MCARE ;ENTRY POINT
 ; See if patient is on MEDICARE
 Q:'$D(^AUPNMCR(DFN))
 S BHSN=$G(^AUPNMCR(DFN,0))
 Q:'$D(^AUPNMCR(DFN,0))
 K BHSITB
 S BHSEDN=0 F  S BHSEDN=$O(^AUPNMCR(DFN,11,BHSEDN)) Q:BHSEDN'=+BHSEDN  D
 .S BHSP=$G(^AUPNMCR(DFN,11,BHSEDN,0))
 .S BHSI=$P(BHSN,U,2)_"-"_$P(BHSP,U,3)
 .S BHSJ=9999999-$P(BHSP,U,1)
 .S BHSITB(BHSI,BHSJ)=DFN_";"_BHSEDN
 S BHSI=0 F BHSQ=0:0 S BHSI=$O(BHSITB(BHSI)) Q:BHSI=""  D
 .S BHSJ=$O(BHSITB(BHSI,0)) S BHSP=BHSITB(BHSI,BHSJ)
 .S BHSPDN=$P(BHSP,";",1),BHSEDN=$P(BHSP,";",2) D DMCARE
 Q
DMCARE ;
 S BHSNM=^AUPNMCR(BHSPDN,11,BHSEDN,0)
 S X=$P(BHSNM,U,1)
 ;--add set of exp date variable, quit if not current
 S (BHSXDT,X)=$P(BHSNM,U,2)
 S:BHSXDT="" BHSXDT=9999999
 Q:BHSXDT<$$DT^XLFDT()
 S CNT=CNT+1
 S BHSUFF=$P(BHSN,U,4) S BHSUFF=$P($G(^AUTTMCS(+BHSUFF,0)),U,1)
 D SET^BADEHL1(.ARY,"IN1",0)
 D SET^BADEHL1(.ARY,CNT,1)
 S BHSN=$G(^AUPNMCR(BHSPDN,0))
 S INSCO=+$P(BHSN,U,2)
 D SET^BADEHL1(.ARY,INSCO,2)     ;Insurer IEN
 D SET^BADEHL1(.ARY,INSCO,3)     ;Insurer IEN
 S BHSINS=$$GET1^DIQ(9999999.18,INSCO,.01)
 S BHSINS=$S($L(BHSINS):BHSINS,1:"???")
 D SET^BADEHL1(.ARY,BHSINS,4)  ;Insurance Company name
 ;Get data on the insurer
 S INS=$G(^AUTNINS(INSCO,0))
 D MSCINS
 ;Get the eligibility and expiration dates
 S X=$$HLDATE^HLFNC($P(BHSNM,U,1))
 D SET^BADEHL1(.ARY,X,12)
 S X=$$HLDATE^HLFNC($P(BHSNM,U,2))
 D SET^BADEHL1(.ARY,X,13)
 ;D SET^BADEHL1(.ARY,$$GET1^DIQ(9000003,DFN,.04),8)  ;Group Number
 ;D SET^BADEHL1(.ARY,$P(BHSNM,U,11),9) ;Group name
 ;D SET^BADEHL1(.ARY,$P(BHSNM,U,3),15) ;Plan type
 S X=$$HLNAME^HLFNC($$GET1^DIQ(9000003,DFN,2101),HLECH)
 F LP=1:1:$L(X,$E(HLECH)) S VAL=$P(X,$E(HLECH),LP) D
 .D SET^BADEHL1(.ARY,VAL,16,LP)
 D SET^BADEHL1(.ARY,"SEL",17)  ;Relationship to patient - File doesn't have .06 field
 D SET^BADEHL1(.ARY,$$HLDATE^HLFNC($$GET1^DIQ(9000003,DFN,2102,"I")),18)  ;Medicare Eligible DOB
 ;No policy so no policy holder address
 D SET^BADEHL1(.ARY,$P(BHSNM,U,8),43)  ; Gender of Insured
 D SET^BADEHL1(.ARY,$P(BHSNM,U,3),47)  ;Coverage Type
 D SET^BADEHL1(.ARY,$P(BHSN,U,3),49)  ; Insured's Medicare ID Number
 S IN1=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^BADEHL1(DFN,"Can't create Medicaid IN1. "_ERR) ;IHS/MSC/AMF 11/23/10 More descriptive alert
 D IN2(INSCO,"")
 K BHSXDT,BHSNM
 Q
THIRD ;EP
 ; OTHER THIRD PARTY
 Q:$O(^AUPNPRVT(DFN,11,0))=""  ; Private Insurance Eligible
 N BHSITB,BHSIDN,BHSP,BHSI,BHSJ
 S BHSIDN=0 F  S BHSIDN=$O(^AUPNPRVT(DFN,11,BHSIDN)) Q:'BHSIDN  D
 .S BHSP=$G(^AUPNPRVT(DFN,11,BHSIDN,0))
 .S BHSITB($P(BHSP,U,1)_"-"_$P(BHSP,U,3),9999999-$P(BHSP,U,6))=BHSIDN
 S BHSI="" F  S BHSI=$O(BHSITB(BHSI)) Q:BHSI=""  D
 .S BHSJ="" F  S BHSJ=$O(BHSITB(BHSI,BHSJ)) Q:BHSJ=""  D
 ..S BHSIDN=BHSITB(BHSI,BHSJ) D DTHIRD
 Q
DTHIRD ;Private insurance data
 N BADEPOLP,INS,ADDR,BHSINS,GRPIEN
 N BHSN,X,BHSXDT,INSCO,POLICY,MEMID
 S (BADEPOLP,INS)=""
 S BHSN=$G(^AUPNPRVT(DFN,11,BHSIDN,0))
 S MEMID=$P($G(^AUPNPRVT(DFN,11,BHSIDN,2)),U)
 S BADEPLCY=$P(BHSN,U,2) ;Policy Number
 S BHSINS=$P($G(^AUTNINS(+$P(BHSN,U,1),0)),U,1)    ;Insurer name
 S BADEPOLP=$P(BHSN,U,8)                      ;policy holder pointer
 ;-- add set of exp date variable, quit if not current
 S (BHSXDT,X)=$P(BHSN,U,7)
 S:BHSXDT="" BHSXDT=9999999
 Q:BHSXDT<$$DT^XLFDT()
 S INSCO=+BHSN
 S CNT=CNT+1
 D SET^BADEHL1(.ARY,"IN1",0)
 D SET^BADEHL1(.ARY,CNT,1)
 D SET^BADEHL1(.ARY,INSCO,2)  ; Insurer IEN
 D SET^BADEHL1(.ARY,INSCO,3)  ; Insurer IEN
 S BHSINS=$$GET1^DIQ(9999999.18,INSCO,.01)
 S BHSINS=$S($L(BHSINS):BHSINS,1:"???")
 D SET^BADEHL1(.ARY,BHSINS,4)               ;Insurance company name
 ;Get data on the insurer
 S INS=$G(^AUTNINS(INSCO,0))
 D MSCINS
 ;
 S POLICY=$G(^AUPN3PPH(+BADEPOLP,0))  ;Policy Node 0
 S GRPIEN=$P(POLICY,U,6)              ; Pointer to Employer Group Insurance
 D SET^BADEHL1(.ARY,$$GET1^DIQ(9999999.77,GRPIEN,.02),8)  ;Group Number
 D SET^BADEHL1(.ARY,$$GET1^DIQ(9999999.77,GRPIEN,.01),9)  ;Group Name
 ;Get the eligibility and expiration dates
 S X=$$HLDATE^HLFNC($P(POLICY,U,17))
 D SET^BADEHL1(.ARY,X,12)
 S X=$$HLDATE^HLFNC($P(POLICY,U,18))
 D SET^BADEHL1(.ARY,X,13)
 ;Name of insured
 S X=$$HLNAME^HLFNC($P(POLICY,U))
 F LP=1:1:$L(X,$E(HLECH)) S VAL=$P(X,$E(HLECH),LP) D
 .D SET^BADEHL1(.ARY,VAL,16,LP)
 ;Relationship to patient
 D SET^BADEHL1(.ARY,$$GETREL($P(BHSN,U,5)),17)
 ;
 S X=$$HLDATE^HLFNC($P(POLICY,U,19))
 D SET^BADEHL1(.ARY,X,18)                ;Insured's DOB
 ;Holder's Address
 D SET^BADEHL1(.ARY,$P(POLICY,U,9),19,1)  ; Street Address
 D SET^BADEHL1(.ARY,$P(POLICY,U,11),19,3) ; City
 D SET^BADEHL1(.ARY,$$GET1^DIQ(5,$$GET1^DIQ(9000003.1,+BADEPOLP,.12,"I"),1),19,4)  ; State Abbrev
 D SET^BADEHL1(.ARY,$P(POLICY,U,13),19,5)  ; Zip
 ;
 D SET^BADEHL1(.ARY,$P(POLICY,U,8),43)  ; Gender of Insured
 I BADEPOLP D
 .;Not Self
 .D SET^BADEHL1(.ARY,MEMID,36) ;Member Number
 .D SET^BADEHL1(.ARY,$P(POLICY,U,4),49)     ;Insured's Member ID number
 E  D
 .;Self
 .D SET^BADEHL1(.ARY,MEMID,36) ;Member Number
 D SET^BADEHL1(.ARY,$$GET1^DIQ(9000003.1,+BADEPOLP,.05),47)  ;Coverage Type
 ;D SET^BADEHL1(.ARY,$P(POLICY,U,4),49)     ;Insured's ID number
 S IN1=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^BADEHL1(DFN,"Can't create IN1. "_ERR) ;IHS/MSC/AMF 11/23/10 More descriptive alert
 ;Do IN2 segment
 D IN2(INSCO,POLICY)
 Q
RR ;EP
 ; RAILROAD RETIREMENT
 Q:'$D(^AUPNRRE(DFN))
 N BHSN,BHSITB,BHSUFF,BHSEDN,BHSP,BHSI,BHSJ,BHSQ,BHSP,BHSPDN
 N BHSNM,BHSPFX,BHSCTYP
 S BHSN=^AUPNRRE(DFN,0)
 ;S BHSINS=$P(^AUTNINS($P(BHSN,U,2),0),U,1)
 ;S BHSUFF=$P(BHSN,U,3)
 S BHSEDN=0 F  S BHSEDN=$O(^AUPNRRE(DFN,11,BHSEDN)) Q:BHSEDN'=+BHSEDN  D
 .S BHSP=$G(^AUPNRRE(DFN,11,BHSEDN,0))
 .S BHSI=$P(BHSN,U,2)_"-"_$P(BHSP,U,3),BHSJ=9999999-$P(BHSP,U,1)
 .S BHSITB(BHSI,BHSJ)=DFN_";"_BHSEDN
 S BHSI=0 F BHSQ=0:0 S BHSI=$O(BHSITB(BHSI)) Q:BHSI=""  D
 .S BHSJ=$O(BHSITB(BHSI,0)) S BHSP=BHSITB(BHSI,BHSJ)
 .S BHSPDN=$P(BHSP,";",1),BHSEDN=$P(BHSP,";",2) D DRR
 Q
DRR ;
 N X,BHSXDT,BHSINS
 S BHSNM=^AUPNRRE(BHSPDN,11,BHSEDN,0)
 S X=$P(BHSNM,U,1)
 ;-- add set of exp date variable, quit if not current
 S (BHSXDT,X)=$P(BHSNM,U,2)
 S:BHSXDT="" BHSXDT=9999999
 Q:BHSXDT<$$DT^XLFDT()
 S CNT=CNT+1
 D SET^BADEHL1(.ARY,"IN1",0)
 D SET^BADEHL1(.ARY,CNT,1)
 S BHSN=^AUPNRRE(DFN,0)
 S INSCO=+$P(BHSN,U,2)
 S BHSPFX=$$GET1^DIQ(9000005,DFN,.03)    ; Prefix
 S BHSCTYP=$P(BHSNM,U,3)  ; Coverage Type
 D SET^BADEHL1(.ARY,INSCO,2)     ; Insurer IEN
 D SET^BADEHL1(.ARY,INSCO,3)     ; Insurer IEN
 S BHSINS=$$GET1^DIQ(9999999.18,INSCO,.01)
 S BHSINS=$S($L(BHSINS):BHSINS,1:"???")
 D SET^BADEHL1(.ARY,BHSINS,4)  ;Insurance Company name
 ;Get data on the insurer
 S INS=$G(^AUTNINS(INSCO,0))
 D MSCINS
 ;Get the eligibility and expiration dates
 S X=$$HLDATE^HLFNC($P(BHSNM,U,1))
 D SET^BADEHL1(.ARY,X,12)
 S X=$$HLDATE^HLFNC($P(BHSNM,U,2))
 D SET^BADEHL1(.ARY,X,13)
 D SET^BADEHL1(.ARY,$$GET1^DIQ(9000005,DFN,.04),8)  ;Group Number
 S X=$$HLNAME^HLFNC($$GET1^DIQ(9000005,DFN,2101),HLECH)  ;Name of insured
 F LP=1:1:$L(X,$E(HLECH)) S VAL=$P(X,$E(HLECH),LP) D
 .D SET^BADEHL1(.ARY,VAL,16,LP)
 D SET^BADEHL1(.ARY,"SEL",17)  ;Relationship to patient - File doesn't have .06 field
 D SET^BADEHL1(.ARY,$$HLDATE^HLFNC($P(BHSNM,U,9)),18)  ;Insured's DOB
 D SET^BADEHL1(.ARY,$$HLDATE^HLFNC($$GET1^DIQ(9000005,DFN,2102,"I")),18)
 ;Insured's address
 ; No policy so no policy holder address
 ;S FLD=$$PTADDR(DFN)
 ;F LP=1:1:$L(FLD,$E(HLECH)) S VAL=$P(FLD,$E(HLECH),LP) D
 ;.D SET^BADEHL1(.ARY,VAL,19,LP)
 ;D SET^BADEHL1(.ARY,$P(BHSN,U,4),36) ;policy number
 D SET^BADEHL1(.ARY,$P(BHSNM,U,8),43)  ; Gender of Insured
 D SET^BADEHL1(.ARY,$P(BHSNM,U,3),47)  ; Coverage Type
 D SET^BADEHL1(.ARY,$S(BHSCTYP="D":$P(BHSNM,U,6),1:BHSPFX_$P(BHSN,U,4)),49)  ; ID Number
 S IN1=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^BADEHL1(DFN,"Can't create Railroad IN1. "_ERR) ;IHS/MSC/AMF 11/23/10 More descriptive alert
 ;Setup the IN2 segment
 D IN2(INSCO,"")
 K BHSNM,BHSXDT
 Q
MSCINS ;Insurance company data
 Q:'$L(INS)
 N ST,ZIP,ADDR,LP,VAL,PHONE,PHD
 S ST=$$GET1^DIQ(5,$P(INS,U,4),1)   ;State Abbrev
 S ZIP=$E($P(INS,U,5),1,5)
 S ADDR=$P(INS,U,2)_"^^"_$P(INS,U,3)_"^"_ST_"^"_ZIP
 F LP=1:1:$L(ADDR,$E(HLECH)) S VAL=$P(ADDR,$E(HLECH),LP) D
 .D SET^BADEHL1(.ARY,VAL,5,LP)
 S PHD=$P(BHSN,U,9)  ;Company Contact Name
 S PHD=$$HLNAME^HLFNC($$GET1^DIQ(9000003.1,PHD,.01),HLECH)
 F LP=1:1:$L(PHD,$E(HLECH)) S VAL=$P(PHD,$E(HLECH),LP) D
 .D SET^BADEHL1(.ARY,VAL,6,LP)
 S PHONE=$$HLPHONE^HLFNC($P(INS,U,6))
 I $L(PHONE) D
 .D SET^BADEHL1(.ARY,PHONE,7,1)  ;Company Phone Number
 .D SET^BADEHL1(.ARY,"WPH",7,2)
 Q
GETREL(RIEN) ;Find the relationship
 N Y,REL
 S REL=""
 I +RIEN D
 .S Y=$$GET1^DIQ(9999999.36,RIEN,.01)
 .I Y="SPOUSE"!(Y="HUSBAND")!(Y="WIFE")!(Y="LIFE PARTNER") S REL="SPO"
 .E  I Y="SELF" S REL="SEL"
 .E  I Y="SON"!(Y="DAUGHTER")!(Y="CHILD")!(Y="STEPSON")!(Y="STEPDAUGHTER")!(Y="STEP CHILD") S REL="CHD"
 .E  S REL="OTH"
 Q REL
IN2(INSCO,POLICY,CASENUM) ;Do the IN2 Segment
 N BADEEMPP,BADEEMPN,BADEPPAT,DEN,DENI
 S CASENUM=$G(CASENUM,"")
 D SET^BADEHL1(.ARY,"IN2",0)
 D SET^BADEHL1(.ARY,CNT,1)
 D SET^BADEHL1(.ARY,CASENUM,8)  ; Medicaid Case Number
 I POLICY'="" D
 .S BADEEMPP=$P(POLICY,U,16)
 .I BADEEMPP'="" D
 ..S BADEEMPN=$P($G(^AUTNEMPL(+BADEEMPP,0)),U,1)  ;Employer name
 ..S X=BADEEMPP_"^"_BADEEMPN
 ..F LP=1:1:$L(X,$E(HLECH)) S VAL=$P(X,$E(HLECH),LP) D
 ...D SET^BADEHL1(.ARY,VAL,3,LP)
 S DEN=$P($G(^AUTNINS(+INSCO,2)),U,5)
 I DEN="U"!(DEN="") S DENI="MD"
 E  S DENI="DN"
 D SET^BADEHL1(.ARY,DENI,59)
 S IN2=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^BADEHL1(DFN,"Can't create IN2. "_ERR) ;IHS/MSC/AMF 11/23/10 More descriptive alert
 Q
 ;
CRTNULL ; Creates empty IN1/IN2
 D SET^BADEHL1(.ARY,"IN1",0)
 D SET^BADEHL1(.ARY,1,1)
 S IN1=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^BADEHL1(DFN,"Can't create IN1. "_ERR) Q  ;IHS/MSC/AMF 11/23/10 More descriptive alert
 D SET^BADEHL1(.ARY,"IN2",0)
 D SET^BADEHL1(.ARY,1,1)
 S IN2=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^BADEHL1(DFN,"Can't create IN2. "_ERR) Q  ;IHS/MSC/AMF 11/23/10 More descriptive alert
 Q
 ; Return HL7 formed patient address
PTADDR(DFN) ;EP
 N HLQ,FLD,PID
 S HLQ=HL1("Q")
 S PID=$$EN^VAFHLPID(DFN,"11")
 S FLD=$P(PID,HLFS,12)
 Q FLD