/*
* DialogNewReferedSerRen.java
*
* Created on 14 Ноябрь 2008 г., 17:41
*/
package clips.service.newReferedSerRen;
import beans.service.create.NewServicesChunk;
import beans.service.create.ServiceCheckupChunk;
import clips.delegate.directory.filtered.DirectoryCheckupTypeItem;
import clips.delegate.directory.filtered.DirectoryServiceItem;
import clips.delegate.doctor.checkup.CheckupXMLData;
import clips.delegate.service.SerRenLocal;
import clips.doctor.checkup.prepareCheckup.DialogEditCheckUpList;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
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.login.UserInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.swing.ListSelectionModel;
import org.jdom.JDOMException;
import framework.security.SecurityChecker;
import beans.UserRightsSet;
import beans.service.ServiceRender;
import cli_fmw.delegate.AuditList;
import cli_fmw.main.audit.AuditFrame;
import cli_fmw.main.audit.AuditManager;
import cli_fmw.utils.ModalDialog;
import framework.audit.AuditDetails;
/**
* Диалог, создающий связанные услуги (безплатные)
* @author vip
*/
public class DialogNewReferedSerRen extends ModalDialog {
private SerRenLocal serRen;
private TableModelReferedService dataModel;
private ArrayList<SerRenLocal> newSerrenList;
/** Creates new form DialogNewReferedSerRen */
public DialogNewReferedSerRen(java.awt.Frame parent, SerRenLocal serRen, AuditManager am) throws ClipsException {
super(parent, "Добавление связанных услуг", am);
initComponents();
if (UserInfo.get().check(UserRightsSet.CREATE_SERVICE_RENDER) == false) {
throw new ClipsException(SecurityChecker.getClientHasNoRightMsg(UserRightsSet.CREATE_SERVICE_RENDER.id));
}
this.serRen = serRen;
dataModel = new TableModelReferedService(serRen.getService());
sortedTable1.setModel(dataModel);
sortedTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
resizeColumns();
StateSaver.attachTo(this);
}
private void resizeColumns() {
TableState state = new TableState();
state.setPreferredWidth(TableModelReferedService.COL_SELECTED, 1);
state.setPreferredWidth(TableModelReferedService.COL_SERVICE, 3);
state.setPreferredWidth(TableModelReferedService.COL_DESCRIPTION, 3);
state.setPreferredWidth(TableModelReferedService.COL_ISNEDD, 1);
StateSaver.setDefaultState(this, sortedTable1, state);
}
/**
* Возвращает результат работы диалога - список назначенных услуг
* @return
*/
public ArrayList<SerRenLocal> getNewSerrenList() {
return newSerrenList;
}
/** 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() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
sortedTable1 = new cli_fmw.utils.sorted_table.SortedTable();
jPanel4 = new javax.swing.JPanel();
btSetService = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
panelTitle = new javax.swing.JPanel();
labTitle = new javax.swing.JLabel();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
jPanel1.setLayout(new java.awt.BorderLayout());
sortedTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{},
{},
{},
{}
},
new String [] {
}
));
jScrollPane1.setViewportView(sortedTable1);
jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
btSetService.setText("Назначить");
btSetService.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btSetServiceActionPerformed(evt);
}
});
jPanel4.add(btSetService);
btCancel.setText("Отменить");
btCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCancelActionPerformed(evt);
}
});
jPanel4.add(btCancel);
labTitle.setText("Добавление связанных бесплатных услуг");
panelTitle.add(labTitle);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 692, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 692, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(panelTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 692, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(panelTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
private void btSetServiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSetServiceActionPerformed
if (sortedTable1.isEditing()) {
sortedTable1.getCellEditor().stopCellEditing();
}
ArrayList<DirectoryServiceItem> selectedServices = dataModel.getSelectedServices();
if (selectedServices.size() == 0) {
return;
}
//создание списка хмлшег
ArrayList<CheckupXMLData> xmlList = new ArrayList<CheckupXMLData>();
try {
for (int i = 0; i < selectedServices.size(); i++) {
DirectoryCheckupTypeItem checkUpType = selectedServices.get(i).getCheckUpType();
if (checkUpType != null) {
xmlList.add(new CheckupXMLData(checkUpType));
} else {
xmlList.add(null);
}
}
} catch (JDOMException ex) {
MessageBox.showError(MessageBox.E_INVALID_XML_STRING);
return;
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
//отправляем хмлшки на редактирование
boolean needDlg = false;
for (int i = 0; i < xmlList.size(); i++) {
if (xmlList.get(i) != null) {
needDlg = true;
}
}
if (needDlg) {
DialogEditCheckUpList dlg = new DialogEditCheckUpList(MainWindow.mainWindow, xmlList);
dlg.setVisible(true);
if (dlg.getDlgResult() == ModalDialog.DLG_CANCEL) {
return;
}
}
//создаем список услуг, содержащих хмл
ArrayList<ServiceCheckupChunk> chunkList = new ArrayList<ServiceCheckupChunk>();
for (int i = 0; i < selectedServices.size(); i++) {
//создаем список хмл
//создаем список id типов чекапов
//создаем чанк услуги и хмл, добавляем в список
CheckupXMLData xmlData = xmlList.get(i);
String xml = xmlData != null ? xmlData.getXMLStr() : null;
int checkupTypeID = xmlData != null ? xmlData.getCheckupType().getID() : 0;
ServiceCheckupChunk chunk = new ServiceCheckupChunk(selectedServices.get(i).getID(), xml, checkupTypeID);
chunkList.add(chunk);
}
//Отправка на сервер для назначения и принятие результатов (назначенных серренов)
try {
NewServicesChunk newServicesChunk = new NewServicesChunk(
serRen.getDiseaseLocal().getID(),
0,
serRen.getPolisData().getDetails(),
0,
chunkList,
new HashMap<Integer, Integer>());
List<AuditDetails> auditList = serRen.getPolisData().getClient().directNewSerren(newServicesChunk, serRen).getAudit();
newSerrenList = new ArrayList<SerRenLocal>();
for (int i = 0; i < auditList.size(); i++) {
if (!auditList.get(i).entityClass.equals(ServiceRender.class.getSimpleName())) {
continue;
}
SerRenLocal serRenLocal = new SerRenLocal(auditList.get(i).getEntityId, getAuditManager());
newSerrenList.add(serRenLocal);
}
dispose();
// AuditFrame dlg = AuditFrame.getDialog();
// dlg.showMe(auditList);
getAuditManager().needDSA(new AuditList(auditList));
} catch (Exception ex) {
MessageBox.showException(ex);
}
setDlgResult(DLG_OK);
setVisible(false);
dispose();
}//GEN-LAST:event_btSetServiceActionPerformed
private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
setDlgResult(DLG_CANCEL);
setVisible(false);
dispose();
}//GEN-LAST:event_btCancelActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btSetService;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel labTitle;
private javax.swing.JPanel panelTitle;
private cli_fmw.utils.sorted_table.SortedTable sortedTable1;
// End of variables declaration//GEN-END:variables
}