4545import org .openimis .imisclaims .domain .entity .PaymentList ;
4646import org .openimis .imisclaims .domain .entity .Service ;
4747import org .openimis .imisclaims .domain .entity .SubServiceItem ;
48+ import org .openimis .imisclaims .network .exception .HttpException ;
4849import org .openimis .imisclaims .tools .Log ;
50+ import org .openimis .imisclaims .usecase .CheckHealthFacility ;
51+ import org .openimis .imisclaims .usecase .FetchClaimAdmin ;
4952import org .openimis .imisclaims .usecase .FetchClaimAdmins ;
5053import org .openimis .imisclaims .usecase .FetchControls ;
5154import org .openimis .imisclaims .usecase .FetchDiagnosesServicesItems ;
5659
5760import java .io .File ;
5861import java .io .FileOutputStream ;
62+ import java .net .HttpURLConnection ;
5963import java .util .ArrayList ;
6064import java .util .Calendar ;
6165import java .util .Date ;
@@ -553,7 +557,7 @@ public void validateClaimAdminCode(final String claimAdminCode) {
553557 if (c .getCount () == 0 ) {
554558 try {
555559 progressDialog .dismiss ();
556- doLoggedIn (() -> DownLoadDiagnosesServicesItems (claimAdminCode ));
560+ doLoggedIn (() -> CheckHealthFacility (claimAdminCode , HealthFacilityName ));
557561 } catch (Exception e ) {
558562 e .printStackTrace ();
559563 }
@@ -564,6 +568,34 @@ public void validateClaimAdminCode(final String claimAdminCode) {
564568 }
565569 }
566570
571+ public void CheckHealthFacility (String claimAdminCode , String HfCode ){
572+ String progress_message = getResources ().getString (R .string .checkHfValidity );
573+ progressDialog = ProgressDialog .show (this , getResources ().getString (R .string .application ), progress_message );
574+ Thread thread = new Thread () {
575+ public void run () {
576+ try {
577+ boolean isValidHealthFacility = new CheckHealthFacility ().execute (HfCode );
578+ Log .e ("is valid" , String .valueOf (isValidHealthFacility ));
579+ if (isValidHealthFacility ){
580+ runOnUiThread (() -> {
581+ progressDialog .dismiss ();
582+ DownLoadDiagnosesServicesItems (claimAdminCode );
583+ });
584+ } else {
585+ runOnUiThread (() -> {
586+ progressDialog .dismiss ();
587+ Toast .makeText (MainActivity .this , getResources ().getString (R .string .InvalidHealthFacility ), Toast .LENGTH_LONG ).show ();
588+ ClaimAdminDialogBox ();
589+ });
590+ }
591+ } catch (Exception e ) {
592+ e .printStackTrace ();
593+ }
594+ }
595+ };
596+ thread .start ();
597+ }
598+
567599 public void DownLoadDiagnosesServicesItems (@ Nullable final String officerCode ) {
568600 if (global .isNetworkAvailable ()) {
569601 String progress_message = getResources ().getString (R .string .Diagnoses ) + ", " + getResources ().getString (R .string .Services ) + ", " + getResources ().getString (R .string .Items ) + "..." ;
@@ -588,46 +620,50 @@ public void run() {
588620
589621 if (officerCode != null ) {
590622 PaymentList paymentList = new FetchPaymentList ().execute (officerCode );
591- String servicesPricelistUuid = paymentList .getServicesPricelistUuid ();
592623 Date date = Calendar .getInstance ().getTime ();
593- List <Service > services = new FetchServices ().execute (servicesPricelistUuid , date );
594- // insert services
595- for (Service service : services ) {
596- sqlHandler .InsertService (service .getId (),
597- service .getCode (),
598- service .getName (), "S" ,
599- String .valueOf (service .getPrice ()),
600- service .getPackageType (),
601- service .getManualPrice ()
602- );
603- sqlHandler .InsertReferences (service .getCode (), service .getName (), "S" , String .valueOf (service .getPrice ()));
604- sqlHandler .InsertMapping (service .getCode (), service .getName (), "S" );
605-
606- if (service .getSubServices () != null && !service .getSubServices ().isEmpty ()) {
607- List <SubServiceItem > subServices = service .getSubServices ();
608- for (SubServiceItem subService : subServices ) {
609- sqlHandler .InsertSubServices (subService .getId (),
610- service .getId (),String .valueOf (subService .getQty ()),subService .getPrice ());
624+ if (paymentList .getServicesPricelistUuid () != null && !paymentList .getServicesPricelistUuid ().isEmpty ()){
625+ List <Service > services = new FetchServices ().execute (paymentList .getServicesPricelistUuid (), date );
626+
627+ // insert services
628+ for (Service service : services ) {
629+ sqlHandler .InsertService (service .getId (),
630+ service .getCode (),
631+ service .getName (), "S" ,
632+ String .valueOf (service .getPrice ()),
633+ service .getPackageType (),
634+ service .getManualPrice ()
635+ );
636+ sqlHandler .InsertReferences (service .getCode (), service .getName (), "S" , String .valueOf (service .getPrice ()));
637+ sqlHandler .InsertMapping (service .getCode (), service .getName (), "S" );
638+
639+ if (service .getSubServices () != null && !service .getSubServices ().isEmpty ()) {
640+ List <SubServiceItem > subServices = service .getSubServices ();
641+ for (SubServiceItem subService : subServices ) {
642+ sqlHandler .InsertSubServices (subService .getId (),
643+ service .getId (),String .valueOf (subService .getQty ()),subService .getPrice ());
644+ }
611645 }
612- }
613- //insert subItems
614- if ( service . getSubItems () != null && ! service .getSubItems (). isEmpty ()) {
615- List < SubServiceItem > subItems = service . getSubItems ();
616- for ( SubServiceItem subItem : subItems ) {
617- sqlHandler . InsertSubItems ( subItem .getId (),
618- service . getId (), String . valueOf ( subItem . getQty ()), subItem . getPrice ());
646+ //insert subItems
647+ if ( service . getSubItems () != null && ! service . getSubItems (). isEmpty ()) {
648+ List < SubServiceItem > subItems = service .getSubItems ();
649+ for ( SubServiceItem subItem : subItems ) {
650+ sqlHandler . InsertSubItems ( subItem . getId (),
651+ service . getId (), String . valueOf ( subItem .getQty ()), subItem . getPrice ());
652+ }
619653 }
620654 }
621655 }
622656
623- String itemsPriceListUuid = paymentList .getItemsPricelistUuid ();
624- List <Medication > medications = new FetchMedications ().execute (itemsPriceListUuid , date );
625- //insert medications or items
626- for (Medication medication : medications ) {
627- sqlHandler .InsertReferences (medication .getCode (), medication .getName (), "I" , String .valueOf (medication .getPrice ()));
628- sqlHandler .InsertMapping (medication .getCode (), medication .getName (), "I" );
629- sqlHandler .InsertItem (medication .getId (),medication .getCode (),medication .getName (), "I" , String .valueOf (medication .getPrice ()));
657+ if (paymentList .getItemsPricelistUuid () != null && !paymentList .getItemsPricelistUuid ().isEmpty ()){
658+ List <Medication > medications = new FetchMedications ().execute (paymentList .getItemsPricelistUuid (), date );
659+ //insert medications or items
660+ for (Medication medication : medications ) {
661+ sqlHandler .InsertReferences (medication .getCode (), medication .getName (), "I" , String .valueOf (medication .getPrice ()));
662+ sqlHandler .InsertMapping (medication .getCode (), medication .getName (), "I" );
663+ sqlHandler .InsertItem (medication .getId (),medication .getCode (),medication .getName (), "I" , String .valueOf (medication .getPrice ()));
664+ }
630665 }
666+
631667 }
632668
633669 List <HealthFacility > healthFacilities = new FetchHealthFacilities ().execute ();
0 commit comments