5050import org .openimis .imisclaims .usecase .FetchControls ;
5151import org .openimis .imisclaims .usecase .FetchDiagnosesServicesItems ;
5252import org .openimis .imisclaims .usecase .FetchHealthfacilities ;
53- import org .openimis .imisclaims .usecase .FetchMedications ;
5453import org .openimis .imisclaims .usecase .FetchPaymentList ;
55- import org .openimis .imisclaims .usecase .FetchServices ;
5654
5755import java .io .File ;
5856import java .io .FileOutputStream ;
@@ -551,7 +549,7 @@ public void validateClaimAdminCode(final String claimAdminCode) {
551549 if (c .getCount () == 0 ) {
552550 try {
553551 progressDialog .dismiss ();
554- doLoggedIn (() -> DownLoadDiagnosesServicesItems (null ));
552+ doLoggedIn (() -> DownLoadDiagnosesServicesItems (claimAdminCode ));
555553 } catch (Exception e ) {
556554 e .printStackTrace ();
557555 }
@@ -573,25 +571,54 @@ public void run() {
573571 saveLastUpdateDate (diagnosesServicesMedications .getLastUpdated ());
574572 sqlHandler .ClearAll ("tblReferences" );
575573 sqlHandler .ClearAll ("tblHealthFacilities" );
574+ sqlHandler .ClearAll ("tblServices" );
575+ sqlHandler .ClearAll ("tblSubServices" );
576+ sqlHandler .ClearAll ("tblSubItems" );
577+ sqlHandler .ClearAll ("tblItems" );
576578 sqlHandler .ClearMapping ("S" );
577579 sqlHandler .ClearMapping ("I" );
578580 //Insert Diagnoses
579581 for (Diagnosis diagnosis : diagnosesServicesMedications .getDiagnoses ()) {
580582 sqlHandler .InsertReferences (diagnosis .getCode (), diagnosis .getName (), "D" , "" );
581583 }
582584
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- }
585+ if (officerCode != null ) {
586+ PaymentList paymentList = new FetchPaymentList ().execute (officerCode );
587+ // insert services
588+ for (Service service : paymentList .getServices ()) {
589+ sqlHandler .InsertService (service .getId (),
590+ service .getCode (),
591+ service .getName (), "S" ,
592+ String .valueOf (service .getPrice ()),
593+ service .getPackageType (),
594+ service .getManualPrice ()
595+ );
596+ sqlHandler .InsertReferences (service .getCode (), service .getName (), "S" , String .valueOf (service .getPrice ()));
597+ sqlHandler .InsertMapping (service .getCode (), service .getName (), "S" );
598+
599+ if (service .getSubServices () != null && !service .getSubServices ().isEmpty ()) {
600+ List <SubServiceItem > subServices = service .getSubServices ();
601+ for (SubServiceItem subService : subServices ) {
602+ sqlHandler .InsertSubServices (subService .getId (),
603+ service .getId (), String .valueOf (subService .getQty ()), subService .getPrice ());
604+ }
605+ }
606+ //insert subItems
607+ if (service .getSubItems () != null && !service .getSubItems ().isEmpty ()) {
608+ List <SubServiceItem > subItems = service .getSubItems ();
609+ for (SubServiceItem subItem : subItems ) {
610+ sqlHandler .InsertSubItems (subItem .getId (),
611+ service .getId (), String .valueOf (subItem .getQty ()), subItem .getPrice ());
612+ }
613+ }
614+ }
588615
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 ()));
616+ //insert Items
617+ for ( Medication medication : paymentList . getMedications ()) {
618+ sqlHandler . InsertReferences ( medication . getCode (), medication . getName (), "I" , String . valueOf ( medication . getPrice ()));
619+ sqlHandler .InsertMapping (medication .getCode (), medication .getName (), "I" );
620+ sqlHandler .InsertItem (medication .getId (), medication . getCode (),medication .getName (), "I" , String . valueOf ( medication . getPrice ()) );
621+ }
595622 }
596623
597624 List <HealthFacility > healthFacilities = new FetchHealthfacilities ().execute ();
@@ -601,7 +628,9 @@ public void run() {
601628
602629 runOnUiThread (() -> {
603630 progressDialog .dismiss ();
604- downloadServices (officerCode );
631+ if (officerCode != null ) {
632+ DownLoadServicesItemsPriceList (officerCode );
633+ }
605634 });
606635 } catch (Exception e ) {
607636 e .printStackTrace ();
@@ -737,63 +766,4 @@ public void onAllRequirementsMet() {
737766 }
738767 refreshCount ();
739768 }
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- }
799769}
0 commit comments