Extracting Patient Information to store on external DB from stable study

I am trying to extract following patient information for the received studies and forward it to another PACS.

  1. Patient Name
  2. Institution
  3. Modality
  4. Study Date
  5. Study Time
    I am currently using OnstoredInstance Lua script which works fine to extract the tags and post to external DB. But it is creating HTTP API POST calls for every instance which is not desirable for me as it overloads the DB receiving many other query from other sources as well. I want to extract this information only when the study is stable (to reduce the number of queries to my DB), for this i tried to use the following nested Lua script but it only sends the Institution, Study Date and Time. It doesnot send the Patient Name and Modality.
    Any suggestions??

Lua Script is below:

JSON = (load(HttpGet(‘http://regex.info/code/JSON.lua’))) ()

function OnStableStudy(studyId, tags, metadata)

local headers = { [“content-type”] = “application/json; charset=utf-8” }

function OnStoredInstance(instanceId, tags, metadata)
local info = {}
info[‘InstitutionName’] = tags[‘InstitutionName’]
info[‘PatientName’] = tags[‘PatientName’]
info[‘Modality’] = tags[‘Modality’]
info[‘StudyInstanceUID’] = tags[‘StudyInstanceUID’]
info[‘StudyDate’] = tags[‘StudyDate’]
info[‘StudyTime’] = tags[‘StudyTime’]
return info

local test = OnStoredInstance(instanceId, tags, metadata)

– Send the POST request
local answer = HttpPost(‘http://localhost:3000/api/dataFromPacsRouter’, JSON:encode(test), headers)

– The answer equals “ERROR” in case of an error
print('Web service called, answer received: ’ … answer)

local moveBody = {}
moveBody[“Synchronous”] = false
moveBody[“Resources”] = {}
table.insert(moveBody[“Resources”], studyId)

local moveJobId = ParseJson(RestApiPost(‘/modalities/ORTHANCLOCAL/store’, DumpJson(moveBody)))[“ID”]
print('moving current study to workstation in job ’ … moveJobId)


function OnJobSuccess(jobId)
local job = ParseJson(RestApiGet(‘/jobs/’ … jobId))

if job[“Type”] == “DicomModalityStore” then
– delete the study once it has been forwarded
RestApiDelete(‘/studies/’ … job[“Content”][“ParentResources”][1])


The “PatientName” tag belongs to the patient level, whereas the “Modality” tag belongs to the series level (in DICOM, different series in the same study can be of different modalities, think of PET/CT for instance).

Here is a full working sample showing how to access the required information:

function OnStableStudy(studyId, tags, metadata)
study = ParseJson(RestApiGet(‘/studies/’ … studyId))

institution = study[‘MainDicomTags’][‘InstitutionName’]
studyDate = study[‘MainDicomTags’][‘StudyDate’]
studyTime = study[‘MainDicomTags’][‘StudyTime’]
patientName = study[‘PatientMainDicomTags’][‘PatientName’]

print(institution, studyDate, studyTime, patientName)

for index, seriesId in ipairs(study[‘Series’]) do
series = ParseJson(RestApiGet(‘/series/’ … seriesId))
print(’ Modality ’ … index … ': ’ … series[‘MainDicomTags’][‘Modality’])


Thank you Sébastien

This resolved my problem.