source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLCSQUE.m@ 1226

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

initial load of WorldVistAEHR

File size: 4.2 KB
Line 
1HLCSQUE ;ALB/MFK HL7 UTILITY FUNCTIONS - 10/4/94 11AM ;05/08/2000 11:07
2 ;;1.6;HEALTH LEVEL SEVEN;**14,61,59**;Oct 13, 1995
3ENQUEUE(IEN,HLDIR) ;Assign a message for queue entry
4 ; INPUT: IEN - Internal Entry Number for file 870 - HL7 QUEUE
5 ; HLDIR - Direction of queue (IN/OUT)
6 ; OUTPUT: BEG - Location in the queue to stuff the message
7 ; -1 - Error
8 ; NOTE: All the locks have been commented out.
9 N FRONT,BACK,DIC,DA,X,BP,FP,REC,DINUM,ENTRY,Y,RETURN,BPOINTER
10 N FPOINTER,HLCNT
11 ; Make sure required variables were given
12 S IEN=$G(IEN)
13 Q:(IEN="") "-1^Queue not given"
14 I +IEN<1 S IEN=$O(^HLCS(870,"B",IEN,""))
15 Q:(IEN="") "-1^Invalid queue"
16 S HLDIR=$G(HLDIR)
17 S HLDIR=$S(HLDIR="1":"IN",HLDIR=2:"OUT",1:HLDIR)
18 I HLDIR'="IN",(HLDIR'="OUT") Q "-1^Invalid Direction"
19 I HLDIR="IN" S HLDIR=1,BPOINTER="IN QUEUE BACK POINTER",FPOINTER="IN QUEUE FRONT POINTER"
20 I HLDIR="OUT" S HLDIR=2,BPOINTER="OUT QUEUE BACK POINTER",FPOINTER="OUT QUEUE FRONT POINTER"
21 F L +^HLCS(870,IEN,FPOINTER):1 Q:$T H 1
22 S FRONT=$G(^HLCS(870,IEN,FPOINTER))
23 L -^HLCS(870,IEN,FPOINTER)
24 D DELETE^HLCSQUE1(IEN,HLDIR,FRONT)
25 F L +^HLCS(870,IEN,BPOINTER):1 Q:$T H 1
26 S BACK=$G(^HLCS(870,IEN,BPOINTER))
27 ; Set up DICN call
28 S DIC="^HLCS(870,"_IEN_","_HLDIR_","
29 S ENTRY=HLDIR+18
30 S DIC(0)="LNX",DA(1)=IEN,DIC("P")=$P(^DD(870,ENTRY,0),"^",2)
31 S (DINUM,X)=BACK+1
32 ; Create Record
33 K DD,DO
34 F L +^HLCS(870,IEN,HLDIR):1 Q:$T H 1
35 F HLCNT=0:1 D Q:Y>0 H HLCNT
36 . D FILE^DICN
37 S REC=$P(Y,"^",1)
38 ; Set the 'status' to 'S' for stub
39 S $P(^HLCS(870,IEN,HLDIR,REC,0),"^",2)="S"
40 S ^HLCS(870,IEN,BPOINTER)=BACK+1
41 ; Put queue pointers back
42 S RETURN=IEN_"^"_REC
43EXIT1 ; Unlock and return results
44 L -^HLCS(870,IEN,HLDIR)
45 L -^HLCS(870,IEN,BPOINTER)
46 K IEN,HLDIR
47 Q RETURN
48DEQUEUE(IEN,HLDIR) ;Release the next message from the queue
49 N MSG,RETURN,FRONT,FP,BACK,POINTER
50 S IEN=$G(IEN)
51 Q:(IEN="") "-1^Queue not given"
52 I +IEN<1 S IEN=$O(^HLCS(870,"B",IEN,""))
53 Q:(IEN="") "-1^Invalid queue"
54 S HLDIR=$G(HLDIR)
55 S HLDIR=$S(HLDIR="1":"IN",HLDIR=2:"OUT",1:HLDIR)
56 I HLDIR'="IN",(HLDIR'="OUT") Q "-1^Invalid Direction"
57 I HLDIR="IN" S HLDIR=1,POINTER="IN QUEUE FRONT POINTER"
58 I HLDIR="OUT" S HLDIR=2,POINTER="OUT QUEUE FRONT POINTER"
59 F L +^HLCS(870,IEN,POINTER):1 Q:$T H 1
60 S FRONT=$G(^HLCS(870,IEN,POINTER))
61 L -^HLCS(870,IEN,POINTER)
62 D DELETE^HLCSQUE1(IEN,HLDIR,FRONT)
63 ;If queue empty or "Stub" record don't dequeue
64 F L +^HLCS(870,IEN,HLDIR,FRONT+1,0):1 Q:$T H 1
65 I '$D(^HLCS(870,IEN,HLDIR,FRONT+1,0)) S RETURN="-1^NO NEXT RECORD" G EXIT2
66 I ($P($G(^HLCS(870,IEN,HLDIR,FRONT+1,0)),"^",2)'="P") S RETURN="-1^STUB" G EXIT2
67 ; for status "P"
68 S ^HLCS(870,IEN,POINTER)=FRONT+1
69 S RETURN=IEN_"^"_(FRONT+1)
70 ; Return success
71EXIT2 ;
72 L -^HLCS(870,IEN,HLDIR,FRONT+1,0)
73 L -^HLCS(870,IEN,POINTER)
74 Q RETURN
75CLEARQUE(IEN,HLDIR) ;Empty an entire queue
76 ; IEN - Entry number for queue - can be name from "B" X-ref
77 ; HLDIR - Can be "IN", "OUT", 1 or 2.
78 ; output: 0 for success
79 ; -1^error for error
80 N MSG,X,ERR,FP,BP
81 ;NOTE: this is not needed to initialize a queue
82 ; enqueue will set up (?) a new queue
83 ; Make sure that required variables exist
84 S IEN=$G(IEN)
85 Q:(IEN="") "-1^Internal Entry Number missing"
86 I +IEN<1 S IEN=$O(^HLCS(870,"B",IEN,""))
87 Q:(IEN="") "-1^Invalid IEN"
88 ; Convert direction to a number
89 S HLDIR=$G(HLDIR)
90 Q:(HLDIR'="IN")&(HLDIR'="OUT")&(HLDIR'=1)&(HLDIR'=2) "-1^Invalid direction"
91 S HLDIR=$S(HLDIR="IN":1,HLDIR="OUT":2,HLDIR=2:2,1:1)
92 ; If in queue, set front pointer to 6, out pointer gets set to 8
93 I HLDIR=1 S FP="IN QUEUE FRONT POINTER",BP="IN QUEUE BACK POINTER"
94 I HLDIR=2 S FP="OUT QUEUE FRONT POINTER",BP="OUT QUEUE BACK POINTER"
95 S MSG=0
96 W !
97 ; Loop through and delete messages
98 F S MSG=$O(^HLCS(870,IEN,HLDIR,MSG)) Q:(MSG'>0) D
99 .S ERR=$$DELMSG^HLCSQUE1(IEN,HLDIR,MSG) W "."
100 .I ERR W ERR,!
101 ; Clear front and back pointers
102 S ^HLCS(870,IEN,FP)=0
103 S ^HLCS(870,IEN,BP)=0
104 ;K IEN,HLDIR
105 Q 0
106 ;
107PUSH(HLDOUT0,HLDOUT1) ;-- Place message back on queue
108 ; INPUT - HLDOUT0 IEN of file 870
109 ; HLDOUT1 IEN of Out Multiple
110 ; OUTPUT- NONE
111 ;
112 ;-- exit if not vaild variables
113 I 'HLDOUT0!'HLDOUT1 G PUSHQ
114 ;-- exit if global does not already exist
115 I '$D(^HLCS(870,HLDOUT0,"OUT QUEUE FRONT POINTER")) G PUSHQ
116 S ^HLCS(870,HLDOUT0,"OUT QUEUE FRONT POINTER")=(HLDOUT1-1)
117PUSHQ Q
118 ;
Note: See TracBrowser for help on using the repository browser.