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

AGMPIHL1.m

Go to the documentation of this file.
AGMPIHL1 ;IHS/SD/TPF - Patient Registration MPI HLO Interface ext ALL HLO MESSAGES
 ;;7.2;IHS PATIENT REGISTRATION;**1**;JAN 07, 2011
 ;CALLED FROM AGMPIHLO
 Q
 ; Create PID segment
PID(DFN) ;EP
 N HRCN,FLD,LP,VAL,ASU,COMP,SUBCOMP
 I '$G(DFN) S ERR="DFN UNDEF IN PID^AGMPIHL1" Q
 I $G(^DPT(DFN,0))="" S ERR="DPT 0 NODE FOR "_DFN_" NOT DEFINED IN PID^AGMPIHL1" Q
 I $P($G(^DPT(DFN,0)),U)="" S ERR="DPT 0 NODE P^1 "_DFN_"NOT POPULATED IN PID^AGMPIHL1" Q
 ;PID(1)="PID^1^V^253032882P~~~USSSA&&0363~SS~VA FACILITY ID&14752&L|
 ;5571~~~USVHA&&0363~PI~VA FACILITY ID&14752&L
 ;^^GEGNUN~DELORES~M~~~~L^BUWSTRYNG~HARRY~M~~~~M^19820328^F^^^
 ;11419 3RD ST~~MORRIS~MN~~~P~|~~MINNEAPOLIS~MN~~~N^^(555)555-1732^^^^^^253032882P^^"
 ;PID(2)="^^MINNEAPOLIS MN^^^^^^^^"
 ;
 ;PID(1)="PID^1^V^V~~~USVHA&&0363~NI~VA FACILITY ID&14752&L|253032882P~~~USSSA&&03
 ;63~SS~VA FACILITY ID&14752&L|5571~~~USVHA&&0363~PI~VA FACILITY ID&14752&L^^GEGNU
 ;N~DELORES~M~~~~L^BUWSTRYNG~HARRY~M~~~~M^19820328^F^^^11419 3RD ST~~MORRIS~MN~~~P
 ;~|~~MINNEAPOL"
 ;PID(2)="IS~MN~~~N^^(555)555-1732^^^^^^253032882P^^^^MINNEAPOLIS MN^^^^^^^^
 S FACNAME=$$GET1^DIQ(9999999.06,DUZ(2)_",",.01,"E")
 K PID,ERR
 D BLDPID^AGMPIPID(DFN,1,"ALL",.PID,.HL1,.ERR)
 S PID(1)=PID(1)_$G(PID(2))
 D MYSET(.ARY,"PID",0)
 D MYSET(.ARY,1,1,1,1,1)  ;ALWAYS 1
 D MYSET(.ARY,$P(PID(1),HL1("FS"),3),2,1,1,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),4),"~"),3,1,1,1)
 D MYSET(.ARY,"USIHS",3,1,4,1)
 D MYSET(.ARY,"0363",3,1,4,3)  ;THIS REFERS TO A TABLE BUT I CAN'T FIND IN VA DOC
 D MYSET(.ARY,"NI",3,1,5,1)
 D MYSET(.ARY,"IHS FACILITY ID - "_FACNAME,3,1,6,1)
 D MYSET(.ARY,$P($$SITE^VASITE,"^",3),3,1,6,2)
 D MYSET(.ARY,"L",3,1,6,3)
 D MYSET(.ARY,$P($P(PID(1),"|",2),"~"),3,2,1,1)
 D MYSET(.ARY,"USSSA",3,2,4,1)
 D MYSET(.ARY,"0363",3,2,4,3)
 D MYSET(.ARY,"SS",3,2,5,1)
 D MYSET(.ARY,"IHS FACILITY ID - "_FACNAME,3,2,6,1)
 D MYSET(.ARY,$P($$SITE^VASITE,"^",3),3,2,6,2)
 D MYSET(.ARY,"L",3,2,6,3)
 D MYSET(.ARY,DFN,3,3,1,1)
 D MYSET(.ARY,"USIHS",3,3,4,1)
 D MYSET(.ARY,"0363",3,3,4,3)
 D MYSET(.ARY,"PI",3,3,5,1)
 D MYSET(.ARY,"IHS FACILITY ID - "_FACNAME,3,3,6,1)
 D MYSET(.ARY,$P($$SITE^VASITE,"^",3),3,3,6,2)
 D MYSET(.ARY,"L",3,3,6,3)
 D MYSET(.ARY,$P(PID(1),HL1("FS"),3),3,4,1,1)
 D MYSET(.ARY,"USIHS",3,4,4,1)
 D MYSET(.ARY,"0363",3,4,4,3)
 D MYSET(.ARY,"NI",3,4,5,1)
 D MYSET(.ARY,"IHS FACILITY ID - "_FACNAME,3,4,6,1)
 D MYSET(.ARY,$P($$SITE^VASITE,"^",3),3,4,6,2)
 D MYSET(.ARY,"L",3,4,6,3)
 D MYSET(.ARY,"200910205571-0700",3,4,8,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),6),"~"),5,1,1,1)  ;LAST NAME
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),6),"~",2),5,1,2,1)  ;FIRST NAME
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),6),"~",3),5,1,3,1)  ;MIDDLE NAME
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),6),"~",4),5,1,4,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),6),"~",5),5,1,5,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),6),"~",6),5,1,6,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),6),"~",7),5,1,7,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),7),"~"),6,1,1,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),7),"~",2),6,1,2,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),7),"~",3),6,1,3,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),7),"~",4),6,1,4,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),7),"~",5),6,1,5,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),7),"~",6),6,1,6,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),7),"~",7),6,1,7,1)
 D MYSET(.ARY,$P(PID(1),HL1("FS"),8),7,1,1,1)   ;DOB
 D MYSET(.ARY,$P(PID(1),HL1("FS"),9),8,1,1,1)   ;SEX
 D MYSET(.ARY,$P(PID(1),HL1("FS"),10),9,1,1,1)
 D MYSET(.ARY,$P(PID(1),HL1("FS"),11),10,1,1,1)  ;RACE
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),12),"~"),11,1,1,1)   ;FIRST LINE
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),12),"~",2),11,1,2,1)   ;SEC LINE
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),12),"~",3),11,1,3,1)   ;CITY
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),12),"~",4),11,1,4,1)   ;STATE
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),12),"~",5),11,1,5,1)   ;ZIP
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),12),"~",6),11,1,6,1)
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),12),"~",7),11,1,7,1)          ;ADDRESS TYPE P=PERMANENT
 D MYSET(.ARY,$P($P($P(PID(1),HL1("FS"),12),"~",8),"|"),11,1,8,1)  ;THIRD LINE
 ;G CONTPID
 D MYSET(.ARY,$P($P(PID(1),"|",4),"~"),11,2,3,1)
 D MYSET(.ARY,$P($P(PID(1),"|",4),"~",2),11,2,2,1)
 D MYSET(.ARY,$P($P(PID(1),"|",4),"~",3),11,2,3,1)
 D MYSET(.ARY,$P($P(PID(1),"|",4),"~",4),11,2,4,1)
 D MYSET(.ARY,$P($P(PID(1),"|",4),"~",5),11,2,5,1)
 D MYSET(.ARY,$P($P(PID(1),"|",4),"~",6),11,2,6,1)
 D MYSET(.ARY,"N",11,2,7,1)  ;address type
 ;
 ;DO ALIASES
 D SALIAS(DFN)
 ;PID-13 PHONES AND EMAIL  ;SET(SEG,VALUE,FIELD,COMP,SUBCOMP,REP)
 ;ADDED THESE FOR PAHSE 2
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),14),"~"),13,1,1,1)    ;PHONE #
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),14),"~",2),13,1,2,1)  ;PRIMARY
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),14),"~",3),13,1,3,1)  ;PHONE
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),15),"~"),13,2,1,1)    ;PHONE #
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),15),"~",2),13,2,2,1)  ;WORK
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),15),"~",3),13,2,3,1)  ;PHONE
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),25),"~"),13,3,1,1)    ;PHONE #
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),25),"~",2),13,3,2,1)  ;OTHER
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),25),"~",3),13,3,3,1)  ;CELL
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),26),"~"),13,4,1,1)    ;EMAIL
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),26),"~",2),13,4,2,1)  ;NET
 D MYSET(.ARY,$P($P(PID(1),HL1("FS"),26),"~",3),13,4,3,1)  ;INTERNET
 D MYSET(.ARY,$P(PID(1),HL1("FS"),17),16,1,1,1)  ;MARITAL STATUS
 D MYSET(.ARY,$P(PID(1),HL1("FS"),18),17,1,1,1)  ;RELIGION
 D MYSET(.ARY,$P(PID(1),HL1("FS"),23),22,1,1,1)  ;ETHNICITY
 D MYSET(.ARY,$P(PID(1),HL1("FS"),27),27,1,1,1)  ;VETERAN STATUS
 D MYSET(.ARY,$P(PID(1),HL1("FS"),29),29,1,1,1)  ;DATE OF DEATH
 ;
