Package clips.analysis.takeSample

Source Code of clips.analysis.takeSample.DialogTakeSample

/*
* DialogClientSampling.java
*
* Created on 21 Январь 2008 г., 17:54
*/
package clips.analysis.takeSample;

import clips.delegate.doctor.checkup.CheckupLocal;
import clips.delegate.doctor.checkup.CheckupXMLData;
import cli_fmw.delegate.utils.TimeLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ModalDialog;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageException;
import cli_fmw.main.audit.AuditManager;
import clips.doctor.checkup.CheckUpTableCellRenderer;
import clips.doctor.contraindication.PanelContraindicationList;
import cli_fmw.utils.EmptyDialog;
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 java.awt.Dimension;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import javax.swing.ListSelectionModel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import framework.utils.Converter;

/**
*
* @author  ViP
*/
public class DialogTakeSample extends ModalDialog implements PageContainer {

    private CheckupLocal checkUp;
    private CheckupXMLData xml;
    private boolean isProbeSeparated;
    private boolean isEditable;
    private TableModelTakeSample tableModel;

    /** Creates new form DialogClientSampling */
    public DialogTakeSample(Frame owner, CheckupLocal checkUp, AuditManager am) throws ClipsException {
        super(owner, "Взятие проб", am);
        initComponents();
        //jTable1.setModel(new DefaultTableModel(0, TableModelTakeSample.COLCOUNT));
        if (checkUp.getSerrenLocal().getPolisData().getClient(am).getContraindicationList().size() > 0) {
            panelContraindications.setVisible(true);
        } else {
            panelContraindications.setVisible(false);
        }
        this.checkUp = checkUp;
        isEditable = checkUp.canModify();
        xml = this.checkUp.getCheckupXMLData();

        Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle dlgSize = this.getBounds();
        this.setLocation((scrSize.width - dlgSize.width) / 2, (scrSize.height -
                dlgSize.height) / 2);
        isProbeSeparated = xml.getProbeNumberSet().size() > 1;
        setScreenFields();
        refreshTable();
        tfProbeNumber.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent e) {
                valueChanged();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                valueChanged();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                valueChanged();
            }
           
