Subversion Repository Public Repository

KNH_Project

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
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcareinpatient.view;

import com.bestray.healthcarecommonutil.exception.HealthCareException;
import com.bestray.healthcarecommonutil.exception.ProcessingException;
import com.bestray.healthcarecommonutil.util.AutoSuggestorMedication;
import com.bestray.healthcarecommonutil.util.DisabledGlassPane;
import com.bestray.healthcarecommonutil.util.Initcap;
import com.bestray.healthcarecommonutil.util.SimpleGradientPanel;
import com.bestray.healthcarecommonutil.vo.TEncounterMedication;
import com.bestray.healthcarecommonutil.vo.TEncounterProcedure;
import com.bestray.healthcarecommonutil.vo.TInpatentAdmission;
import com.bestray.healthcarecommonutil.vo.TMedicationMaster;
import com.bestray.healthcarecommonutil.vo.TPatientEncounter;
import com.bestray.healthcareinpatient.controller.InPatientRoundingController;
import com.bestray.healthcareinpatient.util.MessageProperties;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

/**
 *
 * @author user3
 */
public class MedicationPanel extends javax.swing.JPanel {

    /**
     * Creates new form MedicationPanel
     */
    public MedicationPanel(TPatientEncounter enc,TInpatentAdmission inPatAdmission) {
        this.encounter = enc;
        this.inpatadmission=inPatAdmission;
        populate();
        initComponents();
        new AutoSuggestorMedication().suggesting(medication_combobox, medicationList);
        getCurrentMedications(1);
    }

