コード例 #1
0
 /**
  * Process the data and return the answers that should be changed.
  *
  * Storing the changed values is handled by the calling function.
  *
  * @param \Gems_Tracker_Token $token Gems token object
  * @return array Containing the changed values
  */
 public function processTokenData(\Gems_Tracker_Token $token)
 {
     if (!$token->getReceptionCode()->isSuccess()) {
         return;
     }
     $answers = $token->getRawAnswers();
     if (isset($answers['informedconsent'])) {
         $consent = $this->util->getConsent($answers['informedconsent']);
         if ($consent->exists) {
             // Is existing consent description as answer
             $consentCode = $consent->getDescription();
         } else {
             if ($answers['informedconsent']) {
                 // Uses start of consent description as answer (LS has only 5 chars for an answer option)
                 $consentCode = $this->db->fetchOne("SELECT gco_description FROM gems__consents WHERE gco_description LIKE ? ORDER BY gco_order", $answers['informedconsent'] . '%');
             } else {
                 $consentCode = false;
             }
             if (!$consentCode) {
                 if ($answers['informedconsent']) {
                     // Code not found, use first positive consent
                     $consentCode = $this->db->fetchOne("SELECT gco_description FROM gems__consents WHERE gco_code != ? ORDER BY gco_order", $this->util->getConsentRejected());
                 } else {
                     // Code not found, use first negative consent
                     $consentCode = $this->db->fetchOne("SELECT gco_description FROM gems__consents WHERE gco_code = ? ORDER BY gco_order", $this->util->getConsentRejected());
                 }
             }
         }
         $respondent = $token->getRespondent();
         $values = array('gr2o_patient_nr' => $respondent->getPatientNumber(), 'gr2o_id_organization' => $respondent->getOrganizationId(), 'gr2o_consent' => $consentCode);
         $respondent->getRespondentModel()->save($values);
     }
     return false;
 }
コード例 #2
0
 /**
  * Process the data and return the answers that should be changed.
  *
  * Storing the changed values is handled by the calling function.
  *
  * @param \Gems_Tracker_Token $token Gems token object
  * @return array Containing the changed values
  */
 public function processTokenData(\Gems_Tracker_Token $token)
 {
     $tokenAnswers = $token->getRawAnswers();
     if (isset($tokenAnswers['LENGTH'], $tokenAnswers['WEIGHT']) && $tokenAnswers['LENGTH'] && $tokenAnswers['WEIGHT']) {
         $length = $tokenAnswers['LENGTH'] / 100;
         $newValue = round($tokenAnswers['WEIGHT'] / ($length * $length), 2);
         if ($newValue !== $tokenAnswers['BMI']) {
             return array('BMI' => $newValue);
         }
     }
     return false;
 }
コード例 #3
0
 /**
  * Hook performing actual save
  *
  * @param string $newCode
  * @param int $userId
  * @return $changed
  */
 public function setReceptionCode($newCode, $userId)
 {
     // Get the code object
     $code = $this->util->getReceptionCode($newCode);
     // Use the token function as that cascades the consent code
     $changed = $this->token->setReceptionCode($code, $this->formData['gto_comment'], $userId);
     if ($code->isSuccess()) {
         $this->addMessage(sprintf($this->_('Token %s restored.'), $this->token->getTokenId()));
     } else {
         $this->addMessage(sprintf($this->_('Token %s deleted.'), $this->token->getTokenId()));
         if ($code->hasRedoCode()) {
             $newComment = sprintf($this->_('Redo of token %s.'), $this->token->getTokenId());
             if ($this->formData['gto_comment']) {
                 $newComment .= "\n\n";
                 $newComment .= $this->_('Old comment:');
                 $newComment .= "\n";
                 $newComment .= $this->formData['gto_comment'];
             }
             $this->_replacementTokenId = $this->token->createReplacement($newComment, $userId);
             // Create a link for the old token
             $oldToken = strtoupper($this->token->getTokenId());
             $menuItem = $this->menu->findAllowedController('track', 'show');
             if ($menuItem) {
                 $paramSource['gto_id_token'] = $this->token->getTokenId();
                 $paramSource[\Gems_Model::ID_TYPE] = 'token';
                 $href = $menuItem->toHRefAttribute($paramSource);
                 if ($href) {
                     // \MUtil_Echo::track($oldToken);
                     $link = \MUtil_Html::create('a', $href, $oldToken);
                     $oldToken = $link->setView($this->view);
                 }
             }
             // Tell what the user what happened
             $this->addMessage(new \MUtil_Html_Raw(sprintf($this->_('Created this token %s as replacement for token %s.'), strtoupper($this->_replacementTokenId), $oldToken)));
             // Lookup token
             $newToken = $this->loader->getTracker()->getToken($this->_replacementTokenId);
             // Make sure the Next token is set right
             $this->token->setNextToken($newToken);
             // Copy answers when requested.
             if ($code->hasRedoCopyCode()) {
                 $newToken->setRawAnswers($this->token->getRawAnswers());
             }
         }
     }
     $respTrack = $this->token->getRespondentTrack();
     if ($nextToken = $this->token->getNextToken()) {
         if ($recalc = $respTrack->checkTrackTokens($userId, $nextToken)) {
             $this->addMessage(sprintf($this->plural('%d token changed by recalculation.', '%d tokens changed by recalculation.', $recalc), $recalc));
         }
     }
     return $changed;
 }
コード例 #4
0
 /**
  * Process the data and return the answers that should be changed.
  *
  * Storing the changed values is handled by the calling function.
  *
  * @param \Gems_Tracker_Token $token Gems token object
  * @return array Containing the changed values
  */
 public function processTokenData(\Gems_Tracker_Token $token)
 {
     $result = var_export($token->getRawAnswers(), true);
     \MUtil_Echo::r($result, $token->getTokenId());
     return false;
 }
コード例 #5
0
 /**
  * Returns a field from the raw answers as a date object.
  *
  * A seperate function as only the source knows what format the date/time value has.
  *
  * @param string $fieldName Name of answer field
  * @param \Gems_Tracker_Token $token Gems token object
  * @param int $surveyId Gems Survey Id
  * @param string $sourceSurveyId Optional Survey Id used by source
  * @return \MUtil_Date date time or null
  */
 public function getAnswerDateTime($fieldName, \Gems_Tracker_Token $token, $surveyId, $sourceSurveyId = null)
 {
     $answers = $token->getRawAnswers();
     if (isset($answers[$fieldName]) && $answers[$fieldName]) {
         if (\Zend_Date::isDate($answers[$fieldName], \Zend_Date::ISO_8601)) {
             return new \MUtil_Date($answers[$fieldName], \Zend_Date::ISO_8601);
         }
         if (\Gems_Tracker::$verbose) {
             \MUtil_Echo::r($answers[$fieldName], 'Missed answer date value:');
         }
     }
 }