--[[
    This extraction script identifies the properties for ultrasound (RF)
    images. In this version, only the cine/still property is extracted 
    as image description
    
     Cristian Bonciu,    July-September 2004
	-	CREATED and implemented the functionality from pseudo-code prototypes provided by Allan 
	Allan Noordvyk     September 16, 2005
     -	Check for special Philips private element for series description.
     Allan Noordvyk     Sep 25, 2005
     -	Removed modality sanity check because some sites call RF other things (e.g. "DF")    
--]]

function RegisterProperties()
-- ////////////////////////////////////////////////////////////////////////////
-- This function is called automatically at load of script to register any
-- modality specific properties.  Prior to IP Library build 39 it must be 
-- present even if empty.
-- Modality specific property IDs (3711,1X01)- (3711,1XFF) range
--     If modality specific properties need to be defined, then replace X in the above 
--     numeric ranges with a value that is distinct from those used by other modalities.
-- ////////////////////////////////////////////////////////////////////////////
end

-- ////////////////////////////////////////////////////////////////////////////
-- RF image description property strings 
-- ////////////////////////////////////////////////////////////////////////////

    CINE_DESC_VAL = "Cine"
    STILL_DESC_VAL = "Stills"    

-- ////////////////////////////////////////////////////////////////////////////
-- RF properties extaction functions
-- ////////////////////////////////////////////////////////////////////////////

function ExtractImageDescriptionRF()

    -- If the common function was already successful finding a good description value...
    local seriesDescProp = GetAttr( SERIES_DESC_PROP )
    if (seriesDescProp) then
        -- If it isn't just the special no-info placeholder...
        if (seriesDescProp:Get(1) ~= "?") then
            TraceC( "Common script found description... skipping special RF logic.\n" )
            return seriesDescProp;
            --==============================================
        end
    end 
    
    TraceC( "No good description found by common script... using special RF logic.\n" )   

    -- If this is a Philips device...
    if (ValueForTag(DEVICE_MANUFACTURER_TAG) == "Philips Medical Systems") then
        
          -- Some Phillips CR units put this information in a private element.
          local PHILIPS_PRIVATE_DESC_TAG = maketag( "0019", "1960" )
          
          -- If this tag is present with a value...
          local privValue = ValueForTag( PHILIPS_PRIVATE_DESC_TAG )
          if (privValue ~= nil) then
              -- Just use it directly
              return NewPropWithValue( SERIES_DESC_PROP, privValue )
              -- ==============================================
          end
          
    end    
  
    -- If the image is part of a cine clip
    if (ValueForTag( FRAME_TYPE_PROP ) == CINE_VAL) then
        seriesDescStr = CINE_DESC_VAL   -- just call it "Cine"
    else
	seriesDescStr = STILL_DESC_VAL  -- just call it "Stills"
    end
        
    return NewPropWithValue( SERIES_DESC_PROP, seriesDescStr )
        
end

-- ////////////////////////////////////////////////////////////////////////////
-- extract RF properties 
-- ////////////////////////////////////////////////////////////////////////////

function Execute()

    -- Tag our output with the script version
    NewPropWithValue( MODALITY_SCRIPT_VER_PROP, "$Revision: 1 $ - $Modtime: 2/12/07 3:13p $ - RF" )
    
    ExtractImageDescriptionRF()
end

