1 | BMXRPC ; IHS/OIT/HMW - BMX REMOTE PROCEDURE CALLS ;
|
---|
2 | ;;2.1;BMX;;Jul 26, 2009
|
---|
3 | ;;Stolen from:* MICHAEL REMILLARD, DDS * ALASKA NATIVE MEDICAL CENTER *
|
---|
4 | ;; GENERIC LOOKUP UTILITY FOR RETURNING MATCHING RECORDS
|
---|
5 | ;; OR TABLES TO RPC'S.
|
---|
6 | ;
|
---|
7 | ; *** NOTE: I have discovered a number of cases where these calls
|
---|
8 | ; produce errors (with error messages to IO) or simply
|
---|
9 | ; do not work correctly. ANY CALL to this utility
|
---|
10 | ; should be thoroughly tested in the M environment
|
---|
11 | ; before being used as an RPC.
|
---|
12 | ;
|
---|
13 | ;----------
|
---|
14 | LOOKUP(BMXGBL,BMXFL,BMXFLDS,BMXFLG,BMXIN,BMXMX,BMXIX,BMXSCR,BMXMC) ;EP
|
---|
15 | ;---> Places matching records from requested file into a
|
---|
16 | ;---> result global, ^BMXTEMP($J). The exact global name
|
---|
17 | ;---> is returned in the first parameter (BMXGBL).
|
---|
18 | ;---> Records are returned one per node in the result global.
|
---|
19 | ;---> Each record is terminated with a $C(30), for parsing out
|
---|
20 | ;---> on the VB side, since the Broker concatenates all nodes
|
---|
21 | ;---> into a single string when passing the data out of M.
|
---|
22 | ;---> Requested fields within records are delimited by "^".
|
---|
23 | ;---> NOTE: The first "^"-piece of every node is the IEN of
|
---|
24 | ;---> that entry in its file; the requested fields follow.
|
---|
25 | ;---> The final record (node) contains Error Delimiter,
|
---|
26 | ; $C(31)_$C(31), followed by error text, if any.
|
---|
27 | ;
|
---|
28 | ;---> Parameters:
|
---|
29 | ; 1 - BMXGBL (ret) Name of result global for Broker.
|
---|
30 | ; 2 - BMXFL (req) File for lookup.
|
---|
31 | ; 3 - BMXFLDS (opt) Fields to return w/each entry.
|
---|
32 | ; 4 - BMXFLG (opt) Flags in DIC(0); If null, "M" is sent.
|
---|
33 | ; 5 - BMXIN (opt) Input to match on (see Algorithm below).
|
---|
34 | ; 6 - BMXMX (opt) Maximum number of entries to return.
|
---|
35 | ; 7 - BMXIX (opt) Indexes to search.
|
---|
36 | ; 8 - BMXSCR (opt) Screen/filter (M code).
|
---|
37 | ; 9 - BMXMC (opt) Mixed Case: 1=mixed case, 0=no change.
|
---|
38 | ; (Converts data in uppercase to mixed case.)
|
---|
39 | ;
|
---|
40 | ;---> Set variables, kill temp globals.
|
---|
41 | N (BMXGBL,BMXFL,BMXFLDS,BMXFLG,BMXIN,BMXMX,BMXIX,BMXSCR,BMXMC)
|
---|
42 | S BMX31=$C(31)_$C(31)
|
---|
43 | S BMXGBL="^BMXTEMP("_$J_")",BMXERR="",U="^"
|
---|
44 | K ^BMXTMP($J),^BMXTEMP($J)
|
---|
45 | ;
|
---|
46 | ;---> If file number not provided, return error.
|
---|
47 | I '$G(BMXFL) D ERROUT("File number not provided.",1) Q
|
---|
48 | ;
|
---|
49 | ;---> If no fields provided, pass .01.
|
---|
50 | ;---> IEN will always be the first piece of data returned.
|
---|
51 | ;---> NOTE: If .01 is NOT included, but the Index to lookup on is
|
---|
52 | ;---> NOT on the .01, then the .01 will be returned
|
---|
53 | ;---> automatically as the second ^-piece of data in the
|
---|
54 | ;---> Result Global.
|
---|
55 | ;---> So it would be: IEN^.01^requested fields...
|
---|
56 | I $G(BMXFLDS)="" S BMXFLDS=".01"
|
---|
57 | ;
|
---|
58 | ;---> If no index or flag provided, set flag="M".
|
---|
59 | I $G(BMXFLG)="" D
|
---|
60 | .I $G(BMXIX)="" S BMXFLG="M" Q
|
---|
61 | .S BMXFLG=""
|
---|
62 | ;
|
---|
63 | ;---> If no Maximum Number provided, set it to 200.
|
---|
64 | I '$G(BMXMX) S BMXMX=200
|
---|
65 | ;
|
---|
66 | ;---> Define index and screen.
|
---|
67 | S:'$D(BMXIX) BMXIX=""
|
---|
68 | S:'$D(BMXSCR) BMXSCR=""
|
---|
69 | ;
|
---|
70 | ;---> Set Target Global for output and errors.
|
---|
71 | S BMXG="^BMXTMP($J)"
|
---|
72 | ;
|
---|
73 | ;---> If Mixed Case not set, set to No Change.
|
---|
74 | I '$D(BMXMC) S BMXMC=0
|
---|
75 | ;
|
---|
76 | ;---> Silent Fileman call.
|
---|
77 | D
|
---|
78 | .I $G(BMXIN)="" D Q
|
---|
79 | ..D LIST^DIC(BMXFL,,BMXFLDS,,BMXMX,0,,BMXIX,BMXSCR,,BMXG,BMXG)
|
---|
80 | .D FIND^DIC(BMXFL,,BMXFLDS,BMXFLG,BMXIN,BMXMX,BMXIX,BMXSCR,,BMXG,BMXG)
|
---|
81 | ;
|
---|
82 | D WRITE
|
---|
83 | Q
|
---|
84 | ;
|
---|
85 | ;
|
---|
86 | ;----------
|
---|
87 | WRITE ;EP
|
---|
88 | ;---> Collect data for matching records and write in result global.
|
---|
89 | ;
|
---|
90 | ;---> First, check for errors.
|
---|
91 | ;---> If errors exist, write them and quit.
|
---|
92 | N I,N,X
|
---|
93 | I $D(^BMXTMP($J,"DIERR")) I $O(^("DIERR",0)) D Q
|
---|
94 | .S N=0,X=""
|
---|
95 | .F S N=$O(^BMXTMP($J,"DIERR",N)) Q:'N D
|
---|
96 | ..N M S M=0
|
---|
97 | ..F S M=$O(^BMXTMP($J,"DIERR",N,"TEXT",M)) Q:'M D
|
---|
98 | ...S X=X_^BMXTMP($J,"DIERR",N,"TEXT",M)_" "
|
---|
99 | .D ERROUT(X,1)
|
---|
100 | ;
|
---|
101 | ;
|
---|
102 | ;---> Write Field Names
|
---|
103 | S $P(ASDX,"^",1)="IEN"
|
---|
104 | F ASDC=1:1:$L(BMXFLDS,";") D
|
---|
105 | . S ASDXFNUM=$P(BMXFLDS,";",ASDC)
|
---|
106 | . S ASDXFNAM=$P(^DD(BMXFL,ASDXFNUM,0),"^")
|
---|
107 | . S:ASDXFNAM="" ASDXFNAM="UNKNOWN"_ASDC
|
---|
108 | . S $P(ASDX,"^",ASDC+1)=ASDXFNAM
|
---|
109 | S ^BMXTEMP($J,1)=ASDX_$C(30)
|
---|
110 | ;---> Write valid results.
|
---|
111 | ;---> Loop through the IEN node (...2,N) of the temp global.
|
---|
112 | N I,N,X S N=0
|
---|
113 | F I=2:1 S N=$O(^BMXTMP($J,"DILIST",2,N)) Q:'N D
|
---|
114 | .;---> Always set first piece of X=IEN of entry.
|
---|
115 | .S X=^BMXTMP($J,"DILIST",2,N)
|
---|
116 | .;
|
---|
117 | .;---> Collect other fields and concatenate to X.
|
---|
118 | .N M S M=0
|
---|
119 | .F S M=$O(^BMXTMP($J,"DILIST","ID",N,M)) Q:'M D
|
---|
120 | ..S X=X_U_^BMXTMP($J,"DILIST","ID",N,M)
|
---|
121 | .;
|
---|
122 | .;---> Convert data to mixed case if BMXMC=1.
|
---|
123 | .S:BMXMC X=$$T^BMXTRS(X)
|
---|
124 | .;
|
---|
125 | .;---> Set data in result global.
|
---|
126 | .S ^BMXTEMP($J,I)=X_$C(30)
|
---|
127 | ;
|
---|
128 | ;---> If no results, report it as an error.
|
---|
129 | D:'$O(^BMXTEMP($J,0))
|
---|
130 | .I BMXIN]"" S BMXERR="No entry matches """_BMXIN_"""." Q
|
---|
131 | .S BMXERR="Either the lookup file is empty"
|
---|
132 | .S BMXERR=BMXERR_" or all entries are screened (software error)."
|
---|
133 | ;
|
---|
134 | ;---> Tack on Error Delimiter and any error.
|
---|
135 | S ^BMXTEMP($J,I)=BMX31_BMXERR
|
---|
136 | Q
|
---|
137 | ;
|
---|
138 | ;
|
---|
139 | ;----------
|
---|
140 | ERROUT(BMXERR,I) ;EP
|
---|
141 | ;---> Save next line for Error Code File if ever used.
|
---|
142 | ;---> If necessary, use I>1 to avoid overwriting valid data.
|
---|
143 | S:'$G(I) I=1
|
---|
144 | S ^BMXTEMP($J,I)=BMX31_BMXERR
|
---|
145 | Q
|
---|
146 | ;
|
---|
147 | ;
|
---|
148 | PASSERR(BMXGBL,BMXERR) ;EP
|
---|
149 | ;---> If the RPC routine calling the BMX Generic Lookup above
|
---|
150 | ;---> detects a specific error prior to the call and wants to pass
|
---|
151 | ;---> that error in the result global rather than a generic error,
|
---|
152 | ;---> then a call to this function (PASSERR) can be made.
|
---|
153 | ;---> This call will store the error text passed in the result global.
|
---|
154 | ;---> The calling routine should then quit (abort its call to the
|
---|
155 | ;---> BMX Generic Lookup function above).
|
---|
156 | ;
|
---|
157 | ;---> Parameters:
|
---|
158 | ; 1 - BMXGBL (ret) Name of result global for Broker.
|
---|
159 | ; 2 - BMXERR (req) Text of error to be stored in result global.
|
---|
160 | ;
|
---|
161 | S:$G(BMXERR)="" BMXERR="Error not passed (software error)."
|
---|
162 | ;
|
---|
163 | N BMX31 S BMX31=$C(31)_$C(31)
|
---|
164 | K ^BMXTMP($J),^BMXTEMP($J)
|
---|
165 | S BMXGBL="^BMXTEMP("_$J_")"
|
---|
166 | S ^BMXTEMP($J,1)=BMX31_BMXERR
|
---|
167 | Q
|
---|