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

AMHEYD.m

Go to the documentation of this file.
AMHEYD ; IHS/CMI/LAB - MAIN DRIVER FOR PCC EXPORT TX GEN AUGUST 14, 1992 ; 22 Jun 2017  12:04 PM
 ;;4.0;IHS BEHAVIORAL HEALTH;**1,4,5,6,8,9,10**;JUN 02, 2010;Build 15
START ;
 I $D(ZTQUEUED) S AMHO("SCHEDULED")=""
 S AMHO("RUN")="NEW" ;      Let AMHEYDI know this is a new run.
 D ^AMHEYDI ;           Do initialization
 I $D(AMHO("QUEUE")) D EOJ W !!,"Okay, your request is queued!  Bye",! Q
 I AMH("QFLG")=99 D EOJ W !!,"Bye",!! Q
 I AMH("QFLG") D ABORT Q
DRIVER ;called from TSKMN+2
 S AMH("BT")=$H
 D NOW^%DTC S AMH("RUN START")=%,AMH("MAIN TX DATE")=$P(%,".") K %,%H,%I
 S DIE="^AMHXLOG(",DA=AMH("RUN LOG"),DR=".15///R"_";.03////"_AMH("RUN START") D CALLDIE^AMHLEIN
 I $D(Y) D ABORT Q
 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 PROCESS ;            Generate trasactions
 I AMH("QFLG") D ABORT Q
 D ^AMHEYLOG ;                Update Log
 I AMH("QFLG") D ABORT Q
 D PURGE,PURGESF ;              Purge AEX xref entries
 D RUNTIME^AMHEYEOJ ;            Show run time
 D TAPE ; Write transactions to tape
 I AMH("QFLG") D ABORT Q
 I '$D(ZTQUEUED) W !! S DIR(0)="E",DIR("A")="DONE  --  Press ENTER to Continue" D ^DIR K DIR S:$D(DUOUT) DIRUT=1
 D EOJ
 Q
 ;
PROCESS ;
 W:'$D(ZTQUEUED) !,"Generating transactions.  Counting records.  (1)"
 S AMHCNTR=0,AMHTOTV=0,AMH("CONTROL DATE")=AMH("RUN BEGIN")-1,AMH("T-INIT")="  ",AMH("POSTING DATE")="      "
 F  S AMH("CONTROL DATE")=$O(^AMHREC("AEX",AMH("CONTROL DATE"))) Q:AMH("CONTROL DATE")=""!(AMH("CONTROL DATE")>AMH("RUN END"))  D PROCESS2 Q:AMH("QFLG")
 ;now process suicide forms
 W:'$D(ZTQUEUED) !,"Generating suicide forms..."
 S AMHCNTR=0,AMH("CONTROL DATE")="",AMHSFR=0
 F  S AMH("CONTROL DATE")=$O(^AMHPSUIC("AEX",AMH("CONTROL DATE"))) Q:AMH("CONTROL DATE")=""!(AMH("CONTROL DATE")>AMH("RUN END"))  D
 .S AMHSFIEN=0 F  S AMHSFIEN=$O(^AMHPSUIC("AEX",AMH("CONTROL DATE"),AMHSFIEN)) Q:AMHSFIEN'=+AMHSFIEN  D
 ..I '$D(^AMHPSUIC(AMHSFIEN,0)) K ^AMHPSUIC("AEX",AMH("CONTROL DATE"),AMHSFIEN) Q
 ..S AMHSREC=^AMHPSUIC(AMHSFIEN,0)
 ..S DFN=$P(AMHSREC,U,4),AMHRACE=""
 ..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
 ...;I DUZ=2881 S LORICNT=$G(LORICNT)+1,^LORITEST(LORICNT)=AMHSFIEN_"^"_$P(^AMHRECD(AMHRIEN,11,AMHZ,0),U,1)_"^"_$P(^AMHRECD(AMHRIEN,11,AMHZ,0),U,2)_"^"_X
 ..S AMH("COUNT")=AMH("COUNT")+1,AMHSFC=AMHSFC+1
 ..S ^XTMP("AMHSF",AMH("CONTROL DATE"),AMHSFIEN)=AMH("MAIN TX DATE")
 ..S ^BHSXDATA(AMH("COUNT"))=AMHTX
 ..Q:$D(^AMHXLOG(AMH("RUN LOG"),31,"B",AMHSFIEN))  ;already have that one in the log
 ..S DA=AMH("RUN LOG"),DR="3101///"_AMHSFIEN,DIE="^AMHXLOG(" D CALLDIE^AMHLEIN
 Q
PROCESS2 ;
 S AMHR="" F  S AMHR=$O(^AMHREC("AEX",AMH("CONTROL DATE"),AMHR)) Q:AMHR=""  D PROCESS3 Q:AMH("QFLG")
 Q
