source: BMXNET_RPMS_dotNET_UTILITIES-BMX/trunk/m/BMXRPC.m@ 1209

Last change on this file since 1209 was 1209, checked in by Sam Habiel, 13 years ago

BMXMON fix; updated all routines to v 2.31

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