CONTPID ;EP -
 S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^AGMPIHLO(DFN,ERR)
 Q
 ;
VTQ(DFN) ;EP - CREATE VTQ DIRECT CONNECT EXACT MATCH QUERY
 ;"VTQ^100127^T^EXACT_MATCH_QUERY^ICN^@00108.1~EQ~GOLDTEST~AND|@00122~EQ
 ;~153050678P~AND|@00108.2~EQ~ADD~AND|@00110~EQ~19780506~AND|@00111~EQ~F~AND|@0010
 ;8.3~EQ~NOSSN"
 Q:'$G(DFN)
 N VTQ,SEX,DOB,NAME,FIRSTNAM,LASTNAM,MIDNAME,SSN
 ;
 S SEX=$P(^DPT(DFN,0),U,2)
 S DOB=$P(^DPT(DFN,0),U,3)
 S DOB=$$HLDATE^HLFNC(DOB,"TS")
 S SSN=$P(^DPT(DFN,0),U,9)
 S NAME=$P(^DPT(DFN,0),U)
 S NAME=$$HLNAME^XLFNAME(NAME,"",COMP)
 S LASTNAM=$P(NAME,COMP)    ;LAST NAME
 S FIRSTNAM=$P(NAME,COMP,2)  ;FIRST NAME
 S MIDNAME=$P(NAME,COMP,3)   ;MIDDLE NAME
 ;
 D MYSET(.ARY,"VTQ",0)
 D MYSET(.ARY,DFN,1,1,1,1)
 D MYSET(.ARY,"T",2,1,1,1)
 D MYSET(.ARY,"EXACT_MATCH_QUERY",3,1,1,1)
 D MYSET(.ARY,"ICN",4,1,1,1)
 D MYSET(.ARY,"@OO108.1",5,1,1,1)
 D MYSET(.ARY,"EQ",5,1,2,1)
 D MYSET(.ARY,LASTNAME,5,1,3,1)
 D MYSET(.ARY,"AND",5,1,4,1)
 D MYSET(.ARY,"@00122",5,2,1,1)
 D MYSET(.ARY,"EQ",5,2,2,1)
 D MYSET(.ARY,SSN,5,2,3,1)
 D MYSET(.ARY,"AND",5,2,4,1)
 D MYSET(.ARY,"@00108.2",5,3,1,1)
 D MYSET(.ARY,"EQ",5,3,2,1)
 D MYSET(.ARY,FIRSTNAM,5,3,3,1)
 D MYSET(.ARY,"AND",5,3,4,1)
 D MYSET(.ARY,"@00110",5,4,1,1)
 D MYSET(.ARY,"EQ",5,4,2,1)
 D MYSET(.ARY,DOB,5,4,3,1)
 D MYSET(.ARY,"AND",5,4,4,1)
 D MYSET(.ARY,"@00111",5,5,1,1)
 D MYSET(.ARY,"EQ",5,5,2,1)
 D MYSET(.ARY,SEX,5,5,3,1)
 D MYSET(.ARY,"AND",5,5,4,1)
 D MYSET(.ARY,"@00108.3",5,6,1,1)
 D MYSET(.ARY,"EQ",5,6,2,1)
 D MYSET(.ARY,MIDNAME,5,6,3,1)
 S VTQ=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^AGMPIHLO(DFN,ERR)
 Q
 ;
