def numerator(self, case): visit_time = _get_time_of_visit_after_birth(case) time_birth = _get_tob(case) if visit_time and time_birth: if time_birth < visit_time < time_birth + self.visited_window: # matches total, so you know this will be a subset of those yield get_add(case)
def _get_tob(case): # only guaranteed to be accurate within 24 hours import couchdbkit tob = get_related_prop(case, "time_of_birth") or '00:00:00' tob = couchdbkit.schema.TimeProperty().to_python(tob) tob = datetime.datetime.combine(get_add(case), tob) # convert date to dt.datetime return tob
def filter(self, case): return ( has_delivered_at_all(case) and getattr(case, 'family_planning_type', '') in ( 'no_fp_at_delivery', 'no_fp_adopted_at_delivery', ) and get_add(case) )
def _calculate_both(self, case): complication_date = None complication_shortly_after_birth_date = None if case.type == 'cc_bihar_pregnancy': for form, date in self.get_forms_with_complications(case): complication_date = date if form.xmlns == DELIVERY: add = form.get_data('form/case/update/add') else: add = get_add(case) add = string_to_datetime(add).date() if form.metadata.timeStart.date() - add <= self.days: complication_shortly_after_birth_date = date return complication_shortly_after_birth_date, complication_date
def total(self, case): yield get_add(case)
def numerator(self, case): if less_than_two_kilos(case): yield get_add(case)
def numerator(self, case): if is_preterm(case): yield get_add(case)
def is_newborn(case): return is_pregnant_mother(case) and ( is_recently_delivered(case) or get_related_prop(case, 'birth_status') == "live_birth" ) and get_add(case)
def has_add(self, case): return is_pregnant_mother(case) and get_add(case)
def filter(self, case): return is_pregnant_mother(case) and get_add(case)
def sortkey(self, case, context): # hacky way to sort by reverse add return datetime.datetime.today().date() - (get_add(case) or datetime.datetime.max.date())
def numerator(self, case): if adopted_fp(case): yield get_add(case)
def numerator(self, case): if couple_interested_in_fp(case): yield get_add(case)