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

VDEFQM.m

Go to the documentation of this file.
  1. VDEFQM ;INTEGIC/AM & BPOIFO/JG - VDEF API ; 21 Dec 2005 11:38 AM
  1. ;;1.0;VDEF;**3**;Dec 28, 2004
  1. ;Per VHA Directive 2004-038, this routine should not be modified.
  1. ;
  1. ; IA's: #4271 - Lookup to file #771.2
  1. ; #4321 - Lookup to file #779.001
  1. ;
  1. Q ; No bozos
  1. ;
  1. ; Validates and places a request in the VDEF queue
  1. QUEUE(EVENT,PAIR,MSTEXT,REQIEN,DYNAMIC) ;
  1. ; EVENT = HL7 event in the form Event Type^Message Type (e.g. ADT^A28)
  1. ; PAIR = Name/value pairs uniquely identifying the IEN
  1. ; (e.g. SUBTYPE="CHEM"^IEN=1234)
  1. ; MSTEXT = Returned text message, passed by reference
  1. ; REQIEN = Requestor IEN in file 579.1, only valued for solicited
  1. ; requests
  1. ; DYNAMIC = Dynamic Addressing array in nodes DYNAMIC("LINKS",1-n)
  1. ;
  1. N CNT,CUSTIEN,DATA,DESTIEN,ERR,EVENTIEN,EVTY,EVTYIEN,FDA,VDI,IENROOT
  1. N MESIEN,MSTY,OUTPUT,QUEIEN,RQIEN,SUBTYPE,SUBIEN,NVPIEN
  1. N D0,DA,DH,DI,DIC,DIE,DIK,DIKRFIL,DIN,DIROOT,DR,X,Y
  1. S MSTEXT="",REQIEN=$G(REQIEN) S:$G(U)="" U="^"
  1. ;
  1. ; Check for the existence of the HL7 event
  1. I $G(EVENT)="" S MSTEXT="HL7 event is required" G EXBAD
  1. ;
  1. ; Check for the existence of the name/value pair
  1. I $G(PAIR)="" S MSTEXT="Name/value pair(s) is required" G EXBAD
  1. ;
  1. ; Retrieve the HL7 Message Type and the HL7 Event Type
  1. S MSTY=$P($G(EVENT),U,1),EVTY=$P($G(EVENT),U,2)
  1. ;
  1. ; Validate the HL7 Message type
  1. I MSTY="" S MSTEXT="HL7 Message Type is required" G EXBAD
  1. ;
  1. ; Validate the HL7 Event type
  1. I EVTY="" S MSTEXT="HL7 Event Type is required" G EXBAD
  1. ;
  1. ; Get the default Requestor IEN or '1' if not set up
  1. S REQIEN=$O(^VDEFHL7(579.1,"C","Y",0)) S:REQIEN="" REQIEN=1
  1. ;
  1. ; Retrieve Requestor data and see if Requestor is enabled
  1. S DATA=$G(^VDEFHL7(579.1,REQIEN,0)) I $P(DATA,U,5)="I" D G EXBAD
  1. . S MSTEXT="VDEF HL7 messaging disabled for this Requestor"
  1. ;
  1. ; Get the Request Queue IEN for this Requestor
  1. S QUEIEN=$P(DATA,U,4) I 'QUEIEN S MSTEXT="Could not get a valid Request Queue" G EXBAD
  1. ;
  1. ; Get the Destination IEN for this Requestor
  1. S DESTIEN=$P(DATA,U,3) I 'DESTIEN S MSTEXT="No Destination for this Requestor" G EXBAD
  1. ;
  1. ; Validate Name/Value Pair
  1. I $P($P(PAIR,U),"=",1)'="SUBTYPE"!($P($P(PAIR,U,2),"=",1)'="IEN") D G EXBAD
  1. . S MSTEXT="Invalid Name/Value Pair"
  1. S SUBTYPE=$P($P(PAIR,U),"=",2),NVPIEN=$P($P(PAIR,U,2),"=",2)
  1. ;
  1. ; Validate the Subtype
  1. S SUBIEN=$$FIND1^DIC(577.4,"","BX",SUBTYPE)
  1. I 'SUBIEN S MSTEXT="Invalid VDEF Subtype" G EXBAD
  1. ;
  1. ; Validate the HL7 Message and Event Types
  1. S MESIEN=$$FIND1^DIC(771.2,"","BX",MSTY)
  1. I 'MESIEN S MSTEXT="Invalid HL7 Message Type" G EXBAD
  1. S EVTYIEN=$$FIND1^DIC(779.001,,"BX",EVTY)
  1. I 'EVTYIEN S MSTEXT="Invalid HL7 Event Type" G EXBAD
  1. ;
  1. ; Validate the VDEF Event
  1. S EVENTIEN=$O(^VDEFHL7(577,"BB",MESIEN,EVTYIEN,SUBIEN,""))
  1. I 'EVENTIEN S MSTEXT="Invalid 'Message Type-Event Type-Subtype'" G EXBAD
  1. ;
  1. ; Check if this Request is for a disabled custodial package
  1. S X=$G(^VDEFHL7(577,EVENTIEN,0)),CUSTIEN=$P(X,U,9)
  1. I $P($G(^VDEFHL7(579.6,+CUSTIEN,0)),U,2)="I" D G EXBAD
  1. . S MSTEXT="Custodial package disabled for this event"
  1. ;
  1. ; Check if this VDEF API is disabled
  1. I $P(X,U,11)'="A" D G EXBAD
  1. . S MSTEXT="VDEF API "_$P(X,U,1)_" is turned off"
  1. ;
  1. ; Start filing request into ^VDEFHL7(579.3
  1. ; Lock the queue to prevent other requests from being added to it
  1. ; doesn't affect the processing of existing requests
  1. L +^VDEFHL7(579.3,QUEIEN,"ADD"):10
  1. E S MSTEXT="VDEF queuing is currently unavailable" G EXBAD
  1. ;
  1. ; Populate the Request data (579.31) for this queue
  1. S FDA(1,579.31,"+1,"_QUEIEN_",",.01)=9999 ; DINUM placeholder
  1. S FDA(1,579.31,"+1,"_QUEIEN_",",.02)="Q" ; Request status - "Q"ueued
  1. S FDA(1,579.31,"+1,"_QUEIEN_",",.03)=MSTY ; Message Type
  1. S FDA(1,579.31,"+1,"_QUEIEN_",",.04)=EVTY ; Event Type
  1. S FDA(1,579.31,"+1,"_QUEIEN_",",.06)=REQIEN ; Requestor
  1. S FDA(1,579.31,"+1,"_QUEIEN_",",.07)=DESTIEN ; Destination
  1. D NOW^%DTC S FDA(1,579.31,"+1,"_QUEIEN_",",.08)=% ; DTS when request was added
  1. S FDA(1,579.31,"+1,"_QUEIEN_",",.18)=EVENTIEN ; VDEF Event IEN
  1. D UPDATE^DIE("","FDA(1)","IENROOT","ERR")
  1. S RQIEN=$G(IENROOT(1)) ; Get the assigned Request entry IEN
  1. ;
  1. ; Lock this queue entry to prevent the Request Processor from
  1. ; retrieving an incomplete Request
  1. L +^VDEFHL7(579.3,QUEIEN,RQIEN)
  1. L -^VDEFHL7(579.3,QUEIEN,"ADD") ; Release the queue "ADD" lock
  1. ;
  1. ; Update the DINUM field with the IEN value for this Request
  1. S FDA(1,579.31,RQIEN_","_QUEIEN_",",.01)=RQIEN D FILE^DIE("","FDA(1)","ERR(2)")
  1. ;
  1. ; Set up the name value pairs multiple (579.311)
  1. F VDI=1,2 D
  1. . S FDA(1,579.311,"+"_VDI_","_RQIEN_","_QUEIEN_",",.01)=VDI
  1. . S FDA(1,579.311,"+"_VDI_","_RQIEN_","_QUEIEN_",",.02)=$P(PAIR,U,VDI)
  1. D UPDATE^DIE("","FDA(1)","","ERR")
  1. ;
  1. ; Set up the Dynamic Adressing multiple, if passed in
  1. S (VDI,DATA)="",CNT=0 F S VDI=$O(DYNAMIC("LINKS",VDI)) Q:'VDI D
  1. . ; CNT and VDI may be different since the "LINKS" array may be sparse
  1. . S DATA=$G(DYNAMIC("LINKS",VDI)),CNT=CNT+1
  1. . S FDA(1,579.313,"+"_CNT_","_RQIEN_","_QUEIEN_",",.01)=VDI
  1. . S FDA(1,579.313,"+"_CNT_","_RQIEN_","_QUEIEN_",",.02)=DATA
  1. ;
  1. ; File Dynamic Addressing information
  1. I $D(FDA) D UPDATE^DIE("","FDA(1)","","ERR")
  1. L -^VDEFHL7(579.3,QUEIEN,RQIEN) ; Release the lock on this Request
  1. S MSTEXT="Message "_MSTY_", Event "_EVTY_", Subtype "_SUBTYPE_" queued for processing"
  1. EXIT Q 1 ; Good exit
  1. EXBAD Q 0 ; Bad, bad exit
  1. ;
  1. ; Function to set up a Request Processor Scheduling Rule
  1. SCHEDULE(Q,H) ;
  1. N HT,SIEN,NZ,DOW,STM,ETM
  1. I $G(Q)="" Q ""
  1. I $G(H)="" S H=$H
  1. S DOW=H-2#7,SIEN=0,HT=0
  1. F S SIEN=$O(^VDEFHL7(579.3,Q,2,SIEN)) Q:'SIEN D Q:HT'=0
  1. . S NZ=^VDEFHL7(579.3,Q,2,SIEN,0)
  1. . Q:$P(NZ,U,2)'=DOW
  1. . S STM=$P(NZ,U,4),ETM=$P(NZ,U,5)
  1. . S STM=$TR(STM,":- "),STM=$E(STM,1,2)*60+$E(STM,3,4)*60+$E(STM,5,6)
  1. . S ETM=$TR(ETM,":- "),ETM=$E(ETM,1,2)*60+$E(ETM,3,4)*60+$E(ETM,5,6)
  1. . I $P(H,",",2)'<STM,$P(H,",",2)'>ETM S HT=$P(NZ,U,3)
  1. I HT'=0 Q HT_U_(ETM-$P(H,",",2))
  1. Q ""
  1. ;
  1. TIMECK(T) N H,M,S I T?4.6N S H=+$E(T,1,2),M=+$E(T,3,4),S=+$E(T,5,6)
  1. E I T[":" S H=+$P(T,":"),M=+$P(T,":",2),S=+$P(T,":",3)
  1. E I T["-" S H=+$P(T,"-"),M=+$P(T,"-",2),S=+$P(T,"-",3)
  1. E I T[" " S H=+$P(T," "),M=+$P(T," ",2),S=+$P(T," ",3)
  1. E Q 0
  1. I H<24,M<60,S<60 Q 1
  1. Q 0
  1. ;
  1. REQUEUE(Q,X) ; Requeue Checked Out requests.
  1. ; Change the status of all "C" entries in a Request Queue to "Q".
  1. ; If ZTQUEUED not set, run this interactively.
  1. ; Input - Request Queue IEN
  1. ; Output - 0 = no requests requeued
  1. ; 1 = requests weere requeued
  1. S X=0
  1. I $G(Q)="" W:'$D(ZTQUEUED) !,"Invalid queue IEN" Q
  1. ;
  1. ; Quit if no requests are Checked Out
  1. I $O(^VDEFHL7(579.3,"C","C",0))="" W:'$D(ZTQUEUED) !,"No Requests in Checked Out status" Q
  1. ;
  1. ; Get Queue
  1. N QUE S QUE=$P($G(^VDEFHL7(579.3,Q,0)),U)
  1. I QUE="" W:'$D(ZTQUEUED) !,"Invalid queue" Q
  1. G REQUEUE1:$D(ZTQUEUED)
  1. K DIR S DIR(0)="Y",DIR("A")="Are you sure you want to continue",DIR("B")="No"
  1. W !,"This action will reset all entries in the '"_QUE_"' queue to 'Q'ueued."
  1. D ^DIR I Y=0 W !,"Entries not reset." Q
  1. REQUEUE1 N FDA,IEN,MSG S IEN=""
  1. F S IEN=$O(^VDEFHL7(579.3,"C","C",Q,IEN)) Q:'IEN D
  1. . ;
  1. . ; If request has not had an alert yet or can't be locked,
  1. . ; don't requeue it.
  1. . Q:$$GET1^DIQ(579.31,IEN_","_Q_",",.15,"I")=""
  1. . L +^VDEFHL7(579.3,Q,IEN):1 Q:'$T
  1. . ;
  1. . ; Change status to "Q" (queued up) and delete
  1. . ; the old check out date/time and alert date/time
  1. . ; and error message
  1. . K FDA,MSG S FDA(579.31,IEN_","_Q_",",.02)="Q"
  1. . S FDA(579.31,IEN_","_Q_",",.15)="@"
  1. . S FDA(579.31,IEN_","_Q_",",.09)="@"
  1. . D FILE^DIE(,"FDA","MSG")
  1. . K ^VDEFHL7(579.3,Q,1,IEN,"ERRMSG")
  1. . L -^VDEFHL7(579.3,Q,IEN)
  1. . S X=1
  1. W:'$D(ZTQUEUED) !,"Entries reset to 'Q'ueued status for "_QUE_"."
  1. Q
  1. ;
  1. ; Requeue Errored Out requests.
  1. ; Change the status of all "E" entries in a Request Queue to "Q".
  1. ; If ZTQUEUED not set, run this interactively.
  1. RQERR(Q,X) ;
  1. S X=0
  1. I $G(Q)="" W:'$D(ZTQUEUED) !,"Invalid queue IEN" Q
  1. ;
  1. ; Quit if no requests are Errored Out
  1. I $O(^VDEFHL7(579.3,"C","E",0))="" W:'$D(ZTQUEUED) !,"No Requests in Errored Out status" Q
  1. ;
  1. ; Get Queue
  1. N QUE S QUE=$P($G(^VDEFHL7(579.3,Q,0)),U)
  1. I QUE="" W:'$D(ZTQUEUED) !,"Invalid queue" Q
  1. G RQERR1:$D(ZTQUEUED)
  1. K DIR S DIR(0)="Y",DIR("A")="Are you sure you want to continue",DIR("B")="No"
  1. W !,"This action resets all Errored Out entries in the '"_QUE_"' queue to 'Q'ueued."
  1. D ^DIR I Y=0 W !,"Entries not reset." Q
  1. RQERR1 N FDA,IEN,MSG S IEN=""
  1. F S IEN=$O(^VDEFHL7(579.3,"C","E",Q,IEN)) Q:'IEN D
  1. . L +^VDEFHL7(579.3,Q,IEN):1 Q:'$T
  1. . ;
  1. . ; Fix the actual status in the record if it's not "E".
  1. . I $$GET1^DIQ(579.31,IEN_","_Q_",",.02,"I")'="E" D
  1. .. K FDA,MSG S FDA(579.31,IEN_","_Q_",",.02)="E"
  1. .. D FILE^DIE(,"FDA","MSG")
  1. . ;
  1. . ; Change status to "Q" (queued up) and delete
  1. . ; the old check out date/time and alert date/time
  1. . ; and error message
  1. . K FDA,MSG S FDA(579.31,IEN_","_Q_",",.02)="Q"
  1. . S FDA(579.31,IEN_","_Q_",",.15)="@"
  1. . S FDA(579.31,IEN_","_Q_",",.09)="@"
  1. . D FILE^DIE(,"FDA","MSG")
  1. . K ^VDEFHL7(579.3,Q,1,IEN,"ERRMSG")
  1. . L -^VDEFHL7(579.3,Q,IEN)
  1. . S X=1
  1. W:'$D(ZTQUEUED) !,"Entries reset to 'Q'ueued status for "_QUE_"."
  1. Q