Exemplo n.º 1
0
 def test2(self):
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(2005,03,21),
                                           datetime.date(2007,03,25),
                                           Sex.FEMALE, 
                                           8.2, 45, 74,
                                           Measured.RECUMBENT, None)
   
   # BMI
   util.assertNear(self, 15.3, visit_stats.body_mass_index, 0.1)
   
   # Weight-for-length-or-height
   zandp = visit_stats.get_zandp('weight_for_length_or_height')
   util.assertNear(self, -1.00, zandp.zscore, 0.01)
   util.assertNear(self, 15.9, zandp.percentile, 0.1)
   
   # Weight-for-age
   zandp = visit_stats.get_zandp('weight_for_age')
   util.assertNear(self, -2.87, zandp.zscore, 0.01)
   util.assertNear(self, 0.2, zandp.percentile, 0.1)
   
   # Length-or-height for age
   zandp = visit_stats.get_zandp('length_or_height_for_age')
   util.assertNear(self, -3.87, zandp.zscore, 0.01)
   self.assertTrue(util.isNaN(zandp.percentile))
   
   # BMI-for-age
   zandp = visit_stats.get_zandp('body_mass_index_for_age')
   util.assertNear(self, -0.33, zandp.zscore, 0.01)
   util.assertNear(self, 37.2, zandp.percentile, 0.1)
   
   # HC-for-age
   zandp = visit_stats.get_zandp('head_circumference_for_age')
   util.assertNear(self, -1.58, zandp.zscore, 0.01)
   util.assertNear(self, 5.8, zandp.percentile, 0.1)
Exemplo n.º 2
0
  def export_csv_line(self, patient):
    '''A line of CSV values representing this visit and patient.

    It is in the same order as export_csv_header.
    Use the patient passed in so that we can load patients in bulk.
    '''
    assert patient.key() == self.parent_key()
    patient_line = util.csv_line(Visit._patient_prop_names,
                                 Patient.properties(),
                                 patient)
    visit_line = util.csv_line(Visit._visit_prop_names,
                               Visit.properties(),
                               self)
    visit_stats = self.get_visit_statistics()
    if visit_stats:
      visit_stats_line = util.csv_line(Visit._visit_stat_prop_names,
                                       VisitStatistics.properties(),
                                       self.get_visit_statistics())
    else:
      visit_stat_props = []
      for dummy in range(len(Visit.visit_stats_expanded_names())):
        visit_stat_props.append('')
      visit_stats_line = ",".join(visit_stat_props)

    return patient_line + "," + visit_line + "," + visit_stats_line
Exemplo n.º 3
0
 def testBmiNotNan(self):
   #tombomist is too old for most calculations, but BMI should be calculated
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(1995,03,21),
                                           datetime.date(2007,03,25),
                                           Sex.MALE,
                                           30, 49.5, 140,
                                           Measured.STANDING, None)
   util.assertNear(self, 15.3, visit_stats.body_mass_index, 0.1)
Exemplo n.º 4
0
 def testZeroDayStats(self):
   # Age is 0 days, whcih is still valid.
   # Equivalent to AA2 in the anthrotest.csv
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(2009,11,27),
                                           datetime.date(2009,11,27),
                                           Sex.FEMALE,
                                           4, 35, 49,
                                           Measured.RECUMBENT, None)
   
   # Length-or-height for age
   zandp = visit_stats.get_zandp('length_or_height_for_age')
   util.assertNear(self, -0.08, zandp.zscore, 0.01)
   util.assertNear(self, 46.8, zandp.percentile, 0.1)
Exemplo n.º 5
0
 def testLengthOrHeightForAgeNotNan(self):
   # Age is right on the border, but still valid.
   # Equivalent to AA2 in the anthrotest.csv.
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(2002,03,15),
                                           datetime.date(2007,04,14),
                                           Sex.MALE,
                                           10, 50, 65.6,
                                           Measured.RECUMBENT, None)
    
   # Length-or-height for age
   zandp = visit_stats.get_zandp('length_or_height_for_age')
   util.assertNear(self, -9.76, zandp.zscore, 0.01)
   self.assertTrue(util.isNaN(zandp.percentile))
Exemplo n.º 6
0
 def testHCforAgeNaN(self):
   # Head circumference is calculated slightly differently from other
   # stats in a way that should make it come out NaN.
   # This is "computeFinalZScore" from zscoreOtherRestricted.
   # Equivalent to AA8 in the anthrotest.csv.
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(2007,12,14),
                                           datetime.date(2008,02,29),
                                           Sex.FEMALE,
                                           8, 24.99, 63,
                                           Measured.STANDING, None)
   
   # HC-for-age
   zandp = visit_stats.get_zandp('head_circumference_for_age')
   self.assertTrue(util.isNaN(zandp.zscore))
   self.assertTrue(util.isNaN(zandp.percentile))
