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

BYIMIMM.m

Go to the documentation of this file.
BYIMIMM ;IHS/CIM/THL - IMMUNIZATION DATA EXCHANGE;
 ;;2.0;BYIM IMMUNIZATION DATA EXCHANGE;**3,4,5,6,7,8,9**;JUL 11, 2017;Build 22
 ;
 ;----
ENV ;EP;
 F X="XPO1","XPZ1","XPZ2","XPI1" S XPDDIQ(X)=0
 N BYIMDA
 S BYIMDA=+^AUTTSITE(1,0)
 I '$D(^BYIMPARA(+BYIMDA,0)) D
 .K DIE,DIC,DINUM,DR,DA,DD,DO,DIK,DLAYGO
 .S DIC="^BYIMPARA("
 .S DIC(0)="L"
 .S (X,DINUM)=+^AUTTSITE(1,0)
 .D FILE^DICN
 .K DIE,DIC,DINUM,DR,DA,DD,DO,DIK,DLAYGO
 .S BYIMDA=+Y
 I $D(^BYIMPARA(BYIMDA)),'$D(^BYIMPARA(BYIMDA,0)) D
 .S ^BYIMPARA(BYIMDA,0)=BYIMDA
 .S ^BYIMPARA("B",BYIMDA,BYIMDA)=""
 Q
 ;-----
DE ;EP;IMMUNIZATION EXPORT
 N BYIMJOB,BYIMY,BYIMRMSG,BYIMY,BYIMX,DA,DIC,DIE,DIK,DR,DIR,D19,DD19,DATE,DDATE,DDDATE,DATE19,DEST,ENC,EVDT,FACILITY,BYIMFILE,INA,MSG,NUM,OPATH,IPATH,ZTDESC,ZTDTC,ZTIO,ZTQUEUED,ZTRTN,ZTSAVE,VALMBCK,XPDDIQ,BYIMCNT
 N AGE,AGE19,MSGCNT,DFNCNT,IMMCNT,BYIMQUIT
 N BYIMDATE,DEND
 D PATH
 I OPATH="" D NOPATH Q
 K BYIMQUIT
 I '$D(ZTQUEUED) D  Q:$D(BYIMQUIT)
 .N WRITING,DE
 .S DE=""
 .D READY:$O(^BYIMPARA($$DUZ(),"LAST EXPORT",0))
 .I $D(WRITING) D  Q:$D(BYIMQUIT)
 ..D RESTART
DATE ;EP;SELECT EXPORT DATE
 K BYIMQUIT
 N DATE,X,Y,Z,BYIMDUZ
 S Y=2,BYIMDUZ(Y)=DUZ(2),BYIMALL=1,BYIMADM=1
 I '$D(^BYIMPARA($$DUZ(),0)),+$G(^AUTTSITE(1,0)) D
 .S X=+^AUTTSITE(1,0)
 .I $D(^BYIMPARA(X,0)) S Y=2,DUZ(Y)=X
 I '$D(^BYIMPARA($$DUZ(),0)) D
 .S X=0
 .F  S X=$O(^BYIMPARA(X)) Q:'X  I $D(^BYIMPARA(X,0)) S Y=2,DUZ(Y)=X Q
 Q:'$D(^BYIMPARA($$DUZ(),0))
 D DATE19
 S (DATE,D19)=0
 S X=9999999999
 F  S X=$O(^BYIMPARA($$DUZ(),"LAST EXPORT",X),-1) Q:'X!DATE  D
 .S:$P(^BYIMPARA($$DUZ(),"LAST EXPORT",X),U)&$P(^(X),U,2) (DATE,D19)=X
 I DATE D D1 Q:$D(BYIMQUIT)
 I 'DATE D
 .S (DATE,D19)=$S(YEARS=19:DATE19,1:DATE99)
 .Q:$D(ZTQUEUED)
 .W !!,"The date of the last Immunization export is not on file."
 .W !,"The export will include all Children 0-18 years of age."
 I '$D(ZTQUEUED) D  Q:$D(BYIMQUIT)
 .D ALL^BYIMRT
 .W !!,"Evaluation of immunizations for export to the State Immunization"
 .W !,"registry may take several minutes."
 .S DIR(0)="YO"
 .S DIR("A")="Do you want to proceed"
 .S DIR("B")="NO"
 .W !
 .D ^DIR
 .K DIR
 .I Y'=1 S BYIMQUIT=""
 K ^BYIMTMP($J,"BYIM EXP")
 N X,Y,Z,ZZ,MSGCNT,DFN,BYIMQUIT,XX
 S XX=$P($H,",",2)
 ;PATCH 8
 D PATH
 I OPATH="" D NOPATH Q
 S:'$G(BYIMFAIL) BYIMFAIL=""
 ;END PATCH 8
 D FN
 S ^BYIMTMP("BYIMFILE")=BYIMFILE
 I $D(^BYIMPARA($$DUZ(),"LAST EXPORT")) D LE Q
 I '$D(^BYIMPARA($$DUZ(),"LAST EXPORT")) D NLE Q
 Q
 ;-----
