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

BYIMIMM4.m

Go to the documentation of this file.
BYIMIMM4 ;IHS/CIM/THL - IMMUNIZATION DATA EXCHANGE;
 ;;2.0;BYIM IMMUNIZATION DATA EXCHANGE;**3,4,5,6,7,8,9**;JUL 11, 2017;Build 22
 ;
 ;-----
MULT ;EP;PROCESS MULTIPLE INBOUND MESSAGES
 K BYIMQUIT
 N AUTOIMP,AUTOADD,DIR,FILE
 S AUTOIMP=1
 S AUTOADD=0
 D PATH^BYIMIMM6
 Q:IPATH=""
 S DIR=$$LIST^%ZISH(IPATH,"*",.DIR)
 S FILE=""
 S XX=0
 F  S XX=$O(DIR(XX)) Q:'XX  S:DIR(XX)]"" FILE(DIR(XX))=""
 S XX=""
 F  S XX=$O(FILE(XX)) Q:XX=""  D
 .S:XX["izdata"&(XX[".dat"!(XX[".hl7")) FILE=XX
 .Q:FILE=""
 .N DA
 .S DA=0
 .F  S DA=$O(^BYIMPARA("FILE",FILE,$$DUZ^BYIMIMM(),DA)) Q:'DA  I $P($G(^BYIMPARA($$DUZ^BYIMIMM(),2,+DA,0)),U,3)="I" S BYIMQUIT=""
 .I $D(BYIMQUIT) K BYIMQUIT Q
 .D I1^BYIMIMM1
 Q
 ;-----
ASITE(BYIMDA) ;EP;ADDITIONAL EXPORT SITES
 Q:'$G(BYIMDA)
 I $O(^BYIMPARA(BYIMDA,3,0)) D AS Q
 K DIR
 S DIR(0)="YO"
 S DIR("A")="Add export/import information for additional states"
 S DIR("B")="NO"
 W !!
 D ^DIR
 K DIR
 Q:'Y
AS N BYIMAS
 S BYIMQUIT=0
 F  D ASACT Q:BYIMQUIT
 Q
 ;-----
ASACT ;ADDITIONAL SITE ACTION
 I '$O(^BYIMPARA(BYIMDA,3,0)) D ASADD
 I '$O(^BYIMPARA(BYIMDA,3,0)) S BYIMQUIT=1 Q
 D ASD
 K DIR
 S DIR(0)="SO^1:Edit site;2:Add site;3:Delete site"
 W !!
 D ^DIR
 K DIR
 I 'Y S BYIMQUIT=1 Q
 I Y=1 D ASEDIT Q
 I Y=2 D ASADD Q
 I Y=3 D ASDEL
 Q
 ;-----
ASSEL ;SELECT ADDITION SITE
 I J=1 S Y=1 D ASSEL1 Q
 K DIR
 S DIR(0)="NO^1:"_J
 S DIR("A")="Select site number"
 W !!
 D ^DIR
 K DIR
ASSEL1 Q:'Y
 Q:'$G(BYIMAS(Y))
 S DA=BYIMAS(Y)
 Q
 ;-----
ASD ;DISPLAY SITES
 W @IOF
 W !!?10,"Additional EXPORT/IMPORT Site Directories"
 W !!?5,"NUM",?10,"SITE/STATE"
 W !?5,"---",?10,"--------------------------------------------------"
 N X0,X1
 S J=0
 S BYIMAS=0
 F  S BYIMAS=$O(^BYIMPARA(BYIMDA,3,BYIMAS)) Q:'BYIMAS  D
 .S X0=$G(^BYIMPARA(BYIMDA,3,BYIMAS,0))
 .S X1=$G(^BYIMPARA(BYIMDA,3,BYIMAS,1))
 .S J=J+1
 .S BYIMAS(J)=BYIMAS
 .W !?5,J,?10,$P(X0,U)
 .W !?15,"OUTBOUND: ",$P(X0,U,2)
 .W !?15," INBOUND: ",$P(X0,U,3)
 Q
 ;-----
ASADD ;ADD SITES
 N BYIMQUIT
 S BYIMQUIT=0
 S J=0
 N BYIMAS
 S J=J+1
 K DIR
 S DIR(0)="FO^1:10"
 S DIR("A")="NEW interface state name"
 S DIR("?")="Enter a name to identify the additional interface state, 3-10 characters"
 W !!
 D ^DIR
 K DIR
 K DIE,DIC,DINUM,DR,DA,DD,DO,DIK,DLAYGO
 I X=""!(X[U) S BYIMQUIT=1 Q
 S (NSITE,BYIMAS(J))=X
 S DA(1)=BYIMDA
 S DIC="^BYIMPARA("_BYIMDA_",3,"
 S DIC(0)="L"
 S:'$D(^BYIMPARA(BYIMDA,3,0)) ^BYIMPARA(BYIMDA,3,0)="^90480.03"
 D FILE^DICN
 I Y<0 S BYIMQUIT=1 Q
 K DIE,DIC,DINUM,DR,DA,DD,DO,DIK,DLAYGO
 N NSDA
 S (NSDA,DA)=+Y
 N X,Y,Z,ZZ
 S X=$P(^BYIMPARA(BYIMDA,0),U,2)
 S V=$S(X["\":"\",1:"/")
 S NSITE=$$LC(NSITE)
 S X=$$LC(X)
 I X["hlrbridge" D  I 1
 .S X=$P(X,"hl7bridge")
 .S:$E(X,$L(X))'=V X=X_V
 .S Y=X_"hl7bridge"_V_NSITE_V_"responses"
 .S X=X_"hl7bridge"_V_NSITE_V_"requests"
 E  D
 .S X=$P(X,"requests")
 .S:$E(X,$L(X))'=V X=X_V
 .S Y=X_NSITE_V_"responses"
 .S X=X_NSITE_V_"requests"
 S $P(^BYIMPARA(BYIMDA,3,NSDA,0),U,2)=X
 S $P(^BYIMPARA(BYIMDA,3,NSDA,0),U,3)=Y
 S $P(^BYIMPARA(BYIMDA,3,NSDA,0),U,4,13)=$P(^BYIMPARA(BYIMDA,0),U,4,13)
 S DA=NSDA
 D ASE1
 Q
 ;-----
ASEDIT ;EDIT
 D ASSEL
 Q:'$G(DA)
ASE1 S DA(1)=BYIMDA
 ;INCLUDE AGE TO EXPORT FOR ADD. SITES
 S DR=".01T;.02T;.03T;.06T;1.03T;1.04T;1.05T;.07T;1.06T;1.07T;6.03T;6.04T;6.05T;1.08T;.15T;6.11T;6.08T;6.01T;6.02T;6.09T;.17T;6.1T;.08T;.1T;6.07T;.14T;.16T"
 S DIE="^BYIMPARA("_BYIMDA_",3,"
 W !!
 D ^DIE
 K DA,DR,DIE
 Q
 ;-----
ASDEL ;DELETE
 D ASSEL
 ;PATCH 8 CR 08549
 ;Q:DA
 Q:'$G(DA)
 ;PATCH 8 END
 S X=^BYIMPARA(BYIMDA,3,DA,0)
 W !?10,$P(X,U)
 K DIR
 S DIR(0)="YO"
 S DIR("A")="Delete export/import site: "_$P(X,U)
 S DIR("B")="NO"
 W !
 D ^DIR
 K DIR
 Q:Y'=1
 S DA(1)=BYIMDA
 S DIK="^BYIMPARA("_BYIMDA_",3,"
 D ^DIK
 K DA,DIK
 Q
 ;-----
CP(DFN) ;EP;DETERMINE VARICELLA EXPOSURE
 ;DFN = PATIENT DFN
 Q:'$D(^BIPC("B",+DFN))
 N BIX,VDAT
 S BIX=0
 F  S BIX=$O(^BIPC("B",DFN,BIX)) Q:'BIX  S:$P($G(^BIPC(BIX,0)),U,3)=12 VDAT=$P(^(0),U,4)
 Q:$L($G(VDAT))'=7
 S VDAT=VDAT+17000000
 S RXA="RXA|0|1|"_VDAT_"|"_VDAT_"|998^No vaccine administered^CVX|999"
 S OBX="OBX|1|CE|59784-9^Disease with presumed immunity ^LN|1|38907003^Varicella infection^SCT||||||F|CR|"
 N LINE
 S LINE=$O(^UTILITY("INH",$J,9999999999),-1)+1
 S X=U_"UTILITY(""INH"","_$J_","_LINE_")"
 S @X=RXA
 S X=U_"UTILITY(""INH"","_$J_","_(LINE+1)_")"
 S @X=OBX
 Q
 ;-----
IMMDUP ;EP;DEDUP IMMUNIZATIONS
 S DIK="^AUPNVIMM("
 S DFN=0
 F  S DFN=$O(^AUPNVIMM("AC",DFN)) Q:'DFN  D
 .K TMP
 .S IEN=0
 .F  S IEN=$O(^AUPNVIMM("AC",DFN,IEN)) Q:'IEN  D
 ..S X=$P($G(^AUPNVIMM(IEN,0)),U,1,3)
 ..S VIS=$P(X,U,3)
 ..Q:'$P(X,U,2)!'X!'VIS
 ..S DAT=$P($G(^AUPNVSIT(VIS,0)),".")
 ..Q:'DAT
 ..S X=$P(X,U,1,2)_U_DAT
 ..I +X=242 S $P(X,U)=148
 ..I +X=243 S $P(X,U)=148
 ..S TMP(X,IEN)=""
 .S X=""
 .F  S X=$O(TMP(X)) Q:X=""  D
 ..S J=0
 ..S IEN=0
 ..F  S IEN=$O(TMP(X,IEN)) Q:'IEN  D
 ...S J=J+1
 ...Q:J<2
 ...W:'$D(ZTQUEUED) !,DFN,?10,J,?15,IEN,?25,X,?45,$P(^AUTTIMM(+X,0),U,3)
 ...M ^BYIMTMP("BYIM IMM DUPS",DA)=^AUPNVIMM(DA)
 ...S DA=IEN
 ...;D ^DIK
 Q
 ;-----
DEXIT ;EP;CLEAN UP AFTER IZAD
 K ^BYIMTMP($J,"BYIM DISP")
 Q
 ;-----
ALOT(LDA,IVDA) ;EP;ACTIVATE LOT NUMBER
 Q:'LDA
 Q:'$D(^AUTTIML(LDA,0))
 S NEWLOT(LDA)=^AUTTIML(LDA,0)
 I '$P(NEWLOT(LDA),U,4) D
 .S $P(NEWLOT(LDA),U,4)=IVDA
 .S ^AUTTIML("C",IVDA,LDA)=""
 S $P(^AUTTIML(LDA,0),U,3)=0
 S $P(^AUTTIML(LDA,0),U,4)=IVDA
 Q
 ;-----
ILOT(LDA) ;EP;INACTIVATE LOT NUMBER
 Q:'LDA
 Q:'$D(^AUTTIML(LDA,0))
 S:$G(NEWLOT(LDA))]"" ^AUTTIML(LDA,0)=$G(NEWLOT(LDA))
 K NEWLOT
 Q
 ;-----
LV(DFN,IVDA,LOTDA) ;EP;CALCULATE LAST V IMM FOR PAT
 Q:'$G(DFN)!'$G(IVDA)!'$G(LOTDA)
 N XX,YY,ZZ
 S XX=$O(^AUPNVIMM("AC",DFN,9999999999),-1)
 Q:'XX
 S XX0=$G(^AUPNVIMM(XX,0))
 Q:+XX0'=IVDA
 Q:$P(XX0,U,5)
 S $P(^AUPNVIMM(XX,0),U,5)=LOTDA
 Q
 ;-----
MAN(MAN) ;EP;CHECK IMMUNIZATION MAN.
 Q:MAN=""
 S:MAN["\T\" MAN=$P(MAN,"\T\")_"&"_$P(MAN,"\T\",2)
 N X,Y,Z
 S X=MAN
 X ^%ZOSF("UPPERCASE")
 S MAN=Y
 S MANA=$P(MAN,U)
 S MANN=$P(MAN,U,2)
 S MANDA=$O(^AUTTIMAN("B",MANN,0))
 Q:MANDA
 S X=MANN
 S DIC="^AUTTIMAN("
 S DIC(0)="L"
 S DIC("DR")=".02////"_MANA
 D FILE^DICN
 I Y>0 S MANDA=+Y
 Q
 ;-----
LOT(LOT,MAN,IVDA) ;EP;EVALUATE LOT AND MANUFACTURER DATA
 S LOTDA=""
 S MANDA=""
 Q:$G(LOT)=""
 D:MAN]"" MAN^BYIMIMM4(MAN)
 S X=LOT
 X ^%ZOSF("UPPERCASE")
 S LOT=Y
 S LOTDA=$O(^AUTTIML("B",LOT,0))
 I LOTDA D ALOT(LOTDA,IVDA) Q
 S X=LOT
 S DIC="^AUTTIML("
 S DIC(0)="L"
 S DIC("DR")=".02////"_$G(MANDA)_";.03////1;.04////"_IVDA
 D FILE^DICN
 Q:Y<0
 S LOTDA=+Y
 D ALOT(LOTDA,IVDA)
 Q
 ;-----
LOG(FILE,ACT,DFNCNT,IMMCNT,NODFNCNT,NEWIMCNT,ADDIMCNT,PATH,DFN) ;EP;LOG AUTO IMPORT FILES THAT HAVE BEEN PROCESSED
 ;FILE     = NAME OF FILE IMPORTED OR EXPORTED
 ;ACT      = ACTION - 'I'MPORT OR 'E'XPORT
 ;DFNCNT   = NUMBER OF PATIENTS
 ;IMMCNT   = NUMBER OF IMMUNIZATIONS
 ;NODFNCNT = NUMBER OF PATIENTS FOR WHOM THERE IS NO PATIENT MATCH
 ;NEWIMCNT = NUMBER OF NEW IMMUNIZATIONS
 ;ADDIMCNT = NUMBER OF NEW IMMUNIZATIONS ADDED TO V IMMUNIZATIONS
 ;PATH     = DRIVE/DIRECTORY FILE SENT TO
 Q:$G(FILE)=""!($G(ACT)="")
 S X=FILE
 K DIE,DIC,DINUM,DR,DA,DD,DO,DIK,DLAYGO
 S DA(1)=$$DUZ^BYIMIMM()
 S DIC="^BYIMPARA("_DA(1)_",2,"
 S DIC(0)="L"
 S DIC("DR")=".02////"_DT_";.03////"_ACT_";.04////"_$G(DFNCNT)_";.05////"_$G(IMMCNT)
 S:$G(NODFNCNT) DIC("DR")=DIC("DR")_";.06////"_NODFNCNT
 S:$G(NEWIMCNT) DIC("DR")=DIC("DR")_";.07////"_NEWIMCNT
 S:$G(ADDIMCNT) DIC("DR")=DIC("DR")_";.08////"_ADDIMCNT
 S:$G(PATH)]"" DIC("DR")=DIC("DR")_";.09////"_PATH
 D FILE^DICN
 K DIE,DIC,DINUM,DR,DA,DD,DO,DIK,DLAYGO
 N BYIMACT
 S BYIMACT=$S(ACT="I":"imported from",1:"exported to")
 ;-----
BULLETIN ;EP;CREATE EXPORT/IMPORT BULLETIN
 N %X,%Y,X,XMB,XMDT,XMDUZ,Y1
 S XMB="BYIM EXPORT/IMPORT MESSAGE"
 S XMB(1)="The file '"_FILE_"' was "_BYIMACT_" the State Immunization Registry on "_$$HTE^XLFDT($H)
 S XMDUZ=.5
 D ^XMB
 Q
 ;-----
EXPBULL(BYIMHFNM,DEST,BYIMHDIR) ;EP;EXPORT FILE CREATION FAILED
 N %X,%Y,X,XMB,XMDT,XMDUZ,Y1
 S XMB="BYIM EXPORT FILE FAILED"
 S XMB(1)=BYIMHFNM
 S XMB(2)=$P($G(^INRHD(+DEST,0)),U)
 S XMB(3)=BYIMHDIR
 S XMDUZ=.5
 D ^XMB
 Q
 ;-----
LC(X) ;LOWERCASE
 S X=$TR(X,"ABCDEFGHIJKLMNOPQRSTUVWXYZ ","abcdefghijklmnopqrstuvwxyz_")
 Q X
 ;-----
QPATH(BYIMDA) ;EP;QUERY DIRECTORIES
 Q
 Q:'$G(BYIMDA)
 N V,X,Y,Z
 S X=$P($G(^BYIMPARA(BYIMDA,0)),U,2)
 S X=$$LC(X)
 S V=$S(X["\":"\",1:"/")
 I X["hl7bridge" D  I 1
 .S X=$P(X,"hl7bridge")
 .S:$E(X,$L(X))'=V X=X_V
 .S Y=X_"hl7bridge"_V_"queries"
 .S Z=X_"hl7bridge"_V_"qresponses"
 E  D
 .S X=$P(X,"requests")
 .S:$E(X,$L(X))'=V X=X_V
 .S Y=X_"queries"
 .S Z=X_"qresponses"
 S $P(^BYIMPARA(BYIMDA,1),U)=Y
 S $P(^BYIMPARA(BYIMDA,1),U,2)=Z
 Q
 ;-----
LOGDFN ;EP;LOG PATIENTS INCLUDED IN EXPORT
 N DFN,TYPE
 S TYPE="E"
 S DFN=0
 F  S DFN=$O(^BYIMTMP("LOG",DFN)) Q:'DFN  D
 .D LOGD(DFN,TYPE)
 .K ^BYIMTMP("LOG",DFN)
 Q
 ;-----
LOGD(DFN,TYPE) ;EP;LOG EACH EXPORTED OR IMPORTED IMM
 N IMM,X,Y,Z
 S:$G(TYPE)="" TYPE="E"
 ;S DFNCNT=$G(DFNCNT)+1
 S IMM=0
 F  S IMM=$O(^BYIMTMP("LOG",DFN,IMM)) Q:'IMM  D
 .I $G(BYIMALL)'=2,$D(^BYIMEXP("D",IMM)) Q
 .Q:$G(BYIMMU2)
 .K DIE,DIC,DINUM,DR,DA,DD,DO,DIK,DLAYGO
 .S DIC="^BYIMEXP("
 .S DIC(0)="L"
 .S DIC("DR")=".02////"_DT_";.03////"_IMM_";.04////"_TYPE_";.05////"_$G(XQY)_";.06////"_$G(BYIMALL)
 .S X=DFN
 .D FILE^DICN
 .K DIE,DIC,DINUM,DR,DA,DD,DO,DIK,DLAYGO
 Q
 ;-----
DFN(UIF) ;FIND PATIENT DFN
 N X,Y,Z,LOC,HRN,DFN
 S X=$P($P($G(^INTHU(UIF,3,2,0)),"|",4),U)
 S LOC=$E(X,1,6)
 S HRN=+$E(X,7,12)
 Q:'LOC!'HRN ""
 S LOC=$O(^AUTTLOC("C",LOC,0))
 Q:'LOC ""
 S DFN=""
 S X=0
 F  S X=$O(^AUPNPAT("D",HRN,X)) Q:'X!DFN  S Y=0 F  S Y=$O(^AUPNPAT("D",HRN,X,Y)) Q:'Y!DFN  S:Y=LOC DFN=X
 Q DFN
 ;-----
HFSA(DEST,BYIMHDIR,BYIMHFNM) ;EP - export from this destination
 ;PATCH 8 CR 08549 CHANGES TO CREATE MULTIPLE STATE FILES
 I '$G(DEST) D  Q
 .S ^BYIMTMP("EXP FAIL",$H,"NO DEST")=BYIMHDIR_U_BYIMHFNM_U_DUZ
 .S BYIMFAIL=$G(BYIMFAIL)+1
 I '$D(^INLHDEST(DEST)) D  Q
 .S ^BYIMTMP("EXP FAIL",$H,DEST,"NO MESSAGE")=BYIMHDIR_U_BYIMHFNM_U_DUZ
 .S BYIMFAIL=$G(BYIMFAIL)+1
 S BYIMDUZ=$$DUZ^BYIMIMM()
 K ^BYIMTMP("DEST")
 M ^BYIMTMP("DEST",BYIMDUZ,DEST)=^INLHDEST(DEST)
 N X
 S X=0
 F  S X=$O(^BYIMPARA(BYIMDUZ,3,X)) Q:'X  I X'=BYIMDUZ M ^BYIMTMP("DEST",X,DEST)=^INLHDEST(DEST)
 N BYIMH,BYIMU
 S STATE=0
 F  S STATE=$O(^BYIMTMP("DEST",STATE)) Q:'STATE  D HFSA1(DEST,STATE,BYIMHFNM)
 ;PATCH 8 CR 08549 END
 Q
 ;-----
HFSA1(DEST,STATE,BYIMHFNM) ;PROCESS EACH EXPORT FILE
 N XX,X0,X1,X6,PATH,FE,PI,ESSN
 ;MOVE ASSET CALL TO BYIMIMM5
 D ASSET^BYIMIMM5(STATE)
 ;PATCH 8 CR 08385 - allow 'hl7' or 'dat' file extension
 S BYIMHFNM=$P(BYIMHFNM,".")_"."_$S($G(FE)]"":FE,1:"dat")
 ;PATCH 8 CR 08385 END
 S Y=$$OPEN^%ZISH(PATH,BYIMHFNM,"W")
 I Y D  Q
 .D EXPBULL(BYIMHFNM,DEST,PATH)
 .S ^BYIMTMP("EXP FAIL",$H,DEST,"NO OPEN")=PATH_U_BYIMHFNM_U_DUZ
 .S BYIMFAIL=$G(BYIMFAIL)+1
 S BYIMH=""
 F  S BYIMH=$O(^BYIMTMP("DEST",STATE,DEST,0,BYIMH)) Q:BYIMH=""  D
 .S BYIMU=0
 .F  S BYIMU=$O(^BYIMTMP("DEST",STATE,DEST,0,BYIMH,BYIMU)) Q:'BYIMU  D
 ..K ^BYIMTMP("ORIG",BYIMU)
 ..M ^BYIMTMP("ORIG",BYIMU)=^INTHU(BYIMU)
 ..I $G(^INTHU(BYIMU,3,1,0))["VXU^V04" D  Q:'DFN
 ...S DFN=$$DFN(BYIMU)
 ...I 'DFN D  Q
 ....K ^INLHDEST(DEST,0,BYIMH,BYIMU)
 ....K ^BYIMTMP("DEST",STATE,DEST,0,BYIMH,BYIMU)
 ...S ^BYIMTMP("BYIMIMM4",BYIMU)=DFN
 ...D REFUSAL^BYIMSEG1(DFN,BYIMU)
 ..D LP(BYIMU,STATE)
 ..K ^INTHU(BYIMU)
 ..M ^INTHU(BYIMU)=^BYIMTMP("ORIG",BYIMU)
 ..K ^INLHDEST(DEST,0,BYIMH,BYIMU)
 ..K ^BYIMTMP("DEST",STATE,DEST,0,BYIMH,BYIMU)
 K ^BYIMTMP("BYIMIMM4")
 K ^BYIMTMP("ORIG")
 D ^%ZISC
 D LOGDFN:'$G(BYIMTEST)
 Q
 ;-----
LP(BYIMUIEN,AS)       ;EP - loop through UIF and set to file
 ;INCLUDE AGE TO EXPORT CHECK FOR ADD. SITES
 I 'AGE,$P(^BYIMPARA(BYIMDUZ,0),U,6) Q:$$AGECHK^BYIMIMM5(BYIMUIEN)
 I IO["\\" D
 .F J=1:1:$L(IO,"\\") S X=$P(IO,"\\",J)_"\"
 .S IO=$E(X,1,$L(X)-1)
 I IO["//" D
 .F J=1:1:$L(IO,"//") S X=$P(IO,"//",J)_"/"
 .S IO=$E(X,1,$L(X)-1)
 I $G(PI),$G(^INTHU(BYIMUIEN,3,1,0))["VXU^V04",$$PI(BYIMUIEN) Q
 N BYIMUDA
 S BYIMUDA=0
 F  S BYIMUDA=$O(^INTHU(BYIMUIEN,3,BYIMUDA)) Q:'BYIMUDA  D
 .S SEGX=$G(^INTHU(BYIMUIEN,3,BYIMUDA,0))
 .Q:SEGX=""
 .I SEGX["PID|",$G(ESSN),SEGX["SSA^SS"!($P(SEGX,"|",20)]"") D ESSN(SEGX)
 .I SEGX["PID|"!(SEGX["IN1|"),$G(DFN),SEGX["MEDICARE"!(SEGX["MCR^MC") D MCR(SEGX)
 .I SEGX'["|CR|" D
 ..S BYIMUDA=BYIMUDA+1
 ..S SEGX=SEGX_$G(^INTHU(BYIMUIEN,3,BYIMUDA,0))
 ..Q:SEGX["|CR|"
 ..S BYIMUDA=BYIMUDA+1
 ..S SEGX=SEGX_$G(^INTHU(BYIMUIEN,3,BYIMUDA,0))
 .Q:SEGX'["|CR|"
 .;PATCH 8 CR 08781 - CPT CODE
 .I SEGX["RXA|",$G(CPT)]"" D CPT(CPT)
 .;PATCH 8 CR 08781 END
 .I SEGX["FHS|" S $P(SEGX,"|",9)=BYIMHFNM,$P(SEGX,"|",11)=$E($TR($H,","),1,7)
 .I SEGX["BHS|" S $P(SEGX,"|",11)=$E($TR($H,","),1,7)
 .I '$G(IN1),SEGX["IN1|"!(SEGX["IN2|") Q
 .S:"|MSH|FHS|BHS|BTS|FTS|"'[("|"_$E(SEGX,1,3)_"|") SEGX=$TR(SEGX,"\&")
 .Q:$E(SEGX,1,4)'?2U1UN1"|"
 .I "|BTS|FTS|"'[("|"_$E(SEGX,1,3)_"|") D AE
 .U IO W $P(SEGX,"|CR|"),!
 Q
 ;-----
AE ;PROCESS ADDITIONAL SITE EXPORT FILE
 I $E(SEGX,1,4)="PID|",$G(ESSN),SEGX["SSA^SS" D ESSN(SEGX)
 D SET
 Q
 ;-----
SET ;CUSTOMIZE MSH SEGMENT
 N A,B,X,Y,Z
 S SEG=$E(SEGX,1,3)
 S X=0
 F  S X=$O(XX(SEG,X)) Q:'X  D
 .S Y=0
 .F  S Y=$O(XX(SEG,X,Y)) Q:'Y  S Z=XX(SEG,X,Y) D:Z]""
 ..I SEG="MSH",X=11,'$G(BYIMTEST) Q
 ..I SEG="RXA",X=6,Y=1,$P(SEGX,"|",7),$P(SEGX,"|",7)<100 Q
 ..S B=X
 ..S:"MSHFHSBHS"'[SEG B=X+1
 ..S A=$P(SEGX,"|",B)
 ..S $P(A,U,Y)=Z
 ..S $P(SEGX,"|",B)=A
 Q
 ;-----
PI(UIEN) ;ELIMINATE HL7 MESSAGE IF PATIENT PRIVACY NOT ON FILE
 N HRN,LOC,X,Y,Z,XX
 S DFN=+$G(^BYIMTMP("BYIMIMM4",UIEN))
 I 'DFN S DFN=+$$DFN(UIEN)
 Q:'DFN 1
 Q:$P($G(^BIP(DFN,0)),U,24) 0
 Q 1
 ;-----
CPT(CPT) ;ADJUST RXA-5 FOR CPT
 ;PATCH 8 CR 08781 - CPT CODE
 N X,Y,Z
 S X=$P(SEGX,"|",6)
 Q:CPT=123
 I CPT=0 S X=$P(X,"~")
 I CPT=1,$P(X,"~",2)]"" S X=$P(X,"~",2)
 I CPT=2 S X=$P(X,"~",1,2)
 ;I CPT=1 S X=$P(X,"~")
 ;I CPT=2,$P(X,"~",2)="" S X=$P(X,"~",2)
 ;I CPT=3,$P(X,"~",3)]"" S X=$P(X,"~",3)
 ;I CPT=12 S X=$P(X,"~",1,2)
 ;I CPT=13 S X=$P(X,"~")_"~"_$P(X,"~",3)
 ;I CPT=23 S X=$P(X,"~",2)_"~"_$P(X,"~",3)
 S $P(SEGX,"|",6)=X
 Q
 ;-----
ESSN(SEGX) ;REMOVE SSN
 N J,X,Y,Z,XX
 S X=$P(SEGX,"|",4)
 S XX=""
 F J=1:1 S Y=$P(X,"~",J) Q:Y=""  I Y["SSA^SS" S XX=$P(X,"~",1,J-1) S:$P(X,"~",J+1)]"" XX=XX_"~"_$P(X,"~",J+1,99)
 S $P(SEGX,"|",4)=XX
 S $P(SEGX,"|",20)=""
 Q
 ;-----
MCR(SEGX) ;REMOVE SSN
 N J,X,Y,Z,XX
 S X=$P(SEGX,"|",4)
 S XX=""
 F J=1:1 S Y=$P(X,"~",J) Q:Y=""  I Y["MEDICARE"!(Y["MCR^MC") S XX=$P($P(X,"~",J),U) S:XX[$P($G(^DPT(DFN,0)),U,9) XX=$P(X,"~",1,J-1)_"~"_$P(X,"~",J+1,99)
 S $P(SEGX,"|",4)=XX
 S:SEGX["PID|" $P(SEGX,"|",20)=""
 Q
 ;-----