Package clips.doctor.medexam

Source Code of clips.doctor.medexam.PanelMedexamEdit

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

import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.client.ClientLocal;
import cli_fmw.main.ClipsException;
import clips.delegate.doctor.DiseaseLocal;
import cli_fmw.main.PageContainer;
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.report.ReporterFactory;
import cli_fmw.report.panels.model.delegate.DirectoryComboBoxModel;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.delegate.directory.complex.DirectoryCollaboratorFunctionsItem;
import clips.delegate.directory.simple.profcheckupResult.DirectoryProfcheckupResult;
import clips.delegate.directory.simple.profcheckupResult.DirectoryProfcheckupResultItem;
import clips.delegate.doctor.medexam.MedexamLocal;
import clips.login.UserInfo;
import framework.utils.Converter;
import java.util.ArrayList;
import javax.swing.DefaultCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

/**
* Панель просмотра и добавления услуг клиента работником регистратуры. Содержит
* таблицу услуг. После создания панели необходимо дать панели
* клиента методом setClient(ClientLocal client)
* @author  vip
*/
public class PanelMedexamEdit extends PageGeneric implements Persistentable, Printable {
    private ClientLocal client;
    private DiseaseLocal disease;      //Может быть null, нужен только если отображается список услуг из заболевания
    private MedexamLocal medexamLocal;
    private TableModelMedexamResult model;
    private DirectoryProfcheckupResult dirPR;
  /**
   *
   * @param container
   * @param client
   * @param medexamLocal
   * @throws cli_fmw.main.ClipsException
   */
  public PanelMedexamEdit(PageContainer container, ClientLocal client, MedexamLocal medexamLocal) throws ClipsException {
        super(container);
        initComponents();

        //Выставление режима
        //выставление клиента и заболевания
        this.client = client;
        this.medexamLocal = medexamLocal;
        this.disease = medexamLocal.getDiseaseLocal();
        dirPR = DirectoryLocator.getDirectory(DirectoryProfcheckupResult.class);
        setScreenFields();
        reloadTable();
        new DirectoryComboBoxModel<MedexamLocal, DirectoryProfcheckupResultItem>(cbResult, dirPR, medexamLocal) {

            @Override
            public DirectoryProfcheckupResultItem getSelectedDirectoryItem() throws ClipsException {
                return getObject().getFinalResult();
            }

            @Override
            public void setSelectedDirectoryItem(DirectoryProfcheckupResultItem item) throws ClipsException {
                getObject().setFinalResult(item);
            }

            @Override
            public boolean isEnabled() {
                try {
                    return getObject().canModify() || UserInfo.get().isSuperUser();
                } catch (ClipsException ex) {
                    return false;
                }
            }

        };
    resizeColumn();
    StateSaver.attachTo(this);
    }

    private void setScreenFields() throws ClipsException {
        tfCollab.setText(disease.getCollaborator().toString());
        tfDate.setText(Converter.dateToString(disease.getCreated()));
    }
    /**
     * Выставляет режим панели ( все по периоду или только назначенные)
     * Метод должен быть вызван обязательно до setClient(ClientLocal client)
     * @param mode
     */
    private void reloadTable() throws ClipsException {
        if (model != null) {
            medexamLocal.removeContentStateListener(model);
        }
        model = new TableModelMedexamResult(medexamLocal);
        model.addTableModelListener(jTable);
        jTable.setModel(model);
        DefaultComboBoxModel modelTypes = new DefaultComboBoxModel(dirPR.toArray());
        JComboBox comboPR = new JComboBox(modelTypes);
        jTable.getColumnModel().getColumn(TableModelMedexamResult.COL_RESULT).setCellEditor(new DefaultCellEditor(comboPR));
    }

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

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable = new cli_fmw.utils.sorted_table.SortedTable();
        jPanel6 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        tfCollab = new javax.swing.JTextField();
        tfDate = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        cbResult = new javax.swing.JComboBox();

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

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Результаты"));
        jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jScrollPane1ComponentResized(evt);
            }
        });

        jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_NEXT_COLUMN);
        jScrollPane1.setViewportView(jTable);

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

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

        jLabel2.setText("Сотрудник");
        jPanel1.add(jLabel2);

        jLabel3.setText("Дата");
        jPanel1.add(jLabel3);

        jPanel6.add(jPanel1, java.awt.BorderLayout.WEST);

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

        tfCollab.setEditable(false);
        tfCollab.setText("Сотрудник");
        jPanel2.add(tfCollab);

        tfDate.setEditable(false);
        tfDate.setText("Дата");
        jPanel2.add(tfDate);

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

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

        jLabel4.setText("Итог");
        jPanel3.add(jLabel4, java.awt.BorderLayout.WEST);

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

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 395, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(168, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 390, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents


private void jScrollPane1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jScrollPane1ComponentResized

}//GEN-LAST:event_jScrollPane1ComponentResized
   
    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelMedexamResult.COL_SERVICE,  40);
    state.setPreferredWidth(TableModelMedexamResult.COL_RENDER,    30);
    state.setPreferredWidth(TableModelMedexamResult.COL_DATE,    10);
    state.setPreferredWidth(TableModelMedexamResult.COL_RESULT,    20);
      StateSaver.setDefaultState(this, jTable, state);
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbResult;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private cli_fmw.utils.sorted_table.SortedTable jTable;
    private javax.swing.JTextField tfCollab;
    private javax.swing.JTextField tfDate;
    // End of variables declaration//GEN-END:variables

    @Override
    public String getPageTitle() {
        return "Статталон " + client.toString();
    }

    @Override
    public boolean isDirty() {
        return medexamLocal.isDirty();
    }

    @Override
    public void save() throws ClipsException {
        medexamLocal.save1();
    }

    @Override
    public void restore() {
        medexamLocal.restore();
    }

    @Override
    public boolean readyForPrint() {
        return !isDirty();
    }
       
    @Override
    public void print() {
        try {
            if (readyForPrint()) {
                DirectoryCollaboratorFunctionsItem collab = null;

                DiseaseLocal diseaseLocal = medexamLocal.getDiseaseLocal();

                ArrayList<DirectoryCollaboratorFunctionsItem> collabs = diseaseLocal.getCollabsIn();
                if (collabs.isEmpty()) {
                    JOptionPane.showMessageDialog(this, "В заболевании нет оказанных услуг");
                    return;
                }
                if (collabs.size() > 1) {
                    DirectoryCollaboratorFunctionsItem[] a = new DirectoryCollaboratorFunctionsItem[collabs.size()];
                    a = collabs.toArray(a);
                    collab =
                        (DirectoryCollaboratorFunctionsItem) JOptionPane.showInputDialog(this,
                        "В заболевании несколько ТАПов.\nВыберите сотрудника (специальность), по которому печатать ТАП.",
                        "Выберите сотрудника", JOptionPane.PLAIN_MESSAGE, null, a, null);
                    if (collab == null) {
                        return;
                    }
                }
                else {
                    collab = collabs.get(0);
                }
                CombinedReportCreator parCreator = ReporterFactory.createCombinedReporter(getClass(), 1);
                CombinedReportOptions ops = new CombinedReportOptions();
                ops.topMargin =0;
                ops.bottomMargin = 0;
                ops.leftMargin =0;
                ops.rightMargin = 0;
                ops.setPageA5();
                ops.setOrentation(PageOrentation.horizontal);
                parCreator.setUpReport(null, ops, null);

                diseaseLocal.formPrintFields(collab);
                diseaseLocal.print(parCreator);
                parCreator.finish();

            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

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

Related Classes of clips.doctor.medexam.PanelMedexamEdit

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.