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

APCSHLOC.m

Go to the documentation of this file.
APCSHLOC ;cmi/flag/maw - APCL Cert HL7 Export 5/12/2010 9:26:17 AM
 ;;2.0;IHS PCC SUITE;**6**;MAY 14, 2009;Build 11
 ;
 ;
 ;ihs/cmi/maw - 9/8/2010 added new segments based on patch 5 requirements
 ;
CERT(LABDA,TYPE) ;EP - for certification
 D BATCH(.HLPARM,TYPE)
 N APCSDA,APCSCNT,APCSREC
 S APCSCNT=0
 S APCSDA=0 F  S APCSDA=$O(LABDA(APCSDA)) Q:'APCSDA  D
 . S APCSCNT=APCSCNT+1
 . D NEWMSG(.HLMSTATE,.HLPARM,APCSDA,"ORU","R01",TYPE)
 I $G(HLMSTATE("IEN")) D GL(HLMSTATE("IEN"),TYPE)  ;ihs/cmi/maw 11/23/2010 added $G
 Q
 ;
BATCH(HLPARM,TYP) ;-- start the message batch here
 S HLPARM("COUNTRY")="USA"
 S HLPARM("VERSION")="2.5.1"
 I '$$NEWBATCH^HLOAPI(.HLPARM,.HLMSTATE,.ERROR) D  Q
 . S ERR=$G(ERR)
 Q
 ;
NEWMSG(HLST,HLPM,RC,MTYPE,EVNTTYPE,TYP) ;EP
 N ARY,HLQ,APPARMS,HLMSGIEN,HLECH,HLFS,ERR,WHO
 N LN,HL1,HRCN,FLD,LP,X,LN
 S LN=0
 S HLPM("MESSAGE TYPE")=MTYPE
 S HLPM("EVENT")=EVNTTYPE
 ;S HLPM("VERSION")="2.5.1"
 I '$$ADDMSG^HLOAPI(.HLST,.HLPM,.ERR) D  Q
 .S ERR=$G(ERR)
 S HLFS=HLPM("FIELD SEPARATOR")
 S HLECH=HLPM("ENCODING CHARACTERS")
 S HL1("ECH")=HLECH
 S HL1("FS")=HLFS
 S HL1("Q")=""
 S HL1("VER")=HLPM("VERSION")
 ;Create segments
 ;
 I TYPE="CERT" D
 . N PAT,VST
 . S PAT=$P($G(^AUPNVLAB(RC,0)),U,2)
 . S VST=$P($G(^AUPNVLAB(RC,0)),U,3)
 . I '$D(ERR) D SFTCERT
 . I '$D(ERR) D PIDCERT(.RC,PAT)
 . I '$D(ERR) D ORCCERT(.RC,PAT,VST)
 . I '$D(ERR) D OBRCERT(.RC,PAT,VST)
 . I '$D(ERR) D OBXCERT(.RC,PAT,VST)
 . I '$D(ERR) D SPMCERT(.RC,PAT,VST)
 I '$D(ERR) D
 .; Define sending and receiving parameters
 .S APPARMS("SENDING APPLICATION")="RPMS-ILI^2.16.840.1.113883.3.72.7.1^HL7"
 .S HLMSTATE("HDR","RECEIVING APPLICATION")="PH Application^2.16.840.1.113883.3.72.7.3^HL7"
 .S APPARMS("SENDING FACILITY")="RPMS Facility^2.16.840.1.113883.3.72.7.2^HL7"
 .S HLMSTATE("HDR","RECEIVING FACILITY",1)="PH Facility"
 .S HLMSTATE("HDR","RECEIVING FACILITY",2)="2.16.840.1.113883.3.72.7.4"
 .S HLMSTATE("HDR","RECEIVING FACILITY",3)="HL7"
 .S HLMSTATE("HDR","MESSAGE TYPE")="ORU"
 .S HLMSTATE("HDR","EVENT")="R01"
 .S HLMSTATE("HDR","MESSAGE STRUCTURE")=MTYPE_"_"_EVNTTYPE  ;ihs/cmi/maw for cert
 .S APPARMS("MSH22")="PHLabReport-Ack^^2.16.840.1.114222.4.10.3^ISO"
 .S APPARMS("ACCEPT ACK TYPE")="AL"  ;Commit ACK type
 .S APPARMS("APP ACK RESPONSE")="AACK^APCLSHL"  ;Callback when 'application ACK' is received
 .S APPARMS("ACCEPT ACK RESPONSE")="CACK^APCLSHL"  ;Callback when 'commit ACK' is received
 .S APPARMS("APP ACK TYPE")="AL"  ;Application ACK type
 .S APPARMS("QUEUE")="ILI ADT"   ;Incoming QUEUE
 .S WHO("RECEIVING APPLICATION")="CDC"
 .S WHO("FACILITY LINK NAME")="ILI"
 .I '$$SENDONE^HLOAPI1(.HLST,.APPARMS,.WHO,.ERR) D
 .. S ERR=$G(ERR)
 Q
 ;
