                 for (column, val) in sample {
                     log.info("Refreshing population aggregate for \(column)")
                     if let sampleValue = val as? Double,
-                           typeIdentifier = HMConstants.sharedInstance.mcdbToHK[column]
+                        typeIdentifier = HMConstants.sharedInstance.mcdbToHK[column]
                     {
                         switch typeIdentifier {
                         case HKCategoryTypeIdentifierSleepAnalysis:
                             let sampleType = HKObjectType.categoryTypeForIdentifier(HKCategoryTypeIdentifierSleepAnalysis)!
                             populationAggregates[sampleType] = [MCAggregateSample(value: sampleValue, sampleType: sampleType)]
-
+                            
                         case HKCategoryTypeIdentifierAppleStandHour:
                             let sampleType = HKObjectType.categoryTypeForIdentifier(HKCategoryTypeIdentifierAppleStandHour)!
                             populationAggregates[sampleType] = [MCAggregateSample(value: sampleValue, sampleType: sampleType)]
-
+                            
                         default:
                             let sampleType = HKObjectType.quantityTypeForIdentifier(typeIdentifier)!
                             populationAggregates[sampleType] = [MCAggregateSample(value: sampleValue, sampleType: sampleType)]

import HealthKit
import Async


/**
  This is the manager of information for the comparison population.
  By providing this comparison we provide our study participants with a greater ability to view themselves in context.

  Initially this is defined by the NHANES data.
  With sufficient enrolled subjects, this will be determined by aggregates over the ongoing study population.

 - remark: pulls from PostgreSQL store (AWS RDS) -- see MCRouter --
 */
public class PopulationHealthManager {

    public static let sharedManager = PopulationHealthManager()

    public var aggregateRefreshDate : NSDate = NSDate()

    public var mostRecentAggregates = [HKSampleType: [MCSample]]() {
        didSet {
            aggregateRefreshDate = NSDate()
        }
    }

    // MARK: - Population query execution.

    // Clear all aggregates.
    public func resetAggregates() { mostRecentAggregates = [:] }

    // Retrieve aggregates for all previewed rows.
    public func fetchAggregates() {
        var columnIndex = 0
        var columns : [String:AnyObject] = [:]

        for hksType in PreviewManager.supportedTypes {
            if let column = HMConstants.sharedInstance.hkToMCDB[hksType.identifier] {
                columns[String(columnIndex)] = column
                columnIndex += 1
            }
        }

        // TODO: set filtering constraints from query view controllers.
        let tstart  : NSDate             = NSDate(timeIntervalSince1970: 0)
        let tend    : NSDate             = NSDate()
        var filter  : [String:AnyObject] = [:]

        // Add population filter parameters.
        let popQueryIndex = QueryManager.sharedManager.getSelectedQuery()
        let popQueries = QueryManager.sharedManager.getQueries()

            }
        }
    }
    
    func refreshAggregatesFromMsg(payload: AnyObject?) {
        var populationAggregates : [HKSampleType: [MCSample]] = [:]
        if let aggregates = payload as? [[String: AnyObject]] {
