 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.
-
+ 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()

                }
            }
        }

        let params : [String:AnyObject] = [
            "tstart"  : tstart.timeIntervalSince1970,
            "tend"    : tend.timeIntervalSince1970,
            "columns" : columns,
            "filter"  : filter
        ]

        Service.json(MCRouter.AggMeasures(params), statusCode: 200..<300, tag: "AGGPOST") {
            _, response, result in
            guard !result.isSuccess else {

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