(last_visit_dates)
return XPath.if_(
            use_date_opened,
            "${}".format(SCHEDULE_DATE_CASE_OPENED),
            "${}".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_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_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_visit_date )
def next_visit_date(last_visit_dates):
        """
        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_visit_date)
        """
        # (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("${} < today()".format(SCHEDULE_GLOBAL_NEXT_VISIT_DATE)),
            XPath.or_(
                XPath(SCHEDULE_PHASE).eq(XPath.string('')),
                no_visits
            )
        )
        return XPath.if_(
            use_date_opened,
            "${}".format(SCHEDULE_DATE_CASE_OPENED),
            "${}".format(SCHEDULE_GLOBAL_NEXT_VISIT_DATE),
        )
def next_visit_date ( last_visit_dates ) : # (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 ( "${} < today()" . format ( SCHEDULE_GLOBAL_NEXT_VISIT_DATE ) ) , XPath . or_ ( XPath ( SCHEDULE_PHASE ) . eq ( XPath . string ( '' ) ) , no_visits ) ) return XPath . if_ ( use_date_opened , "${}" . format ( SCHEDULE_DATE_CASE_OPENED ) , "${}" . format ( SCHEDULE_GLOBAL_NEXT_VISIT_DATE ) , )