UserInterface.PatientRole.ManageMyVitalSignsAndFitnessRecordJPanel.java Source code

Java tutorial

Introduction

Here is the source code for UserInterface.PatientRole.ManageMyVitalSignsAndFitnessRecordJPanel.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.PatientRole;

import Business.EcoSystem;
import Business.Enterprise.Enterprise;
import Business.Enterprise.GovernmentEnterprise;
import Business.Network.Network;
import Business.Organization.DoctorOrganization;
import Business.Organization.HealthAndHumanServicesOrganization;
import Business.Organization.Organization;
import Business.Organization.PatientOrganization;
import Business.Patient.Patient;
import Business.Patient.PatientDirectory;
import Business.Patient.Record;
import Business.Patient.RecordHistory;
import Business.UserAccount.UserAccount;
import Business.WorkQueue.PatientDoctorWorkRequest;
import Business.WorkQueue.WorkRequest;
import java.awt.CardLayout;
import java.awt.Color;
import java.util.ArrayList;
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.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author dongyueli
 */
public class ManageMyVitalSignsAndFitnessRecordJPanel extends javax.swing.JPanel {
    private JPanel userProcessContainer;
    private EcoSystem ecoSystem;
    private Enterprise enterprise;
    private UserAccount userAccount;
    private PatientOrganization patientOrganization;
    private Patient patient;
    private RecordHistory recordHistory;

    //private PatientDirectory patientDirectory;
    /**
     * Creates new form ManageMyVitalSignsJPanel
     */
    public ManageMyVitalSignsAndFitnessRecordJPanel(JPanel userProcessContainer, UserAccount userAccount,
            PatientOrganization patientOrganization, Enterprise enterprise, EcoSystem ecoSystem) {
        initComponents();
        this.userProcessContainer = userProcessContainer;
        this.ecoSystem = ecoSystem;
        this.userAccount = userAccount;
        this.patientOrganization = (PatientOrganization) patientOrganization;
        this.enterprise = enterprise;
        this.patient = userAccount.getPatient();
        this.recordHistory = patient.getRecordHistory();

        //this.patientDirectory = patientDirectory;
        populateTable();
    }

