/**
  * The place to check if the data set in the snippet is valid
  * to generate the snippet.
  *
  * When invalid data should result in an error, you can throw it
  * here but you can also perform the check in the
  * checkRegistryRequestsAnswers() function from the
  * {@see \MUtil_Registry_TargetInterface}.
  *
  * @return boolean
  */
 public function hasHtmlOutput()
 {
     if ($this->respondent instanceof \Gems_Tracker_Respondent) {
         if (!$this->patientId) {
             $this->patientId = $this->respondent->getPatientNumber();
         }
         if (!$this->organizationId) {
             $this->organizationId = $this->respondent->getOrganizationId();
         }
     }
     // Try to get $this->respondentTrackId filled
     if (!$this->respondentTrackId) {
         if ($this->respondentTrack) {
             $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId();
         } else {
             $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK);
         }
     }
     // Try to get $this->respondentTrack filled
     if ($this->respondentTrackId && !$this->respondentTrack) {
         $this->respondentTrack = $this->loader->getTracker()->getRespondentTrack($this->respondentTrackId);
     }
     // Set the user id
     if (!$this->userId) {
         $this->userId = $this->loader->getCurrentUser()->getUserId();
     }
     if ($this->respondentTrack) {
         // We are updating
         $this->createData = false;
         // Try to get $this->trackEngine filled
         if (!$this->trackEngine) {
             // Set the engine used
             $this->trackEngine = $this->respondentTrack->getTrackEngine();
         }
     } else {
         // We are inserting
         $this->createData = true;
         $this->saveLabel = $this->_($this->_('Add track'));
         // Try to get $this->trackId filled
         if (!$this->trackId) {
             if ($this->trackEngine) {
                 $this->trackId = $this->trackEngine->getTrackId();
             } else {
                 $this->trackId = $this->request->getParam(\Gems_Model::TRACK_ID);
             }
         }
         // Try to get $this->trackEngine filled
         if ($this->trackId && !$this->trackEngine) {
             $this->trackEngine = $this->loader->getTracker()->getTrackEngine($this->trackId);
         }
         if (!($this->trackEngine && $this->patientId && $this->organizationId && $this->userId)) {
             throw new \Gems_Exception_Coding('Missing parameter for ' . __CLASS__ . ': could not find data for editing a respondent track nor the track engine, patientId and organizationId needed for creating one.');
         }
     }
     return parent::hasHtmlOutput();
 }
 protected function loadExport()
 {
     $this->export = $this->loader->getRespondentExport();
     if ($this->token instanceof \Gems_Tracker_Token) {
         $this->addRespondent($this->token->getPatientNumber(), $this->token->getOrganizationId());
         $this->export->addRespondentTrackFilter($this->token->getRespondentTrackId());
         $this->export->addTokenFilter($this->token->getTokenId());
     } elseif ($this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
         $this->addRespondent($this->respondentTrack->getPatientNumber(), $this->respondentTrack->getOrganizationId());
         $this->export->addRespondentTrackFilter($this->respondentTrack->getRespondentTrackId());
     } elseif ($this->respondent instanceof \Gems_Tracker_Respondent) {
         $this->addRespondent($this->respondent->getPatientNumber(), $this->respondent->getOrganizationId());
     }
 }
 /**
  * The place to check if the data set in the snippet is valid
  * to generate the snippet.
  *
  * When invalid data should result in an error, you can throw it
  * here but you can also perform the check in the
  * checkRegistryRequestsAnswers() function from the
  * {@see \MUtil_Registry_TargetInterface}.
  *
  * @return boolean
  */
 public function hasHtmlOutput()
 {
     if (!$this->multiTracks) {
         return false;
     }
     $this->tracker = $this->loader->getTracker();
     if (!$this->respondentTrackId) {
         $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK);
     }
     if ($this->respondentTrackId) {
         if (!$this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
             $this->respondentTrack = $this->tracker->getRespondentTrack($this->respondentTrackId);
         }
     }
     if ($this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
         if (!$this->respondentTrackId) {
             $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId();
         }
         $this->trackId = $this->respondentTrack->getTrackId();
         if (!$this->respondentId) {
             $this->respondentId = $this->respondentTrack->getRespondentId();
         }
         if (!$this->organizationId) {
             $this->organizationId = $this->respondentTrack->getOrganizationId();
         }
         $this->caption = $this->_('Other assignments of this track to this respondent.');
         $this->onEmpty = $this->_('This track is assigned only once to this respondent.');
     } else {
         if ($this->respondent instanceof \Gems_Tracker_Respondent) {
             if (!$this->respondentId) {
                 $this->respondentId = $this->respondent->getId();
             }
             if (!$this->organizationId) {
                 $this->organizationId = $this->respondent->getOrganizationId();
             }
         }
         $this->caption = $this->_('Existing assignments of this track to this respondent.');
         $this->onEmpty = $this->_('This track is not assigned to this respondent.');
     }
     if (!$this->trackId) {
         $this->trackId = $this->request->getParam(\Gems_Model::TRACK_ID);
     }
     if (!$this->trackId && $this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
         $this->trackId = $this->trackEngine->getTrackId();
     }
     return $this->trackId && $this->respondentId && $this->organizationId && parent::hasHtmlOutput();
 }
 /**
  * The place to check if the data set in the snippet is valid
  * to generate the snippet.
  *
  * When invalid data should result in an error, you can throw it
  * here but you can also perform the check in the
  * checkRegistryRequestsAnswers() function from the
  * {@see \MUtil_Registry_TargetInterface}.
  *
  * @return boolean
  */
 public function hasHtmlOutput()
 {
     // Try to set $this->respondentTrackId, it can be ok when not set
     if (!$this->respondentTrackId) {
         if ($this->respondentTrack) {
             $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId();
         } else {
             $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK);
         }
     }
     // First attempt at trackId
     if (!$this->trackId && $this->trackEngine) {
         $this->trackId = $this->trackEngine->getTrackId();
     }
     // Check if a sufficient set of data is there
     if (!($this->trackId || $this->patientId || $this->organizationId)) {
         // Now we really need $this->respondentTrack
         if (!$this->respondentTrack) {
             if ($this->respondentTrackId) {
                 $this->respondentTrack = $this->loader->getTracker()->getRespondentTrack($this->respondentTrackId);
             } else {
                 // Parameters not valid
                 return false;
             }
         }
     }
     if (!$this->trackId) {
         $this->trackId = $this->respondentTrack->getTrackId();
     }
     if (!$this->patientId) {
         $this->patientId = $this->respondentTrack->getPatientNumber();
     }
     if (!$this->organizationId) {
         $this->organizationId = $this->respondentTrack->getOrganizationId();
     }
     // \MUtil_Echo::track($this->trackId, $this->patientId, $this->organizationId, $this->respondentTrackId);
     return $this->getModel()->loadFirst() && parent::hasHtmlOutput();
 }
 /**
  * Remove the unanswered tokens for inactive rounds.
  *
  * @param \Gems_Tracker_RespondentTrack $respTrack The respondent track to check
  * @param int $userId Id of the user who takes the action (for logging)
  * @return int The number of tokens changed by this code
  */
 protected function removeInactiveRounds(\Gems_Tracker_RespondentTrack $respTrack, $userId)
 {
     $qTrackId = $this->db->quote($this->_trackId);
     $qRespTrackId = $this->db->quote($respTrack->getRespondentTrackId());
     $orgId = $this->db->quote($respTrack->getOrganizationId());
     $where = "gto_start_time IS NULL AND\n            gto_id_respondent_track = {$qRespTrackId} AND\n            gto_id_round != 0 AND\n            gto_id_round IN (SELECT gro_id_round\n                    FROM gems__rounds\n                    WHERE (gro_active = 0 OR gro_organizations NOT LIKE CONCAT('%|',{$orgId},'|%')) AND\n                        gro_id_track = {$qTrackId})";
     return $this->db->delete('gems__tokens', $where);
 }
 /**
  * Determines if this particular track should be included
  * in the report
  *
  * @param  \Gems_Tracker_RespondentTrack $track
  * @return boolean This dummy implementation always returns true
  */
 protected function _isTrackInFilter(\Gems_Tracker_RespondentTrack $track)
 {
     $result = false;
     $trackInfo = array('code' => $track->getCode(), 'trackid' => $track->getTrackId(), 'resptrackid' => $track->getRespondentTrackId(), 'respid' => $track->getRespondentId());
     if (empty($this->trackFilter)) {
         $result = true;
     } else {
         // Now read the filter and split by track code or track id
         foreach ($this->trackFilter as $filter) {
             $remaining = array_diff_assoc($filter, $trackInfo);
             if (empty($remaining)) {
                 $result = true;
                 break;
             }
         }
     }
     // Only if track has a success code
     if ($result && $track->getReceptionCode()->isSuccess()) {
         return true;
     }
     return false;
 }