--[[
   This script generates the hints for sorting the NM sequences within the study
    scout sequences first
	Cristian Bonciu		August 2004
	  - Created and implemented the above functionality for development testing purposes   
	Mahesh Nagarajan	31 FEB 2007
	  - Modified syntaxes for sorting hints as part of v11.5 re-write
	  - Site customized code will be removed and re-located to SortNM.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.	
	Mahesh Nagarajan	17 JUN 2008
	  - Modified the sorting of the "all images" sequence and the thumbnails to (1) ensure
		similar sorting for both and (2) change primary sorting to file name		
    James Zhang, Jan. 12, 2010
      - Customized for Spectrum Health to solve REI 17615.
--]]		

-- ////////////////////////////////////////////////////////////////////////////
-- end common scripting context 
-- ////////////////////////////////////////////////////////////////////////////

-- ////////////////////////////////////////////////////////////////////////////
-- NM grouping function
-- ////////////////////////////////////////////////////////////////////////////

function Execute()
-- ////////////////////////////////////////////////////////////////////////////
-- generates the hints for sorting the NM sequences within a study as follows 
-- scouts first, then the others, by series date, time, number and UID
--- ////////////////////////////////////////////////////////////////////////////
 
	local modalityAttr = GetAttr(MODALITY_TAG)
	if( not modalityAttr ) then
		return -- wrong context (no modality in the input collection)
		-- =====================================================
	end
	if( not BestMatchInAttr(modalityAttr, "NM") ) then
		return -- wrong script or wrong context (NM script applied on other modality)
		-- =====================================================
	end	
	
    local sortHint01 = SortingHint:new("NM Sequence Sort", "DEFAULT")
    
    -- ============ Site Customization goes below ==============
    SPECTRUM_EAST_VAL = "Spectrum Health East"
    local SiteName = GetAttr(INSTITUTION_NAME_TAG)
	if (SiteName ~= nil and BestWordMatchInAttr(SiteName, SPECTRUM_EAST_VAL)) then
        sortHint01:AddEntry(THUMBNAIL_GRP_PROP)
    end
    -- ============ Site Customization goes above ==============
    
    sortHint01:AddEntry(ALI_IMAGE_FILENAME_TAG)
    sortHint01:AddEntry(SERIES_DATE_TAG)
    sortHint01:AddEntry(SERIES_TIME_TAG)
    sortHint01:AddEntry(SERIES_NUMBER_TAG)
    sortHint01:AddEntry(ACQUISITON_DATETIME_TAG)
    sortHint01:AddEntry(ACQUISITON_DATE_TAG)
    sortHint01:AddEntry(ACQUISITON_TIME_TAG)
    sortHint01:AddEntry(IMAGE_ACQUISITON_TIME_TAG)
    sortHint01:AddEntry(NM_IMAGE_TYPE_PROP)
    sortHint01:AddEntry(INSTANCE_NUMBER_TAG)
    sortHint01:AddEntry(SERIES_UID_TAG)
    
    SortSequencesInStudy(sortHint01)  
end
