GemsTracker

GEneric Medical Survey Tracker

User Tools

Site Tools


devzone:giftbox:sequentialnrs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
devzone:giftbox:sequentialnrs [2012/11/27 16:36]
Roel created
devzone:giftbox:sequentialnrs [2020/03/12 12:06] (current)
Line 2: Line 2:
  
 In order to create a sequential (study-)number for each new respondent, you need to create you own respondent controller.\\ In order to create a sequential (study-)number for each new respondent, you need to create you own respondent controller.\\
-Please see the [[devzone:​howto|howto]] page first, on how to do that.\\+Please see the [[devzone:​howto:start|howto]] page first, on how to do that.\\
 In the code below, you will see three functions in this controller: In the code below, you will see three functions in this controller:
   * beforeSave, which will check the respondent number just before saving it   * beforeSave, which will check the respondent number just before saving it
-  * createModel,​ which uses the parent model and creates the new respondent number using an extra variable for organization id+  * createModel,​ which uses the parent model and creates the new respondent number using an extra variable for organization id as default value (*).
   * getRespNr, which uses the organization ID, gets the latest respondent number for that organization and returns the next respondent number   * getRespNr, which uses the organization ID, gets the latest respondent number for that organization and returns the next respondent number
 . .
-<​code>​+<​code ​php>
   class RespondentController extends Gems_Default_RespondentAction   class RespondentController extends Gems_Default_RespondentAction
   {   {
Line 41: Line 41:
  
             if ($data['​gr2o_patient_nr'​] !== $respNr) {             if ($data['​gr2o_patient_nr'​] !== $respNr) {
-                $this->​addMessage(sprintf($this->​_('​Studienummer gewijzigd van %1$s naar %2$s!'​),​ $data['​gr2o_patient_nr'​],​ $respNr));+                $this->​addMessage(sprintf($this->​_('​Studynumber changed from %1$s to %2$s!'​),​ $data['​gr2o_patient_nr'​],​ $respNr));
             }else{             }else{
-                $this->​addMessage(sprintf($this->​_('​Studienummer ​%s toegekend!'), $respNr));+                $this->​addMessage(sprintf($this->​_('​Studynumber ​%s assigned!'), $respNr));
             }             }
    
Line 62: Line 62:
         $orgcodelength = strlen($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;";+        $sql   = "​SELECT ​CAST(substr(`gr2o_patient_nr`,​$orgcodelength+1) AS UNSIGNED) AS mynr, `gr2o_patient_nr`  
 +                  ​FROM `gems__respondent2org` ​ 
 +                  ​WHERE `gr2o_patient_nr` LIKE '​$orgcode%' ​ 
 +                  ​ORDER BY mynr DESC LIMIT 1;"; 
 +        /* 
 +         * This can result in different organisations having identical respnrs if you use orgcodes like A, AB, AC or N, N1, N3, etc !  
 +         * It depends on your situation if this is a feature or an unwanted option. 
 + * If unwanted you should change this code to fit your needs. 
 + * Please note that this is not a problem for Gemstracker as it keeps track of the patient and organization ids. 
 +         */ 
         $value = $this->​db->​fetchRow($sql);​         $value = $this->​db->​fetchRow($sql);​
-        $nr    (int) substr($value['​gr2o_patient_nr'], $orgcodelength);+        $nr = $value['​mynr'];
         $nr++;         $nr++;
         $respnr ​  = $orgcode.sprintf('​%04d',​ $nr);         $respnr ​  = $orgcode.sprintf('​%04d',​ $nr);
  
-        //Tip: use next line (decomment) for debugging: 
         //​MUtil_Echo::​track($respnr);​         //​MUtil_Echo::​track($respnr);​
  
Line 78: Line 87:
  
 </​code>​ </​code>​
 +
 +(*) In a simalar way you can set defaults for other fields in the createModel function:\\
 +<code php>
 +        $model->​set('​gr2o_consent',​ '​default',​ '​Yes'​);​
 +</​code>​
 +or\\
 +<code php>
 +        $model->​set('​grs_gender',​ '​default',​ '​M'​);​
 +</​code>​
 +
 +
devzone/giftbox/sequentialnrs.1354030578.txt.gz · Last modified: 2020/03/12 12:08 (external edit)