1 | C0CSOAP ; CCDCCR/GPL - SOAP WEB SERVICE utilities; 8/25/09
|
---|
2 | ;;1.0;C0C;;May 19, 2009;
|
---|
3 | ;Copyright 2008 George Lilly. Licensed under the terms of the GNU
|
---|
4 | ;General Public License See attached copy of the License.
|
---|
5 | ;
|
---|
6 | ;This program is free software; you can redistribute it and/or modify
|
---|
7 | ;it under the terms of the GNU General Public License as published by
|
---|
8 | ;the Free Software Foundation; either version 2 of the License, or
|
---|
9 | ;(at your option) any later version.
|
---|
10 | ;
|
---|
11 | ;This program is distributed in the hope that it will be useful,
|
---|
12 | ;but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | ;GNU General Public License for more details.
|
---|
15 | ;
|
---|
16 | ;You should have received a copy of the GNU General Public License along
|
---|
17 | ;with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
18 | ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
---|
19 | ;
|
---|
20 | W "This is an SOAP utility library",!
|
---|
21 | W !
|
---|
22 | Q
|
---|
23 | ;
|
---|
24 | TEST1
|
---|
25 | S url="https://ec2-75-101-247-83.compute-1.amazonaws.com:8181/ccr/CCRService?wsdl"
|
---|
26 | D GET1URL^C0CEWD2(url)
|
---|
27 | Q
|
---|
28 | ;
|
---|
29 | INITFARY(ARY) ;initialize the Fileman Field array for SOAP processing
|
---|
30 | ; ARY is passed by name
|
---|
31 | S @ARY@("XML FILE NUMBER")="178.301"
|
---|
32 | S @ARY@("BINDING SUBFILE NUMBER")="178.3014"
|
---|
33 | S @ARY@("MIME TYPE")="2.3"
|
---|
34 | S @ARY@("PROXY SERVER")="2.4"
|
---|
35 | S @ARY@("REPLY TEMPLATE")=".03"
|
---|
36 | S @ARY@("TEMPLATE NAME")=".01"
|
---|
37 | S @ARY@("TEMPLATE XML")="3"
|
---|
38 | S @ARY@("URL")="1"
|
---|
39 | S @ARY@("WSDL URL")="2"
|
---|
40 | S @ARY@("XML")="2.1"
|
---|
41 | S @ARY@("XML HEADER")="2.2"
|
---|
42 | S @ARY@("XPATH REDUCTION STRING")="2.5"
|
---|
43 | S @ARY@("CCR VARIABLE")="4"
|
---|
44 | S @ARY@("FILEMAN FIELD NAME")="1"
|
---|
45 | S @ARY@("FILEMAN FIELD NUMBER")="1.2"
|
---|
46 | S @ARY@("FILEMAN FILE POINTER")="1.1"
|
---|
47 | S @ARY@("INDEXED BY")=".05"
|
---|
48 | S @ARY@("SQLI FIELD NAME")="3"
|
---|
49 | S @ARY@("VARIABLE NAME")="2"
|
---|
50 | Q
|
---|
51 | ;
|
---|
52 | RESTID(INNAM,INFARY) ;EXTRINSIC TO RESOLVE TEMPLATE PASSED BY NAME
|
---|
53 | ; FILE IS IDENTIFIED IN FARY, PASSED BY NAME
|
---|
54 | I '$D(INFARY) D ; NO FILE ARRAY PASSED
|
---|
55 | . S INFARY="FARY"
|
---|
56 | . D INITFARY(INFARY)
|
---|
57 | N ZN,ZREF,ZR
|
---|
58 | S ZN=@INFARY@("XML FILE NUMBER")
|
---|
59 | S ZREF=$$FILEREF^C0CRNF(ZN)
|
---|
60 | S ZR=$O(@ZREF@("B",INNAM,""))
|
---|
61 | Q ZR
|
---|
62 | ;
|
---|
63 | TESTSOAP ;
|
---|
64 | ; USING ICD9 WEB SERVICE TO TEST SOAP
|
---|
65 | S G("CODE")="E*"
|
---|
66 | S G("CODELN")=3
|
---|
67 | D SOAP("GPL","ICD9","G")
|
---|
68 | Q
|
---|
69 | ;
|
---|
70 | SOAP(C0CRTN,C0CTID,C0CVA,C0CVOR,ALTXML) ; MAKES A SOAP CALL FOR
|
---|
71 | ; TEMPLATE ID C0CTID
|
---|
72 | ; RETURNS THE XML RESULT IN C0CRTN, PASSED BY NAME
|
---|
73 | ; C0CVA IS PASSED BY NAME AND IS THE VARIABLE ARRAY TO PASS TO BIND
|
---|
74 | ; C0CVOR IS THE NAME OF A VARIABLE OVERRIDE ARRAY, WHICH IS APPLIED
|
---|
75 | ; BEFORE MAPPING
|
---|
76 | ; IF ALTXML IS PASSED, BIND AND MAP WILL BE SKIPPED AND
|
---|
77 | ; ALTXML WILL BE USED INSTEAD
|
---|
78 | ;
|
---|
79 | ; ARTIFACTS SECTION
|
---|
80 | ; THE FOLLOWING WILL SET UP DEBUGGING ARTIFACTS FOR A POSSIBLE FUTURE
|
---|
81 | ; ONLINE DEBUGGER. IF DEBUG=1, VARIABLES CONTAINING INTERMEDIATE RESULTS
|
---|
82 | ; WILL NOT BE NEWED.
|
---|
83 | I $G(WSDEBUG)="" N C0CV ; CATALOG OF ARTIFACT VARIABLES AND ARRAYS
|
---|
84 | S C0CV(100,"C0CXF","XML TEMPLATE FILE NUMBER")=""
|
---|
85 | S C0CV(200,"C0CHEAD","SOAP HEADER VARIABLE NAME")=""
|
---|
86 | S C0CV(300,"HEADER","SOAP HEADER")=""
|
---|
87 | S C0CV(400,"C0CMIME","MIME TYPE")=""
|
---|
88 | S C0CV(500,"C0CURL","WS URL")=""
|
---|
89 | S C0CV(550,"C0CPURL","PROXY URL")=""
|
---|
90 | S C0CV(600,"C0CXML","XML VARIABLE NAME")=""
|
---|
91 | S C0CV(700,"XML","OUTBOUND XML")=""
|
---|
92 | S C0CV(800,"C0CRSLT","RAW XML RESULT RETURNED FROM WEB SERVICE")=""
|
---|
93 | S C0CV(900,"C0CRHDR","RETURNED HEADER")=""
|
---|
94 | S C0CV(1000,"C0CRXML","XML RESULT NORMALIZED")=""
|
---|
95 | S C0CV(1100,"C0CR","REPLY TEMPLATE")=""
|
---|
96 | S C0CV(1200,"C0CREDUX","REDUX STRING")=""
|
---|
97 | S C0CV(1300,"C0CIDX","RESULT XPATH INDEX")=""
|
---|
98 | S C0CV(1400,"C0CARY","RESULT XPATH ARRAY")=""
|
---|
99 | S C0CV(1500,"C0CNOM","RESULT DOM DOCUMENT NAME")=""
|
---|
100 | S C0CV(1600,"C0CID","RESULT DOM ID")=""
|
---|
101 | I $G(DEBUG)'="" G NOTNEW ; SKIP NEWING THE VARIABLES IF IN DEBUG
|
---|
102 | N ZI,ZJ S ZI=""
|
---|
103 | NEW
|
---|
104 | S ZI=$O(C0CV(ZI))
|
---|
105 | S ZJ=$O(C0CV(ZI,"")) ; SET UP NEW COMMAND
|
---|
106 | ;W ZJ,!
|
---|
107 | N @ZJ ; NEW THE VARIABLE
|
---|
108 | I $O(C0CV(ZI))'="" G NEW ;LOOP TO GET NEW IN CONTEXT
|
---|
109 | NOTNEW
|
---|
110 | ; END ARTIFACTS
|
---|
111 | ;
|
---|
112 | D INITFARY("C0CF") ; SET FILE NUMBER AND PARAMATERS
|
---|
113 | S C0CXF=C0CF("XML FILE NUMBER") ; FILE NUMBER FOR THE XML TEMPLATE FILE
|
---|
114 | I +C0CTID=0 D ; A STRING WAS PASSED FOR THE TEMPLATE NAME
|
---|
115 | . S C0CUTID=$$RESTID(C0CTID,"C0CF") ;RESOLVE TEMPLATE IEN FROM NAME
|
---|
116 | E S C0CUTID=C0CTID ; AN IEN WAS PASSED
|
---|
117 | N XML,TEMPLATE,HEADER
|
---|
118 | N C0CFH S C0CFH=C0CF("XML HEADER")
|
---|
119 | S C0CHEAD=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFH,,"HEADER")
|
---|
120 | N C0CFM S C0CFM=C0CF("MIME TYPE")
|
---|
121 | S C0CMIME=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFM)
|
---|
122 | N C0CFP S C0CFP=C0CF("PROXY SERVER")
|
---|
123 | S C0CPURL=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFP)
|
---|
124 | N C0CFU S C0CFU=C0CF("URL")
|
---|
125 | S C0CURL=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFU)
|
---|
126 | N C0CFX S C0CFX=C0CF("XML")
|
---|
127 | S C0CXML=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFX,,"XML")
|
---|
128 | N C0CFT S C0CFT=C0CF("TEMPLATE XML")
|
---|
129 | S C0CTMPL=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFT,,"TEMPLATE")
|
---|
130 | I C0CTMPL="TEMPLATE" D ; there is a template to process
|
---|
131 | . K XML ; going to replace the xml array
|
---|
132 | . N VARS
|
---|
133 | . I $D(C0CVOR) M @C0CVA=@C0CVOR ; merge in varible overrides
|
---|
134 | . I '$D(ALTXML) D ; if ALTXML is passed in, don't bind
|
---|
135 | . . D BIND("VARS",C0CVA,C0CUTID,"C0CF")
|
---|
136 | . . D MAP("XML","VARS",TPTR,"C0CF")
|
---|
137 | . . K XML(0)
|
---|
138 | . E M XML=@ALTXML ; use ALTXML instead
|
---|
139 | I $G(C0CPROXY) S C0CURL=C0CPURL
|
---|
140 | K C0CRSLT,C0CRHDR
|
---|
141 | S ok=$$httpPOST^%zewdGTM(C0CURL,.XML,C0CMIME,.C0CRSLT,.HEADER,"",.gpl5,.C0CRHDR)
|
---|
142 | K C0CRXML
|
---|
143 | D NORMAL("C0CRXML","C0CRSLT(1)") ;RETURN XML IN AN ARRAY
|
---|
144 | N C0CFR S C0CFR=C0CF("REPLY TEMPLATE")
|
---|
145 | S C0CR=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFR,"I") ; REPLY TEMPLATE
|
---|
146 | ; reply templates are optional and are specified by populating a
|
---|
147 | ; template pointer in field 2.5 of the request template
|
---|
148 | ; if specified, the reply template is the source of the REDUX string
|
---|
149 | ; used for XPath on the reply, and for UNBIND processing
|
---|
150 | ; if no reply template is specified, REDUX is obtained from the request
|
---|
151 | ; template and no UNBIND processing is performed. The XPath array is
|
---|
152 | ; returned without variable bindings
|
---|
153 | I C0CR'="" D ; REPLY TEMPLATE EXISTS
|
---|
154 | . I +$G(DEBUG)'=0 W "REPLY TEMPLATE:",C0CR,!
|
---|
155 | . S C0CTID=C0CR ;
|
---|
156 | N C0CFRDX S C0CFRDX=C0CF("XPATH REDUCTION STRING")
|
---|
157 | S C0CREDUX=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFRDX) ;XPATH REDUCTION STRING
|
---|
158 | K C0CIDX,C0CARY ; XPATH INDEX AND ARRAY VARS
|
---|
159 | S C0CNOM="C0CWS"_$J ; DOCUMENT NAME FOR THE DOM
|
---|
160 | S C0CID=$$PARSE^C0CXEWD("C0CRXML",C0CNOM) ;CALL THE PARSER
|
---|
161 | S C0CID=$$FIRST^C0CXEWD($$ID^C0CXEWD(C0CNOM)) ;ID OF FIRST NODE
|
---|
162 | D XPATH^C0CXEWD(C0CID,"/","C0CIDX","C0CARY","",C0CREDUX) ;XPATH GENERATOR
|
---|
163 | ; Next, call UNBIND to map the reply XPath array to variables
|
---|
164 | ; This is only done if a Reply Template is provided
|
---|
165 | D DEMUXARY(C0CRTN,"C0CARY")
|
---|
166 | ; M @C0CRTN=C0CARY
|
---|
167 | Q
|
---|
168 | ;
|
---|
169 | DEMUXARY(OARY,IARY) ;CONVERT AN XPATH ARRAY PASSED AS IARY TO
|
---|
170 | ; FORMAT @OARY@(x,xpath) where x is the first multiple
|
---|
171 | N ZI,ZJ,ZK,ZL S ZI=""
|
---|
172 | F S ZI=$O(@IARY@(ZI)) Q:ZI="" D ;
|
---|
173 | . D DEMUX^C0CMXP("ZJ",ZI)
|
---|
174 | . S ZK=$P(ZJ,"^",3)
|
---|
175 | . S ZK=$RE($P($RE(ZK),"/",1))
|
---|
176 | . S ZL=$P(ZJ,"^",1)
|
---|
177 | . I ZL="" S ZL=1
|
---|
178 | . S @OARY@(ZL,ZK)=@IARY@(ZI)
|
---|
179 | Q
|
---|
180 | ;
|
---|
181 | NORMAL(OUTXML,INXML) ;NORMALIZES AN XML STRING PASSED BY NAME IN INXML
|
---|
182 | ; INTO AN XML ARRAY RETURNED IN OUTXML, ALSO PASSED BY NAME
|
---|
183 | ;
|
---|
184 | N ZI,ZN,ZTMP
|
---|
185 | S ZN=1
|
---|
186 | S @OUTXML@(ZN)=$P(@INXML,"><",ZN)_">"
|
---|
187 | S ZN=ZN+1
|
---|
188 | F S @OUTXML@(ZN)="<"_$P(@INXML,"><",ZN) Q:$P(@INXML,"><",ZN+1)="" D ;
|
---|
189 | . S @OUTXML@(ZN)=@OUTXML@(ZN)_">"
|
---|
190 | . S ZN=ZN+1
|
---|
191 | Q
|
---|
192 | ;
|
---|
193 | MAP(RARY,IVARS,TPTR,INFARY) ;RETURNS MAPPED XML IN RARY PASSED BY NAME
|
---|
194 | ; IVARS IS AN XPATH ARRAY PASSED BY NAME
|
---|
195 | ; TPTR IS A POINT TO THE C0C XML TEMPLATE FILE USED TO RETRIEVE THE TEMPLATE
|
---|
196 | ;
|
---|
197 | N ZT ;THE TEMPLATE
|
---|
198 | K ZT,@RARY
|
---|
199 | I '$D(INFARY) D ;
|
---|
200 | . S INFARY="FARY"
|
---|
201 | . D INITFARY(INFARY)
|
---|
202 | N ZF,ZFT
|
---|
203 | S ZF=@INFARY@("XML FILE NUMBER")
|
---|
204 | S ZFT=@INFARY@("TEMPLATE XML")
|
---|
205 | I $$GET1^DIQ(ZF,TPTR_",",ZFT,,"ZT")'="ZT" D Q ; ERROR GETTING TEMPLATE
|
---|
206 | . W "ERROR RETRIEVING TEMPLATE",!
|
---|
207 | D MAP^C0CXPATH("ZT",IVARS,RARY) ;DO THE MAPPING
|
---|
208 | Q
|
---|
209 | ;
|
---|
210 | TESTBIND ;
|
---|
211 | S G1("TESTONE")=1
|
---|
212 | S G1("TESTTWO")=2
|
---|
213 | D BIND("G","G1","TEST")
|
---|
214 | W !
|
---|
215 | ZWR G
|
---|
216 | Q
|
---|
217 | ;
|
---|
218 | BIND(RARY,IVARS,INTPTR,INFARY) ;RETURNS AN XPATH ARRAY IN RARY FOR USE WITH MAP
|
---|
219 | ; TO BUILD AN INSTANTIATED TEMPLATE
|
---|
220 | ; TPTR IS THE IEN OF THE XML TEMPATE IN THE C0C XML TEMPLATE FILE
|
---|
221 | ; LOOPS THROUGHT THE BINDING SUBFILE TO PULL OUT XPATHS AND
|
---|
222 | ; EITHER ASSIGNS VARIABLES OR DOES A FILEMAN CALL TO GET VALUES
|
---|
223 | ; VARIABLES ARE IN IVARS WHICH IS PASSED BY NAME
|
---|
224 | I '$D(INFARY) D ;
|
---|
225 | . S INFARY="FARY"
|
---|
226 | . D INITFARY(INFARY) ;INITIALIZE FILE ARRAY IF NOT PASSED
|
---|
227 | I +INTPTR>0 S TPTR=INTPTR
|
---|
228 | E S TPTR=$$RESTID(INTPTR,INFARY)
|
---|
229 | N C0CFF,C0CBF,C0CXI,C0CFREF,C0CXREF
|
---|
230 | S C0CFF=@INFARY@("XML FILE NUMBER") ;fileman file number of XML file
|
---|
231 | S C0CFREF=$$FILEREF^C0CRNF(C0CFF) ; closed file reference to the file
|
---|
232 | S C0CBF=@INFARY@("BINDING SUBFILE NUMBER") ; BINDING SUBFILE NUMBER
|
---|
233 | S C0CXI=$G(@INFARY@("XPATH INDEX")) ; index to the XPath bindings
|
---|
234 | I C0CXI="" S C0CXI="XPATH" ; default is the XPATH index
|
---|
235 | ; this needs to be a whole file index on the XPath subfile with
|
---|
236 | ; the Template IEN perceding the XPath in the index
|
---|
237 | N ZI
|
---|
238 | S ZI=""
|
---|
239 | S C0CXREF=$NA(@C0CFREF@(C0CXI,TPTR)) ; where the xref is
|
---|
240 | ;F S ZI=$O(^C0CX(TPTR,5,"B",ZI)) Q:ZI="" D ; FOR EACH XPATH
|
---|
241 | F S ZI=$O(@C0CXREF@(ZI)) Q:ZI="" D ; for each XPath in this template
|
---|
242 | . ;W !,ZI," ",$O(@C0CXREF@(ZI,TPTR,""))
|
---|
243 | . N ZIEN,ZFILE,ZFIELD,ZVAR,ZIDX,ZINDEX ;
|
---|
244 | . S ZIEN=$O(@C0CXREF@(ZI,TPTR,"")) ; IEN OF THE BINDING RECORD
|
---|
245 | . N ZFF S ZFF=@INFARY@("FILEMAN FILE POINTER")
|
---|
246 | . S ZFILE=$$GET1^DIQ(C0CBF,ZIEN_","_TPTR_",",ZFF,"I")
|
---|
247 | . N ZFFLD S ZFFLD=@INFARY@("FILEMAN FIELD NUMBER")
|
---|
248 | . S ZFIELD=$$GET1^DIQ(C0CBF,ZIEN_","_TPTR_",",ZFFLD,"I")
|
---|
249 | . N ZFV S ZFV=@INFARY@("VARIABLE NAME")
|
---|
250 | . S ZVAR=$$GET1^DIQ(C0CBF,ZIEN_","_TPTR_",",ZFV,"E")
|
---|
251 | . N ZFX S ZFX=("INDEXED BY")
|
---|
252 | . S ZIDX=$$GET1^DIQ(C0CBF,ZIEN_","_TPTR_",",ZFX,"I")
|
---|
253 | . S ZINDEX=""
|
---|
254 | . I ZIDX="DUZ" S ZINDEX=$G(DUZ) ; FILE IS INDEXED BY DUZ
|
---|
255 | . I ZIDX="DFN" S ZINDEX=$G(DFN) ; BY DFN
|
---|
256 | . E I ZIDX'="" S ZINDEX=$G(@ZIDX) ; index variable
|
---|
257 | . ;I ZIDX="ACCT" S ZINDEX=C0CACCT ; BY ACCOUNT RECORD POINT TO C0C WS ACCT
|
---|
258 | . ;I ZIDX="LOC" S ZINDEX=C0CLOC ; BY LOCATION
|
---|
259 | . I ZVAR'="" D ; VARIABLES TAKE PRESCIDENCE OVER FILEMAN FIELDS
|
---|
260 | . . S @RARY@(ZI)=@IVARS@(ZVAR) ;
|
---|
261 | . E D ; IF NO VARIABLE, TRY ACCESSING FROM FILEMAN
|
---|
262 | . . I (ZFILE="")!(ZFIELD="") Q ;QUIT IF FILE OR FIELD NOT THERE
|
---|
263 | . . D CLEAN^DILF
|
---|
264 | . . S @RARY@(ZI)=$$GET1^DIQ(ZFILE,ZINDEX_",",ZFIELD) ;GET THE VALUE
|
---|
265 | . . I $D(^TMP("DIERR",$J,1)) D B ;
|
---|
266 | . . . W "ERROR!",!
|
---|
267 | . . . ZWR ^TMP("DIERR",$J,*)
|
---|
268 | Q
|
---|
269 | ; |
---|