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

IBTRHLI3.m

Go to the documentation of this file.
IBTRHLI3 ;ALB/JWS - Receive and store 278 Response message ;05-JUN-2014
 ;;2.0;INTEGRATED BILLING;**517**;21-MAR-94;Build 240
 ;;Per VA Directive 6402, this routine should not be modified.
 ;
 ;**Program Description**
 ;  This pgm will process the indiv segments of the
 ;  incoming 278 response msgs.
 ;
 ; * Each of these tags are called by IBTRHL2.
 ; 
 ;  This routine is based on IBCNEHL2 which was introduced with patch 300, and subsequently
 ;  patched with patches 345, 416, and 438.
 ;
 ;  Variables
 ;    SEG = HL7 Seg Name
 ;    IBSEG = Array of the segment
 ;
 Q  ; No direct calls
 ;
ZTP(IBSEG,RESIEN,ERROR,SLIEN) ; Process ZTP Subscriber date seg (X12 DTP segs)
 ;  Input:
 ;  IBSEG,RESIEN,SLIEN
 ;
 ;  Output:
 ;  ERROR
 N FLD,LEV,IBFDA,RIEN,LEV1
 I $G(IBSEG(4))="DTP 2000F" D  D UP^IBTRHLI2("DTP","2000F") Q
 .D SLCHECK^IBTRHLI1
 .I $G(IBSEG(2))=472 S IBFDA(356.2216,LEV1,.11)=$P($G(IBSEG(3)),HLCMP),IBFDA(356.2216,LEV1,.17)=$P($G(IBSEG(3)),HLCMP,2) Q  ;service date
 .I $G(IBSEG(2))=102 S IBFDA(356.2216,LEV1,.12)=$P($G(IBSEG(3)),HLCMP) Q  ;cert issue date
 .I $G(IBSEG(2))="036" S IBFDA(356.2216,LEV1,.13)=$P($G(IBSEG(3)),HLCMP) Q  ;cert expiration date
 .I $G(IBSEG(2))="007" S IBFDA(356.2216,LEV1,.14)=$P($G(IBSEG(3)),HLCMP),IBFDA(356.2216,LEV1,.16)=$P($G(IBSEG(3)),HLCMP,2) Q  ;cert effective date
 S LEV="+2,"_RESIEN_","
 I $G(IBSEG(2))=439 S FLD=2.18 G ZTP1 ;Accident Date
 I $G(IBSEG(2))=484 S FLD=2.19 G ZTP1 ;Last Menstrual Period
 I $G(IBSEG(2))="ABC" S FLD=2.2 G ZTP1 ;Estimated DOB
 I $G(IBSEG(2))=431 S FLD=2.21 G ZTP1 ;Illness Date
 I $G(IBSEG(2))="AAH"!($G(IBSEG(2)))=435 S FLD=".07" G ZTP1
 I $G(IBSEG(2))="096" S FLD=2.22 G ZTP1  ;discharge date
 I $G(IBSEG(2))=102 S FLD=2.23 G ZTP1 ;Cert Issue Date
 I $G(IBSEG(2))="036" S FLD=2.24 G ZTP1 ;Cert Expiration Date
 I $G(IBSEG(2))="007" S FLD=2.25,IBFDA(356.22,RESIEN_",",2.26)=$P($G(IBSEG(3)),HLCMP,2) G ZTP1 ;Cert Effective Date
 Q
ZTP1 ;
 S IBFDA(356.22,RESIEN_",",FLD)=$P($G(IBSEG(3)),HLCMP)
 D UP^IBTRHLI2("DTP","2000E")
 Q
 ;
