Package clips.doctor.prescriptiondlo

Source Code of clips.doctor.prescriptiondlo.PanelPrescriptionDlo

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* PanelPrescriptionDlo.java
*
* Created on 06.12.2009, 13:44:06
*/

package clips.doctor.prescriptiondlo;

import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.CheckableDocListener;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageException;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.PrintCreators;
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.DelegateComboboxModel;
import cli_fmw.report.panels.model.delegate.DelegateTextModel;
import cli_fmw.report.panels.model.delegate.DirectoryComboBoxModel;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.delegate_models.DelegateDateModel;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.client.ClientLocal;
import clips.delegate.directory.complex.DirectoryDrugListItem;
import clips.delegate.directory.simple.financesource.DirectoryFinanceSource;
import clips.delegate.directory.simple.financesource.DirectoryFinanceSourceItem;
import clips.delegate.doctor.diagnosis.DiagnosisLocal;
import clips.delegate.doctor.prescriptiondlo.PrescriptionDloLocal;
import clips.doctor.sicklist.dialogs.SicklistDiagnosComboboxModel;
import framework.utils.FormatChecker;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Date;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;

/**
*
* @author lacoste
*/
public class PanelPrescriptionDlo extends PageGeneric implements Persistentable, Printable {

    private static Integer[] PERCENTS = new Integer[]{50, 100};
    private PrescriptionDloLocal prescription;
    private SicklistDiagnosComboboxModel diagModel;
    private PrescriptionDloComitteeComboboxModel comModel;
    private String quantityOld;
    private String quantityNew;
   
    public PanelPrescriptionDlo(PageContainer container, PrescriptionDloLocal pl, ClientLocal client) throws ClipsException {
        super(container);
        initComponents();
        this.prescription = pl;

        diagModel = new SicklistDiagnosComboboxModel(client);
    cbDiagOpen.setModel(diagModel);

        comModel = new PrescriptionDloComitteeComboboxModel(client);
    cbKek.setModel(comModel);

        tfPeriod.setText(Integer.toString(prescription.getPeriod()));
        tfPeriod.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent arg0) {
                setField(arg0.getDocument());
            }

            @Override
            public void removeUpdate(DocumentEvent arg0) {
                setField(arg0.getDocument());
            }

            @Override
            public void changedUpdate(DocumentEvent arg0) {
            }

            private void setField(Document doc) {
                try {
                    if (doc != null && doc.getText(0, doc.getLength()) != null
                            && !doc.getText(0, doc.getLength()).isEmpty()) {
                        int i = Integer.parseInt(doc.getText(0, doc.getLength()));
                        if (i >= 0) {
                            prescription.setPeriod(i);
                        }
                        else {
                            MessageBox.showWarning("Недопустимое значение");
                           
                        }
                    }
                } catch (ClipsException ex) {
                    MessageBox.showException(ex);
                } catch (BadLocationException ex) {
                    MessageBox.showException(ex);
                }
            }
        });

        new DelegateTextModel<PrescriptionDloLocal>(tfSeries, prescription) {

            @Override
            protected void setModelTextChecked(String text) throws ClipsException {
                getObject().setSeries(text);
            }

            @Override
            protected String getModelTextChecked() throws ClipsException {
                return getObject().getSeries();
            }
        };

        new DelegateTextModel<PrescriptionDloLocal>(tfNumber, prescription) {

            @Override
            protected void setModelTextChecked(String text) throws ClipsException {
                getObject().setNumber(text);
            }

            @Override
            protected String getModelTextChecked() throws ClipsException {
                return getObject().getNumber();
            }
        };

        new DelegateDateModel<PrescriptionDloLocal>(prescription, chooserDate) {

            @Override
            protected Date getDateImp() throws ClipsException {
                return getDelegate().getDate();
            }

            @Override
            protected void setDateImp(Date date) throws ClipsException {
            }
        };

        DirectoryFinanceSource finance = DirectoryLocator.getDirectory(DirectoryFinanceSource.class);
        new DirectoryComboBoxModel<PrescriptionDloLocal, DirectoryFinanceSourceItem>(cbFinanceSource, finance, prescription) {

            @Override
            public DirectoryFinanceSourceItem getSelectedDirectoryItem() throws ClipsException {
                return getObject().getFinance();
            }

            @Override
            public void setSelectedDirectoryItem(DirectoryFinanceSourceItem item) throws ClipsException {
                getObject().setFinance(item);
            }

        };

        new DelegateComboboxModel<PrescriptionDloLocal>(cbPercent, prescription, false) {

            @Override
            public Object getElementAtImp(int index) throws ClipsException {
                return PERCENTS[index];
            }

            @Override
            public int getSizeImp() throws ClipsException {
                return PERCENTS.length;
            }

            @Override
            public Object getSelectedItemImp() throws ClipsException {
                return getObject().getPercent();
            }

            @Override
            public void setSelectedItemImp(Object anItem) throws ClipsException {
                Integer percent = (Integer) anItem;
                getObject().setPercent(percent);
            }
        };

