Connecting to Quest Lab 360 Using SOAP

Code

We packaged the code in a ‘quest’ shared module to make a nice clean API to work with.

This is how the Translator is meant to be used, by abstracting the complexity of the underlying plumbing into a shared into a shared modules. However when something goes wrong we can easily get under the hood to see what is going wrong. This is really important when dealing with a complex and ambiguous protocol like SOAP, because there will always be problems.

Here’s the code for the main:

require('node')
require('quest')

local User ='user'

local Password = 'password'

local function trace(a,b,c,d) return end

function main(HL7)
   local X = quest.PlaceOrder(HL7,
      User, Password)
   trace(X)

   if quest.IsFault(X) then
      quest.GetFault(X)
   else
      quest.GetResponse(X)    
   end
end

Here’s the code for the ‘quest’ module:

quest ={}

local function trace(a,b,c,d) return end

local Url = 'https://cert.hub.care360.com/orders/service'

T = [==[<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ord="http://medplus.com/orders">
   <soapenv:Header/>
   <soapenv:Body>
      <ord:submitOrder soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <order xsi:type="java:Order" xs:type="type:Order" xmlns:java="java:com.medplus.serviceHub.orders.webservice" xmlns:xs="http://www.w3.org/2000/XMLSchema-instance">
            <hl7Order xsi:type="xsd:base64Binary">${globalCleanHL7}</hl7Order>
         </order>
      </ord:submitOrder>
   </soapenv:Body>
</soapenv:Envelope>]==]

local function MakePayload(HL7)
   local P = xml.parse{data=T}
   P["soapenv:Envelope"]["soapenv:Body"]["ord:submitOrder"].order.hl7Order[2]
       = filter.base64.enc(HL7)
   return P 
end

function quest.PlaceOrder(HL7, User, Password) 
   local E = MakePayload(HL7)
   trace(E)
   local D,R = net.http.post{
         url=Url, 
         auth={username=User, password=Password},
         headers={['Content-Type']='text/xml',
         SOAPAction=Url..'/submitOrder'}, 
      body=E:S(), live=true}
   if (R == 401) then
      error('Looks like the user name and password were wrong.')
   end
   return xml.parse{data=D}
end

-- Returns nil if we do not have a SOAP fault response
function quest.IsFault(X)  
   return X["env:Envelope"]["env:Body"]["env:Fault"] 
end

-- Extracts the response message from a non fault response
function quest.GetResponse(X)
   return X["env:Envelope"]["env:Body"]
    ["m:submitOrderResponse"].result.responseMsg[2]:S()
end

-- Extracts the error message from a fault response
function quest.GetFault(X)
   return X["env:Envelope"]["env:Body"]["env:Fault"].
      detail["bea_fault:stacktrace"][2]:S()
end

Leave A Comment?