--[[
     This grouping script partition digital x-ray (DX) images as follows:
          Each image in its own sequence
          All images in an "All Images" sequence
	
	Mahesh Nagarajan	04 May 2006
	-	The "All Images" sequence shouldnt be grouped by modality as this creates multiple
		instances of the "All Images" sequences in multi-modality studies.
	-	Added sort hints to match the "all images" sorting scheme used by CR
     Mahesh Nagarajan	12 February 2006  
	-	Site customized code will be removed and re-located to GroupDX.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; it has been decided that this sequence (in CR) will have the option of 
		being sorted on acquisition time or file name.
	Mahesh Nagarajan   July 08, 2007	
	-	Adding another sort hint - a combination of series & image number; primarily for 
		use at Hopital du Sacre Coeur de Mtl
	Shudong Liu 	14 JAN 2009
	-	Customized for site Hopital du Sacre Coeur de Mtl to sort image by laterality. (CRDB70236)	
	Shudong Liu    Feb. 18, 2009
	- 	Removed "*All Images*" sequence for HMI 11.6	
--]]

function RegisterSortingHintTypes( )
-- ////////////////////////////////////////////////////////////////////////////
-- This function will register the various sort orders that are created for DX
-- ////////////////////////////////////////////////////////////////////////////
    RegisterHintType( "DEFAULT SORT", "Default" )
	RegisterHintType( "ALL IMAGES FILENAME SORT", "File Name" )
	RegisterHintType( "ALL IMAGES ACQ TIME SORT", "Acquisition Time" )	
	RegisterHintType( "ALL IMAGES SER_IMAGE NUMBER SORT", "Series/Image Number" )
	RegisterHintType( "ALL IMAGES LATERALITY SORT", "Laterality" )	
end

function Execute()

    TraceC("Group DX executing...\n")

-- ////////////////////////////////////////////////////////////////////////////
-- generates the hints for the sequencer as follows 
-- add IMAGE_UID_TAG as one grouping hint to clasify each image in its own sequence
-- add STUDY_UID_TAG as the grouping hint for the "All images" sequence
-- ////////////////////////////////////////////////////////////////////////////
	
    -- If this is the wrong script for the supplied image...
    if (not SanityOK("DX")) then
		return nil
		-- =====================================================
    end
	
    -- MaxN: It actually doesnt make sense to have a sort-hint for DX; as every DX
    -- 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 DX image
    groupHint01:AddEntry(IMAGE_UID_TAG) -- don't check it since it should be always there 

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