@@ -551,7 +551,7 @@ public void validateClaimAdminCode(final String claimAdminCode) {
551551 if (c .getCount () == 0 ) {
552552 try {
553553 progressDialog .dismiss ();
554- doLoggedIn (() -> DownLoadDiagnosesServicesItems (null ));
554+ doLoggedIn (() -> DownLoadDiagnosesServicesItems (claimAdminCode ));
555555 } catch (Exception e ) {
556556 e .printStackTrace ();
557557 }
@@ -573,25 +573,54 @@ public void run() {
573573 saveLastUpdateDate (diagnosesServicesMedications .getLastUpdated ());
574574 sqlHandler .ClearAll ("tblReferences" );
575575 sqlHandler .ClearAll ("tblHealthFacilities" );
576+ sqlHandler .ClearAll ("tblServices" );
577+ sqlHandler .ClearAll ("tblSubServices" );
578+ sqlHandler .ClearAll ("tblSubItems" );
579+ sqlHandler .ClearAll ("tblItems" );
576580 sqlHandler .ClearMapping ("S" );
577581 sqlHandler .ClearMapping ("I" );
578582 //Insert Diagnoses
579583 for (Diagnosis diagnosis : diagnosesServicesMedications .getDiagnoses ()) {
580584 sqlHandler .InsertReferences (diagnosis .getCode (), diagnosis .getName (), "D" , "" );
581585 }
582586
583- //Insert Services
584- for (Service service : diagnosesServicesMedications .getServices ()) {
585- sqlHandler .InsertReferences (service .getCode (), service .getName (), "S" , String .valueOf (service .getPrice ()));
586- sqlHandler .InsertMapping (service .getCode (), service .getName (), "S" );
587- }
587+ if (officerCode != null ) {
588+ PaymentList paymentList = new FetchPaymentList ().execute (officerCode );
589+ // insert services
590+ for (Service service : paymentList .getServices ()) {
591+ sqlHandler .InsertService (service .getId (),
592+ service .getCode (),
593+ service .getName (), "S" ,
594+ String .valueOf (service .getPrice ()),
595+ service .getPackageType (),
596+ service .getManualPrice ()
597+ );
598+ sqlHandler .InsertReferences (service .getCode (), service .getName (), "S" , String .valueOf (service .getPrice ()));
599+ sqlHandler .InsertMapping (service .getCode (), service .getName (), "S" );
600+
601+ if (service .getSubServices () != null && !service .getSubServices ().isEmpty ()) {
602+ List <SubServiceItem > subServices = service .getSubServices ();
603+ for (SubServiceItem subService : subServices ) {
604+ sqlHandler .InsertSubServices (subService .getId (),
605+ service .getId (),String .valueOf (subService .getQty ()),subService .getPrice ());
606+ }
607+ }
608+ //insert subItems
609+ if (service .getSubItems () != null && !service .getSubItems ().isEmpty ()) {
610+ List <SubServiceItem > subItems = service .getSubItems ();
611+ for (SubServiceItem subItem : subItems ) {
612+ sqlHandler .InsertSubItems (subItem .getId (),
613+ service .getId (), String .valueOf (subItem .getQty ()),subItem .getPrice ());
614+ }
615+ }
616+ }
588617
589- //Insert Items
590- List < Medication > medications = new FetchMedications (). execute ();
591- for ( Medication medication : medications ) {
592- sqlHandler .InsertReferences (medication .getCode (), medication .getName (), "I" , String . valueOf ( medication . getPrice ()) );
593- sqlHandler .InsertMapping (medication .getCode (), medication .getName (), "I" );
594- sqlHandler . InsertItem ( medication . getId (), medication . getCode (), medication . getName (), "I" , String . valueOf ( medication . getPrice ()));
618+ //insert medications or items
619+ for ( Medication medication : paymentList . getMedications ()) {
620+ sqlHandler . InsertReferences ( medication . getCode (), medication . getName (), "I" , String . valueOf ( medication . getPrice ()));
621+ sqlHandler .InsertMapping (medication .getCode (), medication .getName (), "I" );
622+ sqlHandler .InsertItem (medication .getId (), medication . getCode (),medication .getName (), "I" , String . valueOf ( medication . getPrice ()) );
623+ }
595624 }
596625
597626 List <HealthFacility > healthFacilities = new FetchHealthFacilities ().execute ();
@@ -601,7 +630,9 @@ public void run() {
601630
602631 runOnUiThread (() -> {
603632 progressDialog .dismiss ();
604- downloadServices (officerCode );
633+ if (officerCode != null ) {
634+ DownLoadServicesItemsPriceList (officerCode );
635+ }
605636 });
606637 } catch (Exception e ) {
607638 e .printStackTrace ();
@@ -737,63 +768,4 @@ public void onAllRequirementsMet() {
737768 }
738769 refreshCount ();
739770 }
740-
741- public void downloadServices (@ Nullable final String officerCode ) {
742- if (global .isNetworkAvailable ()) {
743- String progress_message = getResources ().getString (R .string .Services );
744- progressDialog = ProgressDialog .show (this , getResources ().getString (R .string .initializing ), progress_message );
745- Thread thread = new Thread (() ->{
746- try {
747- List <Service > services = new FetchServices ().execute ();
748- if (!services .isEmpty ()) {
749- sqlHandler .ClearAll ("tblServices" );
750- sqlHandler .ClearAll ("tblSubServices" );
751- sqlHandler .ClearAll ("tblSubItems" );
752- for (Service service : services ) {
753- sqlHandler .InsertService (service .getId (),
754- service .getCode (),
755- service .getName (), "S" ,
756- String .valueOf (service .getPrice ()),
757- service .getPackageType (),
758- service .getManualPrice ());
759-
760- if (service .getSubServices () != null && !service .getSubServices ().isEmpty ()) {
761- List <SubServiceItem > subServices = service .getSubServices ();
762- for (SubServiceItem subService : subServices ) {
763- sqlHandler .InsertSubServices (subService .getId (),
764- service .getId (),String .valueOf (subService .getQty ()),subService .getPrice ());
765- }
766- }
767- //insert subItems
768- if (service .getSubItems () != null && !service .getSubItems ().isEmpty ()) {
769- List <SubServiceItem > subItems = service .getSubItems ();
770- for (SubServiceItem subItem : subItems ) {
771- sqlHandler .InsertSubItems (subItem .getId (),
772- service .getId (), String .valueOf (subItem .getQty ()),subItem .getPrice ());
773- }
774- }
775- }
776- runOnUiThread (() -> {
777- progressDialog .dismiss ();
778- Toast .makeText (MainActivity .this , getResources ().getString (R .string .installed_updates ), Toast .LENGTH_LONG ).show ();
779- if (officerCode != null ) {
780- DownLoadServicesItemsPriceList (officerCode );
781- }
782- });
783- } else {
784- runOnUiThread (() -> {
785- progressDialog .dismiss ();
786- Toast .makeText (MainActivity .this , getResources ().getString (R .string .downloadFail ), Toast .LENGTH_LONG ).show ();
787- });
788- }
789- } catch ( Exception e ) {
790- e .printStackTrace ();
791- runOnUiThread (() -> progressDialog .dismiss ());
792- }
793- });
794- thread .start ();
795- }else {
796- ErrorDialogBox (getResources ().getString (R .string .CheckInternet ));
797- }
798- }
799771}
0 commit comments