DEX ;EP;TO CREATE ACTUAL HL7 MESSAGES
 ;M ^TMP("BYIMTMP")=^BYIMTMP
 D HEADER
 S:'$G(BYIMALL) BYIMALL=1
 S:'$G(BYIMADM) BYIMADM=1
 S:'$G(DDDATE) DDDATE=""
 K ^BYIMTMP("LOG")
 S (MSGCNT,DFN,DFNCNT,IMMCNT)=0
 F  S DFN=$O(^BYIMTMP($J,"BYIM EXP",DFN)) Q:'DFN  D
 .;PATCH 8 CR 08549 CHANGES TO CREATE MULTIPLE STATE FILES
 .;INCLUDE ALL PATIENT - SCREEN AT FILE CREATION
 .;I $P(^BYIMPARA($$DUZ(),0),U,10),'$P($G(^BIP(DFN,0)),U,24) Q
 .;PATCH 8 CR 08549 END
 .S DA=$O(^BYIMTMP($J,"BYIM EXP",DFN,0))
 .Q:'DA
 .W:'$D(ZTQUEUED) "/"
 .S MSG=$$V04(DA,BYIMALL,BYIMADM,DDDATE)
 .Q:MSG'["Message Created Successfully"
 .S MSGCNT=MSGCNT+1
 .S DFNCNT=DFNCNT+1
 .S IMMCNT=IMMCNT+$$IMMCNT(DFN)
 .S ^BYIMTMP("LOG",DFN)=""
 S ^BYIMTMP("NUM")=MSGCNT_U_DFNCNT_U_IMMCNT
 S BYIMJOB=$J
 K ^BYIMTMP($J,"BYIM EXP")
 S XX=$P($H,",",2)-XX
ZIS S ZTRTN="HFSA^BYIMIMM"
 S ZTDESC="IMMUNIZATION INTERFACE"
 F X="BYIM*","DFN*","MSG*","IMM*" S ZTSAVE(X)=""
 S ZTIO=""
 S ZTDTC=$H
 D ^%ZTLOAD
 I $G(X)[U D  Q
 .W !!,"The export has been terminated."
 .D PAUSE
 .S BYIMQUIT=""
 .D RES1
OUT I '$D(ZTQUEUED) D
 .W !!?10,IMMCNT," immunizations for ",MSGCNT," ",CHILD," 0-",YEARS
 .W !?10,"were evaluated in "
 .N M,S
 .S M=XX\60
 .S S=XX#60
 .I M]"" W M," minutes"
 .I S]"" W ", ",S," seconds"
 .W "."
 .D PATH
 .I OPATH="" D NOPATH Q
 .W !!?10,"The file '",BYIMFILE,"' will now be created in the"
 .W !?10,"'",OPATH,"' directory.  This may take several minutes."
 .W !!?10,"It can be retrieved from this directory for transfer"
 .W !?10,"to the State registry."
 .D PAUSE
 Q
 ;-----