RDF(DFN) ;EP - CRATED RDF SEGMENT FOR VTQ MESSAGE
 ;"RDF^24^@00108.1~ST~30|@00122~ST~9|@00110~TS~8|@00756~ST~6|@00105~ST~1
 ;9|@00108.2~ST~30|@00169~ST~999|@00740~TS~8|@00108.3~ST~16|@00111~ST~1|@00126.1~S
 ;T~30|@00126.2~ST~3|@00108.5~ST~15|@00108.4~ST~10|@00109.1~ST~20|@ZEL6~ST~9|@CASE
 ;#~ST~69|@POW~ST~1|@00127~ST~1|@00112.1~ST~30|@00112.2~ST~25|@00112.3~ST~25|@0011
 ;2.5~ST~10|@00112.4~ST~10"       
 Q:'$G(DFN)
 N RDF
 ;
 D MYSET(.ARY,"RDF",0)
 D MYSET(.ARY,1,1,1,1,1)
 D MYSET(.ARY,"@OO108.1",2,1,1,1)
 D MYSET(.ARY,"ST",2,1,2,1)
 D MYSET(.ARY,30,2,1,3,1)
 D MYSET(.ARY,"@00122",2,2,1,1)
 D MYSET(.ARY,"ST",2,2,2,1)
 D MYSET(.ARY,9,2,2,3,1)
 D MYSET(.ARY,"@00110",2,3,1,1)
 D MYSET(.ARY,"TS",2,3,2,1)
 D MYSET(.ARY,"8",2,2,2,1)
 D MYSET(.ARY,"@00756",2,4,1,1)
 D MYSET(.ARY,"ST",2,4,2,1)
 D MYSET(.ARY,"6",2,4,3,1)
 D MYSET(.ARY,"@00105",2,5,1,1)
 D MYSET(.ARY,"ST",2,5,2,1)
 D MYSET(.ARY,"19",2,5,3,1)
 D MYSET(.ARY,"@00108.2",2,6,1,1)
 D MYSET(.ARY,"ST",2,6,2,1)
 D MYSET(.ARY,"30",2,5,3,1)
 D MYSET(.ARY,"@00169",2,7,1,1)
 D MYSET(.ARY,"ST",2,7,2,1)
 D MYSET(.ARY,"999",2,7,3,1)
 D MYSET(.ARY,"@00740",2,8,1,1)
 D MYSET(.ARY,"TS",2,8,2,1)
 D MYSET(.ARY,"8",2,8,3,1)
 D MYSET(.ARY,"@00108.3",2,9,1,1)
 D MYSET(.ARY,"ST",2,9,2,1)
 D MYSET(.ARY,"16",2,9,3,1)
 D MYSET(.ARY,"@00111",2,10,1,1)
 D MYSET(.ARY,"ST",2,10,2,1)
 D MYSET(.ARY,"1",2,10,3,1)
 D MYSET(.ARY,"@00126.1",2,11,1,1)
 D MYSET(.ARY,"ST",2,11,2,1)
 D MYSET(.ARY,"30",2,11,3,1)
 D MYSET(.ARY,"@00126.2",2,12,1,1)
 D MYSET(.ARY,"ST",2,12,2,1)
 D MYSET(.ARY,"3",2,12,3,1)
 D MYSET(.ARY,"@00108.5",2,13,1,1)
 D MYSET(.ARY,"ST",2,13,2,1)
 D MYSET(.ARY,"15",2,13,3,1)
 D MYSET(.ARY,"@00108.4",2,14,1,1)
 D MYSET(.ARY,"ST",2,14,2,1)
 D MYSET(.ARY,"10",2,14,3,1)
 D MYSET(.ARY,"@00109.1",2,15,1,1)
 D MYSET(.ARY,"ST",2,15,2,1)
 D MYSET(.ARY,"20",2,13,3,1)
 D MYSET(.ARY,"@ZEL6",2,16,1,1)
 D MYSET(.ARY,"ST",2,16,2,1)
 D MYSET(.ARY,"9",2,16,3,1)
 D MYSET(.ARY,"@CASE#",2,17,1,1)
 D MYSET(.ARY,"ST",2,17,2,1)
 D MYSET(.ARY,"69",2,17,3,1)
 D MYSET(.ARY,"@POW",2,18,1,1)
 D MYSET(.ARY,"ST",2,18,2,1)
 D MYSET(.ARY,"1",2,18,3,1)
 D MYSET(.ARY,"@00127",2,19,1,1)
 D MYSET(.ARY,"ST",2,19,2,1)
 D MYSET(.ARY,"1",2,19,3,1)
 D MYSET(.ARY,"@00112.1",2,20,1,1)
 D MYSET(.ARY,"ST",2,20,2,1)
 D MYSET(.ARY,"30",2,20,3,1)
 D MYSET(.ARY,"@00112.2",2,21,1,1)
 D MYSET(.ARY,"ST",2,21,2,1)
 D MYSET(.ARY,"25",2,21,3,1)
 D MYSET(.ARY,"@00112.3",2,22,1,1)
 D MYSET(.ARY,"ST",2,22,2,1)
 D MYSET(.ARY,"25",2,22,3,1)
 D MYSET(.ARY,"@00112.5",2,23,1,1)
 D MYSET(.ARY,"ST",2,23,2,1)
 D MYSET(.ARY,"10",2,23,3,1)
 D MYSET(.ARY,"@00112.4",2,24,1,1)
 D MYSET(.ARY,"ST",2,24,2,1)
 D MYSET(.ARY,"10",2,24,3,1)
 S RDF=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^AGMPIHLO(DFN,ERR)
 Q
