Package clips.doctor.prescription

Source Code of clips.doctor.prescription.PanelPrescription

/*
* PanelPrescription.java
*
* Created on 3 Март 2008 г., 17:34
*/
package clips.doctor.prescription;

import cli_fmw.utils.SelectorEditableExceptional;
import clips.delegate.client.ClientLocal;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.directory.complex.DirectoryVidal;
import clips.delegate.directory.complex.DirectoryVidalItem;
import clips.delegate.directory.filtered.DirectoryMatter;
import clips.delegate.directory.filtered.DirectoryMatterItem;
import clips.delegate.directory.simple.takeDrug.DirectoryTakeDrugItem;
import clips.delegate.doctor.contraindication.ContraindicationLocal;
import clips.delegate.doctor.prescription.PrescriptionItemData;
import clips.delegate.doctor.prescription.PrescriptionLocal;
import cli_fmw.delegate.DelegateLine2;
import clips.directory.DialogDirectoryVidal;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageException;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.Printable;
import cli_fmw.report.CombinedReportCreator;
import cli_fmw.report.CombinedReportOptions;
import cli_fmw.report.PageOptions.PageOrentation;
import cli_fmw.utils.Selector;
import cli_fmw.utils.SelectorEditable;
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.delegate.directory.simple.takeDrug.DirectoryTakeDrug;
import clips.delegate.service.SerRenLocal;
import clips.doctor.PanelEMC;
import framework.utils.Converter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;

/**
*Панель для отображения рецепта (список PrescriptionItems)
* @author  lacoste
*/
public class PanelPrescription extends PageGeneric implements Persistentable, Printable {

    private PrescriptionLocal prescriptionLocal;
    private SelectorEditable<PrescriptionItemData> prescriptionItems;
    private JComboBox boxTakeDrug;
    private DirectoryMatter matterDirectory;
    private ArrayList<DirectoryMatterItem> matters = new ArrayList<DirectoryMatterItem>();
    ClientLocal client;

    /** Creates new form PanelPrescription
     * @param container
     * @param pl
     * @throws ClipsException
     */
    public PanelPrescription(PageContainer container, PrescriptionLocal pl, ClientLocal client) throws ClipsException {
        super(container);
        initComponents();
        this.client = client;
       
        this.prescriptionLocal = pl;
        prescriptionItems = prescriptionLocal.getPrescriptionItemList();
       
        matterDirectory = DirectoryLocator.getDirectory(DirectoryMatter.class);
       
        boxTakeDrug = new JComboBox();
        DirectoryTakeDrug directory = DirectoryLocator.getDirectory(DirectoryTakeDrug.class);
        SelectorEditableExceptional<DirectoryTakeDrugItem> items = directory.getItems();
        for (int i = 0; i < items.size(); i++) {
            boxTakeDrug.addItem(items.get(i));
        }
        formClientMatterList();
        setScreenFields();
    resizeColumn();
    StateSaver.attachTo(this);
    }

    public void setScreenFields() throws ClipsException {
        chooserDate.setDate(prescriptionLocal.getDate());
        refreshTable();
        setEnableComponents();
    }

    public void setEnableComponents() {
        chooserDate.setEnabled(false);
    }

    private void formClientMatterList() throws ClipsException {
        ArrayList<ContraindicationLocal> contraindications =
                (ArrayList<ContraindicationLocal>) client.getContraindicationList();
        for (int i = 0; i < contraindications.size(); i++) {
            matters.add(contraindications.get(i).getMatter());
        }
    }
   
