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

AMHEYRE.m

Go to the documentation of this file.
AMHEYRE ; IHS/CMI/LAB - REDO A PREVIOUS MHSS EXPORT ;
 ;;4.0;IHS BEHAVIORAL HEALTH;;MAY 14, 2010
START ;
 S AMHO("RUN")="REDO" ;     Let ^AMHEYDI know this is a 'REDO'
 D ^AMHEYDI ;           
 I AMH("QFLG") D EOJ W !!,"Bye",!! Q
 D INIT ;               Get Log entry to redo
 I AMH("QFLG") D EOJ W !!,"Bye",!! Q
 D QUEUE^AMHEYDI
 I AMH("QFLG") D EOJ W !!,"Bye",!! Q
 I $D(AMHO("QUEUE")) D EOJ W !!,"Okay your request is queued!",!! Q
 ;
EN ;EP FROM TASKMAN
 S AMHCNT=$S('$D(ZTQUEUED):"X AMHCNT1  X AMHCNT2",1:"S AMHCNTR=AMHCNTR+1"),AMHCNT1="F AMHCNTL=1:1:$L(AMHCNTR)+1 W @AMHBS",AMHCNT2="S AMHCNTR=AMHCNTR+1 W AMHCNTR,"")"""
 D NOW^%DTC S AMH("RUN START")=%,AMH("MAIN TX DATE")=$P(%,".") K %,%H,%I
 I AMH("QFLG") D:$D(ZTQUEUED) ABORT D EOJ Q
 S AMH("BT")=$HOROLOG
 D PROCESS ;            Generate transactions
 I AMH("QFLG") W:'$D(ZTQUEUED) !!,"Abnormal termination!  QFLG=",AMH("QFLG") D:$D(ZTQUEUED) ABORT D EOJ Q
 D ^AMHEYRLG ;                Update Log entry
 I AMH("QFLG") W:'$D(ZTQUEUED) !!,"Log error! ",AMH("QFLG") D:$D(ZTQUEUED) ABORT D EOJ Q
 D:'$D(ZTQUEUED) RUNTIME^AMHEYEOJ
 I AMH("QFLG") W:'$D(ZTQUEUED) !!,"Tape creation error! QFLG=",AMH("QFLG") D:$D(ZTQUEUED) ABORT D EOJ Q
 D:'$D(ZTQUEUED) CHKLOG ;             See if Log needs cleaning
 D RESETV ;             Reset RECORDs processed in Log
 D TAPE ; Write transactions to tape
 I '$D(ZTQUEUED)  S DIR(0)="E",DIR("A")="DONE--Press enter to continue" K DA D ^DIR K DIR
 D EOJ
 K AMH
 Q
 ;
PROCESS ;
 K ^AMHXLOG(AMH("RUN LOG"),51)
 S (AMH("A"),AMH("D"),AMH("M"),AMH("COUNT"),AMH("ERROR COUNT"))=0
 W:'$D(ZTQUEUED) !,"Generating transactions.  Counting visits.  (1)" S AMHCNTR=0
 S AMHR=0 F  S AMHR=$O(^AMHXLOG(AMH("RUN LOG"),21,AMHR)) Q:AMHR'=+AMHR  D PROCESS2 Q:AMH("QFLG")
 S AMHCNTR=0,AMH("CONTROL DATE")="",AMHSFR=0
 W:'$D(ZTQUEUED) !,"Generating suicide forms.."
 S AMHSFIEN=0 F  S AMHSFIEN=$O(^AMHXLOG(AMH("RUN LOG"),31,"B",AMHSFIEN)) Q:AMHSFIEN'=+AMHSFIEN  D
 .I '$D(^AMHPSUIC(AMHSFIEN,0)) Q
 .S AMHSREC=^AMHPSUIC(AMHSFIEN,0)
 .S DFN=$P(AMHSREC,U,4)
 .S AMHRIEN=$O(^AMHRECD("B","BH2",0))
 .I 'AMHRIEN Q
 .S AMHY=0,AMHTX="" F  S AMHY=$O(^AMHRECD(AMHRIEN,11,"B",AMHY)) Q:AMHY'=+AMHY  D
 ..S X=""
 ..S AMHZ=$O(^AMHRECD(AMHRIEN,11,"B",AMHY,0))
 ..Q:'$D(^AMHRECD(AMHRIEN,11,AMHZ,1))
 ..X ^AMHRECD(AMHRIEN,11,AMHZ,1)
 ..S $P(AMHTX,U,AMHY)=X
 .S AMH("COUNT")=AMH("COUNT")+1,AMHSFC=AMHSFC+1
 .S ^XTMP("AMHSF","MAIN TX",AMHSFIEN)=AMH("MAIN TX DATE")
 .S ^BHSXDATA(AMH("COUNT"))=AMHTX
 Q
PROCESS2 ;
 K AMHE,AMHV,AMHTX
 X AMHCNT
 S ^XTMP("AMHREDO","MAIN TX",AMHR)="",AMHV("TX GENERATED")=0
 Q:'$D(^AMHREC(AMHR))
 S AMHREC=^AMHREC(AMHR,0)
 S AMHV("V DATE")=+AMHREC\1
 D KILL^AUPNPAT D RECORD^AMHEYD2
CNTBUILD ;count and build tx
 I AMHE]"" S AMH("ERROR COUNT")=AMH("ERROR COUNT")+1 D ERRLOG^AMHEYD Q
 S AMH("COUNT")=AMH("COUNT")+1
 S AMHV("TX GENERATED")=1,^XTMP("AMH"_$S(AMHO("RUN")="NEW":"DR",AMHO("RUN")="REDO":"REDO",1:"DR"),"MAIN TX",AMHR)=AMH("MAIN TX DATE")
 S ^BHSXDATA(AMH("COUNT"))=AMHTX