    private void populateTable() {
        DefaultTableModel model = (DefaultTableModel) viewVitalSignsJTable1.getModel();
        model.setRowCount(0);

        DoctorOrganization doctorOrganization = null;
        for (Organization o : enterprise.getOrganizationDirectory().getOrganizationList()) {
            if (o instanceof DoctorOrganization) {
                DoctorOrganization dO = (DoctorOrganization) o;
                doctorOrganization = dO;
                break;
            }
        }

        for (WorkRequest request : doctorOrganization.getWorkQueue().getWorkRequestList()) {
            if (request != null) {
                PatientDoctorWorkRequest patientDoctorWorkRequest = (PatientDoctorWorkRequest) request;
                Record r = patientDoctorWorkRequest.getRecord();
                Object[] row = new Object[5];
                row[0] = r;
                row[1] = r.getNormalOrNot();
                row[2] = r.getTotalTime();
                row[3] = r.getNeedMoreExcerciseOrNot();
                String respondStatus = patientDoctorWorkRequest.getRespondStatus();
                row[4] = respondStatus == null ? "Waiting" : respondStatus;

                model.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() {

        jLabel9 = new javax.swing.JLabel();
        addJButton = new javax.swing.JButton();
        viewJButton = new javax.swing.JButton();
        editJButton = new javax.swing.JButton();
        deleteJButton = new javax.swing.JButton();
        showVitalSignsChartJButton = new javax.swing.JButton();
        viewResponseJButton = new javax.swing.JButton();
        sendToMyDoctorJButton = new javax.swing.JButton();
        backJButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        viewVitalSignsJTable1 = new javax.swing.JTable();
        showFitnessChartJButton = new javax.swing.JButton();
        refreshJButton = new javax.swing.JButton();

        jLabel9.setFont(new java.awt.Font("Lucida Grande", 3, 24)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(0, 51, 204));
        jLabel9.setText("Manage Vital Signs and Fitness Record");

        addJButton.setText("Add Record");
        addJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addJButtonActionPerformed(evt);
            }
        });

        viewJButton.setText("View Details");
        viewJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewJButtonActionPerformed(evt);
            }
        });

        editJButton.setText("Edit Record");

        deleteJButton.setText("Delete Record");

        showVitalSignsChartJButton.setText("Show VItal Signs Chart");
        showVitalSignsChartJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showVitalSignsChartJButtonActionPerformed(evt);
            }
        });

        viewResponseJButton.setText("View Response");
        viewResponseJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewResponseJButtonActionPerformed(evt);
            }
        });

        sendToMyDoctorJButton.setText("Send To My Doctor");
        sendToMyDoctorJButton.setMaximumSize(new java.awt.Dimension(131, 29));
        sendToMyDoctorJButton.setMinimumSize(new java.awt.Dimension(131, 29));
        sendToMyDoctorJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendToMyDoctorJButtonActionPerformed(evt);
            }
        });

        backJButton.setText("<<Back");
        backJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backJButtonActionPerformed(evt);
            }
        });

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

        }, new String[] { "Timestamp", "Vital Signs", "Fitness Total Time(mins)", "Fitness", "Respond" }) {
            Class[] types = new Class[] { java.lang.Object.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false, false, false, false };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jScrollPane3.setViewportView(viewVitalSignsJTable1);
        if (viewVitalSignsJTable1.getColumnModel().getColumnCount() > 0) {
            viewVitalSignsJTable1.getColumnModel().getColumn(0).setResizable(false);
            viewVitalSignsJTable1.getColumnModel().getColumn(1).setResizable(false);
            viewVitalSignsJTable1.getColumnModel().getColumn(2).setResizable(false);
            viewVitalSignsJTable1.getColumnModel().getColumn(3).setResizable(false);
            viewVitalSignsJTable1.getColumnModel().getColumn(4).setResizable(false);
        }

        showFitnessChartJButton.setText("Show Fitness Chart");
        showFitnessChartJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showFitnessChartJButtonActionPerformed(evt);
            }
        });

        refreshJButton.setText("Refresh");
        refreshJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshJButtonActionPerformed(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(156, 156, 156)
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 507,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(6, 6, 6).addComponent(refreshJButton))
                        .addGroup(layout.createSequentialGroup().addGap(70, 70, 70).addComponent(jScrollPane3,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 709,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup().addGap(27, 27, 27).addComponent(backJButton))
                        .addGroup(layout.createSequentialGroup().addGap(102, 102, 102).addGroup(layout
                                .createParallelGroup(
                                        javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(showVitalSignsChartJButton,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 175,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(6, 6, 6)
                                        .addComponent(showFitnessChartJButton,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 152,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(6, 6, 6)
                                        .addComponent(viewResponseJButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18).addComponent(sendToMyDoctorJButton,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 163,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(
                                        layout.createSequentialGroup()
                                                .addComponent(addJButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        171, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(12, 12, 12)
                                                .addComponent(viewJButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        146, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(12, 12, 12)
                                                .addComponent(editJButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        141, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(deleteJButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        163, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(117, 117, 117)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel9)
                                .addGroup(layout
                                        .createSequentialGroup().addGap(6, 6, 6).addComponent(refreshJButton)))
                        .addGap(24, 24, 24)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 146,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(addJButton).addComponent(viewJButton).addComponent(editJButton)
                                .addComponent(deleteJButton))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(showVitalSignsChartJButton).addComponent(showFitnessChartJButton)
                                .addComponent(viewResponseJButton).addComponent(sendToMyDoctorJButton,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(46, 46, 46).addComponent(backJButton)));
    }// </editor-fold>//GEN-END:initComponents

    private void showVitalSignsChartJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showVitalSignsChartJButtonActionPerformed
        // TODO add your handling code here:
        ArrayList<Record> recordList = patient.getRecordHistory().getRecordList();
        /*At least 2 vital sign records needed to show chart */
        if (recordList.isEmpty() || recordList.size() == 1) {
            JOptionPane.showMessageDialog(this,
                    "No Vital Signs or only one Vital Sign found. At least 2 Vital Signs records needed to show chart!",
                    "Warning", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        VitalSignsChartJPanel panel = new VitalSignsChartJPanel(userProcessContainer, userAccount,
                patientOrganization, enterprise, ecoSystem);
        userProcessContainer.add("VitalSignsChartJPanel", panel);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.next(userProcessContainer);
    }//GEN-LAST:event_showVitalSignsChartJButtonActionPerformed

    private void showFitnessChartJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showFitnessChartJButtonActionPerformed
        // TODO add your handling code here:
        createChart();
    }//GEN-LAST:event_showFitnessChartJButtonActionPerformed

    private void backJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backJButtonActionPerformed
        // TODO add your handling code here:
        userProcessContainer.remove(this);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.previous(userProcessContainer);
    }//GEN-LAST:event_backJButtonActionPerformed

    private void viewJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewJButtonActionPerformed
        // TODO add your handling code here:
        int selectedRow = viewVitalSignsJTable1.getSelectedRow();
        if (selectedRow < 0) {
            JOptionPane.showMessageDialog(null, "Please select a row from the table first to view detail",
                    "Warning", JOptionPane.WARNING_MESSAGE);

        } else {

            Record vs = (Record) viewVitalSignsJTable1.getValueAt(selectedRow, 0);
            ViewUpdateRecordDetailsJPanel panel = new ViewUpdateRecordDetailsJPanel(userProcessContainer,
                    userAccount, patientOrganization, enterprise, ecoSystem, vs);
            userProcessContainer.add("ViewUpdateRecordDetailsJPanel", panel);
            CardLayout layout = (CardLayout) userProcessContainer.getLayout();
            layout.next(userProcessContainer);

        }

    }//GEN-LAST:event_viewJButtonActionPerformed

    private void addJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addJButtonActionPerformed
        // TODO add your handling code here:
        AddRecordJPanel panel = new AddRecordJPanel(userProcessContainer, userAccount, patientOrganization,
                enterprise, ecoSystem);
        userProcessContainer.add("AddRecordJPanel", panel);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.next(userProcessContainer);

    }//GEN-LAST:event_addJButtonActionPerformed

    private void refreshJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshJButtonActionPerformed
        // TODO add your handling code here:
        populateTable();
    }//GEN-LAST:event_refreshJButtonActionPerformed

    private void sendToMyDoctorJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendToMyDoctorJButtonActionPerformed
        //         TODO add your handling code here:
        int selectedRow = viewVitalSignsJTable1.getSelectedRow();
        if (selectedRow < 0) {
            JOptionPane.showMessageDialog(null, "Please select a row from the table first to view detail",
                    "Warning", JOptionPane.WARNING_MESSAGE);

        } else {

            UserAccount doctor = (UserAccount) patient.getMydoctor();
            PatientDoctorWorkRequest request = new PatientDoctorWorkRequest();
            request.setDoctor(doctor);
            request.setPatientName(userAccount.getName());
            request.setDate();
            request.setVsNormalorNot("Abnormal");
            request.setFtNormalorNot("Need More Excercise");

            Organization org = null;
            for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) {
                if (organization instanceof DoctorOrganization) {
                    org = organization;
                    break;
                }
            }

            if (org != null) {
                org.getWorkQueue().getWorkRequestList().add(request);
                userAccount.getWorkQueue().getWorkRequestList().add(request);
                doctor.getWorkQueue().getWorkRequestList().add(request);
                JOptionPane.showMessageDialog(null, "Success! ");
            }

        }
    }//GEN-LAST:event_sendToMyDoctorJButtonActionPerformed

    private void createChart() {
        DefaultCategoryDataset vitalSignDataset = new DefaultCategoryDataset();
        int selectedRow = viewVitalSignsJTable1.getSelectedRow();
        ArrayList<Record> recordList = patient.getRecordHistory().getRecordList();
        /*At least 2 vital sign records needed to show chart */
        if (recordList.isEmpty() || recordList.size() == 1) {
            JOptionPane.showMessageDialog(this,
                    "No Fitness Record or only one fitness record found. At least 2 fitness records needed to show chart!",
                    "Warning", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        for (Record record : recordList) {
            vitalSignDataset.addValue(record.getStandTime(), "StandTime", record.getDate());
            vitalSignDataset.addValue(record.getMoveTime(), "MoveTime", record.getDate());
            vitalSignDataset.addValue(record.getExcerciseTime(), "ExcerciseTime", record.getDate());
            vitalSignDataset.addValue(record.getTotalTime(), "TotalTime", record.getDate());
        }

        JFreeChart vitalSignChart = ChartFactory.createBarChart3D("Fitness Record Chart", "Time Stamp",
                "Time(mins)", vitalSignDataset, PlotOrientation.VERTICAL, true, false, false);
        vitalSignChart.setBackgroundPaint(Color.white);
        CategoryPlot vitalSignChartPlot = vitalSignChart.getCategoryPlot();
        vitalSignChartPlot.setBackgroundPaint(Color.lightGray);

        CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis();
        vitalSignDomainAxis
                .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

        NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis();
        vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        ChartFrame chartFrame = new ChartFrame("Chart", vitalSignChart);
        chartFrame.setVisible(true);
        chartFrame.setSize(500, 500);
    }

    private void viewResponseJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewResponseJButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_viewResponseJButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addJButton;
    private javax.swing.JButton backJButton;
    private javax.swing.JButton deleteJButton;
    private javax.swing.JButton editJButton;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton refreshJButton;
    private javax.swing.JButton sendToMyDoctorJButton;
    private javax.swing.JButton showFitnessChartJButton;
    private javax.swing.JButton showVitalSignsChartJButton;
    private javax.swing.JButton viewJButton;
    private javax.swing.JButton viewResponseJButton;
    private javax.swing.JTable viewVitalSignsJTable1;
    // End of variables declaration//GEN-END:variables
}