            private void valueChanged() {
                if (!isProbeSeparated) {
                    ArrayList<String> probeList = xml.getProbeList();
                    for (int i = 0; i < probeList.size(); i++) {
                        String probeID = probeList.get(i);
                        if (xml.isProbeNeed(probeID)) {
                            xml.setProbeNumber(probeID, tfProbeNumber.getText());
                        }
                    }
                    tableModel.setProbeSeparated(isProbeSeparated);
                    jTable1.updateUI();
                    setEnabledComponents();
                }
            }
        });
    resizeColumn();
    StateSaver.attachTo(this);
    }

    private void setEnabledComponents() {
        cbProbeSeparated.setEnabled(isEditable);
        //Пробы
        if (isProbeSeparated) {
            tfProbeNumber.setEnabled(false);
        } else {
            tfProbeNumber.setEnabled(true && isEditable);
        }
        btOK.setEnabled(xml.isDirty());
    }
   
    private void setScreenFields() throws ClipsException {
        labFIO.setText(checkUp.getSerrenLocal().getPolisData().getClient(getAuditManager()).getFIO());
        labAnalyseType.setText(checkUp.getType().getTitle());
        //по ссылке идем на услугу анализ, на связанную услугу забор
        //биоматериала, берем дату оказания услуги
        //описание услуги
        Date workingLifeDate = checkUp.getWorkingLifeDate();
        if (workingLifeDate != null) {
            labWorkingLife.setText(Converter.dateToString(workingLifeDate));
        } else {
            labWorkingLife.setText("...");
        }
        String description = checkUp.getType().getDescription();
        if (description != null) {
            taDescription.setText(description);
            taDescription.setCaretPosition(0);
        } else {
            taDescription.setText("Без описания");
        }
       
        //Пробы
        if (isProbeSeparated) {
            cbProbeSeparated.setSelected(true);
            tfProbeNumber.setText("");
        } else {
            cbProbeSeparated.setSelected(false);
            HashSet<String> s = xml.getProbeNumberSet();
            if (s.size() == 0) {
                tfProbeNumber.setText("");
            } else {
                tfProbeNumber.setText(s.iterator().next());
            }
        }
        setEnabledComponents();
    }

    private void refreshTable() throws ClipsException {
        if (tableModel == null) {
            tableModel = new TableModelTakeSample(xml, isEditable);
        }
        tableModel.setProbeSeparated(isProbeSeparated);
        jTable1.setModel(tableModel);
        tableModel.addTableModelListener(new TableModelListener() {
            @Override
            public void tableChanged(TableModelEvent e) {
                setEnabledComponents();
            }
        });
        jTable1.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        jTable1.setDefaultRenderer(Object.class, new CheckUpTableCellRenderer());
    }

    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelTakeSample.COL_PROBETITLE,    2);
    state.setPreferredWidth(TableModelTakeSample.COL_ISNEED,      1);
    state.setPreferredWidth(TableModelTakeSample.COL_PROBENUM,      1);
      StateSaver.setDefaultState(this, jTable1, state);
    }

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

        jPanel5 = new javax.swing.JPanel();
        panelFIO = new javax.swing.JPanel();
        labFIO = new javax.swing.JLabel();
        panelAnalyseType = new javax.swing.JPanel();
        labAnalyseType = new javax.swing.JLabel();
        panelWorkingLife = new javax.swing.JPanel();
        labWorkingLife = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        tfProbeNumber = new javax.swing.JTextField();
        cbProbeSeparated = new javax.swing.JCheckBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        taDescription = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new cli_fmw.utils.sorted_table.SortedTable();
        jPanel1 = new javax.swing.JPanel();
        panelOkCancel = new javax.swing.JPanel();
        btOK = new javax.swing.JButton();
        btCancel = new javax.swing.JButton();
        panelContraindications = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        btcontraindications = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Взятие проб");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        panelFIO.setBorder(javax.swing.BorderFactory.createTitledBorder("ФИО"));
        panelFIO.setLayout(new java.awt.GridLayout(1, 0));

        labFIO.setText("...");
        panelFIO.add(labFIO);

        panelAnalyseType.setBorder(javax.swing.BorderFactory.createTitledBorder("Тип анализа"));
        panelAnalyseType.setLayout(new java.awt.GridLayout(1, 0));

        labAnalyseType.setText("...");
        panelAnalyseType.add(labAnalyseType);

        panelWorkingLife.setBorder(javax.swing.BorderFactory.createTitledBorder("Годен до"));
        panelWorkingLife.setLayout(new java.awt.GridLayout(1, 0));

        labWorkingLife.setText("...");
        panelWorkingLife.add(labWorkingLife);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Номер пробы"));
        jPanel2.setLayout(new java.awt.BorderLayout(5, 0));
        jPanel2.add(tfProbeNumber, java.awt.BorderLayout.CENTER);

        cbProbeSeparated.setText("Раздельные пробы");
        cbProbeSeparated.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbProbeSeparatedActionPerformed(evt);
            }
        });
        jPanel2.add(cbProbeSeparated, java.awt.BorderLayout.EAST);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelFIO, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                    .addComponent(panelAnalyseType, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                    .addComponent(panelWorkingLife, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(panelFIO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelAnalyseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelWorkingLife, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder("Описание"));

        taDescription.setEditable(false);
        jScrollPane2.setViewportView(taDescription);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Пробы"));
        jPanel3.setLayout(new java.awt.CardLayout());

        jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jScrollPane1ComponentResized(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel3.add(jScrollPane1, "card2");

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

        btOK.setText("Записать");
        btOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btOKActionPerformed(evt);
            }
        });

        btCancel.setText("Отменить");
        btCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelOkCancelLayout = new javax.swing.GroupLayout(panelOkCancel);
        panelOkCancel.setLayout(panelOkCancelLayout);
        panelOkCancelLayout.setHorizontalGroup(
            panelOkCancelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelOkCancelLayout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addComponent(btOK)
                .addGap(5, 5, 5)
                .addComponent(btCancel))
        );

        panelOkCancelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOK});

        panelOkCancelLayout.setVerticalGroup(
            panelOkCancelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelOkCancelLayout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addGroup(panelOkCancelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btOK)
                    .addComponent(btCancel)))
        );

        jPanel1.add(panelOkCancel, java.awt.BorderLayout.EAST);

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 16));
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("У пациента имеются непереносимости веществ");
        panelContraindications.add(jLabel1);

        btcontraindications.setText("Посмотреть");
        btcontraindications.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btcontraindicationsActionPerformed(evt);
            }
        });
        panelContraindications.add(btcontraindications);

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

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 502, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
        checkUp.restore();
        this.dispose();
    }//GEN-LAST:event_btCancelActionPerformed

    private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed
        //Завершаем редактирование текущей ячейки таблицы
        if (jTable1.getCellEditor() != null) {
            jTable1.getCellEditor().stopCellEditing();
        }

        //проверяем все ли пробы были сделаны
        boolean allProbes = true;
        ArrayList<String> probelist = xml.getProbeList();
        for (int i = 0; i < probelist.size(); i++) {
            if (xml.isProbeNeed(probelist.get(i)) && xml.getProbeNumber(probelist.get(i)).trim().isEmpty()) {
                allProbes = false;
            }
        }
        if (!allProbes) {
            if (MessageBox.showConfirmYesNo(MessageBox.C_PROBE_NOT_ALL) != MessageBox.ANSWER_OK) {
                return;
            }
        }

        try {
            checkUp.setCheckupXMLData(xml);
            if (checkUp.isDirty()) {
                Date date = TimeLocal.getCurrentTime().getTime();
                checkUp.setDate(date);
                checkUp.save1();
            }
            this.dispose();
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
            checkUp.restore();
        }
    }//GEN-LAST:event_btOKActionPerformed

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        if (checkUp != null){
            checkUp.restore();
        }
}//GEN-LAST:event_formWindowClosed

