/*
* panelDirection.java
*
* Created on 4 Март 2008 г., 18:40
*/
package clips.doctor.direction;
import beans.directory.direction.DirectoryDirectionTypeBean;
import clips.delegate.directory.complex.DirectoryDirectionType;
import clips.delegate.directory.complex.DirectoryDirectionTypeItem;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.directory.complex.DirectoryMKB10Item;
import clips.delegate.directory.filtered.DirectoryServiceItem;
import clips.delegate.doctor.direction.DirectionLocal;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.utils.chooser.ChoosePanelComboException;
import cli_fmw.main.ClipsException;
import clips.directory.dialogs.DirectoryDialogService;
import clips.directory.dialogs.mkb10.DirectoryDialogMKB10;
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.utils.MessageBox;
import cli_fmw.utils.Selector;
import cli_fmw.utils.chooser.ChoosePanelComboListener;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.directory.complex.DirectoryEnterprise;
import clips.delegate.directory.complex.DirectoryMKB10;
import clips.delegate.directory.simple.committeeReason.DirectoryCommitteeReason;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
/**
*Панель отображения направления
* @author lacoste
*/
public class PanelDirection extends PageGeneric implements Persistentable, Printable {
private DirectionLocal directionLocal;
private boolean canBeEdit;
private DirectoryCommitteeReason dirComReason;
private DirectoryDirectionType directionType;
private DirectoryMKB10 dirMkb;
/** Creates new form panelDirection */
public PanelDirection(PageContainer container, DirectionLocal dl) throws ClipsException {
super(container);
initComponents();
this.canBeEdit = dl.getSerrenLocal().canReadMedicalData();
this.directionLocal = dl;
tfDesc.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 {
directionLocal.setDescription(doc.getText(0, doc.getLength()));
} catch (BadLocationException ex) {
MessageBox.showException(ex);
} catch (ClipsException e) {
MessageBox.showException(e);
}
}
});
dirComReason = DirectoryLocator.getDirectory(DirectoryCommitteeReason.class);
chooseComReason.setVisible(false);
chooseService.setVisible(false);
tfService.setText(directionLocal.getService().getTitle());
chooseComReason.setData(dirComReason, directionLocal.getCommitteeReason(),
"Причина направления на КЭК");
chooseComReason.addChoosePanelListener(new ChoosePanelComboListener() {
@Override
public void chooseDone(int type, int id) throws ChoosePanelComboException {
try {
directionLocal.setCommitteeReason(dirComReason.getItemFromID(id));
} catch (ClipsException ex) {
throw new ChoosePanelComboException("Не удалось сменить причину", ex);
}
}
});
directionType = DirectoryLocator.getDirectory(DirectoryDirectionType.class);
Selector ii = directionType.getItems();
for (int i = 0; i < ii.size(); i++) {
DirectoryDirectionTypeItem item = (DirectoryDirectionTypeItem) ii.get(i);
cbType.addItem(item);
}
cbType.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
directionLocal.setType((DirectoryDirectionTypeItem) cbType.getSelectedItem());
int choice = ((DirectoryDirectionTypeItem) cbType.getSelectedItem()).getChoice();
switch (choice) {
case DirectoryDirectionTypeBean.OBLIGATE_SERVICE: {
chooseService.setVisible(true);
chooseComReason.setVisible(false);
break;
}
case DirectoryDirectionTypeBean.OBLIGATE_COMMITTEE: {
chooseService.setVisible(false);
chooseComReason.setVisible(true);
break;
}
default: {
MessageBox.showException(new Exception("не-не-не"));
}
}
setChoosePanelsTrueFields();
} catch (ClipsException e) {
MessageBox.showException(e);
}
}
});
dirMkb = DirectoryLocator.getDirectory(DirectoryMKB10.class);
cbType.setEnabled(directionLocal.isNewlyCreated());
setScreenFields();
StateSaver.attachTo(this);
}
private void setScreenFields() throws ClipsException {
tfMkb.setText(directionLocal.getMkb().toString());
cbType.setSelectedItem(directionLocal.getType());
dateDirection.setDate(directionLocal.getDate());
tfDesc.setText(directionLocal.getDescription());
chOrdered.setSelected(directionLocal.isOrdered());
setChoosePanelsTrueFields();
setEnableComponents();
}
private void setChoosePanelsTrueFields() throws ClipsException {
chooseComReason.setCurrentSelection(0, directionLocal.getCommitteeReason().getID());
}
private void setEnableComponents() {
dateDirection.setEnabled(false);
chOrdered.setEnabled(canBeEdit);
btChangeMkb.setEnabled(canBeEdit);
tfDesc.setEditable(canBeEdit);
chooseComReason.setEnableChoose(canBeEdit);
}
private void checkFields() throws ClipsException {
if (directionLocal.getType().getID() == 0) {
throw new ClipsException("Не выбран тип направления");
}
switch (((DirectoryDirectionTypeItem)directionLocal.getType()).getChoice()) {
case DirectoryDirectionTypeBean.OBLIGATE_SERVICE : {
if (directionLocal.getService().getID() == 0) {
throw new ClipsException("Не выбрана услуга");
}
break;
}
case DirectoryDirectionTypeBean.OBLIGATE_COMMITTEE : {
if (directionLocal.getCommitteeReason().getID() == 0) {
throw new ClipsException("Не выбрана причина направления на комиссию");
}
break;
}
default: throw new ClipsException("Неизвестный тип направления");
}
}
/** 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();
jPanel3 = new javax.swing.JPanel();
values = new javax.swing.JPanel();
dateDirection = new org.infotechservice.ICalendar.components.ICDateChooser();
jPanel11 = new javax.swing.JPanel();
tfDiagCode = new javax.swing.JTextField();
jPanel8 = new javax.swing.JPanel();
tfMkb = new javax.swing.JTextField();
btChangeMkb = new javax.swing.JButton();
cbType = new javax.swing.JComboBox();
jPanel2 = new javax.swing.JPanel();
chooseService = new javax.swing.JPanel();
tfService = new javax.swing.JTextField();
btChangeService = new javax.swing.JButton();
chooseComReason = new cli_fmw.utils.chooser.ChoosePanel();
chOrdered = new javax.swing.JCheckBox();
titles = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
tfDesc = new javax.swing.JTextArea();
jPanel5.setLayout(new java.awt.BorderLayout(5, 5));
jPanel3.setLayout(new java.awt.BorderLayout(5, 5));
values.setLayout(new java.awt.GridLayout(0, 1, 5, 5));
dateDirection.setEnabled(false);
values.add(dateDirection);
jPanel11.setLayout(new java.awt.BorderLayout(5, 5));
tfDiagCode.setColumns(8);
tfDiagCode.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
tfDiagCodeKeyPressed(evt);
}
});
jPanel11.add(tfDiagCode, java.awt.BorderLayout.WEST);
jPanel8.setLayout(new java.awt.BorderLayout(5, 5));
tfMkb.setColumns(30);
tfMkb.setEditable(false);
jPanel8.add(tfMkb, java.awt.BorderLayout.CENTER);
btChangeMkb.setText("...");
btChangeMkb.setPreferredSize(new java.awt.Dimension(25, 24));
btChangeMkb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btChangeMkbActionPerformed(evt);
}
});
jPanel8.add(btChangeMkb, java.awt.BorderLayout.EAST);
jPanel11.add(jPanel8, java.awt.BorderLayout.CENTER);
values.add(jPanel11);
values.add(cbType);
jPanel2.setLayout(new java.awt.CardLayout());
chooseService.setLayout(new java.awt.BorderLayout(5, 5));
tfService.setColumns(40);
tfService.setEditable(false);
chooseService.add(tfService, java.awt.BorderLayout.CENTER);
btChangeService.setText("...");
btChangeService.setPreferredSize(new java.awt.Dimension(25, 24));
btChangeService.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btChangeServiceActionPerformed(evt);
}
});
chooseService.add(btChangeService, java.awt.BorderLayout.EAST);
jPanel2.add(chooseService, "card2");
jPanel2.add(chooseComReason, "card4");
values.add(jPanel2);
chOrdered.setEnabled(false);
chOrdered.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chOrderedActionPerformed(evt);
}
});
values.add(chOrdered);
jPanel3.add(values, java.awt.BorderLayout.CENTER);
titles.setLayout(new java.awt.GridLayout(0, 1, 5, 5));
jLabel2.setText("Дата выписки:");
titles.add(jLabel2);
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
jLabel4.setText("Диагноз:");
titles.add(jLabel4);
jLabel1.setText("Тип направления:");
titles.add(jLabel1);
jLabel3.setText("Куда:");
titles.add(jLabel3);
jLabel6.setText("Погашено: ");
titles.add(jLabel6);
jPanel3.add(titles, java.awt.BorderLayout.WEST);
jPanel5.add(jPanel3, java.awt.BorderLayout.PAGE_START);
jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Примечание"));
tfDesc.setColumns(20);
tfDesc.setLineWrap(true);
tfDesc.setRows(5);
jScrollPane1.setViewportView(tfDesc);
jPanel5.add(jScrollPane1, 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()
.addContainerGap()
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 783, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void chOrderedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chOrderedActionPerformed
try {
directionLocal.setOrdered(chOrdered.isSelected());
} catch (ClipsException e) {
MessageBox.showException(e);
}
}//GEN-LAST:event_chOrderedActionPerformed
private void btChangeMkbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btChangeMkbActionPerformed
try {
DirectoryDialogMKB10 ddd = new DirectoryDialogMKB10(false, directionLocal.getMkb());
ddd.setVisible(true);
if (ddd.getDlgResult() == DirectoryDialogMKB10.DLG_OK) {
Selector<DirectoryMKB10Item> ii = ddd.getSelectedItems();
if (ii.size() > 0) {
DirectoryMKB10Item item = ii.get(0);
tfMkb.setText(item.toString());
directionLocal.setMkb(item);
}
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btChangeMkbActionPerformed
private void btChangeServiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btChangeServiceActionPerformed
try {
DirectoryDialogService dds = new DirectoryDialogService(false, null);
dds.setVisible(true);
if (dds.getDlgResult() == DirectoryDialogService.DLG_OK) {
Selector ii = dds.getSelectedItems();
if (ii.size() > 0) {
DirectoryServiceItem item = (DirectoryServiceItem) ii.get(0);
tfService.setText(item.toString());
directionLocal.setService(item);
}
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btChangeServiceActionPerformed
private void tfDiagCodeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfDiagCodeKeyPressed
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
try {
String code = tfDiagCode.getText().trim().toUpperCase();
if (code.isEmpty()) {
return;
}
try {
DirectoryMKB10Item item = dirMkb.getItemByCode(code);
if (item == null) {
MessageBox.showWarning("Не удалось найти элемент справочника МКБ по введенному коду");
} else {
directionLocal.setMkb(item);
tfMkb.setText(item.toString());
tfMkb.setCaretPosition(0);
tfDiagCode.setText(item.getDiseaseCode());
}
} catch (ParseException ex) {
//do nothing
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}//GEN-LAST:event_tfDiagCodeKeyPressed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btChangeMkb;
private javax.swing.JButton btChangeService;
private javax.swing.JComboBox cbType;
private javax.swing.JCheckBox chOrdered;
private cli_fmw.utils.chooser.ChoosePanel chooseComReason;
private javax.swing.JPanel chooseService;
private org.infotechservice.ICalendar.components.ICDateChooser dateDirection;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel11;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel8;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea tfDesc;
private javax.swing.JTextField tfDiagCode;
private javax.swing.JTextField tfMkb;
private javax.swing.JTextField tfService;
private javax.swing.JPanel titles;
private javax.swing.JPanel values;
// End of variables declaration//GEN-END:variables
@Override
public String getPageTitle() {
return "Направление";
}
@Override
public boolean isDirty() {
return directionLocal == null ? false : directionLocal.isDirty();
}
@Override
public void save() throws ClipsException {
checkFields();
directionLocal.save1();
}
@Override
public void restore() {
if (directionLocal.isNewlyCreated()) {
try {
directionLocal = null;
getContainer().removePage(this, true);
} catch (PageException ex) {
MessageBox.showException(ex);
}
} else {
try {
directionLocal.restore();
setScreenFields();
} catch (ClipsException e) {
}
}
}
@Override
public boolean readyForPrint() {
return !directionLocal.isDirty();
}
@Override
public void print() {
try {
if (readyForPrint()) {
CombinedReportCreator parCreator = PrintCreators.createCombinedReportHeader(getClass());
directionLocal.print(parCreator);
parCreator.finish();
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
@Override
public DelegateLine2 getDelegate() {
return directionLocal;
}
}