AACK ; EP - Application ACK callback - called when AA, AE or AR is received.
 N DATA,AACK,XQAID,XQDATA,XQA,XQAMSG,MSGID
 Q:'$G(HLMSGIEN)
 S MSGID=$P($G(^HLB(+HLMSGIEN,0)),U)
 S AACK=$G(^HLB(HLMSGIEN,4))
 I $P(AACK,U,3)'["|AA|" D
 .S XQAMSG="ILI message "_MSGID_" did not receive a correct application ack."
 .S XQAID="ILI,"_MSGID_","_50
 .S XQDATA=$P(AACK,U,3)
 .S XQA("G.APCS ILI")=""
 .D SETUP^XQALERT
 Q
 ;
CACK ; EP - Commit ACK callback - called when CA, CE or CR is received.
 N CACK,XQAID,XQAMSG,XQA,XQDATA,MSGID
 S MSGID=$P($G(^HLB(+HLMSGIEN,0)),U)
 S CACK=$G(^HLB(HLMSGIEN,4))
 I $P(CACK,U,3)'["|CA|" D
 .S XQAMSG="ILI message "_MSGID_" did not receive a correct commit acknowledgement."
 .S XQAID="ILI,"_MSGID_","_50
 .S XQDATA=$P(CACK,U,3)
 .S XQA("G.APCS ILI")=""
 .D SETUP^XQALERT
 Q
 ;
ERR ;
 Q
 ;
SFTCERT ;-- create the SFT segment
 N SFT11,SFT2,SFT3,SFT4,SFT61
 N PACK,INSTDT,VERI
 S SFT11="IHS"
 S SFT2="5.2"
 S SFT3="IHS Laboratory"
 S SFT4="5.2.1027"
 S PACK=$O(^DIC(9.4,"B","IHS LABORATORY",0))
 I PACK D
 . S VERI=$O(^DIC(9.4,PACK,22,"B","5.2",0))
 . I VERI D
 .. S INSTDT=$$HLD($P($G(^DIC(9.4,PACK,22,VERI,0)),U,2))
 S SFT61=$S($G(INSTDT):INSTDT,1:20000101)
 D SET(.ARY,"SFT",0)
 D SET(.ARY,SFT11,1)
 D SET(.ARY,SFT2,2)
 D SET(.ARY,SFT3,3)
 D SET(.ARY,SFT4,4)
 D SET(.ARY,SFT61,6)
 S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 Q
 ;
