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

Last change on this file since 1806 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

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