ZPD(DFN) ;EP - RPMS SPECIFIC DATA
 N TRIBEPTR,TRIBECOD,ELIGSTAT,BENPTR,BENCLASS,QUANTUM
 S (BENCLASS,TRIBECOD,ELIGSTAT,QUANTUM)=""
 S TRIBEPTR=$$GET1^DIQ(9000001,DFN_",",1108,"I")  ;TRIBE OF MEMBERSHIP PTR
 S:TRIBEPTR'="" TRIBECOD=$$GET1^DIQ(9999999.03,TRIBEPTR_",",.02,"I")  ;TRIBE OF MEMBERSHIP CODE
 S ELIGSTAT=$$GET1^DIQ(9000001,DFN_",",1112,"I")  ;ELIGIBILITY STATUS
 S BENPTR=$$GET1^DIQ(9000001,DFN_",",1111,"I")  ;CLASSIFICATION/BENEFICIARY PTR
 S:BENPTR'="" BENCLASS=$$GET1^DIQ(9999999.25,BENPTR_",",.02,"I")  ;CLASSIFICATION/BENEFICIARY CODE
 S QUANTUM=$$GET1^DIQ(9000001,DFN_",",1110,"I")  ;INDIAN BLOOD QUANTUM
 D MYSET(.ARY,"ZPD",0)
 D MYSET(.ARY,1,1,1,1,1)  ;ALWAYS 1
 D MYSET(.ARY,TRIBECOD,2,1,1,1)
 D MYSET(.ARY,ELIGSTAT,3,1,1,1)
 D MYSET(.ARY,BENCLASS,4,1,1,1)
 D MYSET(.ARY,QUANTUM,5,1,1,1)
 ;POPULATE THE CHARTS
 D SCHART(DFN)
 S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^AGMPIHLO(DFN,ERR)
 Q
 ;
