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; import Business.Person; import Business.PersonDirectory; import Business.VitalSign; import java.awt.CardLayout; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.table.DefaultTableModel; import org.jfree.chart.ChartFactory; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author Sheetal */ public class ViewPersonDetails extends javax.swing.JPanel { /** * Creates new form ViewPersonDetails */ private JPanel userProcessContainer; private PersonDirectory personDirectory; private Person p; public ViewPersonDetails(PersonDirectory personDirectory, JPanel userProcessContainer) { initComponents(); this.userProcessContainer = userProcessContainer; this.personDirectory = personDirectory; cmbPerson.removeAllItems(); for (Person s : personDirectory.getPersonDirectory()) { cmbPerson.addItem(s); // btnviewVitalSigns.setEnabled(false); } } public void populateTable() { DefaultTableModel dtm = (DefaultTableModel) tblvitalSign.getModel(); dtm.setRowCount(0); for (VitalSign s : p.getPatient().getVitalsignHistory().getVitalSignHistory()) { Object row[] = new Object[6]; row[0] = s; row[1] = s.getRespiratoryrate(); row[2] = s.getHeartrate(); row[3] = s.getBloodpressure(); row[4] = s.getWeight(); row[5] = s.getStatus(); dtm.addRow(row); } } public boolean vitalSignStatus(VitalSign vs) { if (p.getPatient().getAge() >= 1 && p.getPatient().getAge() <= 3) { if ((vs.getRespiratoryrate() >= 20 && vs.getRespiratoryrate() <= 30) && (vs.getBloodpressure() >= 80 && vs.getBloodpressure() <= 110) && (vs.getHeartrate() >= 80 && vs.getHeartrate() <= 130) && (vs.getWeight() >= 22 && vs.getWeight() <= 31)) return true; } else if (p.getPatient().getAge() == 4 || p.getPatient().getAge() == 5) { if ((vs.getRespiratoryrate() >= 20 && vs.getRespiratoryrate() <= 30) && (vs.getBloodpressure() >= 80 && vs.getBloodpressure() <= 110) && (vs.getHeartrate() >= 80 && vs.getHeartrate() <= 120) && (vs.getWeight() >= 31 && vs.getWeight() <= 40)) return true; } else if (p.getPatient().getAge() >= 6 && p.getPatient().getAge() <= 12) { if ((vs.getRespiratoryrate() >= 20 && vs.getRespiratoryrate() <= 30) && (vs.getBloodpressure() >= 80 && vs.getBloodpressure() <= 120) && (vs.getHeartrate() >= 70 && vs.getHeartrate() <= 110) && (vs.getWeight() >= 41 && vs.getWeight() <= 92)) return true; } else if (p.getPatient().getAge() >= 13) { if ((vs.getRespiratoryrate() >= 12 && vs.getRespiratoryrate() <= 20) && (vs.getBloodpressure() >= 110 && vs.getBloodpressure() <= 120) && (vs.getHeartrate() >= 55 && vs.getHeartrate() <= 105) && (vs.getWeight() >= 110)) return true; } return false; } /** * 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() { btnback = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); btnupdate = new javax.swing.JButton(); cmbPerson = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); btncreatePatient = new javax.swing.JButton(); btnviewPatient = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); txtpatientID = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); txtpatientName = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); txtpatientAge = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); tblvitalSign = new javax.swing.JTable(); btncreateVitalSign = new javax.swing.JButton(); btnviewVitalSigns = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); txtgender = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); txtdoctorName = new javax.swing.JTextField(); btnupdateVitalSign = new javax.swing.JButton(); btndeleteVitalSign = new javax.swing.JButton(); btngraphic = new javax.swing.JButton(); btnback.setText("<<Back"); btnback.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnbackActionPerformed(evt); } }); jLabel1.setText("Person Details"); btnupdate.setText("Update"); btnupdate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnupdateActionPerformed(evt); } }); cmbPerson.setModel( new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jLabel3.setText("Person Name"); btncreatePatient.setText("Create Patient"); btncreatePatient.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btncreatePatientActionPerformed(evt); } }); btnviewPatient.setText("View Patient"); btnviewPatient.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnviewPatientActionPerformed(evt); } }); jLabel4.setText("Patient ID"); txtpatientID.setEnabled(false); jLabel5.setText("Patient Name"); txtpatientName.setEnabled(false); jLabel6.setText("Patient Age"); txtpatientAge.setEnabled(false); tblvitalSign.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 } }, new String[] { "TimeStamp", "Respiratory Rate", "Heart Rate", "Blood Pressure", "Weight", "Summary" })); jScrollPane1.setViewportView(tblvitalSign); btncreateVitalSign.setText("Create Vital Sign"); btncreateVitalSign.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btncreateVitalSignActionPerformed(evt); } }); btnviewVitalSigns.setText("View Vital Signs"); btnviewVitalSigns.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnviewVitalSignsActionPerformed(evt); } }); jLabel2.setText("Gender"); txtgender.setEnabled(false); jLabel7.setText("Doctor Name"); txtdoctorName.setEnabled(false); btnupdateVitalSign.setText("Update"); btnupdateVitalSign.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnupdateVitalSignActionPerformed(evt); } }); btndeleteVitalSign.setText("Delete"); btndeleteVitalSign.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btndeleteVitalSignActionPerformed(evt); } }); btngraphic.setText("Graphic Display"); btngraphic.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btngraphicActionPerformed(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(48, 48, 48).addComponent(jLabel3) .addGap(77, 77, 77).addComponent(cmbPerson, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(91, 91, 91).addComponent(btncreatePatient) .addGap(79, 79, 79).addComponent(btnupdate)) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(btnback)) .addGroup(layout.createSequentialGroup().addGap(23, 23, 23).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup().addComponent(jLabel4) .addGap(48, 48, 48).addComponent(txtpatientID)) .addComponent(jLabel1) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5).addComponent(jLabel6).addComponent(jLabel2)) .addGap(32, 32, 32) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtpatientName, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(txtdoctorName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE) .addComponent(txtgender, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtpatientAge, javax.swing.GroupLayout.Alignment.LEADING))))) .addComponent(btnviewPatient).addComponent(jLabel7) .addComponent(btncreateVitalSign))) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 391, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(26, 26, 26) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnupdateVitalSign).addComponent(btndeleteVitalSign) .addComponent(btngraphic))) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(btnviewVitalSigns))) .addContainerGap(191, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(jLabel1).addGap(28, 28, 28) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cmbPerson, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btncreatePatient, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(btnupdate)) .addGap(8, 8, 8).addComponent(btnviewPatient).addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(txtpatientID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(23, 23, 23) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5).addComponent(txtpatientName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6).addComponent(txtpatientAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(txtgender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(16, 16, 16) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7).addComponent(txtdoctorName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE) .addComponent(btncreateVitalSign).addGap(27, 27, 27) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addComponent(btnupdateVitalSign) .addGap(29, 29, 29).addComponent(btndeleteVitalSign).addGap(38, 38, 38) .addComponent(btngraphic))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnviewVitalSigns).addGap(5, 5, 5).addComponent(btnback).addGap(48, 48, 48))); }// </editor-fold>//GEN-END:initComponents private void btnbackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnbackActionPerformed // TODO add your handling code here: userProcessContainer.remove(this); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.previous(userProcessContainer); }//GEN-LAST:event_btnbackActionPerformed private void btnupdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnupdateActionPerformed // TODO add your handling code here: { Person result = (Person) cmbPerson.getSelectedItem(); PersonUpdateJPanel panel = new PersonUpdateJPanel(result, userProcessContainer); userProcessContainer.add("PersonUpdateJPanel", panel); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.next(userProcessContainer); } }//GEN-LAST:event_btnupdateActionPerformed private void btncreatePatientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btncreatePatientActionPerformed // TODO add your handling code here: p = (Person) cmbPerson.getSelectedItem(); if (p.getPatient().getName() != null) { JOptionPane.showMessageDialog(null, "Patient is already created", "Information", JOptionPane.INFORMATION_MESSAGE); btncreatePatient.setEnabled(false); } else { CreatePatientJPanel panel = new CreatePatientJPanel(p, userProcessContainer); userProcessContainer.add("CreatePatientJPanel", panel); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.next(userProcessContainer); } }//GEN-LAST:event_btncreatePatientActionPerformed private void btnviewPatientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnviewPatientActionPerformed // TODO add your handling code here: p = (Person) cmbPerson.getSelectedItem(); if (p.getPatient().getName() == null) { JOptionPane.showMessageDialog(null, "Create patient profile", "Information", JOptionPane.INFORMATION_MESSAGE); } else { txtpatientID.setText(p.getPatient().getID()); txtpatientName.setText(p.getPatient().getName()); txtpatientAge.setText(String.valueOf(p.getPatient().getAge())); txtgender.setText(p.getPatient().getGender()); txtdoctorName.setText(p.getPatient().getDoctorName()); } }//GEN-LAST:event_btnviewPatientActionPerformed private void btncreateVitalSignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btncreateVitalSignActionPerformed // TODO add your handling code here: Person result = (Person) cmbPerson.getSelectedItem(); if (result != null) { CreateVitalSignJPanel panel = new CreateVitalSignJPanel(result, userProcessContainer); userProcessContainer.add("CreateVitalSignJPanel", panel); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.next(userProcessContainer); } // btnviewVitalSigns.setEnabled(true); }//GEN-LAST:event_btncreateVitalSignActionPerformed private void btnviewVitalSignsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnviewVitalSignsActionPerformed // TODO add your handling code here: populateTable(); }//GEN-LAST:event_btnviewVitalSignsActionPerformed private void btnupdateVitalSignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnupdateVitalSignActionPerformed // TODO add your handling code here: int selectedRow = tblvitalSign.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Please select a product from the table"); return; } VitalSign vs = (VitalSign) tblvitalSign.getValueAt(selectedRow, 0); UpdateJPanel panel = new UpdateJPanel(p, vs, userProcessContainer); userProcessContainer.add("UpdateJPanel", panel); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.next(userProcessContainer); }//GEN-LAST:event_btnupdateVitalSignActionPerformed private void btndeleteVitalSignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btndeleteVitalSignActionPerformed // TODO add your handling code here: int selectedRow = tblvitalSign.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(this, "Please select a vital sign from table to delete"); return; } VitalSign vs = (VitalSign) tblvitalSign.getValueAt(selectedRow, 0); p.getPatient().getVitalsignHistory().deleteVitalSign(vs); JOptionPane.showMessageDialog(this, "Vital Sign Details deleted Successfully"); }//GEN-LAST:event_btndeleteVitalSignActionPerformed private void btngraphicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btngraphicActionPerformed // TODO add your handling code here: int selectedRow = tblvitalSign.getSelectedRow(); VitalSign vs = (VitalSign) tblvitalSign.getValueAt(selectedRow, 0); JFreeChartJPanel panel = new JFreeChartJPanel(vs, userProcessContainer); userProcessContainer.add("JFreeChartJPanel", panel); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.next(userProcessContainer); }//GEN-LAST:event_btngraphicActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnback; private javax.swing.JButton btncreatePatient; private javax.swing.JButton btncreateVitalSign; private javax.swing.JButton btndeleteVitalSign; private javax.swing.JButton btngraphic; private javax.swing.JButton btnupdate; private javax.swing.JButton btnupdateVitalSign; private javax.swing.JButton btnviewPatient; private javax.swing.JButton btnviewVitalSigns; private javax.swing.JComboBox cmbPerson; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable tblvitalSign; private javax.swing.JTextField txtdoctorName; private javax.swing.JTextField txtgender; private javax.swing.JTextField txtpatientAge; private javax.swing.JTextField txtpatientID; private javax.swing.JTextField txtpatientName; // End of variables declaration//GEN-END:variables }