private void btcontraindicationsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btcontraindicationsActionPerformed
        try {
            EmptyDialog dialog = new EmptyDialog(this, "Непереносимость", getAuditManager());
            PanelContraindicationList panel = new PanelContraindicationList(dialog, checkUp.getSerrenLocal().getPolisData().getClient(getAuditManager()));
            dialog.addNewPage(panel, null);
                        dialog.setVisible(true);                                                  
        } catch (ClipsException ex) {
            ex.printStackTrace();
        }
}
/*
            dialog.setVisible(true);//GEN-LAST:event_btcontraindicationsActionPerformed
*/
private void jScrollPane1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jScrollPane1ComponentResized

}//GEN-LAST:event_jScrollPane1ComponentResized

private void cbProbeSeparatedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProbeSeparatedActionPerformed
    try {
        if (jTable1.getCellEditor() != null) {
            jTable1.getCellEditor().stopCellEditing();
        }
        if (cbProbeSeparated.isSelected()) {
            isProbeSeparated = true;
            tableModel.setProbeSeparated(isProbeSeparated);
            refreshTable();
            setScreenFields();
        } else {
            isProbeSeparated = false;
            tableModel.setProbeSeparated(isProbeSeparated);
            refreshTable();
            setScreenFields();
        }
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_cbProbeSeparatedActionPerformed

    @Override
    public int getDlgResult() {
        return DLG_OK;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancel;
    private javax.swing.JButton btOK;
    private javax.swing.JButton btcontraindications;
    private javax.swing.JCheckBox cbProbeSeparated;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private cli_fmw.utils.sorted_table.SortedTable jTable1;
    private javax.swing.JLabel labAnalyseType;
    private javax.swing.JLabel labFIO;
    private javax.swing.JLabel labWorkingLife;
    private javax.swing.JPanel panelAnalyseType;
    private javax.swing.JPanel panelContraindications;
    private javax.swing.JPanel panelFIO;
    private javax.swing.JPanel panelOkCancel;
    private javax.swing.JPanel panelWorkingLife;
    private javax.swing.JTextArea taDescription;
    private javax.swing.JTextField tfProbeNumber;
    // End of variables declaration//GEN-END:variables
    @Override
    public PageGeneric addNewPage(PageGeneric pageToAdd, PageGeneric afterPage) throws PageException {
        return pageToAdd;
    }

    @Override
    public void removePage(PageGeneric page, boolean forced) throws PageException {
    }

    @Override
    public void activatePage(PageGeneric page) throws PageException {
    }

    @Override
    public PageGeneric getActivePage() {
        return null;
    }

    @Override
    public void contentStateChanged() {
    }

    @Override
    public int getPageCount() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public PageGeneric getPage(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
TOP

Related Classes of clips.analysis.takeSample.DialogTakeSample

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.