Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: ONCSAPIR

ONCSAPIR.m

Go to the documentation of this file.
  1. ONCSAPIR ;HINES OIFO/SG - COLLABORATIVE STAGING (REQUEST) ; 2/8/07 8:28am
  1. ;;2.2;ONCOLOGY;**1,19**;Jul 31, 2013;Build 4
  1. ; ...P19 testing CS Encryption
  1. ; ONC8DST ------------- DESCRIPTOR OF THE DESTINATION BUFFER
  1. ; (a parameter of HEADER, PUT, and TRAILER)
  1. ;
  1. ; ONC8DST( Closed root of the destination buffer
  1. ; "PTR") Pointer in the destination buffer
  1. ; "PTRC") Continuation pointer (optional)
  1. ; "REQ") Name of the root tag of the request
  1. ;
  1. Q
  1. ;
  1. ;***** APPENDS THE STRING TO THE LAST LINE OF THE DESTINATION BUFFER
  1. ;
  1. ; .ONC8DST Reference to a descriptor of the destination buffer.
  1. ;
  1. ; STR String
  1. ;
  1. ; [NOENC] Disable XML encoding (enabled by default)
  1. ;
  1. ; This procedure appends the string as the continuation node
  1. ; to the last line added by the PUT^ONCSAPIR.
  1. ;
  1. APPEND(ONC8DST,STR,NOENC) ;
  1. Q:$G(ONC8DST("PTR"))'>0
  1. N ENCSTR,I1,I2,S1
  1. S ENCSTR=$S('$G(NOENC):$$SYMENC^MXMLUTL(STR),1:STR)
  1. S I2=0
  1. F S I1=I2+1,I2=I1+249,S1=$E(ENCSTR,I1,I2) Q:S1="" D
  1. . S ONC8DST("PTRC")=$G(ONC8DST("PTRC"))+1
  1. . S @ONC8DST@(ONC8DST("PTR"),ONC8DST("PTRC"))=S1
  1. Q
  1. ;
  1. ;***** CHECKS FOR PARSING AND WEB SERVICE ERRORS
  1. ;
  1. ; .ONCXML Reference to the XML parsing descriptor
  1. ;
  1. ; [ONC8INFO] Closed root of the variable that contains
  1. ; additional information related to the error
  1. ;
  1. ; Return values:
  1. ;
  1. ; <0 Error Descriptor
  1. ; 0 Ok
  1. ; 1 Warning(s)
  1. ;
  1. CHKERR(ONCXML,ONC8INFO) ;
  1. N RC,TMP
  1. I $G(ONCXML("ERR"))>0 Q $$ERROR^ONCSAPIE(-5)
  1. I $G(ONCXML("FAULTCODE"))'="" D Q RC
  1. . S TMP=$TR($G(ONCXML("FAULTSTRING")),"^","~")
  1. . S:TMP="" TMP="Unknown error"
  1. . S RC="-2"_U_ONCXML("FAULTCODE")_": "_TMP
  1. . D STORE^ONCSAPIE(RC,$G(ONC8INFO))
  1. . ;--- Error code -11 is returned by the web-service if the
  1. . ; CStage_calculate function calculated only some staging
  1. . ;--- values and returned warning(s).
  1. . S:+$G(ONCXML("RC"))=-11 RC=1
  1. Q 0
  1. ;
  1. ;***** STORES THE REQUEST HEADER INTO THE DESTINATION BUFFER
  1. ;
  1. ; .ONC8DST Reference to a descriptor of the destination buffer.
  1. ;
  1. ; REQUEST Name of the root tag of the request.
  1. ;
  1. ; [.ATTS] Reference to a local variable that stores a list
  1. ; of attribute values (ATTS(name)=value).
  1. ;
  1. ;;<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
  1. ;; soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  1. ;;<soap:Body>
  1. ;
  1. N I,TAG,TMP
  1. S ONC8DST("PTR")=0 K @ONC8DST
  1. D PUT(.ONC8DST,,$$XMLHDR^MXMLUTL())
  1. F I=1:1 S TMP=$P($T(HEADER+I),";;",2) Q:TMP="" D
  1. . D PUT(.ONC8DST,,TMP)
  1. S TAG=REQUEST,I=""
  1. F S I=$O(ATTS(I)) Q:I="" D
  1. . S TAG=TAG_" "_I_"="""_$$SYMENC^MXMLUTL(ATTS(I))_""""
  1. S TAG=TAG_" ver=""2.0"" xmlns=""http://websrv.oncology.domain.ext"""
  1. D PUT(.ONC8DST,TAG,,1)
  1. S ONC8DST("REQ")=REQUEST
  1. Q
  1. ;
  1. ;***** CONVERTS INPUT PARAMETERS INTO XML FORMAT
  1. ;
  1. ; ONC8DST Closed root of the destination buffer
  1. ;
  1. ; REQUEST Name of the root tag of the request.
  1. ;
  1. ; [.INPUT] Reference to a local variable containg
  1. ; input parameters.
  1. ;
  1. ; Return values:
  1. ;
  1. ; <0 Error Descriptor
  1. ; 0 Ok
  1. ;
  1. PARAMS(ONC8DST,REQUEST,INPUT) ;
  1. N I,NAME,VAL
  1. D HEADER(.ONC8DST,REQUEST)
  1. ;---
  1. S NAME=""
  1. F S NAME=$O(INPUT(NAME)) Q:NAME="" D
  1. . S VAL=$G(INPUT(NAME)) D:VAL'="" PUT(.ONC8DST,NAME,VAL)
  1. ;---
  1. D TRAILER(.ONC8DST)
  1. Q 0
  1. ;
  1. ;***** ADDS THE ELEMENT/TEXT TO THE DESTINATION BUFFER
  1. ;
  1. ; .ONC8DST Reference to a descriptor of the destination buffer.
  1. ;
  1. ; [NAME] Name of the element. If omitted or empty then the
  1. ; text line defined by the second parameter is added
  1. ; to the buffer.
  1. ;
  1. ; [VAL] Value of the element.
  1. ;
  1. ; [TAGONLY] Ignore the value and output only the tag defined
  1. ; by the NAME parameter
  1. ;
  1. PUT(ONC8DST,NAME,VAL,TAGONLY) ;
  1. S (ONC8DST("PTR"),PTR)=ONC8DST("PTR")+1 K ONC8DST("PTRC")
  1. I $G(NAME)="" S @ONC8DST@(PTR)=$G(VAL) Q
  1. I $G(TAGONLY) S @ONC8DST@(PTR)="<"_NAME_">" Q
  1. I $G(VAL)="" S @ONC8DST@(PTR)="<"_NAME_"/>" Q
  1. S @ONC8DST@(PTR)="<"_NAME_">"_$$SYMENC^MXMLUTL(VAL)_"</"_NAME_">"
  1. Q
  1. ;
  1. ;***** SENDS THE REQUEST AND GETS THE RESPONSE
  1. ;
  1. ; URL URL (http://host:port/path)
  1. ;
  1. ; ONC8RSP Closed root of the variable where the
  1. ; response text will be returned.
  1. ;
  1. ; [ONC8REQ] Closed root of the variable containing
  1. ; the text of the request.
  1. ;
  1. ; Return Values:
  1. ; 0 Ok
  1. ; <0 Error code
  1. ;
  1. REQUEST(URL,ONC8RSP,ONC8REQ) ;
  1. N HS,ONCINFO,ONCRHDR,ONCSHDR,RC,REPCNT,REPEAT,TMP
  1. ;--- Prepare the request header
  1. S ONCSHDR("Content-Type")="text/xml"
  1. ;---
  1. S (RC,REPCNT)=0 D
  1. . F S REPEAT=0 D Q:'REPEAT
  1. . . ;--- Call the web service
  1. . . M ^TMP("ONC",$J)=ONCREQ
  1. ..S ONCEXEC="G" D T3^ONCWEB1
  1. ..;S ONCEXEC="P" D T3^ONCWEB1
  1. ..M ^TMP("ONCSAPIV",$J)=^TMP("ONCSED01R",$J)
  1. ..M ^TMP("ONCSAPIT",$J)=^TMP("ONCSED01R",$J)
  1. ..;S RC=$$GETURL^ONCX10(URL,60,ONC8RSP,.ONCRHDR,$G(ONC8REQ),.ONCSHDR)
  1. ..S RC="200^OK" ;check the HWSC return code
  1. . . S HS=+RC Q:HS=200
  1. . . ;--- Temporary redirection
  1. . . I HS=302 D Q
  1. . . . S REPCNT=REPCNT+1
  1. . . . I REPCNT>5 S RC=$$ERROR^ONCSAPIE(-12,,REPCNT) Q
  1. . . . S URL=$G(ONCRHDR("LOCATION"))
  1. . . . I URL?." " S RC=$$ERROR^ONCSAPIE(-18) Q
  1. . . . D ERROR^ONCSAPIE(-7,,URL) S REPEAT=1,RC=0
  1. . . ;--- Permanent redirection
  1. . . I HS=301 D Q
  1. . . . S REPCNT=REPCNT+1
  1. . . . I REPCNT>5 S RC=$$ERROR^ONCSAPIE(-12,,REPCNT) Q
  1. . . . S URL=$G(ONCRHDR("LOCATION"))
  1. . . . I URL?." " S RC=$$ERROR^ONCSAPIE(-18) Q
  1. . . . S RC=$$UPDCSURL^ONCSAPIU(URL) Q:RC<0
  1. . . . D ERROR^ONCSAPIE(-8,,URL) S REPEAT=1,RC=0
  1. . . ;--- Record the HTTP client error
  1. . . K ONCINFO S ONCINFO(1)=$P(RC,U,2)_" ("_$P(RC,U)_")"
  1. . . S RC=$$ERROR^ONCSAPIE(-10,.ONCINFO)
  1. . Q:RC<0
  1. ;---
  1. Q $S(RC<0:RC,1:0)
  1. ;
  1. ;***** APPENDS THE REQUEST TRAILER TO THE DESTINATION BUFFER
  1. ;
  1. ; .ONC8DST Reference to a descriptor of the destination buffer.
  1. ;
  1. TRAILER(ONC8DST) ;
  1. S ONC8DST("PTR")=+$O(@ONC8DST@(""),-1)
  1. D PUT(.ONC8DST,"/"_ONC8DST("REQ"),,1)
  1. D PUT(.ONC8DST,"/soap:Body",,1)
  1. D PUT(.ONC8DST,"/soap:Envelope",,1)
  1. Q