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.DoctorAdmin; import Business.Drone.Drone; import Business.Employee.Employee; import Business.Enterprise.Enterprise; import Business.Organization.DoctorAdminOrganization; import Business.Organization.DoctorOrganization; import Business.Organization.Organization; import Business.Patient.Patient; import Business.Patient.VitalSign; import Business.QuickAssist; import Business.UserAccount.UserAccount; import Business.WorkQueue.PatientDoctorWorkRequest; import Business.WorkQueue.WorkRequest; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.table.DefaultTableModel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.chart.renderer.category.StandardBarPainter; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author sanka_001 */ public class TakeRequestJPanel extends javax.swing.JPanel { JPanel userProcessContainer; UserAccount account; // DoctorAdminOrganization organization; Enterprise enterprise; Organization organization; QuickAssist system; Employee assignedDoctor; Patient assignedPatient; PatientDoctorWorkRequest pdwrequest; WorkRequest request; VitalSign vitalSign; String availability; ChartPanel CP; /** * Creates new form NurseWorkAreaJPanel */ public TakeRequestJPanel(JPanel userProcessContainer, UserAccount account, Organization organization, Enterprise enterprise, QuickAssist system) { initComponents(); this.setBackground(Color.white); this.userProcessContainer = userProcessContainer; this.account = account; // this.organization = organization; this.enterprise = enterprise; this.organization = organization; this.system = system; populateDoctorCombo(); populateTable(); } /** * 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() { jLabel1 = new javax.swing.JLabel(); jScrollPane3 = new javax.swing.JScrollPane(); tblDocWorkRequest = new javax.swing.JTable(); btnTakeReq = new javax.swing.JButton(); btnSeeDetails = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); cmbDoctors = new javax.swing.JComboBox(); btnBack2 = new javax.swing.JButton(); btnVitalSign = new javax.swing.JButton(); pnlVitalSign = new javax.swing.JPanel(); lblStatus = new javax.swing.JLabel(); jLabel1.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N jLabel1.setText("Welcome Admin"); tblDocWorkRequest.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N tblDocWorkRequest.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "PatientLocation", "Sender", "Reciever", "Status" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class }; boolean[] canEdit = new boolean[] { false, false, false, false }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane3.setViewportView(tblDocWorkRequest); if (tblDocWorkRequest.getColumnModel().getColumnCount() > 0) { tblDocWorkRequest.getColumnModel().getColumn(0).setResizable(false); tblDocWorkRequest.getColumnModel().getColumn(1).setResizable(false); tblDocWorkRequest.getColumnModel().getColumn(2).setResizable(false); tblDocWorkRequest.getColumnModel().getColumn(3).setResizable(false); } btnTakeReq.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N btnTakeReq.setText("Assign Req"); btnTakeReq.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTakeReqActionPerformed(evt); } }); btnSeeDetails.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N btnSeeDetails.setText("See details"); btnSeeDetails.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSeeDetailsActionPerformed(evt); } }); jLabel3.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N jLabel3.setText("Select Doctors:"); cmbDoctors.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N cmbDoctors.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmbDoctorsActionPerformed(evt); } }); btnBack2.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N btnBack2.setText("Back"); btnBack2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBack2ActionPerformed(evt); } }); btnVitalSign.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N btnVitalSign.setText("See Vital Sign"); btnVitalSign.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnVitalSignActionPerformed(evt); } }); lblStatus.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N lblStatus.setText(" "); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup().addComponent(btnBack2).addGap(18, 18, 18) .addComponent(btnTakeReq, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addComponent(jLabel3).addGap(34, 34, 34) .addComponent(cmbDoctors, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(49, 49, 49) .addComponent(btnSeeDetails)) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(pnlVitalSign, javax.swing.GroupLayout.PREFERRED_SIZE, 806, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(97, 97, 97).addComponent(btnVitalSign)) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 470, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1).addGap(59, 59, 59) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnVitalSign) .addComponent(pnlVitalSign, javax.swing.GroupLayout.PREFERRED_SIZE, 439, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(cmbDoctors, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblStatus)) .addGap(32, 32, 32) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnBack2).addComponent(btnTakeReq).addComponent(btnSeeDetails)))); }// </editor-fold>//GEN-END:initComponents public void populateTable() { DefaultTableModel model = (DefaultTableModel) tblDocWorkRequest.getModel(); model.setRowCount(0); for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) { if (organization instanceof DoctorAdminOrganization) { pdwrequest = (PatientDoctorWorkRequest) request; if (!pdwrequest.getStatus().equals("Task completed")) { Object[] row = new Object[4]; row[0] = pdwrequest; row[1] = pdwrequest.getSender().getUserName(); row[2] = pdwrequest.getReceiver() == null ? "Not assigned" : request.getReceiver().getEmployee().getFirstName(); row[3] = pdwrequest.getStatus(); model.addRow(row); } } } } public void populateChart() { int size = pdwrequest.getAssignedPatient().getVitalSignDirectory().getVitalSignList().size(); vitalSign = pdwrequest.getAssignedPatient().getVitalSignDirectory().getVitalSignList().get(size - 1); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); dataSet.setValue(vitalSign.getsBloodPressure(), "Status", "Systolic Blood Pressure"); dataSet.setValue(vitalSign.getdBloodPressure(), "Status", "Diabolic Blood Pressure"); dataSet.setValue(vitalSign.getHeartRate(), "Status", "Heart Rate"); dataSet.setValue(vitalSign.getWeight(), "Status", "Weight"); dataSet.setValue(vitalSign.getTemperature(), "Status", "Temperature"); JFreeChart chart = ChartFactory.createBarChart( pdwrequest.getAssignedPatient().getFirstName() + "'s Vital Sign Record", "Vital Signs", "Report Status", dataSet, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ((BarRenderer) p.getRenderer()).setBarPainter(new StandardBarPainter()); BarRenderer r = (BarRenderer) chart.getCategoryPlot().getRenderer(); CP = new ChartPanel(chart); pnlVitalSign.add(CP, BorderLayout.CENTER); pnlVitalSign.validate(); } private void populateDoctorCombo() { for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) { if (org instanceof DoctorOrganization) { for (Employee emp : org.getEmployeeDirectory().getEmployeeList()) { cmbDoctors.addItem(emp); } } } } private void btnTakeReqActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTakeReqActionPerformed // Set getReciever as the doctor's useraccount from the combo box // int flag = 0; int selectedRow = tblDocWorkRequest.getSelectedRow(); if (selectedRow >= 0) { request = (WorkRequest) tblDocWorkRequest.getValueAt(selectedRow, 0); request.setReceiver(assignedDoctor.getUserAccount()); request.setStatus("Pending"); populateTable(); } else { JOptionPane.showMessageDialog(null, "Please select a row from the table"); } }//GEN-LAST:event_btnTakeReqActionPerformed private void btnSeeDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSeeDetailsActionPerformed // TODO add your handling code here: int selectedRow = tblDocWorkRequest.getSelectedRow(); if (selectedRow >= 0) { pdwrequest = (PatientDoctorWorkRequest) tblDocWorkRequest.getValueAt(selectedRow, 0); pdwrequest.setStatus("Processing"); pdwrequest.setReceiver(assignedDoctor.getUserAccount()); assignedPatient = pdwrequest.getAssignedPatient(); DoctorAdminConfirmRequestJPanel dcrjp = new DoctorAdminConfirmRequestJPanel(userProcessContainer, system, enterprise, account, pdwrequest); userProcessContainer.add("processWorkRequestJPanel", dcrjp); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.next(userProcessContainer); } else { JOptionPane.showMessageDialog(null, "Please select a row from the table to process"); } }//GEN-LAST:event_btnSeeDetailsActionPerformed private void cmbDoctorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbDoctorsActionPerformed assignedDoctor = (Employee) cmbDoctors.getSelectedItem(); int count = 0; for (WorkRequest workRequest : assignedDoctor.getUserAccount().getWorkQueue().getWorkRequestList()) { if (!workRequest.getStatus().equals("Task completed")) { count++; } } if (count == 0) { lblStatus.setBackground(Color.green); lblStatus.setText("Available"); } else { lblStatus.setBackground(Color.yellow); lblStatus.setText("Assisting other patients"); } }//GEN-LAST:event_cmbDoctorsActionPerformed private void btnBack2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBack2ActionPerformed // TODO add your handling code here: userProcessContainer.remove(this); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.previous(userProcessContainer); }//GEN-LAST:event_btnBack2ActionPerformed private void btnVitalSignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVitalSignActionPerformed int selectedRow = (int) tblDocWorkRequest.getSelectedRow(); if (selectedRow >= 0) { pdwrequest = (PatientDoctorWorkRequest) tblDocWorkRequest.getValueAt(selectedRow, 0); populateChart(); } else { JOptionPane.showMessageDialog(null, "Please select a row from the table to be deleted", "Information", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_btnVitalSignActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnBack2; private javax.swing.JButton btnSeeDetails; private javax.swing.JButton btnTakeReq; private javax.swing.JButton btnVitalSign; private javax.swing.JComboBox cmbDoctors; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JLabel lblStatus; private javax.swing.JPanel pnlVitalSign; private javax.swing.JTable tblDocWorkRequest; // End of variables declaration//GEN-END:variables }