org.freemedsoftware.gwt.client.widget.LedgerPopup.java Source code

Java tutorial

Introduction

Here is the source code for org.freemedsoftware.gwt.client.widget.LedgerPopup.java

Source

/*
 * $Id$
 *
 * Authors:
 *      Jeff Buchbinder <jeff@freemedsoftware.org>
 *
 * FreeMED Electronic Medical Record and Practice Management System
 * Copyright (C) 1999-2012 FreeMED Software Foundation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package org.freemedsoftware.gwt.client.widget;

import static org.freemedsoftware.gwt.client.i18n.I18nUtil._;

import java.util.HashMap;

import org.freemedsoftware.gwt.client.CustomRequestCallback;
import org.freemedsoftware.gwt.client.Util;
import org.freemedsoftware.gwt.client.i18n.AppConstants;
import org.freemedsoftware.gwt.client.widget.LedgerWidget.PayCategory;
import org.freemedsoftware.gwt.client.widget.SchedulerWidget.SchedulerCss;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class LedgerPopup extends DialogBox {

    protected CustomTable procedureTable = null;

    protected String procedureId = "";

    protected CustomListBox actionList = null;

    public static String REBILL = _("Rebill");
    public static String PAYMENT = _("Payment");
    public static String COPAY = _("Copay");
    public static String ADJUSTMENT = _("Adjustment");
    public static String DEDUCTABLE = _("Deductable");
    public static String WITH_HOLD = _("Withhold");
    public static String TRANSFER = _("Transfer");
    public static String ALLOWED_AMOUNT = _("Allowed Amount");
    public static String DENIAL = _("Denial");
    public static String WRITE_OFF = _("Writeoff");
    public static String REFUND = _("Refund");
    public static String MISTAKE = _("Mistake");
    public static String LEDGER = _("Ledger");

    @SuppressWarnings("unused")
    private LedgerPopup() {
    }

    public LedgerPopup(final String procedureId, final String patientId, final String procCovSrc) {
        super();
        this.setStylePrimaryName(SchedulerCss.EVENT_DIALOG);

        this.procedureId = procedureId;

        VerticalPanel popupContainer = new VerticalPanel();
        setWidget(popupContainer);

        // ///Top header
        final HorizontalPanel closeButtonContainer = new HorizontalPanel();
        popupContainer.add(closeButtonContainer);
        closeButtonContainer.setWidth("100%");

        Image closeImage = new Image("resources/images/close_x.16x16.png");
        closeImage.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent arg0) {
                getLedgerPopup().hide();
            }
        });
        closeButtonContainer.add(closeImage);
        closeButtonContainer.setCellHorizontalAlignment(closeImage, HasHorizontalAlignment.ALIGN_RIGHT);

        // content panel
        final VerticalPanel contentVPanel = new VerticalPanel();
        popupContainer.add(contentVPanel);

        final VerticalPanel defaultVPanel = new VerticalPanel();
        contentVPanel.add(defaultVPanel);
        // ///View details
        final HorizontalPanel viewDetailHPanel = new HorizontalPanel();
        defaultVPanel.add(viewDetailHPanel);
        final Label procedureLabel = new Label(_("Procedure"));
        viewDetailHPanel.add(procedureLabel);
        CustomButton showDetails = new CustomButton(_("View Details"), AppConstants.ICON_VIEW);
        viewDetailHPanel.add(showDetails);

        showDetails.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent arg0) {
                contentVPanel.clear();
                final VerticalPanel viewDetailsVPanel = new VerticalPanel();
                contentVPanel.add(viewDetailsVPanel);
                final CustomTable viewDetailsTable = new CustomTable();
                viewDetailsTable.removeTableStyle();
                viewDetailsVPanel.add(viewDetailsTable);
                viewDetailsTable.setWidth("100%");
                viewDetailsTable.addColumn(_("Date"), "date");
                viewDetailsTable.addColumn(_("Type"), "type");
                viewDetailsTable.addColumn(_("Description"), "desc");
                viewDetailsTable.addColumn(_("Charges"), "charge");
                viewDetailsTable.addColumn(_("Payments"), "payment");
                viewDetailsTable.addColumn(_("Balance"), "");
                Util.callApiMethod("Ledger", "getLedgerInfo", new Integer(procedureId),
                        new CustomRequestCallback() {
                            @Override
                            public void onError() {

                            }

                            @SuppressWarnings("unchecked")
                            @Override
                            public void jsonifiedData(Object data) {
                                HashMap<String, String>[] result = (HashMap<String, String>[]) data;
                                viewDetailsTable.setMaximumRows(result.length);
                                viewDetailsTable.loadData(result);
                                // HashMap<String, String> totals =
                                // result[result.length-1];
                                Integer totalCharges = new Integer(result[result.length - 1].get("total_charges"));
                                Integer totalPayments = new Integer(
                                        result[result.length - 1].get("total_payments"));

                                FlexTable totalDetailsTable = viewDetailsTable.getFlexTable();
                                int row = totalDetailsTable.getRowCount();
                                totalDetailsTable.setHTML(row, 0, _("Total"));
                                totalDetailsTable.setHTML(row, 3, totalCharges + "");
                                totalDetailsTable.setHTML(row, 4, totalPayments + "");
                                totalDetailsTable.setHTML(row, 5, (totalCharges - totalPayments) + "");
                                totalDetailsTable.getRowFormatter().setStyleName(row,
                                        AppConstants.STYLE_TABLE_HEADER);
                            }
                        }, "HashMap<String,String>[]");
                final CustomButton backBtn = new CustomButton(_("Back"), AppConstants.ICON_PREV);
                contentVPanel.add(backBtn);
                backBtn.addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent arg0) {
                        contentVPanel.clear();
                        contentVPanel.add(defaultVPanel);
                    }
                });
            }
        });

        // /custom table

        procedureTable = new CustomTable();
        procedureTable.removeTableStyle();
        defaultVPanel.add(procedureTable);
        procedureTable.setMaximumRows(4);
        procedureTable.addColumn(_("Procedure Date"), "proc_date");
        procedureTable.addColumn(_("Procedure Code"), "proc_code");
        procedureTable.addColumn(_("Provider"), "prov_name");
        procedureTable.addColumn(_("Charged"), "proc_obal");
        procedureTable.addColumn(_("Charges"), "proc_charges");
        procedureTable.addColumn(_("Paid"), "proc_paid");
        procedureTable.addColumn(_("Balance"), "proc_currbal");
        procedureTable.addColumn(_("Billed"), "proc_billed");
        procedureTable.setIndexName("Id");

        // //////////action area
        final HorizontalPanel actionHPanel = new HorizontalPanel();
        final Label actionLabel = new Label(_("Action"));
        actionHPanel.add(actionLabel);
        actionList = new CustomListBox();
        actionList.addItem(_("NONE SELECTED"));
        actionList.addItem(REBILL);
        actionList.addItem(PAYMENT);
        actionList.addItem(COPAY);
        actionList.addItem(ADJUSTMENT);
        actionList.addItem(DEDUCTABLE);
        actionList.addItem(WITH_HOLD);
        actionList.addItem(TRANSFER);
        actionList.addItem(ALLOWED_AMOUNT);
        actionList.addItem(DENIAL);
        actionList.addItem(WRITE_OFF);
        actionList.addItem(REFUND);
        actionList.addItem(MISTAKE);
        actionList.addItem(LEDGER);
        actionHPanel.add(actionList);
        final CustomButton proceedButton = new CustomButton(_("Proceed"), AppConstants.ICON_NEXT);
        actionHPanel.add(proceedButton);
        proceedButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent arg0) {
                if (actionList.getSelectedIndex() != 0) {
                    LedgerWidget pw = null;
                    CustomRequestCallback cb = new CustomRequestCallback() {
                        @Override
                        public void onError() {

                        }

                        @Override
                        public void jsonifiedData(Object data) {
                            if (data.toString().equals("update")) {
                                contentVPanel.clear();
                                contentVPanel.add(defaultVPanel);
                                refreshData();
                            } else if (data.toString().equals("close")) {
                                contentVPanel.clear();
                                contentVPanel.add(defaultVPanel);
                                refreshData();
                            } else if (data.toString().equals("cancel")) {
                                contentVPanel.clear();
                                contentVPanel.add(defaultVPanel);
                                refreshData();
                            }
                        }
                    };
                    boolean hasUI = true;
                    if (actionList.getSelectedIndex() == 1) {
                        hasUI = false;
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.REBILLED, cb);
                    } else if (actionList.getSelectedIndex() == 2) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.PAYMENT, cb);
                    } else if (actionList.getSelectedIndex() == 3) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.COPAY, cb);
                    } else if (actionList.getSelectedIndex() == 4) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.ADJUSTMENT, cb);
                    } else if (actionList.getSelectedIndex() == 5) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.DEDUCTABLE, cb);
                    } else if (actionList.getSelectedIndex() == 6) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.WITHHOLD, cb);
                    } else if (actionList.getSelectedIndex() == 7) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.TRANSFER, cb);
                    } else if (actionList.getSelectedIndex() == 8) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.ALLOWEDAMOUNT, cb);
                    } else if (actionList.getSelectedIndex() == 9) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.DENIAL, cb);
                    } else if (actionList.getSelectedIndex() == 10) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.WRITEOFF, cb);
                    } else if (actionList.getSelectedIndex() == 11) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.REFUND, cb);
                    } else if (actionList.getSelectedIndex() == 12) {
                        hasUI = false;
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.MISTAKE, cb);
                    } else if (actionList.getSelectedIndex() == 13) {
                        pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.LEDGER, cb);
                    }

                    if (pw != null) {
                        if (hasUI) {
                            contentVPanel.clear();
                            contentVPanel.add(pw);
                        }
                    }
                } else {
                    Window.alert(_("Please select the action type."));
                }
            }
        });
        defaultVPanel.add(actionHPanel);
        defaultVPanel.setCellHorizontalAlignment(actionHPanel, HasHorizontalAlignment.ALIGN_CENTER);
        refreshData();
    }

    public void refreshData() {
        Util.callApiMethod("ClaimLog", "getProcInfo", new Integer(procedureId), new CustomRequestCallback() {
            @Override
            public void onError() {
            }

            @SuppressWarnings("unchecked")
            @Override
            public void jsonifiedData(Object data) {
                HashMap<String, String>[] result = new HashMap[1];
                result[0] = (HashMap<String, String>) data;
                if (result[0].get("proc_allowed") != null)
                    procedureTable.addColumn("Allowed", result[0].get("proc_allowed"));
                if (result[0].get("proc_billed").equalsIgnoreCase("1"))
                    result[0].put("proc_billed", "Yes");
                else
                    result[0].put("proc_billed", "No");
                procedureTable.loadData(result);
            }
        }, "HashMap<String,String>");
    }

    public void removeAction(String action) {
        for (int index = 0; index < actionList.getItemCount(); index++) {
            if (actionList.getItemText(index).equals(action)) {
                actionList.removeItem(index);
                break;
            }
        }
    }

    public LedgerPopup getLedgerPopup() {
        return this;
    }
}