revision-diff.txt (12 KB)
Hi Tran
Two comments, one small and the other more critical:
(i) the way you are formatting the identifier can be much cleaner by using java String.format(), something like:
String patientCode = String.format(“%s%04d”, orgUnitCode, patientNumber)
which with orgUnitCode as “RWA” and patientNumber as 45, would produce “RWA0045”.
(ii) I am uncomfortable that this custom and particular coding scheme is hardcoded into the controller. It is a bit fragile (deleting patients would reduce totalPatients and thus cause duplicate ids to be issued), it is limited to 9999 patients, and it does not conform to what is generally understood as good practice for patient identifiers.
Whereas this scheme might be acceptable for a particular implementation its not good enough as a general solution. Probably you need a pluggable identifier generator strategy rather than this hard-coded solution.
Bob
···
On 2 July 2013 16:43, noreply@launchpad.net wrote:
revno: 11307
committer: Tran Chau tran.hispvietnam@gmail.com
branch nick: dhis2
timestamp: Tue 2013-07-02 22:18:36 +0700
message:
Add new type of identifier-type to define ID with orgunit-code and 4 digits, e.g. KAW0001
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientIdentifierTypeForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientIdentifierType.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/patientIdentifierType.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programList.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientIdentifierType.vm
–
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-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java’
— dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java 2013-07-02 15:18:36 +0000
@@ -51,6 +51,8 @@
public static final String VALUE_TYPE_NUMBER = "number"; public static final String VALUE_TYPE_LETTER = "letter";
public static final String VALUE_TYPE_ORGUNIT_COUNT = “orgunitCount”;
private String description;
=== modified file ‘dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java’
— dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java 2013-04-26 15:24:15 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java 2013-07-02 15:18:36 +0000
@@ -47,6 +47,7 @@
import org.hisp.dhis.patient.PatientIdentifierTypeService;
import org.hisp.dhis.patient.PatientRegistrationForm;
import org.hisp.dhis.patient.PatientRegistrationFormService;
+import org.hisp.dhis.patient.PatientService;
import org.hisp.dhis.patient.comparator.PatientAttributeGroupSortOrderComparator;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramService;
@@ -107,6 +108,13 @@
this.attributeGroupService = attributeGroupService; }
private PatientService patientService;
public void setPatientService( PatientService patientService )
{
this.patientService = patientService;
}
private I18n i18n; public void setI18n( I18n i18n )
@@ -188,6 +196,13 @@
return attributeGroups; }
private String orgunitCountIdentifier;
public String getOrgunitCountIdentifier()
{
return orgunitCountIdentifier;
}
// ------------------------------------------------------------------------- // Action implementation // -------------------------------------------------------------------------
@@ -227,8 +242,8 @@
Collection<PatientAttribute> patientAttributesInProgram = new HashSet<PatientAttribute>(); Collection<Program> programs = programService.getAllPrograms();
programs.remove(program);
programs.remove( program );
for ( Program _program : programs ) { identifierTypes.removeAll( _program.getPatientIdentifierTypes() );
@@ -253,6 +268,32 @@
noGroupAttributes.removeAll( patientAttributesInProgram ); }
orgunitCountIdentifier = generateOrgunitIdentifier( organisationUnit );
return SUCCESS; }
private String generateOrgunitIdentifier( OrganisationUnit organisationUnit )
{
String value = organisationUnit.getCode();
int totalPatient = patientService.countGetPatientsByOrgUnit( organisationUnit );
if ( totalPatient < 10 )
{
value += "000" + totalPatient;
}
else if ( totalPatient < 100 )
{
value += "00" + totalPatient;
}
else if ( totalPatient < 1000 )
{
value += "0" + totalPatient;
}
else
{
value += totalPatient;
}
return value;
}
}
=== modified file ‘dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml’
— dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-07-02 14:26:44 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-07-02 15:18:36 +0000
@@ -519,6 +519,7 @@
<bean id="org.hisp.dhis.caseentry.action.patient.ShowAddPatientFormAction" class="org.hisp.dhis.caseentry.action.patient.ShowAddPatientFormAction" scope="prototype">
<property name="patientService" ref="org.hisp.dhis.patient.PatientService" /> <property name="selectionManager" ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" /> <property name="attributeService">
=== modified file ‘dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm’
— dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm 2013-07-02 03:54:01 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm 2013-07-02 15:18:36 +0000
@@ -132,9 +132,15 @@
#else #set( $identifier = '' ) #set( $identifier = $identiferMap.get( $identifierType.id ) )
#if($identifierType.type=='orgunitCount' && $!orgunitCountIdentifier)
#set( $identifier = $!orgunitCountIdentifier )
#end
<tr> <td class='text-column'><label>$encoder.htmlEncode($identifierType.displayName) #if($identifierType.mandatory) <em title="$i18n.getString( "required" )" class="required">*</em> #end</label></td>
<td class="input-column"><input type="text" id="iden$identifierType.id" name="iden$identifierType.id" value="$!identifier" data="{related:$identifierType.related}" #if($identifierType.related && $!patient.underAge) disabled="disabled" #end class="{validate:{required:$identifierType.mandatory, #if($!identifierType.noChars) maxlength:$identifierType.noChars, #end #if($identifierType.type=='number') number:true #elseif($!identifierType.type=='letter') lettersonly:true #end }}" /></td>
<td class="input-column">
<input type="text" id="iden$identifierType.id" name="iden$identifierType.id" value="$!identifier" data="{related:$identifierType.related}" #if($identifierType.related && $!patient.underAge) disabled="disabled" #end class="{validate:{required:$identifierType.mandatory, #if($!identifierType.noChars) maxlength:$identifierType.noChars, #end #if($identifierType.type=='number') number:true #elseif($!identifierType.type=='letter') lettersonly:true #end }}" />
</td> </tr> #end #end
=== modified file ‘dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties’
— dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties 2013-07-02 14:26:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties 2013-07-02 15:18:36 +0000
@@ -421,4 +421,5 @@
complete_event = Complete event
send_to = Send to
complete_program = Complete program
-from_the_day_set = From the day set
\ No newline at end of file
+from_the_day_set = From the day set
+orgunit_count = Organisation unit count
\ No newline at end of file
=== modified file ‘dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientIdentifierTypeForm.vm’
— dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientIdentifierTypeForm.vm 2013-02-28 07:12:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientIdentifierTypeForm.vm 2013-07-02 15:18:36 +0000
@@ -54,6 +54,7 @@
<option value="string" selected="selected">$i18n.getString( "text" )</option> <option value="number">$i18n.getString( "number" )</option> <option value="letter">$i18n.getString( "letter_only" )</option>
<option value="orgunitCount">$i18n.getString( "orgunit_count" )</option> </select> </td> <td></td>
=== modified file ‘dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientIdentifierType.js’
— dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientIdentifierType.js 2012-09-17 06:40:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientIdentifierType.js 2013-07-02 15:18:36 +0000
@@ -17,7 +17,7 @@
setInnerHTML( 'relatedField', boolValueMap[boolType] ); setInnerHTML( 'noCharsField', json.patientIdentifierType.noChars );
var valueTypeMap = { 'text':i18n_string, 'number':i18n_number, 'letter':i18n_letter_only };
var valueTypeMap = { 'text':i18n_string, 'number':i18n_number, 'letter':i18n_letter_only, 'orgunitCount': i18n_orgunit_count }; var valueType = json.patientIdentifierType.type; setInnerHTML( 'typeField', valueTypeMap[valueType] );
=== modified file ‘dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/patientIdentifierType.vm’
— dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/patientIdentifierType.vm 2013-06-29 14:16:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/patientIdentifierType.vm 2013-07-02 15:18:36 +0000
@@ -63,4 +63,5 @@
var i18n_yes = '$encoder.jsEscape( $i18n.getString( "yes" ), "'")'; var i18n_no = '$encoder.jsEscape( $i18n.getString( "no" ), "'")'; var i18n_all = '$encoder.jsEscape( $i18n.getString( "all" ), "'")';
var i18n_orgunit_count = '$encoder.jsEscape( $i18n.getString( "orgunit_count" ) , "'")';
=== modified file ‘dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programList.vm’
— dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programList.vm 2013-06-29 14:16:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programList.vm 2013-07-02 15:18:36 +0000
@@ -3,9 +3,9 @@
$i18n.getString( "program_management" ) #openHelp( "program" )
<tr>
<td align="right"><input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='showAddProgramForm.action'" style="width:70px"></td>
</tr>
<td align="right"><input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='showAddProgramForm.action'" style="width:70px"></td>
@@ -113,5 +113,4 @@
var i18n_multiple_events_with_registration = '$encoder.jsEscape( $i18n.getString( "multiple_events_with_registration" ) , "'")'; var i18n_single_event_with_registration = '$encoder.jsEscape( $i18n.getString( "single_event_with_registration" ) , "'")'; var i18n_single_event_without_registration = '$encoder.jsEscape( $i18n.getString( "single_event_without_registration" ) , "'")';
=== modified file ‘dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientIdentifierType.vm’
— dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientIdentifierType.vm 2013-02-28 07:12:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientIdentifierType.vm 2013-07-02 15:18:36 +0000
@@ -55,6 +55,7 @@
<option value="string" #if( $patientIdentifierType.type=='string' ) selected="selected" #end>$i18n.getString( "text" )</option> <option value="number" #if( $patientIdentifierType.type=='number' ) selected="selected" #end>$i18n.getString( "number" )</option> <option value="letter" #if( $patientIdentifierType.type=='letter' ) selected="selected" #end>$i18n.getString( "letter_only" )</option>
<option value="orgunitCount" #if( $patientIdentifierType.type=='orgunitCount' ) selected="selected" #end>$i18n.getString( "orgunit_count" )</option> </select> </td> <td></td>
Mailing list: https://launchpad.net/~dhis2-devs
Post to : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help : https://help.launchpad.net/ListHelp