Esempio n. 1
0
  def test_is_alertworthy(self):
    visit_stats = models.VisitStatistics._parse_visit_statistics(
                    TestVisitStatistics.XML1)
    self.assertTrue(visit_stats.is_alertworthy())
    visit_stats = models.VisitStatistics._parse_visit_statistics(
                    TestVisitStatistics.XML2)
    self.assertTrue(visit_stats.is_alertworthy())
    xml = """<growthserver_response
     date_generated="2009-11-14 20:39:51 +0000">
      <input_data name="dan" sex="MALE" birth_date="2004-01-01"
       visit_date="2005-01-01" weight="10.0" height="75.0"
        height_position="STANDING"/>
      <results age_in_days="366" body_mass_index="17.450514702931162"
       weight_for_length_or_height_percentile="66.7783773713256"
       weight_for_length_or_height_zscore="0.43380445727739364"
       weight_for_age_percentile="62.66980078419666"
       weight_for_age_zscore="0.32312372717576165"
       length_or_height_for_age_percentile="48.690119540446844"
       length_or_height_for_age_zscore="-0.03284387440408244"
       body_mass_index_for_age_percentile="68.23541425051107"
       body_mass_index_for_age_zscore="0.47429455486975625"
       head_circumference_for_age_percentile="93.31248910073958"
       head_circumference_for_age_zscore="1.4994767847047703"/>
      </growthserver_response>"""
    visit_stats = models.VisitStatistics._parse_visit_statistics(xml)
    self.assertEquals(-1.0, util.bucket_zscore(
          visit_stats.get_worst_zscore()))
    self.assertFalse(visit_stats.is_alertworthy())

    xml = """<growthserver_response
     date_generated="2009-11-14 20:39:51 +0000">
      <input_data name="dan" sex="MALE" birth_date="2004-01-01"
       visit_date="2005-01-01" weight="10.0" height="75.0"
        height_position="STANDING"/>
      <results age_in_days="366" body_mass_index="17.450514702931162"
       weight_for_length_or_height_percentile="0.1"
       weight_for_length_or_height_zscore="-3.91"
       weight_for_age_percentile="42.8"
       weight_for_age_zscore="-0.18"
       length_or_height_for_age_percentile="99.6"
       length_or_height_for_age_zscore="2.69"
       body_mass_index_for_age_percentile="1.7"
       body_mass_index_for_age_zscore="-2.13"
       head_circumference_for_age_percentile="93.31248910073958"
       head_circumference_for_age_zscore="1.4994767847047703"/>
      </growthserver_response>"""
    visit_stats = models.VisitStatistics._parse_visit_statistics(xml)
    self.assertEquals(-4.0, util.bucket_zscore(
          visit_stats.get_worst_zscore()))
    self.assertTrue(visit_stats.is_alertworthy())
Esempio n. 2
0
  def set_latest_visit(self, latest_visit = None, force = False, put = True):
    '''Set latest visit cache.

    latest_visit: if the caller knows the latest visit, it can be given,
                  otherwise it is queried
    force: recalculate even if the cache is the same
    put: if False, don't put, so caller can do bulk puts.

    Could throw a TypeError if there is no visit with a numeric zscore.
    '''
    logging.info("Recalculate latest_visit_cache for %s" % self.short_string)
    needs_put = False
    if latest_visit is None:
      latest_visit = self.get_latest_visit()
    if latest_visit:
      if force:
        self.latest_visit_date = latest_visit.visit_date
        self.latest_visit_short_string = latest_visit.short_string
        # TODO(dan): This throws a TypeError if get_worst_zscore is not
        # a float.  Do all clients deal with that?
        self.latest_visit_worst_zscore_rounded = util.bucket_zscore(
          latest_visit.get_visit_statistics().get_worst_zscore())
        # Bound at the bottom for sorting and filtering
        # HACK(dan): This -3 is linked to PatientSearchForm
        if self.latest_visit_worst_zscore_rounded < -3:
          self.latest_visit_worst_zscore_rounded = Patient.BELOW_LOWEST_ZSCORE
#        logging.info("rounded %s" % self.latest_visit_worst_zscore_rounded)

        needs_put = True
        if put:
          self.put()
#        logging.info("Needs put: %s" % self.short_string)
    return needs_put
Esempio n. 3
0
  def test_nans(self):
    '''This was a bug in bucket_zscore: all zscores are NaNs'''

    xml= """
      <growthserver_response date_generated="2011-02-08 21:35:49 +0000">
        <input_data name="" sex="MALE" birth_date="2011-02-10"
         visit_date="2011-02-08"
         weight="30.0" height="40.0" height_position="STANDING"/>
        <results age_in_days="-1" body_mass_index="181.1058322114833"
         weight_for_length_or_height_percentile="NaN"
         weight_for_length_or_height_zscore="NaN"
         weight_for_age_percentile="NaN" weight_for_age_zscore="NaN"
         length_or_height_for_age_percentile="NaN"
         length_or_height_for_age_zscore="NaN"
         body_mass_index_for_age_percentile="NaN"
         body_mass_index_for_age_zscore="NaN"
         head_circumference_for_age_percentile="NaN"
         head_circumference_for_age_zscore="NaN"/>
      </growthserver_response>"""
    visit_stats = models.VisitStatistics._parse_visit_statistics(xml)
    self.assertTrue(util.isNaN(util.bucket_zscore(
          visit_stats.get_worst_zscore())))