Storage on Basis on Institution Name

  • Hi


    I had created a new column HOSPCODE in database table name DICOMSTUDIES. Now i want to set the value of HOSPCODE on the basis of Hospital Name. My entry in dicom.ini file is as below:-


    [lua]
    global = print ('hello world');


    ImportConverter0 = if Data.InstitutionName == 'ABC Children Hospital' then Data.Storage='MAG2' and set HCODE to "ABCCH" and Data.Modality == 'CT' then Data:Compress('jk') end;



    or i should write each separate importconvertor like this.


    [lua]
    global = print ('hello world');


    ImportConverter0 = if Data.InstitutionName == 'ABC Children Hospital' then Data.Storage='MAG2' end;
    ImportConvertor1 = if Data.InstitutionName == 'ABC Children Hospital' then set HCODE to "ABCCH" end;
    ImportConvertor2 = if Data.InstitutionName == 'ABC Children Hospital' and Data.Modality == 'CT' then Data:Compress('jk') end;


    In this way i uses 3 Importconvertors to perform the same task and i want to avoid this due to the limitation of Importconvertor (i.e Importconvertor 1 to 99). Please guide me how can i use nested IF statements in lua.

  • Hi,


    you have the full Lua language at your disposal. So maybe the easiest solution is to call an external Lua script file with e.g.


    [lua]
    importconverter0 = dofile('hammad.lua')


    and write out the if statements as such (untested):


    file hammad.lua

    Code
    if Data.InstitutionName == 'ABC Children Hospital' then
    Data.Storage='MAG2'
    sql(format("UPDATE DICOMStudies SET HOSPID='ABCCH' WHERE DICOMStudies.StudyInsta='%s', Data.StudyInstanceUID))
    if Data.Modality == 'CT' then
    Data:Compress('jk')
    end
    end


    You can put the whole code in dicom.ini but than it needs to be on one line. To debug the lot put in print statements.


    Marcel

  • Hi,


    I just realized that the sql statement may not work: the study may not yet exist (this happens after the importconverter). It would work on the second image. Maybe better to add a private tag (e.g. Data["0009,1234"]="ABCCH") and also define e.g. 0009,1234 in the database through dicom.sql (do not put it first or last).


    Marcel

  • Is this correct ???


    in dicom.sql
    { 0x0009, 0x1234, "HOSPID", 10, SQL_C_CHAR, DT_STR },


    hammad.lua file


    iif Data.InstitutionName == 'ABC Hospital' then
    Data.Storage='MAG2'


    print('------ testing an SQL statement --------')
    print ('Hospital Name is :'..Data.InstitutionName);
    print ('Study Instance Saved is :'..Data.StudyInstanceUID);
    print ('*****************************************************');
    print ('**********Start of Sql Statement***********************');
    print ('******************************************************');
    sql("UPDATE DICOMSTUDIES SET HOSPID= 'ABCH' where dicomstudies.StudyInsta='Data.StudyInstanceUID'");
    print ('******************SUCCESS************************************');
    --sql(format("UPDATE dicomstudies SET Data['0009,1234']='ABCCH' where dicomstudies.StudyInsta='%s', Data.StudyInstanceUID));


    end


    Records are not updated and I get no errors but as all statements are executed. Please guide me.
    --HM

  • Hi,


    Below is the exact correct form of the statement (not using your HOSPID column because I don't have it, and passing the studyinstanceuid of the conquest sample image).


    Code
    sql(string.format("UPDATE DICOMStudies SET StudyDescr='ABCCH' WHERE DICOMStudies.StudyInsta='%s'", "1.2.826.0.1.3680043.2.135.735751.41741719.7.1438276572.812.2"))


    It returns 1, meaning success. If it fails it returns nil. To have this working, the record in the database should already exist, so it will only work on the second image entered.


    regards,


    Marcel

  • You can add a private tag in your dicom image (as I said in the post before), e.g.:


    Data["0009,1234"]="ABCCH"


    This will then automatically be written in the database if the tag is defined in dicom.sql.


    Note that if you change dicom.sql you have to regenerate the whole database, be careful.


    Marcel

Participate now!

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