PIDCERT(R,P) ;EP
 N PID,HRN,NM,ETHCI,ETHC,ETHT,ETHCC,PID34,PID35,RC,RCI,RT,PID341,PID342,PID343
 S HLQ=HL1("Q")
 S PID=$$EN^VAFHLPID(P,"2,3,5,6,7,8,10,11,13,22,",1)
 Q:PID=""
 S HRN=$$HRN^AUPNPAT(P,DUZ(2))
 D SET(.ARY,"PID",0)
 D SET(.ARY,1,1)
 D SET(.ARY,HRN,3,1)  ; Patient HRN
 S PID341="MPI"
 S PID342="2.16.840.1.113883.19.3.2.1"
 S PID343="ISO"
 S PID35="MR"
 S RCI=$$GET1^DIQ(2,P,.06,"I")
 S RC=$S(RCI:$$GET1^DIQ(10,RCI,3),1:"")
 S RCT=$S(RCI:$$GET1^DIQ(10,RCI,.01),1:"")
 D SET(.ARY,PID341,3,4,1)
 D SET(.ARY,PID342,3,4,2)
 D SET(.ARY,PID343,3,4,3)
 D SET(.ARY,PID35,3,5)
 N DOB,SEX,NM,ADD,CTY,ST,STI,ZIP,CTRY,PH
 S DOB=$$HLD($P($G(^DPT(P,0)),U,3))
 S SEX=$P($G(^DPT(P,0)),U,2)
 S LNM=$P($P($G(^DPT(P,0)),U),",")
 S FNM=$P($P($P($G(^DPT(P,0)),U),",",2)," ")
 S ADD=$P($G(^DPT(P,.11)),U)
 S CTY=$P($G(^DPT(P,.11)),U,4)
 S STI=$P($G(^DPT(P,.11)),U,5)
 S ST=$S(STI:$P($G(^DIC(5,STI,0)),U,2),1:"")
 S ZIP=$P($G(^DPT(P,.11)),U,6)
 S CTRY="USA"
 S PH=$P($G(^DPT(P,.13)),U)
 S PH=$TR(PH,"-")
 S PH=$TR(PH,"(")
 S PH=$TR(PH,")")
 D SET(.ARY,LNM,5,1)
 D SET(.ARY,FNM,5,2)
 D SET(.ARY,DOB,7)
 D SET(.ARY,SEX,8)
 D SET(.ARY,ADD,11,1)
 D SET(.ARY,CTY,11,3)
 D SET(.ARY,ST,11,4)
 D SET(.ARY,ZIP,11,5)
 D SET(.ARY,CTRY,11,6)
 D SET(.ARY,"M",11,7)
 D SET(.ARY,PH,13,1)
 D SET(.ARY,"PRN",13,2)
 D SET(.ARY,$E(PH,1,3),13,6)
 D SET(.ARY,$E(PH,4,10),13,7)
 D SET(.ARY,RC,10,1)
 D SET(.ARY,RCT,10,2)
 D SET(.ARY,"HL70005",10,3)
 S ETHCI=$O(^DPT(P,.06,"B",0))
 S ETHCI=$P($G(^DPT(P,.06,+ETHCI,0)),U)
 I ETHCI D
 . S ETHC=$P($G(^DIC(10.2,ETHCI,0)),U,2),ETHT=$P($G(^DIC(10.2,ETHCI,0)),U)
 . D SET(.ARY,ETHC,22,1)
 . D SET(.ARY,ETHT,22,2)
 . D SET(.ARY,"HL70189",22,3)
 S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 Q
 ;