SETUTIL S ^XTMP("AMHREDO",AMHR)=AMHR_U_AMHV("TX GENERATED")
 Q
 ;
TAPE ; COPY TRANSACTIONS TO TAPE
 D EN^AMHEYTAP I $D(ZTQUEUED),AMH("QFLG") D ABORT
 Q
 ;
 ;
CHKLOG ; CHECK LOG FILE
 S AMH("X")=0 F AMH("I")=AMH("RUN LOG"):-1:1 Q:'$D(^AMHXLOG(AMH("I")))  I $O(^AMHXLOG(AMH("I"),21,0)) S AMH("X")=AMH("X")+1
 I AMH("X")>3 W !!,"-->There are more than three generations of RECORDs stored in the LOG file.",!,"-->Time to do a purge."
 Q
 ;
RESETV ; RESET RECORD DATA IN LOG
 W:'$D(ZTQUEUED) !,"Resetting RECORD specific data in Log file.  (1)" S AMHCNTR=0
 S AMH("X")="" F  S AMH("X")=$O(^XTMP("AMHREDO",AMH("X"))) Q:AMH("X")'=+AMH("X")  S AMH("Y")=^(AMH("X")),^AMHXLOG(AMH("RUN LOG"),21,AMH("X"),0)=AMH("Y") X AMHCNT ;FORGIVE ME LORD
 W:'$D(ZTQUEUED) !,"Resetting RECORD TX Flags. (1)" S AMHCNTR=0
 S AMH("X")="" F  S AMH("X")=$O(^XTMP("AMHREDO","MAIN TX",AMH("X"))) Q:AMH("X")'=+AMH("X")  D
 .S DIE="^AMHREC(",DA=AMH("X"),DR=".24///"_$S(^XTMP("AMHREDO","MAIN TX",AMH("X"))]"":^XTMP("AMHREDO","MAIN TX",AMH("X")),1:"@") D CALLDIE^AMHLEIN K DA,DR X AMHCNT
 .Q
 K ^XTMP("AMHREDO")
 ;NOW RESET SUICIDE FORMS
 S AMHCNTR=0,AMHV("R DATE")=""
 F  S AMHV("R DATE")=$O(^XTMP("AMHSF",AMHV("R DATE"))) Q:AMHV("R DATE")'=+AMHV("R DATE")  D PURGE2SF
 K ^XTMP("AMHSF")
 Q
PURGE2SF ;
 S AMHR="" F  S AMHR=$O(^XTMP("AMHSF",AMHV("R DATE"),AMHR)) Q:AMHR=""  D RESETSF
 Q
 ;
RESETSF ; kill MHSS xref and set flag if tx 23 or 24 generated
 I ^XTMP("AMHSF","MAIN TX",AMHR)]"" S DIE="^AMHPSUIC(",DA=AMHR,DR=".23///"_^XTMP("AMHSF","MAIN TX",AMHR) D CALLDIE^AMHLEIN
 X AMHCNT
 Q
 ;
INIT ;
 D INIT^AMHEYRE1
 Q
ABORT ; ABNORMAL TERMINATION
 I $D(AMH("RUN LOG")) S AMH("QFLG1")=$O(^AMHERRC("B",AMH("QFLG"),"")),DA=AMH("RUN LOG"),DIE="^AMHXLOG(",DR=".15///F;.16////"_AMH("QFLG1")
 I $D(ZTQUEUED) D ERRBULL^AMHEYDI3,ABORT,EOJ Q
 W !!,"Abnormal termination!!  QFLG=",AMH("QFLG")
 S DIR(0)="EO",DIR("A")="Press enter to continue" K DA D ^DIR K DIR
 Q
 ;
EOJ ;
 D ^AMHEYEOJ
 Q