RXE(IBSEG,RESIEN,ERROR) ;RXE Pharmacy/Treatment Encoded Order seg
 ;  Input:
 ;  IBSEG,RESIEN
 ;
 ;  Output:
 ;  ERROR
 N LEV,IBFDA,RIEN
 S LEV=RESIEN_","
 S IBFDA(356.22,LEV,8.01)=$P($P($G(IBSEG(14)),HLREP),HLCMP)   ;CR503 OXY EQUIP TYPE
 S IBFDA(356.22,LEV,8.02)=$P($P($G(IBSEG(14)),HLREP,2),HLCMP) ;CR504 OXY EQUIP TYPE
 S IBFDA(356.22,LEV,8.05)=$G(IBSEG(23))                       ;CR506 OXY FLOW RATE
 S IBFDA(356.22,LEV,8.06)=$P($G(IBSEG(19)),HLCMP)             ;CR507 DAILY OXY USE CNT
 S IBFDA(356.22,LEV,8.07)=$P($P($G(IBSEG(1)),HLCMP),HLSCMP)   ;CR508 OXY USE PERIOD HR CNT
 S IBFDA(356.22,LEV,8.08)=$P($G(IBSEG(1)),HLCMP,8)            ;CR509 RESP THERAPIST TEXT
 S IBFDA(356.22,LEV,9.07)=$G(IBSEG(16))                       ;CR516 PORT OXY SYS FLOW
 S IBFDA(356.22,LEV,9.08)=$P($G(IBSEG(29)),HLCMP)             ;CR517 OXY DEL SYS CODE
 S IBFDA(356.22,LEV,8.03)=$P($G(IBSEG(31)),HLCMP,1)           ;CR518 OXY EQUIP TYPE
 D UP^IBTRHLI2("CR5","2000E")
 Q
ZHS(IBSEG,RESIEN,ERROR,SLIEN) ; ZHS Healthcare services delivery seg
 ;  Input:
 ;  IBSEG,RESIEN,SLIEN
 ;
 ;  Output:
 ;  ERROR
 N CT,LEV,IBFDA,RIEN
 I $G(IBSEG(1))="HSD 2000F" D  D UP^IBTRHLI2("HSD","2000F") Q
 .S LEV=SLIEN_","_RESIEN_","
 .S IBFDA(356.2216,LEV,5.01)=$G(IBSEG(2)) ;HCSD Quantity Qualifier
 .S IBFDA(356.2216,LEV,5.02)=$G(IBSEG(3)) ;HCSD Service Unit Count
 .S IBFDA(356.2216,LEV,5.03)=$G(IBSEG(4)) ;HCSD Units of Measurement
 .S IBFDA(356.2216,LEV,5.04)=$G(IBSEG(5)) ;HCSD Sample Selection Modulus
 .S IBFDA(356.2216,LEV,5.05)=$G(IBSEG(6)) ;HCSD Time Period Qualifier
 .S IBFDA(356.2216,LEV,5.06)=$G(IBSEG(7)) ;HCSD Period Count
 .S IBFDA(356.2216,LEV,5.07)=$G(IBSEG(8)) ;HCSD Delivery Frequency
 .S IBFDA(356.2216,LEV,5.08)=$G(IBSEG(9)) ;HCSD Delivery Time Pattern
 .Q
 S LEV=RESIEN_","
 S IBFDA(356.22,LEV,4.01)=$G(IBSEG(2))  ; quantity qualifier
 S IBFDA(356.22,LEV,4.02)=$G(IBSEG(3)) ; unit count
 S IBFDA(356.22,LEV,4.03)=$G(IBSEG(4))  ;measurement code
 S IBFDA(356.22,LEV,4.04)=$G(IBSEG(5))  ;selection modulus
 S IBFDA(356.22,LEV,4.05)=$G(IBSEG(6))  ;period qualifier
 S IBFDA(356.22,LEV,4.06)=$G(IBSEG(7))  ;period count
 S IBFDA(356.22,LEV,4.07)=$G(IBSEG(8))  ;freq code
 S IBFDA(356.22,LEV,4.08)=$G(IBSEG(9))  ;pattern
 D UP^IBTRHLI2("HSD","2000E")
 Q
 ;
