New JAVA Development seeking help with LabOrder duplicate fields for tracking (Code included)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

New JAVA Development seeking help with LabOrder duplicate fields for tracking (Code included)

stiedt
package LabOrders;

import java.io.PrintWriter;
import java.util.Enumeration;
import java.io.IOException;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author stiedt
 */
@Entity
@Table(name = "laborder")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Laborder.findAll", query = "SELECT l FROM Laborder l")
    , @NamedQuery(name = "Laborder.findByOrderId", query = "SELECT l FROM Laborder l WHERE l.orderId = :orderId")
    , @NamedQuery(name = "Laborder.findByPatientName", query = "SELECT l FROM Laborder l WHERE l.patientName = :patientName")
    , @NamedQuery(name = "Laborder.findByHospitalId", query = "SELECT l FROM Laborder l WHERE l.hospitalId = :hospitalId")
    , @NamedQuery(name = "Laborder.findByMedicalRecordId", query = "SELECT l FROM Laborder l WHERE l.medicalRecordId = :medicalRecordId")
    , @NamedQuery(name = "Laborder.findByOrderDate", query = "SELECT l FROM Laborder l WHERE l.orderDate = :orderDate")
    , @NamedQuery(name = "Laborder.findByLabOrderId", query = "SELECT l FROM Laborder l WHERE l.labOrderId = :labOrderId")
    , @NamedQuery(name = "Laborder.findByPatientId", query = "SELECT l FROM Laborder l WHERE l.patientId = :patientId")
    , @NamedQuery(name = "Laborder.findByOrderStatus", query = "SELECT l FROM Laborder l WHERE l.orderStatus = :orderStatus")
    , @NamedQuery(name = "Laborder.findByStatusChangeDate", query = "SELECT l FROM Laborder l WHERE l.statusChangeDate = :statusChangeDate")})
@SuppressWarnings({"ValidAttributes", "JPQLValidation"})
public class Laborder implements Serializable {
   
    public void handleRequest(HttpServletRequest req, HttpServletResponse res) throws IOException {
        PrintWriter out = res.getWriter();
        res.setContentType("text/plain");
        Enumeration<String> parameterNames = req.getParameterNames();
        while (parameterNames.hasMoreElements()) {
        String paramName = parameterNames.nextElement();
        out.write(paramName);
                    out.write("n");
                    String[] paramValues = req.getParameterValues(paramName);
                    for (int i = 0; i < paramValues.length; i++) {
                        String paramValue = paramValues[i];
                        out.write("t" + paramValue);
                        out.write("n");
                    }
                }
                out.close();
        }
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "OrderId")
    private Integer orderId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "PatientName")
    private String patientName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "HospitalId")
    private int hospitalId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "MedicalRecordId")
    private String medicalRecordId;
    @Basic(optional = false)
    @NotNull
    @Column(name = "OrderDate")
    @Temporal(TemporalType.DATE)
    private Date orderDate;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "LabOrderId")
    private String LabOrderId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "patientId")
    private String patientId;
    @Column(name = "OrderStatus")
    private Integer orderStatus;
    @Column(name = "StatusChangeDate")
    @Temporal(TemporalType.DATE)
    private Date statusChangeDate;

    public Laborder() {
    }
   
    public Laborder(Integer orderId) {
        this.orderId = orderId;
    }
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (orderId != null ? orderId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Laborder)) {
            return false;
        }
        Laborder other = (Laborder) object;
        if ((this.orderId == null && other.orderId != null) || (this.orderId != null && !this.orderId.equals(other.orderId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "LabOrders.Laborder[ orderId=" + orderId + " ]";
    }
    //Testing now
     String error;
    List<Object> allData=new ArrayList<Object>();
    List<Object> CountData=new ArrayList<Object>();    
    Object obj=new Object();
 
    public void setObj(Object obj) {
        this.obj = obj;
    }
    public String getError() {
        return error;
    }

@SuppressWarnings("UseSpecificCatch")
    public List getDb_Data()
    {
        int i=0;
       
        try
        {
                String qry;
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://10.55.149.31:3306/JAVA1","java","TG3nR0x!");
                Statement s = con.createStatement();                
                qry="Select OrderId,patientId,OrderStatus,PatientName,StatusChangeDate,OrderDate,LabOrderId from laborder";
                //ResultSet rs = s.executeQuery("SELECT COUNT(*), LabOrderId FROM laborder GROUP BY LabOrderId");
               
                ResultSet r=s.executeQuery(qry);
                while(r.next())
                {
                    DataFields d=new DataFields(r.getInt(1), r.getString(2), r.getInt(3), r.getString(4), r.getDate(5), r.getDate(6), r.getString(7));                                        
                    allData.add(i,d);
                    LabOrderId = (r.getString(7));
                   
                    String tbl = r.getString(7);
                    String query = ("SELECT COUNT(*) FROM " + tbl);  
                    PreparedStatement cnt = con.prepareStatement(query);                        
                    ResultSet ct = cnt.executeQuery();
                    while (ct.next())
                    {
                        nl.add(tbl);
                    }  
                    return nl;                  
                   
                }
                i++;
        }
        catch(Exception ex)
        {
                error="<b>Contact Administrator :</b><br/>" + ex;
                System.out.println("Your query is not working" + ex);
        }
       return allData;
    }    
@SuppressWarnings({"UseSpecificCatch", "StringEquality"})
       
    public class DataFields
    {
        public int orderid,orderstatus;
        public String patientid, patientname, laborderid;
        public Date statuschangedate, orderdate;
 
        public DataFields(int  OrderId,String  patientId,int  OrderStatus,String PatientName, Date statusChangeDate, Date OrderDate, String LabOrderId) {
            this.orderid=OrderId;
            this.patientid=patientId;
            this.orderstatus=OrderStatus;
            this.patientname=PatientName;
            this.statuschangedate=statusChangeDate;
            this.orderdate=OrderDate;
            this.laborderid=LabOrderId;

        }
    }
    public int getOrderId()
    {
        this.orderId =((DataFields)obj).orderid;
        return this.orderId;
    }
    public String getPatientId() {
        this.patientId =((DataFields)obj).patientid;
        return this.patientId;
    }
    public int getOrderStatus() {
        this.orderStatus =((DataFields)obj).orderstatus;
        return this.orderStatus;
    }
    public String getPatientName() {
        this.patientName =((DataFields)obj).patientname;
        return this.patientName;
    }
    public Date getStatusChangeDate() {
        this.statusChangeDate =((DataFields)obj).statuschangedate;
        return this.statusChangeDate;
    }
    public Date getOrderDate() {
        this.orderDate =((DataFields)obj).orderdate;
        return this.orderDate;
    }
}