This is an old revision of the document!
In order to create a sequential (study-)number for each new respondent, you need to create you own respondent controller.
Please see the howto page first, on how to do that.
In the code below, you will see three functions in this controller:
.
class RespondentController extends Gems_Default_RespondentAction { /* * default value for respnr needed before validation of form */ public function createModel($detailed, $action) { $model = parent::createModel($detailed, $action); $orgcode = $this->loader->getOrganization()->getCode(); $model->set('gr2o_patient_nr', 'default', $this->getRespnr($orgcode)); return $model; } /* * get new studynr if needed and display appropriate message */ public function beforeSave(array &$data, $isNew, Zend_Form $form = null) { If ($isNew) { //MUtil_Echo::track($data); $orgcode = $this->loader->getOrganization($data['gr2o_id_organization'])->getCode(); $respNr = $this->getRespNr($orgcode); if ($data['gr2o_patient_nr'] !== $respNr) { $this->addMessage(sprintf($this->_('Studynumber changed from %1$s to %2$s!'), $data['gr2o_patient_nr'], $respNr)); }else{ $this->addMessage(sprintf($this->_('Studynumber %s assigned!'), $respNr)); } $data['gr2o_patient_nr'] = $respNr; } return true; } /* * This function will get the next studynumber for the current organization * use gor_code that can be set in the organization interface * */ protected function getRespNr($orgcode) { $orgcodelength = strlen($orgcode); $sql = "SELECT `gr2o_patient_nr` FROM `gems__respondent2org` WHERE `gr2o_patient_nr` LIKE '$orgcode%' ORDER BY `gems__respondent2org`.`gr2o_patient_nr` DESC LIMIT 1;"; $value = $this->db->fetchRow($sql); $nr = (int) substr($value['gr2o_patient_nr'], $orgcodelength); $nr++; $respnr = $orgcode.sprintf('%04d', $nr); //MUtil_Echo::track($respnr); return $respnr; } }