CTD(IBSEG,RESIEN,ERROR,PEIEN,SLIEN,SLPIEN) ; CTD Contact Data seg
 ;  Input:
 ;  IBSEG,RESIEN,PEIEN,SLIEN,SLPIEN
 ;
 ;  Output:
 ;  ERROR
 N RIEN,LEV
 I $G(IBSEG(1))="PER 2010EB" D  D UP^IBTRHLI2("PER","2010EB") Q
 .S LEV=PEIEN_","_RESIEN_","
 .S IBFDA(356.2213,LEV,.04)="2010EB"
 .S IBFDA(356.2213,LEV,.05)="IC"
 .S IBFDA(356.2213,LEV,.06)=$P($G(IBSEG(2)),HLCMP)  ;CONTACT NAME
 .S IBFDA(356.2213,LEV,.07)=$P($P($G(IBSEG(5)),HLREP),HLCMP,2)  ;COMM NO QUAL1
 .S IBFDA(356.2213,LEV,.08)=$P($P($G(IBSEG(5)),HLREP,2),HLCMP,2) ;COMM NO QUAL2
 .S IBFDA(356.2213,LEV,.09)=$P($P($G(IBSEG(5)),HLREP,3),HLCMP,2) ;COMM NO QUAL3
 .S IBFDA(356.2213,LEV,1)=$P($P($G(IBSEG(5)),HLREP),HLCMP,8) ;CONTACT COMM NUM1
 .S IBFDA(356.2213,LEV,2)=$P($P($G(IBSEG(5)),HLREP,2),HLCMP,8) ;CONTACT COMM NUM2
 .S IBFDA(356.2213,LEV,3)=$P($P($G(IBSEG(5)),HLREP,3),HLCMP,8) ;CONTACT COMM NUM3
 .Q
 I $G(IBSEG(1))="PER 2010FB" D  D UP^IBTRHLI2("PER","2010FB") Q
 .S LEV=SLPIEN_","_SLIEN_","_RESIEN_","
 .S IBFDA(356.22168,LEV,.04)="2010FB"  ;PER loop identifier
 .S IBFDA(356.22168,LEV,.05)="IC"      ;CONTACT FUNCTION CODE
 .S IBFDA(356.22168,LEV,.06)=$P($G(IBSEG(2)),HLCMP)  ;CONTACT NAME
 .S IBFDA(356.22168,LEV,.07)=$P($P($G(IBSEG(5)),HLREP),HLCMP,2)  ;COMM NO QUAL1
 .S IBFDA(356.22168,LEV,.08)=$P($P($G(IBSEG(5)),HLREP,2),HLCMP,2) ;COMM NO QUAL2
 .S IBFDA(356.22168,LEV,.09)=$P($P($G(IBSEG(5)),HLREP,3),HLCMP,2) ;COMM NO QUAL3
 .S IBFDA(356.22168,LEV,1)=$P($P($G(IBSEG(5)),HLREP),HLCMP,8) ;CONTACT COMM NUM1
 .S IBFDA(356.22168,LEV,2)=$P($P($G(IBSEG(5)),HLREP,2),HLCMP,8) ;CONTACT COMM NUM2
 .S IBFDA(356.22168,LEV,3)=$P($P($G(IBSEG(5)),HLREP,3),HLCMP,8) ;CONTACT COMM NUM3
 .Q
 Q
