source: ccr/trunk/p/C0CSOAP.m@ 716

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

updates to web services support

File size: 10.0 KB
Line 
1C0CSOAP ; 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 ;
24TEST1
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 ;
29INITFARY(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 ;
52RESTID(INNAM,INFARY) ;EXTRINSIC TO RESOLVE TEMPLATE PASSED BY NAME
53 ; FILE IS IDENTIFIED IN FARY, PASSED BY NAME
54 N ZN,ZREF,ZR
55 S ZN=@INFARY@("XML FILE NUMBER")
56 S ZREF=$$FILEREF^C0CRNF(ZN)
57 S ZR=$O(@ZREF@("B",INNAM,""))
58 Q ZR
59 ;
60TESTSOAP ;
61 ; USING ICD9 WEB SERVICE TO TEST SOAP
62 S G("CODE")="E*"
63 S G("CODELN")=3
64 D SOAP("GPL","ICD9","G")
65 Q
66 ;
67SOAP(C0CRTN,C0CTID,C0CVA,C0CVOR,ALTXML) ; MAKES A SOAP CALL FOR
68 ; TEMPLATE ID C0CTID
69 ; RETURNS THE XML RESULT IN C0CRTN, PASSED BY NAME
70 ; C0CVA IS PASSED BY NAME AND IS THE VARIABLE ARRAY TO PASS TO BIND
71 ; C0CVOR IS THE NAME OF A VARIABLE OVERRIDE ARRAY, WHICH IS APPLIED
72 ; BEFORE MAPPING
73 ; IF ALTXML IS PASSED, BIND AND MAP WILL BE SKIPPED AND
74 ; ALTXML WILL BE USED INSTEAD
75 ;
76 ; ARTIFACTS SECTION
77 ; THE FOLLOWING WILL SET UP DEBUGGING ARTIFACTS FOR A POSSIBLE FUTURE
78 ; ONLINE DEBUGGER. IF DEBUG=1, VARIABLES CONTAINING INTERMEDIATE RESULTS
79 ; WILL NOT BE NEWED.
80 I $G(WSDEBUG)="" N C0CV ; CATALOG OF ARTIFACT VARIABLES AND ARRAYS
81 S C0CV(100,"C0CXF","XML TEMPLATE FILE NUMBER")=""
82 S C0CV(200,"C0CHEAD","SOAP HEADER VARIABLE NAME")=""
83 S C0CV(300,"HEADER","SOAP HEADER")=""
84 S C0CV(400,"C0CMIME","MIME TYPE")=""
85 S C0CV(500,"C0CURL","WS URL")=""
86 S C0CV(550,"C0CPURL","PROXY URL")=""
87 S C0CV(600,"C0CXML","XML VARIABLE NAME")=""
88 S C0CV(700,"XML","OUTBOUND XML")=""
89 S C0CV(800,"C0CRSLT","RAW XML RESULT RETURNED FROM WEB SERVICE")=""
90 S C0CV(900,"C0CRHDR","RETURNED HEADER")=""
91 S C0CV(1000,"C0CRXML","XML RESULT NORMALIZED")=""
92 S C0CV(1100,"C0CR","REPLY TEMPLATE")=""
93 S C0CV(1200,"C0CREDUX","REDUX STRING")=""
94 S C0CV(1300,"C0CIDX","RESULT XPATH INDEX")=""
95 S C0CV(1400,"C0CARY","RESULT XPATH ARRAY")=""
96 S C0CV(1500,"C0CNOM","RESULT DOM DOCUMENT NAME")=""
97 S C0CV(1600,"C0CID","RESULT DOM ID")=""
98 I $G(DEBUG)'="" G NOTNEW ; SKIP NEWING THE VARIABLES IF IN DEBUG
99 N ZI,ZJ S ZI=""
100NEW
101 S ZI=$O(C0CV(ZI))
102 S ZJ=$O(C0CV(ZI,"")) ; SET UP NEW COMMAND
103 ;W ZJ,!
104 N @ZJ ; NEW THE VARIABLE
105 I $O(C0CV(ZI))'="" G NEW ;LOOP TO GET NEW IN CONTEXT
106NOTNEW
107 ; END ARTIFACTS
108 ;
109 D INITFARY("C0CF") ; SET FILE NUMBER AND PARAMATERS
110 S C0CXF=C0CF("XML FILE NUMBER") ; FILE NUMBER FOR THE XML TEMPLATE FILE
111 I +C0CTID=0 D ; A STRING WAS PASSED FOR THE TEMPLATE NAME
112 . S C0CUTID=$$RESTID(C0CTID,"C0CF") ;RESOLVE TEMPLATE IEN FROM NAME
113 E S C0CUTID=C0CTID ; AN IEN WAS PASSED
114 N XML,TEMPLATE,HEADER
115 N C0CFH S C0CFH=C0CF("XML HEADER")
116 S C0CHEAD=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFH,,"HEADER")
117 N C0CFM S C0CFM=C0CF("MIME TYPE")
118 S C0CMIME=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFM)
119 N C0CFP S C0CFP=C0CF("PROXY SERVER")
120 S C0CPURL=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFP)
121 N C0CFU S C0CFU=C0CF("URL")
122 S C0CURL=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFU)
123 N C0CFX S C0CFX=C0CF("XML")
124 S C0CXML=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFX,,"XML")
125 N C0CFT S C0CFT=C0CF("TEMPLATE XML")
126 S C0CTMPL=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFT,,"TEMPLATE")
127 I C0CTMPL="TEMPLATE" D ; there is a template to process
128 . K XML ; going to replace the xml array
129 . N VARS
130 . I $D(C0CVOR) M @C0CVA=@C0CVOR ; merge in varible overrides
131 . I '$D(ALTXML) D ; if ALTXML is passed in, don't bind
132 . . D BIND("VARS",C0CVA,C0CUTID,"C0CF")
133 . . D MAP("XML","VARS",TPTR,"C0CF")
134 . . K XML(0)
135 . E M XML=@ALTXML ; use ALTXML instead
136 I $G(C0CPROXY) S C0CURL=C0CPURL
137 K C0CRSLT,C0CRHDR
138 S ok=$$httpPOST^%zewdGTM(C0CURL,.XML,C0CMIME,.C0CRSLT,.HEADER,"",.gpl5,.C0CRHDR)
139 K C0CRXML
140 D NORMAL("C0CRXML","C0CRSLT(1)") ;RETURN XML IN AN ARRAY
141 N C0CFR S C0CFR=C0CF("REPLY TEMPLATE")
142 S C0CR=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFR,"I") ; REPLY TEMPLATE
143 ; reply templates are optional and are specified by populating a
144 ; template pointer in field 2.5 of the request template
145 ; if specified, the reply template is the source of the REDUX string
146 ; used for XPath on the reply, and for UNBIND processing
147 ; if no reply template is specified, REDUX is obtained from the request
148 ; template and no UNBIND processing is performed. The XPath array is
149 ; returned without variable bindings
150 I C0CR'="" D ; REPLY TEMPLATE EXISTS
151 . I +$G(DEBUG)'=0 W "REPLY TEMPLATE:",C0CR,!
152 . S C0CTID=C0CR ;
153 N C0CFRDX S C0CFRDX=C0CF("XPATH REDUCTION STRING")
154 S C0CREDUX=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFRDX) ;XPATH REDUCTION STRING
155 K C0CIDX,C0CARY ; XPATH INDEX AND ARRAY VARS
156 S C0CNOM="C0CWS"_$J ; DOCUMENT NAME FOR THE DOM
157 S C0CID=$$PARSE^C0CXEWD("C0CRXML",C0CNOM) ;CALL THE PARSER
158 S C0CID=$$FIRST^C0CXEWD($$ID^C0CXEWD(C0CNOM)) ;ID OF FIRST NODE
159 D XPATH^C0CXEWD(C0CID,"/","C0CIDX","C0CARY","",C0CREDUX) ;XPATH GENERATOR
160 ; Next, call UNBIND to map the reply XPath array to variables
161 ; This is only done if a Reply Template is provided
162 D DEMUXARY(C0CRTN,"C0CARY")
163 ; M @C0CRTN=C0CARY
164 Q
165 ;
166DEMUXARY(OARY,IARY) ;CONVERT AN XPATH ARRAY PASSED AS IARY TO
167 ; FORMAT @OARY@(x,xpath) where x is the first multiple
168 N ZI,ZJ,ZK,ZL S ZI=""
169 F S ZI=$O(@IARY@(ZI)) Q:ZI="" D ;
170 . D DEMUX^C0CMXP("ZJ",ZI)
171 . S ZK=$P(ZJ,"^",3)
172 . S ZK=$RE($P($RE(ZK),"/",1))
173 . S ZL=$P(ZJ,"^",1)
174 . I ZL="" S ZL=1
175 . S @OARY@(ZL,ZK)=@IARY@(ZI)
176 Q
177 ;
178NORMAL(OUTXML,INXML) ;NORMALIZES AN XML STRING PASSED BY NAME IN INXML
179 ; INTO AN XML ARRAY RETURNED IN OUTXML, ALSO PASSED BY NAME
180 ;
181 N ZI,ZN,ZTMP
182 S ZN=1
183 S @OUTXML@(ZN)=$P(@INXML,"><",ZN)_">"
184 S ZN=ZN+1
185 F S @OUTXML@(ZN)="<"_$P(@INXML,"><",ZN) Q:$P(@INXML,"><",ZN+1)="" D ;
186 . S @OUTXML@(ZN)=@OUTXML@(ZN)_">"
187 . S ZN=ZN+1
188 Q
189 ;
190MAP(RARY,IVARS,TPTR,INFARY) ;RETURNS MAPPED XML IN RARY PASSED BY NAME
191 ; IVARS IS AN XPATH ARRAY PASSED BY NAME
192 ; TPTR IS A POINT TO THE C0C XML TEMPLATE FILE USED TO RETRIEVE THE TEMPLATE
193 ;
194 N ZT ;THE TEMPLATE
195 K ZT,@RARY
196 I '$D(INFARY) D ;
197 . S INFARY="FARY"
198 . D INITFARY(INFARY)
199 N ZF,ZFT
200 S ZF=@INFARY@("XML FILE NUMBER")
201 S ZFT=@INFARY@("TEMPLATE XML")
202 I $$GET1^DIQ(ZF,TPTR_",",ZFT,,"ZT")'="ZT" D Q ; ERROR GETTING TEMPLATE
203 . W "ERROR RETRIEVING TEMPLATE",!
204 D MAP^C0CXPATH("ZT",IVARS,RARY) ;DO THE MAPPING
205 Q
206 ;
207TESTBIND ;
208 S G1("TESTONE")=1
209 S G1("TESTTWO")=2
210 D BIND("G","G1","TEST")
211 W !
212 ZWR G
213 Q
214 ;
215BIND(RARY,IVARS,INTPTR,INFARY) ;RETURNS AN XPATH ARRAY IN RARY FOR USE WITH MAP
216 ; TO BUILD AN INSTANTIATED TEMPLATE
217 ; TPTR IS THE IEN OF THE XML TEMPATE IN THE C0C XML TEMPLATE FILE
218 ; LOOPS THROUGHT THE BINDING SUBFILE TO PULL OUT XPATHS AND
219 ; EITHER ASSIGNS VARIABLES OR DOES A FILEMAN CALL TO GET VALUES
220 ; VARIABLES ARE IN IVARS WHICH IS PASSED BY NAME
221 I '$D(INFARY) D ;
222 . S INFARY="FARY"
223 . D INITFARY(INFARY) ;INITIALIZE FILE ARRAY IF NOT PASSED
224 I +INTPTR>0 S TPTR=INTPTR
225 E S TPTR=$$RESTID(INTPTR,INFARY)
226 N C0CFF,C0CBF,C0CXI,C0CFREF,C0CXREF
227 S C0CFF=@INFARY@("XML FILE NUMBER") ;fileman file number of XML file
228 S C0CFREF=$$FILEREF^C0CRNF(C0CFF) ; closed file reference to the file
229 S C0CBF=@INFARY@("BINDING SUBFILE NUMBER") ; BINDING SUBFILE NUMBER
230 S C0CXI=$G(@INFARY@("XPATH INDEX")) ; index to the XPath bindings
231 I C0CXI="" S C0CXI="XPATH" ; default is the XPATH index
232 ; this needs to be a whole file index on the XPath subfile with
233 ; the Template IEN perceding the XPath in the index
234 N ZI
235 S ZI=""
236 S C0CXREF=$NA(@C0CFREF@(C0CXI,TPTR)) ; where the xref is
237 ;F S ZI=$O(^C0CX(TPTR,5,"B",ZI)) Q:ZI="" D ; FOR EACH XPATH
238 F S ZI=$O(@C0CXREF@(ZI)) Q:ZI="" D ; for each XPath in this template
239 . ;W !,ZI," ",$O(@C0CXREF@(ZI,TPTR,""))
240 . N ZIEN,ZFILE,ZFIELD,ZVAR,ZIDX,ZINDEX ;
241 . S ZIEN=$O(@C0CXREF@(ZI,TPTR,"")) ; IEN OF THE BINDING RECORD
242 . N ZFF S ZFF=@INFARY@("FILEMAN FILE POINTER")
243 . S ZFILE=$$GET1^DIQ(C0CBF,ZIEN_","_TPTR_",",ZFF,"I")
244 . N ZFFLD S ZFFLD=@INFARY@("FILEMAN FIELD NUMBER")
245 . S ZFIELD=$$GET1^DIQ(C0CBF,ZIEN_","_TPTR_",",ZFFLD,"I")
246 . N ZFV S ZFV=@INFARY@("VARIABLE NAME")
247 . S ZVAR=$$GET1^DIQ(C0CBF,ZIEN_","_TPTR_",",ZFV,"E")
248 . N ZFX S ZFX=("INDEXED BY")
249 . S ZIDX=$$GET1^DIQ(C0CBF,ZIEN_","_TPTR_",",ZFX,"I")
250 . S ZINDEX=""
251 . I ZIDX="DUZ" S ZINDEX=$G(DUZ) ; FILE IS INDEXED BY DUZ
252 . I ZIDX="DFN" S ZINDEX=$G(DFN) ; BY DFN
253 . E I ZIDX'="" S ZINDEX=$G(@ZIDX) ; index variable
254 . ;I ZIDX="ACCT" S ZINDEX=C0CACCT ; BY ACCOUNT RECORD POINT TO C0C WS ACCT
255 . ;I ZIDX="LOC" S ZINDEX=C0CLOC ; BY LOCATION
256 . I ZVAR'="" D ; VARIABLES TAKE PRESCIDENCE OVER FILEMAN FIELDS
257 . . S @RARY@(ZI)=@IVARS@(ZVAR) ;
258 . E D ; IF NO VARIABLE, TRY ACCESSING FROM FILEMAN
259 . . I (ZFILE="")!(ZFIELD="") Q ;QUIT IF FILE OR FIELD NOT THERE
260 . . D CLEAN^DILF
261 . . S @RARY@(ZI)=$$GET1^DIQ(ZFILE,ZINDEX_",",ZFIELD) ;GET THE VALUE
262 . . I $D(^TMP("DIERR",$J,1)) D B ;
263 . . . W "ERROR!",!
264 . . . ZWR ^TMP("DIERR",$J,*)
265 Q
266 ;
Note: See TracBrowser for help on using the repository browser.