/*
* PanelFollowUpSearch.java
*
* Created on 15 Апрель 2008 г., 12:56
*/
package clips.doctor.followup.search;
import beans.followup.search.FollowupData;
import clips.delegate.client.ClientLocal;
import clips.delegate.doctor.followup.FollowUpFactoryLocal;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.delegate.utils.TimeLocal;
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.PrintCreators;
import cli_fmw.main.Printable;
import cli_fmw.main.PageGeneric;
import cli_fmw.report.TableReportOptions;
import clips.userseach.PanelClientEdit;
import clips.userseach.PanelUserSearch;
import cli_fmw.utils.EmptyDialog;
import cli_fmw.utils.InfoDialog;
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.ro.DirectoryCollaborator;
import java.awt.Frame;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import framework.utils.Converter;
import org.infotechservice.ICalendar.DateEvent;
import org.infotechservice.ICalendar.DateListener;
/**
* панель для отображения списка диспансеризации
* @author lacoste
*/
public class PanelFollowUpSearch extends PageGeneric implements Printable {
private Date dateFrom;
private Date dateTill;
private ArrayList<FollowupData> followupList;
private ClientLocal client;
private DirectoryCollaborator dirColl;
public PanelFollowUpSearch(PageContainer container) throws ClipsException{
super(container);
initComponents();
dirColl = DirectoryLocator.getDirectory(DirectoryCollaborator.class);
tabFollowUps.setModel(new TableModelFollowupListForQuery(new ArrayList<FollowupData>(), dirColl, getAuditManager()));
tabFollowUps.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//слушатели для датачузеров
dateChFrom.addDateListener(new DateListener() {
@Override
public void dateChanged(DateEvent event) {
dateFrom = dateChFrom.getDate();
}
});
//слушатели для датачузеров
dateChTill.addDateListener(new DateListener() {
@Override
public void dateChanged(DateEvent event) {
dateTill = dateChTill.getDate();
}
});
tabFollowUps.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
boolean active = tabFollowUps.getSelectedRowCount() > 0;
btClientEdit.setEnabled(active);
btClientInfo.setEnabled(active);
}
});
dateFrom = TimeLocal.getCurrentTime().getTime();
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(dateFrom);
calendar.add(GregorianCalendar.DAY_OF_MONTH, 7);
dateTill = calendar.getTime();
dateChFrom.setDate(dateFrom);
dateChTill.setDate(dateTill);
chFollowupDown.setHorizontalTextPosition(SwingConstants.LEFT);
resizeColumn();
StateSaver.attachTo(this);
}
private void refreshTable() {
tabFollowUps.setModel(new TableModelFollowupListForQuery(followupList, dirColl, getAuditManager()));
tabFollowUps.setDefaultRenderer(Object.class, new TableCellRendererFollowUpList(followupList));
//tabFollowUps.setDefaultRenderer(Date.class, new TableCellRendererFollowUpList(followupList));
}
/** 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();
tabFollowUps = new cli_fmw.utils.sorted_table.SortedTable();
jPanel5 = new javax.swing.JPanel();
btClientInfo = new javax.swing.JButton();
btClientEdit = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel6 = new javax.swing.JPanel();
cbClient = new javax.swing.JCheckBox();
tfClient = new javax.swing.JTextField();
btClient = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
dateChFrom = new org.infotechservice.ICalendar.components.ICDateChooser();
jPanel8 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
dateChTill = new org.infotechservice.ICalendar.components.ICDateChooser();
chFollowupDown = new javax.swing.JCheckBox();
jPanel4 = new javax.swing.JPanel();
btGoGoGo = new javax.swing.JButton();
setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
setLayout(new java.awt.BorderLayout(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);
}
});
tabFollowUps.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tabFollowUpsMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tabFollowUps);
add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel5.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
btClientInfo.setText("Инфо пациента");
btClientInfo.setEnabled(false);
btClientInfo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btClientInfoActionPerformed(evt);
}
});
jPanel5.add(btClientInfo);
btClientEdit.setText("Перейти к пациенту");
btClientEdit.setEnabled(false);
btClientEdit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btClientEditActionPerformed(evt);
}
});
jPanel5.add(btClientEdit);
add(jPanel5, java.awt.BorderLayout.SOUTH);
jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.PAGE_AXIS));
jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
jLabel1.setFont(jLabel1.getFont().deriveFont((jLabel1.getFont().getStyle() & ~java.awt.Font.ITALIC) | java.awt.Font.BOLD, 13));
jLabel1.setText("Поиск приемов по диспансерному наблюдению:");
jPanel3.add(jLabel1);
jPanel2.add(jPanel3);
jPanel6.setLayout(new java.awt.BorderLayout());
cbClient.setText("по пациенту: ");
cbClient.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbClientActionPerformed(evt);
}
});
jPanel6.add(cbClient, java.awt.BorderLayout.LINE_START);
tfClient.setColumns(40);
tfClient.setEditable(false);
jPanel6.add(tfClient, java.awt.BorderLayout.CENTER);
btClient.setText("...");
btClient.setEnabled(false);
btClient.setPreferredSize(new java.awt.Dimension(24, 24));
btClient.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btClientActionPerformed(evt);
}
});
jPanel6.add(btClient, java.awt.BorderLayout.LINE_END);
jPanel2.add(jPanel6);
jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
jPanel7.setLayout(new java.awt.BorderLayout());
jLabel2.setText("С: ");
jPanel7.add(jLabel2, java.awt.BorderLayout.WEST);
dateChFrom.setPreferredSize(new java.awt.Dimension(130, 19));
jPanel7.add(dateChFrom, java.awt.BorderLayout.CENTER);
jPanel1.add(jPanel7);
jPanel8.setLayout(new java.awt.BorderLayout());
jLabel3.setText("по: ");
jPanel8.add(jLabel3, java.awt.BorderLayout.WEST);
dateChTill.setPreferredSize(new java.awt.Dimension(130, 19));
jPanel8.add(dateChTill, java.awt.BorderLayout.CENTER);
jPanel1.add(jPanel8);
chFollowupDown.setText("+ закрытые приемы ");
jPanel1.add(chFollowupDown);
jPanel2.add(jPanel1);
jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
btGoGoGo.setText("Найти");
btGoGoGo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btGoGoGoActionPerformed(evt);
}
});
jPanel4.add(btGoGoGo);
jPanel2.add(jPanel4);
add(jPanel2, java.awt.BorderLayout.NORTH);
}// </editor-fold>//GEN-END:initComponents
private void btGoGoGoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btGoGoGoActionPerformed
try {
FollowUpFactoryLocal factoryLocal = new FollowUpFactoryLocal();
followupList = factoryLocal.findFollowUpsComing(dateFrom, dateTill, chFollowupDown.isSelected(), client);
refreshTable();
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btGoGoGoActionPerformed
private void btClientInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClientInfoActionPerformed
if (tabFollowUps.getSelectedRowCount() == 0) {
MessageBox.showWarning(MessageBox.W_LIST_ELEMENT_NOT_SELECT);
return;
}
try {
int clientID = followupList.get(tabFollowUps.getSelectedRowSorted()).clientID;
ClientLocal clientLocal = new ClientLocal(clientID, getAuditManager());
clientLocal.getMother();
clientLocal.getFather();
InfoDialog dialog = new InfoDialog((Frame)getContainer(), clientLocal.toHtml());
dialog.setVisible(true);
} catch(ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btClientInfoActionPerformed
private void btClientEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClientEditActionPerformed
if (tabFollowUps.getSelectedRowCount() == 0) {
MessageBox.showWarning(MessageBox.W_LIST_ELEMENT_NOT_SELECT);
return;
}
try {
int clientID = followupList.get(tabFollowUps.getSelectedRowSorted()).clientID;
ClientLocal clientLocal = new ClientLocal(clientID, getAuditManager());
PanelClientEdit panel = new PanelClientEdit(getContainer(), clientLocal);
PageGeneric page = getContainer().addNewPage(panel, this);
getContainer().activatePage(page);
} catch (PageException ex) {
MessageBox.showException(ex);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btClientEditActionPerformed
private void cbClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbClientActionPerformed
try {
if (cbClient.isSelected()) {
EmptyDialog dlg = new EmptyDialog(MainWindow.mainWindow, "Выбор пациента", getAuditManager());
PanelUserSearch panel = new PanelUserSearch(dlg, PanelUserSearch.MODE_SELECT);
dlg.addNewPage(panel, null);
dlg.setVisible(true);
if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
client = panel.getSelectedClient();
tfClient.setText(client.toString());
btClient.setEnabled(true);
}
else {
client = null;
tfClient.setText("");
btClient.setEnabled(false);
cbClient.setSelected(false);
}
}
else {
client = null;
tfClient.setText("");
btClient.setEnabled(false);
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_cbClientActionPerformed
private void btClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClientActionPerformed
try {
EmptyDialog dialog = new EmptyDialog(MainWindow.mainWindow, "Выбор пациента", getAuditManager());
PanelUserSearch panel = new PanelUserSearch(dialog, PanelUserSearch.MODE_SELECT);
dialog.addNewPage((PageGeneric) panel, null);
dialog.setVisible(true);
if (dialog.getDlgResult() == ModalDialog.DLG_OK) {
client = panel.getSelectedClient();
tfClient.setText(client.toString());
btClient.setEnabled(true);
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btClientActionPerformed
private void tabFollowUpsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabFollowUpsMouseClicked
if (evt.getClickCount() == 2) {
btClientEditActionPerformed(null);
}
}//GEN-LAST:event_tabFollowUpsMouseClicked
private void jScrollPane1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jScrollPane1ComponentResized
}//GEN-LAST:event_jScrollPane1ComponentResized
@Override
public String getPageTitle() {
return "Назначенные приемы";
}
private void resizeColumn() {
TableState state = new TableState();
state.setPreferredWidth(TableModelFollowupListForQuery.COL_CLIENT, 13);
state.setPreferredWidth(TableModelFollowupListForQuery.COL_DATEUP, 6);
state.setPreferredWidth(TableModelFollowupListForQuery.COL_COLLABORATOR,11);
state.setPreferredWidth(TableModelFollowupListForQuery.COL_DATEDOWN, 6);
state.setPreferredWidth(TableModelFollowupListForQuery.COL_COLLDOWN, 11);
state.setPreferredWidth(TableModelFollowupListForQuery.COL_DATE, 6);
state.setPreferredWidth(TableModelFollowupListForQuery.COL_ORDERED, 4);
state.setPreferredWidth(TableModelFollowupListForQuery.COL_CANCELLED, 4);
state.setPreferredWidth(TableModelFollowupListForQuery.COL_CALLED, 4);
StateSaver.setDefaultState(this, tabFollowUps, state);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btClient;
private javax.swing.JButton btClientEdit;
private javax.swing.JButton btClientInfo;
private javax.swing.JButton btGoGoGo;
private javax.swing.JCheckBox cbClient;
private javax.swing.JCheckBox chFollowupDown;
private org.infotechservice.ICalendar.components.ICDateChooser dateChFrom;
private org.infotechservice.ICalendar.components.ICDateChooser dateChTill;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
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.JScrollPane jScrollPane1;
private cli_fmw.utils.sorted_table.SortedTable tabFollowUps;
private javax.swing.JTextField tfClient;
// End of variables declaration//GEN-END:variables
@Override
public boolean readyForPrint() {
return true;
}
@Override
public void print() {
if (readyForPrint()) {
//производим поиск чтоб результаты соответствовали фильтру
btGoGoGoActionPerformed(null);
HashMap<String, Object> data = new LinkedHashMap<String, Object>();
data.put("dateFrom", "Дата поиска с: " + Converter.dateToString(dateChFrom.getDate())
+ " по: " + Converter.dateToString(dateChTill.getDate()));
if (client != null) {
data.put("client", "по пациенту: " + client.toString());
}
if (chFollowupDown.isSelected()) {
data.put("plusDown", "включая закрытые приемы");
}
String title = "Список назначенных приемов по фильтру";
TableReportOptions ops = new TableReportOptions(TableReportOptions.PageOrentation.horizontal);
PrintCreators.createGeneratedReport(title, ops, data.entrySet(), null, tabFollowUps.getModel(), getClass());
}
}
@Override
public DelegateLine2 getDelegate() {
return client;
}
}