NK1(IBSEG,RESIEN,ERROR,PEIEN) ;NK1 Next of Kin seg
 ;  Input:
 ;  IBSEG,RESIEN,PEIEN
 ;
 ;  Output:
 ;  ERROR
 N LEV,IBFDA,RIEN
 S LEV=PEIEN_","_RESIEN_","
 S IBFDA(356.2213,LEV,4.01)="2010EB"  ;NM1 loop ident
 S IBFDA(356.2213,LEV,4.02)="L5"      ;Entity ident
 S IBFDA(356.2213,LEV,4.03)=$P($P($G(IBSEG(2)),HLCMP,9),HLSCMP)  ;Entity type qual
 S IBFDA(356.2213,LEV,4.04)=$P($G(IBSEG(2)),HLCMP)   ;Contact last or company name
 S IBFDA(356.2213,LEV,4.05)=$P($G(IBSEG(2)),HLCMP,2) ;contact first
 S IBFDA(356.2213,LEV,4.06)=$P($G(IBSEG(2)),HLCMP,3) ;contact middle
 S IBFDA(356.2213,LEV,4.07)=$P($G(IBSEG(2)),HLCMP,4) ;contact suffix
 S IBFDA(356.2213,LEV,4.08)=$P($G(IBSEG(7)),HLCMP)   ;ident code qualifier
 S IBFDA(356.2213,LEV,4.09)=$P($G(IBSEG(7)),HLCMP,2) ;ident code
 S IBFDA(356.2213,LEV,5)=$P($G(IBSEG(4)),HLCMP)      ;contact addr line 1
 S IBFDA(356.2213,LEV,5.01)=$P($G(IBSEG(4)),HLCMP,2) ;contact addr line 2
 S IBFDA(356.2213,LEV,5.02)=$P($G(IBSEG(4)),HLCMP,3) ;contact city 
 S IBFDA(356.2213,LEV,5.03)=$P($G(IBSEG(4)),HLCMP,4) ;contact state
 S IBFDA(356.2213,LEV,5.04)=$P($G(IBSEG(4)),HLCMP,5) ;contact zip
 S IBFDA(356.2213,LEV,5.05)=$P($G(IBSEG(4)),HLCMP,6) ;contact country
 S IBFDA(356.2213,LEV,5.06)=$P($G(IBSEG(4)),HLCMP,8) ;contact country subdivision
 D UP^IBTRHLI2("NM1","2010EB")
 Q
 ;