PROCESS3 ;
 K AMHT,AMHV,AMHE
 D KILL^AUPNPAT
 Q:$D(^AMHXLOG(AMH("RUN LOG"),21,AMHR))  ;already in log so don't bother, already processed
 S AMHV("TX GENERATED")=0,^XTMP("AMHDR",AMH("CONTROL DATE"),AMHR)="",^XTMP("AMHDR","MAIN TX",AMHR)=""
 X AMHCNT
 S AMHTOTV=AMHTOTV+1
 S AMHREC=^AMHREC(AMHR,0)
 S AMHV("R DATE")=+AMHREC\1
 K AMHE,AMHTX D RECORD^AMHEYD2
 D CNTBUILD
 D ^XBFMK
 I $D(^AMHXLOG(AMH("RUN LOG"),21,AMHR,0)) Q  ;already in log
 S DA=AMH("RUN LOG"),DR="2101///""`"_AMHR_"""",DIE="^AMHXLOG("
 S DR(2,9002014.2101)=".02////"_AMHV("TX GENERATED")
 D CALLDIE^AMHLEIN
 Q
 ;
PURGE ; PURGE 'AEX' XREF FOR MHSS RECORDS JUST DONE
 W:'$D(ZTQUEUED) !,"Deleting cross-reference entries. (1)"
 S AMHCNTR=0,AMHV("R DATE")=""
 F  S AMHV("R DATE")=$O(^XTMP("AMHDR",AMHV("R DATE"))) Q:AMHV("R DATE")'=+AMHV("R DATE")  D PURGE2
 K ^XTMP("AMHDR")
 Q
PURGE2 ;
 S AMHR="" F  S AMHR=$O(^XTMP("AMHDR",AMHV("R DATE"),AMHR)) Q:AMHR=""  D RESET
 Q
 ;
RESET ; kill MHSS xref and set flag if tx 23 or 24 generated
 K ^AMHREC("AEX",AMHV("R DATE"),AMHR)
 I ^XTMP("AMHDR","MAIN TX",AMHR)]"" S DIE="^AMHREC(",DA=AMHR,DR=".24///"_^XTMP("AMHDR","MAIN TX",AMHR)_";.22///@" D CALLDIE^AMHLEIN
 X AMHCNT
 Q
 ;
PURGESF ; PURGE 'AEX' XREF FOR MHSS RECORDS JUST DONE
 W:'$D(ZTQUEUED) !,"Deleting cross-reference entries on suicide forms. (1)"
 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
 K ^AMHPSUIC("AEX",AMHV("R DATE"),AMHR)
 S DIE="^AMHPSUIC(",DA=AMHR,DR=".23///"_^XTMP("AMHSF",AMHV("R DATE"),AMHR) D CALLDIE^AMHLEIN
 X AMHCNT
 Q
 ;
CNTBUILD ;count and build tx
 I AMHE]"" S AMH("ERROR COUNT")=AMH("ERROR COUNT")+1 D ERRLOG 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
 Q
TAPE ; COPY TRANSACTIONS TO TAPE
 D EN^AMHEYTAP I $D(ZTQUEUED),AMH("QFLG") D ERRBULL^AMHEYDI3
 Q
 ;
CHKLOG ; CHECK LOG FILE
 Q
 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")>12 W !,"-->There are more than twelve generations of MHSS RECORDs stored in the LOG file.",!,"-->Time to do a purge."
 Q
 ;
ABORT ; ABNORMAL TERMINATION
 I $D(AMH("RUN LOG")) S AMH("QFLG1")=$O(^AMHDTER("B",AMH("QFLG"),"")),DA=AMH("RUN LOG"),DIE="^AMHXLOG(",DR=".15///F;.16////"_AMH("QFLG1")
 I $D(ZTQUEUED) D ERRBULL^AMHEYDI3,EOJ Q
 W !!,"Abnormal termination!!  QFLG=",AMH("QFLG")
 S DIR(0)="E",DIR("A")="DONE  --  Press ENTER to Continue" D ^DIR K DIR S:$D(DUOUT) DIRUT=1
 D EOJ
 Q
 ;
EOJ ; EOJ
 D ^AMHEYEOJ
 Q
ERRLOG ;EP
 S AMHE("ERR DFN")=$O(^AMHERR("B",AMHE,"")) I AMHE("ERR DFN")="" S AMHE("MSG")=AMHE_"-ERROR INFORMATION NOT IN ERROR FILE" G ERR
 S AMHE("MSG")=AMHE_"-"_$P(^AMHERR(AMHE("ERR DFN"),0),U,2) S:$L(AMHE("MSG"))=5 AMHE("MSG")=AMHE("MSG")_"- ERROR INFORMATION NOT IN ERROR FILE" S AMHE("MSG")=$E(AMHE("MSG"),1,45)
ERR ;
 K DIE,DR S DA=AMH("RUN LOG"),DR="5101///""`"_AMHR_"""",DR(2,9002014.05101)=".02///"_AMHE("MSG"),DIE="^AMHXLOG("
 D CALLDIE^AMHLEIN
 I $D(Y) S AMH("QFLG")=25 W:'$D(ZTQUEUED) !!,"Error encountered in ^AMHERR.  Notify programmer!",! I $D(ZTQUEUED) D ERRBULL^AMHEYDI3
 Q
VERSION() ;EP
 Q "V40P10"