/*
* PanelEMC.java
*
* Created on 11 Декабрь 2007 г., 21:05
*/
package clips.doctor;
import clips.dicom.model.AgregatorItem;
import clips.doctor.newEMC.init.EmcTreeModel;
import clips.doctor.newEMC.init.EmcTreeNode;
import beans.service.ServiceRenderBean;
import clips.doctor.newEMC.init.generic.DelegateNodeInterface;
import cli_fmw.main.ClipsException;
import clips.delegate.client.ClientLocal;
import clips.delegate.doctor.EmcLocal;
import clips.delegate.service.SerRenLocal;
import clips.delegate.doctor.DiseaseLocal;
import clips.delegate.doctor.certificate.CertificateLocal;
import clips.delegate.doctor.checkup.CheckupLocal;
import clips.delegate.doctor.contraindication.ContraindicationLocal;
import clips.delegate.doctor.diagnosis.DiagnosisLocal;
import clips.delegate.doctor.direction.DirectionLocal;
import clips.delegate.doctor.followup.FollowupLocal;
import clips.delegate.doctor.prescription.PrescriptionLocal;
import clips.delegate.doctor.RecommendationLocal;
import clips.delegate.doctor.sicklist.SicklistLocal;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ActivateSensitive;
import cli_fmw.main.PageContainer;
import cli_fmw.main.Persistentable;
import clips.doctor.sicklist.dialogs.DialogSicklistCreate;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PageException;
import cli_fmw.main.Printable;
import clips.service.newReferedSerRen.DialogNewReferedSerRen;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import java.awt.Color;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.ExpandVetoException;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import framework.security.SecurityChecker;
import beans.UserRightsSet;
import beans.service.quickInput.DisSerDiagAuditChunk;
import cli_fmw.delegate.AuditList;
import cli_fmw.delegate.collaborator.GUIConfig;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.login.UserInfoAbstract;
import cli_fmw.main.PageGeneric;
import cli_fmw.report.CombinedReportCreator;
import cli_fmw.report.CombinedReportOptions;
import cli_fmw.report.PageOptions.PageOrentation;
import cli_fmw.report.ReporterFactory;
import cli_fmw.utils.DefaultColors;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.Log;
import cli_fmw.utils.autocomplete.HasColors;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.Main;
import clips.delegate.directory.complex.DirectoryMKB10;
import clips.delegate.doctor.Signable;
import clips.delegate.doctor.checkup.CheckupDICOMLocal;
import clips.delegate.doctor.prescriptiondlo.PrescriptionDloLocal;
import clips.dicom.dicom_emc.DialogSelectDicomObjects;
import clips.doctor.newEMC.init.generic.DelegateNode;
import clips.doctor.newEMC.nodes.CheckupNode;
import clips.doctor.newEMC.nodes.collectors.CertificateCollectorNode;
import clips.doctor.newEMC.nodes.ClientNode;
import clips.doctor.newEMC.nodes.DiseaseNode;
import clips.doctor.newEMC.nodes.EmcNode;
import clips.doctor.newEMC.nodes.SerrenNode;
import clips.doctor.newEMC.nodes.collectors.SicklistCollectorNode;
import clips.login.UserInfo;
import java.awt.Component;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeWillExpandListener;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeSelectionModel;
/**
*
* @author Администратор
*/
public class PanelEMC extends PageGeneric implements PageContainer, Persistentable, Printable/*, ContentStateListener*/ {
private ClientLocal clientLocal;
private EmcLocal emcLocal;
private PageGeneric innerPage = null; //панель, которая отображается в правой части
private DelegateLine2 currentCreatedDelegate;
private boolean showECP = false;
private SerrenNode selectedServiceNode;
private DiseaseNode selectedDiseaseNode;
private boolean nodeRemoving = false;
private TreePath lastSelectionPath;
private TreePath currentSelectionPath;
/** Creates new form PanelEMC
* @param container
* @param clientLocal
* @throws ClipsException
*/
public PanelEMC(PageContainer container, DelegateLine2 clientLocal) throws ClipsException {
super(container);
initComponents();
DirectoryLocator.getDirectory(DirectoryMKB10.class);
this.clientLocal = (ClientLocal) clientLocal;
this.emcLocal = this.clientLocal.getEMC(); //взяли у клиента ЕМС
emcLocal.getDiseaseList();
Date t1 = new Date();
final DefaultTreeModel model = new EmcTreeModel(new ClientNode(this.clientLocal));
model.addTreeModelListener(new TreeModelListenerImpl(model));
treeEMC.setModel(model);
treeEMC.setCellRenderer(new TreeCellRendererImpl());
DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModelImpl();
selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
treeEMC.setSelectionModel(selectionModel);
treeEMC.addTreeWillExpandListener(new TreeWillExpandListenerImpl());
treeEMC.addTreeSelectionListener(new TreeSelectionListenerImpl());
treeEMC.setScrollsOnExpand(true);
treeEMC.setExpandsSelectedPaths(true);
Date t2 = new Date();
System.out.println("EMC TREE CREATED IN " + (t2.getTime() - t1.getTime()) + " MS");
setEnabledComponents();
GUIConfig config = UserInfoAbstract.get().getGuiConfig();
showECP = config.getBoolean(GUIConfig.P_SHOW_ECP);
StateSaver.attachTo(this);
}
private void addECPPanel(Signable s) throws PageException {
try {
if (showECP) {
JPanel panel = null;
Icon ic = ErrorValue.KEY_ICON;
if (!s.isSignCorrect()) {
ic = ErrorValue.RED_KEY_ICON;
}
panel = new PanelECP(s.getSignMessage(), ic);
jPanel6.add(panel);
jPanel6.revalidate();
}
} catch (ClipsException ex) {
throw new PageException("Не удалось получить цифровую подпись", ex);
}
}
private CheckupLocal getSelectedCheckup() {
CheckupLocal checkup = null;
EmcTreeNode node = getCurrentSelectedNode();
if (node != null){
if (node instanceof CheckupNode) {
checkup = (CheckupLocal) node.getDelegate();
} else {
node = node.findParentByDelegateClass(CheckupLocal.class);
if (node != null) {
checkup = (CheckupLocal) node.getDelegate();
}
}
}
return checkup;
}
/**
* разрешает и запрещает кнопки
*/
private void setEnabledComponents() {
EmcTreeNode node = getCurrentSelectedNode();
if (node != null){
if (node instanceof SerrenNode){
selectedServiceNode = (SerrenNode) node;
}else{
selectedServiceNode = (SerrenNode) node.findParentByDelegateClass(SerRenLocal.class);
}
if (node instanceof DiseaseNode){
selectedDiseaseNode = (DiseaseNode) node;
}else{
selectedDiseaseNode = (DiseaseNode) node.findParentByDelegateClass(DiseaseLocal.class);
}
}
boolean canBeClosed = isInnerPanelClear();
btRemove.setEnabled(canBeClosed
&& node != null
&& !(node instanceof ClientNode)
&& !(node instanceof EmcNode)
&& (node.getDelegate() instanceof DelegateNode));
btNewDisease.setEnabled(canBeClosed);
btFollowUp.setEnabled(canBeClosed);
btCertificate.setEnabled(canBeClosed);
btSicklist.setEnabled(canBeClosed);
btQuickInput.setEnabled(canBeClosed);
boolean enabled;
try {
enabled = canBeClosed
&& selectedServiceNode != null
&& selectedServiceNode.getDelegate().canReadMedicalData();
} catch (ClipsException ex) {
ex.printStackTrace();
enabled = false;
}
btAdd.setEnabled(enabled);
btFollowUp.setEnabled(enabled);
btSicklist.setEnabled(enabled);
boolean canWriteMedicalData = false;
boolean hasChildServices = false;
if (selectedServiceNode != null) {
try {
canWriteMedicalData = selectedServiceNode.getDelegate().hasRight(ServiceRenderBean.COMMAND_MODIFY);
hasChildServices = selectedServiceNode.getDelegate().getService().getChildServices().size() > 0;
} catch (ClipsException ex) {
ex.printStackTrace();
canWriteMedicalData = false;
}
}
miAddReferedService.setEnabled(hasChildServices);
miCheckup.setEnabled(canWriteMedicalData);
miContraindication.setEnabled(canWriteMedicalData);
miDiagnosis.setEnabled(canWriteMedicalData);
miDirection.setEnabled(canWriteMedicalData);
miPrescription.setEnabled(canWriteMedicalData);
miRecomendation.setEnabled(canWriteMedicalData);
miDloDrug.setEnabled(canWriteMedicalData);
miDICOM.setEnabled(getSelectedCheckup() != null);
if (!canWriteMedicalData && !hasChildServices) {
//Если нельзя добавлять мед данные и нельзя назначить связанные услуги
btAdd.setEnabled(false);
}
}
/*
* Вернёт текущиц выделенный узел дерева или нулл если выделения нет
* @return
*/
private EmcTreeNode getCurrentSelectedNode(){
Object object = treeEMC.getLastSelectedPathComponent();
if (object != null){
if (object instanceof EmcTreeNode){
EmcTreeNode node = (EmcTreeNode)object;
return node;
}else{
throw new IllegalStateException("Element with unsupported class in EMC tree!");
}
}
return null;
}
/**
* Проверяет можно ли закрыть текущую страницу
* @return истина если можно
*/
private boolean isInnerPanelClear(){
boolean notDirty = (innerPage != null && innerPage instanceof Persistentable) ? !((Persistentable) innerPage).isDirty() : true;
return notDirty;
}
/** 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() {
jPopupMenu1 = new javax.swing.JPopupMenu();
miContraindication = new javax.swing.JMenuItem();
miCheckup = new javax.swing.JMenuItem();
miPrescription = new javax.swing.JMenuItem();
miDirection = new javax.swing.JMenuItem();
miRecomendation = new javax.swing.JMenuItem();
miDiagnosis = new javax.swing.JMenuItem();
miDICOM = new javax.swing.JMenuItem();
miAddReferedService = new javax.swing.JMenuItem();
miDloDrug = new javax.swing.JMenuItem();
jSplitPane1 = new javax.swing.JSplitPane();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
treeEMC = new javax.swing.JTree();
jPanel7 = new javax.swing.JPanel();
jPanel8 = new javax.swing.JPanel();
btRemove = new javax.swing.JButton();
btAdd = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
pnlView = new javax.swing.JPanel();
jPanel6 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
btFollowUp = new javax.swing.JButton();
btCertificate = new javax.swing.JButton();
btSicklist = new javax.swing.JButton();
btNewDisease = new javax.swing.JButton();
btQuickInput = new javax.swing.JButton();
miContraindication.setText("Непереносимость");
miContraindication.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miContraindicationActionPerformed(evt);
}
});
jPopupMenu1.add(miContraindication);
miCheckup.setText("Осмотр");
miCheckup.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miCheckupActionPerformed(evt);
}
});
jPopupMenu1.add(miCheckup);
miPrescription.setText("Назначение");
miPrescription.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miPrescriptionActionPerformed(evt);
}
});
jPopupMenu1.add(miPrescription);
miDirection.setText("Направление");
miDirection.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miDirectionActionPerformed(evt);
}
});
jPopupMenu1.add(miDirection);
miRecomendation.setText("Рекомендацию");
miRecomendation.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miRecomendationActionPerformed(evt);
}
});
jPopupMenu1.add(miRecomendation);
miDiagnosis.setText("Диагноз");
miDiagnosis.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miDiagnosisActionPerformed(evt);
}
});
jPopupMenu1.add(miDiagnosis);
miDICOM.setText("Объект DICOM");
miDICOM.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miDICOMActionPerformed(evt);
}
});
jPopupMenu1.add(miDICOM);
miAddReferedService.setText("Связанную услугу");
miAddReferedService.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miAddReferedServiceActionPerformed(evt);
}
});
jPopupMenu1.add(miAddReferedService);
miDloDrug.setText("Льготный рецепт");
miDloDrug.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miDloDrugActionPerformed(evt);
}
});
jPopupMenu1.add(miDloDrug);
setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
setLayout(new java.awt.BorderLayout());
jSplitPane1.setDividerLocation(250);
jPanel1.setLayout(new java.awt.BorderLayout());
treeEMC.setBorder(javax.swing.BorderFactory.createEtchedBorder());
treeEMC.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
treeEMCKeyPressed(evt);
}
});
jScrollPane1.setViewportView(treeEMC);
jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel7.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel7.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
btRemove.setText("Удалить");
btRemove.setPreferredSize(new java.awt.Dimension(86, 40));
btRemove.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btRemoveActionPerformed(evt);
}
});
btAdd.setText("Добавить...");
btAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btAddActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
jPanel8.setLayout(jPanel8Layout);
jPanel8Layout.setHorizontalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel8Layout.createSequentialGroup()
.addContainerGap()
.addComponent(btRemove, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btAdd)
.addContainerGap())
);
jPanel8Layout.setVerticalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel8Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btAdd)
.addComponent(btRemove, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel8Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btAdd, btRemove});
jPanel7.add(jPanel8);
jPanel1.add(jPanel7, java.awt.BorderLayout.SOUTH);
jSplitPane1.setLeftComponent(jPanel1);
jPanel4.setLayout(new java.awt.BorderLayout());
jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel3.setLayout(new java.awt.BorderLayout());
pnlView.setLayout(new java.awt.BorderLayout());
jPanel3.add(pnlView, java.awt.BorderLayout.CENTER);
jPanel6.setLayout(new java.awt.BorderLayout());
jPanel3.add(jPanel6, java.awt.BorderLayout.PAGE_END);
jPanel4.add(jPanel3, java.awt.BorderLayout.CENTER);
btFollowUp.setText("<html><center>Поставить<br>на ДУ</center></html>");
btFollowUp.setToolTipText("Поставить пациента на диспансеризацию");
btFollowUp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btFollowUpActionPerformed(evt);
}
});
btCertificate.setText("<html><center>Исходящая<br>документация</center></html>");
btCertificate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCertificateActionPerformed(evt);
}
});
btSicklist.setText("<html><p align=\"center\">Открыть<br>больничный</p></html>");
btSicklist.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btSicklistActionPerformed(evt);
}
});
btNewDisease.setText("<html><p align=\"center\">Новое<p align=\"center\">заболевание");
btNewDisease.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btNewDiseaseActionPerformed(evt);
}
});
btQuickInput.setText("<html><p align=\"center\">Быстрый<p align=\"center\">ввод");
btQuickInput.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btQuickInputActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(btFollowUp)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCertificate)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btSicklist)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btNewDisease)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btQuickInput)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCertificate, btFollowUp, btNewDisease, btQuickInput, btSicklist});
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCertificate, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btSicklist, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btNewDisease, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btQuickInput, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(btFollowUp, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btCertificate, btFollowUp, btNewDisease, btQuickInput, btSicklist});
jPanel4.add(jPanel2, java.awt.BorderLayout.SOUTH);
jSplitPane1.setRightComponent(jPanel4);
add(jSplitPane1, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void btSicklistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSicklistActionPerformed
if (isInnerPanelClear()) {
try {
DialogSicklistCreate dlg = new DialogSicklistCreate(MainWindow.mainWindow, clientLocal, selectedServiceNode.getDelegate(), getAuditManager());
dlg.setVisible(true);
if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
SicklistLocal sicklistLocal = dlg.getSicklist();
ClientNode root = (ClientNode) treeEMC.getModel().getRoot();
for (int i = 0; i < root.getChildCount(); i++) {
if (root.getChildAt(i) instanceof SicklistCollectorNode) {
root.getChildAt(i).getDelegate().addChild(sicklistLocal);
return;
}
}
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
} else {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
}
}//GEN-LAST:event_btSicklistActionPerformed
private void btCertificateActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btCertificateActionPerformed
{//GEN-HEADEREND:event_btCertificateActionPerformed
if (isInnerPanelClear()) {
try {
CertificateLocal cl = new CertificateLocal(clientLocal, selectedDiseaseNode != null ? selectedDiseaseNode.getDelegate() : null);
if (!cl.canCreate()) {
throw new ClipsException(SecurityChecker.getClientHasNoRightMsg(UserRightsSet.MODIFY_CERTIFICATE.id));
}
ClientNode root = (ClientNode) treeEMC.getModel().getRoot();
for (int i = 0; i < root.getChildCount(); i++) {
if (root.getChildAt(i) instanceof CertificateCollectorNode) {
root.getChildAt(i).getDelegate().addChild(cl);
return;
}
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
} else {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
}
}//GEN-LAST:event_btCertificateActionPerformed
@SuppressWarnings("unchecked")
private void btRemoveActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btRemoveActionPerformed
{//GEN-HEADEREND:event_btRemoveActionPerformed
try {
if (!isInnerPanelClear()) {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
}else{
EmcTreeNode node = getCurrentSelectedNode();
if (MessageBox.showConfirmYesNo(MessageBox.C_DEL_OBJECT) == MessageBox.ANSWER_YES){
if (node != null){
if (node.getDelegate() instanceof DelegateNode) {
DelegateNode child = (DelegateNode) node.getDelegate();
if (child instanceof SerRenLocal && ((SerRenLocal)child).getPacketServiceID() != 0) {
if (MessageBox.showConfirmYesNo(MessageBox.C_DEL_SERV_FROM_PACK) != MessageBox.ANSWER_YES) {
return;
}
((SerRenLocal)child).removeAndBreakPacket();
} else if (child instanceof DiseaseLocal && ((DiseaseLocal)child).isMedexam()) {
((DiseaseLocal)child).getMedexamLocal().remove();
} else {
child.remove();
}
try{
if (isPathContains(lastSelectionPath, node)){
lastSelectionPath = null;
}
currentSelectionPath = null;
}catch(Exception e){
throw new ClipsException("Ошибка при смене выделения", e);
}finally{//если уж прокатило удаление объекта из базы, то не стоит оставлять его в кеше,
// даже если были проблемы с переводом выделения
node.getParent().getDelegate().removeChild(child);
}
}else{
MessageBox.showWarning(MessageBox.W_UNDELETED_TYPE);
}
}
}
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btRemoveActionPerformed
private void btFollowUpActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btFollowUpActionPerformed
{//GEN-HEADEREND:event_btFollowUpActionPerformed
if (!isInnerPanelClear()) {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
}else{
addDelegateToEMC(FollowupLocal.class);
}
}//GEN-LAST:event_btFollowUpActionPerformed
private void btNewDiseaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNewDiseaseActionPerformed
if (!isInnerPanelClear()) {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
} else {
addDelegateToEMC(DiseaseLocal.class);
}
}//GEN-LAST:event_btNewDiseaseActionPerformed
private void miContraindicationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miContraindicationActionPerformed
addDelegateToService(ContraindicationLocal.class);
}//GEN-LAST:event_miContraindicationActionPerformed
private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
jPopupMenu1.show(btAdd, 0, 0);
}//GEN-LAST:event_btAddActionPerformed
private void miCheckupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCheckupActionPerformed
addDelegateToService(CheckupLocal.class);
}//GEN-LAST:event_miCheckupActionPerformed
private void miPrescriptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miPrescriptionActionPerformed
addDelegateToService(PrescriptionLocal.class);
}//GEN-LAST:event_miPrescriptionActionPerformed
private void miDirectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miDirectionActionPerformed
addDelegateToService(DirectionLocal.class);
}//GEN-LAST:event_miDirectionActionPerformed
private void miRecomendationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miRecomendationActionPerformed
addDelegateToService(RecommendationLocal.class);
}//GEN-LAST:event_miRecomendationActionPerformed
private void miDiagnosisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miDiagnosisActionPerformed
addDelegateToService(DiagnosisLocal.class);
}//GEN-LAST:event_miDiagnosisActionPerformed
private void miAddReferedServiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAddReferedServiceActionPerformed
try {
if (selectedServiceNode != null){
DialogNewReferedSerRen dlg = new DialogNewReferedSerRen(MainWindow.mainWindow, selectedServiceNode.getDelegate(), getAuditManager());
dlg.setVisible(true);
if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
DiseaseNode diseaseNode = (DiseaseNode) selectedServiceNode.getParent();
for (SerRenLocal serRenLocal : dlg.getNewSerrenList()) {
diseaseNode.getDelegate().addChild(serRenLocal);
}
}
}else{
MessageBox.showWarning(MessageBox.W_SERVICE_NOT_SELECT);
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_miAddReferedServiceActionPerformed
private boolean isPathContains(TreePath path, Object element){
if (path != null){
for (Object object : path.getPath()) {
if (object.equals(element)){
return true;
}
}
}
return false;
}
/**
* Добавляет делегата в ЭМК
* @param aClass
* @throws ClipsException
*/
private void addDelegateToEMC(Class<? extends DelegateNode> aClass){
DelegateNode node = null;
try{
if (aClass.equals(DiseaseLocal.class)) {
node = new DiseaseLocal(clientLocal.getEMC());
} else if (aClass.equals(FollowupLocal.class)) {
if (selectedServiceNode != null){
if(selectedServiceNode.getDelegate().getDiseaseLocal().getSpecificDiagnosis() == null){
MessageBox.showWarning(MessageBox.W_INCORRECT_DATA, "В заболевании не указан заключительный диагноз");
}else{
node = new FollowupLocal(selectedServiceNode.getDelegate());
}
}else{
MessageBox.showWarning(MessageBox.W_INCORRECT_DATA, "Необходимо выбрать услугу");
}
} else {
throw new ClipsException("Попытка создать объект неучтённого типа");
}
if (node != null) {
System.out.println("PANEL EMC, NODE " + node + " ADD TO EMC");
clientLocal.getEMC().addChild(node);
}
}catch(ClipsException e){
MessageBox.showException(e);
}
}
/**
* Добавляет элемент в текущую услугу, переводит выделение на него
* @param aClass
*/
private void addDelegateToService(Class<? extends DelegateNode> aClass) {
if (selectedServiceNode != null) {
SerRenLocal selectedService = selectedServiceNode.getDelegate();
try {
DelegateNode leaf = null;
if (aClass.equals(ContraindicationLocal.class)) {
leaf = new ContraindicationLocal(selectedService);
} else if (aClass.equals(CheckupLocal.class)) {
leaf = new CheckupLocal(selectedService);
} else if (aClass.equals(PrescriptionLocal.class)) {
leaf = new PrescriptionLocal(selectedService);
} else if (aClass.equals(DirectionLocal.class)) {
leaf = new DirectionLocal(selectedService);
} else if (aClass.equals(RecommendationLocal.class)) {
leaf = new RecommendationLocal(selectedService);
} else if (aClass.equals(DiagnosisLocal.class)) {
leaf = new DiagnosisLocal(selectedService);
} else if (aClass.equals(PrescriptionDloLocal.class)) {
leaf = new PrescriptionDloLocal(selectedService);
} else {
throw new ClipsException("Попытка создать объект не учтённого типа");
}
if (leaf != null) {
System.out.println("PANEL EMC, LEAF " + leaf + " ADD TO SERVICE " + selectedService);
selectedService.addChild(leaf);
}
} catch (ClipsException e) {
MessageBox.showException(e);
}
}
}
private void btQuickInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btQuickInputActionPerformed
if (!isInnerPanelClear()) {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
} else {
try {
//Попытка найти текущее заболевание
DiseaseLocal selectedDisease = selectedDiseaseNode != null ? selectedDiseaseNode.getDelegate() : null;
DialogQuickInput dlg = new DialogQuickInput(MainWindow.mainWindow, emcLocal, selectedDisease, getAuditManager());
dlg.setVisible(true);
if (dlg.getDlgResult() == ModalDialog.DLG_OK && dlg.getResult() != null) {
DisSerDiagAuditChunk result = dlg.getResult();
// AuditFrame auditDlg = AuditFrame.getDialog();
// auditDlg.showMe(result.auditDetailsList);
getAuditManager().needDSA(new AuditList(result.auditDetailsList));
ClientNode root = (ClientNode) treeEMC.getModel().getRoot();
DiseaseLocal newDisease = new DiseaseLocal(emcLocal, result.diseaseDetails, getAuditManager());
EmcTreeNode findNode = root.findNode(newDisease);
boolean needAddToEmc = false;
if (findNode != null) {
selectedDisease = (DiseaseLocal) findNode.getDelegate();
} else {
selectedDisease = newDisease;
needAddToEmc = true;
}
if (needAddToEmc) {
emcLocal.addChild(selectedDisease);
} else {
SerRenLocal serRenLocal = new SerRenLocal(selectedDisease, result.serrenDetails, getAuditManager());
selectedDisease.addChild(serRenLocal);
}
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}//GEN-LAST:event_btQuickInputActionPerformed
private void miDICOMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miDICOMActionPerformed
CheckupLocal checkup = getSelectedCheckup();
if (checkup != null) {
try {
DialogSelectDicomObjects dsdo = new DialogSelectDicomObjects(MainWindow.mainWindow);
dsdo.setVisible(true);
if (dsdo.getDlgResult() == ModalDialog.DLG_OK) {
List<AgregatorItem> items = dsdo.getItems();
for (AgregatorItem agregatorItem : items) {
checkup.addChild(new CheckupDICOMLocal(checkup, agregatorItem));
}
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}//GEN-LAST:event_miDICOMActionPerformed
private void treeEMCKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_treeEMCKeyPressed
if (Main.DEVELOPED_ON){
EmcTreeNode currentSelectedNode = getCurrentSelectedNode();
if (evt.getKeyCode() == KeyEvent.VK_I && evt.isControlDown() && currentSelectedNode != null){
MessageBox.showInfo("Выделение: " + currentSelectedNode.getDelegate().getClass().getSimpleName() + " [id: " + currentSelectedNode.getDelegate().getID() + "]");
}
}
}//GEN-LAST:event_treeEMCKeyPressed
private void miDloDrugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miDloDrugActionPerformed
try {
if (!UserInfo.get().getCollaborator().isDlo()) {
throw new ClipsException("Вы не обладаете правом выписки льготных рецептов");
}
if (!clientLocal.hasRightNSU()) {
throw new ClipsException("Пациент не обладает правом получения льготных рецептов");
}
addDelegateToService(PrescriptionDloLocal.class);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_miDloDrugActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btAdd;
private javax.swing.JButton btCertificate;
private javax.swing.JButton btFollowUp;
private javax.swing.JButton btNewDisease;
private javax.swing.JButton btQuickInput;
private javax.swing.JButton btRemove;
private javax.swing.JButton btSicklist;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel jPanel8;
private javax.swing.JPopupMenu jPopupMenu1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JMenuItem miAddReferedService;
private javax.swing.JMenuItem miCheckup;
private javax.swing.JMenuItem miContraindication;
private javax.swing.JMenuItem miDICOM;
private javax.swing.JMenuItem miDiagnosis;
private javax.swing.JMenuItem miDirection;
private javax.swing.JMenuItem miDloDrug;
private javax.swing.JMenuItem miPrescription;
private javax.swing.JMenuItem miRecomendation;
private javax.swing.JPanel pnlView;
private javax.swing.JTree treeEMC;
// End of variables declaration//GEN-END:variables
private void resetPage(PageGeneric page) throws PageException{
boolean force = (innerPage != null && innerPage.getDelegate() != null)
? innerPage.getDelegate().isNewlyCreated()
: false;
removePage(innerPage, force);
addNewPage(page, null);
}
@Override
public PageGeneric addNewPage(PageGeneric pageToAdd, PageGeneric afterPage) throws PageException {
if (innerPage == null) {
innerPage = pageToAdd;
if (pageToAdd.getDelegate() != null && pageToAdd.getDelegate().isNewlyCreated()){
currentCreatedDelegate = pageToAdd.getDelegate();
currentCreatedDelegate.addContentStateListener(this);
}
pnlView.add((JPanel) pageToAdd);
pnlView.revalidate();
contentStateChanged();
return pageToAdd;
} else {
throw new PageException("Страница не может быть добавлена");
}
}
@Override
public void removePage(PageGeneric page, boolean forced) throws PageException {
if (page == null) {
return;
}
if (this.innerPage == page) {
if (page instanceof ActivateSensitive) {
ActivateSensitive as = (ActivateSensitive) page;
as.beforeDeactivate();
}
boolean canBeRemove = true;
if (!forced && (page instanceof Persistentable) && (((Persistentable) page).isDirty())) {
canBeRemove = false;
}
if (canBeRemove) {
pnlView.removeAll();
repaint();
this.innerPage = null;
fireContainerEventStateChanged();
jPanel6.removeAll();
}
} else {
throw new PageException("Попытка удалить неизвестную страницу");
}
}
@Override
public void activatePage(PageGeneric page) throws PageException {
throw new PageException("Не должно быть реализовано");
}
@Override
public void contentStateChanged() {
getContainer().contentStateChanged();
setEnabledComponents();
}
@Override
public boolean isDirty() {
if (innerPage != null) {
boolean res = (innerPage instanceof Persistentable)
? ((Persistentable) innerPage).isDirty()
: false;
return res;
} else {
return false;
}
}
@Override
public void save() throws ClipsException {
if (innerPage != null){
Persistentable p = (Persistentable) innerPage;
p.save();
if (!p.isDirty()){
currentCreatedDelegate = null;
}
}
setEnabledComponents();
}
@Override
@SuppressWarnings("unchecked")
public void restore() {
if (innerPage.getDelegate() != null && innerPage.getDelegate().isNewlyCreated()){
try {
EmcTreeNode node = getCurrentSelectedNode();
if (node != null){
EmcTreeNode parent = node.getParent();
if (parent != null){
DelegateLine2 delegate = innerPage.getDelegate();
parent.getDelegate().removeChild((DelegateNodeInterface) delegate);
lastSelectionPath = null;
}
}
} catch (ClipsException ex) {
ex.printStackTrace();
}
}
if (innerPage != null && innerPage instanceof Persistentable){
((Persistentable) innerPage).restore();
}
currentCreatedDelegate = null;
setEnabledComponents();
}
@Override
public PageGeneric getActivePage() {
return innerPage;
}
@Override
public int getPageCount() {
return (innerPage == null) ? 0 : 1;
}
@Override
public PageGeneric getPage(int index) {
return innerPage;
}
@Override
public String getPageTitle() {
return "ЭМК: " + clientLocal.toString();
}
@Override
public boolean readyForPrint() {
if (innerPage != null) {
if (innerPage instanceof Printable) {
return ((Printable)innerPage).readyForPrint();
}
return false;
}
return !isDirty();
}
@Override
public void print() {
try {
if (readyForPrint()) {
if (innerPage != null) {
((Printable)innerPage).print();
}
else {
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.horizontal);
parCreator.setUpReport(null, ops, null);
emcLocal.getClient().print(parCreator);
parCreator.finish();
}
}
}catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
@Override
public DelegateLine2 getDelegate() {
return clientLocal;
}
/**
* Переводит выделение на заданный делегат в эмк, если он в ней есть
* @param object
* @throws ClipsException
*/
public void selectInEmc(DelegateNode object) throws ClipsException{
ClientNode root = (ClientNode) treeEMC.getModel().getRoot();
EmcTreeNode node = null;
if (object instanceof CertificateLocal){
for (int i = 0; i < root.getChildCount() && node == null; i++) {
if (root.getChildAt(i) instanceof CertificateCollectorNode){
node = root.getChildAt(i).findNode((DelegateNode) object);
}
}
}else if(object instanceof SicklistLocal){
for (int i = 0; i < root.getChildCount() && node == null; i++) {
if (root.getChildAt(i) instanceof SicklistCollectorNode){
node = root.getChildAt(i).findNode((DelegateNode) object);
}
}
}else{
node = root.findNode(object);
}
if (node == null){
MessageBox.showError(MessageBox.E_MAKE_FUCKING_EXCEPTION, "Объект \"" + object + "\" не найден в ЭМК" );
}else{
selectNode(node);
}
}
private void selectNode(TreeNode node){
ArrayList<TreeNode> path = new ArrayList<TreeNode>();
while (node != null) {
path.add(0, node);
node = node.getParent();
}
treeEMC.setSelectionPath(new TreePath(path.toArray()));
}
///////////////////////////служебные классы/////////////////////////////////
private class TreeWillExpandListenerImpl implements TreeWillExpandListener {
public TreeWillExpandListenerImpl() {
}
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
EmcTreeNode current = getCurrentSelectedNode();
// System.out.println("PANEL EMC TREE, treeWillCollapse, path: " + event.getPath() + " current: " + current);
EmcTreeNode collaps = (EmcTreeNode) event.getPath().getLastPathComponent();
boolean canCollaps = true;
if (current != null) {
current = current.getParent();
while (current != null && canCollaps) {
canCollaps = !current.equals(collaps);
current = current.getParent();
}
}
canCollaps = canCollaps || isInnerPanelClear();
if (!canCollaps) {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
throw new ExpandVetoException(event);
}
}
}
private class TreeSelectionListenerImpl implements TreeSelectionListener {
public TreeSelectionListenerImpl() {
}
@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath path = e.getNewLeadSelectionPath();
if (path != null) {
Object lastPathComponent = path.getLastPathComponent();
if (lastPathComponent != null) {
EmcTreeNode node = (EmcTreeNode) lastPathComponent;
try {
resetPage(node.getPanel(PanelEMC.this));
if (node.getDelegate() instanceof Signable){
Signable s = (Signable) node.getDelegate();
addECPPanel(s);
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}else{
try {
removePage(innerPage, true);
} catch (PageException ex) {
MessageBox.showException(ex);
}
}
setEnabledComponents();
}
}
private class DefaultTreeSelectionModelImpl extends DefaultTreeSelectionModel {
public DefaultTreeSelectionModelImpl() {
}
@Override
public void setSelectionPath(TreePath path) {
if (!path.equals(currentSelectionPath)) {
if (isInnerPanelClear() || nodeRemoving) {
lastSelectionPath = currentSelectionPath;
super.setSelectionPath(path);
currentSelectionPath = path;
if (!treeEMC.isVisible(path)) {
JScrollBar hScrollBar = jScrollPane1.getHorizontalScrollBar();
int value = hScrollBar.getValue();
treeEMC.scrollPathToVisible(path);
hScrollBar.setValue(value);
}
} else {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
}
}
}
@Override
public void removeSelectionPath(TreePath path) {
if (isInnerPanelClear()) {
super.removeSelectionPath(path);
} else {
MessageBox.showWarning(MessageBox.W_NOT_CLOSE_EDITING);
}
}
}
private class TreeCellRendererImpl implements TreeCellRenderer {
// private JLabel label = new JLabel();
private DefaultTreeCellRenderer label;
public TreeCellRendererImpl() {
label = new DefaultTreeCellRenderer();
}
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
label = (DefaultTreeCellRenderer) label.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
try{
if (value instanceof EmcTreeNode) {
label.setIcon(((EmcTreeNode) value).getIcon());
}
if (value instanceof HasColors){
label.setForeground(((HasColors)value).getForeground());
}
// if (selected && value instanceof HasColors) {
// Color foreground = ((HasColors) value).getForeground();
// label.setForeground(DefaultColors.middle(label.getForeground(), foreground));
// }
}catch(Exception e){
Log.printlnAnsPos(e.getMessage());
label.setIcon(null);
label.setForeground(Color.RED);
}
return label;
}
}
private class TreeModelListenerImpl implements TreeModelListener {
private final DefaultTreeModel model;
public TreeModelListenerImpl(DefaultTreeModel model) {
this.model = model;
}
@Override
public void treeNodesChanged(TreeModelEvent e) {
// System.out.println("treeNodesChanged: " + e);
contentStateChanged();
}
@Override
public void treeNodesInserted(TreeModelEvent e) {
// System.out.println("treeNodesInserted: " + e);
if (e.getChildIndices().length > 0) {
int index = e.getChildIndices()[0];
Object[] path = e.getPath();
TreePath treePath = new TreePath(path);
Object object = treePath.getLastPathComponent();
if (object != null) {
TreeNode node = ((EmcTreeNode) object).getChildAt(index);
TreeNode[] pathToRoot = model.getPathToRoot(node);
treeEMC.setSelectionPath(new TreePath(pathToRoot));
} else {
// System.out.println("------CAN SELECT 1------");
}
} else {
// System.out.println("------CAN SELECT 2------");
}
}
@Override
public void treeNodesRemoved(TreeModelEvent e) {
// System.out.println("treeNodesRemoved: " + e);
nodeRemoving = true;
if (lastSelectionPath == null){
treeEMC.setSelectionPath(new TreePath(e.getPath()));
}else{
treeEMC.setSelectionPath(lastSelectionPath);
}
nodeRemoving = false;
}
@Override
public void treeStructureChanged(TreeModelEvent e) {
// System.out.println("treeStructureChanged: " + e);
}
}
}