PSL(IBSEG,RESIEN,ERROR,SLIEN) ;PSL Product/Service Line Item seg
 ;  Input:
 ;  IBSEG,RESIEN,SLIEN
 ;
 ;  Output:
 ;  ERROR
 N LEV,IBFDA,CT,RIEN,LEV1
 I $G(IBSEG(1))="SV1 2000F" D  D UP^IBTRHLI2("SV1","2000F"),PSL2("P") Q
 .D SLCHECK^IBTRHLI1,PSL3("P")
 .S IBFDA(356.2216,LEV1,1.01)=$P($G(IBSEG(7)),HLCMP)   ;SV101-1
 .S IBFDA(356.2216,LEV1,1.04)=$P($G(IBSEG(8)),HLCMP)   ;SV101-3
 .S IBFDA(356.2216,LEV1,1.05)=$P($G(IBSEG(8)),HLCMP,2) ;SV101-4
 .S IBFDA(356.2216,LEV1,1.06)=$P($G(IBSEG(8)),HLCMP,4) ;SV101-5
 .S IBFDA(356.2216,LEV1,1.07)=$P($G(IBSEG(8)),HLCMP,5) ;SV101-6
 .S IBFDA(356.2216,LEV1,1.08)=$G(IBSEG(9))             ;SV101-7
 .;S IBFDA(356.2216,LEV1,1.03)=$P($G(IBSEG(7)),HLCMP,5) ;SV101-8
 .S IBFDA(356.2216,LEV1,1.09)=$G(IBSEG(15))            ;SV102
 .;S IBFDA(356.2216,LEV1,1.1)=$P($G(IBSEG(12)),HLCMP,2) ;SV103
 .S IBFDA(356.2216,LEV1,1.11)=$P($G(IBSEG(12)),HLCMP)  ;SV104
 .S IBFDA(356.2216,LEV1,2.05)=$G(IBSEG(47))            ;SV111
 .S IBFDA(356.2216,LEV1,2.09)=$G(IBSEG(48))            ;SV120
 .Q
 I $G(IBSEG(1))="SV2 2000F" D  D UP^IBTRHLI2("SV2","2000F"),PSL2("I") Q
 .D SLCHECK^IBTRHLI1,PSL3("I")
 .S IBFDA(356.2216,LEV1,2.06)=$G(IBSEG(17))            ;SV201
 .S IBFDA(356.2216,LEV1,1.01)=$P($G(IBSEG(7)),HLCMP)   ;SV202-1
 .S IBFDA(356.2216,LEV1,1.04)=$P($G(IBSEG(8)),HLCMP)   ;SV202-3
 .S IBFDA(356.2216,LEV1,1.05)=$P($G(IBSEG(8)),HLCMP,2) ;SV202-4
 .S IBFDA(356.2216,LEV1,1.06)=$P($G(IBSEG(8)),HLCMP,4) ;SV202-5
 .S IBFDA(356.2216,LEV1,1.07)=$P($G(IBSEG(8)),HLCMP,5) ;SV202-6
 .S IBFDA(356.2216,LEV1,1.08)=$G(IBSEG(9))             ;SV202-7
 .;S IBFDA(356.2216,LEV1,1.03)=$P($G(IBSEG(7)),HLCMP,5) ;SV202-8
 .S IBFDA(356.2216,LEV1,1.09)=$G(IBSEG(15))            ;SV203
 .S IBFDA(356.2216,LEV1,1.11)=$P($G(IBSEG(12)),HLCMP)  ;SV205
 .S IBFDA(356.2216,LEV1,2.07)=$G(IBSEG(13))            ;SV206
 .S IBFDA(356.2216,LEV1,2.09)=$G(IBSEG(48))            ;SV210
 .Q
 I $G(IBSEG(1))="SV3 2000F" D  D UP^IBTRHLI2("SV3","2000F"),PSL2("D") Q
 .D SLCHECK^IBTRHLI1,PSL3("D")
 .S IBFDA(356.2216,LEV1,1.01)=$P($G(IBSEG(7)),HLCMP)   ;SV301-1
 .S IBFDA(356.2216,LEV1,1.04)=$P($G(IBSEG(8)),HLCMP)   ;SV301-3
 .S IBFDA(356.2216,LEV1,1.05)=$P($G(IBSEG(8)),HLCMP,2) ;SV301-4
 .S IBFDA(356.2216,LEV1,1.06)=$P($G(IBSEG(8)),HLCMP,4) ;SV301-5
 .S IBFDA(356.2216,LEV1,1.07)=$P($G(IBSEG(8)),HLCMP,5) ;SV301-6
 .S IBFDA(356.2216,LEV1,1.08)=$G(IBSEG(9))             ;SV301-7
 .;S IBFDA(356.2216,LEV1,1.03)=$P($G(IBSEG(7)),HLCMP,5) ;SV301-8
 .S IBFDA(356.2216,LEV1,1.09)=$G(IBSEG(15))            ;SV302
 .S IBFDA(356.2216,LEV1,1.11)=$P($G(IBSEG(12)),HLCMP) ;SV306
 .S IBFDA(356.2216,LEV1,3.06)=$G(IBSEG(17))            ;SV305
 .S IBFDA(356.2216,LEV1,3.01)=$P($G(IBSEG(33)),HLCMP)  ;SV304-1
 .S IBFDA(356.2216,LEV1,3.02)=$P($G(IBSEG(33)),HLCMP,2) ;SV304-2
 .S IBFDA(356.2216,LEV1,3.03)=$P($G(IBSEG(33)),HLCMP,4) ;SV304-3
 .S IBFDA(356.2216,LEV1,3.04)=$P($G(IBSEG(33)),HLCMP,5) ;SV304-4
 .S IBFDA(356.2216,LEV1,3.05)=$P($G(IBSEG(33)),HLCMP,9) ;SV304-5
 .Q
 I $G(IBSEG(1))="TOO 2000F" D  D UP^IBTRHLI2("TOO","2000F") Q
 .S LEV="+3,"_SLIEN_","_RESIEN_","
 .S IBFDA(356.22164,LEV,.01)=$P($G(IBSEG(7)),HLCMP,2)  ;TOO02
 .S IBFDA(356.22164,LEV,.02)=$P($G(IBSEG(33)),HLCMP)   ;TOO03-1
 .S IBFDA(356.22164,LEV,.03)=$P($G(IBSEG(33)),HLCMP,2) ;TOO03-2
 .S IBFDA(356.22164,LEV,.04)=$P($G(IBSEG(33)),HLCMP,4) ;TOO03-3
 .S IBFDA(356.22164,LEV,.05)=$P($G(IBSEG(33)),HLCMP,5) ;TOO03-4
 .S IBFDA(356.22164,LEV,.06)=$P($G(IBSEG(33)),HLCMP,9) ;TOO03-5
 .Q
 I $G(IBSEG(1))="PWK 2000F" D  D UP^IBTRHLI2("PWK","2000F") Q
 .S LEV="+3,"_SLIEN_","_RESIEN_","
 .S IBFDA(356.22166,LEV,.01)=$P($G(IBSEG(19)),HLCMP) ;PWK01
 .S IBFDA(356.22166,LEV,.02)=$G(IBSEG(20))           ;PWK02
 .S IBFDA(356.22166,LEV,.03)=$P($G(IBSEG(19)),HLCMP,2) ;PWK03
 .S IBFDA(356.22166,LEV,.04)=$P($G(IBSEG(19)),HLCMP,3) ;PWK04
 .Q
 I $G(IBSEG(1))="PWK 2000E" D  D UP^IBTRHLI2("PWK","2000E") Q
 .S LEV="+2,"_RESIEN_","
 .S CT=$O(^IBT(356.22,RESIEN,11,"A"),-1)+1
 .S IBFDA(356.2211,LEV,.01)=$P($G(IBSEG(19)),HLCMP) ;RPT TYPE CODE
 .S IBFDA(356.2211,LEV,.02)=$G(IBSEG(20))           ;RPT TRANS CODE
 .S IBFDA(356.2211,LEV,.03)=$P($G(IBSEG(19)),HLCMP,2) ;ATTACHMENT CTL #
 .S IBFDA(356.2211,LEV,.04)=$P($G(IBSEG(19)),HLCMP,3) ;ATTACHMENT DESC
 Q
