/*
* PanelCreateDeseaseList.java
*
* Created on 17 Март 2008 г., 17:49
*/
package clips.administrator.register;
import beans.UserRightsSet;
import beans.report.register.RegisterBean;
import beans.report.register.RegisterBeanRemote;
import beans.report.register.RegisterData;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.SharedBean;
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.Printable;
import cli_fmw.main.PageGeneric;
import cli_fmw.report.FormReportCreator;
import cli_fmw.report.ReporterFactory;
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.administrator.register.writer.TableModelRegister;
import clips.administrator.register.writer.WriterAbstract;
import clips.administrator.register.writer.WriterAll;
import clips.administrator.register.writer.WriterByCode;
import clips.delegate.client.ClientLocal;
import clips.delegate.config.ConfigLocal;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import clips.delegate.service.SerRenLocal;
import clips.dicom.utils.Pair;
import clips.doctor.PanelEMC;
import clips.login.UserInfo;
import clips.main.ClipsConfig;
import clips.userseach.PanelClientEdit;
import framework.utils.Converter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.xBaseJ.micro.xBaseJException;
/**
* Панель поиска больничных по заданным параметрам
* @author petr
*/
public class PanelRegister extends PageGeneric implements Printable {
private SharedBean<RegisterBeanRemote> bean = new SharedBean<RegisterBeanRemote>(RegisterBean.class.getSimpleName());
private ErrorList errorList;
private ArrayList<WriterAbstract> writerList;
/** Creates new form PanelCreateDeseaseList */
public PanelRegister(PageContainer container) throws ClipsException {
super(container);
initComponents();
initWriterList();
ClipsConfig cfg = ClipsConfig.getInstance();
tfDir.setText(cfg.getRegisterExportPath().getAbsolutePath());
tableErrors.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tableErrors.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (tableErrors.getSelectedRowCount() > 0) {
btEmc.setEnabled(UserInfo.get().check(UserRightsSet.READ_MEDICAL_DATA));
} else {
btEmc.setEnabled(false);
}
}
});
refreshTable();
resizeColumn();
StateSaver.attachTo(this);
}
private void refreshTable() {
tableErrors.setModel(new TableModelRegisterError(errorList));
}
private void resizeColumn() {
TableState state = new TableState();
state.setPreferredWidth(TableModelRegisterError.COL_ID, 1);
state.setPreferredWidth(TableModelRegisterError.COL_TEXT, 12);
StateSaver.setDefaultState(this, tableErrors, state);
}
/** 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() {
jPanel6 = new javax.swing.JPanel();
dchFromDate = new org.infotechservice.ICalendar.components.ICDateChooser();
dchTillDate = new org.infotechservice.ICalendar.components.ICDateChooser();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
btStart = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
tfDir = new javax.swing.JTextField();
btDirSelect = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
tableErrors = new cli_fmw.utils.sorted_table.SortedTable();
btEmc = new javax.swing.JButton();
setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Отчетный период"));
dchFromDate.setPreferredSize(new java.awt.Dimension(150, 19));
dchTillDate.setPreferredSize(new java.awt.Dimension(150, 19));
jLabel1.setText("c");
jLabel2.setText("по");
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(dchFromDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(dchTillDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(191, Short.MAX_VALUE))
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(dchFromDate, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(dchTillDate, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel6Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {dchFromDate, dchTillDate, jLabel1, jLabel2});
btStart.setText("Начать");
btStart.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btStartActionPerformed(evt);
}
});
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Путь для экспорта"));
jPanel2.setLayout(new java.awt.BorderLayout());
tfDir.setEditable(false);
jPanel2.add(tfDir, java.awt.BorderLayout.CENTER);
btDirSelect.setText("Выбрать");
btDirSelect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btDirSelectActionPerformed(evt);
}
});
jPanel2.add(btDirSelect, java.awt.BorderLayout.EAST);
jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Ошибки в реестре"));
tableErrors.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
}
));
tableErrors.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tableErrorsMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tableErrors);
btEmc.setText("Просмотр");
btEmc.setEnabled(false);
btEmc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btEmcActionPerformed(evt);
}
});
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(btStart)
.addContainerGap(499, Short.MAX_VALUE))
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(472, Short.MAX_VALUE)
.addComponent(btEmc)
.addContainerGap())
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
);
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)
.addGap(7, 7, 7)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btStart)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btEmc))
);
}// </editor-fold>//GEN-END:initComponents
/**
* клик на "редактировать"
* @param evt
*/
private void btStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btStartActionPerformed
try {
errorList = null;
List<RegisterData> list = bean.get().getRegisterDataList(dchFromDate.getDate(), dchTillDate.getDate());
System.out.println("Реестр загружен, количество записей " + list.size());
for (int i = 0; i < writerList.size(); i++) {
WriterAbstract w = writerList.get(i);
System.out.println("Запись реестра: " + w.getTitle());
w.createRegLpu();
if (w instanceof WriterAll) {
errorList = w.fillRegLpu(list);
} else {
w.fillRegLpu(list);
}
w.createLpuInfo();
w.fillLpuInfo(dchFromDate.getCalendar(), dchTillDate.getCalendar());
}
refreshTable();
MessageBox.showInfo("Реестр сформирован, ошибок " + errorList.size());
} catch (xBaseJException ex) {
MessageBox.showException(ex);
} catch (IOException ex) {
MessageBox.showException(ex);
} catch (Exception ex) {
bean.clear();
MessageBox.showException(new ClipsException("Не удалось выгрузить реестр", ex));
}
//bean.clear();
//MessageBox.showException(ex);
}//GEN-LAST:event_btStartActionPerformed
private void btDirSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDirSelectActionPerformed
JFileChooser dlg = new JFileChooser();
ClipsConfig cfg = ClipsConfig.getInstance();
dlg.setCurrentDirectory(cfg.getRegisterExportPath());
dlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int res = dlg.showOpenDialog(this);
if (res == JFileChooser.APPROVE_OPTION){
cfg.setRegisterExportPath(dlg.getSelectedFile());
}
tfDir.setText(cfg.getRegisterExportPath().getAbsolutePath());
}//GEN-LAST:event_btDirSelectActionPerformed
private void btEmcActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEmcActionPerformed
if (tableErrors.getSelectedRowCount() > 0) {
try {
int row = tableErrors.getSelectedRowSorted();
int serrenID = errorList.getSerrenID(row);
SerRenLocal serren = new SerRenLocal(serrenID, getAuditManager());
ClientLocal client = serren.getPolisData().getClient(getAuditManager());
switch (errorList.getType(row)) {
case ErrorList.SERREN_ERROR : {
PanelEMC panel = new PanelEMC(getContainer(), client);
getContainer().addNewPage(panel, this);
panel.selectInEmc(serren);
break;
}
case ErrorList.CLIENT_ERROR : {
PanelClientEdit panel = new PanelClientEdit(getContainer(), client);
getContainer().addNewPage(panel, this);
break;
}
default: throw new ClipsException("Неизвестный тип ошибки " + errorList.getType(row));
}
} catch (PageException ex) {
MessageBox.showException(ex);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}//GEN-LAST:event_btEmcActionPerformed
private void tableErrorsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableErrorsMouseClicked
if (evt.getClickCount() == 2) {
btEmc.doClick();
}
}//GEN-LAST:event_tableErrorsMouseClicked
@Override
public String getPageTitle() {
return "Реестр в ФОМС";
}
public String getPageIcon() {
return null;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btDirSelect;
private javax.swing.JButton btEmc;
private javax.swing.JButton btStart;
private org.infotechservice.ICalendar.components.ICDateChooser dchFromDate;
private org.infotechservice.ICalendar.components.ICDateChooser dchTillDate;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel6;
private javax.swing.JScrollPane jScrollPane1;
private cli_fmw.utils.sorted_table.SortedTable tableErrors;
private javax.swing.JTextField tfDir;
// End of variables declaration//GEN-END:variables
@Override
public DelegateLine2 getDelegate() {
return null;
}
@Override
public boolean readyForPrint() {
return true;
}
@Override
public void print() {
//PrintCreators.createGeneratedReport(title, null, data.entrySet(), null, model, getClass());
try {
if (!readyForPrint()) {
return;
}
initWriterList();
DialogSelectInsurer dlg = new DialogSelectInsurer(MainWindow.mainWindow, writerList);
dlg.setVisible(true);
if (dlg.getDlgResult() != ModalDialog.DLG_OK) {
return;
}
WriterAbstract writer = dlg.getResult();
TableModelRegister model = new TableModelRegister(writer);
HashMap<String, Object> data = new LinkedHashMap<String, Object>();
ConfigLocal configLocal = ConfigLocal.getInstance();
DirectoryCollaboratorItem director = UserInfo.get().getCollaborator().getLpu().getChiefDoctor();
DirectoryCollaboratorItem accountantGeneral = UserInfo.get().getCollaborator().getLpu().getAccountant();
Pair<Date, Date> dates = model.getDates();
data.put("count", String.valueOf(model.getRowCount()));
data.put("director", director == null ? "" : director.toString());
data.put("buh", accountantGeneral == null ? "" : accountantGeneral.toString());
data.put("datefrom", dates.first == null ? "" : Converter.dateToString(dates.first));
data.put("datetill", dates.first == null ? "" : Converter.dateToString(dates.second));
data.put("insurer", model.getInsurerTitle());
data.put("currentdate", model.getDateGenerated() == null ? "" : Converter.dateToString(model.getDateGenerated()));
FormReportCreator report = ReporterFactory.createFormReporter(getClass(), 2);
report.createReport(data, model);
report.finish();
//PrintCreators.createGeneratedReport(title, null, data.entrySet(), null, model, getClass());
try {
writer.closeRegLpu();
} catch (IOException ex) {
MessageBox.showException(ex);
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
} catch (xBaseJException ex) {
MessageBox.showException(ex);
} catch (IOException ex) {
MessageBox.showException(ex);
}
}
private void initWriterList() {
writerList = new ArrayList<WriterAbstract>();
writerList.add(new WriterAll());
writerList.add(new WriterByCode(184));
writerList.add(new WriterByCode(186));
writerList.add(new WriterByCode(187));
writerList.add(new WriterByCode(286));
writerList.add(new WriterByCode(344));
writerList.add(new WriterByCode(347));
writerList.add(new WriterByCode(349));
writerList.add(new WriterByCode(355));
writerList.add(new WriterByCode(358));
}
}