Subversion Repository Public Repository

Pharmacy_09_03_18

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcareemr.Views;

import com.bestray.healthcarecommonutil.controller.MyFavController;
import com.bestray.healthcarecommonutil.exception.HealthCareException;
import com.bestray.healthcarecommonutil.exception.ProcessingException;
import com.bestray.healthcarecommonutil.util.DisabledGlassPane;
import com.bestray.healthcarecommonutil.util.HeadingPanel;
import com.bestray.healthcarecommonutil.util.PanelType;
import com.bestray.healthcarecommonutil.util.PreferenceUtil;
import com.bestray.healthcarecommonutil.util.SimpleGradientPanel;
import com.bestray.healthcarecommonutil.util.TextPrompt;
import com.bestray.healthcarecommonutil.util.Theme;
import com.bestray.healthcarecommonutil.views.MyFavMedicationSearchDialog;
import com.bestray.healthcarecommonutil.vo.TAccount;
import com.bestray.healthcarecommonutil.vo.TEncounterMedication;
import com.bestray.healthcarecommonutil.vo.TMedicationMaster;
import com.bestray.healthcarecommonutil.vo.TPatient;
import com.bestray.healthcarecommonutil.vo.TPatientEncounter;
import com.bestray.healthcareemr.Controller.AmbulatoryMedicationController;
import com.bestray.healthcareemr.Controller.MedicationMasterController;
import com.bestray.healthcareemr.Controller.OutPatientController;
import com.bestray.healthcareemr.Util.MessageProperties;
import com.bestray.healthcareemr.reports.MedicationReport;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;

/**
 *
 * @author User1
 */
public class AmbulatoryMedicationPanel extends javax.swing.JPanel {

    /**
     * Creates new form AmbulatoryMedicationPanel
     */
    public AmbulatoryMedicationPanel() {
        initComponents();
        TextPrompt tp7 = new TextPrompt("Search For Medications", search_textField);
        tp7.setForeground( Color.RED );
        tp7.changeAlpha(0.5f);
        tp7.changeStyle(Font.BOLD);
    }
    