PSL2(TYPE) ;
 N PTR
 I $D(ERROR) Q
 ; I National Drug code type (5-4-2 format) set NDC Code #1
 I $P($G(IBSEG(7)),HLCMP)="N4" D
 .S IBFDA(356.2216,LEV1,12.01)=$P($G(IBSEG(7)),HLCMP,2)
 S PTR=$$CODE($P($G(IBSEG(7)),HLCMP),$P($G(IBSEG(7)),HLCMP,2))
 S IBFDA(356.2216,LEV1,1.02)=PTR   ;SV101-2, SV201-2, SV301-2
 I TYPE'="D" S IBFDA(356.2216,LEV1,1.1)=$P($G(IBSEG(12)),HLCMP,2) ;SV103, SV204
 K ERROR
 D FILE^DIE("","IBFDA","ERROR")
 I $D(ERROR) D ERR^IBTRHLI2($P(IBSEG(1)," ")_" Loop "_$P(IBSEG(1)," ",2),$P(IBSEG(1)," ",2))
 I $P($G(IBSEG(7)),HLCMP,5)="" Q
 S PTR=$$CODE($P($G(IBSEG(7)),HLCMP),$P($G(IBSEG(7)),HLCMP,5))  ;SV101-8, SV202-8, SV301-8
 S IBFDA(356.2216,LEV1,1.03)=PTR
 ; I National Drug code type (5-4-2 format) set NDC Code #2
 I $P($G(IBSEG(7)),HLCMP)="N4" S IBFDA(356.2216,LEV1,12.02)=$P($G(IBSEG(7)),HLCMP,5)
 K ERROR
 D FILE^DIE("","IBFDA","ERROR")
 I $D(ERROR) D ERR^IBTRHLI2($P(IBSEG(1)," ")_" Loop "_$P(IBSEG(1)," ",2),$P(IBSEG(1)," ",2))
 Q
 ;
