Skip to content

Commit 7a18cc1

Browse files
committed
fix min & max length verification with config
1 parent 231648c commit 7a18cc1

12 files changed

Lines changed: 279 additions & 48 deletions

File tree

claimManagement/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ android {
109109
resValue "string", "app_name_claims", "Claims CSU"
110110
resValue "string", "release_tag", "csu"
111111
buildConfigField "String", "API_BASE_URL", '"https://csuapps.minsante.cm/"'
112+
buildConfigField "String", "MASTER_DATA_URL", '"https://csureport.minsante.cm/"'
112113
buildConfigField "String", "RAR_PASSWORD", '"xc3-ed@/dfr;nJ3R"'
113114
dimension 'std'
114115
resValue "string", "sentry_dsn", '"https://54612a80b36c47e78722b9779410e3d1@glitchtip-csuapps.minsante.cm/9"'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
query GetConfigs($layer: String) {
2+
moduleConfigurations(layer: $layer) {
3+
config,
4+
module
5+
}
6+
}

claimManagement/src/main/java/org/openimis/imisclaims/ClaimActivity.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

claimManagement/src/main/java/org/openimis/imisclaims/MainActivity.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ public void run() {
847847
runOnUiThread(() -> {
848848
progressDialog.dismiss();
849849
Toast.makeText(MainActivity.this, getResources().getString(R.string.MapSuccessful), Toast.LENGTH_LONG).show();
850+
downloadConfigs();
850851
});
851852
} catch (Exception e) {
852853
e.printStackTrace();
@@ -870,6 +871,45 @@ public void run() {
870871

871872
}
872873

874+
public void downloadConfigs (){
875+
if (global.isNetworkAvailable()){
876+
String progress_message = getResources().getString(R.string.getConfig) + "...";
877+
progressDialog = ProgressDialog.show(this, getResources().getString(R.string.download), progress_message);
878+
Thread thread = new Thread() {
879+
public void run() {
880+
try {
881+
List<ModuleConfig> configs = new FetchConfigs().execute();
882+
if(!configs.isEmpty()){
883+
sqlHandler.ClearAll("tblConfig");
884+
for (int i = 0; i < configs.size(); i++) {
885+
sqlHandler.InsertConfig(i+1,configs.get(i).getModule(), configs.get(i).getConfig());
886+
}
887+
}
888+
runOnUiThread(() -> {
889+
progressDialog.dismiss();
890+
Toast.makeText(MainActivity.this, getResources().getString(R.string.downloaded_config), Toast.LENGTH_LONG).show();
891+
});
892+
} catch (Exception e) {
893+
e.printStackTrace();
894+
Sentry.captureException(e);
895+
runOnUiThread(() -> {
896+
progressDialog.dismiss();
897+
if(!global.isNetworkAvailable()){
898+
Toast.makeText(MainActivity.this, getResources().getString(R.string.CheckConnection), Toast.LENGTH_LONG).show();
899+
}else {
900+
Toast.makeText(MainActivity.this, e.getMessage() + "-" + getResources().getString(R.string.AccessDenied), Toast.LENGTH_LONG).show();
901+
}
902+
});
903+
}
904+
};
905+
};
906+
thread.start();
907+
} else {
908+
runOnUiThread(() -> progressDialog.dismiss());
909+
ErrorDialogBox(getResources().getString(R.string.CheckInternet));
910+
}
911+
}
912+
873913
public void saveLastUpdateDate(String lastUpdateDate) {
874914
if (global.getSDCardStatus().equals(Environment.MEDIA_MOUNTED)) {
875915
String dir = global.getSubdirectory("Authentications");
@@ -927,6 +967,8 @@ public boolean checkRequirements() {
927967
}
928968

929969
return false;
970+
} else {
971+
sqlHandler.updateTables();
930972
}
931973

932974
return true;

claimManagement/src/main/java/org/openimis/imisclaims/SQLHandler.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class SQLHandler extends SQLiteOpenHelper {
5656
private static final String createTableClaimItems = "CREATE TABLE IF NOT EXISTS tblClaimItems(ClaimUUID TEXT, ItemCode TEXT, ItemPrice TEXT, ItemQuantity TEXT);";
5757
private static final String createTableClaimServices = "CREATE TABLE IF NOT EXISTS tblClaimServices(ClaimUUID TEXT, ServiceCode TEXT, ServicePrice TEXT, ServiceQuantity TEXT, ServicePackageType TEXT, SubServicesItems TEXT);";
5858
private static final String createTableClaimUploadStatus = "CREATE TABLE IF NOT EXISTS tblClaimUploadStatus(ClaimUUID TEXT, UploadDate TEXT, UploadStatus TEXT, UploadMessage TEXT);";
59+
private static final String createTableModuleConfig = "CREATE TABLE IF NOT EXISTS tblConfig(Id INTEGER, Module TEXT, Config TEXT);";
5960

6061
public final String REFERENCE_UNKNOWN;
6162

@@ -893,7 +894,8 @@ public JSONObject getItem(String itemId) {
893894
public void createTables() {
894895
String[] commands = {CreateTableControls, CreateTableReferences, CreateTableClaimAdmins,CreateTablePrograms,CreateTableDiagnosis,
895896
createTablePolicyInquiry, createTableClaimDetails, createTableClaimItems, createTableClaimServices,CreateTableSubItems,
896-
CreateTableSubServices,CreateTableItems,CreateTableServices, createTableClaimUploadStatus, CreateTableHealthFacilities};
897+
CreateTableSubServices,CreateTableItems,CreateTableServices, createTableClaimUploadStatus, CreateTableHealthFacilities,
898+
createTableModuleConfig};
897899
for (String command : commands) {
898900
try {
899901
db.execSQL(command);
@@ -903,6 +905,10 @@ public void createTables() {
903905
}
904906
}
905907

908+
public void updateTables(){
909+
db.execSQL(createTableModuleConfig);
910+
}
911+
906912
public void createMappingTables() {
907913
String[] commandsMapping = {CreateTableMapping};
908914
for (String command : commandsMapping) {
@@ -1274,4 +1280,34 @@ public String getReferenceName(@NonNull String referenceCode) {
12741280
return REFERENCE_UNKNOWN;
12751281
}
12761282
}
1283+
1284+
public void InsertConfig(int id, String module, String config) {
1285+
try {
1286+
ContentValues cv = new ContentValues();
1287+
cv.put("Id", id);
1288+
cv.put("Module", module);
1289+
cv.put("Config", config);
1290+
1291+
db.insert("tblConfig", null, cv);
1292+
} catch (Exception e) {
1293+
e.printStackTrace();
1294+
}
1295+
}
1296+
1297+
public JSONObject getModuleConfig(String module){
1298+
JSONObject config = new JSONObject();
1299+
try {
1300+
String query = "SELECT Config FROM tblConfig WHERE Module = \"" + module + "\"";
1301+
Cursor cursor1 = db.rawQuery(query, null);
1302+
// looping through all rows
1303+
if (cursor1.moveToFirst()) {
1304+
do {
1305+
config = new JSONObject(cursor1.getString(0));
1306+
} while (cursor1.moveToNext());
1307+
}
1308+
} catch (Exception e) {
1309+
e.printStackTrace();
1310+
}
1311+
return config;
1312+
}
12771313
}

0 commit comments

Comments
 (0)