2525import org .json .JSONException ;
2626import org .json .JSONObject ;
2727import org .openimis .imisclaims .tools .Log ;
28+ import org .openimis .imisclaims .util .JsonUtils ;
29+ import org .openimis .imisclaims .util .StringUtils ;
2830
2931import java .text .SimpleDateFormat ;
3032import java .util .ArrayList ;
@@ -52,7 +54,7 @@ public class ClaimActivity extends ImisActivity {
5254 private int year , month , day ;
5355 int TotalItemService ;
5456
55- EditText etStartDate , etEndDate , etClaimCode , etHealthFacility , etInsureeNumber , etClaimAdmin , etGuaranteeNo ;
57+ EditText etStartDate , etEndDate , etClaimCode , etHealthFacility , etInsureeNumber , etClaimAdmin , etGuaranteeNo , etTotalClaimed , etTotalApproved , etTotalAdjusted , etExplanation , etAdjustment ;
5658 AutoCompleteTextView etDiagnosis , etDiagnosis1 , etDiagnosis2 , etDiagnosis3 , etDiagnosis4 ;
5759 TextView tvItemTotal , tvServiceTotal ;
5860 Button btnPost , btnNew ;
@@ -95,6 +97,11 @@ protected void onCreate(Bundle savedInstanceState) {
9597 rbEmergency = findViewById (R .id .rbEmergency );
9698 rbReferral = findViewById (R .id .rbReferral );
9799 rbOther = findViewById (R .id .rbOther );
100+ etTotalClaimed = findViewById (R .id .etTotalClaimed );
101+ etTotalApproved = findViewById (R .id .etTotalApproved );
102+ etTotalAdjusted = findViewById (R .id .etTotalAdjusted );
103+ etExplanation = findViewById (R .id .etExplanation );
104+ etAdjustment = findViewById (R .id .etAdjustment );
98105
99106
100107 tvItemTotal .setText ("0" );
@@ -154,6 +161,7 @@ protected void onCreate(Bundle savedInstanceState) {
154161 }));
155162 }),
156163 () -> {
164+ progressDialog .dismiss ();
157165 },
158166 500
159167 );
@@ -387,7 +395,7 @@ private void fillClaimFromRestore(String claimRestoreText) {
387395
388396 if (etGuaranteeNo .getVisibility () != View .GONE ) {
389397 String guaranteeNumber = claim .getString ("guarantee_number" );
390- if ("" . equals (guaranteeNumber ) || "null" . equals ( guaranteeNumber ))
398+ if (StringUtils . isEmpty (guaranteeNumber , true ))
391399 etGuaranteeNo .setText ("" );
392400 else etGuaranteeNo .setText (guaranteeNumber );
393401 }
@@ -471,27 +479,27 @@ private void fillClaimFromDatabase(String claimUUID) {
471479 try {
472480 JSONObject claimDetails = claimObject .getJSONObject ("details" );
473481
474- etClaimCode .setText (claimDetails .getString ("ClaimCode" ));
482+ etClaimCode .setText (claimDetails .optString ("ClaimCode" ));
475483 if (etClaimAdmin .getVisibility () != View .GONE ) {
476- etClaimAdmin .setText (claimDetails .getString ("ClaimAdmin" ));
484+ etClaimAdmin .setText (claimDetails .optString ("ClaimAdmin" ));
477485 }
478- etHealthFacility .setText (claimDetails .getString ("HFCode" ));
486+ etHealthFacility .setText (claimDetails .optString ("HFCode" ));
479487
480488 if (etGuaranteeNo .getVisibility () != View .GONE ) {
481- etGuaranteeNo .setText (claimDetails .getString ("GuaranteeNumber" ));
489+ etGuaranteeNo .setText (claimDetails .optString ("GuaranteeNumber" ));
482490 }
483491
484- etInsureeNumber .setText (claimDetails .getString ("InsureeNumber" ));
485- etStartDate .setText (claimDetails .getString ("StartDate" ));
486- etEndDate .setText (claimDetails .getString ("EndDate" ));
492+ etInsureeNumber .setText (claimDetails .optString ("InsureeNumber" ));
493+ etStartDate .setText (claimDetails .optString ("StartDate" ));
494+ etEndDate .setText (claimDetails .optString ("EndDate" ));
487495
488- etDiagnosis .setText (claimDetails .getString ("ICDCode" ));
489- etDiagnosis1 .setText (claimDetails .getString ("ICDCode1" ));
490- etDiagnosis2 .setText (claimDetails .getString ("ICDCode2" ));
491- etDiagnosis3 .setText (claimDetails .getString ("ICDCode3" ));
492- etDiagnosis4 .setText (claimDetails .getString ("ICDCode4" ));
496+ etDiagnosis .setText (claimDetails .optString ("ICDCode" ));
497+ etDiagnosis1 .setText (claimDetails .optString ("ICDCode1" ));
498+ etDiagnosis2 .setText (claimDetails .optString ("ICDCode2" ));
499+ etDiagnosis3 .setText (claimDetails .optString ("ICDCode3" ));
500+ etDiagnosis4 .setText (claimDetails .optString ("ICDCode4" ));
493501
494- switch (claimDetails .getString ("VisitType" )) {
502+ switch (claimDetails .optString ("VisitType" ). substring ( 0 , 1 )) {
495503 case "E" :
496504 rgVisitType .check (R .id .rbEmergency );
497505 break ;
@@ -505,17 +513,44 @@ private void fillClaimFromDatabase(String claimUUID) {
505513 rgVisitType .clearCheck ();
506514 }
507515
516+ // Show claim adjustment if available (after update)
517+ if (!(JsonUtils .isStringEmpty (claimDetails , "Total" , true )
518+ && JsonUtils .isStringEmpty (claimDetails , "TotalApproved" , true )
519+ && JsonUtils .isStringEmpty (claimDetails , "TotalAdjusted" , true )
520+ && JsonUtils .isStringEmpty (claimDetails , "Explanation" , true )
521+ && JsonUtils .isStringEmpty (claimDetails , "Adjustment" , true ))) {
522+
523+ etTotalClaimed .setVisibility (View .VISIBLE );
524+ etTotalApproved .setVisibility (View .VISIBLE );
525+ etTotalAdjusted .setVisibility (View .VISIBLE );
526+ etExplanation .setVisibility (View .VISIBLE );
527+ etAdjustment .setVisibility (View .VISIBLE );
528+
529+ etTotalClaimed .setText (claimDetails .optString ("Total" ));
530+ etTotalApproved .setText (claimDetails .optString ("TotalApproved" ));
531+ etTotalAdjusted .setText (claimDetails .optString ("TotalAdjusted" ));
532+ etExplanation .setText (claimDetails .optString ("Explanation" ));
533+ etAdjustment .setText (claimDetails .optString ("Adjustment" ));
534+ }
535+
536+
508537 lvItemList .clear ();
509538 if (claimObject .has ("items" )) {
510539 JSONArray items = claimObject .getJSONArray ("items" );
511540 for (int i = 0 ; i < items .length (); i ++) {
512541 HashMap <String , String > item = new HashMap <>();
513542 JSONObject itemJson = items .getJSONObject (i );
514543
515- item .put ("Name" , sqlHandler .getReferenceName (itemJson .getString ("ItemCode" )));
516- item .put ("Code" , itemJson .getString ("ItemCode" ));
517- item .put ("Price" , itemJson .getString ("ItemPrice" ));
518- item .put ("Quantity" , itemJson .getString ("ItemQuantity" ));
544+ item .put ("Name" , sqlHandler .getReferenceName (itemJson .optString ("ItemCode" )));
545+ item .put ("Code" , itemJson .optString ("ItemCode" ));
546+ item .put ("Price" , itemJson .optString ("ItemPrice" ));
547+ item .put ("Quantity" , itemJson .optString ("ItemQuantity" ));
548+ item .put ("PriceAdjusted" , itemJson .optString ("ItemPriceAdjusted" ));
549+ item .put ("QuantityAdjusted" , itemJson .optString ("ItemQuantityAdjusted" ));
550+ item .put ("Explanation" , itemJson .optString ("ItemExplanation" ));
551+ item .put ("Justification" , itemJson .optString ("ItemJustification" ));
552+ item .put ("Valuated" , itemJson .optString ("ItemValuated" ));
553+ item .put ("Result" , itemJson .optString ("ItemResult" ));
519554
520555 lvItemList .add (item );
521556 }
@@ -529,10 +564,16 @@ private void fillClaimFromDatabase(String claimUUID) {
529564 HashMap <String , String > service = new HashMap <>();
530565 JSONObject serviceJson = services .getJSONObject (i );
531566
532- service .put ("Name" , sqlHandler .getReferenceName (serviceJson .getString ("ServiceCode" )));
533- service .put ("Code" , serviceJson .getString ("ServiceCode" ));
534- service .put ("Price" , serviceJson .getString ("ServicePrice" ));
535- service .put ("Quantity" , serviceJson .getString ("ServiceQuantity" ));
567+ service .put ("Name" , sqlHandler .getReferenceName (serviceJson .optString ("ServiceCode" )));
568+ service .put ("Code" , serviceJson .optString ("ServiceCode" ));
569+ service .put ("Price" , serviceJson .optString ("ServicePrice" ));
570+ service .put ("Quantity" , serviceJson .optString ("ServiceQuantity" ));
571+ service .put ("PriceAdjusted" , serviceJson .optString ("ServicePriceAdjusted" ));
572+ service .put ("QuantityAdjusted" , serviceJson .optString ("ServiceQuantityAdjusted" ));
573+ service .put ("Explanation" , serviceJson .optString ("ServiceExplanation" ));
574+ service .put ("Justification" , serviceJson .optString ("ServiceJustification" ));
575+ service .put ("Valuated" , serviceJson .optString ("ServiceValuated" ));
576+ service .put ("Result" , serviceJson .optString ("ServiceResult" ));
536577
537578 lvServiceList .add (service );
538579 }
@@ -664,7 +705,7 @@ protected void showValidationDialog(View view, String msg) {
664705 }
665706
666707 protected void confirmNewDialog (String msg ) {
667- runOnUiThread (() -> showDialog (msg , (dialog , which ) -> ClearForm (), (dialog , which ) -> dialog .dismiss ()));
708+ runOnUiThread (() -> showDialog (null , msg , (dialog , which ) -> ClearForm (), (dialog , which ) -> dialog .dismiss ()));
668709 }
669710
670711 private boolean saveClaim () {
@@ -680,13 +721,16 @@ private boolean saveClaim() {
680721 Calendar cal = Calendar .getInstance ();
681722 String claimDate = format .format (cal .getTime ());
682723
724+ SimpleDateFormat isoFormat = AppInformation .DateTimeInfo .getDefaultIsoShortDatetimeFormatter ();
725+
683726 int SelectedId ;
684727 SelectedId = rgVisitType .getCheckedRadioButtonId ();
685728 RadioButton selectedTypeButton ;
686729 selectedTypeButton = findViewById (SelectedId );
687730 String visitType = selectedTypeButton .getTag ().toString ();
688731
689732 ContentValues claimCV = new ContentValues ();
733+ String updateDate = isoFormat .format (new Date ());
690734
691735 claimCV .put ("ClaimUUID" , claimUUID );
692736 claimCV .put ("ClaimDate" , claimDate );
@@ -705,6 +749,7 @@ private boolean saveClaim() {
705749 claimCV .put ("ICDCode3" , etDiagnosis3 .getText ().toString ());
706750 claimCV .put ("ICDCode4" , etDiagnosis4 .getText ().toString ());
707751 claimCV .put ("VisitType" , visitType );
752+ claimCV .put ("LastUpdated" , updateDate );
708753
709754 ArrayList <ContentValues > claimItemCVs = new ArrayList <>(lvItemList .size ());
710755 for (int i = 0 ; i < lvItemList .size (); i ++) {
@@ -714,6 +759,7 @@ private boolean saveClaim() {
714759 claimItemCV .put ("ItemCode" , lvItemList .get (i ).get ("Code" ));
715760 claimItemCV .put ("ItemPrice" , lvItemList .get (i ).get ("Price" ));
716761 claimItemCV .put ("ItemQuantity" , lvItemList .get (i ).get ("Quantity" ));
762+ claimItemCV .put ("LastUpdated" , updateDate );
717763
718764 claimItemCVs .add (claimItemCV );
719765 }
@@ -726,6 +772,7 @@ private boolean saveClaim() {
726772 claimServiceCV .put ("ServiceCode" , lvServiceList .get (i ).get ("Code" ));
727773 claimServiceCV .put ("ServicePrice" , lvServiceList .get (i ).get ("Price" ));
728774 claimServiceCV .put ("ServiceQuantity" , lvServiceList .get (i ).get ("Quantity" ));
775+ claimServiceCV .put ("LastUpdated" , updateDate );
729776
730777 claimServiceCVs .add (claimServiceCV );
731778 }
0 commit comments