ORCCERT(R,P,V) ;-- setup the cert ORC segment
 N ID,FN,AANI,AAUI,AAUIT,STR,CTY,ST,ZIP,PH,AT,ORG,ORPI,APCSNAME,STA,LNM,FNM
 S ORPI=$P($G(^AUPNVLAB(R,12)),U,2)
 Q:'ORPI
 S ID=$$GET1^DIQ(200,ORPI,41.99)
 S LNM=$P($P($G(^VA(200,ORPI,0)),U),",")
 S FNM=$P($P($P($G(^VA(200,ORPI,0)),U),",",2)," ")
 S AANI=$$GET1^DIQ(4,DUZ(2),.01)
 S STR=$$GET1^DIQ(4,DUZ(2),1.01)
 S CTY=$$GET1^DIQ(4,DUZ(2),1.03)
 S ST=$$GET1^DIQ(4,DUZ(2),.02)
 S ZIP=$$GET1^DIQ(4,DUZ(2),1.04)
 S STA=$$GET1^DIQ(4,DUZ(2),99)
 S PH=$P($G(^DIC(4,DUZ(2),2,1,0)),U,3)
 D SET(.ARY,"ORC",0)
 D SET(.ARY,"RE",1)
 D SET(.ARY,ID,12,1)
 D SET(.ARY,LNM,12,2)
 D SET(.ARY,FNM,12,3)
 D SET(.ARY,AANI,12,9,1)
 D SET(.ARY,"2.16.840.1.113883.19.4.6",12,9,2)
 D SET(.ARY,"ISO",12,9,3)
 D SET(.ARY,AANI,21,1)
 D SET(.ARY,"L",21,2)
 D SET(.ARY,AANI,21,6,1)
 D SET(.ARY,"2.16.840.1.113883.19.4.6",21,6,2)
 D SET(.ARY,"ISO",21,6,3)
 D SET(.ARY,"XX",21,7)
 D SET(.ARY,ID,21,10)
 D SET(.ARY,STR,22,1)
 D SET(.ARY,CTY,22,3)
 D SET(.ARY,ST,22,4)
 D SET(.ARY,ZIP,22,5)
 D SET(.ARY,"B",22,7)
 D SET(.ARY,PH,23,1)
 D SET(.ARY,"PRN",23,2)
 D SET(.ARY,$E(PH,1,3),23,6)
 D SET(.ARY,$E(PH,4,10),23,7)
 D SET(.ARY,STR,24,1)
 D SET(.ARY,CTY,24,3)
 D SET(.ARY,ST,24,4)
 D SET(.ARY,ZIP,24,5)
 D SET(.ARY,"B",24,7)
 S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 Q
 ;
OBRCERT(R,P,V) ;-- setup the cert OBR segment
 N ACC,ACCN,LOINCI,LOINC,LOINCT,ALT,ALTT,OBS,OBSI,RESI,RCI,ID,FN,AANI,RES,RESS,IDEN,IDENT,ORPI,APCSNAME,IDENI,OBR31,LNM,FNM,LOINCO,LOINCOI,LOINCOT,SVC
 S ORPI=$P($G(^AUPNVLAB(R,12)),U,2)
 Q:'ORPI
 S LNM=$P($P($G(^VA(200,ORPI,0)),U),",")
 S FNM=$P($P($P($G(^VA(200,ORPI,0)),U),",",2)," ")
 S ACC=$$GET1^DIQ(9000010.09,R,.06)
 S ACCN="Lab"
 S SVC=$$GET1^DIQ(9000010,V,.07,"I")
 S LOINCI=$$GET1^DIQ(9000010.09,R,1113,"I")
 S LOINCO=$$GET1^DIQ(95.3,LOINCI,34)
 S LOINCOI=$S(LOINCO]"":$P(LOINCO,"-"),1:"")
 S LOINC=$$GET1^DIQ(9000010.09,R,1113)
 S LOINCOT=$S($G(LOINCOI):$$GET1^DIQ(95.3,LOINCOI,81),1:"")
 S LOINCT=$S(LOINCI:$$GET1^DIQ(95.3,LOINCI,81),1:"")
 S ALT=$$GET1^DIQ(9000010.09,R,.01,"I")
 S ALTT=$$GET1^DIQ(9000010.09,R,.01)
 S OBSI=$$GET1^DIQ(9000010.09,R,1201,"I")
 S OBS=$S(OBSI:$$HLD(OBSI),1:"")
 S RCI=$$GET1^DIQ(9000010.09,R,1601)
 S ID=$$GET1^DIQ(200,ORPI,41.99)
 S AANI=$$GET1^DIQ(4,DUZ(2),.01)
 S RESI=$$GET1^DIQ(9000010.09,R,1212,"I")
 S RES=$S(RESI:$$HLD(RESI),1:OBS)
 S RESS="F"
 S OBR31=$$BLDOBR31(V)
 I OBR31="",SVC="I" D
 . N NEWV
 . S NEWV=$$FNDH(V)
 . S OBR31=$$BLDOBR31(NEWV)
 S IDENI=$O(^AUPNVPOV("AD",V,0))
 S IDEN=$S(IDENI:$$GET1^DIQ(9000010.07,IDENI,.01),1:"")
 S IDENT=$S(IDENI:$P($G(^ICD9(IDENI,0)),U,3),1:"")
 D SET(.ARY,"OBR",0)
 D SET(.ARY,1,1)
 D SET(.ARY,ACC,3,1)
 D SET(.ARY,ACCN,3,2)
 D SET(.ARY,"2.16.840.1.113883.19.3.1.6",3,3)
 D SET(.ARY,"ISO",3,4)
 D SET(.ARY,$S($G(LOINCO)]"":LOINCO,1:LOINC),4,1)
 D SET(.ARY,$S($G(LOINCOT)]"":LOINCOT,1:LOINCT),4,2)
 D SET(.ARY,"LN",4,3)
 D SET(.ARY,ALT,4,4)
 D SET(.ARY,ALTT,4,5)
 D SET(.ARY,"L",4,6)
 D SET(.ARY,OBS,7)
 D SET(.ARY,RCI,13)
 D SET(.ARY,ID,16,1)
 D SET(.ARY,LNM,16,2)
 D SET(.ARY,FNM,16,3)
 D SET(.ARY,AANI,16,9,1)
 D SET(.ARY,"2.16.840.1.113883.19.4.6",16,9,2)
 D SET(.ARY,"ISO",16,9,3)
 D SET(.ARY,RES,22)
 D SET(.ARY,RESS,25)
 S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 Q
 ;