    public AmbulatoryMedicationPanel(TPatientEncounter encounter) {
        this.encounter = encounter;
        populateData();
        initComponents();
        TextPrompt tp7 = new TextPrompt("Search For Medications", search_textField);
        tp7.setForeground( Color.RED );
        tp7.changeAlpha(0.5f);
        tp7.changeStyle(Font.BOLD);
        medicationTableModel();
        fetchCurrentMedication();
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        medicatonTable = new javax.swing.JTable(){

            public boolean isCellEditable(int row, int column){
                return false;
            }
            public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) {
                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
                if (rowIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) {
                    c.setForeground(Color.BLACK);
                    c.setBackground(new Color(200, 225, 250));
                }
                else if(rowIndex % 2 == 0 && isCellSelected(rowIndex, vColIndex)){
                    c.setForeground(Color.WHITE);
                    c.setBackground(Color.BLUE);
                }
                else if(rowIndex % 2 != 0 && isCellSelected(rowIndex, vColIndex)){
                    c.setForeground(Color.WHITE);
                    c.setBackground(Color.BLUE);
                }
                else {
                    c.setForeground(Color.BLACK);
                    c.setBackground(getBackground());
                }
                return c;
            }

        };
        jToolBar2 = new javax.swing.JToolBar();
        remove_medication_button = new javax.swing.JButton();
        edit_button = new javax.swing.JButton();
        taking_button = new javax.swing.JButton();
        reorder_button = new javax.swing.JButton();
        prev_medi_button = new javax.swing.JButton();
        print_button = new javax.swing.JButton();
        jPanel2 = new HeadingPanel("", Theme.GLOSSY_SKYBLUE_THEME, PanelType.PANEL_ROUNDED_RECTANGLUR);
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel3 = new SimpleGradientPanel();
        search_textField = new javax.swing.JTextField();
        jToolBar1 = new javax.swing.JToolBar();
        search_button = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setLayout(new java.awt.BorderLayout());

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        medicatonTable.setAutoCreateRowSorter(true);
        medicatonTable.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
        medicatonTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        medicatonTable.setRowHeight(25);
        medicatonTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        medicatonTable.setShowHorizontalLines(false);
        medicatonTable.setShowVerticalLines(false);
        medicatonTable.getTableHeader().setReorderingAllowed(false);
        medicatonTable.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 10));
        jScrollPane1.setViewportView(medicatonTable);

        jToolBar2.setBackground(new java.awt.Color(204, 204, 255));
        jToolBar2.setFloatable(false);
        jToolBar2.setRollover(true);

        remove_medication_button.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
        remove_medication_button.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete 16x16.png"))); // NOI18N
        remove_medication_button.setText("Remove");
        remove_medication_button.setFocusable(false);
        remove_medication_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        remove_medication_button.setOpaque(false);
        remove_medication_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                remove_medication_buttonActionPerformed(evt);
            }
        });
        jToolBar2.add(remove_medication_button);
        remove_medication_button.setVisible(false);

        edit_button.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
        edit_button.setText("Edit Details");
        edit_button.setFocusable(false);
        edit_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        edit_button.setOpaque(false);
        edit_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edit_buttonActionPerformed(evt);
            }
        });
        jToolBar2.add(edit_button);

        taking_button.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
        taking_button.setText("Taking / Not Taking");
        taking_button.setFocusable(false);
        taking_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        taking_button.setOpaque(false);
        taking_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                taking_buttonActionPerformed(evt);
            }
        });
        jToolBar2.add(taking_button);

        reorder_button.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
        reorder_button.setText("Reorder / Not Reorder");
        reorder_button.setFocusable(false);
        reorder_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        reorder_button.setOpaque(false);
        reorder_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reorder_buttonActionPerformed(evt);
            }
        });
        reorder_button.setVisible(false);
        jToolBar2.add(reorder_button);

        prev_medi_button.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
        prev_medi_button.setText("Previeous Medications");
        prev_medi_button.setFocusable(false);
        prev_medi_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        prev_medi_button.setOpaque(false);
        prev_medi_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prev_medi_buttonActionPerformed(evt);
            }
        });
        jToolBar2.add(prev_medi_button);

        print_button.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
        print_button.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/print 16.png"))); // NOI18N
        print_button.setText("Generate Medication Receipt");
        print_button.setFocusable(false);
        print_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        print_button.setOpaque(false);
        print_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                print_buttonActionPerformed(evt);
            }
        });
        jToolBar2.add(print_button);

        jPanel2.setBackground(new java.awt.Color(127, 180, 234));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Text-Edit-icon24X24.png"))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Medication Details");

        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(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addComponent(jLabel1)
                .addGap(5, 5, 5))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        search_textField.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N

        jToolBar1.setBackground(new java.awt.Color(255, 255, 255));
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setOpaque(false);

        search_button.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
        search_button.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/search-icon16X16.png"))); // NOI18N
        search_button.setText("Search");
        search_button.setFocusable(false);
        search_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        search_button.setOpaque(false);
        search_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                search_buttonActionPerformed(evt);
            }
        });
        jToolBar1.add(search_button);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(search_textField, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(search_textField)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(8, 8, 8))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 1026, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );

        add(jPanel1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void search_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_search_buttonActionPerformed
        medicaineList = new Vector<TMedicationMaster>();
        rootPane = SwingUtilities.getRootPane(this);
        glassPane = new DisabledGlassPane();
        if(search_textField.getText().length()>=0){
            try {
                expr = search_textField.getText().toUpperCase();
                SwingWorker s = new SwingWorker() {

                    @Override
                    protected Object doInBackground() throws Exception {
                        rootPane.setGlassPane(glassPane);
                        glassPane.activateLoadingImage();
                        if(expr.length()>0){
                            List<TMedicationMaster> mlist = new ArrayList<TMedicationMaster>();
                            mlist = medicationController.getMedicationByName(expr);
                            for(TMedicationMaster m:mlist){
                                medicaineList.add(m);
                            }
                        }else{
                            medicaineList = medicationController.getAllMedication();
                        }
                        return medicaineList;
                    }

                    @Override
                    protected void done() {
                        if(medicaineList.size()>0){
                            super.done();
                            myFavMedicineList = new Vector<TMedicationMaster>();
                            try {
                                myFavMedicineList = myFavController.getFavMedicationByAccount(useraccount,"MEDICATION");
                            } catch (ProcessingException ex) {
                                Logger.getLogger(EncounterFollowupPanel.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            glassPane.deactivate();
                            glassPane.activate("");
                            MyFavMedicationSearchDialog medicationSearchDialog = new MyFavMedicationSearchDialog(MainAPP, true,medicaineList,myFavMedicineList,expr);
                            medicationSearchDialog.setResizable(false);
                            medicationSearchDialog.setLocationRelativeTo(null);
                            medicationSearchDialog.setVisible(true);
                            medicationSearchDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
                            glassPane.deactivate();
                            List<TMedicationMaster> medic = medicationSearchDialog.getMedicationList();
                            if(medic!=null){
                                if(isDuplicateMedication(medic)){
                                    int reply = JOptionPane.showConfirmDialog(null, "Do you want to add ?", " Message", JOptionPane.YES_NO_OPTION);
                                    if(reply == JOptionPane.YES_OPTION){
                                        showSelectedMedication(medic);
                                    }else{
                                     //do some thing 
                                    }
                                }else{
                                  showSelectedMedication(medic);
                                }
                                
                            }
                        }else{
                            JOptionPane.showMessageDialog(null, "No medication present");
                            glassPane.deactivate();
                            search_textField.setText(null);
                        }
                    }
                };
                s.execute();
            } catch (Exception ex) {
                Logger.getLogger(OutPatientEncounterPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }else{
            JOptionPane.showMessageDialog(null, "Search filed is empty");
        }
    }//GEN-LAST:event_search_buttonActionPerformed

    private void remove_medication_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove_medication_buttonActionPerformed
        int row = medicatonTable.getSelectedRow();
        model = (DefaultTableModel) medicatonTable.getModel();
            if(row!=-1){
                    TEncounterMedication medication = (TEncounterMedication)medicatonTable.getValueAt(row, 0);
                    model.removeRow(row);
                    removeMedication(medication.getId());               
            }else{
                JOptionPane.showMessageDialog(null, "No medication selected for delete");
            }
    }//GEN-LAST:event_remove_medication_buttonActionPerformed

    private void taking_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_taking_buttonActionPerformed
        int row = medicatonTable.getSelectedRow();
            try {
            if(row!=-1){
                String status = medicatonTable.getValueAt(row, 7).toString();
                String orderStatus = medicatonTable.getValueAt(row, 8).toString();
                    if(!orderStatus.equalsIgnoreCase("Reordered")){
                        if(status.equalsIgnoreCase("taking")){
                                TEncounterMedication encounterMedication = (TEncounterMedication)medicatonTable.getValueAt(row, 0);
                                encounterMedication.setEncounterMed(encounterMedication.getEncounterMed());
                                encounterMedication.setMedication((TMedicationMaster)medicatonTable.getValueAt(row, 1));
                                encounterMedication.setStatus(0);
                                ambulatoryMedicationController.updateMedicationEncounter(encounterMedication);
                                medicationTableModel();
                                fetchCurrentMedication();
                        }
                    }else{
                        JOptionPane.showMessageDialog(null, "First Cancel the ReOrder...");
                    }
            }else{
                JOptionPane.showMessageDialog(null, "Select a record to change the status");
            }
            } catch (ProcessingException ex) {
                                Logger.getLogger(AmbulatoryMedicationPanel.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (HibernateOptimisticLockingFailureException ex) {
                                Logger.getLogger(AmbulatoryMedicationPanel.class.getName()).log(Level.SEVERE, null, ex);
                            }
        
    }//GEN-LAST:event_taking_buttonActionPerformed

    private void prev_medi_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prev_medi_buttonActionPerformed
        getPreviousMedication(0); // 0 for not taking
        DisabledGlassPane glassPane = new DisabledGlassPane();
        JRootPane rootPane = SwingUtilities.getRootPane(this);
        rootPane.setGlassPane(glassPane);
        PreviousMedicationDialog preferenceListDialog = new PreviousMedicationDialog(MainAPP, true, encPreviousMedication);
        preferenceListDialog.setResizable(false);
        preferenceListDialog.setLocationRelativeTo(null);
        glassPane.activate("");
        preferenceListDialog.setVisible(true);
        preferenceListDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        glassPane.deactivate();
    }//GEN-LAST:event_prev_medi_buttonActionPerformed

    private void reorder_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reorder_buttonActionPerformed
        int row = medicatonTable.getSelectedRow();
        try {
            if(row!=-1){
                String reorderstatus = medicatonTable.getValueAt(row, 8).toString();
                    if(reorderstatus.equalsIgnoreCase("Reordered")){
                        TEncounterMedication encounterMedication = (TEncounterMedication)medicatonTable.getValueAt(row, 0);
                        encounterMedication.setEncounterMed(encounterMedication.getEncounterMed());
                        encounterMedication.setMedication((TMedicationMaster)medicatonTable.getValueAt(row, 1));
                        encounterMedication.setStatus(1);
                        ambulatoryMedicationController.updateMedicationEncounter(encounterMedication);
                        TEncounterMedication encMedication = new TEncounterMedication();
                        encMedication.setEncounterMed(encounter);
                        encMedication.setMedication((TMedicationMaster)medicatonTable.getValueAt(row, 1));
                        encMedication.setStatus(0);
                        ambulatoryMedicationController.saveMedicationEncounter(encMedication);
                        medicationTableModel();
                        fetchCurrentMedication();
                    }else{
                        TEncounterMedication encounterMedication = (TEncounterMedication)medicatonTable.getValueAt(row, 0);
                        encounterMedication.setEncounterMed(encounterMedication.getEncounterMed());
                        encounterMedication.setMedication((TMedicationMaster)medicatonTable.getValueAt(row, 1));
                        encounterMedication.setStatus(0);
                        ambulatoryMedicationController.updateMedicationEncounter(encounterMedication);
                        TEncounterMedication encMedication = new TEncounterMedication();
                        encMedication.setEncounterMed(encounter);
                        encMedication.setMedication((TMedicationMaster)medicatonTable.getValueAt(row, 1));
                        encMedication.setStatus(1);
                        ambulatoryMedicationController.saveMedicationEncounter(encMedication);
                        medicationTableModel();
                        fetchCurrentMedication();
                        
                }
            }else{
                JOptionPane.showMessageDialog(null, "Select a record to reorder");
            }
            } catch (ProcessingException ex) {
                        Logger.getLogger(AmbulatoryMedicationPanel.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (HibernateOptimisticLockingFailureException ex) {
                        Logger.getLogger(AmbulatoryMedicationPanel.class.getName()).log(Level.SEVERE, null, ex);
                    }
    }//GEN-LAST:event_reorder_buttonActionPerformed

    private void print_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_print_buttonActionPerformed
        medicationReport = new MedicationReport();
        patientinfo = encounter.getPatient();
        String patientName = patientinfo.getPatientFName();
        Long patientId = patientinfo.getId();
                try {
                    medicationReport.getPdfReport(patientId,patientName);
                } catch (Exception ex) {
                    Logger.getLogger(OpenEncounterDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                medicationReport.openPdfReport();
    }//GEN-LAST:event_print_buttonActionPerformed

    private void edit_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edit_buttonActionPerformed
        TEncounterMedication medicationDetails = new TEncounterMedication();
            try{
                int row = medicatonTable.getSelectedRow();
                    medicationDetails.setMedication((TMedicationMaster)(medicatonTable.getValueAt(row, 1)));
                    medicationDetails.setDose(String.valueOf(medicatonTable.getValueAt(row, 3)));
                    medicationDetails.setFrequency(String.valueOf(medicatonTable.getValueAt(row, 4)));
                    medicationDetails.setRoute(String.valueOf(medicatonTable.getValueAt(row, 5)));
                    medicationDetails.setComments(String.valueOf(medicatonTable.getValueAt(row, 6)));
                    DisabledGlassPane glassPane = new DisabledGlassPane();
                    JRootPane rootPane = SwingUtilities.getRootPane(this);
                    rootPane.setGlassPane(glassPane);
                    MedicationModificationDialoge medicationModificationDialog = new MedicationModificationDialoge(MainAPP, true, medicationDetails);
                    medicationModificationDialog.setResizable(false);
                    medicationModificationDialog.setLocationRelativeTo(null);
                    glassPane.activate("");
                    medicationModificationDialog.setVisible(true);
                    medicationModificationDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
                    glassPane.deactivate();
                    TEncounterMedication medication = medicationModificationDialog.getMedication();
                    if(medication!=null){
                        TEncounterMedication encounterMedication = (TEncounterMedication)medicatonTable.getValueAt(row, 0);
                        encounterMedication.setEncounterMed(encounterMedication.getEncounterMed());
                        encounterMedication.setMedication(encounterMedication.getMedication());
                        encounterMedication.setDose(medication.getDose());
                        encounterMedication.setFrequency(medication.getFrequency());
                        encounterMedication.setRoute(medication.getRoute());
                        encounterMedication.setComments(medication.getComments());
                        TEncounterMedication encMed = ambulatoryMedicationController.updateMedicationEncounter(encounterMedication);
                        medicatonTable.setValueAt(encMed,row,0);
                        medicatonTable.setValueAt(encMed.getMedication(),row,1);
                        medicatonTable.setValueAt(encMed.getMedication().getMedicationName(), row, 2);
                        medicatonTable.setValueAt(encMed.getDose(), row, 3);
                        medicatonTable.setValueAt(encMed.getFrequency(), row, 4);
                        medicatonTable.setValueAt(encMed.getRoute(), row, 5);
                        medicatonTable.setValueAt(encMed.getComments(), row, 6);
                    }
            }catch(Exception e){
                e.printStackTrace();
                JOptionPane.showMessageDialog(null, MessageProperties.getMessage("notselected.edit"));
            }
    }//GEN-LAST:event_edit_buttonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton edit_button;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JTable medicatonTable;
    private javax.swing.JButton prev_medi_button;
    private javax.swing.JButton print_button;
    private javax.swing.JButton remove_medication_button;
    private javax.swing.JButton reorder_button;
    private javax.swing.JButton search_button;
    private javax.swing.JTextField search_textField;
    private javax.swing.JButton taking_button;
    // End of variables declaration//GEN-END:variables
    private Vector<TMedicationMaster> medicaineList = new Vector<TMedicationMaster>();
    private Vector<TMedicationMaster> myFavMedicineList = new Vector<TMedicationMaster>();
    private List<TEncounterMedication> currentMedication = new ArrayList<TEncounterMedication>();
    private List<TPatientEncounter> lastVists = new ArrayList<TPatientEncounter>();
    private TPatientEncounter encounter = new TPatientEncounter();
    private TEncounterMedication medicationEnc = new TEncounterMedication();
    private MedicationReport medicationReport ;
    private AmbulatoryMedicationController ambulatoryMedicationController;
    private List<TEncounterMedication> encPreviousMedication;
    private MyFavController myFavController;
    private MedicationMasterController medicationController;
    private OutPatientController outPatientController;
    private TAccount useraccount;
    private TPatient patientinfo;
    private Preferences myPrefObj = Preferences.userRoot();
    private JRootPane rootPane;
    private DisabledGlassPane glassPane;
    private Vector<Object> addObject;
    private DefaultTableModel model;
    private DefaultListModel listModel;
    private JFrame MainAPP;
    private String expr;
    

    private void populateData() {
        outPatientController = (OutPatientController)HealthcareLogin.context.getBean("outPatientController");
        ambulatoryMedicationController = (AmbulatoryMedicationController)HealthcareLogin.context.getBean("ambulatoryMedicationController");
        medicationController=(MedicationMasterController)HealthcareLogin.context.getBean("medicationMasterController");
        myFavController = (MyFavController)HealthcareLogin.context.getBean("myFavController");
        try{
            lastVists = outPatientController.getEncounterDates(encounter.getPatient());
            useraccount = (TAccount)PreferenceUtil.getObject(myPrefObj, "user");
        }catch(Exception e){
             JOptionPane.showMessageDialog(null,MessageProperties.getMessage("error.fetch",new Object[]{"Current ueser details"}));
             throw new HealthCareException(MessageProperties.getMessage("error.dao"));
        }
    }
    
    private void medicationTableModel() {
        medicatonTable.setModel(new javax.swing.table.DefaultTableModel(new Object [][] {},new String [] {
                "Obj", "medicineObj", "Name", "Dose", "Frequency", "Route", "Comments", "Status", "Reorder"}));
        medicatonTable.getColumnModel().getColumn(0).setMinWidth(0);
        medicatonTable.getColumnModel().getColumn(0).setPreferredWidth(0);
        medicatonTable.getColumnModel().getColumn(0).setMaxWidth(0);
        medicatonTable.getColumnModel().getColumn(1).setMinWidth(0);
        medicatonTable.getColumnModel().getColumn(1).setPreferredWidth(0);
        medicatonTable.getColumnModel().getColumn(1).setMaxWidth(0);
    }

    private boolean isDuplicateMedication(List<TMedicationMaster> medictionList){
        
        boolean valid = false;
        if(medicatonTable.getRowCount() > 0){
          for (int row = 0; row < medicatonTable.getRowCount(); row++) {
            TMedicationMaster med = (TMedicationMaster)medicatonTable.getValueAt(row, 1);
            if(medictionList.contains(med)){
                 valid = true;   
            }
          } 
        }
        return valid;
    }
    
    private void fetchCurrentMedication() {
        try {
            currentMedication = ambulatoryMedicationController.getEncounterMedication(lastVists,1);
        } catch (ProcessingException ex) {
            Logger.getLogger(OutPatientEncounterPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        showCurrentMedication(currentMedication);
    }

    private void showCurrentMedication(List<TEncounterMedication> currentMedication) {
        model = (DefaultTableModel)medicatonTable.getModel();
        for(TEncounterMedication m:currentMedication){
             addObject = new Vector<Object>();
             addObject.add(m);
             addObject.add(m.getMedication());
             addObject.add(m.getMedication().getMedicationName());
             if(m.getDose()!=null){
                 addObject.add(m.getDose());
             }else{
                 addObject.add("");
             }
             if(m.getFrequency()!=null){
                 addObject.add(m.getFrequency());
             }else{
                 addObject.add("");
             }
             if(m.getRoute()!=null){
                 addObject.add(m.getRoute());
             }else{
                 addObject.add("");
             }
             if(m.getComments()!=null){
                 addObject.add(m.getComments());
             }else{
                 addObject.add("");
             }
             if(m.getStatus()==1){
                 addObject.add("Taking");
             }else{
                 addObject.add("Not Taking");
             }
             addObject.add("");
             model.addRow(addObject);
        }
    
    }
    /*show selected medication by encounter*/
    private void showSelectedMedication(List<TMedicationMaster> medicines) {
        model = (DefaultTableModel)medicatonTable.getModel();
       for(TMedicationMaster medicine : medicines){
           addObject = new Vector<Object>();  
           TEncounterMedication encounterMedication = new TEncounterMedication();
           encounterMedication.setEncounterMed(encounter);
           encounterMedication.setMedication(medicine);
           encounterMedication.setDose(medicine.getMedicationDose());
           encounterMedication.setFrequency(medicine.getMedicationFrequency());
           encounterMedication.setRoute(medicine.getMedicationAdministration());
           encounterMedication.setComments("");
           encounterMedication.setStatus(1);
            try {
                medicationEnc = ambulatoryMedicationController.saveMedicationEncounter(encounterMedication);
                addObject.add(medicationEnc);
                addObject.add(medicationEnc.getMedication());
                addObject.add(medicationEnc.getMedication().getMedicationName());
                addObject.add(medicationEnc.getDose());
                addObject.add(medicationEnc.getFrequency());
                addObject.add(medicationEnc.getRoute());
                addObject.add(medicationEnc.getComments());
                if(medicationEnc.getStatus()==1){
                 addObject.add("Taking");
             }else{
                 addObject.add("Not Taking");
             }
                addObject.add("");
                model.addRow(addObject);
            } catch (ProcessingException ex) {
                Logger.getLogger(AmbulatoryMedicationPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
       }
    }
    /*remove medication from encounter*/
    private void removeMedication(Long removeMedicationId){
            try {
                ambulatoryMedicationController.deleteEncounterMedications(removeMedicationId);
            } catch (ProcessingException ex) {
                Logger.getLogger(AmbulatoryMedicationPanel.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalArgumentException ex) {
                Logger.getLogger(AmbulatoryMedicationPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
    }
     
    private void getPreviousMedication(int status){
        try {
            encPreviousMedication = outPatientController.getEncounterMedication(lastVists,status);
        } catch (ProcessingException ex) {
            Logger.getLogger(OutPatientEncounterPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        listModel = new DefaultListModel();
        for(TEncounterMedication m:encPreviousMedication){
            listModel.addElement(m.getMedication());
        }
    }
}

Commits for Pharmacy_09_03_18/Dr Gyana ProjectSpace/DrGyanaEMR/src/main/java/com/bestray/healthcareemr/Views/AmbulatoryMedicationPanel.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Fri 27 Jul, 2018 07:30:57 +0000