    /**
     * 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 SimpleGradientPanel(Color.WHITE, Color.LIGHT_GRAY);
        medicationspanel = new javax.swing.JPanel();
        jSplitPane5 = new javax.swing.JSplitPane();
        jScrollPane12 = new javax.swing.JScrollPane();
        jPanel14 = new javax.swing.JPanel();
        jToolBar7 = new javax.swing.JToolBar();
        jLabel21 = new javax.swing.JLabel();
        jToolBar8 = new javax.swing.JToolBar();
        addmedication_button = new javax.swing.JButton();
        remove_medication_button = new javax.swing.JButton();
        taking_button = new javax.swing.JButton();
        reorder_button = new javax.swing.JButton();
        prev_medi_button = new javax.swing.JButton();
        jPanel15 = new SimpleGradientPanel();
        jLabel40 = new javax.swing.JLabel();
        jLabel42 = new javax.swing.JLabel();
        jLabel43 = new javax.swing.JLabel();
        jLabel44 = new javax.swing.JLabel();
        jScrollPane13 = new javax.swing.JScrollPane();
        medication_comments = new javax.swing.JTextArea();
        route_textbox = new javax.swing.JTextField();
        frequency_textbox = new javax.swing.JTextField();
        medication_combobox = new javax.swing.JComboBox();
        jLabel41 = new javax.swing.JLabel();
        dose_textbox = new javax.swing.JTextField();
        jPanel22 = new SimpleGradientPanel();
        medicationscroll = new javax.swing.JScrollPane();
        medication_table = 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);
                try{
                    String id = (String)getModel().getValueAt(rowIndex, 0);
                    c.setBackground(Color.WHITE);
                    c.setForeground(Color.BLACK);
                    if(isCellSelected(rowIndex, vColIndex)){
                        c.setForeground(Color.WHITE);
                        c.setBackground(Color.BLUE);
                    }
                }catch(ClassCastException e){
                    c.setBackground(new Color(204,204,255));
                    c.setForeground(Color.BLACK);
                    if(isCellSelected(rowIndex, vColIndex)){
                        c.setForeground(Color.WHITE);
                        c.setBackground(Color.BLUE);
                    }

                }
                return c;
            }
        };

        setLayout(new java.awt.BorderLayout());

        medicationspanel.setLayout(new java.awt.BorderLayout());

        jSplitPane5.setBorder(null);
        jSplitPane5.setDividerLocation(251);
        jSplitPane5.setDividerSize(-1);
        jSplitPane5.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jScrollPane12.setBorder(null);

        jPanel14.setLayout(new java.awt.BorderLayout());

        jToolBar7.setBackground(new java.awt.Color(204, 255, 204));
        jToolBar7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jToolBar7.setFloatable(false);
        jToolBar7.setRollover(true);

        jLabel21.setFont(new java.awt.Font("SansSerif", 1, 14)); // NOI18N
        jLabel21.setText("  Medications :");
        jToolBar7.add(jLabel21);

        jPanel14.add(jToolBar7, java.awt.BorderLayout.PAGE_START);

        jToolBar8.setBackground(new java.awt.Color(204, 255, 255));
        jToolBar8.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jToolBar8.setFloatable(false);
        jToolBar8.setRollover(true);

        addmedication_button.setFont(new java.awt.Font("SansSerif", 1, 12)); // NOI18N
        addmedication_button.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Add-icon16x16.png"))); // NOI18N
        addmedication_button.setText("Add");
        addmedication_button.setFocusable(false);
        addmedication_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        addmedication_button.setOpaque(false);
        addmedication_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addmedication_buttonActionPerformed(evt);
            }
        });
        jToolBar8.add(addmedication_button);

        //remove_medication_button.setVisible(false);
        remove_medication_button.setFont(new java.awt.Font("SansSerif", 1, 12)); // NOI18N
        remove_medication_button.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/minus-icon.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);
            }
        });
        jToolBar8.add(remove_medication_button);

        taking_button.setFont(new java.awt.Font("SansSerif", 1, 12)); // NOI18N
        taking_button.setText("Taking / Not Taking");
        taking_button.setFocusable(false);
        taking_button.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        taking_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        taking_button.setOpaque(false);
        taking_button.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        taking_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                taking_buttonActionPerformed(evt);
            }
        });
        jToolBar8.add(taking_button);

        reorder_button.setFont(new java.awt.Font("SansSerif", 1, 12)); // NOI18N
        reorder_button.setText("Reorder / Not Reorder");
        reorder_button.setFocusable(false);
        reorder_button.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        reorder_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        reorder_button.setOpaque(false);
        reorder_button.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        reorder_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reorder_buttonActionPerformed(evt);
            }
        });
        jToolBar8.add(reorder_button);

        prev_medi_button.setFont(new java.awt.Font("SansSerif", 1, 12)); // NOI18N
        prev_medi_button.setText("Previous Medication");
        prev_medi_button.setFocusable(false);
        prev_medi_button.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        prev_medi_button.setMargin(new java.awt.Insets(2, 20, 2, 20));
        prev_medi_button.setOpaque(false);
        prev_medi_button.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        prev_medi_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prev_medi_buttonActionPerformed(evt);
            }
        });
        jToolBar8.add(prev_medi_button);

        jPanel14.add(jToolBar8, java.awt.BorderLayout.PAGE_END);

        jLabel40.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
        jLabel40.setText("Name :");

        jLabel42.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
        jLabel42.setText("Frequency :");

        jLabel43.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        jLabel43.setText("Route :");

        jLabel44.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
        jLabel44.setText("Comments :");

        medication_comments.setColumns(20);
        medication_comments.setRows(5);
        jScrollPane13.setViewportView(medication_comments);

        medication_combobox.setEditable(true);
        /*
        medication_combobox.setModel(new javax.swing.DefaultComboBoxModel(medicationList));
        medication_combobox.setSelectedIndex(-1);
        AutoCompleteDecorator.decorate(this.medication_combobox);*/
        medication_combobox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                medication_comboboxItemStateChanged(evt);
            }
        });

        jLabel41.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        jLabel41.setText("Dose :");

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel44)
                            .addComponent(jLabel42)
                            .addComponent(jLabel43))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(medication_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(frequency_textbox, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(route_textbox, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addComponent(jLabel41)
                        .addGap(40, 40, 40)
                        .addComponent(dose_textbox, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel40, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel40, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(medication_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(8, 8, 8)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel42)
                    .addComponent(frequency_textbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel41)
                    .addComponent(dose_textbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel43)
                    .addComponent(route_textbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel44)
                    .addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel14.add(jPanel15, java.awt.BorderLayout.CENTER);

        jScrollPane12.setViewportView(jPanel14);

        jSplitPane5.setTopComponent(jScrollPane12);

        jPanel22.setOpaque(false);

        medication_table.setAutoCreateRowSorter(true);
        medication_table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Id", "Name", "Dose", "Frequency", "Route", "Comments", "Status", "Reorder", "EncId"
            }
        ));
        medication_table.setRowHeight(21);
        medication_table.getTableHeader().setReorderingAllowed(false);
        medication_table.getColumnModel().getColumn(0).setMinWidth(0);
        medication_table.getColumnModel().getColumn(0).setPreferredWidth(0);
        medication_table.getColumnModel().getColumn(0).setMaxWidth(0);

        medication_table.getColumnModel().getColumn(8).setMinWidth(0);
        medication_table.getColumnModel().getColumn(8).setPreferredWidth(0);
        medication_table.getColumnModel().getColumn(8).setMaxWidth(0);
        medication_table.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 11));
        medication_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        medication_table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                medication_tableMouseClicked(evt);
            }
        });
        medicationscroll.setViewportView(medication_table);

        javax.swing.GroupLayout jPanel22Layout = new javax.swing.GroupLayout(jPanel22);
        jPanel22.setLayout(jPanel22Layout);
        jPanel22Layout.setHorizontalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel22Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(medicationscroll, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );
        jPanel22Layout.setVerticalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel22Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(medicationscroll, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        jSplitPane5.setRightComponent(jPanel22);

        medicationspanel.add(jSplitPane5, java.awt.BorderLayout.CENTER);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(medicationspanel, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(medicationspanel, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                    .addContainerGap()))
        );

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

    private void addmedication_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addmedication_buttonActionPerformed
        if(validateMedication()){
            try {
                encounterMedication = new TEncounterMedication();
                medication = new TMedicationMaster();
                String medname = ((JTextField)medication_combobox.getEditor().getEditorComponent()).getText();
                String medfrequency = frequency_textbox.getText();
                String meddose = dose_textbox.getText();
                String medroute = route_textbox.getText();
                String medcomments = medication_comments.getText();
                Date d = new Date();
                TMedicationMaster medications = inPatientRoundingController.getMedication(medname);
                if(medications!=null){
                    medication = medications;
                }else{
                    medication.setMedicationName(medname.toUpperCase());
                    medication.setCreatedDate(d);
                    medication.setMedicationStatus("ACTIVE");
                    medication.setMedicationDose(null);
                    medication.setMedicationFrequency(null);
                    inPatientRoundingController.saveMedicationMaster(medication);
                    medication = inPatientRoundingController.getMedication(medname);
                }
                /*if(encounter==null){
                    encounter = new TPatientEncounter();
                    encounter.setPatient(inpatadmission.getPatientId());
                    encounter.setDoctor(inpatadmission.getDoctorId());
                }*/
                encounter = getOrCreateIPEncounter(inpatadmission);
                encounterMedication.setEncounterMed(encounter);
                encounterMedication.setMedication(medication);
                if(meddose.length()>0){
                    encounterMedication.setDose(meddose);
                }else{
                    encounterMedication.setDose("-");
                }
                if(medfrequency.length()>0){
                    encounterMedication.setFrequency(medfrequency);
                }else{
                    encounterMedication.setFrequency("-");
                }
                if(medroute.length()>0){
                    encounterMedication.setRoute(medroute);
                }else{
                    encounterMedication.setRoute("-");
                }
                if(medcomments.length()>0){
                    encounterMedication.setComments(medcomments);
                }else{
                    encounterMedication.setComments("-");
                }
                encounterMedication.setStatus(1);
                TEncounterMedication encmed = inPatientRoundingController.saveMedication(encounterMedication);
                if(encmed!=null){
                    addMedicationIntoTable(encmed);
                    clearMedic();
                }
            } catch (Exception ex) {
                Logger.getLogger(EncounterPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_addmedication_buttonActionPerformed

    private void remove_medication_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove_medication_buttonActionPerformed
        try{
            int row = medication_table.getSelectedRow();
            model = (DefaultTableModel) medication_table.getModel();
            if(row!=-1){
                if(String.valueOf(model.getValueAt(row, 6)).equalsIgnoreCase("taking")){
                    int reply = JOptionPane.showConfirmDialog(null, "Do you want to delete ?", " Delete", JOptionPane.YES_NO_OPTION);
                    if (reply == JOptionPane.YES_OPTION){
                        Long encmedid = Long.parseLong(medication_table.getValueAt(row, 0).toString());
                        TEncounterMedication encmed = inPatientRoundingController.getEncounterMedicationById(encmedid);
                        DisabledGlassPane glassPane = new DisabledGlassPane();
                        JRootPane rootPane = SwingUtilities.getRootPane(this);
                        rootPane.setGlassPane(glassPane);
                        CommentsForCancelDialog c = new CommentsForCancelDialog(MainAPP, true);
                        c.setResizable(false);
                        c.setLocationRelativeTo(null);
                        glassPane.activate("");
                        c.setVisible(true);
                        c.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
                        glassPane.deactivate();
                        String comments = String.valueOf(medication_table.getValueAt(row, 5));
                        if(c.getComments()!=null){
                            if(comments.equalsIgnoreCase("-")||comments==null){
                                comments="(Canceled: "+c.getComments()+")";
                            }else{
                                comments= String.valueOf(medication_table.getValueAt(row, 5)).concat(" (Canceled: "+c.getComments()+")");
                            }
                            inpatenc = getOrCreateIPEncounter(inpatadmission);
                            encmed.setComments(comments);
                            encmed.setStatus(2);
                            inPatientRoundingController.saveMedication(encmed);
                            medication_table.setValueAt(comments, row, 5);
                            medication_table.setValueAt("Canceled", row, 6);
                        }
                    }
                }else{
                    String s = model.getValueAt(row, 6).toString();
                    JOptionPane.showMessageDialog(null, Initcap.toInitCap(s.toLowerCase())+" activity can't be deleted");
                }
            }else{
                JOptionPane.showMessageDialog(null, "No medication record seleted for delete");
            }
        }catch(Exception ex){
            Logger.getLogger(EncounterPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_remove_medication_buttonActionPerformed

    private void taking_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_taking_buttonActionPerformed
        try{
            int row = medication_table.getSelectedRow();
            if(row!=-1){
                Long encmedid = Long.parseLong(medication_table.getValueAt(row, 0).toString());
                TEncounterMedication encmed = inPatientRoundingController.getEncounterMedicationById(encmedid);
                TPatientEncounter enc = (TPatientEncounter)medication_table.getValueAt(row, 8);
                String status = medication_table.getValueAt(row, 6).toString();
                String orderStatus = medication_table.getValueAt(row, 7).toString();
                if(!orderStatus.equalsIgnoreCase("Reordered")){             //0-NotTaking, 1-Taking, 2-Canceled
                    if(status.equalsIgnoreCase("taking")){
                        encmed.setStatus(0);
                        medication_table.setValueAt("Not Taking", row, 6);
                    }else if(status.equalsIgnoreCase("not taking")){
                        encmed.setStatus(1);
                        medication_table.setValueAt("Taking", row, 6);
                    }
                    enc.setEncUpdateDate(new Date());
                    //inPatientRoundingController.createIPEncounter(enc);
                    inpatenc = getOrCreateIPEncounter(inpatadmission);
                    inPatientRoundingController.saveMedication(encmed);
                }else{
                    JOptionPane.showMessageDialog(null, "First Cancel the ReOrder...");
                }
            }else{
                JOptionPane.showMessageDialog(null, "Select a record to change the status");
            }
        }catch(Exception ex){
            Logger.getLogger(EncounterPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_taking_buttonActionPerformed

    private void reorder_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reorder_buttonActionPerformed
        try{
            int row = medication_table.getSelectedRow();
            model = (DefaultTableModel)medication_table.getModel();
            if(row!=-1){
                String reorderstatus = medication_table.getValueAt(row, 7).toString();
                if(reorderstatus.equalsIgnoreCase("Reordered")){
                    JOptionPane.showMessageDialog(null, "Medication is already reordered");
                }else{                                                          // selected medication will be not taking
                    Long encmedid = Long.parseLong(medication_table.getValueAt(row, 0).toString());
                    TEncounterMedication encmed = inPatientRoundingController.getEncounterMedicationById(encmedid);
                    Long encid = ((TPatientEncounter)medication_table.getValueAt(row, 8)).getEncId();
                    TPatientEncounter enc = inPatientRoundingController.getEncounterById(encid);
                    encmed.setStatus(0);
                    enc.setEncUpdateDate(new Date());
                    //inPatientRoundingController.createIPEncounter(enc);
                    inpatenc = getOrCreateIPEncounter(inpatadmission);
                    TEncounterMedication newmed = inPatientRoundingController.reorderMedication(encmed);
                    addMedicationIntoTable(newmed);
                    medication_table.setValueAt("Reordered", row, 7);
                    medication_table.setValueAt("Not Taking", row, 6);
                }
            }
        }catch(Exception ex){
            Logger.getLogger(EncounterPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_reorder_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 medication_comboboxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_medication_comboboxItemStateChanged
        TMedicationMaster id = new TMedicationMaster();
        if(medication_combobox.getSelectedIndex()!=-1){
            id = (TMedicationMaster) medication_combobox.getSelectedItem();
            if(id.getMedicationDose()!=null){
                dose_textbox.setText(String.valueOf(id.getMedicationDose()));
            }else{
                dose_textbox.setText(null);
            }
            if(id.getMedicationFrequency()!=null){
                frequency_textbox.setText(String.valueOf(id.getMedicationFrequency()));
            }else{
                frequency_textbox.setText(null);
            }
            if(id.getMedicationAdministration()!=null){
                route_textbox.setText(String.valueOf(id.getMedicationAdministration()));
            }else{
                route_textbox.setText(null);
            }
        }
    }//GEN-LAST:event_medication_comboboxItemStateChanged

    private void medication_tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_medication_tableMouseClicked
        if (evt.getClickCount()==2) {
            TEncounterMedication medicationDetails = new TEncounterMedication();
            try{
                int row = medication_table.getSelectedRow();
                Long encmedid = Long.parseLong(medication_table.getValueAt(row, 0).toString());
                medicationDetails = inPatientRoundingController.getEncounterMedicationById(encmedid);
                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();
                String buttonclick = medicationModificationDialog.getbuttonclick();
                if(buttonclick.equalsIgnoreCase("done")){
                    TEncounterMedication m = medicationModificationDialog.getMedication();
                    if(m!=null){
                        medication_table.setValueAt(m.getDose(), row, 2);
                        medication_table.setValueAt(m.getFrequency(), row, 3);
                        medication_table.setValueAt(m.getRoute(), row, 4);
                        medication_table.setValueAt(m.getComments(), row, 5);
                        inpatenc = getOrCreateIPEncounter(inpatadmission);
                        inPatientRoundingController.saveMedication(m);
                    }
                }
            }catch(Exception e){
                e.printStackTrace();
                JOptionPane.showMessageDialog(null, MessageProperties.getMessage("notselected.edit"));
            }

        }
    }//GEN-LAST:event_medication_tableMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addmedication_button;
    private javax.swing.JTextField dose_textbox;
    private javax.swing.JTextField frequency_textbox;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane13;
    private javax.swing.JSplitPane jSplitPane5;
    private javax.swing.JToolBar jToolBar7;
    private javax.swing.JToolBar jToolBar8;
    private javax.swing.JComboBox medication_combobox;
    private javax.swing.JTextArea medication_comments;
    private javax.swing.JTable medication_table;
    private javax.swing.JScrollPane medicationscroll;
    private javax.swing.JPanel medicationspanel;
    private javax.swing.JButton prev_medi_button;
    private javax.swing.JButton remove_medication_button;
    private javax.swing.JButton reorder_button;
    private javax.swing.JTextField route_textbox;
    private javax.swing.JButton taking_button;
    // End of variables declaration//GEN-END:variables
    
    private TEncounterMedication encounterMedication;
    private TMedicationMaster medication;
    private InPatientRoundingController inPatientRoundingController;
    private TPatientEncounter encounter;
    private TInpatentAdmission inpatadmission;
    private int i;
    private List<String> addlist;
    private DefaultTableModel model;
    private Vector<Object> addObject;
    private JFrame MainAPP;
    private List<TEncounterMedication> encPreviousMedication;
    private List<TEncounterMedication> encCurrentMedication;
    private Vector<TMedicationMaster> medicationList = new Vector<TMedicationMaster>();
    private SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-YYYY");
    private SimpleDateFormat sdftime = new SimpleDateFormat("dd-MM-YYYY  hh:mm:ss a");
    private TPatientEncounter inpatenc;
    
    private void populate() {
        inPatientRoundingController=(InPatientRoundingController)HealthCareInpatientHome.context.getBean("inPatientRoundingController");
        try{
            medicationList = inPatientRoundingController.getAllMedication();
        }catch(Exception e){
             JOptionPane.showMessageDialog(null,MessageProperties.getMessage("error.fetch",new Object[]{"visit type"}));
             throw new HealthCareException(MessageProperties.getMessage("error.dao"));
        }
    }
    
    private boolean validateMedication(){
        boolean valid = true;
        if(medication_combobox.getSelectedIndex()==-1 && ((JTextField)medication_combobox.getEditor().getEditorComponent()).getText().length()==0){
            JOptionPane.showMessageDialog(null, MessageProperties.getMessage("medication.mandatory"));
            ((JTextField)medication_combobox.getEditor().getEditorComponent()).requestFocus();
            valid = false;
        }else if(medication_table.getRowCount()>0){
            i=0;
                addlist = new ArrayList<String>();
                for(int i=0;i<medication_table.getRowCount();i++){
                    String medname = String.valueOf(medication_table.getValueAt(i, 1));
                    addlist.add(medname);
                }
                String name = ((JTextField)medication_combobox.getEditor().getEditorComponent()).getText();
                for(String o:addlist){
                    if(o.equalsIgnoreCase(name)){
                        i=1;
                    }
                }
                if(i==1){
                    valid = false;
                    JOptionPane.showMessageDialog(null, "Already added in table.");
                }
        }
        return valid;
    }
    
    private void addMedicationIntoTable(TEncounterMedication encmed) {
        model = (DefaultTableModel)medication_table.getModel();
        addObject = new Vector<Object>();
        addObject.add(encmed.getId());
        addObject.add(encmed.getMedication());
        if(encmed.getDose()!=null){
            addObject.add(encmed.getDose());
        }else{
            addObject.add("-");
        }
        if(encmed.getFrequency()!=null){
            addObject.add(encmed.getFrequency());
        }else{
            addObject.add("-");
        }
        if(encmed.getRoute()!=null){
            addObject.add(encmed.getRoute());
        }else{
            addObject.add("-");
        }
        if(encmed.getComments()!=null){
            addObject.add(encmed.getComments());
        }else{
            addObject.add("-");
        }
        if(encmed.getStatus()==1){
            addObject.add("Taking");
        }else{
            addObject.add("Not Taking");
        }
        addObject.add("-");
        addObject.add(encmed.getEncounterMed());
        model.addRow(addObject);
    }
    
    private void getPreviousMedication(int status){
        try {
            encPreviousMedication = encCurrentMedication = inPatientRoundingController.getEncounterMedication(encounter,status);
        } catch (ProcessingException ex) {
            Logger.getLogger(EncounterPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void clearMedic(){
        medication_combobox.setSelectedIndex(-1);
        dose_textbox.setText(null);
        frequency_textbox.setText(null);
        medication_comments.setText(null);
        route_textbox.setText(null);
        medication_combobox.requestFocus();
        ((JTextField)medication_combobox.getEditor().getEditorComponent()).setText(null);
    }
    
    private void getCurrentMedications(int status){
        try {
            encCurrentMedication = inPatientRoundingController.getEncounterMedication(encounter,status);
        } catch (ProcessingException ex) {
            Logger.getLogger(EncounterPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        model = (DefaultTableModel)medication_table.getModel();
        for(TEncounterMedication m:encCurrentMedication){
             addObject = new Vector<Object>();
             addObject.add(m.getId());
             addObject.add(m.getMedication());
             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("-");
             addObject.add(m.getEncounterMed());
             model.addRow(addObject);
        }
    }
    
    private TPatientEncounter getOrCreateIPEncounter(TInpatentAdmission inpatadmission) {
        try{
            inpatenc = inPatientRoundingController.getIPEncounterByPatient(inpatadmission.getPatientId());
            if(inpatenc!=null){
                inpatenc = inPatientRoundingController.saveIPEncounter(true,inpatenc);
            }else{
                inpatenc = new TPatientEncounter();
                inpatenc.setPatient(inpatadmission.getPatientId());
                inpatenc.setDoctor(inpatadmission.getDoctorId());
                inpatenc = inPatientRoundingController.saveIPEncounter(false,inpatenc);
            }
        }catch(Exception ex){
            Logger.getLogger(RoundingPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        return inpatenc;
    }
}

Commits for KNH_Project/HealthCareInPatient/src/main/java/com/bestray/healthcareinpatient/view/MedicationPanel.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Fri 27 Jul, 2018 13:29:42 +0000