Package clips.userseach

Source Code of clips.userseach.PanelUserSearch$ClientListener

/*
* PanelUserSearch.java
*
* Created on 27 Ноябрь 2007 г., 20:06
*/
package clips.userseach;

import beans.user.search.ClientFilter;
import cli_fmw.main.PageContainer;
import cli_fmw.utils.SelectorEditableExceptional;
import clips.delegate.client.ClientSearchLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.Selector;
import clips.delegate.directory.simple.sex.DirectorySexItem;
import clips.main.CardInfo;
import java.awt.Dimension;
import java.awt.Window;
import java.text.ParseException;
import javax.swing.ListSelectionModel;
import clips.delegate.client.ClientLocal;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.delegate.utils.TimeLocal;
import cli_fmw.directory.dialogs.DirectoryDialogDefault;
import cli_fmw.main.PageException;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.Printable;
import clips.service.newSerRen.DialogNewSerRen;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.sorted_table.renderer.simple.DefaultRenderer;
import cli_fmw.utils.table_config_states.SplitPaneState;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.delegate.directory.complex.DirectoryEnterprise;
import clips.delegate.directory.complex.DirectoryEnterpriseItem;
import clips.delegate.directory.simple.sex.DirectorySex;
import clips.login.UserInfo;
import clips.main.UserPanelsEnum;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import beans.UserRightsSet;
import cli_fmw.address.DialogAddressM;
import cli_fmw.address.DialogAddressM;
import cli_fmw.delegate.client.Address;
import cli_fmw.main.ContentStateListener;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PageGeneric;
import cli_fmw.report.panels.model.TextFieldModel;
import clips.Main;
import clips.delegate.client.ClientDocumentData;
import clips.delegate.config.ConfigLocal;
import clips.delegate.directory.simple.name.DirectoryName;
import clips.delegate.directory.simple.pathron.DirectoryPathron;
import clips.delegate.directory.simple.surname.DirectorySurname;
import clips.main.AppMainWindow;
import framework.beans.address.entities.AddressDetails;
import framework.beans.directory.simple.entities.Sex;
import framework.utils.Converter;
import java.awt.Frame;
import java.util.StringTokenizer;
import javax.swing.border.TitledBorder;

