XDS.b Example

Here’s an example of how to build a XDS.b Provide and Register request using our XDS.b modules.

The following code snippet shows the main function.  The “Fill” functions map data into a Lua table.  The code then calls xds_b.pnr.simpleapi.make to build the Provide and Register Document Set request.  Finally, the response is parsed.

require 'xds_b.pnr.simpleapi'

local addElement = node.addElement
local setAttr = node.setAttr
local setInner = node.setInner

local PNR = require 'xds_b.pnr.model'
require 'example_xds_b_pnr_datamap'

function main(Data)
   --[[ 
   The current example does not use the inbound data as it hard codes everything.
   This will not be the case in a real scenario.  For example, the inbound data might 
   be an HL7 v2 message.  In this case, the message would be parsed using hl7.parse
   and fed into the helper functions for mapping.
   ]]

   FillAttachments(PNR)
   FillSubmissionSet(PNR)   
   FillDocumentEntries(PNR) 

   PNR.url = 'http://ihexds.nist.gov:12080/tf6/services/xdsrepositoryb'

   local HTTPHeaders, Body = xds_b.pnr.simpleapi.make(PNR)
   local Response, Status = net.http.post{
      url=PNR.url, 
      headers=HTTPHeaders, 
      body=Body, 
      live=true}

   return Status, xds_b.pnr.simpleapi.parseResponse{response=Response}
end

Here’s the module where the data is mapped.

require 'xds_b.pnr.simpleapi'
local PNR = require 'xds_b.pnr.model'

function FillAttachments(PNR)
   PNR.attachments[1] = PNR.attachments.create()
   PNR.attachments[1].content = 'Hello World!'
   PNR.attachments[1].id = 'DocumentId1'
   PNR.attachments[1].mime = 'text/plain'
   PNR.attachments[1].uuid = ihe.getUUID()
   PNR.attachments[2] = PNR.attachments.create()
   PNR.attachments[2].content = 'This is great!'
   PNR.attachments[2].id = 'DocumentId2'
   PNR.attachments[2].mime = 'text/plain'
   PNR.attachments[2].uuid = ihe.getUUID()   

   return PNR
end

function FillSubmissionSet(PNR)
   PNR.submissionSet.id = 'SubmissionSet01'
   PNR.submissionSet.submissionTime = '201307111000'
   PNR.submissionSet.name = 'Physical'
   PNR.submissionSet.description = 'Annual Physical'
   PNR.submissionSet.authors[1] = PNR.submissionSet.authors.create()
   PNR.submissionSet.authors[1].person.last = 'Smith'
   PNR.submissionSet.authors[1].person.first = 'John'
   PNR.submissionSet.authors[1].person.prefix = 'Dr.'
   PNR.submissionSet.authors[1].institutions[1] = 
   PNR.submissionSet.authors[1].institutions.create()
   PNR.submissionSet.authors[1].institutions[1].value = 'Cleveland Clinic'
   PNR.submissionSet.authors[1].institutions[1] = 
   PNR.submissionSet.authors[1].institutions.create()
   PNR.submissionSet.authors[1].institutions[1].value = 'Berea Community'
   PNR.submissionSet.authors[1].roles[1] = 
   PNR.submissionSet.authors[1].roles.create()
   PNR.submissionSet.authors[1].roles[1].value = 'Primary Surgon'
   PNR.submissionSet.authors[1].specialities[1] = 
   PNR.submissionSet.authors[1].specialities.create()
   PNR.submissionSet.authors[1].specialities[1].value = 'Orthopedic'
   PNR.submissionSet.ids[1] = PNR.submissionSet.ids.create()
   PNR.submissionSet.ids[1].id_type = 'unique'
   PNR.submissionSet.ids[1].value = '1.2009.0827.08.33.5026'
   PNR.submissionSet.ids[2] = PNR.submissionSet.ids.create()
   PNR.submissionSet.ids[2].id_type = 'source'
   PNR.submissionSet.ids[2].value = '1.3.6.1.4.1.21367.2009.1.2.1'
   PNR.submissionSet.ids[3] = PNR.submissionSet.ids.create()
   PNR.submissionSet.ids[3].id_type = 'patient'
   PNR.submissionSet.ids[3].value = 
   '58bdf99f28b44c7^^^&1.3.6.1.4.1.21367.2005.3.7&ISO'
   PNR.submissionSet.codes[1] = PNR.submissionSet.codes.create()
   PNR.submissionSet.codes[1].name = 'History and Physical'
   PNR.submissionSet.codes[1].code_type = 'ContentType'

   return PNR
end

