--[[
    This grouping script partition endoscopy (ES) images as follows:
    Group images by image UID.
    
	Michael Lai	13 SEP 2006		
	-	Created and implemented functionality from existing scripts in VSS
	Mahesh Nagarajan	13 SEP 2006
	-	Added alternates for "all images" grouping; this functionality may be disabled
		owing to its current useless-ness when it comes to handling both stills and cines
	-	window-dressing and typo corrections
	Mahesh Nagarajan	12 FEB 2006
	-	Site customized code will be removed and re-located to GroupES.site files ->
		starting with 11.5, unless extraction routines are fundamentally flawed, all
		change requests will be incorporated into a site file.
	- 	Modified syntaxes for grouping and sorting hints as part of v11.5 re-write
	-	"All Images" will no longer be created in the sequencing scripts; HRS will take 
		responsibility for generating this sequence
	Mahesh Nagarajan   May 17, 2007
	-	Removed the modality prefix and sort suffix from sort names as it looked stupid
	Mahesh Nagarajan   May 28, 2007
	- 	Bringing back the "All Images" sequence until the corresponding HRS feature gets implemented; this will get one sort order
		called "Default"	
	Shudong Liu    Feb. 18, 2009
	- 	Removed "*All Images*" sequence for HMI 11.6		
--]]

function DeclareTags()
end

function RegisterSortingHintTypes( )
-- ////////////////////////////////////////////////////////////////////////////
-- This function will register the various sort orders that are created for ES
-- ////////////////////////////////////////////////////////////////////////////
    RegisterHintType( "DEFAULT SORT", "Default" )
end

function Execute()    
-- ////////////////////////////////////////////////////////////////////////////
-- generates the hints for the sequencer as follows 
-- Group by image UID; thereby making each image its own sequence
-- ////////////////////////////////////////////////////////////////////////////

    TraceC("Group ES executing\n")	

    -- If this is the wrong script for the supplied image...
    if (not SanityOK("ES")) then
		return nil
		-- =====================================================
    end
    
    DeclareTags()
	
    -- MaxN: It actually doesnt make sense to have a sort-hint for ES; as every ES
    -- sequence has only one image. The code below just ensures that the sort-hint is
    -- not null. This will also ensure that unnecessary errors are not logged.
    local sortHint01 = SortingHint:new( "Default", "DEFAULT SORT" )
    sortHint01:AddEntry(MODALITY_PROP)
    sortHint01:AddEntry(INSTANCE_NUMBER_TAG)
    sortHint01:AddEntry(IMAGE_UID_TAG)
    sortHint01:AddEntry(ALI_IMAGE_FILENAME_TAG)	
	
	-- "Sort Hint Set" created here...
	local sortHintSet01 = SortingHintSet:new( )
	sortHintSet01:AddHint( sortHint01, true ) 

	local groupHint01 = GroupingHint:new( ValueForTag( SERIES_DESC_PROP, "?" ) )		
    -- add image UID as the grouping hint ensuring the creation of a new sequence per ES image
    groupHint01:AddEntry(IMAGE_UID_TAG) -- don't check it since it should be always there 

    AddImage2Sequence( "ES Sequence", groupHint01, sortHintSet01 )
    
    TraceC("Group ES complete.\n")    
	
end