/**
*
* @author  Администратор
*/
public class PanelUserSearch extends PageGeneric
        implements Printable, ContentStateListener {

    public static final int MODE_FIND = 0,  MODE_SELECT = 1,  MODE_MULTISELECT = 2;
    private ArrayList<ClientLocal> clientList;
    private DirectoryEnterpriseItem enterprise;
    private DirectorySex dirSex;
    private Address address;
    private int mode = MODE_FIND;
    private String fio = "";
    private ClientFilter filter;
   
    ClientSearchLocal searchEngine;

    /**
   *
   * @param container
   * @param mode
   * @throws cli_fmw.main.ClipsException
   */
    public PanelUserSearch(PageContainer container, int mode) throws ClipsException {
        super(container);
        initComponents();
        mainTable.setModel(new TableModelUserSearch(new ArrayList<ClientLocal>()));

//        По старому
//        btEmcClient.addActionListener(new ActivatePanelAction(UserPanelsEnum.PANEL_PanelEMC, container));
//        btEditClient.addActionListener(new ActivatePanelAction(UserPanelsEnum.PANEL_PanelClientEdit, container));
//        по новому
        btEmcClient.addActionListener(MainWindow.mainWindow.getPanelListeners(UserPanelsEnum.PANEL_PanelEMC));
        btEditClient.addActionListener(MainWindow.mainWindow.getPanelListeners(UserPanelsEnum.PANEL_PanelClientEdit));

       
        searchEngine = new ClientSearchLocal(getAuditManager());
        initeDefaultPeriod();

        this.mode = mode;
        btSelectClient.setVisible(mode == MODE_SELECT || mode == MODE_MULTISELECT);
        btNewClient.setEnabled(mode == MODE_FIND);

        mainTable.getSelectionModel().addListSelectionListener(new ClientListener());
        initSexCombo();
    resizeColumn();
        tfEMCnum.setEnabled(chbEmc.isSelected());

        new TextFieldModel(editFIO) {

            @Override
            protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
                fio = text;
            }

            @Override
            protected String getModelTextChecked() throws ClipsException {
                return fio;
            }
        };

        StateSaver.setDefaultState(this, jSplitPane1, new SplitPaneState(450, SplitPaneState.OffsetType.rightOffset));
    StateSaver.attachTo(this);
    }

    /**
     * Creates new form PanelUserSearch
   * @param container
   * @throws ClipsException
   */
    public PanelUserSearch(PageContainer container) throws ClipsException {
        this(container, MODE_FIND);
    }
   
    private void initSexCombo() throws ClipsException {
        sexCombo.removeAllItems();
        dirSex = DirectoryLocator.getDirectory(DirectorySex.class);
        SelectorEditableExceptional<DirectorySexItem> it = dirSex.getItems();
        for(int i=0; i<it.size(); i++) {
            sexCombo.addItem(it.get(i));
        }
        sexCombo.setSelectedItem(dirSex.getNullItem());
    }
   
    public ClientLocal getSelectedClient() {
        if(mainTable.getSelectedRowCount() > 0) {
            return clientList.get(mainTable.getSelectedRowSorted());
        }
        return null;
    }

    public ArrayList<ClientLocal> getSelectedClientList() {
        ArrayList<ClientLocal> selectedClientList = new ArrayList<ClientLocal>();
        int[] rows = mainTable.getSelectedRowsSorted();
        for (int i = 0; i < rows.length; i++) {
            selectedClientList.add(clientList.get(rows[i]));
        }
        return selectedClientList;
    }

    /** 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() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel3 = new javax.swing.JPanel();
        btGoFind = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        labelClientInfo = new javax.swing.JLabel() {
            @Override
            public Dimension getPreferredSize() {
                Dimension d = super.getPreferredSize();
                d.width = 1;
                return d;
            }

        }
        ;
        jScrollPane1 = new javax.swing.JScrollPane();
        mainTable = new cli_fmw.utils.sorted_table.SortedTable();
        jPanel4 = new javax.swing.JPanel();
        btSelectClient = new javax.swing.JButton();
        btEditClient = new javax.swing.JButton();
        btEmcClient = new javax.swing.JButton();
        btAddService = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        btNewClient = new javax.swing.JButton();
        jPanel15 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jPanel14 = new javax.swing.JPanel();
        chbEmc = new javax.swing.JCheckBox();
        tfEMCnum = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        chbLastReception = new javax.swing.JCheckBox();
        dateFrom = new org.infotechservice.ICalendar.components.ICDateChooser();
        jLabel1 = new javax.swing.JLabel();
        dateTo = new org.infotechservice.ICalendar.components.ICDateChooser();
        rbTap = new javax.swing.JRadioButton();
        rbShedule = new javax.swing.JRadioButton();
        jPanel6 = new javax.swing.JPanel();
        chbOnReception = new javax.swing.JCheckBox();
        jPanel18 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        chbEnterprise = new javax.swing.JCheckBox();
        chbEnterpriseRecurs = new javax.swing.JCheckBox();
        jPanel17 = new javax.swing.JPanel();
        entterpriseField = new javax.swing.JTextField();
        chooseEnterprise = new javax.swing.JButton();
        jPanel13 = new javax.swing.JPanel();
        jPanel19 = new javax.swing.JPanel();
        tfAddress = new javax.swing.JTextField();
        btAddress = new javax.swing.JButton();
        chbAddress = new javax.swing.JCheckBox();
        jPanel16 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        editFIO = new javax.swing.JTextField();
        jPanel12 = new javax.swing.JPanel();
        sexCombo = new javax.swing.JComboBox();
        jPanel10 = new javax.swing.JPanel();
        btClearFilter = new javax.swing.JButton();

        buttonGroup1.add(rbTap);
        buttonGroup1.add(rbShedule);

        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        btGoFind.setText("Найти");
        btGoFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btGoFindActionPerformed(evt);
            }
        });
        jPanel3.add(btGoFind);

        jSplitPane1.setDividerLocation(400);
        jSplitPane1.setResizeWeight(0.5);

        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Информация о пациенте"));
        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setHorizontalScrollBar(null);

        labelClientInfo.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jScrollPane2.setViewportView(labelClientInfo);

        jSplitPane1.setRightComponent(jScrollPane2);

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        mainTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mainTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(mainTable);

        jSplitPane1.setLeftComponent(jScrollPane1);

        jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        btSelectClient.setText("    Выбрать    ");
        btSelectClient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSelectClientActionPerformed(evt);
            }
        });
        jPanel4.add(btSelectClient);

        btEditClient.setText("Редактировать");
        btEditClient.setEnabled(false);
        jPanel4.add(btEditClient);

        btEmcClient.setText("          ЭМК          ");
        btEmcClient.setEnabled(false);
        jPanel4.add(btEmcClient);

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

        jPanel5.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        btNewClient.setText("Регистрация нового пациента");
        btNewClient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNewClientActionPerformed(evt);
            }
        });
        jPanel5.add(btNewClient);

        jPanel15.setBorder(javax.swing.BorderFactory.createTitledBorder("Критерии поиска"));
        jPanel15.setLayout(new java.awt.BorderLayout());

        jPanel8.setLayout(new java.awt.GridLayout(5, 1, 0, 2));

        jPanel14.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        chbEmc.setText("№ электронно-медицинской карты");
        chbEmc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chbEmcActionPerformed(evt);
            }
        });
        jPanel14.add(chbEmc);

        tfEMCnum.setColumns(10);
        tfEMCnum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfEMCnumActionPerformed(evt);
            }
        });
        jPanel14.add(tfEMCnum);

        jPanel8.add(jPanel14);

        jPanel7.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        chbLastReception.setText("Последняя дата обращения: c");
        chbLastReception.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chbLastReceptionActionPerformed(evt);
            }
        });
        jPanel7.add(chbLastReception);

        dateFrom.setEnabled(false);
        jPanel7.add(dateFrom);

        jLabel1.setText("по");
        jPanel7.add(jLabel1);

        dateTo.setEnabled(false);
        jPanel7.add(dateTo);

        rbTap.setSelected(true);
        rbTap.setText("По Посещениям");
        rbTap.setEnabled(false);
        jPanel7.add(rbTap);

        rbShedule.setText("По расписанию");
        rbShedule.setEnabled(false);
        jPanel7.add(rbShedule);

        jPanel8.add(jPanel7);

        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        chbOnReception.setText("Поиск по записанным на прием");
        chbOnReception.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chbOnReceptionActionPerformed(evt);
            }
        });
        jPanel6.add(chbOnReception);

        jPanel8.add(jPanel6);

        jPanel18.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jPanel1.setLayout(new java.awt.BorderLayout(5, 0));

        chbEnterprise.setText("Место работы:");
        chbEnterprise.setPreferredSize(new java.awt.Dimension(120, 22));
        chbEnterprise.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chbEnterpriseActionPerformed(evt);
            }
        });
        jPanel1.add(chbEnterprise, java.awt.BorderLayout.WEST);

        chbEnterpriseRecurs.setText("Включая подразделения");
        chbEnterpriseRecurs.setEnabled(false);
        jPanel1.add(chbEnterpriseRecurs, java.awt.BorderLayout.EAST);

        jPanel17.setLayout(new java.awt.BorderLayout(5, 0));

        entterpriseField.setColumns(26);
        entterpriseField.setEditable(false);
        jPanel17.add(entterpriseField, java.awt.BorderLayout.CENTER);

        chooseEnterprise.setText("...");
        chooseEnterprise.setEnabled(false);
        chooseEnterprise.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chooseEnterpriseActionPerformed(evt);
            }
        });
        jPanel17.add(chooseEnterprise, java.awt.BorderLayout.EAST);

        jPanel1.add(jPanel17, java.awt.BorderLayout.CENTER);

        jPanel18.add(jPanel1);

        jPanel8.add(jPanel18);

        jPanel13.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jPanel19.setLayout(new java.awt.BorderLayout(5, 0));

        tfAddress.setColumns(42);
        tfAddress.setEditable(false);
        jPanel19.add(tfAddress, java.awt.BorderLayout.CENTER);

        btAddress.setText("...");
        btAddress.setEnabled(false);
        btAddress.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddressActionPerformed(evt);
            }
        });
        jPanel19.add(btAddress, java.awt.BorderLayout.EAST);

        chbAddress.setText("По адресу:");
        chbAddress.setPreferredSize(new java.awt.Dimension(120, 22));
        chbAddress.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chbAddressActionPerformed(evt);
            }
        });
        jPanel19.add(chbAddress, java.awt.BorderLayout.WEST);

        jPanel13.add(jPanel19);

        jPanel8.add(jPanel13);

        jPanel15.add(jPanel8, java.awt.BorderLayout.PAGE_START);

        jPanel16.setLayout(new java.awt.BorderLayout());

        jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 5));

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0), "Фамилия Имя Отчество", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP));
        jPanel9.setLayout(new java.awt.BorderLayout());

        editFIO.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        editFIO.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editFIOActionPerformed(evt);
            }
        });
        jPanel9.add(editFIO, java.awt.BorderLayout.CENTER);

        jPanel12.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0), "Пол", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP));
        jPanel12.setLayout(new java.awt.BorderLayout());

        jPanel12.add(sexCombo, java.awt.BorderLayout.CENTER);

        jPanel10.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btClearFilter.setText("Очистить фильтр");
        btClearFilter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btClearFilterActionPerformed(evt);
            }
        });
        jPanel10.add(btClearFilter, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 22, -1, -1));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, 50, Short.MAX_VALUE)
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel10, 0, 50, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel16.add(jPanel2, java.awt.BorderLayout.CENTER);

        jPanel15.add(jPanel16, java.awt.BorderLayout.SOUTH);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 791, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 791, Short.MAX_VALUE)
                    .addComponent(jPanel15, javax.swing.GroupLayout.DEFAULT_SIZE, 791, Short.MAX_VALUE)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 791, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE)
                        .addGap(141, 141, 141)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void initeDefaultPeriod() throws ClipsException {
        //set default period
        GregorianCalendar gc = TimeLocal.getCurrentTime();
        dateTo.setDate(gc.getTime());
        gc.add(GregorianCalendar.MONTH, -1);
        dateFrom.setDate(gc.getTime());
    }
    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelUserSearch.COL_FIO,    7);
    state.setPreferredWidth(TableModelUserSearch.COL_DATE,    3);
        if (Main.DEVELOPED_ON) {
            state.setPreferredWidth(TableModelUserSearch.COLCOUNT, 1);
        }
      StateSaver.setDefaultState(this, mainTable, state);
     }

    /**
     * Нажатие на кнопку "Найти клиентов"
     * @param evt
     */
    private void btGoFindActionPerformed(java.awt.event.ActionEvent evt) {                                            
        System.out.println("Search on");
        mainTable.setModel(new DefaultTableModel());
        mainTable.setDefaultRenderer(Object.class, new DefaultRenderer());
       
        filter = new ClientFilter();
        String emcNum = null;
        if (chbEmc.isSelected()){
            emcNum = tfEMCnum.getText().trim().isEmpty() ? null : tfEMCnum.getText().trim();
            if (emcNum == null){
                emcNum = "";
            }
        }
        filter.EMCnum = emcNum;

        //Парсит ФИО
        StringTokenizer tk = new StringTokenizer(fio, " ");
        if (tk.hasMoreElements()) {
            if (fio.startsWith(" ")) {
                filter.surname = null;
            } else {
                filter.surname = Converter.firstUpper(tk.nextToken().trim(), true);
            }
            if (tk.hasMoreElements()) {
                filter.name = Converter.firstUpper(tk.nextToken().trim(), true);
                if (tk.hasMoreElements()) {
                    filter.pathron = Converter.firstUpper(tk.nextToken().trim(), true);
                } else {
                    filter.pathron = null;
                }
            } else {
                filter.name = null;
            }
        } else {
            filter.surname = null;
        }
        filter.enterpriseID = (enterprise == null) ? null : enterprise.getID();
        filter.enterpTitle = (enterprise == null) ? null : enterprise.getTitle();
        filter.includeSubEnterprises = chbEnterpriseRecurs.isSelected();
        filter.inReception = chbOnReception.isSelected();
        filter.sexID = (sexCombo.getSelectedItem() == null) ?
            0 : ((DirectorySexItem)sexCombo.getSelectedItem()).getID();
       
        filter.lastComing = chbLastReception.isSelected();
        if(chbLastReception.isSelected()) {
            filter.lastComingFrom = dateFrom.getDate();
            filter.lastComingTill = dateTo.getDate();
            filter.lastComingByTap = rbTap.isSelected();
        }
        if (address != null) {
            AddressDetails ad = address.getDetails();
            filter.ad = ad.clone();
            filter.addressTitle = address.toString();
        }

        if (filter.isEmpty()) {
            jScrollPane1.setBorder(new TitledBorder(""));
            mainTable.setModel(new TableModelUserSearch(null));
            MessageBox.showWarning("Введите параметры поиска");
            contentStateChanged();
            return;
        }
        try {
            filter.collId = UserInfo.get().getCollaborator().getID();

            clientList = searchEngine.getClientList(filter);
            mainTable.setModel(new TableModelUserSearch(clientList));

            fireContainerEventStateChanged();
            if (mode == MODE_FIND || mode == MODE_SELECT) {
                mainTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            }
            if (mode == MODE_MULTISELECT) {
                mainTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            String title = "";

            if (clientList.size() == 0) {
                title = "Не найдено ни одного пациента";
            }
            else {
                title = "Найденные пациенты (отображены "
                    + clientList.size() + " из " + searchEngine.getListSize() + ")";
            }
            jScrollPane1.setBorder(new TitledBorder(title));
           
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

    @Override
    public void contentStateChanged() {
        getContainer().contentStateChanged();
    }
   
    class ClientListener implements ListSelectionListener {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            boolean selected = getSelectedClient() != null;
           
            btSelectClient.setEnabled((mode == MODE_SELECT || mode == MODE_MULTISELECT));
            btEditClient.setEnabled(selected && mode == MODE_FIND
                    && UserInfo.get().check(UserRightsSet.READ_CLIENT_PUBLIC_INFO));
            // UserInfo.getMandate().getSetOfRights();
            btEmcClient.setEnabled(selected && mode == MODE_FIND
                    && UserInfo.get().check(UserRightsSet.READ_MEDICAL_DATA));
            btAddService.setEnabled(selected && mode == MODE_FIND);
           
            fireContainerEventStateChanged();
            viewClientInfo(getSelectedClient());
        }       
    }
   
    private void viewClientInfo(ClientLocal client) {
        if (client != null) {
            try {
                labelClientInfo.setText(client.toHtml());
            } catch (ClipsException ex) {
                labelClientInfo.setText("Ошибка доступа к информации о пациенте");
            }
        } else {
            labelClientInfo.setText("");
        }
    }

    public void setFIO(String fio) {
        editFIO.setText(fio);
    }

    /**
     * Нажатие на кнопку "Создание нового клиента"
     * @param evt
     */
    private void btNewClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNewClientActionPerformed
        if (mode == MODE_FIND) {
            try {
                ClientLocal clientLocal = new ClientLocal(getAuditManager());
                CardInfo cardInfo = ((AppMainWindow) MainWindow.getMainWindow()).getCardInfo();
                if (cardInfo != null){
                    DirectorySurname surname = DirectoryLocator.getDirectory(DirectorySurname.class);
                    DirectoryName name = DirectoryLocator.getDirectory(DirectoryName.class);
                    DirectoryPathron pathron = DirectoryLocator.getDirectory(DirectoryPathron.class);
                    clientLocal.setSurname(surname.getItemFromTitle(cardInfo.surname));
                    clientLocal.setName(name.getItemFromTitle(cardInfo.name));
                    clientLocal.setPathron(pathron.getItemFromTitle(cardInfo.patron));
                    clientLocal.setBorn(cardInfo.born);
                    clientLocal.setInn(cardInfo.inn);
                    clientLocal.setSex(dirSex.getItemFromTitle(cardInfo.sex));
                    clientLocal.setSnils(cardInfo.snils);
                }
                PanelClientEdit panel = new PanelClientEdit(getContainer(), clientLocal);
                PageGeneric page = getContainer().addNewPage((PageGeneric) panel, null);
                getContainer().activatePage(page);
            } catch (PageException ex) {
                MessageBox.showException(ex);
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
        }
    }//GEN-LAST:event_btNewClientActionPerformed

    /**
     * Нажатие на кнопку "Выбор клиента"
     * Разрешено только в режиме выбора клиента из списка
     * @param evt
     */
    private void btSelectClientActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        try {
            getContainer().removePage(this, false);
        } catch (PageException ex) {
            MessageBox.showException(ex);
        }
    }                                             

    /**
     * Нажатие на кнопку "Информация о клиенте"
     * Разрешено Регистратуре и Доктору в любом режиме.
     * Вызывает диалоговое окно с информацией о клиенте.
     * @param evt
     */
  private void chooseEnterpriseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseEnterpriseActionPerformed
    try {
      DirectoryEnterprise directory = DirectoryLocator.getDirectory(DirectoryEnterprise.class, false);
      DirectoryDialogDefault dlg = new DirectoryDialogDefault(false, enterprise, "\\", directory);
      dlg.setAlwaysOnTop(true);
            dlg.setVisible(true);
      if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
        Selector items = dlg.getSelectedItems();
        enterprise =  (DirectoryEnterpriseItem) items.get(0);
//        if (enterprise.getID() == 0) {
//          chbEnterprise.setSelected(false);
//          chbEnterpriseActionPerformed(null);
//        } else {
          entterpriseField.setText(enterprise.getTitle());
                    entterpriseField.setCaretPosition(0);
          chbEnterpriseRecurs.setSelected(false);
//        }
      }
      else {
        if (enterprise == null) {
          entterpriseField.setText("");
          chbEnterprise.setSelected(false);
        }
      }
    } catch (ClipsException ex) {
      MessageBox.showException(ex);
    }
  }//GEN-LAST:event_chooseEnterpriseActionPerformed

  private void chbEnterpriseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chbEnterpriseActionPerformed
    if (!chbEnterprise.isSelected()) {
        enterprise = null;
        entterpriseField.setText("");
        chbEnterpriseRecurs.setSelected(false);
    }
    else {
        chooseEnterpriseActionPerformed(null);
    }
    chooseEnterprise.setEnabled(chbEnterprise.isSelected());
    chbEnterpriseRecurs.setEnabled(chbEnterprise.isSelected());
  }//GEN-LAST:event_chbEnterpriseActionPerformed

  private void chbLastReceptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chbLastReceptionActionPerformed
        boolean selected = chbLastReception.isSelected();
        dateFrom.setEnabled(selected);
    dateTo.setEnabled(selected);
        rbTap.setEnabled(selected);
        rbShedule.setEnabled(selected);
        if (selected) {
            chbOnReception.setSelected(false);
        }
  }//GEN-LAST:event_chbLastReceptionActionPerformed

  private void btAddServiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddServiceActionPerformed
    try {
        DialogNewSerRen dlg = new DialogNewSerRen(MainWindow.mainWindow, getSelectedClient(), getAuditManager());
        dlg.setVisible(true);
    } catch (Exception ex) {
        MessageBox.showExceptionOnly(ex);
    }
  }//GEN-LAST:event_btAddServiceActionPerformed

  private void mainTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mainTableMouseClicked
    if (evt.getClickCount() == 2) {
        if (mode == MODE_SELECT || mode == MODE_MULTISELECT) {
            btSelectClientActionPerformed(null);
        }
    }
  }//GEN-LAST:event_mainTableMouseClicked

    private void chbAddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chbAddressActionPerformed
        if (!chbAddress.isSelected()) {
        address = null;
        tfAddress.setText("");
    }
    else {
        btAddressActionPerformed(null);
    }
    btAddress.setEnabled(chbAddress.isSelected());
}//GEN-LAST:event_chbAddressActionPerformed

    private void btAddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddressActionPerformed
        try {
            Address ad;
            if (address != null) {
                ad = new Address(address.getDetails().clone());
            }
            else {
                ad = new Address(new AddressDetails());
            }
            Address addressDefault = UserInfo.get().getCollaborator().getLpu().getAddress();
            DialogAddressM dlg = new DialogAddressM((Window) getContainer(), ad, addressDefault, getAuditManager());
            dlg.setVisible(true);
            if (dlg.getDlgResult() == ModalDialog.DLG_OK){
                address = dlg.getAddress();
                tfAddress.setText(address.toString());
                tfAddress.setCaretPosition(0);
            }
            else if (address == null) {
                chbAddress.setSelected(false);
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
}//GEN-LAST:event_btAddressActionPerformed

    private void tfEMCnumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfEMCnumActionPerformed
        btGoFindActionPerformed(evt);
    }//GEN-LAST:event_tfEMCnumActionPerformed

    private void editFIOActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editFIOActionPerformed
        btGoFindActionPerformed(evt);
    }//GEN-LAST:event_editFIOActionPerformed

    private void btClearFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClearFilterActionPerformed
        sexCombo.setSelectedIndex(0);
        chbEnterprise.setSelected(false);
        chbEnterpriseActionPerformed(evt);
        chbLastReception.setSelected(false);
        chbLastReceptionActionPerformed(evt);
        chbOnReception.setSelected(false);
        chbAddress.setSelected(false);
        chbAddressActionPerformed(evt);
        editFIO.setText("");
        tfEMCnum.setText("");
        rbTap.setSelected(true);
        chbEmc.setSelected(false);
        tfEMCnum.setEnabled(false);
    }//GEN-LAST:event_btClearFilterActionPerformed

    private void chbEmcActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chbEmcActionPerformed
        tfEMCnum.setEnabled(chbEmc.isSelected());
        if (!chbEmc.isSelected()){
            tfEMCnum.setText("");
        }
}//GEN-LAST:event_chbEmcActionPerformed

    private void chbOnReceptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chbOnReceptionActionPerformed
        if (chbOnReception.isSelected()) {
            chbLastReception.setSelected(false);
        }
    }//GEN-LAST:event_chbOnReceptionActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAddService;
    private javax.swing.JButton btAddress;
    private javax.swing.JButton btClearFilter;
    private javax.swing.JButton btEditClient;
    private javax.swing.JButton btEmcClient;
    private javax.swing.JButton btGoFind;
    private javax.swing.JButton btNewClient;
    private javax.swing.JButton btSelectClient;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JCheckBox chbAddress;
    private javax.swing.JCheckBox chbEmc;
    private javax.swing.JCheckBox chbEnterprise;
    private javax.swing.JCheckBox chbEnterpriseRecurs;
    private javax.swing.JCheckBox chbLastReception;
    private javax.swing.JCheckBox chbOnReception;
    private javax.swing.JButton chooseEnterprise;
    private org.infotechservice.ICalendar.components.ICDateChooser dateFrom;
    private org.infotechservice.ICalendar.components.ICDateChooser dateTo;
    private javax.swing.JTextField editFIO;
    private javax.swing.JTextField entterpriseField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JLabel labelClientInfo;
    private cli_fmw.utils.sorted_table.SortedTable mainTable;
    private javax.swing.JRadioButton rbShedule;
    private javax.swing.JRadioButton rbTap;
    private javax.swing.JComboBox sexCombo;
    private javax.swing.JTextField tfAddress;
    private javax.swing.JTextField tfEMCnum;
    // End of variables declaration//GEN-END:variables
    @Override
    public String getPageTitle() {
        return "Поиск пациентов";
    }

    @Override
    public ClientLocal getDelegate() {
        return getSelectedClient();
    }

    @Override
    public boolean readyForPrint() {
        return filter != null && !filter.isEmpty();
    }

    @Override
    public void print() {
        if (readyForPrint()) {
           
            HashMap<String, Object> data = new LinkedHashMap<String, Object>();
            if (filter.EMCnum != null) {
                data.put("EMCnum", "По совпадению номера электронно-медицинской карты \"" + filter.EMCnum.trim() + "\"");
            }
            if (filter.lastComing) {
                String reception = "По дате последнего обращения (";
                if (filter.lastComingByTap) {
                    reception += "по посещениям)";
                }
                else {
                    reception += "по расписанию)";
                }
                data.put("lastReception", reception + " c: " + Converter.dateToString(filter.lastComingFrom)
                        + "   по: " + Converter.dateToString(filter.lastComingTill));
            }
            if (filter.enterpriseID != null && filter.enterpriseID != 0) {
                String enterp = "По месту работы: " + filter.enterpTitle;
                if (filter.includeSubEnterprises) {
                    enterp += "(включая подразделения)";
                }
                data.put("enterprise", enterp);
            }

            if (filter.addressTitle != null) {
                data.put("address", "По адресу пациента: " + filter.addressTitle);
            }

            if (filter.inReception) {
                data.put("onReception", "По записанным на прием");
            }
            String coincidence = "По совпадению ";
            boolean isCoincidence = false;
            if (filter.surname != null) {
                coincidence += "фамилии: \"" + filter.surname + "\"";
                isCoincidence = true;
            }
            if (filter.name != null) {
                coincidence += ";    имени: \"" + filter.name + "\"";
                isCoincidence = true;
            }
            if (filter.pathron != null) {
                coincidence += ";    отчества: \"" + filter.pathron + "\"";
                isCoincidence = true;
            }
            if (isCoincidence) {
                data.put("coincidence", coincidence);
            }
            if (filter.sexID != 0) {
                String sexStr = "Поиск по полу: ";
                if (filter.sexID == Sex.CLIENT_SEX_MALE) {
                    sexStr += "мужской";
                }
                else {
                    sexStr += "женский";
                }
                data.put("findBySex", sexStr);
            }
           
            String title = "Список пациентов по фильтру";
            PrintCreators.createGeneratedReport(title, null, data.entrySet(), null, mainTable.getModel(), getClass());
        }
    }

}
TOP

Related Classes of clips.userseach.PanelUserSearch$ClientListener

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.