Skip to content

Commit 59c5cba

Browse files
committed
fix ISE when synchronizing claims
1 parent 48b6f26 commit 59c5cba

3 files changed

Lines changed: 86 additions & 2 deletions

File tree

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

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import android.database.Cursor;
1111
import android.inputmethodservice.Keyboard;
1212
import android.os.Bundle;
13+
import android.text.Editable;
1314
import android.text.InputType;
15+
import android.text.TextWatcher;
1416
import android.view.Menu;
1517
import android.view.MenuInflater;
1618
import android.view.MenuItem;
@@ -93,7 +95,7 @@ public static Intent newIntent(@NonNull Context context, @NonNull String claimUU
9395
RadioButton rbEmergency, rbReferral, rbOther, rbPositive, rbNegative;
9496
ImageButton btnScan;
9597
LinearLayout llFagepFields;
96-
TextInputLayout ettClaimPrefix, ettGuaranteeNo;
98+
TextInputLayout ettClaimPrefix, ettGuaranteeNo, ettClaimCode;
9799

98100
@Override
99101
protected void onCreate(Bundle savedInstanceState) {
@@ -140,6 +142,10 @@ protected void onCreate(Bundle savedInstanceState) {
140142
etVisitType = findViewById(R.id.etVisitType);
141143
ettClaimPrefix = findViewById(R.id.ettClaimPrefix);
142144
ettGuaranteeNo = findViewById(R.id.ettGuaranteeNo);
145+
View claimCodeParent = (View) etClaimCode.getParent();
146+
if (claimCodeParent instanceof TextInputLayout) {
147+
ettClaimCode = (TextInputLayout) claimCodeParent;
148+
}
143149

144150
String[] visitTypes = getResources().getStringArray(R.array.visitType);
145151
ArrayAdapter<String> visitTypeAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, visitTypes);
@@ -170,6 +176,25 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
170176
rgVisitType.setVisibility(View.GONE);
171177
ettGuaranteeNo.setVisibility(View.GONE);
172178

179+
TextWatcher claimCodeUniquenessWatcher = new TextWatcher() {
180+
@Override
181+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
182+
// no-op
183+
}
184+
185+
@Override
186+
public void onTextChanged(CharSequence s, int start, int before, int count) {
187+
// no-op
188+
}
189+
190+
@Override
191+
public void afterTextChanged(Editable s) {
192+
validateLocalClaimCodeUniqueness();
193+
}
194+
};
195+
etClaimCode.addTextChangedListener(claimCodeUniquenessWatcher);
196+
etClaimPrefix.addTextChangedListener(claimCodeUniquenessWatcher);
197+
173198
tvItemTotal.setText("0");
174199
tvServiceTotal.setText("0");
175200

@@ -842,6 +867,10 @@ private boolean isValidData() {
842867
return false;
843868
}
844869

870+
if (!validateLocalClaimCodeUniqueness()) {
871+
return false;
872+
}
873+
845874
// if (rgVisitType.getCheckedRadioButtonId() == -1) {
846875
// showValidationDialog(rgVisitType, getResources().getString(R.string.MissingVisitType));
847876
// return false;
@@ -970,4 +999,47 @@ private boolean saveClaim() {
970999
return true;
9711000
}
9721001

1002+
private boolean validateLocalClaimCodeUniqueness() {
1003+
if (getIntent().hasExtra(EXTRA_CLAIM_UUID)) {
1004+
if (ettClaimCode != null) {
1005+
ettClaimCode.setError(null);
1006+
ettClaimCode.setErrorEnabled(false);
1007+
} else {
1008+
etClaimCode.setError(null);
1009+
}
1010+
return true;
1011+
}
1012+
1013+
String finalCode = etClaimPrefix.getText().toString() + etClaimCode.getText().toString();
1014+
if (finalCode.trim().isEmpty()) {
1015+
if (ettClaimCode != null) {
1016+
ettClaimCode.setError(null);
1017+
ettClaimCode.setErrorEnabled(false);
1018+
} else {
1019+
etClaimCode.setError(null);
1020+
}
1021+
return true;
1022+
}
1023+
1024+
boolean exists = sqlHandler.existsClaimCode(finalCode);
1025+
if (exists) {
1026+
String errorMessage = getResources().getString(R.string.ClaimNumberExist);
1027+
if (ettClaimCode != null) {
1028+
ettClaimCode.setErrorEnabled(true);
1029+
ettClaimCode.setError(errorMessage);
1030+
} else {
1031+
etClaimCode.setError(errorMessage);
1032+
}
1033+
return false;
1034+
}
1035+
1036+
if (ettClaimCode != null) {
1037+
ettClaimCode.setError(null);
1038+
ettClaimCode.setErrorEnabled(false);
1039+
} else {
1040+
etClaimCode.setError(null);
1041+
}
1042+
return true;
1043+
}
1044+
9731045
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,18 @@ public String getClaimUUIDForCode(@NonNull String claimCode) {
11941194
return null;
11951195
}
11961196

1197+
public boolean existsClaimCode(@NonNull String claimCode) {
1198+
try (Cursor cursor = db.rawQuery(
1199+
"SELECT 1 FROM tblClaimDetails WHERE LOWER(ClaimCode) = LOWER(?) LIMIT 1",
1200+
new String[]{claimCode}
1201+
)) {
1202+
return cursor != null && cursor.moveToFirst();
1203+
} catch (Exception e) {
1204+
Log.e(LOG_TAG, "Error while checking claim code uniqueness", e);
1205+
return false;
1206+
}
1207+
}
1208+
11971209
@NonNull
11981210
public JSONObject getClaimCounts() {
11991211
JSONArray claimCounts = getQueryResultAsJsonArray(

claimManagement/src/main/java/org/openimis/imisclaims/usecase/CreateClaim.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ public Integer execute(
3737
) throws Exception {
3838
return checkMutation.execute(
3939
createClaimGraphQLRequest.create(claim,hfId ,adminId, insureeId, programId, diagnosisId, programCode),
40-
"Error while creating policy for beneficiary '" + claim.getClaimNumber() + "'");
40+
"Error while creating claim No '" + claim.getClaimNumber() + "'");
4141
}
4242
}

0 commit comments

Comments
 (0)