Package clips.service

Source Code of clips.service.PanelSerRenList

/*
* PanelServiceList.java
*
* Created on 21 Февраль 2008 г., 15:30
*/
package clips.service;

import beans.contract.search.ContractFilter;
import clips.delegate.client.ClientLocal;
import clips.delegate.doctor.DiseaseLocal;
import cli_fmw.delegate.DelegateLine2;
import clips.service.newSerRen.DialogNewSerRen;
import clips.delegate.service.SerRenLocal;
import cli_fmw.delegate.utils.TimeLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageException;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.Printable;
import cli_fmw.main.PageGeneric;
import cli_fmw.report.TableReportOptions;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.contract.info.PanelContractInfo;
import clips.delegate.contract.ContractFactoryLocal;
import clips.delegate.contract.ContractLocal;
import clips.login.UserInfo;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import javax.swing.ListSelectionModel;
import framework.utils.Converter;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
* Панель просмотра и добавления услуг клиента работником регистратуры. Содержит
* таблицу услуг. После создания панели необходимо дать панели
* клиента методом setClient(ClientLocal client)
* @author  vip
*/
public class PanelSerRenList extends PageGeneric implements Printable {

    public static final int MODE_BY_PERIOD = 0;
    public static final int MODE_NOT_IN_DISEASE = 1;
    public static final int MODE_ONLY_DISEASE = 2;
    private ClientLocal client;
    private DiseaseLocal disease;      //Может быть null, нужен только если отображается список услуг из заболевания
    private ContractLocal contract;
    List<SerRenLocal> serRenList;                     //Итератор отображаемых услуг
    private int mode;

    public PanelSerRenList(PageContainer container, DelegateLine2 client) throws ClipsException {
        this(container, (ClientLocal) client, null, null, MODE_BY_PERIOD);
    }

