Exemple #1
0
def evtLoop(s, tok):
  # Each request comes with a principal, some credentials, and the body of the
  # request. (We'll just be mocking the request for now...)
  (p, cred, request) = ExternNetwork.nextRequest()
  # If this is a request for patient records
  if isinstance(request, Request.GetPatientRecords):
    test = (PolicyTypes.checkIn(PolicyTypes.ActiveRole(p, RoleType.Doctor), s)
            or PolicyTypes.checkIn(Attribute.ActiveRole(p, RoleType.Nurse), s)
            or PolicyTypes.checkIn(Attribute.ActiveRole(
                p, RoleType.InsuranceProvider), s))
    if test:
      records, tokNew = searchByKw(p, cred, kw, s, tok)
      ExternNetwork.respond(Response.RecordList(records))
      evtLoop(s, tokNew)
    else:
      ExternNetwork.respond(Response.Denied("Sorry, insufficient privilege"))
      evtLoop(s, tok)
  elif isinstance(request, Request.GetRecordContents):
    r = request.record   
    test = (p == r.author or
            ((p == r.patient) and
              PolicyTypes.checkIn(
                Attribute.ActiveRole(p, RoleType.Patient), s)) or
            (PolicyTypes.checkIn(Attribute.IsTreating(p, r.patient), s) and
              ((isinstance(r.subject, HealthDB.Psychiatric) and
                  PolicyTypes.checkIn(
                    Attribute.ActiveRole(p, RoleType.Psychiatrist), s)) or
               ((not isinstance(r.subject, HealthDB.Psychiatric) and 
                  PolicyTypes.checkIn(
                    Attribute.ActiveRole(p, RoleType.Doctor), s))))))
    if test:
      d, con, al, tokNew = HealthDB.readContents(p, cred, r, s, tok)
      ExternNetwork.respond(Response.RecordContents(d, con, al))
      evtloop(s, tokNew)
    else:
      ExternNetwork.respond(Response.Denied("Sorry, insufficient privilege"))
      evtLoop(s, tok)
  if isinstance(request, Request.ActivateRole):
    r = request.role   
    test = PolicyTypes.checkIn(Attribute.CanBeInRole(p, r), s)
    if test:
      sNew, tokNew = HealthDB.activateRole(p, cred, r, s, tok)
      ExternNetwork.respond(ExternNework.Ok)
      evtLoop(sNew, tokNew)
    else:
      ExternNetwork.respond(
        ExternNetwork.Denied("Sorry, insufficient privilege"))
      evtloop(s, tok)
  if isinstance(request, Request.ConsentToTreatment):
    doc = request.prin
    test = (PolicyTypes.checkIn(Attribute.ActiveRole(p, RoleType.Patient), s)
              and policyTypes.checkIn(Attribute.CanBeInRole(doc, Doctor), s))
    if test:
      sNew, tokNew = AuthAPI.consentToTreatment(p, cred, doc, s, tok)
      ExternNetwork.respond(Response.Ok)
      evtLoop(sNew, tokNew)
    else:
      ExternNetwork.respond(Response.Denied("Sorry, insufficient privilege"))
      evtLoop(s, tok)
Exemple #2
0
 def __init__(self, db_params_dict, debug):
     self.garmindb = GarminDB.GarminDB(db_params_dict, debug)
     self.mondb = GarminDB.MonitoringDB(db_params_dict, debug)
     self.garminsumdb = GarminDB.GarminSummaryDB(db_params_dict, debug)
     self.sumdb = HealthDB.SummaryDB(db_params_dict, debug)
     self.garmin_act_db = GarminDB.ActivitiesDB(db_params_dict, debug)
     self.english_units = (GarminDB.Attributes.measurements_type_metric(
         self.garmindb) == False)
 def __init__(self, db_params_dict, debug):
     self.garmindb = GarminDB.GarminDB(db_params_dict, debug)
     self.mondb = GarminDB.MonitoringDB(db_params_dict, debug)
     self.garminsumdb = GarminDB.GarminSummaryDB(db_params_dict, debug)
     self.sumdb = HealthDB.SummaryDB(db_params_dict, debug)
     self.garmin_act_db = GarminDB.ActivitiesDB(db_params_dict, debug)
     self.english_units = (GarminDB.Attributes.get(
         self.garmindb, 'dist_setting') == 'statute')
Exemple #4
0
 def __init__(self, db_params_dict, debug):
     self.garmin_db = GarminDB.GarminDB(db_params_dict, debug)
     self.garmin_mon_db = GarminDB.MonitoringDB(db_params_dict, debug)
     self.garmin_sum_db = GarminDB.GarminSummaryDB(db_params_dict, debug)
     self.sum_db = HealthDB.SummaryDB(db_params_dict, debug)
     self.garmin_act_db = GarminDB.ActivitiesDB(db_params_dict, debug)
     self.measurement_system = GarminDB.Attributes.measurements_type(
         self.garmin_db)
 def __init__(self, db_params_dict, debug):
     """Return an instance of the Analyze class."""
     self.garmin_db = GarminDB.GarminDB(db_params_dict, debug)
     self.garmin_mon_db = GarminDB.MonitoringDB(db_params_dict, debug)
     self.garmin_sum_db = GarminDB.GarminSummaryDB(db_params_dict, debug)
     self.sum_db = HealthDB.SummaryDB(db_params_dict, debug)
     self.garmin_act_db = GarminDB.ActivitiesDB(db_params_dict, debug)
     self.measurement_system = GarminDB.Attributes.measurements_type(self.garmin_db)
 def setUpClass(cls):
     db_params = GarminDBConfigManager.get_db_params()
     db = HealthDB.SummaryDB(db_params)
     table_dict = {
         'summary_table': HealthDB.Summary,
         'months_table': HealthDB.MonthsSummary,
         'weeks_table': HealthDB.WeeksSummary,
         'days_table': HealthDB.DaysSummary
     }
     super().setUpClass(db, table_dict)