PSL3(TYPE) ;
 ; this is being created here due to file SCREENing on field 356.2216, 1.01 needs 1.12 set 1st
 K ERROR
 S IBFDA(356.2216,LEV1,1.12)=TYPE  ;Set service line type
 D FILE^DIE("","IBFDA","ERROR")
 I $D(ERROR) D ERR^IBTRHLI2($P(IBSEG(1)," ")_" Loop "_$P(IBSEG(1)," ",2),$P(IBSEG(1)," ",2))
 Q
 ;
CODE(TYPE,CODE) ; obtain Variable Procedure Code pointer
 I $G(RIEN(2)),RIEN(2)'=$G(SLIEN) S SLIEN=RIEN(2),LEV=SLIEN_","_RESIEN_","
 N SCRN,PTR
 S (PTR,SCRN)=""
 I TYPE="HC"!(TYPE="AD") D
 .S PTR=$$FIND1^DIC(81,,"P",CODE,"B",SCRN)
 .I PTR S PTR=PTR_";ICPT("
 I TYPE="ID"!(PTR="ZZ") D
 .S PTR=$$FIND1^DIC(80.1,,"P",CODE,"AB",SCRN)
 .I PTR S PTR=PTR_";ICD0("
 Q PTR
 ;
NTE(IBSEG,RESIEN,ERROR) ;NTE Notes seg
 ;  Input:
 ;  IBSEG,RESIEN
 ;
 ;  Output:
 ;  ERROR
 N LEV,IBFDA,RIEN
 I $G(IBSEG(4))="MSG 2000E" D  Q
 .S LEV=RESIEN_","
 .S IBFDA(1)=$G(IBSEG(3))
 .D WP^DIE(356.22,LEV,12,"","IBFDA","ERROR")
 .I $D(ERROR) D ERR^IBTRHLI2("Problem loading MSG Loop 2000E segment data","2000E")
 .Q
 I $G(IBSEG(4))="MSG 2000F" D  Q
 .S LEV=SLIEN_","_RESIEN_","
 .S IBFDA(1)=$G(IBSEG(3))
 .D WP^DIE(356.2216,LEV,7,"","IBFDA","ERROR")
 .I $D(ERROR) D ERR^IBTRHLI2("Problem loading MSG Loop 2000F segment data","2000F")
 .Q
 Q
  ;
DG1(IBSEG,RESIEN,ERROR,SLIEN) ;
 ;  Input:
 ;  IBSEG,RESIEN,SLIEN
 ;
 ;  Output:
 ;  ERROR
 N CT,LEV,IBFDA,RIEN,LEV1,LEV2,PTR
 I $G(IBSEG(11))="HI 2000F" D  Q
 .D SLCHECK^IBTRHLI1
 .S LEV="+3,"_SLIEN_","_RESIEN_","
 .S IBFDA(356.2316,LEV,.01)=$G(IBSEG(1)) ;HI sequence
 .S IBFDA(356.2316,LEV,.02)=$G(IBSEG(17)) ;Code list qualifier
 .D UP^IBTRHLI2("HI","2000F")
 .I '$G(RIEN(3)) Q
 .S LEV2=RIEN(3)_","_RESIEN_","
 .S PTR=$$CODE1($G(IBSEG(17)),$P($G(IBSEG(3)),HLCMP))
 .S IBFDA(356.2316,LEV2,.03)=PTR ;Code
 .K ERROR
 .D FILE^DIE("","IBFDA","ERROR")
 .I $D(ERROR) D ERR^IBTRHLI2("HI Loop 2000F","2000F") Q
 .Q
 S LEV="+2,"_RESIEN_","
 S IBFDA(356.223,LEV,.01)=$G(IBSEG(17)) ;Code list qualifier
 S IBFDA(356.223,LEV,.03)=$G(IBSEG(5)) ;Date
 D UP^IBTRHLI2("HI","2000E")
 S LEV2=RIEN(2)_","_RESIEN_","
 S PTR=$$CODE1($G(IBSEG(17)),$P($G(IBSEG(3)),HLCMP))
 S IBFDA(356.223,LEV2,.02)=PTR ;Code
 K ERROR
 D FILE^DIE("","IBFDA","ERROR")
 I $D(ERROR) D ERR^IBTRHLI2("HI Loop 2000E","2000E") Q
 Q