SCHART(IEN) ;EP - GET ACTIVE CHARTS
 N INACTIVE,DUZ2,HRNREC,SEQ,UNIQID,SCHART,STAT
 S INACTIVE=1
 S SCHART=""
 S DUZ2=0
 ;SET(SEG,VALUE,FIELD,REP,COMP,SUBCOMP)
 F SEQ=1:1 S DUZ2=$O(^AUPNPAT(IEN,41,DUZ2)) Q:DUZ2=""  D
 .Q:$P($G(^AGFAC(DUZ2,0)),U,21)'="Y"  ;ONLY OFFICAL REG. FACILITY
 .S HRN=$P($G(^AUPNPAT(IEN,41,DUZ2,0)),U,2)
 .S HRN=$$FILLSTR(HRN,10,"R","0")
 .S HRNFAC=$P($G(^AUPNPAT(IEN,41,DUZ2,0)),U)
 .S UNIQID=$$GET1^DIQ(9999999.06,HRNFAC_",",.32)
 .S DATEINAC=$P($G(^AUPNPAT(IEN,41,DUZ2,0)),U,3)  ;SEND INACTIVE DATE
 .S:DATEINAC'="" DATEINAC=$$CONDT^AGMPHLU(DATEINAC)  ;CHANGE FM DATE TO SQL NEXTGATE DATE
 .S STAT=$$GET1^DIQ(4,DUZ2_",",99,"I")
 .D MYSET(.ARY,STAT,6,SEQ,1,1)
 .D MYSET(.ARY,HRN,6,SEQ,2,1)
 .D MYSET(.ARY,HRNFAC,6,SEQ,3,1)
 .D MYSET(.ARY,UNIQID,6,SEQ,4,1)
 .D MYSET(.ARY,DATEINAC,6,SEQ,5,1)
 Q
 ;