FNDH(VP) ;-- find H visit for this I visit
 N IVR,IDAT,DFN,ITYP,ILOC,FND,OLD,HDFN,DVD,HOSP,VDH,SVD,HDFN,HVR,HDAT,HTYP,HLOC,INPD,DCD,FND
 S IVR=$G(^AUPNVSIT(VP,0))
 S IDAT=+$P(IVR,U),DFN=$P(IVR,U,5),ITYP=$P(IVR,U,3),ILOC=$P(IVR,U,6),(FND,OLD,HDFN)=0,DVD=$P(IDAT,".") K HOSP
 ; Check for hospitalization prior to (or on same day) as the "I" visit
 S VDH=(9999999-DVD),SVD=(VDH-1)_".9999",HDFN=""
 F  S SVD=$O(^AUPNVSIT("AAH",DFN,SVD)) Q:SVD'=+SVD!($P(SVD,".")<VDH)  D
 . S HDFN=0 F  S HDFN=$O(^AUPNVSIT("AAH",DFN,SVD,HDFN)) Q:HDFN'=+HDFN  I HDFN]"",$D(^AUPNVSIT(HDFN,0)),'$P(^(0),U,11),$P(^(0),U,9) D
 ..S HVR=^AUPNVSIT(HDFN,0)
 ..S HDAT=+$P(HVR,U),HTYP=$P(HVR,U,3),HLOC=$P(HVR,U,6)
 ..S INPD="",INPD=$S(ITYP="C":$O(^AUPNVCHS("AD",HDFN,"")),1:$O(^AUPNVINP("AD",HDFN,"")))
 ..;Q:INPD=""  ;ihs/cmi/maw at this point we dont care if there is a discharge
 ..;S:ITYP="C" DCD=$P(^AUPNVCHS(INPD,0),U,7)
 ..;S:ITYP'="C" DCD=$P(^AUPNVINP(INPD,0),U)
 ..;I DCD'<DVD S FND=FND+1,HOSP(HDFN)=""
 ..S FND=FND+1
 ..S HOSP(HDFN)=""
 Q $S(FND=1:$O(HOSP("")),1:VP)
 ;
BLDOBR31(VP) ;-- build obr 31
 N PV,IDENI,IDEN,IDENT,CNT,VALUE
 S CNT=0
 S VALUE=""
 S PV=0 F  S PV=$O(^AUPNVPOV("AD",VP,PV)) Q:'PV  D
 . S IDENI=$P($G(^AUPNVPOV(PV,0)),U)
 . S IDEN=$$GET1^DIQ(9000010.07,PV,.01)
 . S IDENT=$P($G(^ICD9(IDENI,0)),U,3)
 . S CNT=CNT+1
 . D SET(.ARY,IDEN,31,1,,CNT)
 . D SET(.ARY,IDENT,31,2,,CNT)
 . D SET(.ARY,"I9",31,3,,CNT)
 . S $P(VALUE,"~",CNT)=IDEN_U_IDENT_U_"I9"
 Q $G(VALUE)
 ;
