@@ -96,6 +96,10 @@ public static Intent newIntent(@NonNull Context context, @NonNull String claimUU
9696 ImageButton btnScan ;
9797 LinearLayout llFagepFields ;
9898 TextInputLayout ettClaimPrefix , ettGuaranteeNo , tilCHFID ;
99+ JSONObject insureeConfig ;
100+ JSONObject policyConfig ;
101+ JSONObject claimConfig ;
102+ int minChequeNumber = 6 , minChfId = 12 , maxChfId = 20 , codeMaxLength = 6 ;
99103
100104 @ Override
101105 protected void onCreate (Bundle savedInstanceState ) {
@@ -144,6 +148,18 @@ protected void onCreate(Bundle savedInstanceState) {
144148 ettGuaranteeNo = findViewById (R .id .ettGuaranteeNo );
145149 tilCHFID = findViewById (R .id .tilCHFID );
146150
151+ try {
152+ insureeConfig = sqlHandler .getModuleConfig ("fe-insuree" );
153+ policyConfig = sqlHandler .getModuleConfig ("fe-policy" );
154+ claimConfig = sqlHandler .getModuleConfig ("fe-claim" );
155+ minChequeNumber = policyConfig .getInt ("minChequeNumberRequired" );
156+ minChfId = insureeConfig .getInt ("insureeForm.chfIdMinLength" );
157+ maxChfId = insureeConfig .getInt ("insureeForm.chfIdMaxLength" );
158+ codeMaxLength = claimConfig .getInt ("claimForm.codeMaxLength" );
159+ } catch (JSONException e ) {
160+ e .printStackTrace ();
161+ }
162+
147163 String [] visitTypes = getResources ().getStringArray (R .array .visitType );
148164 ArrayAdapter <String > visitTypeAdapter = new ArrayAdapter <>(this , android .R .layout .simple_dropdown_item_1line , visitTypes );
149165 visitTypeAdapter .setDropDownViewResource (android .R .layout .select_dialog_singlechoice );
@@ -354,8 +370,10 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {}
354370 @ Override
355371 public void afterTextChanged (Editable s ) {
356372 int length = s != null ? s .length () : 0 ;
357- if (length > 0 && length < 12 ) {
358- tilCHFID .setError (getResources ().getString (R .string .minChfIdRequired ));
373+ if (length > 0 && length < minChfId ) {
374+ tilCHFID .setError (getResources ().getString (R .string .minCharactersRequired , minChfId ));
375+ } else if (length > maxChfId ){
376+ tilCHFID .setError (getResources ().getString (R .string .maxCharactersRequired , maxChfId ));
359377 } else {
360378 tilCHFID .setError (null );
361379 }
@@ -374,8 +392,8 @@ public void afterTextChanged(Editable s) {
374392 String program = etProgram .getText ().toString ();
375393 if (program .equals ("Cheque Santé" ) || program .equals ("Chèque Santé" )){
376394 int length = s != null ? s .length () : 0 ;
377- if (length > 0 && length < 6 ) {
378- ettClaimPrefix .setError (getResources ().getString (R .string .minChequeNumberRequired ));
395+ if (length > 0 && length < minChequeNumber ) {
396+ ettClaimPrefix .setError (getResources ().getString (R .string .minCharactersRequired , minChequeNumber ));
379397 } else {
380398 ettClaimPrefix .setError (null );
381399 }
@@ -818,8 +836,11 @@ private boolean isValidData() {
818836 if (etInsureeNumber .getText ().length () == 0 ) {
819837 showValidationDialog (etInsureeNumber , getResources ().getString (R .string .MissingCHFID ));
820838 return false ;
821- } else if (etInsureeNumber .getText ().length () < 12 ){
822- showValidationDialog (etInsureeNumber , getResources ().getString (R .string .minChfIdRequired ));
839+ } else if (etInsureeNumber .getText ().length () < minChfId ){
840+ showValidationDialog (etInsureeNumber , getResources ().getString (R .string .minCharactersRequired , minChfId ));
841+ return false ;
842+ } else if (etInsureeNumber .getText ().length () > maxChfId ) {
843+ showValidationDialog (etInsureeNumber , getResources ().getString (R .string .maxCharactersRequired , maxChfId ));
823844 return false ;
824845 }
825846
@@ -881,13 +902,13 @@ private boolean isValidData() {
881902 if (etClaimPrefix .getText ().length () == 0 ){
882903 showValidationDialog (etClaimPrefix , getResources ().getString (R .string .MissingChequeNumber ));
883904 return false ;
884- } else if ((program .equals ("Cheque Santé" ) || program .equals ("Chèque Santé" )) && etClaimPrefix .length () < 6 ){
885- showValidationDialog (etClaimPrefix , getResources ().getString (R .string .minChequeNumberRequired ));
905+ } else if ((program .equals ("Cheque Santé" ) || program .equals ("Chèque Santé" )) && etClaimPrefix .length () < minChequeNumber ){
906+ showValidationDialog (etClaimPrefix , getResources ().getString (R .string .minCharactersRequired , minChequeNumber ));
886907 return false ;
887908 }
888909
889- if (etClaimCode .getText ().length () > 7 ){
890- showValidationDialog (etClaimPrefix , getResources ().getString (R .string .InvalidClaimCode ));
910+ if (etClaimCode .getText ().length () > codeMaxLength ){
911+ showValidationDialog (etClaimPrefix , getResources ().getString (R .string .InvalidClaimCode , codeMaxLength ));
891912 return false ;
892913 }
893914
0 commit comments