    /**
     *
     * @param container
     * @param client
     * @param contract
     * @param disease
     * @param mode
     * @throws ClipsException
     */
    public PanelSerRenList(PageContainer container, ClientLocal client, ContractLocal contract, DiseaseLocal disease, int mode) throws ClipsException {
        super(container);
        initComponents();

        //Выставление режима
        this.mode = mode;
        if (mode == MODE_NOT_IN_DISEASE) {
            jPanel1.setVisible(false);
            btContract.setVisible(false);
            btTransactions.setVisible(false);
        }
        if (mode == MODE_ONLY_DISEASE) {
            jPanel1.setVisible(false);
            jPanel6.setVisible(false);
        }
        //выставление клиента и заболевания
        this.client = client;
        this.disease = disease;
        this.contract = contract;
        GregorianCalendar gc = new GregorianCalendar();
        try {
            gc = TimeLocal.getCurrentTime();
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
        gc.set(GregorianCalendar.HOUR_OF_DAY, 0);
        gc.set(GregorianCalendar.MINUTE, 0);
        gc.set(GregorianCalendar.SECOND, 0);
        gc.set(GregorianCalendar.MILLISECOND, 0);
        dateTo.setDate(gc.getTime());
        gc.add(GregorianCalendar.MONTH, -1);
        dateFrom.setDate(gc.getTime());

        DefaultComboBoxModel contractModel = new DefaultComboBoxModel(loadContractList()) ;
        cbContract.setModel(contractModel);
        if (this.contract != null) {
            cbContract.setSelectedItem(this.contract);
        } else {
            cbContract.setSelectedIndex(0);
        }
        cbContract.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    reloadTable();
                } catch (ClipsException ex) {
                    MessageBox.showException(ex);
                }
            }
        });

        reloadTable();
  resizeColumn();

        tabSerRenList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                boolean sel = tabSerRenList.getSelectedRowCount() > 0;
                btContract.setEnabled(sel);
                btRemove.setEnabled(sel);
                btTransactions.setEnabled(sel);
            }
        });
       
  StateSaver.attachTo(this);
    }

    /**
     * Выставляет режим панели ( все по периоду или только назначенные)
     * Метод должен быть вызван обязательно до setClient(ClientLocal client)
     * @param mode
     */
    private void reloadTable() throws ClipsException {
        if (mode == MODE_BY_PERIOD) {
            // все услуги за период
            //Поправка в периоде на 1 день вперед т.к. время у dateTo 00:00
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(dateTo.getDate());
            gc.add(GregorianCalendar.DAY_OF_YEAR, 1);
            Object selectedItem = cbContract.getSelectedItem();
            contract = selectedItem instanceof ContractLocal ? (ContractLocal)selectedItem : null;
            serRenList = client.getSerRenList(dateFrom.getDate(), gc.getTime(), contract);
        } else if (mode == MODE_NOT_IN_DISEASE) {
            // услуги из заболевания + назначенные услуги
            System.out.println("Услуги из заболевания и назначенные");
            serRenList = client.getSerRenListOutofDisease();
        } else if (mode == MODE_ONLY_DISEASE) {
            // все услуги из данного заболевания
            serRenList = disease.getSerrenList();
        }
       
        for (int i = 0; i < serRenList.size(); i++) {
            serRenList.get(i).getPolisData();
            serRenList.get(i).addAuditListener(getAuditManager());
        }
        tabSerRenList.setModel(new TableModelSerRenList(serRenList));

        tabSerRenList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tabSerRenList.setDefaultRenderer(Object.class, new TableCellRendererSerRenList(serRenList));
        fireContainerEventStateChanged();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        dateFrom = new org.infotechservice.ICalendar.components.ICDateChooser();
        jLabel1 = new javax.swing.JLabel();
        dateTo = new org.infotechservice.ICalendar.components.ICDateChooser();
        jLabel3 = new javax.swing.JLabel();
        cbContract = new javax.swing.JComboBox();
        btReload = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        btContract = new javax.swing.JButton();
        btTransactions = new javax.swing.JButton();
        btRemove = new javax.swing.JButton();
        btAdd = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabSerRenList = new cli_fmw.utils.sorted_table.SortedTable();

        setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        setLayout(new java.awt.BorderLayout(5, 5));

        jLabel2.setText("c");

        dateFrom.setPreferredSize(new java.awt.Dimension(132, 27));

        jLabel1.setText("по");

        dateTo.setPreferredSize(new java.awt.Dimension(132, 27));

        jLabel3.setText("Договор");

        btReload.setText("Обновить");
        btReload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btReloadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dateFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dateTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbContract, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btReload)
                .addContainerGap(27, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel2)
            .addComponent(dateFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jLabel1)
            .addComponent(dateTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3)
                .addComponent(cbContract, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(btReload))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btReload, cbContract, dateFrom, dateTo, jLabel1, jLabel2, jLabel3});

        add(jPanel1, java.awt.BorderLayout.NORTH);

        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        btContract.setText("Договор");
        btContract.setEnabled(false);
        btContract.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btContractActionPerformed(evt);
            }
        });
        jPanel6.add(btContract);

        btTransactions.setText("Перечисления");
        btTransactions.setEnabled(false);
        btTransactions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTransactionsActionPerformed(evt);
            }
        });
        jPanel6.add(btTransactions);

        btRemove.setText(" Удалить услугу ");
        btRemove.setEnabled(false);
        btRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoveActionPerformed(evt);
            }
        });
        jPanel6.add(btRemove);

        btAdd.setText("Назначить услугу");
        btAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddActionPerformed(evt);
            }
        });
        jPanel6.add(btAdd);

        add(jPanel6, java.awt.BorderLayout.SOUTH);

        jScrollPane1.setViewportView(tabSerRenList);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void btTransactionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTransactionsActionPerformed
        if (tabSerRenList.getSelectedRowCount() > 0) {
            try {
                SerRenLocal service = serRenList.get(tabSerRenList.getSelectedRowSorted());
                DialogTransactionList dialog = new DialogTransactionList(MainWindow.mainWindow, service);
                dialog.setVisible(true);
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
        } else {
            MessageBox.showWarning(MessageBox.W_SERVICE_NOT_SELECT);
        }
    }//GEN-LAST:event_btTransactionsActionPerformed

    private void btContractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btContractActionPerformed
        if (tabSerRenList.getSelectedRowCount() > 0) {
            try {
                SerRenLocal service = serRenList.get(tabSerRenList.getSelectedRowSorted());
                ContractLocal c = service.getPolisData().getContract();
                if (c != null) {
                    PanelContractInfo panel = new PanelContractInfo(getContainer(), c);
                    getContainer().addNewPage(panel, this);
                }
            } catch (PageException ex) {
                MessageBox.showException(ex);
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
        } else {
            MessageBox.showWarning(MessageBox.W_SERVICE_NOT_SELECT);
        }
    }//GEN-LAST:event_btContractActionPerformed

    /**
     * оказываем услугу
     * @param evt
     */
    private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
        try {
            DialogNewSerRen dlg = new DialogNewSerRen(MainWindow.mainWindow, client, getAuditManager());
            dlg.setVisible(true);
            if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
                ArrayList<SerRenLocal> list = dlg.getNewSerrenList();
                for (int i = 0; i < list.size(); i++) {
                    list.get(i).addAuditListener(getAuditManager());
                    serRenList.add(list.get(i));
                }
                tabSerRenList.setModel(new TableModelSerRenList(serRenList));
            }
        } catch (Exception ex) {
            MessageBox.showExceptionOnly(ex);
        }
    }//GEN-LAST:event_btAddActionPerformed

    private void btRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoveActionPerformed
        int pos = tabSerRenList.getSelectedRowSorted();
        if (pos >= 0) {
            SerRenLocal sr = serRenList.get(pos);

            /**Удаляемый объект услуга и она в пакете*/
            boolean serRenInPacket = false;
            try {
                serRenInPacket = sr.getPacketServiceID() != 0;
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
                return;
            }

            if (serRenInPacket) {
                if (MessageBox.showConfirmYesNo(MessageBox.C_DEL_SERV_FROM_PACK) != MessageBox.ANSWER_YES) {
                    return;
                }
            }

            try {
                sr.removeAndBreakPacket();
                serRenList.remove(pos);
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
            tabSerRenList.setModel(new TableModelSerRenList(serRenList));
        }
    }//GEN-LAST:event_btRemoveActionPerformed

    private void btReloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btReloadActionPerformed
        try {
            reloadTable();
        } catch (ClipsException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btReloadActionPerformed

    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelSerRenList.COL_PACKET,    3);
    state.setPreferredWidth(TableModelSerRenList.COL_SERVICE,    18);
    state.setPreferredWidth(TableModelSerRenList.COL_DIRECTED,    15);
    state.setPreferredWidth(TableModelSerRenList.COL_RENDERED,    10);
    state.setPreferredWidth(TableModelSerRenList.COL_PRICE,      6);
    state.setPreferredWidth(TableModelSerRenList.COL_MONEY,      6);
    state.setPreferredWidth(TableModelSerRenList.COL_DISCOUNT,    5);
    state.setPreferredWidth(TableModelSerRenList.COL_REST,      8);
    state.setPreferredWidth(TableModelSerRenList.COL_PAY,      6);
    state.setPreferredWidth(TableModelSerRenList.COL_STT,      3);
      StateSaver.setDefaultState(this, tabSerRenList, state);
       
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAdd;
    private javax.swing.JButton btContract;
    private javax.swing.JButton btReload;
    private javax.swing.JButton btRemove;
    private javax.swing.JButton btTransactions;
    private javax.swing.JComboBox cbContract;
    private org.infotechservice.ICalendar.components.ICDateChooser dateFrom;
    private org.infotechservice.ICalendar.components.ICDateChooser dateTo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private cli_fmw.utils.sorted_table.SortedTable tabSerRenList;
    // End of variables declaration//GEN-END:variables

    @Override
    public String getPageTitle() {
        return "Список услуг: " + client.toString();
    }

    @Override
    public boolean readyForPrint() {
        return true;
    }

    @Override
    public void print() {
        if (readyForPrint()) {
            HashMap<String, Object> data = new LinkedHashMap<String, Object>();                       
            String title = "Список услуг пациента";
            if (mode == MODE_BY_PERIOD) {
                data.put("dateFrom", "Дата с: " + Converter.dateToString(dateFrom.getDate())
                        + "   по: " + Converter.dateToString(dateTo.getDate()));
                title += " по временному фильтру";
            }
            if (mode == MODE_NOT_IN_DISEASE) {
                title += ", вне заболеваний";
            }
            data.put("client", "Пациент: " + client.toString());
            TableReportOptions ops = new TableReportOptions(TableReportOptions.PageOrentation.horizontal);
            PrintCreators.createGeneratedReport(title, ops, data.entrySet(), null, tabSerRenList.getModel(), getClass());
        }
    }

    @Override
    public DelegateLine2 getDelegate() {
        return client;
    }


    private Object[] loadContractList() throws ClipsException {
        ContractFactoryLocal cf = new ContractFactoryLocal(getAuditManager());
        ContractFilter filter = new ContractFilter();
        filter.index = "";
        filter.enterpriseId = -1;
        filter.onlyOpen = true;
        filter.lpuID = UserInfo.get().getCollaborator().getLpu().getID();
        ArrayList list = cf.findContractList(filter);
        for (int i = 0; i < list.size(); i++) {
            ContractLocal c = (ContractLocal) list.get(i);
            if (contract != null && contract.getID() == c.getID()) {
                contract = c;
            }
        }
        list.add(0, "Любой");
        return list.toArray();
    }

}
TOP

Related Classes of clips.service.PanelSerRenList

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.