UserInterfaces.HAdministration.ReportDataJPanel.java Source code

Java tutorial

Introduction

Here is the source code for UserInterfaces.HAdministration.ReportDataJPanel.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 UserInterfaces.HAdministration;

import Business.EcoSystem;
import Business.Enterprise.ClinicEnterprise;
import Business.Enterprise.Enterprise;
import Business.Enterprise.HospitalEnterprise;
import Business.NetWork.Network;
import Business.Organization.Organization;
import Business.Report.ReportToReporter;
import Business.UserAccount.UserAccount;
import Business.Util.ErrorUtil;
import Business.Util.Reportsatifty;
import Business.Util.Source;
import Business.UtilPersonnel.AdminstrationErrorPerson;
import Business.UtilPersonnel.ErrorPerson;
import Business.UtilPersonnel.NurseErrorPerson;
import Business.UtilPersonnel.PathologistriceErrorPerson;
import Business.UtilPersonnel.PharmacistErrorPerson;
import Business.UtilPersonnel.PhysicianErrorPerson;
import Business.UtilPersonnel.SurgeonErrorPerson;
import Business.WorkQueue.WorkRequest;
import java.awt.CardLayout;
import java.awt.Color;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

/**
 *
 * @author Jeremy
 */
public class ReportDataJPanel extends javax.swing.JPanel {

    /**
     * Creates new form ReportToReporterDataJPanel
     */
    JPanel container;
    UserAccount ua;
    Organization organization;
    Enterprise enterprise;
    EcoSystem es;

    public ReportDataJPanel(JPanel container, UserAccount ua, Organization org, Enterprise enterpirse,
            EcoSystem ecoSystem) {
        initComponents();
        this.container = container;
        this.ua = ua;
        this.organization = org;
        this.enterprise = enterpirse;
        es = ecoSystem;

    }