OBXCERT(R,P,V) ;-- setup the cert OBX segment
 N LOINCI,LOINC,LOINCT,VAL,UNIT,RL,RH,ABN,OBSS,OBS,ANA,ORG,ORGT,OAANI,OST,OCTY,OST,OZIP,OSTA,STYP
 S LOINCI=$$GET1^DIQ(9000010.09,R,1113,"I")
 S LOINC=$$GET1^DIQ(9000010.09,R,1113)
 S LOINCT=$S(LOINCI:$$GET1^DIQ(95.3,LOINCI,81),1:"")
 S STYP=$S($$GET1^DIQ(95.3,LOINCI,37)]"":$$GET1^DIQ(95.3,LOINCI,37),1:"NM")
 S VAL=$$GET1^DIQ(9000010.09,R,.04)
 S UNIT=$$GET1^DIQ(9000010.09,R,1101)
 S RL=$$GET1^DIQ(9000010.09,R,1104)
 S RH=$$GET1^DIQ(9000010.09,R,1105)
 I RL="",RH]"" S RL=RH
 I RL]"",RH]"" S RL=RL_"-"_RH
 S ABN=$$GET1^DIQ(9000010.09,R,.05)
 S OBSS="F"
 S OBS=$S($$GET1^DIQ(9000010.09,R,1201,"I"):$$HLD($$GET1^DIQ(9000010.09,R,1201,"I")),1:"")
 S ANA=$S($$GET1^DIQ(9000010.09,R,1212,"I"):$$HLD($$GET1^DIQ(9000010.09,R,1212,"I")),1:OBS)
 S OAANI=$$GET1^DIQ(4,DUZ(2),.01)
 S OSTR=$$GET1^DIQ(4,DUZ(2),1.01)
 S OCTY=$$GET1^DIQ(4,DUZ(2),1.03)
 S OST=$$GET1^DIQ(4,DUZ(2),.02)
 S OZIP=$$GET1^DIQ(4,DUZ(2),1.04)
 S OSTA=$$GET1^DIQ(4,DUZ(2),99)
 D SET(.ARY,"OBX",0)
 D SET(.ARY,1,1)
 D SET(.ARY,STYP,2)
 D SET(.ARY,LOINC,3,1)
 D SET(.ARY,LOINCT,3,2)
 D SET(.ARY,"LN",3,3)
 D SET(.ARY,1,4)
 D SET(.ARY,VAL,5)
 D SET(.ARY,UNIT,6,1)
 D SET(.ARY,UNIT,6,2)
 D SET(.ARY,"UCUM",6,3)
 D SET(.ARY,RL,7)
 D SET(.ARY,ABN,8)
 D SET(.ARY,OBSS,11)
 D SET(.ARY,OBS,14,1)
 D SET(.ARY,"",17)
 D SET(.ARY,ANA,19)
 D SET(.ARY,OAANI,23,1)
 D SET(.ARY,"L",23,2)
 D SET(.ARY,"CLIA",23,6,1)
 D SET(.ARY,"2.16.840.1.113883.19.4.6",23,6,2)
 D SET(.ARY,"ISO",23,6,3)
 D SET(.ARY,"XX",23,7)
 D SET(.ARY,OSTA,23,10)
 D SET(.ARY,OSTR,24,1)
 D SET(.ARY,OCTY,24,3)
 D SET(.ARY,OST,24,4)
 D SET(.ARY,OZIP,24,5)
 D SET(.ARY,"B",24,7)
 S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 Q
 ;
