public function updateTracks()
    {
        $tokenChanges = 0;
        $tracker      = $this->loader->getTracker();

        // Find all the fields that use this agenda item
        $select = $this->db->select();
        $select->from('gems__respondent2track2appointment', array('gr2t2a_id_respondent_track'))
                ->joinInner(
                        'gems__respondent2track',
                        'gr2t_id_respondent_track = gr2t2a_id_respondent_track',
                        array('gr2t_id_track')
                        )
                ->where('gr2t2a_id_appointment = ?', $this->_appointmentId)
                ->distinct();

        // AND find the filters for any new fields to fill
        $filters = $this->agenda->matchFilters($this);
        if ($filters) {
            $ids = array_map(function ($value) {
                return $value->getTrackId();
            }, $filters);

            // \MUtil_Echo::track(array_keys($filters), $ids);
            $respId = $this->getRespondentId();
            $orgId  = $this->getOrganizationId();
            $select->orWhere(
                    "gr2t_id_user = $respId AND gr2t_id_organization = $orgId AND gr2t_id_track IN (" .
                    implode(', ', $ids) . ")"
                    );
            // \MUtil_Echo::track($this->getId(), implode(', ', $ids));
        }

        // \MUtil_Echo::track($select->__toString());

        // Now find all the existing tracks that should be checked
        $respTracks = $this->db->fetchPairs($select);

        // \MUtil_Echo::track($respTracks);
        $existingTracks = array();
        if ($respTracks) {
            foreach ($respTracks as $respTrackId => $trackId) {
                $respTrack = $tracker->getRespondentTrack($respTrackId);

                // Recalculate this track
                $fieldsChanged = false;
                $tokenChanges += $respTrack->recalculateFields($fieldsChanged);

                // Store the track for creation checking
                $existingTracks[$trackId][] = $respTrack;
            }
        }

        // Only check if we need to create when this appointment is active and today or later
        if ($this->isActive() && $this->getAdmissionTime()->isLaterOrEqual(new \MUtil_Date())) {
            $tokenChanges += $this->checkCreateTracks($filters, $existingTracks, $tracker);
        }

        return $tokenChanges;
    }