UserInterface.CentreForDiseaseControl.DataAnalysis.java Source code

Java tutorial

Introduction

Here is the source code for UserInterface.CentreForDiseaseControl.DataAnalysis.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 UserInterface.CentreForDiseaseControl;

import Business.Enterprise.CDCEnterprise;
import Business.Enterprise.PHDEnterprise;
import Business.Enterprise.SiteEnterprise;
import Business.Enterprise.VaccineManufacturerEnterprise;
import Business.Network.Network;
import Business.Order.Order;
import Business.Order.OrderItem;
import Business.Person.Patient;
import Business.Person.Person;
import java.awt.CardLayout;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;

/**
 *
 * @author Rishika Idnani
 */
public class DataAnalysis extends javax.swing.JPanel {

    /**
     * Creates new form DataAnalysis
     */
    private JPanel userProcessContainer;
    private CDCEnterprise enterprise;
    private Network network;

    public DataAnalysis(JPanel userProcessContainer, CDCEnterprise enterprise) {
        initComponents();
        this.userProcessContainer = userProcessContainer;
        this.enterprise = enterprise;
        this.network = enterprise.getNetwork();

        getMostPopularManufacturer();
    }

    public void getMostPopularManufacturer() {
        int totalVaccinesSold = 0;
        int totalQuantity = 0;
        VaccineManufacturerEnterprise popularManufacturer = null;

        for (VaccineManufacturerEnterprise manufactureres : enterprise.getVaccineManufacturerList()) {
            for (Order order : enterprise.getMasterOrderCatalog().getOrderList()) {
                for (OrderItem orderItem : order.getOrderItemList()) {
                    if (orderItem.getVaccine().getVaccineManufacturer() == manufactureres) {
                        totalQuantity = totalQuantity + orderItem.getTotalQuantity();
                        if (totalQuantity > totalVaccinesSold) {
                            totalVaccinesSold = totalQuantity;
                            popularManufacturer = manufactureres;
                        }
                    }
                }
            }
            totalQuantity = 0;
        }
        if (popularManufacturer != null) {
            popularManufacturerJTextField.setText(popularManufacturer.getName());
        }
    }

    /**
     * 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();
        jLabel2 = new javax.swing.JLabel();
        popularManufacturerJTextField = new javax.swing.JTextField();
        salesDetailJButton = new javax.swing.JButton();
        summarizeInsuranceJButton = new javax.swing.JButton();
        backJButton = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel1.setText("Data Analysis");

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel2.setText("Most Popular Manufacturer");

        popularManufacturerJTextField.setEditable(false);

        salesDetailJButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        salesDetailJButton.setText("Sales detail of each manufacturer");
        salesDetailJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salesDetailJButtonActionPerformed(evt);
            }
        });

        summarizeInsuranceJButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        summarizeInsuranceJButton.setText("Summarize Insurance Information of Citizens");
        summarizeInsuranceJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                summarizeInsuranceJButtonActionPerformed(evt);
            }
        });

        backJButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        backJButton.setText("<< Back");
        backJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backJButtonActionPerformed(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().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel1)
                        .addGroup(layout.createSequentialGroup().addComponent(jLabel2).addGap(18, 18, 18)
                                .addComponent(popularManufacturerJTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        117, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(salesDetailJButton, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(summarizeInsuranceJButton, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE))
                        .addComponent(backJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 97,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(264, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1).addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2).addComponent(popularManufacturerJTextField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30).addComponent(salesDetailJButton).addGap(27, 27, 27)
                        .addComponent(summarizeInsuranceJButton).addGap(26, 26, 26).addComponent(backJButton)
                        .addContainerGap(110, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents

    private void salesDetailJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salesDetailJButtonActionPerformed
        // TODO add your handling code here:
        int totalVaccinesSold = 0;
        int totalQuantity = 0;
        VaccineManufacturerEnterprise popularManufacturer = null;
        DefaultPieDataset pieDataset = new DefaultPieDataset();

        for (VaccineManufacturerEnterprise manufactureres : enterprise.getVaccineManufacturerList()) {
            for (Order order : enterprise.getMasterOrderCatalog().getOrderList()) {
                for (OrderItem orderItem : order.getOrderItemList()) {
                    if (orderItem.getVaccine().getVaccineManufacturer() == manufactureres) {
                        totalQuantity = totalQuantity + orderItem.getTotalQuantity();
                        if (totalQuantity > totalVaccinesSold) {
                            totalVaccinesSold = totalQuantity;
                            popularManufacturer = manufactureres;
                        }
                    }
                }
            }
            pieDataset.setValue(manufactureres.getName(), totalQuantity);
            totalQuantity = 0;
        }

        JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true);
        PiePlot p = (PiePlot) chart.getPlot();
        ChartFrame frame = new ChartFrame("Sale details of Manufacturers", chart);
        frame.setVisible(true);
        frame.setSize(450, 500);

    }//GEN-LAST:event_salesDetailJButtonActionPerformed

    private void summarizeInsuranceJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_summarizeInsuranceJButtonActionPerformed
        // TODO add your handling code here:
        DefaultPieDataset pieDataset = new DefaultPieDataset();
        int numberOfCitizensWithNoInsurance = 0;

        for (PHDEnterprise phdEnterprise : enterprise.getPhdList()) {
            for (SiteEnterprise siteEnterprise : phdEnterprise.getSiteList()) {
                for (Person person : siteEnterprise.getPersonDirectory().getPersonList()) {
                    if (person instanceof Patient) {
                        Patient patient = (Patient) person;
                        if (patient.getInsuranceInformation().equals("No Insurance")) {
                            numberOfCitizensWithNoInsurance++;
                        }
                    }
                }
            }
        }
        pieDataset.setValue("No Insurance", numberOfCitizensWithNoInsurance);

        int numberOfCitizensWithPrivateInsurance = 0;

        for (PHDEnterprise phdEnterprise : enterprise.getPhdList()) {
            for (SiteEnterprise siteEnterprise : phdEnterprise.getSiteList()) {
                for (Person person : siteEnterprise.getPersonDirectory().getPersonList()) {
                    if (person instanceof Patient) {
                        Patient patient = (Patient) person;
                        if (patient.getInsuranceInformation().equals("Private Insurance Coverage")) {
                            numberOfCitizensWithPrivateInsurance++;
                        }
                    }
                }
            }
        }
        pieDataset.setValue("Private Insurance", numberOfCitizensWithPrivateInsurance);

        int numberOfCitizensUnderInsured = 0;

        for (PHDEnterprise phdEnterprise : enterprise.getPhdList()) {
            for (SiteEnterprise siteEnterprise : phdEnterprise.getSiteList()) {
                for (Person person : siteEnterprise.getPersonDirectory().getPersonList()) {
                    if (person instanceof Patient) {
                        Patient patient = (Patient) person;
                        if (patient.getInsuranceInformation().equals("Under Insured")) {
                            numberOfCitizensUnderInsured++;
                        }
                    }
                }
            }
        }
        pieDataset.setValue("Under Insured", numberOfCitizensUnderInsured);

        JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true);
        PiePlot p = (PiePlot) chart.getPlot();
        ChartFrame frame = new ChartFrame("Insurance Information of Citizens", chart);
        frame.setVisible(true);
        frame.setSize(450, 500);
    }//GEN-LAST:event_summarizeInsuranceJButtonActionPerformed

    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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backJButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField popularManufacturerJTextField;
    private javax.swing.JButton salesDetailJButton;
    private javax.swing.JButton summarizeInsuranceJButton;
    // End of variables declaration//GEN-END:variables
}