| 1 | PSXDODNT ;CMC/WPB Utility to watch DoD directories ;04/01/02 16:52:42
 | 
|---|
| 2 |  ;;2.0;CMOP;**38,45**;11 Apr 97
 | 
|---|
| 3 |  ;this routine will watch the incoming directories for files from DoD
 | 
|---|
| 4 |  ;facilities and direct processing to the appropriate routine.
 | 
|---|
| 5 |  ;
 | 
|---|
| 6 |  ;create an option to call the routine, then schedule the option to run
 | 
|---|
| 7 |  ;every 15 minutes using the TaskMan scheduler
 | 
|---|
| 8 |  ;
 | 
|---|
| 9 |  ;files extensions:
 | 
|---|
| 10 |  ;  .trn - transmission of dispense request from Outside Agency to VistA
 | 
|---|
| 11 |  ;  .ack - acknowledgement of dispense requests from VistA to Outside Agency
 | 
|---|
| 12 |  ;  .qry - prescription fulfillment data from VistA to Outside Agency
 | 
|---|
| 13 |  ;  .qac - acknowledgement of receipt of fulfillment data from Outside Agency to VistA 
 | 
|---|
| 14 |  ;  .sit - activation/deactivation from Outside Agency to VistA
 | 
|---|
| 15 |  ;  .sac - acknowledgement of activation/deactivation message from VistA to Outside Agency
 | 
|---|
| 16 |  ;  .sch - auto transmission schedule/unscheduled message from Outside Agency to VistA
 | 
|---|
| 17 |  ;  .hac - acknowledgement of auto transmission schedule/unscheduled message from VistA to Outside Agency
 | 
|---|
| 18 |  ;
 | 
|---|
| 19 |  ;the path must be setup before this routine can run:
 | 
|---|
| 20 |  ;    path = \\SERVERNAME\CMOP\INBOX
 | 
|---|
| 21 |  ;for testing the servername = vhacmcdhc3
 | 
|---|
| 22 |  ;
 | 
|---|
| 23 |  ;          VARIABLES
 | 
|---|
| 24 |  ;   FILELIST        the type of files to look for. this is set to all files in the directory
 | 
|---|
| 25 |  ;   FILE            stores the list of files
 | 
|---|
| 26 |  ;   PATH            the path to the directory where the files are stored
 | 
|---|
| 27 |  ;
 | 
|---|
| 28 | EN ;reads the directory for files
 | 
|---|
| 29 |  K FILELIST,FILE,PSXERCNT
 | 
|---|
| 30 |  ; test if previous job still running
 | 
|---|
| 31 |  S PREVJOB=$O(^XTMP("PSXDODNT")),PSXJOB="PSXDODNT-"_$J
 | 
|---|
| 32 |  I PREVJOB'="",PREVJOB["PSXDODNT-",PREVJOB'=PSXJOB D  I PSXQUIT W !,"STOPPING" Q
 | 
|---|
| 33 |  . S PSXQUIT=1
 | 
|---|
| 34 |  . D NOW^%DTC S X1=%,X2=^XTMP(PREVJOB,1) S DIF=$$FMDIFF^XLFDT(X1,X2,2)
 | 
|---|
| 35 |  . I DIF<1200 Q  ; if less than 20 minutes quit
 | 
|---|
| 36 |  . ;if > 20 minutes, store off previous trail and start new
 | 
|---|
| 37 |  . D NOW^%DTC
 | 
|---|
| 38 |  . M ^XTMP("PSXDODERR",%,PREVJOB)=^XTMP(PREVJOB) K ^XTMP(PREVJOB)
 | 
|---|
| 39 |  . S X=$$FMADD^XLFDT(DT,3) S ^XTMP("PSXDODERR",0)=X_U_DT_U_"DOD CMOP PROCESS ERROR CAPTURE"
 | 
|---|
| 40 |  . K ^XTMP(PREVJOB) S PSXQUIT=0
 | 
