Пример #1
0
def is_stillborn(case):
    properties = (
        'child_cried',
        'child_breathing',
        'child_movement',
        'child_heartbeats'
    )
    for xform in get_forms(case, action_filter=lambda a: a.xform_xmlns == DELIVERY):
        if xform.form.get('has_delivered') != 'yes':
            continue
        for p in properties:
            value = xform.xpath('form/child_info/%s' % p)
            if not value:
                child_infos = xform.xpath('form/child_info')
                if not child_infos:
                    continue
                for child_info in child_infos:
                    child_info.get(p)
                    # no idea whether this is a thing that can get called
                    logging.debug('(nested) %s: %s' % (p, value))
                    if value != 'no':
                        return False
            else:
                if value != 'no':
                    return False
        return True
Пример #2
0
 def numerator(self, case):
     self._visits_used = set()
     for date, form in self._total(case):
         for form in get_forms(case,
                               action_filter=self._get_numerator_action_filter(form, date)):
             self._visits_used.add(form._id)
             yield date
             break  # only allow one numerator per denominator
Пример #3
0
 def no_prep(self, case):
     forms = list(get_forms(case, action_filter=self.action_filter))
     return any(
         all(
             form.get_data(xpath) != 'yes'
             for form in forms
         )
         for xpath in self.no_prep_paths
     )
Пример #4
0
 def _total(self, case):
     """
     Private method for calculating the "total" for the denominator. In addition to emitting
     the appropriate date it also emits the form that generated it, so that it can be referenced
     by the numerator.
     """
     for form in get_forms(case, action_filter=self._total_action_filter):
         date = self.get_date_next(form)
         if date and self.additional_filter(case, date):
             yield (date, form)
Пример #5
0
 def get_forms_with_complications(self, case):
     for form, action in get_forms(case, yield_action=True):
         try:
             complication_paths = self.complications_by_form[form.xmlns]
         except KeyError:
             continue
         else:
             for p in complication_paths:
                 if form.get_data('form/' + p) == 'yes':
                     yield form, action.date
Пример #6
0
    def total(self, case):

        def mother_died(a):
            return (
                a.updated_known_properties.get('mother_alive') == 'no'
                and a.xform_xmlns in (DELIVERY, PNC)
            )

        for xform in get_forms(case, action_filter=mother_died, reverse=True):
            yield xform.form.get('date_death')
            # yield at most one
            break