UserInterface.SearchPatientJPanel.java Source code

Java tutorial

Introduction

Here is the source code for UserInterface.SearchPatientJPanel.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package UserInterface;

import Business.Patient;
import Business.Person;
import Business.PersonDirectory;
import Business.VitalSign;
import java.awt.BorderLayout;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Raghuram
 */
public class SearchPatientJPanel extends javax.swing.JPanel {

    private JPanel userProcessContainer;
    private PersonDirectory personDirectory;

    /**
     * Creates new form SearchPatientJPanel
     */
    public SearchPatientJPanel(PersonDirectory personDirectory, JPanel userProcessContainer) {
        initComponents();
        this.personDirectory = personDirectory;
        this.userProcessContainer = userProcessContainer;
        populateTable();
    }

    public void populateTable() {
        DefaultTableModel dtm = (DefaultTableModel) patientTable.getModel();
        dtm.setRowCount(0);
        for (Person P : personDirectory.getpersonDirectory()) {
            if (P.getPatient().getPatientId() != null) {
                Object row[] = new Object[4];
                row[0] = P.getPatient();
                row[1] = P.getPatient().getPatientId();
                row[2] = P.getPatient().getDoctorName();
                row[3] = P.getPatient().getPharmacy();
                dtm.addRow(row);
            }
        }
    }

    /**
     * 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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        patientTable = new javax.swing.JTable();
        btnGenerateChart = new javax.swing.JButton();

        patientTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Patient Name", "Patient ID", "Preferred Doctor", "Pharmacy" }) {
            boolean[] canEdit = new boolean[] { false, false, true, true };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jScrollPane1.setViewportView(patientTable);

        btnGenerateChart.setText("Generate Chart");
        btnGenerateChart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerateChartActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGap(30, 30, 30).addComponent(
                                        jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 420,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup().addGap(183, 183, 183)
                                        .addComponent(btnGenerateChart)))
                        .addContainerGap(315, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(36, 36, 36)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 130,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18).addComponent(btnGenerateChart).addContainerGap(225, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents

    private void btnGenerateChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateChartActionPerformed
        int row = patientTable.getSelectedRow();
        if (row < 0) {
            JOptionPane.showMessageDialog(null, "Please select person", "Warning", JOptionPane.WARNING_MESSAGE);
        } else {
            Patient patient = (Patient) patientTable.getValueAt(row, 0);
            for (VitalSign vs : patient.getVitalSignHistory().getVitalSignList()) {
                DefaultCategoryDataset dataset = new DefaultCategoryDataset();
                JPanel chartJPanel = new JPanel();
                dataset.setValue(vs.getRespiratoryRate(), "RR", "Respiratory Rate");
                dataset.setValue(vs.getHeartRate(), "HR", "Heart Rate");
                dataset.setValue(vs.getBloodPressure(), "BP", "BP");
                dataset.setValue(vs.getWeight(), "WT", "Weight");
                JFreeChart chart = ChartFactory.createBarChart("Vital Sign", "Vital Sign", "Values", dataset);
                ChartFrame frame = new ChartFrame("Bar chart for Vital Sign", chart);
                ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setDomainZoomable(true);
                chartJPanel.setLayout(new BorderLayout());
                chartJPanel.add(chartPanel, BorderLayout.NORTH);
                frame.setVisible(true);
                frame.setSize(500, 300);

            }
        }

        // TODO add your handling code here:
    }//GEN-LAST:event_btnGenerateChartActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGenerateChart;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable patientTable;
    // End of variables declaration//GEN-END:variables
}