TARGET = '/etc/orthanc/images' function OnStableSeries(seriesId, instanceId, tags, metadata, origin) print('This series is now stable, writing its instances on the disk: ' .. seriesId) -- colocar call para tela com a mesma print -- Replace non-alphanumeric characters by underscore local filename = string.gsub(tags['PatientName'], '[^a-zA-Z0-9]', '_') --GOT error in this line because of tags['PatientName'] filename = filename .. '-' .. instanceId -- Generate a PNG preview of the DICOM file local png = RestApiGet('/instances/' .. instanceId .. '/preview') -- Create Folder outputFolder = TARGET .. '/' .. filename os.execute("mkdir -p " .. outputFolder) print('Pasta driada: ' .. filename) -- colocar call para tela com a mesma print -- Write the PNG to the file path = outputFolder .. '/' .. filename .. '.png' print('Writing image of the patient to: ' .. path) -- colocar call para tela com a mesma print local target = assert(io.open(path, 'wb')) target:write(png) target:close() print('Feito') -- TESTAR A PARTE DO TXT TAGS local tagsFilePath = outputFolder .. "/TAGS.txt" local tagsFile = io.open(tagsFilePath, "w") if tagsFile then tagsFile:write("Nome do Paciente: " .. patientName .. "\n") tagsFile:write("Idade: " .. (studyMetadata["0010,1010"] or "Falha1") .. "\n") tagsFile:write("Data de Nascimento: " .. (studyMetadata["0010,0030"] or "Falha2") .. "\n") tagsFile:write("Nome do Estudo: " .. (studyMetadata["0008,1030"] or "Falha3") .. "\n") tagsFile:write(tags['PatientName'] .. "\n") tagsFile:write(tags['PatientAge'] .. "\n") tagsFile:close() end -- Remove the received DICOM instance from Orthanc (optional) -- Delete(instanceId) -- end end