    /**
     * 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() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jLabel1 = new javax.swing.JLabel();
        level1jButton1 = new javax.swing.JButton();
        feedjButton2 = new javax.swing.JButton();
        personneljButton3 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        sourcejButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        backjButton1 = new javax.swing.JButton();

        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 18)); // NOI18N
        jLabel1.setText("Report Data");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(267, 34, 180, -1));

        level1jButton1.setText("View");
        level1jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                level1jButton1ActionPerformed(evt);
            }
        });
        add(level1jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 150, -1, -1));

        feedjButton2.setText("View");
        feedjButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                feedjButton2ActionPerformed(evt);
            }
        });
        add(feedjButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(630, 260, -1, -1));

        personneljButton3.setText("View");
        personneljButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                personneljButton3ActionPerformed(evt);
            }
        });
        add(personneljButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 200, -1, -1));

        jLabel2.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
        jLabel2.setText("Were the reporter satisfied with the respond of the institutes they reported :");
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 260, -1, -1));

        sourcejButton1.setText("View");
        sourcejButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sourcejButton1ActionPerformed(evt);
            }
        });
        add(sourcejButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 320, -1, -1));

        jLabel3.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
        jLabel3.setText("Reported Medical Error");
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 150, -1, -1));

        jLabel4.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
        jLabel4.setText("Related Personnel of Reported Medical Error");
        add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 200, -1, -1));

        jLabel5.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
        jLabel5.setText("Source of Reports");
        add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 320, -1, -1));

        backjButton1.setText("back");
        backjButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backjButton1ActionPerformed(evt);
            }
        });
        add(backjButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 20, -1, -1));
    }// </editor-fold>//GEN-END:initComponents

    private void feedjButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_feedjButton2ActionPerformed
        // TODO add your handling code here:
        int satifynumber = 0;
        int unsatnumber = 0;

        //pop the last report
        //int workrequestSize = organization.getWorkQueue().getWorkRequestList().size();
        //WorkRequest lastRequest = organization.getWorkQueue().getWorkRequestList().get(workrequestSize - 1);
        for (WorkRequest workRequest : organization.getWorkQueue().getWorkRequestList()) {
            if (workRequest.getSatisfylevel().toString().equals(Reportsatifty.YES)) {
                satifynumber = satifynumber + 1;
            }
            if (workRequest.getSatisfylevel().toString().equals(Reportsatifty.NO)) {
                unsatnumber = unsatnumber + 1;
            }
        }

        ReportToReporter report = organization.getReport();
        report.setYes(satifynumber);
        report.setNo(unsatnumber);
        report.setStatus("success");

        DefaultPieDataset pieDataset = new DefaultPieDataset();
        pieDataset.setValue("satisfy", satifynumber);
        pieDataset.setValue("not satisfy", unsatnumber);
        JFreeChart chart = ChartFactory.createPieChart("Satifaction", pieDataset, true, true, true);

        PiePlot p = (PiePlot) chart.getPlot();
        // p.setForegroundAlpha(TOP_ALIGNMENT);

        ChartFrame frame = new ChartFrame("Chart for Satifaction", chart);
        frame.setVisible(true);
        frame.setSize(350, 450);

        //set the report to the enterprise`s report
        //so all the organization within the enterprise could get it
        for (Network network : es.getNetworkList()) {
            for (Enterprise e : network.getEd().getEnterprisesList()) {

                if (e.getOrgName().equals(enterprise.getOrgName())) {
                    for (Enterprise en : network.getEd().getEnterprisesList()) {
                        if (en instanceof HospitalEnterprise || en instanceof ClinicEnterprise) {
                            en.setReport(report);
                            // System.out.println(en);
                        }

                    }
                }

            }

        }

        //for (WorkRequest workRequest : organization.getWorkQueue().getWorkRequestList()) {

    }//GEN-LAST:event_feedjButton2ActionPerformed

    private void level1jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_level1jButton1ActionPerformed
        // TODO add your handling code here:

        int incidentnumber = 0;
        int unsafenumber = 0;
        int nearmissnumber = 0;
        int maxlevel1number = 0;

        for (WorkRequest workRequest : organization.getWorkQueue().getWorkRequestList()) {
            if (workRequest.getLevel1().toString().equals(ErrorUtil.INCIDENT)) {
                incidentnumber = incidentnumber + 1;
            }
            if (workRequest.getLevel1().toString().equals(ErrorUtil.UNSAFE_CONDITION)) {
                unsafenumber = unsafenumber + 1;
            }
            if (workRequest.getLevel1().toString().equals(ErrorUtil.NEAR_MISS)) {
                nearmissnumber = nearmissnumber + 1;
            }

        }
        if (incidentnumber > maxlevel1number) {
            maxlevel1number = incidentnumber;
            if (unsafenumber > maxlevel1number) {
                maxlevel1number = unsafenumber;
                if (nearmissnumber > maxlevel1number) {
                    maxlevel1number = nearmissnumber;

                }

            }

        }

        ReportToReporter report = organization.getReport();
        report.setMaxlevel1(maxlevel1number);
        report.setNearmissnumber(nearmissnumber);
        report.setUnsafenumber(unsafenumber);
        report.setIncidentnumber(incidentnumber);
        report.setStatus("success");

        // Level1reportJPanel ljp = new Level1reportJPanel(container, report);
        //container.add("Level1reportJPanel", ljp);
        //CardLayout layout = (CardLayout) container.getLayout();
        //layout.next(container);
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(nearmissnumber, "Near miss", "Near miss");
        dataset.addValue(unsafenumber, "Unsafe condition", "Unsafe condition");
        dataset.addValue(incidentnumber, "incident", "incident");
        //dataset.setValue(80, "masd", "sss");

        JFreeChart chart = ChartFactory.createBarChart("Level1 Error", "Error Name", "Times", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setRangeGridlinePaint(Color.DARK_GRAY);
        ChartFrame frame = new ChartFrame("Chart for ERROR", chart);
        frame.setVisible(true);
        frame.setSize(450, 550);

        //set the report to the enterprise's report
        //this means all the enterprise(all the organization also) within one network could have the access to see 
        //the report (these report are based on all the data from one network'enterprise ) 
        for (Network network : es.getNetworkList()) {
            for (Enterprise e : network.getEd().getEnterprisesList()) {
                if (e.getOrgName().equals(enterprise.getOrgName())) {
                    for (Enterprise en : network.getEd().getEnterprisesList()) {
                        if (en instanceof HospitalEnterprise || en instanceof ClinicEnterprise) {
                            en.setReport(report);
                        }
                    }
                }
            }
        }
        // report.getMaxlevel1() = maxlevel1number;

    }//GEN-LAST:event_level1jButton1ActionPerformed

    private void sourcejButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourcejButton1ActionPerformed
        // TODO add your handling code here:
        int firsthandnumber = 0;
        int secondhandnumber = 0;

        // int workrequestSize = organization.getWorkQueue().getWorkRequestList().size();
        // WorkRequest lastRequest = organization.getWorkQueue().getWorkRequestList().get(workrequestSize - 1);
        for (WorkRequest workRequest : organization.getWorkQueue().getWorkRequestList()) {
            if (workRequest.getSource().toString().equals(Source.FIRST)) {
                firsthandnumber = firsthandnumber + 1;
            }
            if (workRequest.getSource().toString().equals(Source.SECOND)) {
                secondhandnumber = secondhandnumber + 1;
            }
        }

        ReportToReporter report = organization.getReport();
        report.setFirsthandsource(firsthandnumber);
        report.setSecondhandsource(secondhandnumber);
        report.setStatus("success");

        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("First hand", firsthandnumber);
        dataset.setValue("Second hand", secondhandnumber);

        JFreeChart chart = ChartFactory.createPieChart("Source of Reports", dataset, true, true, true);

        PiePlot p = (PiePlot) chart.getPlot();

        ChartFrame chartFrame = new ChartFrame("Source of Reports", chart);
        chartFrame.setSize(450, 550);
        chartFrame.setVisible(true);

        for (Network network : es.getNetworkList()) {
            for (Enterprise e : network.getEd().getEnterprisesList()) {
                if (e.getOrgName().equals(enterprise.getOrgName())) {
                    for (Enterprise en : network.getEd().getEnterprisesList()) {
                        if (en instanceof HospitalEnterprise || en instanceof ClinicEnterprise) {
                            en.setReport(report);
                        }
                    }
                }
            }

        }

    }//GEN-LAST:event_sourcejButton1ActionPerformed

    private void personneljButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_personneljButton3ActionPerformed
        // TODO add your handling code here:
        int timeofadmin = 0;
        int timeofnurse = 0;
        int timeofpathology = 0;
        int timeofphar = 0;
        int timeofphysician = 0;
        int timeofsurgeon = 0;

        for (WorkRequest workRequest : organization.getWorkQueue().getWorkRequestList()) {
            for (ErrorPerson ep : workRequest.getEpd().getErrorpersonlist()) {

                if (ep instanceof AdminstrationErrorPerson) {
                    // if (ep.getEpt().getValue().equals(ErrorPerson.ErrorPersonType.ADMINSTRATION.getValue())) {
                    timeofadmin = timeofadmin + 1;
                }
                if (ep instanceof NurseErrorPerson) {
                    timeofnurse = timeofnurse + 1;
                }
                if (ep instanceof PathologistriceErrorPerson) {
                    timeofpathology = timeofpathology + 1;
                }
                if (ep instanceof PharmacistErrorPerson) {
                    timeofphar = timeofphar + 1;
                }
                if (ep instanceof PhysicianErrorPerson) {
                    timeofphysician = timeofphysician + 1;
                }
                if (ep instanceof SurgeonErrorPerson) {
                    timeofsurgeon = timeofsurgeon + 1;

                }

                /*if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.NURESE)) {
                 timeofnurse = timeofnurse + 1;
                 }
                 if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.PATHOLOGIST)) {
                 timeofpathology = timeofpathology + 1;
                 }
                 if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.PHARMACIST)) {
                 timeofphar = timeofphar + 1;
                 }
                 if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.PHYSICIAN)) {
                 timeofphysician = timeofphysician + 1;
                 }
                 if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.SURGEON)) {
                 timeofsurgeon = timeofsurgeon + 1;
                 }*/
            }
        }
        ReportToReporter report = organization.getReport();
        report.setTimeofadmin(timeofadmin);
        report.setTimeofnurse(timeofnurse);
        report.setTimeofpathology(timeofpathology);
        report.setTimeofphar(timeofphar);
        report.setTimeofphysician(timeofphysician);
        report.setTimeofsurgeon(timeofsurgeon);
        report.setStatus("success");

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(timeofadmin, "Adminstration", "Adminstration");
        dataset.addValue(timeofnurse, "Nurse", "Nurse");
        dataset.addValue(timeofpathology, "Pathologist", "Pathologist");
        dataset.addValue(timeofphar, "Pharmacist", "Pharmacist");
        dataset.addValue(timeofphysician, "Physician", "Physician");
        dataset.addValue(timeofsurgeon, "Surgeon", "Surgeon");
        //dataset.setValue(80, "masd", "sss");

        JFreeChart chart = ChartFactory.createBarChart("Personnel", "Position", "Times", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setRangeGridlinePaint(Color.WHITE);
        ChartFrame frame = new ChartFrame("Chart for ERROR", chart);
        frame.setVisible(true);
        frame.setSize(900, 700);

        for (Network network : es.getNetworkList()) {
            for (Enterprise e : network.getEd().getEnterprisesList()) {
                if (e.getOrgName().equals(enterprise.getOrgName())) {
                    for (Enterprise en : network.getEd().getEnterprisesList()) {
                        if (e instanceof HospitalEnterprise || e instanceof ClinicEnterprise) {
                            e.setReport(report);
                        }
                    }
                }

            }

        }

    }//GEN-LAST:event_personneljButton3ActionPerformed

    private void backjButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backjButton1ActionPerformed
        // TODO add your handling code here:
        container.remove(this);
        CardLayout cl = (CardLayout) container.getLayout();
        cl.previous(container);
    }//GEN-LAST:event_backjButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backjButton1;
    private javax.swing.JButton feedjButton2;
    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.JPopupMenu jPopupMenu1;
    private javax.swing.JButton level1jButton1;
    private javax.swing.JButton personneljButton3;
    private javax.swing.JButton sourcejButton1;
    // End of variables declaration//GEN-END:variables
}