class MetricsEhrServiceTest(SqlTestBase):

  def setUp(self, with_data=True, use_mysql=True):
    super(MetricsEhrServiceTest, self).setUp(with_data=with_data, use_mysql=use_mysql)
    self.service = MetricsEhrService()
    self.hpo_dao = HPODao()
    self.org_dao = OrganizationDao()

    self.hpo_foo = self._make_hpo(hpoId=10, name='FOO', displayName='Foo')
    self.hpo_bar = self._make_hpo(hpoId=11, name='BAR', displayName='Bar')

    self.org_foo_a = self._make_org(
      organizationId=10,
      externalId='FOO_A',
      displayName='Foo A',
      hpoId=self.hpo_foo.hpoId
    )
    self.org_bar_a = self._make_org(
      organizationId=11,
      externalId='BAR_A',
      displayName='Bar A',
      hpoId=self.hpo_bar.hpoId
    )
    self.org_bar_b = self._make_org(
      organizationId=12,
      externalId='BAR_B',
      displayName='Bar B',
      hpoId=self.hpo_bar.hpoId
    )

  def _make_hpo(self, **kwargs):
    hpo = HPO(**kwargs)
    self.hpo_dao.insert(hpo)
    return hpo

  def _make_org(self, **kwargs):
    org = Organization(**kwargs)
    self.org_dao.insert(org)
    return org

  def test_get_organization_ids_from_hpo_ids(self):
    self.assertEqual(
      self.service._get_organization_ids_from_hpo_ids([self.hpo_foo.hpoId]),
      [self.org_foo_a.organizationId]
    )
    self.assertEqual(
      self.service._get_organization_ids_from_hpo_ids([self.hpo_bar.hpoId]),
      [
        self.org_bar_a.organizationId,
        self.org_bar_b.organizationId,
      ]
    )
    self.assertEqual(
      self.service._get_organization_ids_from_hpo_ids([self.hpo_foo.hpoId, self.hpo_bar.hpoId]),
      [
        self.org_foo_a.organizationId,
        self.org_bar_a.organizationId,
        self.org_bar_b.organizationId,
      ]
    )
  def setUp(self, with_data=True, use_mysql=True):
    super(MetricsEhrServiceTest, self).setUp(with_data=with_data, use_mysql=use_mysql)
    self.service = MetricsEhrService()
    self.hpo_dao = HPODao()
    self.org_dao = OrganizationDao()

    self.hpo_foo = self._make_hpo(hpoId=10, name='FOO', displayName='Foo')
    self.hpo_bar = self._make_hpo(hpoId=11, name='BAR', displayName='Bar')

    self.org_foo_a = self._make_org(
      organizationId=10,
      externalId='FOO_A',
      displayName='Foo A',
      hpoId=self.hpo_foo.hpoId
    )
    self.org_bar_a = self._make_org(
      organizationId=11,
      externalId='BAR_A',
      displayName='Bar A',
      hpoId=self.hpo_bar.hpoId
    )
    self.org_bar_b = self._make_org(
      organizationId=12,
      externalId='BAR_B',
      displayName='Bar B',
      hpoId=self.hpo_bar.hpoId
    )
Example #3
0
  def get_filtered_results(self, stratification, start_date, end_date, awardee_ids,
                           enrollment_statuses, version):
    """Queries DB, returns results in format consumed by front-end

    :param start_date: Start date object
    :param end_date: End date object
    :param awardee_ids: indicate awardee ids
    :param enrollment_statuses: indicate the enrollment status
    :param stratification: How to stratify (layer) results, as in a stacked bar chart
    :param version: indicate the version of the result filter
    :return: Filtered, stratified results by date
    """

    if stratification == Stratifications.TOTAL:
      dao = MetricsEnrollmentStatusCacheDao(MetricsCacheType.PUBLIC_METRICS_EXPORT_API)
      return dao.get_total_interested_count(start_date, end_date, awardee_ids)
    elif stratification == Stratifications.ENROLLMENT_STATUS:
      dao = MetricsEnrollmentStatusCacheDao(MetricsCacheType.PUBLIC_METRICS_EXPORT_API)
      return dao.get_latest_version_from_cache(start_date, end_date, awardee_ids)
    elif stratification == Stratifications.GENDER_IDENTITY:
      dao = MetricsGenderCacheDao(MetricsCacheType.PUBLIC_METRICS_EXPORT_API, version)
      return dao.get_latest_version_from_cache(start_date, end_date, awardee_ids,
                                               enrollment_statuses)
    elif stratification == Stratifications.AGE_RANGE:
      dao = MetricsAgeCacheDao(MetricsCacheType.PUBLIC_METRICS_EXPORT_API)
      return dao.get_latest_version_from_cache(start_date, end_date, awardee_ids,
                                               enrollment_statuses)
    elif stratification == Stratifications.RACE:
      dao = MetricsRaceCacheDao(MetricsCacheType.PUBLIC_METRICS_EXPORT_API, version)
      return dao.get_latest_version_from_cache(start_date, end_date, awardee_ids,
                                               enrollment_statuses)
    elif stratification in [Stratifications.GEO_STATE, Stratifications.GEO_CENSUS,
                            Stratifications.GEO_AWARDEE]:
      dao = MetricsRegionCacheDao(MetricsCacheType.PUBLIC_METRICS_EXPORT_API)
      return dao.get_latest_version_from_cache(end_date, stratification, awardee_ids,
                                               enrollment_statuses)
    elif stratification == Stratifications.LANGUAGE:
      dao = MetricsLanguageCacheDao(MetricsCacheType.PUBLIC_METRICS_EXPORT_API)
      return dao.get_latest_version_from_cache(start_date, end_date, awardee_ids,
                                               enrollment_statuses)
    elif stratification == Stratifications.LIFECYCLE:
      dao = MetricsLifecycleCacheDao(MetricsCacheType.PUBLIC_METRICS_EXPORT_API)
      return dao.get_latest_version_from_cache(end_date, awardee_ids)
    elif stratification == Stratifications.PRIMARY_CONSENT:
      dao = MetricsLifecycleCacheDao(MetricsCacheType.PUBLIC_METRICS_EXPORT_API)
      return dao.get_primary_consent_count_over_time(start_date, end_date, awardee_ids)
    elif stratification == Stratifications.EHR_METRICS:
      params = {
        'start_date': convert_to_datetime(start_date),
        'end_date': convert_to_datetime(end_date),
        'hpo_ids': awardee_ids,
        'interval': INTERVAL_DAY
      }
      result_set = MetricsEhrService().get_metrics(**params)
      if 'metrics_over_time' in result_set:
        return result_set['metrics_over_time']
      else:
        return []
    else:
      raise BadRequest('Invalid stratification: %s' % str(stratification))
Example #4
0
 def get(self):
     valid_arguments = self.parse_input()
     org_ids = self._get_organization_ids_from_organizations(
         valid_arguments['organizations'])
     return MetricsEhrService().get_metrics(
         start_date=valid_arguments['start_date'],
         end_date=valid_arguments['end_date'],
         interval=valid_arguments['interval'],
         organization_ids=org_ids)
Example #5
0
 def get(self):
     valid_arguments = self.parse_input()
     return MetricsEhrService().get_current_ehr_data(
         organization_ids=valid_arguments['organization'])
Example #6
0
 def get(self):
     valid_arguments = self.parse_input()
     return MetricsEhrService().get_organization_metrics_data(
         end_date=valid_arguments['end_date'],
         organization_ids=valid_arguments['organization'])