Exemplo n.º 7
0
  def visit_stats_expanded_names():
    '''Expand Visit._visit_stat_props.

    Each ZscoreAndPercentileProperty gets two slots: x_zscore, x_percentile'''
    visit_stat_props = []
    vsprops = VisitStatistics.properties()
    for prop in Visit._visit_stat_prop_names:
      # HACK(dan): Expand ZscoreAndPercentileProperty names into 2:
      # x_zscore, x_percentile
      # This is a hack because the printing actually takes place in
      # util.csv_line()
      if isinstance(vsprops[prop], ZscoreAndPercentileProperty):
        visit_stat_props.append('%s_zscore' % prop)
        visit_stat_props.append('%s_percentile' % prop)
      else:
        visit_stat_props.append(prop)
    return visit_stat_props
Exemplo n.º 8
0
  def testFile(self):
    lineNum = 0
    for row in csv.DictReader(open('growthcalc/anthrotest.csv')):
      lineNum += 1
      # The first fields are the visit
      name = row['name']
      sex = row['sex']
      
      try:
        dateOfBirth = datetime.datetime.strptime(row['dateOfBirth'], "%m/%d/%Y")   
      except:
        dateOfBirth = None
      
      try:
        dateOfVisit = datetime.datetime.strptime(row['dateOfVisit'], "%m/%d/%Y")
      except:
        dateOfVisit = None
        
      weight = float(row['weight'])
      height = float(row['lengthOrHeight'])
      headCircumference = float(row['headCircumference'])
      measured = row['measured']
      if row['oedema'] == "TRUE":
        oedema = True
      elif row['oedema'] == "FALSE":
        oedema = False

      visit_stats = VisitStatistics.get_stats(dateOfBirth,
                                              dateOfVisit,
                                              sex,
                                              weight,
                                              headCircumference,
                                              height,
                                              measured,
                                              oedema,
                                              None)
      
      testScore = float(row['bmi'])
      eps = float(row['bmi-eps'])
      self.assertTrue(util.isNanOrNear(
                                   testScore, visit_stats.body_mass_index, eps))
          
      testScore = float(row['weight-for-length-or-height'])
      eps = float(row['weight-for-length-or-height-eps'])
      zandp = visit_stats.get_zandp('weight_for_length_or_height')
      util.assertIsNanOrNear(self, testScore, zandp.zscore, eps)        
      testScore = float(row['weight-for-length-or-height-%'])
      eps = float(row['weight-for-length-or-height-%-eps'])
      util.assertIsNanOrNear(self, testScore, zandp.percentile, eps)        
      
      testScore = float(row['weight-for-age'])
      eps = float(row['weight-for-age-eps'])
      zandp = visit_stats.get_zandp('weight_for_age')
      util.assertIsNanOrNear(self, testScore, zandp.zscore, eps)
      testScore = float(row['weight-for-age-%'])
      eps = float(row['weight-for-age-%-eps'])        
      util.assertIsNanOrNear(self, testScore, zandp.percentile, eps)        
      
      testScore = float(row['length-or-height-for-age'])
      eps = float(row['length-or-height-for-age-eps'])
      zandp = visit_stats.get_zandp('length_or_height_for_age')
      self.assertTrue(util.isNanOrNear(testScore, zandp.zscore, eps))
      testScore = float(row['length-or-height-for-age-%'])
      eps = float(row['length-or-height-for-age-%-eps'])
      self.assertTrue(util.isNanOrNear(testScore, zandp.percentile, eps))
      
      testScore = float(row['bmi-for-age'])
      eps = float(row['bmi-for-age-eps'])
      zandp = visit_stats.get_zandp('body_mass_index_for_age')
      self.assertTrue(util.isNanOrNear(testScore, zandp.zscore, eps))
      testScore = float(row['bmi-for-age-%'])
      eps = float(row['bmi-for-age-%-eps'])
      self.assertTrue(util.isNanOrNear(testScore, zandp.percentile, eps))
     
      testScore = float(row['head-circumference-for-age'])
      eps = float(row['head-circumference-for-age-eps'])
      zandp = visit_stats.get_zandp('head_circumference_for_age')
      self.assertTrue(util.isNanOrNear(testScore, zandp.zscore, eps))
      testScore = float(row['head-circumference-for-age-%'])
      eps = float(row['head-circumference-for-age-%-eps'])
      self.assertTrue(util.isNanOrNear(testScore, zandp.percentile, eps))
    self.assertEquals(lineNum, 23)