function FillDocumentEntries(PNR)
   for i = 1, #PNR.attachments do
      PNR.documentEntries[i] = PNR.documentEntries.create()
      PNR.documentEntries[i].id = PNR.attachments[i].id
      PNR.documentEntries[i].mime = PNR.attachments[i].mime
      PNR.documentEntries[i].creationTime = '201307111000'
      PNR.documentEntries[i].languageCode = 'en-US'
      PNR.documentEntries[i].sourcePatientId = '89765a87b^^^&3.4.5&ISO'
      PNR.documentEntries[i].serviceStartTime = '201307111000'
      PNR.documentEntries[i].serviceStopTime = '201307111200'
      PNR.documentEntries[i].sourcePatientInfo.PID3 = 'pid1^^^&1.2.3&ISO'
      PNR.documentEntries[i].sourcePatientInfo.PID5 = 'Doe^John^^^'
      PNR.documentEntries[i].sourcePatientInfo.PID7 = '19560527'
      PNR.documentEntries[i].sourcePatientInfo.PID8 = 'M'
      PNR.documentEntries[i].sourcePatientInfo.PID11 =
      '100 Main St^^Metropolis^Il^44130^USA'
      PNR.documentEntries[i].name = 'Document 1'
      PNR.documentEntries[i].description = 'First Document'
      PNR.documentEntries[i].authors[1] = PNR.documentEntries[i].authors.create()
      PNR.documentEntries[i].authors[1].person.last = 'Smith'
      PNR.documentEntries[i].authors[1].person.first = 'John'
      PNR.documentEntries[i].authors[1].person.prefix = 'Dr.'
      PNR.documentEntries[i].authors[1].institutions[1] = 
      PNR.documentEntries[i].authors[1].institutions.create()
      PNR.documentEntries[i].authors[1].institutions[1].value = 'Cleveland Clinic'
      PNR.documentEntries[i].authors[1].institutions[2] = 
      PNR.documentEntries[i].authors[1].institutions.create()
      PNR.documentEntries[i].authors[1].institutions[2].value = 'Berea Community'
      PNR.documentEntries[i].authors[1].roles[1] = 
      PNR.documentEntries[i].authors[1].roles.create()
      PNR.documentEntries[i].authors[1].roles[1].value = 'Primary Surgon'
      PNR.documentEntries[i].authors[1].specialities[1] = 
      PNR.documentEntries[i].authors[1].specialities.create()
      PNR.documentEntries[i].authors[1].specialities[1].value = 'Orthopedic'
      PNR.documentEntries[i].codes[1] = PNR.documentEntries[i].codes.create()
      PNR.documentEntries[i].codes[1].name = 'History and Physical'
      PNR.documentEntries[i].codes[1].code_type = 'Class' 
      PNR.documentEntries[i].codes[2] = PNR.documentEntries[i].codes.create()
      PNR.documentEntries[i].codes[2].name = 'Clinical-Staff'
      PNR.documentEntries[i].codes[2].code_type = 'Confidentiality'    
      PNR.documentEntries[i].codes[3] = PNR.documentEntries[i].codes.create()
      PNR.documentEntries[i].codes[3].name = 'CDAR2/IHE 1.0'
      PNR.documentEntries[i].codes[3].code_type = 'Format' 
      PNR.documentEntries[i].codes[4] = PNR.documentEntries[i].codes.create()
      PNR.documentEntries[i].codes[4].name = 'Outpatient'
      PNR.documentEntries[i].codes[4].code_type = 'HealthcareFacilityType'    
      PNR.documentEntries[i].codes[5] = PNR.documentEntries[i].codes.create()
      PNR.documentEntries[i].codes[5].name = 'General Medicine'
      PNR.documentEntries[i].codes[5].code_type = 'PracticeSetting'    
      PNR.documentEntries[i].codes[6] = PNR.documentEntries[i].codes.create()
      PNR.documentEntries[i].codes[6].name = 'Outpatient Evaluation And Management'
      PNR.documentEntries[i].codes[6].code_type = 'Type'   
      PNR.documentEntries[i].ids[1] = PNR.submissionSet.ids.create()
      PNR.documentEntries[i].ids[1].id_type = 'unique'
      PNR.documentEntries[i].ids[1].value = '1.2009.0827.08.33.50'
      PNR.documentEntries[i].ids[2] = PNR.submissionSet.ids.create()
      PNR.documentEntries[i].ids[2].id_type = 'patient'
      PNR.documentEntries[i].ids[2].value = 
      '58bdf99f28b44c7^^^&1.3.6.1.4.1.21367.2005.3.7&ISO'    
      PNR.documentEntries[i].association_status = 'Original' 
   end

   return PNR
end

Here’s the project containing the XDS.b modules.

XDS_b_PNR_Simple_API_To_Translator.zip