--[[
	This extraction script identifies the properties for OT, RG, RTIMAGE, SC, 
	BI, CS, DG, DM, EC, ECG, EPS, ES, FA, FS, GM, IO, PX, SM, ST, TG, XC,
	and similiar modality images which will still frames only.  This script
	does no special processing at this time, beyond trying to compensate
	for missing series descriptions by consulting body regions, etc.
    
     Allan Noordvyk    19 JAN 2005       CREATED   
     -	based on old ExtractOT version
 	Mahesh Nagarajan   17 DEC 2006
	-	Signing in for Shudong owing to time constraints; taking one step towards eliminating 
		the use of the "?" for series description; trying to use modality+frame type instead.
--]]	 
    
-- ////////////////////////////////////////////////////////////////////////////
-- Modality specific string definitions 
--	If extraction requires reference to specific value strings (e.g. for substring
--      matching) define them here rather than in-line.
-- ////////////////////////////////////////////////////////////////////////////

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

-- ////////////////////////////////////////////////////////////////////////////
-- Modality specific property extraction functions 
--      Any modality specific extraction logic would be encapsulated in functions
--      defined below.  By standard convention, these shall have names of the form
--	Extract<Property><Modality>, where <Property> is the name of the property
--	being handled and <Modality> is the character prefix for this modality. 
-- ////////////////////////////////////////////////////////////////////////////

function ExtractDescriptionGenericStill() 
-- ////////////////////////////////////////////////////////////////////////////
	-- This function sets the image description property of the image based
	-- on an examination of the header values and previously derived image
	-- properties.  The set property is returned.
	--
	-- This method will always return some kind of property.  If it can't
	-- come up with anything else, it will use a question mark for the
	-- image description just so that we have something to show in the UI.
	--
	-- IMPORTANT: As this function makes use of derived properties, it should
	-- be called LAST, after all other extraction functions have been run.
-- ///////////////////////////////////////////////////////////////////////////

    -- 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 generic still logic.\n" )
            return seriesDescProp;
            --==============================================
        end
    end
    
    TraceC( "No good description found by common script... using special generic still logic.\n" )      
  
    -- Try to build a descriptive sentence by using derived properties
    local seriesDescStr
    seriesDescStr = SmartAppendWords( ValueForTag(PROJECTION_PROP), " ", ValueForTag(LATERALITY_PROP) )
    seriesDescStr = SmartAppendWords( seriesDescStr, " ", ValueForTag(BODY_REGION_PROP) )
      
    -- If we have an image type other than boring old "Original"...
    local imageTypeStr = ValueForTag(IMAGE_TYPE_PROP) 
    if (imageTypeStr and imageTypeStr ~= "Original" and imageTypeStr ~= "ORIGINAL") then 
        -- Append non-boring image type to custom series description
        seriesDescStr = SmartAppendWords( seriesDescStr, " ", imageTypeStr )
    end
        
    if (not seriesDescStr or string.len(seriesDescStr) == 0) then
        -- Nothing useful found; using a modality+frame type instead
  		local modalityType = ValueForTag(MODALITY_PROP)
		local frameType = ValueForTag(FRAME_TYPE_PROP)
		seriesDescStr = SmartAppendWords(modalityType," ",frameType)
    end		
		
    -- If we had no success above...
    if (not seriesDescStr or string.len(seriesDescStr) == 0) then
        TraceC( "No components available for building series description.\n" )
        seriesDescStr = "?"
    end
       
    return NewPropWithValue( SERIES_DESC_PROP, seriesDescStr )

end

-- ////////////////////////////////////////////////////////////////////////////
-- The Execute function is the single function called by the sequence engine
-- when encountering images of a modality for which this script is applicable.
-- This function is called after ExtractCommon's Execute function and should
-- directly invoke any modality specific property extraction functions defined
-- above in the desired order.
-- ////////////////////////////////////////////////////////////////////////////

function Execute()

    TraceC("Extract Generic Still executing...\n")

    -- Note that since this is a generic script covering multiple modalities
    -- we do not do a modality sanity check.
    
    -- Tag our output with the script version
    NewPropWithValue( MODALITY_SCRIPT_VER_PROP, "$Revision: 1 $ - $Modtime: 12/24/07 10:42a $ - GenericSingleStill" )

    -- Insert calls to any modality specific extraction functions here.
    ExtractDescriptionGenericStill()	

    TraceC("Extract Generic Still complete.\n")
    --==============================================
end
