source: WorldVistAEHR/trunk/r/VDEF-VDEF/VDEFQM.m@ 1578

Last change on this file since 1578 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 8.9 KB
Line 
1VDEFQM ;INTEGIC/AM & BPOIFO/JG - VDEF API ; 21 Dec 2005 11:38 AM
2 ;;1.0;VDEF;**3**;Dec 28, 2004
3 ;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5 ; IA's: #4271 - Lookup to file #771.2
6 ; #4321 - Lookup to file #779.001
7 ;
8 Q ; No bozos
9 ;
10 ; Validates and places a request in the VDEF queue
11QUEUE(EVENT,PAIR,MSTEXT,REQIEN,DYNAMIC) ;
12 ; EVENT = HL7 event in the form Event Type^Message Type (e.g. ADT^A28)
13 ; PAIR = Name/value pairs uniquely identifying the IEN
14 ; (e.g. SUBTYPE="CHEM"^IEN=1234)
15 ; MSTEXT = Returned text message, passed by reference
16 ; REQIEN = Requestor IEN in file 579.1, only valued for solicited
17 ; requests
18 ; DYNAMIC = Dynamic Addressing array in nodes DYNAMIC("LINKS",1-n)
19 ;
20 N CNT,CUSTIEN,DATA,DESTIEN,ERR,EVENTIEN,EVTY,EVTYIEN,FDA,VDI,IENROOT
21 N MESIEN,MSTY,OUTPUT,QUEIEN,RQIEN,SUBTYPE,SUBIEN,NVPIEN
22 N D0,DA,DH,DI,DIC,DIE,DIK,DIKRFIL,DIN,DIROOT,DR,X,Y
23 S MSTEXT="",REQIEN=$G(REQIEN) S:$G(U)="" U="^"
24 ;
25 ; Check for the existence of the HL7 event
26 I $G(EVENT)="" S MSTEXT="HL7 event is required" G EXBAD
27 ;
28 ; Check for the existence of the name/value pair
29 I $G(PAIR)="" S MSTEXT="Name/value pair(s) is required" G EXBAD
30 ;
31 ; Retrieve the HL7 Message Type and the HL7 Event Type
32 S MSTY=$P($G(EVENT),U,1),EVTY=$P($G(EVENT),U,2)
33 ;
34 ; Validate the HL7 Message type
35 I MSTY="" S MSTEXT="HL7 Message Type is required" G EXBAD
36 ;
37 ; Validate the HL7 Event type
38 I EVTY="" S MSTEXT="HL7 Event Type is required" G EXBAD
39 ;
40 ; Get the default Requestor IEN or '1' if not set up
41 S REQIEN=$O(^VDEFHL7(579.1,"C","Y",0)) S:REQIEN="" REQIEN=1
42 ;
43 ; Retrieve Requestor data and see if Requestor is enabled
44 S DATA=$G(^VDEFHL7(579.1,REQIEN,0)) I $P(DATA,U,5)="I" D G EXBAD
45 . S MSTEXT="VDEF HL7 messaging disabled for this Requestor"
46 ;
47 ; Get the Request Queue IEN for this Requestor
48 S QUEIEN=$P(DATA,U,4) I 'QUEIEN S MSTEXT="Could not get a valid Request Queue" G EXBAD
49 ;
50 ; Get the Destination IEN for this Requestor
51 S DESTIEN=$P(DATA,U,3) I 'DESTIEN S MSTEXT="No Destination for this Requestor" G EXBAD
52 ;
53 ; Validate Name/Value Pair
54 I $P($P(PAIR,U),"=",1)'="SUBTYPE"!($P($P(PAIR,U,2),"=",1)'="IEN") D G EXBAD
55 . S MSTEXT="Invalid Name/Value Pair"
56 S SUBTYPE=$P($P(PAIR,U),"=",2),NVPIEN=$P($P(PAIR,U,2),"=",2)
57 ;
58 ; Validate the Subtype
59 S SUBIEN=$$FIND1^DIC(577.4,"","BX",SUBTYPE)
60 I 'SUBIEN S MSTEXT="Invalid VDEF Subtype" G EXBAD
61 ;
62 ; Validate the HL7 Message and Event Types
63 S MESIEN=$$FIND1^DIC(771.2,"","BX",MSTY)
64 I 'MESIEN S MSTEXT="Invalid HL7 Message Type" G EXBAD
65 S EVTYIEN=$$FIND1^DIC(779.001,,"BX",EVTY)
66 I 'EVTYIEN S MSTEXT="Invalid HL7 Event Type" G EXBAD
67 ;
68 ; Validate the VDEF Event
69 S EVENTIEN=$O(^VDEFHL7(577,"BB",MESIEN,EVTYIEN,SUBIEN,""))
70 I 'EVENTIEN S MSTEXT="Invalid 'Message Type-Event Type-Subtype'" G EXBAD
71 ;
72 ; Check if this Request is for a disabled custodial package
73 S X=$G(^VDEFHL7(577,EVENTIEN,0)),CUSTIEN=$P(X,U,9)
74 I $P($G(^VDEFHL7(579.6,+CUSTIEN,0)),U,2)="I" D G EXBAD
75 . S MSTEXT="Custodial package disabled for this event"
76 ;
77 ; Check if this VDEF API is disabled
78 I $P(X,U,11)'="A" D G EXBAD
79 . S MSTEXT="VDEF API "_$P(X,U,1)_" is turned off"
80 ;
81 ; Start filing request into ^VDEFHL7(579.3
82 ; Lock the queue to prevent other requests from being added to it
83 ; doesn't affect the processing of existing requests
84 L +^VDEFHL7(579.3,QUEIEN,"ADD"):10
85 E S MSTEXT="VDEF queuing is currently unavailable" G EXBAD
86 ;
87 ; Populate the Request data (579.31) for this queue
88 S FDA(1,579.31,"+1,"_QUEIEN_",",.01)=9999 ; DINUM placeholder
89 S FDA(1,579.31,"+1,"_QUEIEN_",",.02)="Q" ; Request status - "Q"ueued
90 S FDA(1,579.31,"+1,"_QUEIEN_",",.03)=MSTY ; Message Type
91 S FDA(1,579.31,"+1,"_QUEIEN_",",.04)=EVTY ; Event Type
92 S FDA(1,579.31,"+1,"_QUEIEN_",",.06)=REQIEN ; Requestor
93 S FDA(1,579.31,"+1,"_QUEIEN_",",.07)=DESTIEN ; Destination
94 D NOW^%DTC S FDA(1,579.31,"+1,"_QUEIEN_",",.08)=% ; DTS when request was added
95 S FDA(1,579.31,"+1,"_QUEIEN_",",.18)=EVENTIEN ; VDEF Event IEN
96 D UPDATE^DIE("","FDA(1)","IENROOT","ERR")
97 S RQIEN=$G(IENROOT(1)) ; Get the assigned Request entry IEN
98 ;
99 ; Lock this queue entry to prevent the Request Processor from
100 ; retrieving an incomplete Request
101 L +^VDEFHL7(579.3,QUEIEN,RQIEN)
102 L -^VDEFHL7(579.3,QUEIEN,"ADD") ; Release the queue "ADD" lock
103 ;
104 ; Update the DINUM field with the IEN value for this Request
105 S FDA(1,579.31,RQIEN_","_QUEIEN_",",.01)=RQIEN D FILE^DIE("","FDA(1)","ERR(2)")
106 ;
107 ; Set up the name value pairs multiple (579.311)
108 F VDI=1,2 D
109 . S FDA(1,579.311,"+"_VDI_","_RQIEN_","_QUEIEN_",",.01)=VDI
110 . S FDA(1,579.311,"+"_VDI_","_RQIEN_","_QUEIEN_",",.02)=$P(PAIR,U,VDI)
111 D UPDATE^DIE("","FDA(1)","","ERR")
112 ;
113 ; Set up the Dynamic Adressing multiple, if passed in
114 S (VDI,DATA)="",CNT=0 F S VDI=$O(DYNAMIC("LINKS",VDI)) Q:'VDI D
115 . ; CNT and VDI may be different since the "LINKS" array may be sparse
116 . S DATA=$G(DYNAMIC("LINKS",VDI)),CNT=CNT+1
117 . S FDA(1,579.313,"+"_CNT_","_RQIEN_","_QUEIEN_",",.01)=VDI
118 . S FDA(1,579.313,"+"_CNT_","_RQIEN_","_QUEIEN_",",.02)=DATA
119 ;
120 ; File Dynamic Addressing information
121 I $D(FDA) D UPDATE^DIE("","FDA(1)","","ERR")
122 L -^VDEFHL7(579.3,QUEIEN,RQIEN) ; Release the lock on this Request
123 S MSTEXT="Message "_MSTY_", Event "_EVTY_", Subtype "_SUBTYPE_" queued for processing"
124EXIT Q 1 ; Good exit
125EXBAD Q 0 ; Bad, bad exit
126 ;
127 ; Function to set up a Request Processor Scheduling Rule
128SCHEDULE(Q,H) ;
129 N HT,SIEN,NZ,DOW,STM,ETM
130 I $G(Q)="" Q ""
131 I $G(H)="" S H=$H
132 S DOW=H-2#7,SIEN=0,HT=0
133 F S SIEN=$O(^VDEFHL7(579.3,Q,2,SIEN)) Q:'SIEN D Q:HT'=0
134 . S NZ=^VDEFHL7(579.3,Q,2,SIEN,0)
135 . Q:$P(NZ,U,2)'=DOW
136 . S STM=$P(NZ,U,4),ETM=$P(NZ,U,5)
137 . S STM=$TR(STM,":- "),STM=$E(STM,1,2)*60+$E(STM,3,4)*60+$E(STM,5,6)
138 . S ETM=$TR(ETM,":- "),ETM=$E(ETM,1,2)*60+$E(ETM,3,4)*60+$E(ETM,5,6)
139 . I $P(H,",",2)'<STM,$P(H,",",2)'>ETM S HT=$P(NZ,U,3)
140 I HT'=0 Q HT_U_(ETM-$P(H,",",2))
141 Q ""
142 ;
143TIMECK(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)
144 E I T[":" S H=+$P(T,":"),M=+$P(T,":",2),S=+$P(T,":",3)
145 E I T["-" S H=+$P(T,"-"),M=+$P(T,"-",2),S=+$P(T,"-",3)
146 E I T[" " S H=+$P(T," "),M=+$P(T," ",2),S=+$P(T," ",3)
147 E Q 0
148 I H<24,M<60,S<60 Q 1
149 Q 0
150 ;
151REQUEUE(Q,X) ; Requeue Checked Out requests.
152 ; Change the status of all "C" entries in a Request Queue to "Q".
153 ; If ZTQUEUED not set, run this interactively.
154 ; Input - Request Queue IEN
155 ; Output - 0 = no requests requeued
156 ; 1 = requests weere requeued
157 S X=0
158 I $G(Q)="" W:'$D(ZTQUEUED) !,"Invalid queue IEN" Q
159 ;
160 ; Quit if no requests are Checked Out
161 I $O(^VDEFHL7(579.3,"C","C",0))="" W:'$D(ZTQUEUED) !,"No Requests in Checked Out status" Q
162 ;
163 ; Get Queue
164 N QUE S QUE=$P($G(^VDEFHL7(579.3,Q,0)),U)
165 I QUE="" W:'$D(ZTQUEUED) !,"Invalid queue" Q
166 G REQUEUE1:$D(ZTQUEUED)
167 K DIR S DIR(0)="Y",DIR("A")="Are you sure you want to continue",DIR("B")="No"
168 W !,"This action will reset all entries in the '"_QUE_"' queue to 'Q'ueued."
169 D ^DIR I Y=0 W !,"Entries not reset." Q
170REQUEUE1 N FDA,IEN,MSG S IEN=""
171 F S IEN=$O(^VDEFHL7(579.3,"C","C",Q,IEN)) Q:'IEN D
172 . ;
173 . ; If request has not had an alert yet or can't be locked,
174 . ; don't requeue it.
175 . Q:$$GET1^DIQ(579.31,IEN_","_Q_",",.15,"I")=""
176 . L +^VDEFHL7(579.3,Q,IEN):1 Q:'$T
177 . ;
178 . ; Change status to "Q" (queued up) and delete
179 . ; the old check out date/time and alert date/time
180 . ; and error message
181 . K FDA,MSG S FDA(579.31,IEN_","_Q_",",.02)="Q"
182 . S FDA(579.31,IEN_","_Q_",",.15)="@"
183 . S FDA(579.31,IEN_","_Q_",",.09)="@"
184 . D FILE^DIE(,"FDA","MSG")
185 . K ^VDEFHL7(579.3,Q,1,IEN,"ERRMSG")
186 . L -^VDEFHL7(579.3,Q,IEN)
187 . S X=1
188 W:'$D(ZTQUEUED) !,"Entries reset to 'Q'ueued status for "_QUE_"."
189 Q
190 ;
191 ; Requeue Errored Out requests.
192 ; Change the status of all "E" entries in a Request Queue to "Q".
193 ; If ZTQUEUED not set, run this interactively.
194RQERR(Q,X) ;
195 S X=0
196 I $G(Q)="" W:'$D(ZTQUEUED) !,"Invalid queue IEN" Q
197 ;
198 ; Quit if no requests are Errored Out
199 I $O(^VDEFHL7(579.3,"C","E",0))="" W:'$D(ZTQUEUED) !,"No Requests in Errored Out status" Q
200 ;
201 ; Get Queue
202 N QUE S QUE=$P($G(^VDEFHL7(579.3,Q,0)),U)
203 I QUE="" W:'$D(ZTQUEUED) !,"Invalid queue" Q
204 G RQERR1:$D(ZTQUEUED)
205 K DIR S DIR(0)="Y",DIR("A")="Are you sure you want to continue",DIR("B")="No"
206 W !,"This action resets all Errored Out entries in the '"_QUE_"' queue to 'Q'ueued."
207 D ^DIR I Y=0 W !,"Entries not reset." Q
208RQERR1 N FDA,IEN,MSG S IEN=""
209 F S IEN=$O(^VDEFHL7(579.3,"C","E",Q,IEN)) Q:'IEN D
210 . L +^VDEFHL7(579.3,Q,IEN):1 Q:'$T
211 . ;
212 . ; Fix the actual status in the record if it's not "E".
213 . I $$GET1^DIQ(579.31,IEN_","_Q_",",.02,"I")'="E" D
214 .. K FDA,MSG S FDA(579.31,IEN_","_Q_",",.02)="E"
215 .. D FILE^DIE(,"FDA","MSG")
216 . ;
217 . ; Change status to "Q" (queued up) and delete
218 . ; the old check out date/time and alert date/time
219 . ; and error message
220 . K FDA,MSG S FDA(579.31,IEN_","_Q_",",.02)="Q"
221 . S FDA(579.31,IEN_","_Q_",",.15)="@"
222 . S FDA(579.31,IEN_","_Q_",",.09)="@"
223 . D FILE^DIE(,"FDA","MSG")
224 . K ^VDEFHL7(579.3,Q,1,IEN,"ERRMSG")
225 . L -^VDEFHL7(579.3,Q,IEN)
226 . S X=1
227 W:'$D(ZTQUEUED) !,"Entries reset to 'Q'ueued status for "_QUE_"."
228 Q
Note: See TracBrowser for help on using the repository browser.