    private void refreshTable() throws ClipsException {
        tablePrescription.setModel(prescriptionLocal.getItemsTableModel());
        tablePrescription.setDefaultRenderer(Object.class, new TableCellRendererPrescription(client));
        tablePrescription.getColumnModel().getColumn(TableModelPrescription.COL_TAKE_DRUG).setCellEditor(new DefaultCellEditor(boxTakeDrug));
        //tablePrescription.getColumnModel().getColumn(TableModelPrescription.COL_VIDAL).setCellEditor(new CellEditorPrescriptionItems());
    }

    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelPrescription.COL_VIDAL,    3);
    state.setPreferredWidth(TableModelPrescription.COL_TAKE_DRUG,  3);
    state.setPreferredWidth(TableModelPrescription.COL_DESC,    4);
      StateSaver.setDefaultState(this, tablePrescription, state);
    }

    private boolean isFieldsOK() throws ClipsException {
        for (int i = 0; i < prescriptionItems.size(); i++) {
            PrescriptionItemData itemData = prescriptionItems.get(i);
            if (itemData.getTakeDrug().getID() == 0 || itemData.getVidal().getID() == 0) {
                return false;
            }
        }
        return prescriptionLocal.getPrescriptionItemList().size() != 0;
    }
   
    /** 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() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablePrescription = new cli_fmw.utils.sorted_table.SortedTable();
        jPanel1 = new javax.swing.JPanel();
        btClassification = new javax.swing.JButton();
        btAdd = new javax.swing.JButton();
        btDel = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        chooserDate = new org.infotechservice.ICalendar.components.ICDateChooser();

        jMenuItem1.setText("Распечатать рецепт");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(jMenuItem1);

        jPanel3.setLayout(new java.awt.BorderLayout(5, 5));

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

        jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);

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

        btClassification.setText("Классификаторы");
        btClassification.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btClassificationActionPerformed(evt);
            }
        });
        jPanel1.add(btClassification);

        btAdd.setText("Добавить лекарство");
        btAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddActionPerformed(evt);
            }
        });
        jPanel1.add(btAdd);

        btDel.setText("Удалить лекарство");
        btDel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDelActionPerformed(evt);
            }
        });
        jPanel1.add(btDel);

        jPanel3.add(jPanel1, java.awt.BorderLayout.PAGE_END);

        jPanel2.setLayout(new java.awt.BorderLayout(5, 5));

        jLabel1.setText("Дата выписки:");
        jPanel2.add(jLabel1, java.awt.BorderLayout.WEST);

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

        chooserDate.setEnabled(false);
        jPanel4.add(chooserDate, java.awt.BorderLayout.WEST);

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

        jPanel3.add(jPanel2, java.awt.BorderLayout.NORTH);

        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()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 667, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btClassificationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClassificationActionPerformed
        try {
            DialogClassificators dialog = new DialogClassificators(MainWindow.mainWindow, getAuditManager());
            dialog.setVisible(true);
            if (dialog.getDlgResult() == ModalDialog.DLG_OK) {
                boolean badVidal = false;
                DirectoryVidalItem vidal = dialog.getVidal();
                Selector<DirectoryMatterItem> mattersByVidal = matterDirectory.getFilteredItems(vidal);
                for (int i = 0; i < mattersByVidal.size(); i++) {
                    if (matters.contains(mattersByVidal.get(i))) {
                        badVidal = true;
                        break;
                    }
                }
                if (badVidal && MessageBox.showConfirmYesNo(MessageBox.C_BAD_VIDAL) != MessageBox.ANSWER_YES) {
                    return;
                }
                PrescriptionItemData item = new PrescriptionItemData(prescriptionLocal);
                item.setVidal(vidal);
                item.setDescription("");
                prescriptionLocal.getPrescriptionItemList().append(item);
            }
            refreshTable();
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }//GEN-LAST:event_btClassificationActionPerformed

    private void btDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDelActionPerformed
        try {
            if (tablePrescription.getSelectedRowCount() == 0) {
                return;
            }           
            if (MessageBox.showConfirmYesNo(MessageBox.C_DEL_DRUG) ==
                    MessageBox.ANSWER_YES) {
                int[] selRows = tablePrescription.getSelectedRowsSorted();
                for (int i = selRows.length - 1; i > -1; i--) {
                    prescriptionLocal.getPrescriptionItemList().remove(selRows[i]);
                }
                refreshTable();
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }

    }//GEN-LAST:event_btDelActionPerformed

private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
        try {
            DirectoryVidal directory = DirectoryLocator.getDirectory(DirectoryVidal.class, false);
            DialogDirectoryVidal dialog = new DialogDirectoryVidal(MainWindow.mainWindow, directory, "");
            dialog.setVisible(true);
            if (dialog.getDlgResult() == ModalDialog.DLG_OK) {
                boolean badVidal = false;
                DirectoryVidalItem vidal = dialog.getSelectedItem();
                if (vidal != null) {
                    Selector<DirectoryMatterItem> mattersByVidal = matterDirectory.getFilteredItems(vidal);
                    for (int i = 0; i < mattersByVidal.size(); i++) {
                        if (matters.contains(mattersByVidal.get(i))) {
                            badVidal = true;
                            break;
                        }
                    }

                    if (badVidal && MessageBox.showConfirmYesNo(MessageBox.C_BAD_VIDAL) != MessageBox.ANSWER_YES) {
                        return;
                    }
                    PrescriptionItemData item = new PrescriptionItemData(prescriptionLocal);
                    item.setVidal(vidal);
                    item.setDescription("");
                    prescriptionLocal.getPrescriptionItemList().append(item);
                }
            }
            refreshTable();
        } catch (ClipsException ex) {
            ex.printStackTrace();
        }
}//GEN-LAST:event_btAddActionPerformed

private void tablePrescriptionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablePrescriptionMouseClicked
    if (evt.getButton() == MouseEvent.BUTTON3 && tablePrescription.getSelectedRowCount() > 0){
        jPopupMenu1.show(tablePrescription, evt.getX(), evt.getY());       
    }
}//GEN-LAST:event_tablePrescriptionMouseClicked

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    try {
        int k = tablePrescription.getSelectedRowSorted();
        PrescriptionItemData itemData = prescriptionItems.get(k);
        prescriptionLocal.itemPrint(itemData);
    } catch (ClipsException ex) {
        MessageBox.showExceptionOnly(ex);
    }
}//GEN-LAST:event_jMenuItem1ActionPerformed

    @Override
    public String getPageTitle() {
        return "Назначения";
    }

    public String getPageIcon() {
        return null;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAdd;
    private javax.swing.JButton btClassification;
    private javax.swing.JButton btDel;
    private org.infotechservice.ICalendar.components.ICDateChooser chooserDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private cli_fmw.utils.sorted_table.SortedTable tablePrescription;
    // End of variables declaration//GEN-END:variables
   
    @Override
    public boolean isDirty() {
        return prescriptionLocal == null ? false : prescriptionLocal.isDirty();
    }

    @Override
    public void save() throws ClipsException {
        if (isFieldsOK()) {
            prescriptionLocal.save1();
        } else {
            throw new ClipsException("Не заполнены необходимые поля");
        }
    }

    @Override
    public void restore() {
        if (prescriptionLocal.isNewlyCreated()) {
            try {
                prescriptionLocal = null;
                getContainer().removePage(this, true);
            } catch (PageException ex) {
                MessageBox.showException(ex);
            }
        } else {
            try {
                prescriptionLocal.restore();
                setScreenFields();
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
        }
    }

    @Override
    public boolean readyForPrint() {
        return !isDirty();
    }

    @Override
    public void print() {
        try {
            if (readyForPrint()) {
                CombinedReportCreator parCreator = PrintCreators.createCombinedReportHeader(getClass());
                prescriptionLocal.print(parCreator);
                parCreator.finish();
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

    @Override
    public DelegateLine2 getDelegate() {
        return prescriptionLocal;
    }
}
TOP

Related Classes of clips.doctor.prescription.PanelPrescription

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.