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
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.xpath('form/' + p) == 'yes': yield form, action.date
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
def no_prep(self, case): forms = list(get_forms(case, action_filter=self.action_filter)) return any(all(form.xpath(xpath) != "yes" for form in forms) for xpath in self.no_prep_paths)