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

VDEFREQ.m

Go to the documentation of this file.
  1. VDEFREQ ;INTEGIC/AM & BPOIFO/JG - VDEF Request Processor ;15 Nov 2005 3:00 PM
  1. ;;1.0;VDEF;**3,14**;Dec 28, 2004;Build 3
  1. ;Per VA Directive 6402, this routine should not be modified.
  1. ;
  1. ; IA: 10063 - $$S^%ZTLOAD
  1. ; 10063 - $$ASKSTOP^%ZTLOAD
  1. ;
  1. Q ; No bozos
  1. ;
  1. EN ; Main entry point for the Request Queue processor from TaskMan
  1. ;
  1. ; Input parameter:
  1. ; QIEN - Request Queue IEN passed in by TaskMan
  1. ;
  1. ; Output parameters:
  1. ; ZTSTOP - flag indicating whether to stop processing: 0 by default
  1. ; 1 if an outside request to stop the Processor or internal error
  1. ; 2 if VistA HL7 API errored out
  1. ; ZTREQ - Tells the Submanager to delete this task's record if "@"
  1. ;
  1. N DSTDATA,DSTIEN,ERR,FDA,NVPIEN,QUEUE,SCHED,IEN,VDEFWAIT,VDEFTSK
  1. S VDEFTSK=ZTSK
  1. ;
  1. ; Lock this Request Queue from other processors. If it's already locked,
  1. ; another process has it.
  1. L +^VDEFHL7(579.3,"QUEUE",QIEN):1 G EXIT:'$T
  1. ;
  1. EN1 ; Re-entry point after the wait period has expired
  1. ;
  1. ; Quit if there has been a request to stop processing
  1. S ZTSTOP=$$S^%ZTLOAD() G EXIT:ZTSTOP
  1. ;
  1. ; Get the queue data
  1. S QUEUE=$G(^VDEFHL7(579.3,QIEN,0))
  1. ;
  1. ; Quit if this Request Queue is suspended
  1. G EXIT:$P(QUEUE,U,9)="S"
  1. ;
  1. ; Set the wait period to the REQUEST QUEUE WAKEUP
  1. S VDEFWAIT=+$P(QUEUE,U,2)
  1. ;
  1. ; See if current time is in a scheduling rule
  1. S SCHED=$$SCHEDULE^VDEFQM(QIEN,$H) G EN2:'SCHED
  1. ;
  1. ; If current time is in a suspend rule, set wait period to
  1. ; the next start time or the basic wakeup period whichever is longer.
  1. I $P(SCHED,U)="S",$P(SCHED,U,2)>VDEFWAIT S VDEFWAIT=$P(SCHED,U,2) G WAITLOOP
  1. ;
  1. EN2 ; Update the Request Queue definition with the current task #
  1. K FDA S FDA(1,579.3,QIEN_",",.11)=VDEFTSK D FILE^DIE("","FDA(1)","ERR(1)")
  1. ;
  1. ; Store VDEF Destination data in a local array
  1. S DSTIEN=0 F S DSTIEN=$O(^VDEFHL7(579.2,DSTIEN)) Q:'DSTIEN D
  1. . S DSTDATA(DSTIEN)=$G(^VDEFHL7(579.2,DSTIEN,0))
  1. ;
  1. ; Loop through the Queued Up requests for this queue
  1. S (ZTSTOP,IEN)=0
  1. F S IEN=$O(^VDEFHL7(579.3,"C","Q",QIEN,IEN)) Q:IEN="" D Q:ZTSTOP
  1. . ;
  1. . ; Quit if there has been a request to stop processing
  1. . S ZTSTOP=$$S^%ZTLOAD() Q:ZTSTOP
  1. . I $P($G(^VDEFHL7(579.3,QIEN,0)),U,9)="S" S ZTSTOP=1 Q
  1. . N DSTPROT,DSTTYP,DYNAMIC,ERR,SITEPARM,VDEFN
  1. . N FDA,VDEFHL,HLA,HLCS,IEN577,IENS,II,HL
  1. . N NAMEVAL,PAIR,REQUEST,SUBT,VAL,VDEFERR
  1. . S IENS=IEN_","_QIEN_"," ; Request Queue IEN string
  1. . L +^VDEFHL7(579.3,QIEN,IEN):5 Q:'$T
  1. . M VAL=^VDEFHL7(579.3,QIEN,1,IEN) S REQUEST=$G(VAL(0))
  1. . M NAMEVAL=VAL(.05) ; Name Value pairs
  1. . M DYNAMIC=VAL(.19) ; Dynamic Addressing information
  1. . K VAL
  1. . ;
  1. . ; Check for an incomplete record
  1. . ;VDEF*14 - should not rely on global structure
  1. . ;I '$D(NAMEVAL(1)) L -^VDEFHL7(579.3,QIEN,IEN) Q
  1. . ;
  1. . ; Change request status from "Q"ueued Up to "C"hecked Out
  1. . S FDA(1,579.31,IENS,.02)="C" D FILE^DIE("","FDA(1)") K FDA
  1. . ;
  1. . ; VDEF*14 loop through the NAMEVAL array - regardless of ien
  1. . S (SUBT,NVPIEN)="",VDEFN=0
  1. . F S VDEFN=$O(NAMEVAL(VDEFN)) Q:VDEFN="" D
  1. .. S PAIR=$P($G(NAMEVAL(VDEFN,0)),U,2)
  1. .. I PAIR["SUBTYPE" S SUBT=$P(PAIR,"=",2)
  1. .. I PAIR["IEN" S NVPIEN=$P(PAIR,"=",2)
  1. .. Q
  1. . ;VDEF*14 quit if unable to determine subtype or ien
  1. . I SUBT="" D ERR("Subtype missing from Name/Value Pair") L -^VDEFHL7(579.3,QIEN,IEN) Q
  1. . I NVPIEN="" D ERR("IEN missing from Name/Value Pair") L -^VDEFHL7(579.3,QIEN,IEN) Q
  1. . ;
  1. . ; Retrieve the Destination information for this request
  1. . S DSTIEN=$P(REQUEST,U,7),DSTTYP=$P($G(DSTDATA(+DSTIEN)),U,2)
  1. . ;
  1. . ; Get the VDEF Event IEN
  1. . S IEN577=$P(REQUEST,U,18)
  1. . ;
  1. . ; Get the VISTA HL7 Protocol
  1. . S DSTPROT=$P($G(^VDEFHL7(577,IEN577,0)),U,7)
  1. . I DSTPROT="" D ERR("Protocol not defined in VDEF event file") S ZTSTOP=1 L -^VDEFHL7(579.3,QIEN,IEN) Q
  1. . ;
  1. . ; Create delimiter structure to use when building segments
  1. . D INIT^HLFNC2(DSTPROT,.VDEFHL)
  1. . I '$D(VDEFHL) D ERR("No HL7 parameters for this Protocol") S ZTSTOP=1 L -^VDEFHL7(579.3,QIEN,IEN) Q
  1. . S HLCS=$E(VDEFHL("ECH")) M HL=VDEFHL ; Some called routines use 'HL' array
  1. . ;
  1. . ; Get the site parameters
  1. . S SITEPARM=$$PARAM^HLCS2
  1. . ;
  1. . ; If no IEN don't generate an HL7 message
  1. . I $G(NVPIEN)="" D STATUS^VDEFREQ1(IENS,"P"),ERR("Invalid IEN") S ZTSTOP=1 L -^VDEFHL7(579.3,QIEN,IEN) Q
  1. . D NOW^%DTC S FDA(1,579.31,IENS,.09)=%
  1. . ;
  1. . ; Update this Request record with the current date & time
  1. . D FILE^DIE("","FDA(1)","ERR(1)") K FDA
  1. . ;
  1. . ; Generate HL7 message for this request
  1. . D GENERATE^VDEFREQ1(NVPIEN,.HLA,HLCS,IEN577,SUBT,DSTPROT,DSTTYP,.ZTSTOP,.VDEFHL,.DYNAMIC)
  1. . ;
  1. . ; Update request status from Checked Out to Processed or Errored Out
  1. . ; Leave Request Checked Out if VistA HL7 errored out (ZTSTOP=2)
  1. . I ZTSTOP'=2 D STATUS^VDEFREQ1(IENS,$S(ZTSTOP=1:"E",1:"P")) S ZTSTOP=0
  1. . I ZTSTOP=2 S ZTSTOP=0 ; If VistA HL7 errored out, continue processing
  1. . ;
  1. . ; Unlock the record
  1. . L -^VDEFHL7(579.3,QIEN,IEN)
  1. ;
  1. ; Quit if necessary.
  1. G EXIT:ZTSTOP
  1. ; Wait for the next time to run.
  1. ; The wait process is in a loop so it can check if there
  1. ; has been a request to stop processing before the wait expires.
  1. WAITLOOP N I S ZTSTOP=0 F I=1:1:VDEFWAIT D Q:ZTSTOP
  1. . S ZTSTOP=$$S^%ZTLOAD() Q:ZTSTOP
  1. . I $P(^VDEFHL7(579.3,QIEN,0),U,9)="S" S ZTSTOP=1 Q
  1. . H 1
  1. ;
  1. ; Quit or resume processing
  1. I 'ZTSTOP K I G EN1
  1. ;
  1. ; Quit
  1. ; Unlock the record in case it left the loop with an error
  1. EXIT L -^VDEFHL7(579.3,"QUEUE",QIEN),-^VDEFHL7(579.3,QIEN,IEN)
  1. D ALERT^VDEFUTIL("VDEF REQUEST QUEUE PROCESSOR FOR "_$P(QUEUE,U)_" HAS EXITED.")
  1. ;
  1. ; Stop the task and delete this task's record
  1. N X,I S ZTSK=VDEFTSK,X=$$ASKSTOP^%ZTLOAD(ZTSK),ZTREQ="@"
  1. F I=1:1:5 D STAT^%ZTLOAD Q:ZTSK(1)=0!(ZTSK(1)>2) H 1
  1. K X,I
  1. Q
  1. ;
  1. ERR(TEXT) ; Error processing
  1. N FDA,ERR
  1. S VDEFERR=$TR(TEXT,"^"),FDA(1,579.31,IENS,.17)=VDEFERR
  1. D FILE^DIE("","FDA(1)","ERR")
  1. Q