SPMCERT(R,P,V) ;--setup the cert SPM segment
 N STI,STT,ST
 S STI=$$GET1^DIQ(9000010.09,R,1103,"I")
 I STI D
 . S STT=$$GET1^DIQ(9000010.09,R,1103)
 . S ST=$P($G(^LAB(61,STI,0)),U,2)
 D SET(.ARY,"SPM",0)
 D SET(.ARY,$G(ST),4,1)
 D SET(.ARY,$G(STT),4,2)
 D SET(.ARY,"SNM",4,3)
 D SET(.ARY,$G(STT),4,4)
 D SET(.ARY,$G(ST),4,5)
 D SET(.ARY,"HL70070",4,6)
 D SET(.ARY,"20080131",4,7)
 D SET(.ARY,"2.5.1",4,8)
 S X=$$ADDSEG^HLOAPI(.HLST,.ARY,.ERR)
 Q
 ;
SET(ARY,V,F,C,S,R) ;EP
 D SET^HLOAPI(.ARY,.V,.F,.C,.S,.R)
 Q
 ; Fix for non-working ZIPCODE Field trigger in File 2
FIXZIP(DFN,ZIP) ;EP
 Q:$G(ZIP) ZIP
 Q $$GET1^DIQ(2,DFN,.116)
 ;
HLD(FDT) ;-- convert to HL7 date
 I $G(FDT)="" Q ""
 S D=$$FMTHL7^XLFDT(FDT)
 Q D
 ;
GL(IN,TYP) ;-- write out the batch to a global for saving in APCSSLAB
 K ^APCSTMP($J)
 N BDA,BDO,HLODAT,MSH,MSGP,MSG
 S APCSCNT=0
 S MSG=$P($G(^HLB(IN,0)),U,2)
 S BDA=0 F  S BDA=$O(^HLB(IN,3,BDA)) Q:'BDA  D
 . S MSH=""
 . S MSGP=$P($G(^HLB(IN,3,BDA,0)),U)
 . S BDO=0 F  S BDO=$O(^HLB(IN,3,BDA,BDO)) Q:'BDO  D
 .. S HLOMSH=$G(^HLB(IN,3,BDA,BDO))
 .. S MSH=MSH_HLOMSH
 . D SETGL(MSH)
 . D REST(MSG,MSGP)
 D WRITE(TYP,APCSCNT)
 Q
 ;
REST(M,MP) ;-- write out the remainder of the segments to the global
 N MDA,DATA,MCNT
 S MCNT=0
 S MDA=0 F  S MDA=$O(^HLA(M,2,MP,1,MDA)) Q:'MDA  D
 . S DATA=$G(^HLA(M,2,MP,1,MDA,0))
 . Q:DATA=""
 . D SETGL(DATA)
 Q
 ;
SETGL(D) ;-- set the temp global
 S APCSCNT=APCSCNT+1
 S ^APCSTMP($J,APCSCNT)=D
 Q
 ;
WRITE(T,COUNT) ; use XBGSAVE to save the temp global (APCSDATA) to a delimited
 ; file that is exported to the IE system
 N XBGL,XBQ,XBQTO,XBNAR,XBMED,XBFLT,XBUF,XBFN
 S XBGL="APCSTMP",XBMED="F",XBQ="N",XBFLT=1,XBF=$J,XBE=$J
 S XBNAR=TYP_"_HL7 EXPORT"
 S APCSASU=$P($G(^AUTTLOC($P(^AUTTSITE(1,0),U),0)),U,10)  ;asufac for file name
 S XBFN=TYP_"HL7_"_APCSASU_"_"_$$DATE(DT)_$TR($H,",","")_".txt"
 S XBS1="CERTIFICATION LAB EXPORT"
 ;
 D ^XBGSAVE
 ;
 I XBFLG'=0 D
 . I XBFLG(1)="" W:'$D(ZTQUEUED) !!,TYP_" HL7 file successfully created",!!
 . I XBFLG(1)]"" W:'$D(ZTQUEUED) !!,TYP_" HL7 file NOT successfully created",!!
 . W:'$D(ZTQUEUED) !,"File was NOT successfully transferred to IHS/CDC",!,"you will need to manually ftp it.",!
 . W:'$D(ZTQUEUED) !,XBFLG(1),!!
 K ^APCSTMP($J),APCSCNT
 Q
DATE(D) ;EP
 Q (1700+$E(D,1,3))_$E(D,4,5)_$E(D,6,7)
 ;