Auto-route with string manipulation

  • Hi,


    I would like to auto-route dicom files through ConQuest where the string in the SeriesDescription tag is shortened to remove some unwanted text. E.g. I would like "RG Ph 0%/15.00bpm 2.0 RTP RTP Body HALF" to become "RG Ph 0%". However, I only want this to happen for files which have been scanned using the following protocol "RTP Retrospective Gating", I believe this is contained in the tag 0018,1030.


    I've been reading the manual and this site and attempted it in version 1.4.16. However, I haven't been very successful, so I was hoping someone here might be able to point me in the right direction!


    So far I have added the following code to dicom.ini:


    Code
    # Configuration of rules to modify, log or reject incoming DICOM slicesImportconverters = 1ImportConverter0 = call RPMFilter.cq# Configuration of rules to auto-export incoming DICOM slicesForwardAssociationLevel = IMAGEForwardAssociationCloseDelay = 5ForwardAssociationRefreshDelay = 3600Exportconverters = 1ExportConverter0 = ifnotequal "%V0018,1030","RTP Retrospective Gating";stop;forward Series to PINN810S1 org %u


    Then in RPMFilter.cq I have the following code:


    Code
    ifnotequal "%V0018,1030","RTP Retrospective Gating";stop; s = Data.SeriesDescription; key = string.match(s, "/"); key = key - 1; Data.SeriesDescription = string.sub(s, 1, key) end;


    Now the I think the RPMFilter.cq is causing the problem, likely because I'm not familar with Lua! Here's a sample from the log:


    Code
    [CONQUESTSRV1] *** Importconverter-1.2 error: s = Data.SeriesDescription
    [CONQUESTSRV1] *** Importconverter-1.3 error: key = string.match(s, "/")
    [CONQUESTSRV1] *** Importconverter-1.4 error: key = key - 1
    [CONQUESTSRV1] *** Importconverter-1.5 error: Data.SeriesDescription = string.sub(s, 1, key) end


    I'm not sure the variables are being picked up correctly? Do I need to delcare that I would like to use Lua somewhere or does it expect Lua?
    Apologies if these are trivial questions but this is rather new to me so any help would be much appreciated.


    Many thanks,


    Ben

  • Hi Ben,


    you mix the orginal conquest scripting and lua. Try:


    [lua]
    ImportConverter0 = dofile('RPMFilter.lua')


    RPMFilter.lua

    Code
    if Data.ProtocolName == "RTP Retrospective Gating" then
    s = Data.SeriesDescription
    key = string.match(s, "/")
    if key then
    key = key - 1
    Data.SeriesDescription = string.sub(s, 1, key)
    end
    end
  • I had to adjust my lua code in 'RPMFilter.lua' to get the right output see below:


    Code
    if Data.ProtocolName == "RTP Retrospective Gating" then str = Data.SeriesDescription str = str:match('[^/]*' ) Data.SeriesDescription = str print (Data.SeriesDescription) print (str)end


    In the log file str prints as "RG Ph 0%" but Data.SeriesDescription prints as "RG Ph 0%/15.00bpm 2.0 RTP RTP Body HALF". I can't see why the line:


    Code
    Data.SeriesDescription = str


    is not setting the SeriesDescription to "RG Ph 0%". What am I missing?


    Thanks for your help so far it makes much more sense now!


    Ben


    Edit: I have just been reading the manual, I now understand that the % needs to be sent as a %% to appear as a % as this is an escape character in Conquest

  • Hi Ben,


    lua scripting has seen lots of fixes between 1.4.16 and 1.4.16k. It may be fixed, but it is more likely that the % in the string is causing trouble. The conquest script command generated by lua is:


    set name to "string"


    So it will interpret %m in string as modality etc. To get a plain % it should be listed as %%.


    Try str = string.gsub(str, '%%', '%%') -- % is a magic character in lua as well.


    This is a bug that I will take out in later releases.


    Marcel

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!