--[[
     This grouping script partition computed radiograpy (CR) images as follows:
     -	Each image in its own sequence
     -	All images in an "All Images" sequence
       
     Allan Noordvyk,      August                      CREATED
     Cristian Bonciu			27 SEP 2004
     -	implemented as per the comments above
     Allan Noordvyk			11 APR 2005
     -	Changed *All Images* to group by frame type not modality in order 
          to handle CR/RF studies.
       Allan Noordvyk			16 SEP 2005
     -	Added modality sort for All Images sequence for better handling of 
          CR/RF studies.
     Mahesh Nagarajan		18 JAN 2006
     -	Added sort hint for ID SOP Instance UID just before filename
     Mahesh Nagarajan    March 28, 2006
     -	Added sort hint for thumbnail group to ensure that CAD images come
		last in the 'all images' sequence
     Mahesh Nagarajan		18 APR 2006
     -	Increased the priority of sort hint for file name; this ensures that the 
		images in the "all images" sequence are in the same order they were sent.
     Cartik S. Sharma			17 JAN 2007	 
     -	Modified location of conditional checks for acqusition date and time, so that
		those could be checked after the modality property.
	Mahesh Nagarajan		01 FEB 2007
	-	Site customized code will be removed and re-located to GroupCR.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		17 MAY 2007
	-	Removed the modality prefix and sort suffix from sort names as it looked stupid
	Mahesh Nagarajan		28 MAY 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		07 FEB 2008
	-	Adding back site-specific code snippets; after a long discussion with Cristian B., it 
		is understood that this code has to stay in the code until proper site files have been 
		installed. Such code is added back but within "dollar sign" demarcations to ensure easy 
		removal at a later date.
     Mahesh Nagarajan		15 APR 2008
	-	Added SouthWestern Mississippi to list of institutions where image acquisition time
		is given priority for sorting.
     Mahesh Nagarajan    		26 MAY 2008
	-	Added St. Lukes Episcopal to list of institutions where image acquisition time
		is given priority for sorting.
	Mahesh Nagarajan		06 JUN 2008
	-	Added Bayshore medical to list of institutions where image number is given priority for sorting.		
	Mahesh Nagarajan		08 JUL 2008
	-	Added Huntsville to list of institutions where image acquisition time
		is given priority for sorting.
       Shudong Liu    Oct. 27, 2008
	  - Customized for Kosair Childrens Hospital to give image file name lower priority.
       Shudong Liu    Nov. 10,  2008
	  - Customized for Monongolia General Hospital to sort images by acquisition time. (CRDB68229)
	  - Customize the script to sort CR images by IMAGE ACQUISITON TIME instead of 
	      image file name. (CRDB68577)
       Shudong Liu    Dec. 17,  2008
	  - Customized for Pocono Medical Center to sort images by acquisition time.(CRDB69932)	
       Shudong Liu    Jan. 14, 2009
	  - Customized for CHRISTUS St. Elizabeth Hospital (CRDB70500) and site CSSS GATINEAU (CRDB70464)  
	    to sort images by acquisition time. 	  
       Shudong Liu    Jan. 28, 2009
	  - Customized for ELKHART GENERAL HOSPITAL to sort images by acquisition time. (CRDB70838)
        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 CR
-- ////////////////////////////////////////////////////////////////////////////
    RegisterHintType( "DEFAULT SORT", "Default" )
	RegisterHintType( "ALL IMAGES FILENAME SORT", "File Name" )
	RegisterHintType( "ALL IMAGES ACQ TIME SORT", "Acquisition Time" )
	RegisterHintType( "ALL IMAGES IMAGE NUMBER SORT", "Image Number" )
end

function Execute()

    TraceC("Group CR 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
	-- ////////////////////////////////////////////////////////////////////////////

    -- No modality check since also used for scanned films and other "modalities"
	
    -- MaxN: It actually doesnt make sense to have a sort-hint for CR; as every CR
    -- 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 CR image
    groupHint01:AddEntry(IMAGE_UID_TAG) -- don't check it since it should be always there 
      
    AddImage2Sequence( "CR Sequence", groupHint01, sortHintSet01 )
	    
    TraceC("Group CR complete.\n")

end