Exemple #7
0
 def graph_activity(self, activity, period, days):
     """Generate a graph for the given activity with points every period spanning days."""
     if period is None or period == 'default':
         period = GarminDBConfigManager.graphs_activity_config(activity, 'period')
     if days is None or days == 'default':
         days = GarminDBConfigManager.graphs_activity_config(activity, 'days')
     db_params_dict = GarminDBConfigManager.get_db_params()
     sum_db = HealthDB.SummaryDB(db_params_dict, self.debug)
     end_ts = datetime.datetime.now()
     start_ts = end_ts - datetime.timedelta(days=days)
     table = self.__table[period]
     data = table.get_for_period(sum_db, table, start_ts, end_ts)
     if period == 'days':
         time = [entry.day for entry in data]
     else:
         time = [entry.first_day for entry in data]
     graph_func_name = '_graph_' + activity
     graph_func = getattr(self, graph_func_name, None)
     graph_func(time, data, period)
Exemple #8
0
 def __init__(self, db_params_dict):
     self.mshealthdb = MSHealthDB.MSHealthDB(db_params_dict)
     self.sumdb = HealthDB.SummaryDB(db_params_dict)
Exemple #9
0
 def stop_loc(self):
     """Return the ending location of activity segment as a Location instance."""
     return HealthDB.Location(self.stop_lat, self.stop_long)
Exemple #10
0
def main(argv):
    debug = 0
    save = False
    hr = False
    itime = False
    steps = False
    weight = False
    days = 31
    end_ts = datetime.datetime.now()
    start_ts = end_ts - datetime.timedelta(days=days)
    period = 'days'
    table = {
        'days': HealthDB.DaysSummary,
        'weeks': HealthDB.WeeksSummary,
        'months': HealthDB.MonthsSummary
    }

    try:
        opts, args = getopt.getopt(argv, "adhHl:p:rsSt:wv", [
            "all", "latest=", "period=", "hr", "itime", "save", "steps",
            "trace=", "weight", "version"
        ])
    except getopt.GetoptError as e:
        __print_usage(sys.argv[0], str(e))

    for opt, arg in opts:
        if opt == '-h':
            __print_usage(sys.argv[0])
        elif opt in ("-v", "--version"):
            __print_version(sys.argv[0])
        elif opt in ("-a", "--all"):
            logger.info("All: " + arg)
            hr = GarminDBConfigManager.is_stat_enabled('rhr')
        elif opt in ("-l", "--latest"):
            days = int(arg)
            end_ts = datetime.datetime.now()
            start_ts = end_ts - datetime.timedelta(days=days)
        elif opt in ("-p", "--period"):
            logging.info("Period: %s", arg)
            period = arg
        elif opt in ("-S", "--save"):
            save = True
        elif opt in ("-s", "--steps"):
            steps = True
        elif opt in ("-H", "--hr"):
            logging.debug("HR")
            hr = True
        elif opt in ("-i", "--itime"):
            logging.debug("Intenist time")
            itime = True
        elif opt in ("-w", "--weight"):
            logging.info("Weight")
            weight = True
        elif opt in ("-t", "--trace"):
            debug = int(arg)

    if debug > 0:
        root_logger.setLevel(logging.DEBUG)
    else:
        root_logger.setLevel(logging.INFO)

    db_params_dict = GarminDBConfigManager.get_db_params()
    sum_db = HealthDB.SummaryDB(db_params_dict, debug)
    data = table[period].get_for_period(sum_db, table[period], start_ts,
                                        end_ts)
    if period == 'days':
        time = [entry.day for entry in data]
    else:
        time = [entry.first_day for entry in data]

    if hr:
        graph_hr(time, data, period, save)

    if itime:
        graph_itime(time, data, period, save)

    if steps:
        graph_steps(time, data, period, save)

    if weight:
        graph_weight(time, data, period, save)
Exemple #11
0
 def start_loc(self):
     return HealthDB.Location(self.start_lat, self.start_long)
Exemple #12
0
 def start_loc(self):
     """Return the lap start location."""
     return HealthDB.Location(self.start_lat, self.start_long)
Exemple #13
0
 def position(self):
     return HealthDB.Location(self.position_lat, self.position_long)
Exemple #14
0
 def __init__(self, db_params_dict):
     """Return an instance of the Analyze class."""
     self.fitbitdb = FitBitDB.FitBitDB(db_params_dict)
     self.sumdb = HealthDB.SummaryDB(db_params_dict)
Exemple #15
0
 def position(self):
     """Return the location where the record was recorded."""
     return HealthDB.Location(self.position_lat, self.position_long)
Exemple #16
0
 def __init__(self, db_params):
     """Return an instance of the Analyze class."""
     self.mshealthdb = MSHealthDB.MSHealthDB(db_params)
     self.sumdb = HealthDB.SummaryDB(db_params)
Exemple #17
0
 def __init__(self, db_params_dict):
     self.fitbitdb = FitBitDB.FitBitDB(db_params_dict)
     self.sumdb = HealthDB.SummaryDB(db_params_dict)