(forms, case_xpath)
return XPath.if_(
            use_date_opened,
            case_xpath.slash(SCHEDULE_DATE_CASE_OPENED),
            "/data/{}".format(SCHEDULE_GLOBAL_NEXT_VISIT_DATE),
        )
Returns the next visit date given all the last visits
        if($next_visit_date < today() and (current_schedule_phase = '' or last_visit_date_{all_forms} = ''),
            $date_case_opened,
            $next_due_visit)
Returns the next visit date given all the last visits
        if($next_visit_date < today() and (current_schedule_phase = '' or last_visit_date_{all_forms} = ''),
            $date_case_opened,
            $next_due_visit)
Returns the next visit date given all the last visits if ( $next_visit_date < today () and ( current_schedule_phase = or last_visit_date_ { all_forms } = ) $date_case_opened $next_due_visit )
def next_visit_date(forms, case_xpath):
        """
        Returns the next visit date given all the last visits
        if($next_visit_date < today() and (current_schedule_phase = '' or last_visit_date_{all_forms} = ''),
            $date_case_opened,
            $next_due_visit)
        """
        last_visit_dates = [case_xpath.slash(SCHEDULE_LAST_VISIT_DATE).format(form.schedule_form_id)
                            for form in forms]
        # (last_visit_f1 = '' and last_visit_f2 = '' and ...)
        no_visits = XPath.and_(*["{} = ''".format(last_visit)
                                 for last_visit in last_visit_dates])

        use_date_opened = XPath.and_(
            XPath("/data/{} < today()".format(SCHEDULE_GLOBAL_NEXT_VISIT_DATE)),
            XPath.or_(
                XPath(case_xpath.slash(SCHEDULE_PHASE)).eq(XPath.string('')),
                no_visits
            )
        )
        return XPath.if_(
            use_date_opened,
            case_xpath.slash(SCHEDULE_DATE_CASE_OPENED),
            "/data/{}".format(SCHEDULE_GLOBAL_NEXT_VISIT_DATE),
        )
def next_visit_date ( forms , case_xpath ) : last_visit_dates = [ case_xpath . slash ( SCHEDULE_LAST_VISIT_DATE ) . format ( form . schedule_form_id ) for form in forms ] # (last_visit_f1 = '' and last_visit_f2 = '' and ...) no_visits = XPath . and_ ( * [ "{} = ''" . format ( last_visit ) for last_visit in last_visit_dates ] ) use_date_opened = XPath . and_ ( XPath ( "/data/{} < today()" . format ( SCHEDULE_GLOBAL_NEXT_VISIT_DATE ) ) , XPath . or_ ( XPath ( case_xpath . slash ( SCHEDULE_PHASE ) ) . eq ( XPath . string ( '' ) ) , no_visits ) ) return XPath . if_ ( use_date_opened , case_xpath . slash ( SCHEDULE_DATE_CASE_OPENED ) , "/data/{}" . format ( SCHEDULE_GLOBAL_NEXT_VISIT_DATE ) , )