← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10770: [mobile] generate system identifier for patient

 

------------------------------------------------------------
revno: 10770
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Mon 2013-05-06 16:24:22 +0700
message:
  [mobile] generate system identifier for patient
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java	2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java	2013-05-06 09:24:22 +0000
@@ -35,12 +35,11 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import javax.servlet.http.HttpServletRequest;
-
 import org.apache.commons.lang.math.NumberUtils;
 import org.apache.struts2.StrutsStatics;
 import org.hisp.dhis.light.utils.FormUtils;
+import org.hisp.dhis.light.utils.PatientIdentifierGenerator;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttribute;
@@ -59,7 +58,6 @@
 import org.joda.time.DateTime;
 import org.joda.time.format.DateTimeFormatter;
 import org.joda.time.format.ISODateTimeFormat;
-
 import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ActionContext;
 
@@ -478,7 +476,21 @@
                 }
             }
         }
-
+        
+        String identifier = PatientIdentifierGenerator.getNewIdentifier( patient.getBirthDate(), gender );
+
+        PatientIdentifier systemGenerateIdentifier = patientIdentifierService.get( null, identifier );
+        while ( systemGenerateIdentifier != null )
+        {
+            identifier = PatientIdentifierGenerator.getNewIdentifier( patient.getBirthDate(), patient.getGender() );
+            systemGenerateIdentifier = patientIdentifierService.get( null, identifier );
+        }
+
+        systemGenerateIdentifier = new PatientIdentifier();
+        systemGenerateIdentifier.setIdentifier( identifier );
+        systemGenerateIdentifier.setPatient( patient );
+        patient.getIdentifiers().add( systemGenerateIdentifier );
+        
         for ( PatientAttribute patientAttribute : patientAttributes )
         {
             patientAttributeSet.add( patientAttribute );