Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<DME_WrapperCheck> doGenerate() {
- List<DME_Service_Item__c> itemList = new List<DME_Service_Item__c>();
- this.checkItemMap = new Map<String, DME_WrapperCheck>();
- this.billCheckMap = new Map<Id, String>();
- this.checkItemList = new List<DME_WrapperCheck>();
- if(!this.showError) {
- String day;
- String month;
- String formattedStringDate;
- //format date to correct SOQL format
- if(this.checkDate != null) {
- if(this.checkDate.day()<10) {
- day = '0' + String.valueOf(checkDate.day());
- } else {
- day = String.valueOf(checkDAte.day());
- }
- if(checkDate.month()<10) {
- month = '0' + String.valueOf(checkDate.month());
- } else {
- month = String.valueOf(checkDate.month());
- }
- formattedStringDate = checkDate.year() + '-' + month + '-' + day;
- }
- Boolean run = false;
- //general query string for paid items without filter criteria by check date or number
- String queryString = 'SELECT Order__r.DME_Injury__r.Person__r.LastName, Order__r.DME_Injury__r.Person__r.FirstName, '
- + 'Bill_Line_Item__r.Bill__r.ProviderInvoice__c, DOS_From__c, Product__r.ProductCode, Product__r.Name, '
- + 'Quantity__c, Bill_Line_Item__r.Linecharge__c, Discount_Amount__c, APR__c, Bill_Line_Item__r.Name, '
- + 'Bill_Line_Item__r.Denial_Reason__c, Bill_Line_Item__r.Bill__r.Id, Bill_Line_Item__r.Bill__r.Trading_Partner__r.Name, '
- + 'Check_Number__c, Check_Paid_Amount__c, Check_Paid_Date__c, Bill_Line_Item__r.Bill__r.Trading_Partner__r.Id, '
- + 'Bill_Line_Item__r.Bill__r.Trading_Partner__r.RA_Doc_Type_Preference__c, Bill_Line_Item__c, '
- + 'Bill_Line_Item__r.Compliance_Reason__c, Bill_Line_Item__r.Duplicate_Check_Amount__c, Bill_Line_Item__r.Duplicate_Check_Number__c, '
- + 'Bill_Line_Item__r.Bill__r.Trading_Partner__r.RA_Delivery_Preference__c, Bill_Line_Item__r.Reasoncode__c '
- + 'FROM DME_Service_Item__c '
- + 'WHERE (Paid__c = TRUE) AND (Check_Paid_Amount__c <> null AND Check_Paid_Amount__c <> 0 AND Check_Number__c <> '') '
- + 'AND ';
- //append check date and number filter to query string
- if(this.checkDate != null) {
- if(this.checkNumber != '' && this.checkNumber != null) {
- queryString += '(Check_Paid_Date__c = ' + formattedStringDate + ' AND Check_Number__c = ''+ checkNumber + '') ';
- run = true;
- } else {
- queryString += '(Check_Paid_Date__c = ' + formattedStringDate + ') ';
- run = true;
- }
- } else if(this.checkNumber != '' && this.checkNumber != null) {
- queryString += '(Check_Number__c = '' + checkNumber + '') ';
- run = true;
- } else {
- showError = true;
- errorMsg = 'Please enter at least one search criteria';
- }
- if(!this.showError) {
- //get records
- if(run) {
- System.debug(queryString);
- itemList = Database.query(queryString);
- this.runReport = true;
- }
- Set<Id> tempBillIdList = new Set<Id>();
- List<DME_Service_Item__c> tempDeniedItemList = new List<DME_Service_Item__c>();
- //get bill ids of paid bills
- for(DME_Service_Item__c si : itemList) {
- if(si.Bill_Line_Item__r.Bill__r.Id != null) {
- tempBillIdList.add(si.Bill_Line_Item__r.Bill__r.Id);
- }
- }
- //get unpaid items of the bills which have been paid for (partial denied)
- tempDeniedItemList = [ SELECT Order__r.DME_Injury__r.Person__r.LastName, Order__r.DME_Injury__r.Person__r.FirstName,
- Bill_Line_Item__r.Bill__r.ProviderInvoice__c, DOS_From__c, Product__r.ProductCode, Product__r.Name,
- Quantity__c, Bill_Line_Item__r.Linecharge__c, Discount_Amount__c, APR__c, Bill_Line_Item__r.Name,
- Bill_Line_Item__r.Bill__r.Trading_Partner__r.Id, Bill_Line_Item__r.Denial_Reason__c,
- Bill_Line_Item__r.Bill__r.Id, Bill_Line_Item__r.Bill__r.Trading_Partner__r.Name, Bill_Line_Item__c,
- Check_Number__c, Check_Paid_Amount__c, Check_Paid_Date__c, Bill_Line_Item__r.Bill__r.Trading_Partner__r.RA_Doc_Type_Preference__c,
- Bill_Line_Item__r.Bill__r.Trading_Partner__r.RA_Delivery_Preference__c, Bill_Line_Item__r.Reasoncode__c,
- Bill_Line_Item__r.Compliance_Reason__c, Bill_Line_Item__r.Duplicate_Check_Amount__c, Bill_Line_Item__r.Duplicate_Check_Number__c
- FROM DME_Service_Item__c
- WHERE Status__c = :DME_Constants.SERVICE_ITEM_STATUS_DENIED_SI AND Bill_Line_Item__r.Bill__r.Id IN :tempBillIdList AND Id NOT IN :itemList ];
- //remove denial reason string and get only denial code
- for(DME_Service_Item__c si : tempDeniedItemList) {
- if(si.Bill_Line_Item__r.Denial_Reason__c != null) {
- si.Bill_Line_Item__r.Denial_Reason__c = si.Bill_Line_Item__r.Denial_Reason__c.substring(0, 2);
- }
- }
- itemList.addAll(tempDeniedItemList);
- Set<Id> bliIdList = new Set<Id>();
- for(DME_Service_Item__c si : itemList) {
- if(si.Discount_Amount__c == null) {
- si.Discount_Amount__c = 0.00;
- }
- if(si.Check_Paid_Amount__c == null) {
- si.Discount_Amount__c = 0.00;
- }
- if(si.Bill_Line_Item__r.Linecharge__c == null) {
- si.Bill_Line_Item__r.Linecharge__c = 0.00;
- }
- bliIdList.add(si.Bill_Line_Item__c);
- }
- List<DME_Bill_Line_Item__c> tempDeniedBliList = new List<DME_Bill_Line_Item__c>();
- tempDeniedBliList = [ SELECT Id, Bill__c, Bill__r.Patient_FirstName__c, Bill__r.Patient_LastName__c,
- Bill__r.ProviderInvoice__c, Servicefrom__c, Procedure_Code__c, Procedure_Description__c, Units__c, Linecharge__c, Name,
- Reasoncode__c, Bill__r.Check_Number__c, Compliance_Reason__c, Duplicate_Check_Amount__c, Duplicate_Check_Number__c
- FROM DME_Bill_Line_Item__c WHERE Status__c = :DME_Constants.BILL_LINE_ITEM_STATUS_DENIED AND Bill__c IN :tempBillIdList
- AND Id NOT IN :bliIdList ];
- //map bill id to check number
- for(DME_Service_Item__c si : itemList) {
- if(si.Bill_Line_Item__r.Bill__r.Id != null) {
- if(billCheckMap.get(si.Bill_Line_Item__r.Bill__r.Id) == null) {
- billCheckMap.put(si.Bill_Line_Item__r.Bill__r.Id, si.Check_Number__c);
- }
- }
- }
- String tempCheckNo = '';
- //map all items to the check number which maps to its bill
- for(DME_Service_Item__c si : itemList) {
- tempCheckNo = billCheckMap.get(si.Bill_Line_Item__r.Bill__r.Id);
- if(checkItemMap.get(tempCheckNo) == null) {
- DME_WrapperCheck wc = new DME_WrapperCheck(tempCheckNo, si.Check_Paid_Amount__c,
- si.Check_Paid_Date__c, si.Bill_Line_Item__r.Bill__r.Trading_Partner__r.Name,
- si.Bill_Line_Item__r.Bill__r.Trading_Partner__r.RA_Doc_Type_Preference__c,
- si.Bill_Line_Item__r.Bill__r.Trading_Partner__r.RA_Delivery_Preference__c,
- si.Bill_Line_Item__r.Bill__r.Trading_Partner__r.Id,
- null );
- wc.siList.add(si);
- checkItemMap.put(tempCheckNo, wc);
- } else {
- checkItemMap.get(tempCheckNo).siList.add(si);
- if(si.Check_Paid_Amount__c!=null) {
- checkItemMap.get(tempCheckNo).checkAmount += si.Check_Paid_Amount__c;
- }
- }
- }
- for(DME_Bill_Line_Item__c bli : tempDeniedBliList) {
- checkItemMap.get(bli.Bill__r.Check_Number__c).bliList.add(bli);
- }
- for(DME_WrapperCheck wc : checkItemMap.values()) {
- // get the count of display items in the check items
- counter += wc.sortLists(counter);
- System.debug('counter' + counter);
- system.debug('wc.displayList - ' + wc.displayList);
- system.debug('wc.senditemList - ' + wc.sendDisplayItemList);
- checkItemList.add(wc);
- }
- // If limit exceeds show the error popup and send all records to the logged in user
- if(counter > 4) {
- this.limitExceedError = true;
- // Check whether the email is not sent
- if(!this.emailSent) {
- this.sendFiltered(checkItemList);
- }
- }
- }
- }
- for(DME_WrapperCheck wc : checkItemList) {
- String formattedStringDate;
- String day;
- String month;
- if(wc.checkDate.day()<10) {
- day = '0' + String.valueOf(wc.checkDate.day());
- } else {
- day = String.valueOf(wc.checkDate.day());
- }
- if(wc.checkDate.month()<10) {
- month = '0' + String.valueOf(wc.checkDate.month());
- } else {
- month = String.valueOf(wc.checkDate.month());
- }
- wc.dlcdate = month + '/' + day + '/' + wc.checkDate.year();
- }
- return checkItemList;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement