public void updateData(SampleHuman sampleHuman) throws LIMSRuntimeException { SampleHuman oldData = readSampleHuman(sampleHuman.getId()); SampleHuman newData = sampleHuman; // add to audit trail try { AuditTrailDAO auditDAO = new AuditTrailDAOImpl(); String sysUserId = sampleHuman.getSysUserId(); String event = IActionConstants.AUDIT_TRAIL_UPDATE; String tableName = "SAMPLE_HUMAN"; auditDAO.saveHistory(newData, oldData, sysUserId, event, tableName); } catch (Exception e) { // bugzilla 2154 LogEvent.logError("SampleHumanDAOImpl", "updateData()", e.toString()); throw new LIMSRuntimeException("Error in SampleHuman AuditTrail updateData()", e); } try { HibernateUtil.getSession().merge(sampleHuman); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); HibernateUtil.getSession().evict(sampleHuman); HibernateUtil.getSession().refresh(sampleHuman); } catch (Exception e) { // bugzilla 2154 LogEvent.logError("SampleHumanDAOImpl", "updateData()", e.toString()); throw new LIMSRuntimeException("Error in SampleHuman updateData()", e); } }
public void deleteData(List sampleHumans) throws LIMSRuntimeException { // add to audit trail try { AuditTrailDAO auditDAO = new AuditTrailDAOImpl(); for (int i = 0; i < sampleHumans.size(); i++) { SampleHuman data = (SampleHuman) sampleHumans.get(i); SampleHuman oldData = (SampleHuman) readSampleHuman(data.getId()); SampleHuman newData = new SampleHuman(); String sysUserId = data.getSysUserId(); String event = IActionConstants.AUDIT_TRAIL_DELETE; String tableName = "SAMPLE_HUMAN"; auditDAO.saveHistory(newData, oldData, sysUserId, event, tableName); } } catch (Exception e) { // bugzilla 2154 LogEvent.logError("SampleHumanDAOImpl", "AuditTrail deleteData()", e.toString()); throw new LIMSRuntimeException("Error in SampleHuman AuditTrail deleteData()", e); } try { for (int i = 0; i < sampleHumans.size(); i++) { SampleHuman data = (SampleHuman) sampleHumans.get(i); // bugzilla 2206 data = (SampleHuman) readSampleHuman(data.getId()); HibernateUtil.getSession().delete(data); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); } } catch (Exception e) { // bugzilla 2154 LogEvent.logError("SampleHumanDAOImpl", "deleteData()", e.toString()); throw new LIMSRuntimeException("Error in SampleHuman deleteData()", e); } }
public void getData(SampleHuman sampleHuman) throws LIMSRuntimeException { try { SampleHuman sampHuman = (SampleHuman) HibernateUtil.getSession().get(SampleHuman.class, sampleHuman.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sampHuman != null) { PropertyUtils.copyProperties(sampleHuman, sampHuman); } else { sampleHuman.setId(null); } } catch (Exception e) { // bugzilla 2154 LogEvent.logError("SampleHumanDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleHuman getData()", e); } }
protected ActionForward performAction( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); BaseActionForm dynaForm = (BaseActionForm) form; ActionMessages errors = dynaForm.validate(mapping, request); String accessionNumber = (String) dynaForm.get("accessionNumber"); String birthWeight = (String) dynaForm.get("birthWeight"); Patient patient = new Patient(); Person person = new Person(); Sample sample = new Sample(); SampleHuman sampleHuman = new SampleHuman(); SampleNewborn sampleNewborn = new SampleNewborn(); UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); // populate valueholder from form PropertyUtils.copyProperties(sample, dynaForm); PropertyUtils.copyProperties(person, dynaForm); PropertyUtils.copyProperties(sampleHuman, dynaForm); PropertyUtils.copyProperties(sampleNewborn, dynaForm); String birthDate = dynaForm.getString("birthDateForDisplay"); String birthTime = dynaForm.getString("birthTimeForDisplay"); String format = "MM/dd/yyyy"; if ((birthDate != null) && (birthDate.length() > 0)) { java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format); java.sql.Timestamp dob = new java.sql.Timestamp(f.parse(birthDate).getTime()); if ((birthTime != null) && (birthTime.length() > 0)) { Calendar cal = Calendar.getInstance(); cal.setTime(dob); cal.set(Calendar.HOUR_OF_DAY, Integer.valueOf(birthTime.substring(0, 2)).intValue()); cal.set(Calendar.MINUTE, Integer.valueOf(birthTime.substring(3, 5)).intValue()); dob = new java.sql.Timestamp(cal.getTimeInMillis()); } patient.setBirthDate(dob); } String collectionDate = dynaForm.getString("collectionDateForDisplay"); String collectionTime = dynaForm.getString("collectionTimeForDisplay"); java.sql.Timestamp collDate = null; if ((collectionDate != null) && (collectionDate.length() > 0)) { java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format); collDate = new java.sql.Timestamp(f.parse(collectionDate).getTime()); if ((collectionTime != null) && (collectionTime.length() > 0)) { Calendar cal = Calendar.getInstance(); cal.setTime(collDate); cal.set(Calendar.HOUR_OF_DAY, Integer.valueOf(collectionTime.substring(0, 2)).intValue()); cal.set(Calendar.MINUTE, Integer.valueOf(collectionTime.substring(3, 5)).intValue()); collDate = new java.sql.Timestamp(cal.getTimeInMillis()); } } SampleDAO sampleDAO = new SampleDAOImpl(); PersonDAO personDAO = new PersonDAOImpl(); PatientDAO patientDAO = new PatientDAOImpl(); SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl(); SampleNewbornDAO sampleNewbornDAO = new SampleNewbornDAOImpl(); try { sample.setSysUserId(sysUserId); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); sample.setStatus(SystemConfiguration.getInstance().getSampleStatusEntry1Complete()); sample.setCollectionDate(collDate); sampleDAO.updateData(sample); person.setSysUserId(sysUserId); patient.setSysUserId(sysUserId); personDAO.insertData(person); patient.setPerson(person); patientDAO.insertData(patient); sampleHuman.setSysUserId(sysUserId); sampleHuman.setSampleId(sample.getId()); sampleHuman.setPatientId(patient.getId()); sampleHumanDAO.insertData(sampleHuman); sampleNewborn.setSysUserId(sysUserId); sampleNewborn.setId(sampleHuman.getId()); sampleNewborn.setWeight(birthWeight); sampleNewbornDAO.insertData(sampleNewborn); } catch (LIMSRuntimeException lre) { LogEvent.logError("NewbornSampleOneUpdateAction", "performAction()", lre.toString()); request.setAttribute(IActionConstants.REQUEST_FAILED, true); errors = new ActionMessages(); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { error = new ActionError("errors.OptimisticLockException", null, null); } else { error = new ActionError("errors.UpdateException", null, null); } errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); request.setAttribute(ALLOW_EDITS_KEY, "false"); forward = FWD_FAIL; } if (forward.equals(FWD_FAIL)) return mapping.findForward(forward); return mapping.findForward(FWD_SUCCESS); }
protected ActionForward performAction( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, TRUE); BaseActionForm dynaForm = (BaseActionForm) form; ActionMessages errors = dynaForm.validate(mapping, request); UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); String birthDateForDisplay = dynaForm.getString("birthDateForDisplay"); String birthTimeForDisplay = dynaForm.getString("birthTimeForDisplay"); String format = "MM/dd/yyyy"; java.sql.Timestamp dob = null; if ((birthDateForDisplay != null) && (birthDateForDisplay.length() > 0)) { java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format); dob = new java.sql.Timestamp(f.parse(birthDateForDisplay).getTime()); if ((birthTimeForDisplay != null) && (birthTimeForDisplay.length() > 0)) { Calendar cal = Calendar.getInstance(); cal.setTime(dob); cal.set( Calendar.HOUR_OF_DAY, Integer.valueOf(birthTimeForDisplay.substring(0, 2)).intValue()); cal.set(Calendar.MINUTE, Integer.valueOf(birthTimeForDisplay.substring(3, 5)).intValue()); dob = new java.sql.Timestamp(cal.getTimeInMillis()); } } String dateFirstFeedingForDisplay = dynaForm.getString("dateFirstFeedingForDisplay"); String timeFirstFeedingForDisplay = dynaForm.getString("timeFirstFeedingForDisplay"); java.sql.Timestamp dateFirstFeeding = null; if ((dateFirstFeedingForDisplay != null) && (dateFirstFeedingForDisplay.length() > 0)) { java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format); dateFirstFeeding = new java.sql.Timestamp(f.parse(dateFirstFeedingForDisplay).getTime()); if ((timeFirstFeedingForDisplay != null) && (timeFirstFeedingForDisplay.length() > 0)) { Calendar cal = Calendar.getInstance(); cal.setTime(dob); cal.set( Calendar.HOUR_OF_DAY, Integer.valueOf(timeFirstFeedingForDisplay.substring(0, 2)).intValue()); cal.set( Calendar.MINUTE, Integer.valueOf(timeFirstFeedingForDisplay.substring(3, 5)).intValue()); dateFirstFeeding = new java.sql.Timestamp(cal.getTimeInMillis()); } } String collectionDateForDisplay = dynaForm.getString("collectionDateForDisplay"); String collectionTimeForDisplay = dynaForm.getString("collectionTimeForDisplay"); java.sql.Timestamp collDate = null; if ((collectionDateForDisplay != null) && (collectionDateForDisplay.length() > 0)) { java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format); collDate = new java.sql.Timestamp(f.parse(collectionDateForDisplay).getTime()); if ((collectionTimeForDisplay != null) && (collectionTimeForDisplay.length() > 0)) { Calendar cal = Calendar.getInstance(); cal.setTime(collDate); cal.set( Calendar.HOUR_OF_DAY, Integer.valueOf(collectionTimeForDisplay.substring(0, 2)).intValue()); cal.set( Calendar.MINUTE, Integer.valueOf(collectionTimeForDisplay.substring(3, 5)).intValue()); collDate = new java.sql.Timestamp(cal.getTimeInMillis()); } } String dateTransfutionForDisplay = (String) dynaForm.getString("dateTransfutionForDisplay"); java.sql.Timestamp dateTransfution = null; if ((dateTransfutionForDisplay != null) && (dateTransfutionForDisplay.length() > 0)) { java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format); dateTransfution = new java.sql.Timestamp(f.parse(dateTransfutionForDisplay).getTime()); } String motherBirthDateForDisplay = (String) dynaForm.get("motherBirthDateForDisplay"); java.sql.Timestamp motherBirthDate = null; if ((motherBirthDateForDisplay != null) && (motherBirthDateForDisplay.length() > 0)) { java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format); motherBirthDate = new java.sql.Timestamp(f.parse(motherBirthDateForDisplay).getTime()); } org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); String accessionNumber = (String) dynaForm.get("accessionNumber"); try { // Sample Sample sample = new Sample(); SampleDAO sampleDAO = new SampleDAOImpl(); sample.setSysUserId(sysUserId); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); sample.setBarCode((String) dynaForm.get("barcode")); sample.setStatus(SystemConfiguration.getInstance().getSampleStatusEntry2Complete()); sample.setCollectionDate(collDate); sampleDAO.updateData(sample); // SampleHuman SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl(); SampleHuman sampleHuman = new SampleHuman(); sampleHuman.setSampleId(sample.getId()); sampleHumanDAO.getDataBySample(sampleHuman); // Patient - child Patient childPatient = new Patient(); PatientDAO patientDAO = new PatientDAOImpl(); Person childPerson = new Person(); childPatient.setId(sampleHuman.getPatientId()); patientDAO.getData(childPatient); // Person - child PersonDAO personDAO = new PersonDAOImpl(); childPerson = childPatient.getPerson(); personDAO.getData(childPerson); childPerson.setSysUserId(sysUserId); childPerson.setLastName((String) dynaForm.get("lastName")); childPerson.setFirstName((String) dynaForm.get("firstName")); personDAO.updateData(childPerson); childPatient.setSysUserId(sysUserId); childPatient.setBirthDate(dob); childPatient.setGender((String) dynaForm.get("gender")); patientDAO.updateData(childPatient); // PatientRelation PatientRelation patientRelation = new PatientRelation(); PatientRelationDAO patientRelationDAO = new PatientRelationDAOImpl(); patientRelation.setPatientIdSource(childPatient.getId()); patientRelation = patientRelationDAO.getPatientRelationByChildId(patientRelation); Person motherPerson = new Person(); Patient motherPatient = new Patient(); if (!StringUtil.isNullorNill(patientRelation.getId())) { motherPatient.setId(patientRelation.getPatientId()); patientDAO.getData(motherPatient); motherPerson = motherPatient.getPerson(); personDAO.getData(motherPerson); } motherPerson.setLastName((String) dynaForm.get("motherLastName")); motherPerson.setFirstName((String) dynaForm.get("motherFirstName")); String motherHomePhone = (String) dynaForm.get("motherPhoneNumber"); if ((motherHomePhone != null) && (motherHomePhone.length() > 0)) motherHomePhone = StringUtil.formatPhone(motherHomePhone, null); motherPerson.setHomePhone(motherHomePhone); motherPerson.setStreetAddress((String) dynaForm.get("motherStreetAddress")); motherPerson.setCity((String) dynaForm.get("city")); motherPerson.setState((String) dynaForm.get("state")); motherPerson.setZipCode((String) dynaForm.get("zipCode")); motherPerson.setSysUserId(sysUserId); if (!StringUtil.isNullorNill(motherPerson.getId())) personDAO.updateData(motherPerson); else personDAO.insertData(motherPerson); motherPatient.setBirthDate(motherBirthDate); motherPatient.setPerson(motherPerson); motherPatient.setSysUserId(sysUserId); if (!StringUtil.isNullorNill(motherPatient.getId())) patientDAO.updateData(motherPatient); else patientDAO.insertData(motherPatient); patientRelation.setSysUserId(sysUserId); patientRelation.setPatientId(motherPatient.getId()); String motherRelation = SystemConfiguration.getInstance().getNewbornPatientRelation(); patientRelation.setRelation(motherRelation); if (!StringUtil.isNullorNill(patientRelation.getId())) patientRelationDAO.updateData(patientRelation); else patientRelationDAO.insertData(patientRelation); // SampleNewborn SampleNewborn sampleNewborn = new SampleNewborn(); SampleNewbornDAO sampleNewbornDAO = new SampleNewbornDAOImpl(); sampleNewborn.setId(sampleHuman.getId()); sampleNewbornDAO.getData(sampleNewborn); sampleNewborn.setSysUserId(sysUserId); sampleNewborn.setMedicalRecordNumber((String) dynaForm.get("medicalRecordNumber")); sampleNewborn.setYnumber((String) dynaForm.get("ynumber")); sampleNewborn.setYellowCard((String) dynaForm.get("yellowCard")); sampleNewborn.setWeight((String) dynaForm.get("birthWeight")); sampleNewborn.setMultiBirth((String) dynaForm.get("multipleBirth")); sampleNewborn.setBirthOrder((String) dynaForm.get("birthOrder")); sampleNewborn.setGestationalWeek((Double) dynaForm.get("gestationalWeek")); sampleNewborn.setDateFirstFeeding(dateFirstFeeding); sampleNewborn.setBreast((String) dynaForm.get("breast")); sampleNewborn.setTpn((String) dynaForm.get("tpn")); sampleNewborn.setFormula((String) dynaForm.get("formula")); sampleNewborn.setMilk((String) dynaForm.get("milk")); sampleNewborn.setSoy((String) dynaForm.get("soy")); sampleNewborn.setJaundice((String) dynaForm.get("jaundice")); sampleNewborn.setAntibiotic((String) dynaForm.get("antibiotic")); sampleNewborn.setTransfused((String) dynaForm.get("transfused")); sampleNewborn.setNicu((String) dynaForm.get("nicuPatient")); sampleNewborn.setBirthDefect((String) dynaForm.get("birthDefect")); sampleNewborn.setPregnancyComplication((String) dynaForm.get("pregnancyComplication")); sampleNewborn.setDeceasedSibling((String) dynaForm.get("deceasedSibling")); sampleNewborn.setCauseOfDeath((String) dynaForm.get("causeOfDeath")); sampleNewborn.setFamilyHistory((String) dynaForm.get("familyHistory")); sampleNewborn.setOther((String) dynaForm.get("other")); sampleNewborn.setDateTransfution(dateTransfution); if (!StringUtil.isNullorNill(sampleNewborn.getId())) sampleNewbornDAO.updateData(sampleNewborn); else { sampleNewborn.setId(sampleHuman.getId()); sampleNewbornDAO.insertData(sampleNewborn); } // Provider Provider provider = new Provider(); Person providerPerson = new Person(); ProviderDAO providerDAO = new ProviderDAOImpl(); if (!StringUtil.isNullorNill(sampleHuman.getProviderId())) { provider.setId(sampleHuman.getProviderId()); providerDAO.getData(provider); } if (!StringUtil.isNullorNill(sampleHuman.getProviderId())) { provider.setId(sampleHuman.getProviderId()); providerDAO.getData(provider); providerPerson = (Person) provider.getPerson(); } // SampleOrganization Organization o = new Organization(); OrganizationDAO organizationDAO = new OrganizationDAOImpl(); o.setOrganizationLocalAbbreviation((String) dynaForm.get("submitterNumber")); o = organizationDAO.getOrganizationByLocalAbbreviation(o, true); SampleOrganization sampleOrganization = new SampleOrganization(); SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl(); sampleOrganizationDAO.getDataBySample(sampleOrganization); sampleOrganization.setSample(sample); sampleOrganization.setOrganization(o); sampleOrganization.setSysUserId(sysUserId); if (!StringUtil.isNullorNill(sampleOrganization.getId())) sampleOrganizationDAO.updateData(sampleOrganization); else sampleOrganizationDAO.insertData(sampleOrganization); // Person - provider providerPerson.setSysUserId(sysUserId); providerPerson.setFirstName((String) dynaForm.get("physicianFirstName")); providerPerson.setLastName((String) dynaForm.get("physicianLastName")); String providerHomePhone = (String) dynaForm.get("physicianPhoneNumber"); if ((providerHomePhone != null) && (providerHomePhone.length() > 0)) providerHomePhone = StringUtil.formatPhone(providerHomePhone, null); providerPerson.setHomePhone(providerHomePhone); if (!StringUtil.isNullorNill(providerPerson.getId())) personDAO.updateData(providerPerson); else personDAO.insertData(providerPerson); provider.setPerson(providerPerson); provider.setExternalId(BLANK); provider.setSysUserId(sysUserId); if (!StringUtil.isNullorNill(provider.getId())) providerDAO.updateData(provider); else providerDAO.insertData(provider); sampleHuman.setProviderId(provider.getId()); sampleHuman.setSysUserId(sysUserId); sampleHumanDAO.updateData(sampleHuman); tx.commit(); } catch (LIMSRuntimeException lre) { LogEvent.logError("NewbornSampleFullUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { error = new ActionError("errors.OptimisticLockException", null, null); } else { error = new ActionError("errors.UpdateException", null, null); } errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); request.setAttribute(ALLOW_EDITS_KEY, "false"); forward = FWD_FAIL; } finally { HibernateUtil.closeSession(); } if (forward.equals(FWD_FAIL)) return mapping.findForward(forward); // Trigger QA if birthWeight < 200 grams int birthWeight = Integer.parseInt((String) dynaForm.get("birthWeight")); if ((birthWeight > 0) && (birthWeight < 200)) { forward = FWD_SUCCESS_QA_EVENTS_ENTRY; return getForward(mapping.findForward(forward), accessionNumber); } return mapping.findForward(FWD_SUCCESS); }