--[[
   This script generates the hints for sorting the MG sequences within the study
   acquisition date/time based sorting
   
	Cristian Bonciu			August 2004
     -	Created and  implemented the above functionality for development testing purposes   
	Mahesh Nagarajan		23 MAY 2006
     -	Added sort hint for thumbnail group property to ensure that CAD images
		were sent to the back of the thumbnail bar
	Mahesh Nagarajan		13 FEB 2007
	- 	Modified syntaxes for sorting hints as part of v11.5 re-write
	-	Site customized code will be removed and re-located toSortMG.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                    13 MAY 2008
	- 	Customized for site Resurrection Center for Breast Care to change sort order.	
	Mahesh Nagarajan		22 May 2008	
	-	Making the above change a generic one to conform with "All Images" sorting
    James Zhang     Mar 25, 2010 
    - Customized for RUIS - Abitibi to sort by series number (REI 18478/CRDB85099).
--]]

-- ////////////////////////////////////////////////////////////////////////////
-- MG sorting function
-- ////////////////////////////////////////////////////////////////////////////

function Execute()
-- ////////////////////////////////////////////////////////////////////////////
-- generates the hints for sorting the MG sequences like sorting images 
-- within a regular sequence, since every MG image stays in its own sequence
-- ////////////////////////////////////////////////////////////////////////////
 
-- ////////////////////////////////////////////////////////////////////////////
	local modalityAttr = GetAttr(MODALITY_TAG)
	if( not modalityAttr ) then
		return -- wrong context (no modality in the input collection)
		-- =====================================================
	end
	if( not BestMatchInAttr(modalityAttr, "MG") ) then
		return -- wrong script or wrong context (MG script applied on other modality)
		-- =====================================================
	end	
	
    CSSSRN_VAL = "CSSS ROUYN NORANDA"
	local SiteName = GetAttr(INSTITUTION_NAME_TAG)

    local sortHint01 = SortingHint:new("MG Sequence Sort", "DEFAULT")
    sortHint01:AddEntry(THUMBNAIL_GRP_PROP)
	if (SiteName ~= nil and BestWordMatchInAttr(SiteName, CSSSRN_VAL)) then
        sortHint01:AddEntry(SERIES_NUMBER_TAG)
    end
    sortHint01:AddEntry(ACQUISITON_DATETIME_TAG)
    sortHint01:AddEntry(ACQUISITON_DATE_TAG)
    sortHint01:AddEntry(ACQUISITON_TIME_TAG)
    sortHint01:AddEntry(IMAGE_ACQUISITON_TIME_TAG)
    sortHint01:AddEntry(SERIES_NUMBER_TAG)
    sortHint01:AddEntry(MG_PROJECTION_PROP)
    sortHint01:AddEntry(ACQ_NUMBER_TAG)
    sortHint01:AddEntry(INSTANCE_NUMBER_TAG)
    sortHint01:AddEntry(ALI_IMAGE_FILENAME_TAG)
    
    SortSequencesInStudy(sortHint01) 
end