|---|
| 41 |  . D NOW^%DTC S XX=$$FMTE^XLFDT(%)
 | 
|---|
| 42 |  . S XMSUB="DOD CMOP INTERFACE STOPPED IRREGULARLY "_XX,XMTEXT="TXT("
 | 
|---|
| 43 |  . K TXT
 | 
|---|
| 44 |  . S TXT(1,0)="The DOD CMOP Interface has been idle more than 20 minutes "_XX
 | 
|---|
| 45 |  . S TXT(2,0)="The XTMP audit trail has been stored in ^XTMP(""PSXDODERR"","_%
 | 
|---|
| 46 |  . S TXT(3,0)="If this message is appearing frequently contact your CMOP IRM support"
 | 
|---|
| 47 |  . D ^XMD
 | 
|---|
| 48 |  ; proceeding to process files
 | 
|---|
| 49 |  D RESEND
 | 
|---|
| 50 |  S X1=DT,X2=1 D C^%DTC S PSXDT=X
 | 
|---|
| 51 |  D NOW^%DTC
 | 
|---|
| 52 |  K ^XTMP(PSXJOB)
 | 
|---|
| 53 |  S ^XTMP(PSXJOB,0)=PSXDT_U_%_U_"DOD PSXDODNT LOGGER"
 | 
|---|
| 54 |  S ^XTMP(PSXJOB,1)=%
 | 
|---|
| 55 |  ;S FILELIST("*.*")=""
 | 
|---|
| 56 |  F EXT="*.trn","*.sit","*.sch","*.qac" S FILELIST(EXT)="" ;****testing
 | 
|---|
| 57 |  ; SET PATH=INBOX DIRECTORY PATH
 | 
|---|
| 58 |  S PATH=$$GET1^DIQ(554,1,20),FILE=""
 | 
|---|
| 59 |  S Y=$$LIST^%ZISH(PATH,"FILELIST","FILE")
 | 
|---|
| 60 |  I Y'=1 D  Q  ;if Y doesn't equal 1 there weren't any files to get, the routine will stop until called by TaskMan
 | 
|---|
| 61 |  . D KVAR
 | 
|---|
| 62 |  . K ^XTMP(PSXJOB) ;****TESTING
 | 
|---|
| 63 |  ;
 | 
|---|
| 64 | DIRECT ;reads the FILE variable to see what types files are available for processing and then sends process to the appropriate routine
 | 
|---|
| 65 |  I $E(IOST)="C" W !,"Processing Files:" S FILENM="" F  S FILENM=$O(FILE(FILENM)) Q:FILENM=""  W !,?5,FILENM
 | 
|---|
| 66 |  S FILENM=""
 | 
|---|
| 67 |  ; re-entry for next file if error encountered
 | 
|---|
| 68 |  ;W !,"nxtfile3"
 | 
|---|
| 69 |  ;F  W !,"Nxtfile3a ",FILENM S FILENM=$O(FILE(FILENM)) W !,"nxtfile3b ",FILENM Q:FILENM=""  D
 | 
|---|
| 70 |  F  S FILENM=$O(FILE(FILENM)) Q:FILENM=""  D
 | 
|---|
| 71 |  . I '$G(^XTMP("PSXNTSTOP-1",0)) N $ETRAP,$ESTACK S $ETRAP="D ZTER^PSXDODNT"
 | 
|---|
| 72 |  . S EXT=$$UP^XLFSTR($P(FILENM,".",2))
 | 
|---|
| 73 |  . ; the following line to be used with Vitria BusinessWare
 | 
