/**
  * Refresh the data
  */
 public function refresh()
 {
     $default = true;
     $filter = array();
     if ($this->patientId) {
         $filter['gr2o_patient_nr'] = $this->patientId;
         $default = false;
     } elseif ($this->respondentId) {
         $filter['gr2o_id_user'] = $this->respondentId;
         $default = false;
     }
     if (!$filter) {
         // Otherwise we load the first patient in the current organization
         $filter[] = '1=0';
     }
     if ($this->organizationId) {
         $filter['gr2o_id_organization'] = $this->organizationId;
     }
     $this->model->setFilter($filter);
     $this->_gemsData = $this->model->loadFirst();
     if ($this->_gemsData) {
         $this->exists = true;
         $this->patientId = $this->_gemsData['gr2o_patient_nr'];
         $this->organizationId = $this->_gemsData['gr2o_id_organization'];
         $this->respondentId = $this->_gemsData['gr2o_id_user'];
     } else {
         $this->_gemsData = $this->model->loadNew();
         $this->exists = false;
     }
 }
 /**
  * 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->model) {
         $this->model->setIfExists('grs_email', 'itemDisplay', array('MUtil_Html_AElement', 'ifmail'));
         $this->model->setIfExists('gr2o_comments', 'rowspan', 2);
         if ($this->showConsentWarning && $this->model->has('gr2o_consent')) {
             $this->model->set('gr2o_consent', 'formatFunction', array($this, 'checkConsent'));
         }
         if (!$this->repeater) {
             if (!$this->respondentData) {
                 $this->repeater = $this->model->loadRepeatable();
             } else {
                 // In case a single array of values was passed: make nested
                 if (is_array(reset($this->respondentData))) {
                     $data = $this->respondentData;
                 } else {
                     $data = array($this->respondentData);
                 }
                 $this->repeater = \MUtil_Lazy::repeat($data);
             }
         }
         return true;
     }
     return false;
 }
 /**
  * - Fetches respondent based on bsn / reception code and patient nr
  * - Creates the respondent if it does not exist, updates otherwise
  *
  * @see \Gems_Model_RespondentModel
  * @see \Gems_Communication_RespondentWriter::writeRespondent()
  *
  * @param  \Gems_Communication_RespondentContainer $respondent
  * @param  int $userId
  * @return boolean True if a new respondent was added, false if one was updated
  */
 public function writeRespondent(\Gems_Communication_RespondentContainer $respondent, &$userId)
 {
     $parameters = $this->_model->applyParameters(array('grs_ssn' => $respondent->getBsn(), 'gr2o_reception_code' => \GemsEscort::RECEPTION_OK, 'gr2o_patient_nr' => $respondent->getPatientId()));
     $data = $this->_model->loadFirst();
     $isNew = false;
     if (empty($data)) {
         $isNew = true;
         $data = $this->_model->loadNew();
     }
     unset($data['grs_email']);
     $data['gr2o_patient_nr'] = $respondent->getPatientId();
     $data['grs_first_name'] = $respondent->getFirstName();
     $data['grs_last_name'] = $respondent->getLastName();
     $data['grs_surname_prefix'] = $respondent->getSurnamePrefix();
     $data['grs_ssn'] = $respondent->getBsn();
     $data['grs_gender'] = $respondent->getGender();
     $data['grs_birthday'] = $respondent->getBirthday();
     $data = $this->_model->save($data);
     $userId = $data['grs_id_user'];
     return $isNew;
 }
 /**
  * Set those values needed for editing
  *
  * @return \Gems_Model_RespondentModel
  */
 public function applyEditSettings()
 {
     parent::applyEditSettings();
     $translator = $this->getTranslateAdapter();
     if ($this->hashSsn !== \Gems_Model_RespondentModel::SSN_HIDE) {
         self::setDutchSsn($this, $translator);
     }
     $this->setIfExists('grs_iso_lang', 'default', 'nl');
     $this->setIfExists('gr2o_treatment', 'description', $this->_('DBC\'s, etc...'));
     self::setDutchZipcode($this, $translator);
     return $this;
 }
 /**
  * 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->model) {
         $this->model->setIfExists('grs_email', 'itemDisplay', array('MUtil_Html_AElement', 'ifmail'));
         $this->model->setIfExists('gr2o_comments', 'rowspan', 2);
         if ($this->showConsentWarning && $this->model->has('gr2o_consent')) {
             $this->model->set('gr2o_consent', 'formatFunction', array($this, 'checkConsent'));
         }
         if (!$this->repeater) {
             if (!$this->respondent) {
                 $this->repeater = $this->model->loadRepeatable();
             } else {
                 $data = array($this->respondent->getArrayCopy());
                 $this->repeater = \MUtil_Lazy::repeat($data);
             }
         }
         return true;
     }
     return false;
 }
 /**
  * Creates the model
  *
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel()
 {
     if (!$this->model instanceof \Gems_Model_AppointmentModel) {
         $this->model = $this->loader->getModels()->createAppointmentModel();
         $this->model->applyBrowseSettings();
     }
     $this->model->addColumn(new \Zend_Db_Expr("CONVERT(gap_admission_time, DATE)"), 'date_only');
     $this->model->set('date_only', 'dateFormat', \Zend_Date::WEEKDAY . ' ' . \Zend_Date::DAY_SHORT . ' ' . \Zend_Date::MONTH_NAME . ' ' . \Zend_Date::YEAR);
     $this->model->set('gap_admission_time', 'label', $this->_('Time'), 'dateFormat', 'HH:mm');
     $this->model->set('gr2o_patient_nr', 'label', $this->_('Respondent nr'));
     \Gems_Model_RespondentModel::addNameToModel($this->model, $this->_('Name'));
     // \MUtil_Model::$verbose = true;
     return $this->model;
 }
 /**
  * Set the reception code for a respondent and cascade non-success codes to the
  * tracks / surveys.
  *
  * @param string $newCode     String or \Gems_Util_ReceptionCode
  * @return \Gems_Util_ReceptionCode The new code reception code object for further processing
  */
 public function setReceptionCode($newCode)
 {
     return $this->model->setReceptionCode($this->getPatientNumber(), $this->getOrganizationId(), $newCode, $this->getId(), $this->getReceptionCode());
 }