--[[
   This script generates the hints for sorting the CT sequences within the study
    scout sequences first
     Cristian Bonciu, August         2004
	-	CREATED and implemented the above functionality for development testing purposes 
     Allan Noordvyk	 	July 18, 2005       
	-	Reversed primary sorting order so that scouts grouped first.
     Mahesh Nagarajan			November 14, 2005
	-	On request of Outpatient Radiology LLC, Wyoming, reversed the sorting order yet 
		again so that scouts were pushed right to the end
     Mahesh Nagarajan		February 14, 2006
	-	Removed sort hint for Image Type as its made useless by the thumbnail group property
     Mahesh Nagarajan		January 31, 2007
	- 	Modified syntaxes for sorting hints as part of v11.5 re-write
	-	Site customized code will be removed and re-located to SortCT.site files -> starting with 11.5, 
		unless sort orders are fundamentally flawed, all change requests to sorting schemes will be
		incorporated into a site file for the site.
     Shudong Liu   January 6, 2009
	-	Customized for site University of Kentucky Medical Center to sort images by series time. (REI11225)
--]]

function Execute()
-- ////////////////////////////////////////////////////////////////////////////
-- generates the hints for sorting the CT sequences within a study
--- ////////////////////////////////////////////////////////////////////////////
 
     TraceC( "Executing sort for CT...\n" )
	 
	-- Sanity Check
	local modalityAttr = GetAttr(MODALITY_TAG)
	if( not modalityAttr ) then
		return -- wrong context (no modality in the input collection)
		-- =====================================================
	end
	if( not BestMatchInAttr(modalityAttr, "CT") ) then
		return -- wrong script or wrong context (CT script applied on other modality)
		-- =====================================================
	end	

	local sortByThumbnailProp = true
	local InstName = GetAttr( INSTITUTION_NAME_TAG )	
	if ( InstName ~= nil and BestWordMatchInAttr(InstName, "University of Kentucky Medical Center") ) then
		sortByThumbnailProp = false
	end	
	
    local sortHint01 = SortingHint:new("CT Sequence Sort", "DEFAULT")

	if (sortByThumbnailProp) then
		sortHint01:AddEntry(THUMBNAIL_GRP_PROP, true)         
	    -- Ensures that Originals come first and Scouts go last
		-- MIPs, MPRs and other derived types come in the middle 
	end
        
	sortHint01:AddEntry(SERIES_DATE_TAG, true)
    sortHint01:AddEntry(SERIES_TIME_TAG, true)
    sortHint01:AddEntry(SERIES_NUMBER_TAG, true)
    sortHint01:AddEntry(PHASE_PROP, true)    
    sortHint01:AddEntry(ACQ_NUMBER_TAG, true)   
    sortHint01:AddEntry(SERIES_UID_TAG, true)
    
    SortSequencesInStudy(sortHint01) 
	
    TraceC( "Completed Sort for CT.\n" )	
end