//        tfQuantity.getDocument().addDocumentListener(
//                new CheckableDocListener(tfQuantity, FormatChecker.QUANTITY) {
//
//            @Override
//            public void setField(String doc) {
//                quantityNew = doc;
//                fireContainerEventStateChanged();
//            }
//        });

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

    public void setScreenFields() throws ClipsException {
        if (prescription.getDrug() != null) {
            tfDrug.setText(prescription.getDrug().toString());
        }
        SicklistDiagnosComboboxModel.Item diag =
                new SicklistDiagnosComboboxModel.Item(prescription.getDiagnosis());
        diagModel.setSelectedItem(diag);

        PrescriptionDloComitteeComboboxModel.Item com =
                new PrescriptionDloComitteeComboboxModel.Item(prescription.getCommittee());
        comModel.setSelectedItem(com);

        tfPeriod.setText(prescription.getPeriod() + "");

//        Double dQuantity = (double) prescription.getQuantity();
//        String sQuantity = String.format("%.2f",dQuantity/1000);
//        quantityOld = new String(sQuantity);
//        tfQuantity.setText(sQuantity);
    }

    /** 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel16 = new javax.swing.JPanel();
        jPanel15 = new javax.swing.JPanel();
        jPanel13 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        cbDiagOpen = new javax.swing.JComboBox();
        jPanel6 = new javax.swing.JPanel();
        tfDrug = new javax.swing.JTextField();
        btDrug = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel14 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPanel18 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        tfSeries = new javax.swing.JTextField();
        tfNumber = new javax.swing.JTextField();
        chooserDate = new org.infotechservice.ICalendar.components.ICDateChooser();
        cbPercent = new javax.swing.JComboBox();
        tfPeriod = new cli_fmw.utils.NumberTextField();
        jPanel5 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jPanel11 = new javax.swing.JPanel();
        cbFinanceSource = new javax.swing.JComboBox();
        cbKek = new javax.swing.JComboBox();

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

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

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

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

        jLabel6.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        jLabel6.setText("Рецепт ДЛО");
        jPanel13.add(jLabel6, java.awt.BorderLayout.PAGE_START);

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

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

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

        cbDiagOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDiagOpenActionPerformed(evt);
            }
        });
        jPanel1.add(cbDiagOpen);

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

        tfDrug.setEditable(false);
        jPanel6.add(tfDrug, java.awt.BorderLayout.CENTER);

        btDrug.setText("...");
        btDrug.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDrugActionPerformed(evt);
            }
        });
        jPanel6.add(btDrug, java.awt.BorderLayout.LINE_END);

        jPanel1.add(jPanel6);

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

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

        jLabel8.setText("Диагноз*");
        jPanel3.add(jLabel8);

        jLabel5.setText("Лекарство*");
        jPanel3.add(jLabel5);

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

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

        jPanel14.setLayout(new java.awt.BorderLayout(0, 3));

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

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

        jLabel1.setText("Серия ");
        jPanel8.add(jLabel1);

        jLabel2.setText("Номер");
        jPanel8.add(jLabel2);

        jLabel7.setText("Дата выписки");
        jPanel8.add(jLabel7);

        jLabel3.setText("Процент льготы рецепта");
        jPanel8.add(jLabel3);

        jLabel4.setText("Срок действия рецепта (дней) ");
        jPanel8.add(jLabel4);

        jPanel12.add(jPanel8, java.awt.BorderLayout.WEST);

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

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

        tfSeries.setColumns(16);
        jPanel9.add(tfSeries);

        tfNumber.setColumns(16);
        jPanel9.add(tfNumber);

        chooserDate.setEnabled(false);
        jPanel9.add(chooserDate);

        jPanel9.add(cbPercent);

        tfPeriod.setText("numberTextField2");
        tfPeriod.setFieldLength(2);
        jPanel9.add(tfPeriod);

        jPanel18.add(jPanel9, java.awt.BorderLayout.WEST);

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

        jPanel14.add(jPanel12, java.awt.BorderLayout.NORTH);

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

        jPanel7.setLayout(new java.awt.BorderLayout(27, 5));

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

        jLabel9.setText("Источник финансирования*");
        jPanel10.add(jLabel9);

        jLabel10.setText("Заседание КЭК");
        jPanel10.add(jLabel10);

        jPanel7.add(jPanel10, java.awt.BorderLayout.LINE_START);

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

        jPanel11.add(cbFinanceSource);

        jPanel11.add(cbKek);

        jPanel7.add(jPanel11, java.awt.BorderLayout.CENTER);

        jPanel5.add(jPanel7, java.awt.BorderLayout.NORTH);

        jPanel14.add(jPanel5, java.awt.BorderLayout.CENTER);

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

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

        jPanel15.add(jPanel13, java.awt.BorderLayout.CENTER);

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

        add(jPanel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(13, 9, 590, 310));
    }// </editor-fold>//GEN-END:initComponents

    private void btDrugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDrugActionPerformed
        try {
            DlgDloDrugChooser dlg = new DlgDloDrugChooser(MainWindow.mainWindow, true);
            dlg.setVisible(true);
            if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
                DirectoryDrugListItem drug = dlg.getSelectedDrug();
                prescription.setDrug(drug);
                tfDrug.setText(drug.toString());
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }//GEN-LAST:event_btDrugActionPerformed

    private void cbDiagOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDiagOpenActionPerformed
        try {
            DiagnosisLocal diag = diagModel.getSelectedDiagnosis();
            prescription.setDiagnosis(diag);
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
}//GEN-LAST:event_cbDiagOpenActionPerformed

    @Override
    public String getPageTitle() {
        return "Льготный рецепт";
    }

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

    @Override
    public boolean isDirty() {
        boolean res = prescription == null ? false : prescription.isDirty();
        return res; //|| !quantityNew.equals(quantityOld);
    }

    public String getPageIcon() {
        return null;
    }

    @Override
    public void save() throws ClipsException {
//        String checkQuantity = FormatChecker.checkUet(quantityNew);
//        if (checkQuantity == null) {
//            try {
//                Number num = NumberFormat.getInstance().parse(quantityNew);
//                double d = num.doubleValue();
//                prescription.setQuantity(d);
//            } catch (ParseException pex) {
//                throw new ClipsException(pex.getLocalizedMessage());
//            }
//        }
//        else {
//            tfQuantity.setText(quantityOld);
//            throw new ClipsException(checkQuantity);
//        }
        prescription.save1();
        //quantityOld = new String(quantityNew);
    }

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


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btDrug;
    private javax.swing.JComboBox cbDiagOpen;
    private javax.swing.JComboBox cbFinanceSource;
    private javax.swing.JComboBox cbKek;
    private javax.swing.JComboBox cbPercent;
    private org.infotechservice.ICalendar.components.ICDateChooser chooserDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    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 jPanel18;
    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.JTextField tfDrug;
    private javax.swing.JTextField tfNumber;
    private cli_fmw.utils.NumberTextField tfPeriod;
    private javax.swing.JTextField tfSeries;
    // End of variables declaration//GEN-END:variables

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

    @Override
    public void print() {
        try {
            if (readyForPrint()) {
                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.vertical);
                parCreator.setUpReport(null, ops, null);
                prescription.print(parCreator);
                parCreator.finish();
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

}
TOP

Related Classes of clips.doctor.prescriptiondlo.PanelPrescriptionDlo

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.