99import android .content .Intent ;
1010import android .database .Cursor ;
1111import android .os .Bundle ;
12+ import android .text .Editable ;
13+ import android .text .TextWatcher ;
1214import android .view .Menu ;
1315import android .view .MenuInflater ;
1416import android .view .MenuItem ;
@@ -86,7 +88,13 @@ public static Intent newIntent(@NonNull Context context, @NonNull String claimUU
8688 RadioButton rbEmergency , rbReferral , rbOther ;
8789 ImageButton btnScan ;
8890 CheckBox etPreAuthorization ;
89- TextInputLayout tfReferal ;
91+ TextInputLayout tfReferal , tiPatientCondition ;
92+ JSONObject claimConfig ;
93+ JSONObject insureeConfig ;
94+ int codeMaxLength = 8 , chfIdMaxLength = 12 , numberOfAdditionalDiagnosis = 4 ;
95+ boolean showPatientCondition = false , showPreAuthorization = false , canSaveClaimWithoutServiceNorItem = true ;
96+ List <AutoCompleteTextView > secDiagnosis = new ArrayList <>();
97+
9098
9199 @ Override
92100 protected void onCreate (Bundle savedInstanceState ) {
@@ -128,6 +136,7 @@ protected void onCreate(Bundle savedInstanceState) {
128136 etPatientCondition = findViewById (R .id .patientCondition );
129137 etVisitType = findViewById (R .id .etVisitType );
130138 tfReferal = findViewById (R .id .tfReferal );
139+ tiPatientCondition = findViewById (R .id .tiPatientCondition );
131140
132141 String [] visitTypes = getResources ().getStringArray (R .array .visitType );
133142 ArrayAdapter <String > visitTypeAdapter = new ArrayAdapter <>(this , android .R .layout .simple_dropdown_item_1line , visitTypes );
@@ -196,18 +205,26 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
196205 etDiagnosis1 .setAdapter (adapter );
197206 etDiagnosis1 .setThreshold (1 );
198207 etDiagnosis1 .setOnItemClickListener (adapter );
208+ etDiagnosis1 .setVisibility (View .GONE );
209+ secDiagnosis .add (etDiagnosis1 );
199210
200211 etDiagnosis2 .setAdapter (adapter );
201212 etDiagnosis2 .setThreshold (1 );
202213 etDiagnosis2 .setOnItemClickListener (adapter );
214+ etDiagnosis2 .setVisibility (View .GONE );
215+ secDiagnosis .add (etDiagnosis2 );
203216
204217 etDiagnosis3 .setAdapter (adapter );
205218 etDiagnosis3 .setThreshold (1 );
206219 etDiagnosis3 .setOnItemClickListener (adapter );
220+ etDiagnosis3 .setVisibility (View .GONE );
221+ secDiagnosis .add (etDiagnosis3 );
207222
208223 etDiagnosis4 .setAdapter (adapter );
209224 etDiagnosis4 .setThreshold (1 );
210225 etDiagnosis4 .setOnItemClickListener (adapter );
226+ etDiagnosis4 .setVisibility (View .GONE );
227+ secDiagnosis .add (etDiagnosis4 );
211228
212229 HFAdapter hfAdapter = new HFAdapter (ClaimActivity .this , sqlHandler );
213230 etReferalHF .setAdapter (hfAdapter );
@@ -229,6 +246,8 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
229246 return false ;
230247 });
231248
249+ initConfigurations ();
250+
232251 findViewById (R .id .ivAddItem ).setOnClickListener (v -> addItem ());
233252 findViewById (R .id .ivAddService ).setOnClickListener (v -> addService ());
234253
@@ -298,6 +317,88 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
298317 }
299318 });
300319 }
320+
321+ etInsureeNumber .addTextChangedListener (new TextWatcher () {
322+ @ Override
323+ public void beforeTextChanged (CharSequence s , int start , int count , int after ) {
324+ }
325+
326+ @ Override
327+ public void onTextChanged (CharSequence s , int start , int before , int count ) {
328+ }
329+
330+ @ Override
331+ public void afterTextChanged (Editable s ) {
332+ int length = s != null ? s .length () : 0 ;if (length > chfIdMaxLength ) {
333+ etInsureeNumber .setError (getResources ().getString (R .string .maxCharactersRequired , chfIdMaxLength ));
334+ } else {
335+ etInsureeNumber .setError (null );
336+ }
337+ }
338+ });
339+
340+ etClaimCode .addTextChangedListener (new TextWatcher () {
341+ @ Override
342+ public void beforeTextChanged (CharSequence charSequence , int i , int i1 , int i2 ) {}
343+
344+ @ Override
345+ public void onTextChanged (CharSequence charSequence , int i , int i1 , int i2 ) {}
346+
347+ @ Override
348+ public void afterTextChanged (Editable s ) {
349+ int length = s != null ? s .length () : 0 ;
350+ if (length > codeMaxLength ) {
351+ etClaimCode .setError (getResources ().getString (R .string .maxCharactersRequired , codeMaxLength ));
352+ } else {
353+ etClaimCode .setError (null );
354+ }
355+ }
356+ });
357+ }
358+
359+ private void initConfigurations (){
360+ try {
361+ claimConfig = sqlHandler .getModuleConfig ("fe-claim" );
362+ insureeConfig = sqlHandler .getModuleConfig ("fe-insuree" );
363+
364+ if (claimConfig .has ("claimForm.codeMaxLength" )){
365+ codeMaxLength = claimConfig .getInt ("claimForm.codeMaxLength" );
366+ }
367+
368+ if (insureeConfig .has ("insureeForm.chfIdMaxLength" )){
369+ chfIdMaxLength = insureeConfig .getInt ("insureeForm.chfIdMaxLength" );
370+ }
371+
372+ if (claimConfig .has ("showPatientCondition" )){
373+ showPatientCondition = claimConfig .getBoolean ("showPatientCondition" );
374+ }
375+
376+ if (claimConfig .has ("showPreAuthorization" )){
377+ showPreAuthorization = claimConfig .getBoolean ("showPreAuthorization" );
378+ }
379+
380+ if (claimConfig .has ("claimForm.numberOfAdditionalDiagnosis" )){
381+ numberOfAdditionalDiagnosis = claimConfig .getInt ("claimForm.numberOfAdditionalDiagnosis" );
382+ }
383+
384+ if (!showPreAuthorization ){
385+ etPreAuthorization .setVisibility (View .GONE );
386+ } else {
387+ etPreAuthorization .setVisibility (View .VISIBLE );
388+ }
389+
390+ if (!showPatientCondition ){
391+ tiPatientCondition .setVisibility (View .GONE );
392+ } else {
393+ tiPatientCondition .setVisibility (View .VISIBLE );
394+ }
395+
396+ for (int i = 0 ; i < numberOfAdditionalDiagnosis ; i ++){
397+ secDiagnosis .get (i ).setVisibility (View .VISIBLE );
398+ }
399+ } catch (JSONException e ) {
400+ e .printStackTrace ();
401+ }
301402 }
302403
303404 private boolean isIntentReadonly () {
@@ -746,11 +847,21 @@ protected boolean isValidData() {
746847 return false ;
747848 }
748849
850+ if (etClaimCode .getText ().length () > codeMaxLength ){
851+ showValidationDialog (etClaimCode , getResources ().getString (R .string .InvalidClaimCode , codeMaxLength ));
852+ return false ;
853+ }
854+
749855 if (etInsureeNumber .getText ().length () == 0 ) {
750856 showValidationDialog (etInsureeNumber , getResources ().getString (R .string .MissingCHFID ));
751857 return false ;
752858 }
753859
860+ if (etInsureeNumber .getText ().length () > chfIdMaxLength ) {
861+ showValidationDialog (etInsureeNumber , getResources ().getString (R .string .invalidChfId , chfIdMaxLength ));
862+ return false ;
863+ }
864+
754865 if (!isValidInsureeNumber ()) {
755866 showValidationDialog (etInsureeNumber , getResources ().getString (R .string .InvalidCHFID ));
756867 return false ;
@@ -802,7 +913,7 @@ protected boolean isValidData() {
802913 return false ;
803914 }
804915
805- if (Float .parseFloat (tvItemTotal .getText ().toString ()) + Float .parseFloat (tvServiceTotal .getText ().toString ()) == 0 ) {
916+ if (! canSaveClaimWithoutServiceNorItem && Float .parseFloat (tvItemTotal .getText ().toString ()) + Float .parseFloat (tvServiceTotal .getText ().toString ()) == 0 ) {
806917 showValidationDialog (tvItemTotal , getResources ().getString (R .string .MissingClaim ));
807918 return false ;
808919 }
@@ -884,8 +995,10 @@ protected boolean saveClaim() {
884995 claimCV .put ("ICDCode4" , etDiagnosis4 .getText ().toString ());
885996 claimCV .put ("VisitType" , etVisitType .getTag ().toString ());
886997 claimCV .put ("ReferalHF" , etReferalHF .getText ().toString ());
887- claimCV .put ("PatientCondition" , etPatientCondition .getTag ().toString ());
888- if (etPreAuthorization .isChecked ()){
998+ if (showPatientCondition ){
999+ claimCV .put ("PatientCondition" , etPatientCondition .getTag ().toString ());
1000+ }
1001+ if (showPreAuthorization && etPreAuthorization .isChecked ()){
8891002 claimCV .put ("PreAuthorization" , 1 );
8901003 }else {
8911004 claimCV .put ("PreAuthorization" , 0 );
0 commit comments