CODE1(TYPE,CODE) ; obtain Variable Procedure Code pointer
 N SCRN,PTR
 S (PTR,SCRN)=""
 I TYPE="DR" D
 .S PTR=$$FIND1^DIC(80.2,,"P",CODE,"B",SCRN)
 .I PTR S PTR=PTR_";ICD("
 I TYPE="LOI" D
 .S CODE=$P(CODE,"-")
 .S PTR=$$FIND1^DIC(95.3,,"P",CODE,"B",SCRN)
 E  D
 .S CODE=$E(CODE,1,3)_"."_$E(CODE,4,99)  ;1/31/15 decimals stripped for transmitting
 .S PTR=$$FIND1^DIC(80,,"P",CODE,"AB",SCRN)
 .I PTR S PTR=PTR_";ICD9(" Q
 .; IF xxx.xx is not found, try xxxx.xx if 1st char = 'E'
 .I $E(CODE)'="E" Q
 .S CODE=$E(CODE,1,4)_"."_$E(CODE,5,99)  ; 2/5/15 there are some 4 char 1st dec half of ICD9 codes
 .S PTR=$$FIND1^DIC(80,,"P",CODE,"AB",SCRN)
 .I PTR S PTR=PTR_";ICD9(" Q
 Q PTR
 ;
RXA(IBSEG,RESIEN,ERROR) ;RXA Pharmacy/Treatment Admin seg
 ;  Input:
 ;  IBSEG,RESIEN
 ;
 ;  Output:
 ;  ERROR 
 N LEV,IBFDA,RIEN
 S LEV=RESIEN_","
 S IBFDA(356.22,LEV,7.05)=$G(IBSEG(1)) ;TREATMENT SERIES #
 S IBFDA(356.22,LEV,7.06)=$G(IBSEG(2)) ;TREATMENT COUNT
 S IBFDA(356.22,LEV,7.07)=$P($G(IBSEG(9)),HLREP) ;SUBLUXATION LEVEL CODE#1
 S IBFDA(356.22,LEV,7.08)=$P($G(IBSEG(9)),HLREP,2) ;SUBLUXATION LEVEL CODE#2
 D UP^IBTRHLI2("CR2","2000E")
 Q
 ;
FNDCT(DFN,EVNTDT,RESIEN) ; find matching CT entry in file 356
 ; DFN - file 2 ien
 ; EVNTDT - event date from 356.22/.07
 ; RESIEN - ien of the response in file 356.22
 ;
 ; returns file 356 ien of matching ct entry or null if no match found
 ;
 N CTIEN,EDT,EVTYPE,INPAT,RES,STOPFLG
 S RES=""
 I +$G(DFN)>0,+$G(EVNTDT)>0,+$G(RESIEN)>0 D
 .S EDT=$P(EVNTDT,"-")
 .S INPAT=$S($P($G(^IBT(356.22,RESIEN,0)),U,4)="I":1,1:0)
 .I INPAT S STOPFLG=0 F EVTYPE=1,5 D  Q:STOPFLG
 ..S CTIEN=+$O(^IBT(356,"APTY",DFN,EVTYPE,EDT,"")) I CTIEN>0 S RES=CTIEN,STOPFLG=1
 ..Q
 .I 'INPAT S EVTYPE=2,CTIEN=+$O(^IBT(356,"APTY",DFN,EVTYPE,EDT,"")) S:CTIEN>0 RES=CTIEN
 .Q
 Q RES