|
50 | 50 | import org.openimis.imisclaims.usecase.FetchControls; |
51 | 51 | import org.openimis.imisclaims.usecase.FetchDiagnosesServicesItems; |
52 | 52 | import org.openimis.imisclaims.usecase.FetchHealthfacilities; |
| 53 | +import org.openimis.imisclaims.usecase.FetchMedications; |
53 | 54 | import org.openimis.imisclaims.usecase.FetchPaymentList; |
| 55 | +import org.openimis.imisclaims.usecase.FetchServices; |
54 | 56 |
|
55 | 57 | import java.io.File; |
56 | 58 | import java.io.FileOutputStream; |
57 | 59 | import java.util.ArrayList; |
| 60 | +import java.util.Calendar; |
| 61 | +import java.util.Date; |
58 | 62 | import java.util.List; |
59 | 63 |
|
60 | 64 |
|
@@ -584,40 +588,48 @@ public void run() { |
584 | 588 |
|
585 | 589 | if (officerCode != null) { |
586 | 590 | PaymentList paymentList = new FetchPaymentList().execute(officerCode); |
| 591 | + Date date = Calendar.getInstance().getTime(); |
| 592 | + |
587 | 593 | // 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()); |
| 594 | + if(paymentList.getServicesPricelistUuid() != null && !paymentList.getServicesPricelistUuid().isEmpty()){ |
| 595 | + List<Service> services = new FetchServices().execute(paymentList.getServicesPricelistUuid(), date); |
| 596 | + for (Service service : services) { |
| 597 | + sqlHandler.InsertService(service.getId(), |
| 598 | + service.getCode(), |
| 599 | + service.getName(), "S", |
| 600 | + String.valueOf(service.getPrice()), |
| 601 | + service.getPackageType(), |
| 602 | + service.getManualPrice() |
| 603 | + ); |
| 604 | + sqlHandler.InsertReferences(service.getCode(), service.getName(), "S", String.valueOf(service.getPrice())); |
| 605 | + sqlHandler.InsertMapping(service.getCode(), service.getName(), "S"); |
| 606 | + |
| 607 | + if (service.getSubServices() != null && !service.getSubServices().isEmpty()) { |
| 608 | + List<SubServiceItem> subServices = service.getSubServices(); |
| 609 | + for (SubServiceItem subService : subServices) { |
| 610 | + sqlHandler.InsertSubServices(subService.getId(), |
| 611 | + service.getId(), String.valueOf(subService.getQty()), subService.getPrice()); |
| 612 | + } |
604 | 613 | } |
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()); |
| 614 | + //insert subItems |
| 615 | + if (service.getSubItems() != null && !service.getSubItems().isEmpty()) { |
| 616 | + List<SubServiceItem> subItems = service.getSubItems(); |
| 617 | + for (SubServiceItem subItem : subItems) { |
| 618 | + sqlHandler.InsertSubItems(subItem.getId(), |
| 619 | + service.getId(), String.valueOf(subItem.getQty()), subItem.getPrice()); |
| 620 | + } |
612 | 621 | } |
613 | 622 | } |
614 | 623 | } |
615 | 624 |
|
616 | 625 | //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())); |
| 626 | + if(paymentList.getItemsPricelistUuid() != null && !paymentList.getItemsPricelistUuid().isEmpty()){ |
| 627 | + List<Medication> medications = new FetchMedications().execute(paymentList.getItemsPricelistUuid(), date); |
| 628 | + for (Medication medication : medications) { |
| 629 | + sqlHandler.InsertReferences(medication.getCode(), medication.getName(), "I", String.valueOf(medication.getPrice())); |
| 630 | + sqlHandler.InsertMapping(medication.getCode(), medication.getName(), "I"); |
| 631 | + sqlHandler.InsertItem(medication.getId(),medication.getCode(),medication.getName(), "I", String.valueOf(medication.getPrice())); |
| 632 | + } |
621 | 633 | } |
622 | 634 | } |
623 | 635 |
|
@@ -660,16 +672,21 @@ private void DownLoadServicesItemsPriceList(@NonNull final String claimAdministr |
660 | 672 | public void run() { |
661 | 673 | try { |
662 | 674 | PaymentList paymentList = new FetchPaymentList().execute(claimAdministratorCode); |
| 675 | + String servicesPricelistUuid = paymentList.getServicesPricelistUuid(); |
| 676 | + Date date = Calendar.getInstance().getTime(); |
| 677 | + List<Service> services = new FetchServices().execute(servicesPricelistUuid, date); |
| 678 | + String itemsPriceListUuid = paymentList.getItemsPricelistUuid(); |
| 679 | + List<Medication> medications = new FetchMedications().execute(itemsPriceListUuid, date); |
663 | 680 | sqlHandler.ClearMapping("S"); |
664 | 681 | sqlHandler.ClearMapping("I"); |
665 | 682 |
|
666 | 683 | //Insert Services |
667 | | - for (Service service : paymentList.getServices()) { |
| 684 | + for (Service service : services) { |
668 | 685 | sqlHandler.InsertMapping(service.getCode(), service.getName(), "S"); |
669 | 686 | } |
670 | 687 |
|
671 | 688 | //Insert Items |
672 | | - for (Medication medication : paymentList.getMedications()) { |
| 689 | + for (Medication medication : medications) { |
673 | 690 | sqlHandler.InsertMapping(medication.getCode(), medication.getName(), "I"); |
674 | 691 | } |
675 | 692 | runOnUiThread(() -> { |
|
0 commit comments