|---|
| 74 |  . S ROU=$S(EXT["SIT":"ACT^PSXDODAC(PATH,FILENM)",EXT["SCH":"EN^PSXDODAT(PATH,FILENM)",EXT["TRN":"EN^PSXDODB(PATH,FILENM)",EXT["QAC":"EN^PSXDODAK(PATH,FILENM)",1:"")
 | 
|---|
| 75 |  . ;the following line to be used when Vitrai BusinessWare is not being used
 | 
|---|
| 76 |  . ;S ROU=$S(EXT["SIT":"ACT^PSXDODAC(PATH,FILENM)",EXT["SCH":"EN^PSXDODAT(PATH,FILENM)",EXT["TRN":"EN^PSXDODH(PATH,FILENM)",EXT["QAC":"EN^PSXDODAK(PATH,FILENM)",1:"")
 | 
|---|
| 77 |  . H 2 D NOW^%DTC S ^XTMP(PSXJOB,%)=FILENM,^XTMP(PSXJOB,1)=%,JOBBEG=% ;I $E(IOST)="C" W !,JOBBEG,?20,^XTMP(PSXJOB,JOBBEG)
 | 
|---|
| 78 |  . D ROU
 | 
|---|
| 79 |  . D FINISH
 | 
|---|
| 80 |  . H 2 D NOW^%DTC S $P(^XTMP(PSXJOB,JOBBEG),U,3)=%,^XTMP(PSXJOB,1)=% ;I $E(IOST)="C" W !,%,?20,^XTMP(PSXJOB,JOBBEG)
 | 
|---|
| 81 |  K I,INC,Y,ROU
 | 
|---|
| 82 |  D KVAR
 | 
|---|
| 83 |  G EN ;loop to see if any other files came in to pickup
 | 
|---|
| 84 |  ;
 | 
|---|
| 85 | FINISH ;
 | 
|---|
| 86 |  I $E(IOST)="C" W !,"nxtfile4 Finish of ",FILENM
 | 
|---|
| 87 |  K ^TMP($J,"PSXDODNT")
 | 
|---|
| 88 | PULL S PATH=$$GET1^DIQ(554,1,20) S Y=$$FTG^%ZISH(PATH,FILENM,$NA(^TMP($J,"PSXDODNT",1)),3)
 | 
|---|
| 89 | ARCHIVE ;
 | 
|---|
| 90 |  S FILENMAR=FILENM
 | 
|---|
| 91 |  I FILENM[".TRN" S FILENMAR=FILENM_".BW"
 | 
|---|
| 92 |  S PATH=$$GET1^DIQ(554,1,22) F XX=1:1:5 S Y=$$GTF^%ZISH($NA(^TMP($J,"PSXDODNT",1)),3,PATH,FILENMAR) Q:Y=1  H 4
 | 
|---|
| 93 |  I Y'=1 S GBL=$NA(^TMP($J,"PSXDODNT")) D FALERT(FILENMAR,PATH,GBL)
 | 
|---|
| 94 | REMOVE I $L($G(FILENM)) K PSXL S PSXL(FILENM)="",PATH=$$GET1^DIQ(554,1,20),Y=$$DEL^%ZISH(PATH,"PSXL")
 | 
|---|
| 95 |  Q
 | 
|---|
| 96 | KVAR ;K FILELIST,FILE,Y,PATH,BADFILE
 | 
|---|
| 97 |  Q
 | 
|---|
| 98 | ROU ; nest the new command so variables will be protected
 | 
|---|
| 99 |  N FILE,JOBBEG,JOBEND,PSXJOB
 | 
|---|
| 100 |  I $E(IOST)="C" W !,FILENM," ",ROU
 | 
|---|
| 101 |  D @ROU
 | 
|---|
| 102 |  Q
 | 
|---|
| 103 | ZTER ;Friendly RE-cycle error and move to next file
 | 
|---|
| 104 |  S XXERR=$$EC^%ZOSV
 | 
|---|
| 105 |  S XMSUB="DOD CMOP Error on  File "_FILENM
 | 
|---|
| 106 |  S BADFILE=FILENM
 | 
|---|
| 107 |  S XMTEXT="TEXT("
 | 
|---|
| 108 |  S TEXT(1,0)="DOD CMOP encountered the following error. Please investigate"
 | 
|---|
| 109 |  S TEXT(2,0)="File:  "_FILENM
 | 
|---|
| 110 |  S TEXT(3,0)="Error: "_XXERR
 | 
|---|
| 111 |  S TEXT(4,0)="The file has been moved into the Hold directory "_$$GET1^DIQ(554,1,23)
 | 
|---|
| 112 |  D GRP1^PSXNOTE
 | 
|---|
| 113 |  D ^%ZTER ;log error into Kernel K8SYS pg 183
 | 
|---|
| 114 |  D ^XMD
 | 
|---|
| 115 |  I $E(IOST)="C" W !,"zter2:Error Finish & Removal of ",FILENM
 | 
|---|
| 116 |  K ^TMP($J,"PSXDODNT"),TEXT
 | 
|---|
| 117 | PULL2 S PATH=$$GET1^DIQ(554,1,20),Y=$$FTG^%ZISH(PATH,FILENM,$NA(^TMP($J,"PSXDODNT",1)),3)
 | 
|---|
| 118 | HOLD S PATH=$$GET1^DIQ(554,1,23) F XX=1:1:5 S Y=$$GTF^%ZISH($NA(^TMP($J,"PSXDODNT",1)),3,PATH,FILENM) Q:Y=1  H 4
 | 
|---|
| 119 |  I Y'=1 S GBL=$NA(^TMP($J,"PSXDODNT")) D FALERT(FILENM,PATH,GBL)
 | 
|---|
| 120 | ARCHIVE2 S PATH=$$GET1^DIQ(554,1,22) F XX=1:1:5 S Y=$$GTF^%ZISH($NA(^TMP($J,"PSXDODNT",1)),3,PATH,FILENM) Q:Y=1  H 4
 | 
|---|
| 121 |  I Y'=1 S GBL=$NA(^TMP($J,"PSXDODNT")) D FALERT(FILENM,PATH,GBL)
 | 
|---|
| 122 | REMOVE2 K PSXL S PSXL(FILENM)="",PATH=$$GET1^DIQ(554,1,20),Y=$$DEL^%ZISH(PATH,"PSXL")
 | 
|---|
| 123 |  D NOW^%DTC S Y=% X ^DD("DD")
 | 
|---|
| 124 |  S XQAMSG="PLEASE INVESTIGATE - CMOP/DOD error "_XXERR_" "_Y,XQAID="PSXDODNT"
 | 
|---|
| 125 |  D GRP1^PSXNOTE M XQA=XMY D SETUP^XQALERT
 | 
|---|
| 126 |  H 10
 | 
|---|
| 127 |  G UNWIND^%ZTER ; return to code 1 level above where $ETRAP set ie the F Loop
 | 
|---|
| 128 |  Q
 | 
|---|
| 129 | FALERT(FILE,PATH,GBL) ;fail to pass file into target directory, send alert, store for later
 | 
|---|
| 130 |  D NOW^%DTC S Y=% X ^DD("DD")
 | 
|---|
| 131 |  S XQAMSG="DOD: "_FILE_" failed placement into: "_PATH_" "_Y,XQAID="PSXDODNT"
 | 
|---|
| 132 |  D GRP1^PSXNOTE M XQA=XMY ;****TESTING
 | 
|---|
| 133 |  ;S XQA(DUZ)="" ;****TESTING
 | 
|---|
| 134 |  D SETUP^XQALERT
 | 
|---|
| 135 | STORE ; store file intO XTMP if GBL PROVIDED
 | 
|---|
| 136 |  Q:$G(GBL)=""
 | 
|---|
| 137 |  D NOW^%DTC S NMSPACE="PSXFILE"_"-"_%
 | 
|---|
| 138 |  S DTPRG=$$FMADD^XLFDT(DT,7) ; save for 7 days
 | 
|---|
| 139 |  K ^XTMP(NMSPACE)
 | 
|---|
| 140 |  S ^XTMP(NMSPACE,0)=DTPRG_U_DT_U_"DOD FILE TO SEND"
 | 
|---|
| 141 |  S ^XTMP(NMSPACE,1)=FILE,^XTMP(NMSPACE,2)=PATH
 | 
|---|
| 142 |  M ^XTMP(NMSPACE,"T")=@GBL ; GBL IN FORM OF S GBL=$NA(^TMP($J,"PSXDODNT"))
 | 
|---|
| 143 |  Q
 | 
|---|
| 144 | RESEND ; SCAN XTMP and if entries put the files into the boxes
 | 
|---|
| 145 |  S NMSPACE="PSXFILE"
 | 
|---|
| 146 |  F  S NMSPACE=$O(^XTMP(NMSPACE)) Q:$E(NMSPACE,1,7)'="PSXFILE"  D
 | 
|---|
| 147 |  .S FILE=^XTMP(NMSPACE,1),PATH=^XTMP(NMSPACE,2)
 | 
|---|
| 148 |  .;W !,FILE,"  ",PATH
 | 
|---|
| 149 |  .S Y=$$GTF^%ZISH($NA(^XTMP(NMSPACE,"T",1)),3,PATH,FILE)
 | 
|---|
| 150 |  .I Y'=1 D FALERT("Resending DOD files ",PATH) S NMSPACE="XX" Q
 | 
|---|
| 151 |  .K ^XTMP(NMSPACE)
 | 
|---|
| 152 |  .D NOW^%DTC S Y=% X ^DD("DD")
 | 
|---|
| 153 |  .S XQAMSG="DOD: "_FILE_" DID PLACE into: "_PATH_" "_Y,XQAID="PSXDODNT"
 | 
|---|
| 154 |  .;W !,XQAMSG
 | 
|---|
| 155 |  .D GRP1^PSXNOTE M XQA=XMY ;****TESTING
 | 
|---|
| 156 |  .;S XQA(DUZ)="" ;****TESTING
 | 
|---|
| 157 |  .D SETUP^XQALERT
 | 
|---|
| 158 |  .Q
 | 
|---|
| 159 | CLEAR ; CLEAR PREVIOUS NODES history nodes
 | 
|---|
| 160 |  S X="PSXDODNT" F  S X=$O(^XTMP(X)) Q:X'["PSXDODNT"  W !,X K ^XTMP(X)
 | 
|---|
| 161 |  Q
 | 
|---|
| 162 | KILLERR ; kill the error LOG ^XTMP("PSXDODERR", )
 | 
|---|
| 163 |  K ^XTMP("PSXDODERR")
 | 
|---|
| 164 |  Q
 | 
|---|
| 165 | START ;enable/start auto error trapping
 | 
|---|
| 166 |  K ^XTMP("PSXNTSTOP-1")
 | 
|---|
| 167 |  Q
 | 
|---|
| 168 | STOP ;disable auto error trapping
 | 
|---|
| 169 |  S ^XTMP("PSXNTSTOP-1",0)=DT_U_DT_U_"disable PSXDODNT auto error trapping"
 | 
|---|
| 170 |  Q
 | 
|---|
| 171 | EDIT ; edit the PSX DODNT option K8 SYS pg 342
 | 
|---|
| 172 |  D EDIT^XUTMOPT("PSX DOD CMOP INTERFACE")
 | 
|---|
| 173 |  Q
 | 
|---|
| 174 | DISP ; display schedule
 | 
|---|
| 175 |  D DISP^XUTMOPT("PSX DOD CMOP INTERFACE")
 | 
|---|
| 176 |  Q
 | 
|---|
| 177 | CLEARALL ; clear boxes out, archive, hold of all files
 | 
|---|
| 178 |  F XX=21,22,23 D CLEARFLS^PSXDODH(XX,"*.*")
 | 
|---|
| 179 |  Q
 | 
|---|