SALIAS(IEN) ;EP - GET ALIASES
 N ALIASREC,COMPTR,ALIASDAT,SALIAS
 ;^DPT(8118,.01,1,0)=SHISH,KABOB^^464
 S SALIAS=""
 S ALIASREC=0
 S SEQ=0
 F  S ALIASREC=$O(^DPT(IEN,.01,ALIASREC)) Q:'ALIASREC  D
 .S COMPTR=$P(^DPT(IEN,.01,ALIASREC,0),U,3)
 .I 'COMPTR S SEQ=SEQ+1 D PARSE(ALIASREC) Q
 .;Q:'COMPTR  ;IF NO NAME COMPONENT PULL FROM DPT
 .Q:'$D(^VA(20,COMPTR))
 .S ALIASDAT=$G(^VA(20,COMPTR,1))
 .Q:ALIASDAT=""
 .S SEQ=SEQ+1
 .S ALIASLST=$P(ALIASDAT,U)
 .S ALIASFST=$P(ALIASDAT,U,2)
 .S ALIASMID=$P(ALIASDAT,U,3)
 .S ALIASPRE=$P(ALIASDAT,U,4)
 .S ALIASSUF=$P(ALIASDAT,U,5)
 .;SET(SEG,VALUE,FIELD,REP,COMP,SUBCOMP)
 .D MYSET(.ARY,ALIASLST,9,SEQ,1,1)
 .D MYSET(.ARY,ALIASFST,9,SEQ,2,1)
 .D MYSET(.ARY,ALIASMID,9,SEQ,3,1)
 .D MYSET(.ARY,ALIASPRE,9,SEQ,4,1)
 .D MYSET(.ARY,ALIASSUF,9,SEQ,5,1)
 Q
 ;
