Help Changing Accession Number with LUA Script

  • I am not an experienced coder by any means so, please don't laugh too hard when you look at this..


    I am trying to assign a new accession number to some groups of studies using an LUA script with and ImportConverter. I have been successful in generating the new accession number but, cannot get it to apply at a study level. It runs (and generates a new accession number for every new image it imports). Can anyone help me fix this or maybe give me a better method to accomplish the accession number assignment?


    Here is the ImportConverters section from my dicom.ini...
    ***********************************************************************


    # Configuration of rules to modify, log or reject incoming DICOM slices
    ImportConverters = 5
    ImportConverter0 = change.lua
    ImportConverter1 = setifempty 0008,1030 to "EmptyStudyDescription"
    ImportConverter2 = setifempty 0008,0090 to "EmptyReferringPhysicianName"
    ImportConverter3 = setifempty 0008,103E to "EmptySeriesDescription"
    ImportConverter4 = setifempty 0008,0080 to "EmptyInstitutionName"


    ForwardCollectDelay = 600
    MaximumExportRetries = 0
    MaximumDelayedFetchForwardRetries = 0




    And here is the LUA script I am using...
    ***************************************************
    change.lua


    script('changeacc')
    local inf = assert(io.open("acc.txt", "r"), "Failed to open input file")
    local bigstring = inf:read("*all")
    local bigstring2 = bigstring + 1
    print(bigstring2)
    io.close (inf)
    local file = assert(io.open("acc.txt", "w+"), "Failed to open input file")
    file:write(bigstring2)
    io.close (file)
    Desig = "ILHMIG"
    Data.AccessionNumber= Desig..bigstring2 .. Data.AccessionNumber



    Any guidance would be greatly appreciated!


    Thanks,


    Matt

  • Hi Matt,


    looks OK for a start to me. The basic issue that images of a study can come in in any order and even interleaved with images of other studies. So the only way to set accession number on a study level is to derive it from StudyInstanceUID.


    This line will do the job:


    Data.AccessionNumber = changeuid(Data.StudyInstanceUID, crc(Data.StudyInstanceUID))


    the changeuid function will keep a record of every change made and reapply the same change for the same value. The function crc calculates a checksum of the passed data that is bound to be unique. But if you make a counter and pass that instead the effect will that each study gets a unique number as well.


    Marcel

Participate now!

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