Java tutorial
/* * 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.doctor; import business.patient.Patient; import business.patient.VitalSignInfo; import java.awt.CardLayout; import java.awt.Color; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.logging.Level; import java.util.logging.Logger; 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.DateAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.time.Second; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; /** * * @author ilanigam17 */ public class ReportingPatientVitalHistJPanel extends javax.swing.JPanel { private Patient patient; private JPanel userProcessContainer; /** * Creates new form ReportingPatientVitalHistJPanel */ public ReportingPatientVitalHistJPanel(Patient patient, JPanel userProcessContainer) { initComponents(); this.patient = patient; this.userProcessContainer = userProcessContainer; populateVitalTable(); } public void populateVitalTable() { nameJTextField.setText(patient.getName()); idJTextField.setText(patient.getId()); DefaultTableModel dtm = (DefaultTableModel) vitalJTable.getModel(); dtm.setRowCount(0); Object row[] = new Object[6]; for (VitalSignInfo vitalInfo : patient.getVitalHistory().getVitalHistory()) { row[0] = vitalInfo.getRespRate(); row[1] = vitalInfo.getHeartRate(); row[2] = vitalInfo.getSystolicBP(); row[3] = vitalInfo.getWeight(); row[4] = vitalInfo.getCurrentTime(); row[5] = vitalInfo.getSensorId(); 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(); vitalJTable = new javax.swing.JTable(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); nameJTextField = new javax.swing.JTextField(); idJTextField = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); respJButton = new javax.swing.JButton(); heartJButton = new javax.swing.JButton(); sysBPJButton = new javax.swing.JButton(); weightJButton = new javax.swing.JButton(); backJButton = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); setBackground(new java.awt.Color(255, 255, 255)); vitalJTable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null } }, new String[] { "Respiratory rate", "Heart rate", "Systonic BP", "Weight", "Record time", "Sensor Id" })); jScrollPane1.setViewportView(vitalJTable); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel1.setForeground(new java.awt.Color(0, 102, 102)); jLabel1.setText("Vital History Record "); jLabel2.setText("Name"); nameJTextField.setEditable(false); nameJTextField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { nameJTextFieldActionPerformed(evt); } }); idJTextField.setEditable(false); jLabel3.setText("ID"); respJButton.setText("RespiratoryRate"); respJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { respJButtonActionPerformed(evt); } }); heartJButton.setText("HeartRate"); heartJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { heartJButtonActionPerformed(evt); } }); sysBPJButton.setText("Systonic BP"); sysBPJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sysBPJButtonActionPerformed(evt); } }); weightJButton.setText("Weight"); weightJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { weightJButtonActionPerformed(evt); } }); backJButton.setText("<< Back"); backJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { backJButtonActionPerformed(evt); } }); jButton1.setText("Vital Analysis"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(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().addGap(157, 157, 157).addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel3).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(idJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(33, 33, 33)) .addComponent(jScrollPane1) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(64, 64, 64).addComponent(respJButton) .addGap(33, 33, 33).addComponent(heartJButton).addGap(34, 34, 34) .addComponent(sysBPJButton).addGap(41, 41, 41).addComponent(weightJButton)) .addGroup(layout.createSequentialGroup().addGap(19, 19, 19).addComponent(jLabel2) .addGap(18, 18, 18) .addComponent(nameJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(28, 28, 28).addComponent(backJButton)) .addGroup(layout.createSequentialGroup().addGap(259, 259, 259).addComponent(jButton1))) .addContainerGap(142, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(10, 10, 10).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(idJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3).addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(nameJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(respJButton).addComponent(heartJButton).addComponent(sysBPJButton) .addComponent(weightJButton)) .addGap(27, 27, 27).addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 78, Short.MAX_VALUE) .addComponent(backJButton).addGap(34, 34, 34))); }// </editor-fold>//GEN-END:initComponents private void nameJTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameJTextFieldActionPerformed // TODO add your handling code here: }//GEN-LAST:event_nameJTextFieldActionPerformed 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 sysBPJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sysBPJButtonActionPerformed // TODO add your handling code here: DefaultTableModel dtm = (DefaultTableModel) vitalJTable.getModel(); DefaultCategoryDataset sysBPbarChartSet = new DefaultCategoryDataset(); for (VitalSignInfo vhl : patient.getVitalHistory().getVitalHistory()) { sysBPbarChartSet.setValue(vhl.getSystolicBP(), "Systonic BP rate", vhl.getCurrentTime()); } JFreeChart respChart = ChartFactory.createBarChart3D("Vital History", "Time", "Systonic BP Rate", sysBPbarChartSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = respChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Bar Chart for Systonic BP Vital Sign", respChart); frame.setVisible(true); frame.setSize(450, 350); }//GEN-LAST:event_sysBPJButtonActionPerformed private void respJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_respJButtonActionPerformed DefaultTableModel dtm = (DefaultTableModel) vitalJTable.getModel(); DefaultCategoryDataset respBarChartSet = new DefaultCategoryDataset(); for (VitalSignInfo vhl : patient.getVitalHistory().getVitalHistory()) { respBarChartSet.setValue(vhl.getRespRate(), "Resp rate", vhl.getCurrentTime()); } JFreeChart respChart = ChartFactory.createBarChart3D("Vital History", "Time", "Resp Rate", respBarChartSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = respChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Bar Chart for Respiratory Vital Sign", respChart); frame.setVisible(true); frame.setSize(450, 350); }//GEN-LAST:event_respJButtonActionPerformed private void heartJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_heartJButtonActionPerformed // TODO add your handling code here: DefaultTableModel dtm = (DefaultTableModel) vitalJTable.getModel(); DefaultCategoryDataset heartBarChartSet = new DefaultCategoryDataset(); for (VitalSignInfo vhl : patient.getVitalHistory().getVitalHistory()) { heartBarChartSet.setValue(vhl.getHeartRate(), "Heart rate", vhl.getCurrentTime()); } JFreeChart respChart = ChartFactory.createBarChart3D("Vital History", "Time", "Heart Rate", heartBarChartSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = respChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Bar Chart for Heart rate Vital Information", respChart); frame.setVisible(true); frame.setSize(450, 350); }//GEN-LAST:event_heartJButtonActionPerformed private void weightJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_weightJButtonActionPerformed // TODO add your handling code here: // TODO add your handling code here: DefaultTableModel dtm = (DefaultTableModel) vitalJTable.getModel(); DefaultCategoryDataset weightbarChartSet = new DefaultCategoryDataset(); for (VitalSignInfo vhl : patient.getVitalHistory().getVitalHistory()) { weightbarChartSet.setValue(vhl.getWeight(), "Weight", vhl.getCurrentTime()); } JFreeChart respChart = ChartFactory.createBarChart3D("Vital History", "Time", "Weight", weightbarChartSet, PlotOrientation.VERTICAL, false, true, false); respChart.setBackgroundPaint(Color.WHITE); respChart.getTitle().setPaint(Color.BLACK); CategoryPlot p = respChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Bar Chart for Vital Information: Weight", respChart); frame.setVisible(true); frame.setSize(450, 350); }//GEN-LAST:event_weightJButtonActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: TimeSeriesCollection ts = new TimeSeriesCollection(); TimeSeries object1 = new TimeSeries("RespiratoryRate"); TimeSeries object2 = new TimeSeries("HeartRate"); TimeSeries object3 = new TimeSeries("SystolicPressure"); TimeSeries object4 = new TimeSeries("Weight"); for (VitalSignInfo vitalsign : patient.getVitalHistory().getVitalHistory()) { int rr = (int) vitalsign.getRespRate(); int hr = (int) vitalsign.getHeartRate(); int sp = (int) vitalsign.getSystolicBP(); int wt = (int) vitalsign.getWeight(); try { object1.add(new Second(vitalsign.getTimeStamp()), rr); object2.add(new Second(vitalsign.getTimeStamp()), hr); object3.add(new Second(vitalsign.getTimeStamp()), sp); object4.add(new Second(vitalsign.getTimeStamp()), wt); } catch (ParseException ex) { // Logger.getLogger(ReportingPatientVitalHistJPanel.class.getName()).log(Level.SEVERE, null, ex); } } ts.addSeries(object1); ts.addSeries(object2); ts.addSeries(object3); ts.addSeries(object4); JFreeChart chart = ChartFactory.createTimeSeriesChart("Vital Signs", "TimeStamp", "Vital Sign Values", ts, true, true, true); chart.setBackgroundPaint(Color.GRAY); chart.getTitle().setPaint(Color.red); XYPlot xy = (XYPlot) chart.getPlot(); DateAxis da = (DateAxis) xy.getDomainAxis(); da.setDateFormatOverride(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")); ChartFrame frame = new ChartFrame("Chart for Vital Signs", chart); frame.setVisible(true); frame.setSize(450, 350); }//GEN-LAST:event_jButton1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton backJButton; private javax.swing.JButton heartJButton; private javax.swing.JTextField idJTextField; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField nameJTextField; private javax.swing.JButton respJButton; private javax.swing.JButton sysBPJButton; private javax.swing.JTable vitalJTable; private javax.swing.JButton weightJButton; // End of variables declaration//GEN-END:variables }