PARSE(ALIASREC) ;EP - PARSE ALIAS NAME
 S COMP="~"
 S ALIAS=$P($G(^DPT(IEN,.01,ALIASREC,0)),U)
 S ALIASLST=$P(ALIAS,",")
 S ALIASFST=$P($P(ALIAS,",",2)," ")
 S ALIASMID=$P(ALIAS," ",2)
 D MYSET(.ARY,ALIASLST,9,SEQ,1,1)
 D MYSET(.ARY,ALIASFST,9,SEQ,2,1)
 D MYSET(.ARY,ALIASMID,9,SEQ,3,1)
 Q
 ;
FILLSTR(STR,LENGTH,JUST,FILLER) ;EP - FILL STRING TO FIXED LENGTH
 N FILL
 S LENGTH=$G(LENGTH),JUST=$G(JUST)
 S STR=$E(STR,1,LENGTH)
 Q:$L(STR)=LENGTH STR
 S $P(FILL,FILLER,LENGTH-$L(STR)+1)=""
 I JUST="L" S STR=STR_FILL
 E  S STR=FILL_STR
 Q STR
 ;
MRG(DFN2) ;EP - CREATE MERGE SEGMENT
 N ICN,NODE,NAME,FIRSTNM,LASTNAM,MIDNAME
 S NODE=$$MPINODE^AGMPIPID(DFN2)
 S ICN=$S($P(NODE,U)=-1:"",1:$P(NODE,U))_"V"_$S($P(NODE,U,2)?1.N:$P(NODE,U,2),1:"")
 S NAME=$P(^DPT(DFN2,0),U)
 S NAME=$$HLNAME^XLFNAME(NAME,"",COMP)
 S LASTNAME=$P(NAME,COMP)    ;LAST NAME
 S FIRSTNAM=$P(NAME,COMP,2)  ;FIRST NAME
 S MIDNAME=$P(NAME,COMP,3)   ;MIDDLE NAME
 D MYSET(.ARY,"MRG",0)
 D MYSET(.ARY,ICN,1,1,1,1)
 D MYSET(.ARY,"USIHS",1,1,4,1)
 D MYSET(.ARY,"0363",1,1,4,3)
 D MYSET(.ARY,"NI",1,1,5,1)
 D MYSET(.ARY,"IHS FACILIY ID",1,1,6,1)
 D MYSET(.ARY,$P($$SITE^VASITE,"^",3),1,1,6,2)
 D MYSET(.ARY,"L",1,1,6,3)
 D MYSET(.ARY,DFN2,1,2,1,1)
 D MYSET(.ARY,"NI",1,1,5,1)
 D MYSET(.ARY,"USIHS",1,2,4,1)
 D MYSET(.ARY,"0363",1,2,4,3)
 D MYSET(.ARY,"PI",1,2,5,1)
 D MYSET(.ARY,"IHS FACILIY ID",1,2,6,1)
 D MYSET(.ARY,$P($$SITE^VASITE,"^",3),1,2,6,2)
 D MYSET(.ARY,"L",1,2,6,3)
 D MYSET(.ARY,LASTNAME,7,1,1,1)
 D MYSET(.ARY,FIRSTNAM,7,1,2,1)
 D MYSET(.ARY,MIDNAME,7,1,3,1)
 D MYSET(.ARY,"L",7,1,7,1)
 S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 I $D(ERR) D NOTIF^AGMPIHLO(DFN,ERR)
 Q
 ;SET(SEG,VALUE,FIELD,REP,COMP,SUBCOMP)
 ;THIS LOOKS MORE LIKE THE ARRAY WILL ACTUALLY TURN OUT
 ;AND ALSO MATCHES THE AGMPPARS V1.6 MESSAGE PARSER GENERIC OUTPUT
MYSET(ARY,V,F,R,C,S) ;EP
 D SET^HLOAPI(.ARY,.V,.F,.C,.S,.R)
 Q