/** * Inserts a lab procedure into the database. * * @param b The LabProcedureBean to be inserted. * @return A long containing the ID of the newly inserted lab procedure bean. * @throws DBException */ public long addLabProcedure(LabProcedureBean b) throws DBException { Connection conn = null; PreparedStatement ps = null; try { if (b.getPid() == 0L) throw new SQLException("PatientMID cannot be null"); conn = factory.getConnection(); ps = conn.prepareStatement( "INSERT INTO LabProcedure (PatientMID, LaboratoryProcedureCode, Status, Commentary, Results, OfficeVisitID, Rights) VALUES (?,?,?,?,?,?,?)"); ps.setLong(1, b.getPid()); ps.setString(2, b.getLoinc()); ps.setString(3, b.getStatus()); ps.setString(4, b.getCommentary()); ps.setString(5, b.getResults()); ps.setLong(6, b.getOvID()); ps.setString(7, b.getRights()); ps.executeUpdate(); return DBUtil.getLastInsert(conn); } catch (SQLException e) { e.printStackTrace(); throw new DBException(e); } finally { DBUtil.closeConnection(conn, ps); } }
public void testUpdateRights() throws Exception { long id = lpDAO.addLabProcedure(l); LabProcedureBean procedures = lpDAO.getLabProcedure(id); assertEquals(1L, procedures.getPid()); l.allow(); l.setProcedureID(id); lpDAO.updateRights(l); LabProcedureBean updprocedures = lpDAO.getLabProcedure(id); assertEquals(LabProcedureBean.Allow, updprocedures.getRights()); }
/** * Updates the rights of a user on a given lab procedure. * * @param b The LabProcedureBean in question. * @throws DBException */ public void updateRights(LabProcedureBean b) throws DBException { Connection conn = null; PreparedStatement ps = null; try { if (b.getPid() == 0L) throw new SQLException("PatientMID cannot be null"); conn = factory.getConnection(); ps = conn.prepareStatement( "UPDATE LabProcedure SET Rights = ?, UpdatedDate = ? WHERE LaboratoryProcedureID=?"); ps.setString(1, b.getRights()); ps.setTimestamp(2, new java.sql.Timestamp(System.currentTimeMillis())); ps.setLong(3, b.getProcedureID()); ps.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); throw new DBException(e); } finally { DBUtil.closeConnection(conn, ps); } }
/** * testGetLabProc * * @throws Exception */ public void testGetLabProc() throws Exception { LabProcedureBean lp = new LabProcedureBean(); lp.setPid(2L); lp.setLoinc("10763-1"); lp.setCommentary("This is a test"); lp.setOvID(902L); lp.setResults("Test Result"); lp.allow(); lp.statusReceived(); lp.setLTID(5000000005L); long id = lpDAO.addLabProcedure(lp); lp.setProcedureID(id); assertEquals(lp.getCommentary(), action.getLabProcedure(id).getCommentary()); assertEquals(lp.getPid(), action.getLabProcedure(id).getPid()); assertEquals(lp.getLoinc(), action.getLabProcedure(id).getLoinc()); assertEquals(lp.getOvID(), action.getLabProcedure(id).getOvID()); assertEquals(lp.getResults(), action.getLabProcedure(id).getResults()); assertEquals(lp.getLTID(), action.getLabProcedure(id).getLTID()); assertEquals(lp.getStatus(), action.getLabProcedure(id).getStatus()); assertEquals(lp.getRights(), action.getLabProcedure(id).getRights()); }