HFSA ;EP;TO PROCESS EXPORT
 H 60
 S:'$G(BYIMTEST)&'$D(^BYIMPARA($$DUZ(),"LAST EXPORT",DT)) ^BYIMPARA($$DUZ(),"LAST EXPORT",DT)=$H
 N READY
 S READY=""
 D READY
 I $D(BYIMQUIT) K BYIMQUIT G HFSA
 S DEST=$O(^INRHD("B","HL IHS IZV04 FRAMEWORK",0))
 N PRI
 S PRI=+$O(^INLHDEST(DEST,""))
 D HFSA^BYIMIMM6(DEST,PRI)
 S NUM=$G(^BYIMTMP("NUM"))
 S DFNCNT=$P(NUM,U,2)
 S IMMCNT=$P(NUM,U,3)
 S NUM=+NUM
 N J,X,Y
 S J=0
 S X=""
 F  S X=$O(^INLHDEST(DEST,PRI,X)) Q:X=""  D
 .S Y=0
 .F  S Y=$O(^INLHDEST(DEST,PRI,X,Y)) Q:'Y  S J=J+1
 G:J<NUM HFSA
 D FOOTER
 D:$G(BYIMTEST) CLEAN^BYIMIMM5
 H 30
 S ^TMP($J,"BYIM","CLEAN","BEFORE")=$D(^INLHDEST(DEST))
 D CLEAN
 S ^TMP($J,"BYIM","CLEAN","AFTER")=$D(^INLHDEST(DEST))
HFSARES ;EP;RESTART EXPORT WHEN FILE NOT CREATED 
 S DEST=$O(^INRHD("B","HL IHS IZV04 FRAMEWORK",0))
 N PRI
 S PRI=+$O(^INLHDEST(DEST,""))
 S NUM=$G(^BYIMTMP("NUM"))
 K ^BYIMTMP("NUM"),^("BYIMFILE")
 S DFNCNT=$P(NUM,U,2)
 S IMMCNT=$P(NUM,U,3)
 S NUM=+NUM
 D PATH
 I OPATH="" D NOPATH Q
 S:'$G(BYIMFAIL) BYIMFAIL=""
 D FN
 D HFSA^BYIMIMM4(DEST,OPATH,BYIMFILE)
 I $G(BYIMFAIL)=1 H 10 G HFSARES
 I $G(BYIMFAIL)>1 S:'$G(BYIMTEST) $P(^BYIMPARA($$DUZ(),"LAST EXPORT",DT),U,2)="ExportFail" Q
 S:'$G(BYIMTEST) $P(^BYIMPARA($$DUZ(),"LAST EXPORT",DT),U,2)=$H
 D LOG^BYIMIMM4(BYIMFILE,"E",DFNCNT,IMMCNT,,,,OPATH)
 K ^BYIMTMP("NUM")
 K ^BYIMTMP("BYIMFILE")
 ;PATCH 8 CR 08549 PROCESS FILES FOR MULTIPLE STATES
 ;D ADDEX
 ;PATCH 8 CR 08549 END
 Q
 ;-----
