UserInterface.QuickAssist.SeePatientDetailsJPanel.java Source code

Java tutorial

Introduction

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

import Business.Enterprise.Enterprise;
import Business.Network.Network;
import Business.Organization.Organization;
import Business.Organization.PatientOrganization;
import Business.Patient.Patient;
import Business.Patient.VitalSign;
import Business.QuickAssist;
import Business.UserAccount.UserAccount;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
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 SeePatientDetailsJPanel extends javax.swing.JPanel {

    JPanel userProcessContainer;
    QuickAssist system;
    Organization organization;
    UserAccount userAccount;
    Enterprise enterprise;
    int dBP;
    int sBP;
    int weight;
    int pulse;
    int heartRate;
    int temperature;
    int respRate;
    Date dateobj;
    Patient patient;
    double patLong;
    double patLat;
    VitalSign vitalSign;
    String condition = "Abnormal";
    Random rand = new Random();
    static int currRand;
    Network network;
    ChartPanel CP;

    /**
     * Creates new form PatientWorkAreaJPanel
     */
    public SeePatientDetailsJPanel(JPanel userProcessContainer, UserAccount account, Organization organization,
            Enterprise enterprise, QuickAssist system, Network network) {
        initComponents();
        this.setBackground(Color.white);
        this.userProcessContainer = userProcessContainer;
        this.system = system;
        this.organization = organization;
        this.userAccount = account;
        this.enterprise = enterprise;
        this.network = network;
        populateSensors();
        disableTxtFields();
    }

    /**
     * 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();
        jLabel3 = new javax.swing.JLabel();
        txtSBP = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtWeight = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtRespRate = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtHeartRate = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtTemperature = new javax.swing.JTextField();
        lblNormalAbnormal = new javax.swing.JLabel();
        lblTimeStamp = new javax.swing.JLabel();
        lblTimeStampDisable = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        cmbSensor = new javax.swing.JComboBox();
        lblPatientDisable = new javax.swing.JLabel();
        pnlVitalSignChart = new javax.swing.JPanel();
        lblPatientName = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtDBP = new javax.swing.JTextField();
        lblCondition = new javax.swing.JLabel();
        btnRequestMedicines = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        jLabel1.setText("SensorAdminWorkArea");

        jLabel2.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel2.setText("Recorded Vital Signs:");

        jLabel3.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel3.setText("Systolic B.P ");

        txtSBP.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        txtSBP.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtSBPKeyPressed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel4.setText("Weight");

        txtWeight.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        txtWeight.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtWeightKeyPressed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel5.setText("Respiratory Rate");

        txtRespRate.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        txtRespRate.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtRespRateKeyPressed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel6.setText("Heart Rate");

        txtHeartRate.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        txtHeartRate.setText(" ");
        txtHeartRate.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtHeartRateKeyPressed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel7.setText("Temperature");

        txtTemperature.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        txtTemperature.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtTemperatureKeyPressed(evt);
            }
        });

        lblNormalAbnormal.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        lblNormalAbnormal.setForeground(new java.awt.Color(255, 255, 255));

        lblTimeStamp.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N

        lblTimeStampDisable.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        lblTimeStampDisable.setText("Time Stamp:");

        jLabel8.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel8.setText("Select Sensor:");

        cmbSensor.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        cmbSensor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbSensorActionPerformed(evt);
            }
        });

        lblPatientDisable.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        lblPatientDisable.setText("Patient Name:");

        lblPatientName.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        lblPatientName.setText("   ");

        jLabel9.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel9.setText("Diastolic  B.P ");

        txtDBP.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        txtDBP.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDBPKeyPressed(evt);
            }
        });

        lblCondition.setText("  ");

        btnRequestMedicines.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        btnRequestMedicines.setText("Request Assistance");
        btnRequestMedicines.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRequestMedicinesActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jButton1.setText("Back");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(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)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 182,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(
                                                lblCondition, javax.swing.GroupLayout.PREFERRED_SIZE, 224,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(554, 554, 554))
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                layout.createSequentialGroup().addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                        .addGroup(layout.createSequentialGroup()
                                                                .addGroup(layout.createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                        .addComponent(jLabel7)
                                                                        .addComponent(jLabel6))
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE)
                                                                .addGroup(layout.createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                        .addComponent(txtHeartRate,
                                                                                javax.swing.GroupLayout.Alignment.TRAILING,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                133,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addComponent(txtTemperature,
                                                                                javax.swing.GroupLayout.Alignment.TRAILING,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                133,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                        .addGroup(layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(jLabel2)
                                                                .addGroup(layout.createSequentialGroup()
                                                                        .addGroup(layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                .addComponent(jLabel5)
                                                                                .addComponent(jLabel4)
                                                                                .addComponent(jLabel9)
                                                                                .addComponent(jLabel3))
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addGroup(layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                .addComponent(txtSBP,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        133,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                .addComponent(txtDBP,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        133,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                .addComponent(txtRespRate,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        133,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                .addComponent(txtWeight,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        133,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(pnlVitalSignChart,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 767,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                layout.createSequentialGroup().addComponent(jButton1)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(btnRequestMedicines)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 153,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(
                                                        lblPatientDisable, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGap(83, 83, 83)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lblPatientName,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 230,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(cmbSensor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        232, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(577, 577, 577))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(lblNormalAbnormal,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 247,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(lblTimeStampDisable))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(lblTimeStamp, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        207, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(1624, 1624, 1624)))));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
                                        .createSequentialGroup().addGap(93, 93, 93).addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel3).addComponent(txtSBP,
                                                        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(jLabel9)
                                                .addComponent(txtDBP, 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(jLabel4)
                                                .addComponent(txtWeight, 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(jLabel5).addComponent(txtRespRate,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(txtHeartRate, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel6))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel7).addComponent(txtTemperature,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createSequentialGroup().addComponent(lblCondition).addGap(21, 21, 21)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(pnlVitalSignChart, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                430, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel8).addComponent(cmbSensor,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(lblPatientDisable)
                                                        .addComponent(lblPatientName))))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                        .addComponent(lblNormalAbnormal, javax.swing.GroupLayout.PREFERRED_SIZE, 26,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(105, 105, 105)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lblTimeStampDisable,
                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(lblTimeStamp, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 19,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton1))
                                .addComponent(btnRequestMedicines, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addContainerGap()));
    }// </editor-fold>//GEN-END:initComponents

    private void disableTxtFields() {
        txtSBP.setEditable(false);
        txtHeartRate.setEditable(false);
        txtRespRate.setEditable(false);
        txtTemperature.setEditable(false);
        txtWeight.setEditable(false);
    }

    //    private void deletePatients(){
    //        for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) {
    //            if (org instanceof PatientOrganization) {
    //                for (Patient p : org.getPatientDirectory().getPatientList()) {
    //                    if(p.getSensorId()==""){
    //                        org.getPatientDirectory().getPatientList().remove(p);
    //                    }
    //                }
    //            }
    //        }
    //    }
    private void populateSensors() {
        for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) {
            if (org instanceof PatientOrganization) {
                for (Patient p : org.getPatientDirectory().getPatientList()) {
                    patient = p;
                    cmbSensor.addItem(p.getSensorId());

                }
            }
        }
    }

    private int generateVitalSignValues() {

        //bloodPressure= (int) (Math.random()*100);
        Random r = new Random();
        int Low = 30;
        int High = 100;
        int Result = r.nextInt(High - Low) + Low;
        return Result;
    }

    private int generateLongitude() {
        Random r = new Random();
        int Low = 1;
        int High = 100;
        int Result = r.nextInt(High - Low) + Low;
        return Result;
    }

    private int generateLatitude() {
        Random r = new Random();
        int Low = 1;
        int High = 100;
        int Result = r.nextInt(High - Low) + Low;
        return Result;
    }

    private void populateVitalSignFields() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        txtSBP.setText(String.valueOf(sBP));
        txtRespRate.setText(String.valueOf(respRate));
        txtHeartRate.setText(String.valueOf(heartRate));
        txtWeight.setText(String.valueOf(weight));
        txtTemperature.setText(String.valueOf(temperature));
        txtDBP.setText(String.valueOf(dBP));
        lblCondition.setText(condition);
        lblTimeStamp.setText(dateFormat.format(dateobj));
    }

    private int generatesBPValues() {

        //bloodPressure= (int) (Math.random()*100);
        Random r = new Random();
        int Low = 70;
        int High = 170;
        int Result = r.nextInt(High - Low) + Low;
        return Result;
    }

    private int generatedBPValues() {

        //bloodPressure= (int) (Math.random()*100);
        Random r = new Random();
        int Low = 40;
        int High = 90;
        int Result = r.nextInt(High - Low) + Low;
        return Result;
    }

    private int generateTemperatureValues() {

        //bloodPressure= (int) (Math.random()*100);
        Random r = new Random();
        int Low = 100;
        int High = 109;
        int Result = r.nextInt(High - Low) + Low;
        return Result;
    }

    private int generateRespRateValues() {

        //bloodPressure= (int) (Math.random()*100);
        Random r = new Random();
        int Low = 10;
        int High = 38;
        int Result = r.nextInt(High - Low) + Low;
        return Result;
    }

    private int generateWeightValues() {

        //bloodPressure= (int) (Math.random()*100);
        Random r = new Random();
        int Low = 20;
        int High = 130;
        int Result = r.nextInt(High - Low) + Low;
        return Result;
    }

    private int generateHeartRateValues() {

        //bloodPressure= (int) (Math.random()*100);
        Random r = new Random();
        int Low = 30;
        int High = 170;
        int Result = r.nextInt(High - Low) + Low;
        return Result;
    }

    public static boolean isBetween(int x, int lower, int upper) {
        return lower <= x && x <= upper;
    }

    public void normalAbnormal(int age) {

        if (isBetween(age, 5, 12)) {

            if ((respRate > 19 && respRate < 31) && (heartRate > 40 && heartRate < 150) && (sBP > 60 && sBP < 150)
                    && (dBP > 50 && dBP < 80) && (weight > 10 && weight < 40)
                    && (temperature > 99 && temperature < 103)) {
                condition = "Normal";
            }

        } else if (isBetween(age, 13, 30)) {
            if ((respRate > 11 && respRate < 31) && (heartRate > 30 && heartRate < 150) && (sBP > 90 && sBP < 150)
                    && (weight > 40 && weight < 70) && (dBP > 50 && dBP < 80)
                    && (temperature > 99 && temperature < 104)) {
                condition = "Normal";
            }

        } else if (isBetween(age, 31, 110)) {
            if ((respRate > 11 && respRate < 31) && (heartRate > 30 && heartRate < 150) && (sBP > 95 && sBP < 150)
                    && (dBP > 50 && dBP < 80) && (weight > 70 && weight < 110)
                    && (temperature > 99 && temperature < 104)) {
                condition = "Normal";
            }
        }
    }

    private void generatePatientVitalSigns() {
        //
        //        bloodPressure = generateVitalSignValues();
        //        pulse = generateVitalSignValues();
        //        heartRate = generateVitalSignValues();
        //        temperature = generateVitalSignValues();
        //        dateobj = new Date();
        //        vitalSign = patient.getVitalSignDirectory().createAndAddVitalSign(bloodPressure, weight, pulse, heartRate, temperature, dateobj);
        dBP = generatedBPValues();
        sBP = generatesBPValues();
        heartRate = generateHeartRateValues();
        for (VitalSign vs : patient.getVitalSignDirectory().getVitalSignList()) {
            if (vs.getWeight() == 0) {
                weight = generateWeightValues();
            } else {
                weight = vs.getWeight();
            }

        }
        temperature = generateTemperatureValues();
        respRate = generateRespRateValues();
        dateobj = new Date();
        normalAbnormal(patient.getAge());
        vitalSign = patient.getVitalSignDirectory().createAndAddVitalSign(dBP, weight, sBP, heartRate, respRate,
                temperature, dateobj, condition);

        populateVitalSignFields();
        if (CP != null) {
            pnlVitalSignChart.removeAll();
        }
        populateChart();

    }

    public void getLocation(double x0, double y0, int radius) {
        Random random = new Random();

        // Convert radius from meters to degrees
        double radiusInDegrees = radius / 111000f;

        double u = random.nextDouble();
        double v = random.nextDouble();
        double w = radiusInDegrees * Math.sqrt(u);
        double t = 2 * Math.PI * v;
        double x = w * Math.cos(t);
        double y = w * Math.sin(t);

        // Adjust the x-coordinate for the shrinking of the east-west distances
        double new_x = x / Math.cos(y0);

        patLong = new_x + x0;
        patLat = y + y0;
    }

    private void cmbSensorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbSensorActionPerformed
        getLocation(42.321371, -71.088806, 8000);

        String name = (String) cmbSensor.getSelectedItem();
        for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) {
            if (org instanceof PatientOrganization) {
                for (Patient p : org.getPatientDirectory().getPatientList()) {
                    if (p.getSensorId().equals(name)) {
                        patient = p;
                        patient.setLongitude(patLong);
                        patient.setLatitude(patLat);
                        lblPatientName.setText(patient.getFirstName());
                        vitalSign = patient.getVitalSignDirectory().getVitalSignList().get(0);
                        weight = vitalSign.getWeight();
                        generatePatientVitalSigns();
                    }
                }
            }
        }

    }//GEN-LAST:event_cmbSensorActionPerformed

    private void txtSBPKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSBPKeyPressed

    }//GEN-LAST:event_txtSBPKeyPressed

    private void txtDBPKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDBPKeyPressed

    }//GEN-LAST:event_txtDBPKeyPressed

    private void txtWeightKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtWeightKeyPressed

    }//GEN-LAST:event_txtWeightKeyPressed

    private void txtRespRateKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRespRateKeyPressed

    }//GEN-LAST:event_txtRespRateKeyPressed

    private void txtHeartRateKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtHeartRateKeyPressed

    }//GEN-LAST:event_txtHeartRateKeyPressed

    private void txtTemperatureKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTemperatureKeyPressed

    }//GEN-LAST:event_txtTemperatureKeyPressed

    private void btnRequestMedicinesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRequestMedicinesActionPerformed
        String id = (String) cmbSensor.getSelectedItem();
        if (id == null) {
            JOptionPane.showMessageDialog(null, "Please select a patient sensor first");
        } else {
            AssistanceRequestedJPanel arjp = new AssistanceRequestedJPanel(userProcessContainer, system,
                    userAccount, enterprise, patient, network);
            userProcessContainer.add("medicineRequestedJPanel", arjp);
            CardLayout layout = (CardLayout) userProcessContainer.getLayout();
            layout.next(userProcessContainer);
        }

    }//GEN-LAST:event_btnRequestMedicinesActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        userProcessContainer.remove(this);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.previous(userProcessContainer);
    }//GEN-LAST:event_jButton1ActionPerformed

    public void populateChart() {
        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(patient.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);
        pnlVitalSignChart.add(CP, BorderLayout.CENTER);
        pnlVitalSignChart.validate();

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnRequestMedicines;
    private javax.swing.JComboBox cmbSensor;
    private javax.swing.JButton jButton1;
    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.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel lblCondition;
    private javax.swing.JLabel lblNormalAbnormal;
    private javax.swing.JLabel lblPatientDisable;
    private javax.swing.JLabel lblPatientName;
    private javax.swing.JLabel lblTimeStamp;
    private javax.swing.JLabel lblTimeStampDisable;
    private javax.swing.JPanel pnlVitalSignChart;
    private javax.swing.JTextField txtDBP;
    private javax.swing.JTextField txtHeartRate;
    private javax.swing.JTextField txtRespRate;
    private javax.swing.JTextField txtSBP;
    private javax.swing.JTextField txtTemperature;
    private javax.swing.JTextField txtWeight;
    // End of variables declaration//GEN-END:variables
}