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.HospitalDoctor; import business.Enterprise.Enterprise; import business.Organization.HospitalDoctorOrg; import business.Organization.HouseholdOrg; import business.Organization.Organization; import business.Person.Member; import business.Person.Person; import business.UserAccount.UserAccount; import business.WorkQueue.HospitalWorkRequest; import business.WorkQueue.WorkRequest; import business.vitalSignSensor.VitalSign; import java.awt.Color; import java.util.ArrayList; import java.util.Date; 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 Reshmi */ public class HospitalDoctorWorkAreaJPanel extends javax.swing.JPanel { /** * Creates new form HospitalDoctorWorkAreaJPanel */ private JPanel userProcessContainer; //private PersonDirectory personDir; private HospitalDoctorOrg hdOrg; private UserAccount userAccount; private UserAccount account; private Enterprise enterprise; public HospitalDoctorWorkAreaJPanel(JPanel userProcessContainer, HospitalDoctorOrg hdOrg, UserAccount userAccount, Enterprise enterprise) { initComponents(); this.userProcessContainer = userProcessContainer; this.hdOrg = hdOrg; this.userAccount = userAccount; this.enterprise = enterprise; populatePatientsTable(); populateAlertsTable(); } public void populatePatientsTable() { DefaultTableModel model = (DefaultTableModel) vitalSignjTable.getModel(); model.setRowCount(0); for (WorkRequest request : hdOrg.getWorkQueue().getWorkRequestList()) { if (request instanceof HospitalWorkRequest) { Person person = request.getPerson(); for (Member mem : person.getMemberDir().getMemberDirectory()) { if (mem.getMemberName().equals(request.getMessage())) { int patientAge = mem.getAge(); for (VitalSign vs : mem.getVitalSignList().getVitalSignList()) { Object[] row = new Object[7]; row[0] = request; row[1] = vs; row[2] = vs.getRespiratoryRate(); row[3] = vs.getHeartRate(); row[4] = vs.getBloodPressure(); row[5] = vs.getTemperature(); row[6] = mem.getVitalSignList().VitalSignStatus(patientAge, vs); 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() { jScrollPane2 = new javax.swing.JScrollPane(); alertDetailsTable = new javax.swing.JTable(); jScrollPane1 = new javax.swing.JScrollPane(); vitalSignjTable = new javax.swing.JTable(); jPanel1 = new javax.swing.JPanel(); sendAlertBtn = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); messageTxt = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); severityTxt = new javax.swing.JTextField(); viewChatBtn = new javax.swing.JButton(); setBackground(new java.awt.Color(255, 255, 255)); alertDetailsTable.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N alertDetailsTable.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[] { "Member Name", "Severity", "Message", "Sent On", "Status", "Checked Date" }) { boolean[] canEdit = new boolean[] { false, false, false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane2.setViewportView(alertDetailsTable); vitalSignjTable.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 } }, new String[] { "Name", "Timestamp", "Respiratory Rate", "Heart Rate", "Blood Pressure", "Temperature", "Status" }) { boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane1.setViewportView(vitalSignjTable); jPanel1.setBackground(new java.awt.Color(255, 255, 255)); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Message", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 0, 11), new java.awt.Color(102, 0, 102))); // NOI18N sendAlertBtn.setBackground(new java.awt.Color(0, 153, 0)); sendAlertBtn.setFont(new java.awt.Font("Verdana", 3, 12)); // NOI18N sendAlertBtn.setForeground(new java.awt.Color(255, 255, 255)); sendAlertBtn.setText("Send "); sendAlertBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sendAlertBtnActionPerformed(evt); } }); jLabel2.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N jLabel2.setText("Message"); messageTxt.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N jLabel4.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N jLabel4.setText("Severity"); severityTxt.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap() .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4).addComponent(jLabel2)) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(50, 50, 50) .addComponent(severityTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(messageTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(jPanel1Layout.createSequentialGroup().addGap(95, 95, 95) .addComponent(sendAlertBtn))) .addContainerGap())); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(14, 14, 14).addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel4) .addComponent(severityTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(messageTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18).addComponent(sendAlertBtn).addContainerGap())); viewChatBtn.setBackground(new java.awt.Color(0, 153, 0)); viewChatBtn.setFont(new java.awt.Font("Verdana", 3, 12)); // NOI18N viewChatBtn.setForeground(new java.awt.Color(255, 255, 255)); viewChatBtn.setText("View Chart"); viewChatBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { viewChatBtnActionPerformed(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(94, 94, 94) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGap(15, 15, 15) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2).addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)) .addContainerGap()) .addGroup(layout.createSequentialGroup().addGap(168, 168, 168) .addComponent(viewChatBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(4, 4, 4).addComponent(viewChatBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(16, 16, 16).addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(29, 29, 29))); }// </editor-fold>//GEN-END:initComponents private void sendAlertBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendAlertBtnActionPerformed int selectedRow = vitalSignjTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Please select a row", "WARNING", JOptionPane.WARNING_MESSAGE); return; } else { VitalSign vs = (VitalSign) vitalSignjTable.getValueAt(selectedRow, 1); if (vs.getAlertStatus().equals("Requested doc")) { vs.setAlertStatus("Doc Reviewed"); HospitalWorkRequest request = (HospitalWorkRequest) vitalSignjTable.getValueAt(selectedRow, 0); Date responseDate = new Date(); request.setReceiver(userAccount); String alert = messageTxt.getText(); request.setAlert(alert); request.setRequestDate(responseDate); String severity = severityTxt.getText(); request.setSeverity(severity); request.setStatus("checked by doctor"); populateAlertsTable(); JOptionPane.showMessageDialog(null, "Doctor's Response Sent", "MESSAGE", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Doctor has already reviewed", "MESSAGE", JOptionPane.INFORMATION_MESSAGE); } } }//GEN-LAST:event_sendAlertBtnActionPerformed private void viewChatBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewChatBtnActionPerformed int selectedRow = vitalSignjTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(this, "Please select a patient from table.", "Error", JOptionPane.INFORMATION_MESSAGE); return; } createChart(); }//GEN-LAST:event_viewChatBtnActionPerformed private void createChart() { DefaultCategoryDataset vitalSignDataset = new DefaultCategoryDataset(); int selectedRow = vitalSignjTable.getSelectedRow(); Member member = (Member) vitalSignjTable.getValueAt(selectedRow, 0); ArrayList<VitalSign> vitalSignList = member.getVitalSignList().getVitalSignList(); /*At least 2 vital sign records needed to show chart */ if (vitalSignList.isEmpty() || vitalSignList.size() == 1) { JOptionPane.showMessageDialog(this, "No vital signs or only one vital sign found. At least 2 vital sign records needed to show chart!", "Warning", JOptionPane.INFORMATION_MESSAGE); return; } for (VitalSign vitalSign : vitalSignList) { vitalSignDataset.addValue(vitalSign.getRespiratoryRate(), "RR", vitalSign.getTimestamp()); vitalSignDataset.addValue(vitalSign.getHeartRate(), "HR", vitalSign.getTimestamp()); vitalSignDataset.addValue(vitalSign.getBloodPressure(), "BP", vitalSign.getTimestamp()); vitalSignDataset.addValue(vitalSign.getTemperature(), "Temp", vitalSign.getTimestamp()); } JFreeChart vitalSignChart = ChartFactory.createBarChart3D("Vital Sign Chart", "Time Stamp", "Rate", 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); } public void populateAlertsTable() { DefaultTableModel dtm = (DefaultTableModel) alertDetailsTable.getModel(); dtm.setRowCount(0); for (WorkRequest request : hdOrg.getWorkQueue().getWorkRequestList()) { if (hdOrg.getWorkQueue().getWorkRequestList() != null) { Object[] row = new Object[6]; row[0] = request.getMessage(); row[1] = request.getSeverity(); row[2] = ((HospitalWorkRequest) request).getAlert(); row[3] = request.getRequestDate(); row[4] = request.getStatus(); row[5] = request.getResponseDate(); // row[1] = request.getStatus(); dtm.addRow(row); } } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTable alertDetailsTable; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextField messageTxt; private javax.swing.JButton sendAlertBtn; private javax.swing.JTextField severityTxt; private javax.swing.JButton viewChatBtn; private javax.swing.JTable vitalSignjTable; // End of variables declaration//GEN-END:variables }