READY ;EP;
 N X,Y,Z
 S X=""
 F  S X=$O(^INLHSCH(0,X)) Q:X=""!$D(BYIMQUIT)  D
 .S Y=0
 .F  S Y=$O(^INLHSCH(0,X,Y)) Q:'Y!$D(BYIMQUIT)  D
 ..S:$G(^INTHU(Y,3,1,0))["V04" BYIMQUIT=""
 I '$D(BYIMQUIT) D  Q
 .S DEST=$O(^INRHD("B","HL IHS IZV04 FRAMEWORK",0))
 .I '$D(READY),$D(^INLHDEST(+DEST)) D  Q
 ..W:'$D(ZTQUEUED) !!,"Immunization data file creation still in process."
 ..S WRITING=""
 ..H 4
 .Q:$D(ZTQUEUED)!$D(DE)
 .N NUM
 .S NUM=+$G(^BYIMTMP("NUM"))
 .H 2
 .W !!,"The Immunization data export file is ready for transmission"
 .W !,"to the state immunization registry."
 .H 4
 .N J,X,Y,NUM,PRI
 .S PRI=0
 .S J=0
 .S X=""
 .F  S X=$O(^INLHDEST(DEST,PRI,X)) Q:X=""  D
 ..S Y=0
 ..F  S Y=$O(^INLHDEST(DEST,PRI,X,Y)) Q:'Y  S J=J+1
 .S $P(^BYIMTMP("NUM"),U)=J
 Q:$D(ZTQUEUED)
 W !!,"Immunization data export still in process."
 S J=0
 S X=""
 F  S X=$O(^INLHSCH(0,X)) Q:X=""  D
 .S Y=0
 .F  S Y=$O(^INLHSCH(0,X,Y)) Q:'Y  D
 ..S:$G(^INTHU(Y,3,1,0))["V04" J=J+1
 W " (",J,")"
 H 2
 Q
 ;-----
V04(BYIMVST,BYIMALL,BYIMADM,DDDATE)        ;this is the unsolicited Imm record
 I 'BYIMVST Q $$MSG("VST")
 D PATH
 S BYIMPAT=$P($G(^AUPNVSIT(BYIMVST,0)),U,5)
 S INDA=BYIMPAT
 S INDA(9000010,1)=BYIMVST
 S INDA(2,1)=BYIMPAT
 S INDA("BYIMALL")=$G(BYIMALL)
 S INDA("BYIMADM")=$G(BYIMADM)
 S INDA("DDDATE")=$G(DDDATE)
 S BYIMPAR="HL IHS IZV04 OUT PARENT"
 D ^INHF(BYIMPAR,.INDA)
 D EOJ
 Q $$MSG(INHF)
 ;-----
 S DEST=$O(^INRHD("B","HL IHS IZV04 FRAMEWORK",0))
 K ^INLHDEST(+DEST)
 D NOW^%DTC
 S INA("EVDT")=%
 S EVDT="INA(""EVDT"")"
 S INA("ENC")="^~\&"
 S ENC="INA(""ENC"")"
 S INA("FACILITY")=$P($G(^DIC(4,$$DUZ(),0)),U)
 S FACILITY="INA(""FACILITY"")"
 L +^INTHU(0):DTIME
 S INDA=$P(^INTHU(0),U,3)
 D ^INHF("HL IHS IZV04 OUT HEADER PARENT",.INDA,.INA)
 L -^INTHU(0)
 D EOJ
 Q
 ;-----
 S INDA=$P(^INTHU(0),U,3)+1
 D ^INHF("HL IHS IZV04 OUT FOOTER PARENT",.INDA,.INA)
 D EOJ
 Q
 ;-----
EOJ ;EP;kills variables
 K INDA,BYIMPAT,BYIMVST,BYIMVAIN,BYIMADT
 Q
 ;-----
MSG(BYIMMVAR)        ;-- return message defining status
 I BYIMMVAR="PAT" S BYIMRMSG="Patient Not Passed In, Message Not Created"
 I BYIMMVAR="VST" S BYIMRMSG="Visit Not Passed In, Message Not Created"
 I BYIMMVAR="VLAB" S BYIMRMSG="VLAB Not Passed In, Message Not Created"
 I BYIMMVAR="MFL" S BYIMRMSG="Mstr File Not Passed In, Message Not Created"
 I BYIMMVAR=0 S BYIMRMSG="Message Not Created, problem with GIS call"
 I BYIMMVAR S BYIMRMSG=BYIMMVAR_U_"Message Created Successfully"
 Q $G(BYIMRMSG)
 ;-----
IMZIS S ZTRTN="HFSARES^BYIMIMM"
 S ZTDESC="IMMUNIZATION INTERFACE"
 S ZTIO=""
 S ZTSAVE("BYIMJOB")=""
 S ZTDTC=$H
 D ^%ZTLOAD
 Q
 ;-----
STRIP(Z) ;REMOVE CONTROLL CHARACTERS
 N I
 F I=1:1:$L(Z) I (32>$A($E(Z,I))) S Z=$E(Z,1,I-1)_" "_$E(Z,I+1,999)
 Q Z
 ;-----
BACK S VALMBCK="R"
 Q
 ;-----
MPORT ;EP;run the import package utility
 I $O(^INXPORT(""))="" D  Q
 . W !,"Global ^INXPORT missing, please restore and the global."
 S BYIMIT=$O(^INXPORT(""))
 S BYIMIST=$O(^INXPORT(BYIMIT,""))
 S BYIMIPK=$O(^INXPORT(BYIMIT,BYIMIST,""))
 W !,"Importing GIS "_$G(BYIMIT)_" Supplement "_$G(BYIMIPK)
 W ", developing site "_$G(BYIMIST)
 D ^BYIMPORT
 W !,"Finished Importing GIS Supplement "
 K BYIMIT,BYIMIST,BYIMIPK
 Q
 ;-----
RESTART ;EP;
 S DIR(0)="YO"
 W !!,"Do you want to restart the export?"
 S DIR("B")="NO"
 D ^DIR
 K DIR
 I Y'=1 S BYIMQUIT="" Q
 D HFSARES
 Q:'$G(BYIMFAIL)
 D RES1
 D PATH
 I OPATH="" D NOPATH Q
 D FN
 S Y=$$DEL^%ZISH(OPATH,BYIMFILE)
 Q
 ;-----
RES1 ;CLEAR CURRENT EXPORT QUEUE
 S DEST=$O(^INRHD("B","HL IHS IZV04 FRAMEWORK",0))
 K ^INLHDEST(DEST)
 N X,Y,Z,BYIMQUIT
 S X=""
 F  S X=$O(^INLHSCH(0,X)) Q:X=""!$D(BYIMQUIT)  D
 .S Y=0
 .F  S Y=$O(^INLHSCH(0,X,Y)) Q:'Y!$D(BYIMQUIT)  D
 ..I $G(^INTHU(Y,3,1,0))["V04" K ^INLHSCH(0,X,Y)
 Q
 ;-----
DATE19 ;SET AGE FOR EXPORT
 N Y
 S Y=$P($G(^BYIMPARA($$DUZ(),0)),U,6)
 S YEARS=$S('Y:19,Y=1:65,1:99)
 S CHILD=$S('Y:"Children",1:"Patients")
 S (AGE,AGE19)=19*10000
 S DATE19=DT-(19*10000)
 S AGE65=65*10000
 S DATE65=DT-(65*10000)
 S AGE99=99*10000
 S DATE99=DT-(99*10000)
 S D19=$S(YEARS=19:DATE19,YEARS=65:DATE65,1:DATE99)
 Q
 ;-----
ADDEX ;EP;PROCESS ADDITIONAL EXPORT SITES
 ;PATCH 8 CR 08627 CORRECT 'COPY' FOR MULTI-SITES
 ;PATCH 8 CR 08627 END
 Q
 ;-----
LE ;PROCESS SEQUENTIAL EXPORT
 S:'$G(DDDATE) DDDATE=""
 S:'$G(DEND) DEND=9999999
 S D19=D19-.01
 F  S D19=$O(^AUPNVSIT("APCIS",D19)) Q:'D19!(D19>DEND)  D
 .S DA=0
 .F  S DA=$O(^AUPNVSIT("APCIS",D19,DA)) Q:'DA  D
 ..S X=$G(^AUPNVSIT(DA,0))
 ..S DFN=$P(X,U,5)
 ..Q:'DFN
 ..Q:$D(^BYIMTMP($J,"BYIM EXP",DFN))
 ..Q:$G(^DPT(DFN,.35))!'$O(^AUPNPAT(DFN,41,0))!'$G(^AUPNPAT(DFN,0))
 ..S X=$G(^DPT(DFN,0))
 ..Q:X=""
 ..Q:X["PATIENT,ERROR"!(X["ERROR,PATIENT")!(X["DEMO,PAT")
 ..;FILTER OUT KIDS WITHOUT PERMANENT NAME
 ..Q:X["BABY "!(X["BABY ")
 ..;PATCH 8 CR 08549 CHANGES TO CREATE MULTIPLE STATE FILES
 ..;Q:$P($G(^BIP(DFN,0)),U,24)=0
 ..S:'$G(BYIMALL) BYIMALL=1
 ..S:'$G(BYIMADM) BYIMADM=1
 ..S:'$G(DDATE) DDATE=""
 ..;PATCH 8 CR 08549 END
 ..I YEARS=19 Q:$P(X,U,3)<DATE19
 ..I YEARS=65 Q:$P(X,U,3)<DATE19&($P(X,U,3)>DATE65)
 ..I BYIMALL,BYIMALL'=2!(BYIMADM&BYIMADM'=2) Q:'$$NEW^BYIMIMM6(DFN,BYIMALL,BYIMADM,DDDATE)
 ..S ^BYIMTMP($J,"BYIM EXP",DFN,DA)=""
 ..W:'$D(ZTQUEUED) "."
 I '$O(^BYIMTMP($J,"BYIM EXP",0)) D  Q
 .S BYIMFILE="NoImmsToExp_"_$P($G(^AUTTLOC($$DUZ(),0)),U,10)_"_"_(DT+17000000)_"_"_$P($H,",",2)_".dat"
 .S:'$G(BYIMTEST) $P(^BYIMPARA($$DUZ(),"LAST EXPORT",DT),U)=$H,$P(^(DT),U,2)=$H
 .S DFNCNT=0
 .S IMMCNT=0
 .D PATH^BYIMIMM6
 .D LOG^BYIMIMM4(BYIMFILE,"E",DFNCNT,IMMCNT,,,,OPATH)
 .S:'$G(BYIMTEST) $P(^BYIMPARA($$DUZ(),"LAST EXPORT",DT),U,2)="NoImmsToExp"
 .Q:$D(ZTQUEUED)
 .W !!,"No Immunizations found that need to be exported."
 .D PAUSE
 D DEX
 S Y=2,DUZ(Y)=BYIMDUZ(2)
 Q
 ;-----
NLE ;PROCESS FIRST EXPORT
 N BYIMALL
 S BYIMALL=2
 S BYIMADM=2
 F  S D19=$O(^DPT("ADOB",D19)) Q:'D19  D
 .S DFN=0
 .F  S DFN=$O(^DPT("ADOB",D19,DFN)) Q:'DFN  D
 ..Q:$G(^DPT(DFN,.35))!'$G(^AUPNPAT(DFN,0))
 ..S X=$G(^DPT(DFN,0))
 ..Q:X["PATIENT,ERROR"!(X["ERROR,PATIENT")!(X["DEMO,PAT")!($E(X,1,2)="ZZ")!$P(X,U,19)
 ..S X=$O(^AUPNVSIT("AC",DFN,9999999999),-1)
 ..Q:'X
 ..Q:'$G(^AUPNVSIT(X,0))
 ..Q:+^AUPNVSIT(X,0)<DATE
 ..Q:$O(^BYIMTMP($J,"BYIM EXP",DFN,0))
 ..S ^BYIMTMP($J,"BYIM EXP",DFN,X)=""
 ..W:'$D(ZTQUEUED) "."
 D DEX
 S Y=2,DUZ(Y)=BYIMDUZ(2)
 Q
 ;-----
D1 ;PROCESS WHEN DATE IDENTIFIED
 S (Y,DDDATE)=DATE
 X ^DD("DD")
 S DDATE=Y
 S Y=DT-AGE
 X ^DD("DD")
 S DD19=Y
 Q:$D(ZTQUEUED)
 W @IOF
 W !!,"The last Immunization export ran on: ",DDATE
 I YEARS=19 D
 .W !,"Children 18 and under were born after: ",DD19
 W !!,"This export will include: ",!
 I YEARS=19 D
 .W !?5,"Children 18 and under"
 I YEARS=65 D
 .W !?5,"Children 18 and under and"
 .W !?5,"Adults.. 65 and over"
 I YEARS=99 D
 .W !?5,"All patients"
 W !!,"who have had a visit since the last export."
 W !,"You can enter another date for the export."
 S DIR(0)="DO"
 S DIR("A")="Export Immunizations given since "_DDATE
 S DIR("B")=DDATE
 W !
 D ^DIR
 K DIR
 I 'Y S BYIMQUIT="" Q
 S (BYIMDATE,DATE,D19)=Y
 S Y=DT
 X ^DD("DD")
 S DEND=Y
 S DIR(0)="DO"
 S DIR("A")="Exclude Immunizations given after "_DEND
 S DIR("B")=DEND
 W !
 I D19=DT S Y=DT
 I D19<DT D ^DIR
 K DIR
 I 'Y S BYIMQUIT="" Q
 S DEND=Y
 Q
 ;-----
PATH ;EP;SET PATH
 D PATH^BYIMIMM6
 Q
 ;-----
NOPATH ;EP;NO PATH MESSAGE
 D NOPATH^BYIMIMM6
 Q
 ;-----
PAUSE ;EP;FOR PAUSE READ
 D PAUSE^BYIMIMM6
 Q
 ;-----
CLEAN ;CLEAN OUT MESSAGES WITH NO RXA SEGMENT, BLANK RXR AND OBX SEGMENTS
 N DEST,QUIT,X,Y,Z,XX,ZZ
 S DEST=$O(^INRHD("B","HL IHS IZV04 FRAMEWORK",0))
 Q:'DEST
 S X=""
 F  S X=$O(^INLHDEST(DEST,X)) Q:'X  D
 .S Y=""
 .F  S Y=$O(^INLHDEST(DEST,X,Y)) Q:Y=""  D
 ..S Z=0
 ..F  S Z=$O(^INLHDEST(DEST,X,Y,Z)) Q:'Z  D
 ...S QUIT=0
 ...S ZZ=0
 ...F  S ZZ=$O(^INTHU(Z,3,ZZ)) Q:'ZZ  S XX=^(ZZ,0) D
 ....I XX["RXA" S QUIT=1 Q
 ....I XX["RXR||" K ^INTHU(Z,3,ZZ,0) Q
 ....I XX["OBX|"&(XX["V00") K ^INTHU(Z,3,ZZ,0)
 ...Q:QUIT
 ...K ^INLHDEST(DEST,X,Y,Z)
 Q
 ;-----
IMMCNT(DFN) ;COUNT PT IMMS TO BE EXPORTED
 N X,Y,Z
 S Y=0
 S X=0
 F  S X=$O(^AUPNVIMM("AC",DFN,X)) Q:'X  D
 .I $G(BYIMALL)=2 S Y=Y+1,^BYIMTMP("LOG",DFN,X)="" Q
 .I '$D(^BYIMEXP("D",X)) S Y=Y+1,^BYIMTMP("LOG",DFN,X)=""
 Q Y
 ;-----
FN ;EP;SET FILE NAME
 S:'$G(ASUFAC) ASUFAC=$P($G(^AUTTLOC($$DUZ(),0)),U,10)
 S:$G(BYIMFILE)="" BYIMFILE="izdata_"_$G(ASUFAC)_"_"_(DT+17000000)_"_"_$P($H,",",2)_$S($G(BYIMTEST):"_test",1:"")_"."_BYIMEXT
 Q
 ;-----
DUZ() ;PRIMARY PARAM SITE
 N X,Y,Z
 S Y=0
 S X=0
 F  S X=$O(^BYIMPARA(X)) Q:'X  I X=+^AUTTSITE(1,0) S Y=X
 I 'Y S X=0 F  S X=$O(^BYIMPARA(X)) Q:'X  I $D(^BYIMPARA(X,0)) S Y=X
 Q Y
 ;-----