List of usage examples for org.apache.commons.beanutils PropertyUtils copyProperties
public static void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfo
classes).
For more details see PropertyUtilsBean
.
From source file:us.mn.state.health.lims.renametestsection.daoimpl.RenameTestSectionDAOImpl.java
public void getData(RenameTestSection testSection) throws LIMSRuntimeException { try {/* ww w . j a va 2 s . co m*/ RenameTestSection uom = (RenameTestSection) HibernateUtil.getSession().get(RenameTestSection.class, testSection.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (uom != null) { PropertyUtils.copyProperties(testSection, uom); } else { testSection.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("TestSectionDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in TestSection getData()", e); } }
From source file:us.mn.state.health.lims.reports.action.AuditTrailReportBySampleProcessAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; BaseActionForm dynaForm = (BaseActionForm) form; ActionMessages errors = null;//from w w w . java 2 s . c o m request.setAttribute(ALLOW_EDITS_KEY, "false"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); String accessionNumber = (String) dynaForm.getString("accessionNumber"); SampleXmlHelper sampleXmlHelper = new SampleXmlHelper(); if (!StringUtil.isNullorNill(accessionNumber)) { Sample sample = new Sample(); SampleDAO sampleDAO = new SampleDAOImpl(); sample.setAccessionNumber(accessionNumber); List testTestAnalytes = new ArrayList(); try { sampleDAO.getSampleByAccessionNumber(sample); if (!StringUtil.isNullorNill(sample.getStatus()) && sample.getStatus() .equals(SystemConfiguration.getInstance().getSampleStatusLabelPrinted())) { dynaForm.set("accessionNumber", accessionNumber); request.setAttribute(ALLOW_EDITS_KEY, "false"); return mapping.findForward(FWD_FAIL); } } catch (LIMSRuntimeException lre) { LogEvent.logError("AuditTrailReportBySampleProcessAction", "performAction()", lre.toString()); errors = new ActionMessages(); ActionError error = null; error = new ActionError("errors.GetException", null, null); errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); request.setAttribute(ALLOW_EDITS_KEY, "false"); return mapping.findForward(FWD_FAIL); } String domain = sample.getDomain(); String humanDomain = SystemConfiguration.getInstance().getHumanDomain(); String animalDomain = SystemConfiguration.getInstance().getAnimalDomain(); if (domain != null && domain.equals(humanDomain)) { // go to human view Patient patient = new Patient(); Person patientPerson = new Person(); Provider provider = new Provider(); Person providerPerson = new Person(); SampleHuman sampleHuman = new SampleHuman(); SampleOrganization sampleOrganization = new SampleOrganization(); Organization organization = new Organization(); List sampleProjects = new ArrayList(); Project project = new Project(); Project project2 = new Project(); SampleItem sampleItem = new SampleItem(); try { PatientDAO patientDAO = new PatientDAOImpl(); ProviderDAO providerDAO = new ProviderDAOImpl(); SampleItemDAO sampleItemDAO = new SampleItemDAOImpl(); SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl(); SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl(); AuditTrailDAO auditTrailDAO = new AuditTrailDAOImpl(); SystemUserDAO systemUserDAO = new SystemUserDAOImpl(); if (!StringUtil.isNullorNill(sample.getId())) { sampleHuman.setSampleId(sample.getId()); sampleHumanDAO.getDataBySample(sampleHuman); sampleOrganization.setSampleId(sample.getId()); sampleOrganizationDAO.getDataBySample(sampleOrganization); sampleItem.setSample(sample); sampleItemDAO.getDataBySample(sampleItem); if (sampleHuman != null) { if (sampleHuman.getPatientId() != null) { patient.setId(sampleHuman.getPatientId()); patientDAO.getData(patient); patientPerson = patient.getPerson(); provider.setId(sampleHuman.getProviderId()); providerDAO.getData(provider); providerPerson = provider.getPerson(); } } } organization = (Organization) sampleOrganization.getOrganization(); sampleProjects = sample.getSampleProjects(); if (sampleProjects != null && sampleProjects.size() > 0) { SampleProject sampleProject = (SampleProject) sampleProjects.get(0); project = sampleProject.getProject(); if (sampleProjects.size() > 1) { SampleProject sampleProject2 = (SampleProject) sampleProjects.get(1); project2 = sampleProject2.getProject(); } } String tableName = "SAMPLE"; ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl(); ReferenceTables referenceTables = new ReferenceTables(); referenceTables.setTableName(tableName); ReferenceTables rt = referenceTablesDAO.getReferenceTableByName(referenceTables); PropertyUtils.copyProperties(sampleXmlHelper, sample); //String data = auditTrailDAO.retrieveBlobData(sample.getId()); //String data = auditTrailDAO.retrieveBlobData("9446"); History history = new History(); history.setReferenceId(sample.getId()); history.setReferenceTable(rt.getId()); List historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history); List sampleHistoryRecords = populateHistoryList(request, historyRecords, "sample", "sampleHistoryMapping.xsl"); sampleXmlHelper.setHistoryRecords((ArrayList) sampleHistoryRecords); tableName = "SAMPLE_ITEM"; referenceTables = new ReferenceTables(); referenceTables.setTableName(tableName); rt = referenceTablesDAO.getReferenceTableByName(referenceTables); history = new History(); history.setReferenceId(sampleItem.getId()); history.setReferenceTable(rt.getId()); historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history); List sampleItemHistoryRecords = populateHistoryList(request, historyRecords, "sampleItem", "sampleItemHistoryMapping.xsl"); sampleXmlHelper.addHistoryRecords((ArrayList) sampleItemHistoryRecords); tableName = "PATIENT"; referenceTables = new ReferenceTables(); referenceTables.setTableName(tableName); rt = referenceTablesDAO.getReferenceTableByName(referenceTables); history = new History(); history.setReferenceId(patient.getId()); history.setReferenceTable(rt.getId()); historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history); List patientHistoryRecords = populateHistoryList(request, historyRecords, "patient", "patientHistoryMapping.xsl"); sampleXmlHelper.addHistoryRecords((ArrayList) patientHistoryRecords); tableName = "PERSON"; referenceTables = new ReferenceTables(); referenceTables.setTableName(tableName); rt = referenceTablesDAO.getReferenceTableByName(referenceTables); history = new History(); history.setReferenceId(patientPerson.getId()); history.setReferenceTable(rt.getId()); historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history); //List patientPersonHistoryRecords = populateHistoryList(request, historyRecords, "person", "personHistoryMapping.xsl"); //sampleXmlHelper.addHistoryRecords((ArrayList)patientPersonHistoryRecords); tableName = "PERSON"; referenceTables = new ReferenceTables(); referenceTables.setTableName(tableName); rt = referenceTablesDAO.getReferenceTableByName(referenceTables); history = new History(); history.setReferenceId(providerPerson.getId()); history.setReferenceTable(rt.getId()); historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history); //List providerPersonHistoryRecords = populateHistoryList(request, historyRecords, "person", "personHistoryMapping.xsl"); //sampleXmlHelper.addHistoryRecords((ArrayList)providerPersonHistoryRecords); tableName = "SAMPLE_PROJECTS"; referenceTables = new ReferenceTables(); referenceTables.setTableName(tableName); rt = referenceTablesDAO.getReferenceTableByName(referenceTables); history = new History(); history.setReferenceId(providerPerson.getId()); history.setReferenceTable(rt.getId()); historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history); List sampleProjectHistoryRecords = populateHistoryList(request, historyRecords, "sampleProject", "sampleProjectHistoryMapping.xsl"); sampleXmlHelper.addHistoryRecords((ArrayList) sampleProjectHistoryRecords); // initialize the form dynaForm.initialize(mapping); tableName = "SAMPLE_ORGANIZATION"; referenceTables = new ReferenceTables(); referenceTables.setTableName(tableName); rt = referenceTablesDAO.getReferenceTableByName(referenceTables); history = new History(); history.setReferenceId(sampleOrganization.getId()); history.setReferenceTable(rt.getId()); historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history); List sampleOrganizationHistoryRecords = populateHistoryList(request, historyRecords, "sampleOrganization", "sampleOrganizationHistoryMapping.xsl"); sampleXmlHelper.addHistoryRecords((ArrayList) sampleOrganizationHistoryRecords); List historyRecordsForSorting = sampleXmlHelper.getHistoryRecords(); Collections.sort(historyRecordsForSorting, HistoryComparator.NAME_COMPARATOR); String savedUserName = ""; List dateSortList = new ArrayList(); List finalList = new ArrayList(); //now within name sort by date desc for (int i = 0; i < historyRecordsForSorting.size(); i++) { //break down into chunks by name HistoryXmlHelper hist = (HistoryXmlHelper) historyRecordsForSorting.get(i); if (i > 0 && !hist.getUserName().equals(savedUserName)) { //now sort chunk so far Collections.sort(dateSortList, HistoryComparator.DATE_COMPARATOR); finalList.addAll(dateSortList); dateSortList.clear(); } dateSortList.add(hist); savedUserName = hist.getUserName(); } if (dateSortList != null && dateSortList.size() > 0) { Collections.sort(dateSortList, HistoryComparator.DATE_COMPARATOR); finalList.addAll(dateSortList); dateSortList.clear(); } sampleXmlHelper.setHistoryRecords((ArrayList) finalList); // initialize the form dynaForm.initialize(mapping); } catch (LIMSRuntimeException lre) { // if error then forward to fail and don't update to blank // page // = false //bugzilla 2154 LogEvent.logError("ResultsEntryViewAction", "performAction()", lre.toString()); errors = new ActionMessages(); ActionError error = null; error = new ActionError("errors.GetException", null, null); errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); request.setAttribute(ALLOW_EDITS_KEY, "false"); return mapping.findForward(FWD_FAIL); } // populate form from valueholder //PropertyUtils.setProperty(dynaForm, "sampleLastupdated", sample //.getLastupdated()); PropertyUtils.setProperty(dynaForm, "patientFirstName", patientPerson.getFirstName()); PropertyUtils.setProperty(dynaForm, "patientLastName", patientPerson.getLastName()); PropertyUtils.setProperty(dynaForm, "patientId", patient.getExternalId()); PropertyUtils.setProperty(dynaForm, "gender", patient.getGender()); PropertyUtils.setProperty(dynaForm, "chartNumber", patient.getChartNumber()); PropertyUtils.setProperty(dynaForm, "birthDateForDisplay", (String) patient.getBirthDateForDisplay()); TypeOfSample typeOfSample = sampleItem.getTypeOfSample(); SourceOfSample sourceOfSample = sampleItem.getSourceOfSample(); if (typeOfSample == null) { PropertyUtils.setProperty(dynaForm, "typeOfSample", new TypeOfSample()); } else { PropertyUtils.setProperty(dynaForm, "typeOfSample", typeOfSample); } if (sourceOfSample == null) { PropertyUtils.setProperty(dynaForm, "sourceOfSample", new SourceOfSample()); } else { PropertyUtils.setProperty(dynaForm, "sourceOfSample", sourceOfSample); } PropertyUtils.setProperty(dynaForm, "sourceOther", sampleItem.getSourceOther()); PropertyUtils.setProperty(dynaForm, "receivedDateForDisplay", (String) sample.getReceivedDateForDisplay()); PropertyUtils.setProperty(dynaForm, "collectionDateForDisplay", (String) sample.getCollectionDateForDisplay()); PropertyUtils.setProperty(dynaForm, "collectionTimeForDisplay", (String) sample.getCollectionTimeForDisplay()); PropertyUtils.setProperty(dynaForm, "referredCultureFlag", (String) sample.getReferredCultureFlag()); PropertyUtils.setProperty(dynaForm, "stickerReceivedFlag", (String) sample.getStickerReceivedFlag()); if (organization == null) { PropertyUtils.setProperty(dynaForm, "organization", new Organization()); } else { PropertyUtils.setProperty(dynaForm, "organization", organization); } if (project == null) { PropertyUtils.setProperty(dynaForm, "project", new Project()); } else { PropertyUtils.setProperty(dynaForm, "project", project); } if (project2 == null) { PropertyUtils.setProperty(dynaForm, "project2", new Project()); } else { PropertyUtils.setProperty(dynaForm, "project2", project2); } // reload accession number PropertyUtils.setProperty(dynaForm, "accessionNumber", accessionNumber); PropertyUtils.setProperty(dynaForm, "domain", domain); PropertyUtils.setProperty(dynaForm, "sampleXmlHelper", sampleXmlHelper); forward = FWD_SUCCESS_HUMAN; } else if (domain != null && domain.equals(animalDomain)) { // go to animal view // System.out.println("Going to animal view"); forward = FWD_SUCCESS_ANIMAL; } else { forward = FWD_SUCCESS; } } return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.reports.send.sample.action.SampleXMLBySampleProcessAction.java
License:asdf
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; BaseActionForm dynaForm = (BaseActionForm) form; ActionMessages errors = null;/* w w w. jav a 2 s .com*/ request.setAttribute(ALLOW_EDITS_KEY, "false"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); // CHANGED String xmlString = null; // get transmission resources properties ResourceLocator rl = ResourceLocator.getInstance(); // Now load a java.util.Properties object with the // properties transmissionMap = new Properties(); try { propertyStream = rl.getNamedResourceAsInputStream(ResourceLocator.XMIT_PROPERTIES); transmissionMap.load(propertyStream); } catch (IOException e) { //bugzilla 2154 LogEvent.logError("SampleXMLBySampleProcessAction", "performAction()", e.toString()); throw new LIMSRuntimeException("Unable to load transmission resource mappings.", e); } finally { if (null != propertyStream) { try { propertyStream.close(); propertyStream = null; } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SampleXMLBySampleProcessAction", "performAction()", e.toString()); } } } String accessionNumber = (String) dynaForm.get("accessionNumber"); // PROCESS String humanDomain = SystemConfiguration.getInstance().getHumanDomain(); String animalDomain = SystemConfiguration.getInstance().getAnimalDomain(); try { PatientDAO patientDAO = new PatientDAOImpl(); PersonDAO personDAO = new PersonDAOImpl(); ProviderDAO providerDAO = new ProviderDAOImpl(); SampleDAO sampleDAO = new SampleDAOImpl(); SampleItemDAO sampleItemDAO = new SampleItemDAOImpl(); SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl(); SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); ResultDAO resultDAO = new ResultDAOImpl(); TypeOfSampleDAO typeOfSampleDAO = new TypeOfSampleDAOImpl(); SourceOfSampleDAO sourceOfSampleDAO = new SourceOfSampleDAOImpl(); OrganizationDAO organizationDAO = new OrganizationDAOImpl(); TestTrailerDAO testTrailerDAO = new TestTrailerDAOImpl(); TypeOfTestResultDAO typeOfTestResultDAO = new TypeOfTestResultDAOImpl(); // for overall message portion of message MessageXmit message = new MessageXmit(); // for UHL portion of message UHLXmit uhl = new UHLXmit(); Organization organization = new Organization(); TestingFacilityXmit uhlFacility = new TestingFacilityXmit(); //bugzilla 2069 organization.setOrganizationLocalAbbreviation( SystemConfiguration.getInstance().getMdhOrganizationIdForXMLTransmission()); organization = organizationDAO.getOrganizationByLocalAbbreviation(organization, true); StringBuffer orgName = new StringBuffer(); orgName.append(organization.getOrganizationName()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(organization.getStreetAddress()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(organization.getCity()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(organization.getState()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(organization.getZipCode()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(SystemConfiguration.getInstance().getMdhPhoneNumberForXMLTransmission()); uhl.setId(SystemConfiguration.getInstance().getMdhUhlIdForXMLTransmission()); uhlFacility.setOrganizationName(orgName.toString()); uhlFacility.setUniversalId(SystemConfiguration.getInstance().getMdhUniversalIdForXMLTransmission()); uhlFacility.setUniversalIdType( SystemConfiguration.getInstance().getMdhUniversalIdTypeForXMLTransmission()); uhl.setFacility(uhlFacility); uhl.setApplicationName(SystemConfiguration.getInstance().getDefaultApplicationName()); uhl.setMessageTime((new Timestamp(System.currentTimeMillis())).toString()); uhl.setProcessingId(SystemConfiguration.getInstance().getDefaultProcessingIdForXMLTransmission()); uhl.setTransportMethod(SystemConfiguration.getInstance().getDefaultTransportMethodForXMLTransmission()); PatientXmit patient = new PatientXmit(); Person person = new Person(); ProviderXmit provider = new ProviderXmit(); FacilityXmit facility = new FacilityXmit(); Person providerPerson = new Person(); SampleHuman sampleHuman = new SampleHuman(); SampleOrganization sampleOrganization = new SampleOrganization(); List analyses = null; SourceOfSample sourceOfSample = new SourceOfSample(); TypeOfSample typeOfSample = new TypeOfSample(); Sample sample = new Sample(); SampleItem sampleItem = new SampleItem(); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); sampleHuman.setSampleId(sample.getId()); sampleHumanDAO.getDataBySample(sampleHuman); sampleOrganization.setSampleId(sample.getId()); sampleOrganizationDAO.getDataBySample(sampleOrganization); //bugzilla 1773 need to store sample not sampleId for use in sorting sampleItem.setSample(sample); sampleItemDAO.getDataBySample(sampleItem); patient.setId(sampleHuman.getPatientId()); patientDAO.getData(patient); person = patient.getPerson(); personDAO.getData(person); provider.setId(sampleHuman.getProviderId()); providerDAO.getData(provider); providerPerson = provider.getPerson(); personDAO.getData(providerPerson); //bugzilla 2227 analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem); for (int i = 0; i < analyses.size(); i++) { Analysis analysis = (Analysis) analyses.get(i); sampleItemDAO.getData(sampleItem); sourceOfSample.setId(sampleItem.getSourceOfSampleId()); if (!StringUtil.isNullorNill(sourceOfSample.getId())) { sourceOfSampleDAO.getData(sourceOfSample); } typeOfSample.setId(sampleItem.getTypeOfSampleId()); if (!StringUtil.isNullorNill(typeOfSample.getId())) { typeOfSampleDAO.getData(typeOfSample); } // System.out.println("This is sampleItem " + sampleItem); if (sampleItem != null) { //bugzilla 1773 need to store sample not sampleId for use in sorting String sampleId = sampleItem.getSample().getId(); SampleXmit sampleXmit = new SampleXmit(); sampleXmit.setId(sampleId); sampleDAO.getData(sampleXmit); // marshall to XML Mapping castorMapping = new Mapping(); String castorMappingName = transmissionMap.getProperty("SampleToXmlMapping"); InputSource source = getSource(castorMappingName); // bugzilla #1346 add ability to hover over accession // number and // view patient/person information (first and last name // and external id) String domain = sampleXmit.getDomain(); if (domain != null && domain.equals(humanDomain)) { // go to human view // bugzilla #1346 add ability to hover over // accession number and // view patient/person information (first and last // name and external id) if (!StringUtil.isNullorNill(sampleXmit.getId())) { sampleHuman.setSampleId(sampleXmit.getId()); sampleHumanDAO.getDataBySample(sampleHuman); sampleOrganization.setSampleId(sampleXmit.getId()); sampleOrganizationDAO.getDataBySample(sampleOrganization); //bugzilla 1827 set id = external id AFTER getting data patient.setId(sampleHuman.getPatientId()); patientDAO.getData(patient); // per Nancy 01/12/2007 // this should be external id (if none just patient // id because we can't send null if (!StringUtil.isNullorNill(patient.getExternalId())) { patient.setId(patient.getExternalId()); } else { patient.setId(sampleHuman.getPatientId()); } person.setId(patient.getPerson().getId()); personDAO.getData(person); // do we need to set id on patient to be externalId? patient.setLastName(person.getLastName()); patient.setFirstName(person.getFirstName()); patient.setStreetAddress(person.getState()); patient.setCity(person.getCity()); patient.setState(person.getState()); patient.setZipCode(person.getZipCode()); patient.setHomePhone(person.getHomePhone()); provider.setId(sampleHuman.getProviderId()); providerDAO.getData(provider); providerPerson = provider.getPerson(); personDAO.getData(providerPerson); Organization o = sampleOrganization.getOrganization(); if (o != null) { PropertyUtils.copyProperties(facility, provider); // per Nancy 01/12/2007 // have added null check if (!StringUtil.isNullorNill(o.getCliaNum())) { facility.setId(o.getCliaNum()); } facility.setOrganizationName(o.getOrganizationName()); facility.setDepartment(o.getOrganizationName()); facility.setStreetAddress(o.getStreetAddress()); facility.setCity(o.getCity()); facility.setState(o.getState()); facility.setZipCode(o.getZipCode()); } provider.setWorkPhone(providerPerson.getWorkPhone()); provider.setLastName(providerPerson.getLastName()); provider.setFirstName(providerPerson.getFirstName()); if (StringUtil.isNullorNill(sampleXmit.getRevision())) { sampleXmit.setRevision("0"); } sampleXmit.setExternalId(patient.getExternalId()); if (StringUtil.isNullorNill(sampleXmit.getStatus())) { sampleXmit.setStatus("THIS IS SAMPLE STATUS - IF BLANK SHOULD WE SEND DEFAULT"); } sampleXmit.setPatient(patient); sampleXmit.setProvider(provider); sampleXmit.setFacility(facility); // get all tests for this sample //bugzilla 2227 analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem); ArrayList sampleTests = new ArrayList(); // assemble Test Elements for (int j = 0; j < analyses.size(); j++) { TestXmit sampleTest = new TestXmit(); Analysis a = (Analysis) analyses.get(j); Test t = a.getTest(); sampleTest.setMethod(t.getMethodName()); sampleTest.setReleasedDate(a.getReleasedDate()); if (sourceOfSample != null && !StringUtil.isNullorNill(sourceOfSample.getDescription())) { sampleTest.setSourceOfSample(sourceOfSample.getDescription()); } if (typeOfSample != null && !StringUtil.isNullorNill(typeOfSample.getDescription())) { sampleTest.setTypeOfSample(typeOfSample.getDescription()); } CodeElementXmit testName = new CodeElementXmit(); // do we need go to receiver_xref to get // their test name? identifier, codesystem // type, testName.setIdentifier(TestService.getLocalizedTestName(a.getTest())); testName.setCodeSystemType("L"); testName.setText("This is some kind of text"); sampleTest.setName(testName); TestTrailer testTrailer = t.getTestTrailer(); CommentXmit testComment = new CommentXmit(); if (testTrailer != null) { testComment.setComment(testTrailer.getText()); testComment.setCommentSource(""); } sampleTest.setComment(testComment); sampleTest.setStatus("This could be analysis status"); // NOW GET THE RESULTS FOR THIS TEST TestResultDAO testResultDAO = new TestResultDAOImpl(); DictionaryDAO dictDAO = new DictionaryDAOImpl(); // load collection of // TestAnalyte_TestResults for the // test TestAnalyteDAO testAnalyteDAO = new TestAnalyteDAOImpl(); List testAnalytes = testAnalyteDAO.getAllTestAnalytesPerTest(t); ArrayList testResults = new ArrayList(); for (int k = 0; k < testAnalytes.size(); k++) { TestAnalyte testAnalyte = (TestAnalyte) testAnalytes.get(k); Result result = new Result(); resultDAO.getResultByAnalysisAndAnalyte(result, analysis, testAnalyte); ResultXmit resultXmit = new ResultXmit(); if (result != null && !StringUtil.isNullorNill(result.getId())) { // we have at least one result so // add this TestResult testResult = result.getTestResult(); String value = null; if (testResult.getTestResultType() .equals(SystemConfiguration.getInstance().getDictionaryType())) { // get from dictionary Dictionary dictionary = new Dictionary(); dictionary.setId(testResult.getValue()); dictDAO.getData(dictionary); // System.out.println("setting // dictEntry " // + dictionary.getDictEntry()); value = dictionary.getDictEntry(); } else { value = testResult.getValue(); } // now create other objects // within the result ObservationXmit observationXmit = new ObservationXmit(); CodeElementXmit observationIdentifier = new CodeElementXmit(); Analyte analyte = testAnalyte.getAnalyte(); if (!StringUtil.isNullorNill(analyte.getExternalId())) { observationIdentifier.setIdentifier(analyte.getExternalId()); } else { observationIdentifier.setIdentifier(analyte.getId()); } observationIdentifier.setText(analyte.getAnalyteName()); observationIdentifier.setCodeSystemType(SystemConfiguration.getInstance() .getDefaultTransmissionCodeSystemType()); observationXmit.setIdentifier(observationIdentifier); observationXmit.setValue(value); //bugzilla 1866 TypeOfTestResult totr = new TypeOfTestResult(); totr.setTestResultType(testResult.getTestResultType()); totr = typeOfTestResultDAO.getTypeOfTestResultByType(totr); observationXmit.setValueType(totr.getHl7Value()); //end bugzilla 1866 resultXmit.setObservation(observationXmit); //bugzilla 1867 remove empty tags //resultXmit.setReferenceRange("UNKNOWN"); resultXmit.setReferenceRange(null); /*CodeElementXmit unitCodeElement = new CodeElementXmit(); unitCodeElement .setIdentifier("UNKNOWN"); unitCodeElement.setText("UNKNOWN"); unitCodeElement .setCodeSystemType(SystemConfiguration .getInstance() .getDefaultTransmissionCodeSystemType());*/ //resultXmit.setUnit(unitCodeElement); resultXmit.setUnit(null); //end bugzilla 1867 } testResults.add(resultXmit); } // END RESULTS FOR TEST sampleTest.setResults(testResults); sampleTest.setReleasedDate(analysis.getReleasedDate()); // there is a requirement that there is at least // one result for a test if (testResults.size() > 0) { sampleTests.add(sampleTest); } } sampleXmit.setTests(sampleTests); message.setSample(sampleXmit); message.setUhl(uhl); try { // castorMapping.loadMapping(url); castorMapping.loadMapping(source); // Marshaller marshaller = new Marshaller( // new OutputStreamWriter(System.out)); //bugzilla 2393 String fileName = FILENAME_PREFIX + accessionNumber + ".xml"; Marshaller marshaller = new Marshaller(); marshaller.setMapping(castorMapping); Writer writer = new StringWriter(); marshaller.setWriter(writer); marshaller.marshal(message); xmlString = writer.toString(); //bugzilla 2393 allow for download of file response.reset(); response.setHeader("Content-Disposition", "attachment;filename=" + fileName); //response.setContentType("application/xml"); response.setContentType("multipart/xml"); response.setContentLength((int) xmlString.length()); try { OutputStream os = response.getOutputStream(); byte[] xmlBytes = xmlString.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(xmlBytes); InputStream is = (InputStream) bais; int count; byte buf[] = new byte[4096]; while ((count = is.read(buf)) > -1) os.write(buf, 0, count); is.close(); os.close(); } catch (Exception ex) { ex.printStackTrace(); } //end try/catch //no need to display xml - we are saving a file instead xmlString = ""; //xmlString = convertToDisplayableXML(xmlString); } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SampleXMLBySampleProcessAction", "performAction()", e.toString()); } // this writes a default mapping to oc4j's // j2ee/home directory /* * try { MappingTool tool = new MappingTool(); * tool.setForceIntrospection(false); * tool.addClass("us.mn.state.health.lims.patient.valueholder.Patient"); * tool.write(new FileWriter("XMLTestMapping.xml")); } * catch(MappingException ex){ * System.out.println("Error" + * ex.getLocalizedMessage());} catch(IOException * ex){ System.out.println("Error" + * ex.getLocalizedMessage());} */ } } else if (domain != null && domain.equals(animalDomain)) { // go to animal view // System.out.println("Going to animal view"); } else { // go toother view } } } } catch (LIMSRuntimeException lre) { // if error then forward to fail and don't update to blank // page // = false //bugzilla 2154 LogEvent.logError("SampleXMLBySampleProcessAction", "performAction()", lre.toString()); errors = new ActionMessages(); ActionError error = null; error = new ActionError("errors.GetException", null, null); errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); request.setAttribute(ALLOW_EDITS_KEY, "false"); return mapping.findForward(FWD_FAIL); } // END PROCESS // initialize the form dynaForm.initialize(mapping); PropertyUtils.setProperty(dynaForm, "accessionNumber", accessionNumber); // PropertyUtils.setProperty(dynaForm, "xmlString", // "<ajdf>asdfasdf</ajdf>"); PropertyUtils.setProperty(dynaForm, "xmlString", xmlString); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.reports.send.sample.action.SampleXMLByTestProcessAction.java
License:asdf
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; BaseActionForm dynaForm = (BaseActionForm) form; ActionMessages errors = null;//from www . java 2 s . co m request.setAttribute(ALLOW_EDITS_KEY, "false"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); request.setAttribute(IAuthorizationActionConstants.UPDATE_TESTCOMPONENT_TESTRESULT, "true"); // CHANGED // String selectedTestId = (String) request.getParameter("Test"); String xmlString = null; // get transmission resources properties ResourceLocator rl = ResourceLocator.getInstance(); // Now load a java.util.Properties object with the // properties transmissionMap = new Properties(); try { propertyStream = rl.getNamedResourceAsInputStream(ResourceLocator.XMIT_PROPERTIES); transmissionMap.load(propertyStream); } catch (IOException e) { //bugzilla 2154 LogEvent.logError("SampleXMLByTestProcessAction", "performAction()", e.toString()); throw new LIMSRuntimeException("Unable to load transmission resource mappings.", e); } finally { if (null != propertyStream) { try { propertyStream.close(); propertyStream = null; } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SampleXMLByTestProcessAction", "performAction()", e.toString()); } } } List methods = new ArrayList(); MethodDAO methodDAO = new MethodDAOImpl(); methods = methodDAO.getAllMethods(); //Get tests/testsections by user system id //bugzilla 2160 UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl(); List testSections = userTestSectionDAO.getAllUserTestSections(request); //bugzilla 2291 List tests = userTestSectionDAO.getAllUserTests(request, true); // get 3 drop down selections so we can repopulate String selectedTestSectionId = (String) dynaForm.get("selectedTestSectionId"); String selectedMethodId = (String) dynaForm.get("selectedMethodId"); String selectedTestId = (String) dynaForm.get("selectedTestId"); // PROCESS String humanDomain = SystemConfiguration.getInstance().getHumanDomain(); String animalDomain = SystemConfiguration.getInstance().getAnimalDomain(); if (!StringUtil.isNullorNill(selectedTestId)) { Test test = new Test(); test.setId(selectedTestId); TestDAO testDAO = new TestDAOImpl(); testDAO.getData(test); try { List analyses = new ArrayList(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); //bugzilla 2227 analyses = analysisDAO.getAllMaxRevisionAnalysesPerTest(test); SampleDAO sampleDAO = new SampleDAOImpl(); ResultDAO resultDAO = new ResultDAOImpl(); PatientDAO patientDAO = new PatientDAOImpl(); PersonDAO personDAO = new PersonDAOImpl(); ProviderDAO providerDAO = new ProviderDAOImpl(); SampleItemDAO sampleItemDAO = new SampleItemDAOImpl(); TypeOfSampleDAO typeOfSampleDAO = new TypeOfSampleDAOImpl(); SourceOfSampleDAO sourceOfSampleDAO = new SourceOfSampleDAOImpl(); SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl(); SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl(); OrganizationDAO organizationDAO = new OrganizationDAOImpl(); TestTrailerDAO testTrailerDAO = new TestTrailerDAOImpl(); TypeOfTestResultDAO typeOfTestResultDAO = new TypeOfTestResultDAOImpl(); // for overall message portion of message MessageXmit message = new MessageXmit(); // for UHL portion of message UHLXmit uhl = new UHLXmit(); Organization organization = new Organization(); TestingFacilityXmit uhlFacility = new TestingFacilityXmit(); //bugzilla 2069 organization.setOrganizationLocalAbbreviation( SystemConfiguration.getInstance().getMdhOrganizationIdForXMLTransmission()); organization = organizationDAO.getOrganizationByLocalAbbreviation(organization, true); StringBuffer orgName = new StringBuffer(); orgName.append(organization.getOrganizationName()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(organization.getStreetAddress()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(organization.getCity()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(organization.getState()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(organization.getZipCode()); orgName.append(SystemConfiguration.getInstance().getDefaultTransmissionTextSeparator()); orgName.append(SystemConfiguration.getInstance().getMdhPhoneNumberForXMLTransmission()); uhl.setId(SystemConfiguration.getInstance().getMdhUhlIdForXMLTransmission()); uhlFacility.setOrganizationName(orgName.toString()); uhlFacility.setUniversalId(SystemConfiguration.getInstance().getMdhUniversalIdForXMLTransmission()); uhlFacility.setUniversalIdType( SystemConfiguration.getInstance().getMdhUniversalIdTypeForXMLTransmission()); uhl.setFacility(uhlFacility); uhl.setApplicationName(SystemConfiguration.getInstance().getDefaultApplicationName()); uhl.setMessageTime((new Timestamp(System.currentTimeMillis())).toString()); uhl.setProcessingId(SystemConfiguration.getInstance().getDefaultProcessingIdForXMLTransmission()); uhl.setTransportMethod( SystemConfiguration.getInstance().getDefaultTransportMethodForXMLTransmission()); PatientXmit patient = new PatientXmit(); Person person = new Person(); ProviderXmit provider = new ProviderXmit(); FacilityXmit facility = new FacilityXmit(); Person providerPerson = new Person(); SampleHuman sampleHuman = new SampleHuman(); SampleOrganization sampleOrganization = new SampleOrganization(); List analysesBySample = null; SourceOfSample sourceOfSample = new SourceOfSample(); TypeOfSample typeOfSample = new TypeOfSample(); for (int i = 0; i < analyses.size(); i++) { Analysis analysis = (Analysis) analyses.get(i); SampleItem sampleItem = (SampleItem) analysis.getSampleItem(); sampleItemDAO.getData(sampleItem); sourceOfSample.setId(sampleItem.getSourceOfSampleId()); if (!StringUtil.isNullorNill(sourceOfSample.getId())) { sourceOfSampleDAO.getData(sourceOfSample); } typeOfSample.setId(sampleItem.getTypeOfSampleId()); if (!StringUtil.isNullorNill(typeOfSample.getId())) { typeOfSampleDAO.getData(typeOfSample); } // System.out.println("This is sampleItem " + sampleItem); if (sampleItem != null) { //bugzilla 1773 need to store sample not sampleId for use in sorting String sampleId = sampleItem.getSample().getId(); SampleXmit sample = new SampleXmit(); sample.setId(sampleId); sampleDAO.getData(sample); // marshall to XML Mapping castorMapping = new Mapping(); String castorMappingName = transmissionMap.getProperty("SampleToXmlMapping"); InputSource source = getSource(castorMappingName); // bugzilla #1346 add ability to hover over accession // number and // view patient/person information (first and last name // and external id) String domain = sample.getDomain(); if (domain != null && domain.equals(humanDomain)) { // go to human view // bugzilla #1346 add ability to hover over // accession number and // view patient/person information (first and last // name and external id) if (!StringUtil.isNullorNill(sample.getId())) { sampleHuman.setSampleId(sample.getId()); sampleHumanDAO.getDataBySample(sampleHuman); sampleOrganization.setSampleId(sample.getId()); sampleOrganizationDAO.getDataBySample(sampleOrganization); patient.setId(sampleHuman.getPatientId()); patientDAO.getData(patient); person.setId(patient.getPerson().getId()); personDAO.getData(person); //do we need to set id on patient to be externalId? patient.setLastName(person.getLastName()); patient.setFirstName(person.getFirstName()); patient.setStreetAddress(person.getState()); patient.setCity(person.getCity()); patient.setState(person.getState()); patient.setZipCode(person.getZipCode()); patient.setHomePhone(person.getHomePhone()); provider.setId(sampleHuman.getProviderId()); providerDAO.getData(provider); providerPerson = provider.getPerson(); personDAO.getData(providerPerson); Organization o = sampleOrganization.getOrganization(); if (o != null) { PropertyUtils.copyProperties(facility, provider); //per Nancy 01/12/2007 // have added null check if (!StringUtil.isNullorNill(o.getCliaNum())) { facility.setId(o.getCliaNum()); } facility.setOrganizationName(o.getOrganizationName()); facility.setDepartment(o.getOrganizationName()); facility.setStreetAddress(o.getStreetAddress()); facility.setCity(o.getCity()); facility.setState(o.getState()); facility.setZipCode(o.getZipCode()); } provider.setWorkPhone(providerPerson.getWorkPhone()); provider.setLastName(providerPerson.getLastName()); provider.setFirstName(providerPerson.getFirstName()); if (StringUtil.isNullorNill(sample.getRevision())) { sample.setRevision("0"); } sample.setExternalId(patient.getExternalId()); if (StringUtil.isNullorNill(sample.getStatus())) { sample.setStatus("THIS IS SAMPLE STATUS - IF BLANK SHOULD WE SEND DEFAULT"); } sample.setPatient(patient); sample.setProvider(provider); sample.setFacility(facility); // get all tests for this sample //bugzilla 2227 analysesBySample = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem); ArrayList sampleTests = new ArrayList(); // assemble Test Elements for (int j = 0; j < analysesBySample.size(); j++) { TestXmit sampleTest = new TestXmit(); Analysis a = (Analysis) analysesBySample.get(j); Test t = a.getTest(); sampleTest.setMethod(t.getMethodName()); sampleTest.setReleasedDate(a.getReleasedDate()); if (sourceOfSample != null && !StringUtil.isNullorNill(sourceOfSample.getDescription())) { sampleTest.setSourceOfSample(sourceOfSample.getDescription()); } if (typeOfSample != null && !StringUtil.isNullorNill(typeOfSample.getDescription())) { sampleTest.setTypeOfSample(typeOfSample.getDescription()); } CodeElementXmit testName = new CodeElementXmit(); // do we need go to receiver_xref to get // their test name? identifier, codesystem // type, testName.setIdentifier(TestService.getLocalizedTestName(a.getTest())); testName.setCodeSystemType("L"); testName.setText("This is some kind of text"); sampleTest.setName(testName); TestTrailer testTrailer = t.getTestTrailer(); CommentXmit testComment = new CommentXmit(); if (testTrailer != null) { testComment.setComment(testTrailer.getText()); testComment.setCommentSource(""); } sampleTest.setComment(testComment); sampleTest.setStatus("This could be analysis status"); // NOW GET THE RESULTS FOR THIS TEST TestResultDAO testResultDAO = new TestResultDAOImpl(); DictionaryDAO dictDAO = new DictionaryDAOImpl(); // load collection of // TestAnalyte_TestResults for the // test TestAnalyteDAO testAnalyteDAO = new TestAnalyteDAOImpl(); List testAnalytes = testAnalyteDAO.getAllTestAnalytesPerTest(t); ArrayList testResults = new ArrayList(); for (int k = 0; k < testAnalytes.size(); k++) { TestAnalyte testAnalyte = (TestAnalyte) testAnalytes.get(k); Result result = new Result(); ResultXmit resultXmit = new ResultXmit(); resultDAO.getResultByAnalysisAndAnalyte(result, analysis, testAnalyte); if (result != null && !StringUtil.isNullorNill(result.getId())) { // we have at least one result so // add this TestResult testResult = result.getTestResult(); String value = null; if (testResult.getTestResultType().equals( SystemConfiguration.getInstance().getDictionaryType())) { // get from dictionary Dictionary dictionary = new Dictionary(); dictionary.setId(testResult.getValue()); dictDAO.getData(dictionary); // System.out.println("setting // dictEntry " // + dictionary.getDictEntry()); value = dictionary.getDictEntry(); } else { value = testResult.getValue(); } // now create other objects // within the result ObservationXmit observationXmit = new ObservationXmit(); CodeElementXmit observationIdentifier = new CodeElementXmit(); Analyte analyte = testAnalyte.getAnalyte(); if (!StringUtil.isNullorNill(analyte.getExternalId())) { observationIdentifier.setIdentifier(analyte.getExternalId()); } else { observationIdentifier.setIdentifier(analyte.getId()); } observationIdentifier.setText(analyte.getAnalyteName()); observationIdentifier.setCodeSystemType(SystemConfiguration .getInstance().getDefaultTransmissionCodeSystemType()); observationXmit.setIdentifier(observationIdentifier); observationXmit.setValue(value); //bugzilla 1866 TypeOfTestResult totr = new TypeOfTestResult(); totr.setTestResultType(testResult.getTestResultType()); totr = typeOfTestResultDAO.getTypeOfTestResultByType(totr); observationXmit.setValueType(totr.getHl7Value()); //end bugzilla 1866 resultXmit.setObservation(observationXmit); //bugzilla 1867 remove empty tags //resultXmit.setReferenceRange("UNKNOWN"); resultXmit.setReferenceRange(null); /*CodeElementXmit unitCodeElement = new CodeElementXmit(); unitCodeElement .setIdentifier("UNKNOWN"); unitCodeElement.setText("UNKNOWN"); unitCodeElement .setCodeSystemType(SystemConfiguration .getInstance() .getDefaultTransmissionCodeSystemType());*/ //resultXmit.setUnit(unitCodeElement); resultXmit.setUnit(null); //end bugzilla 1867 } testResults.add(resultXmit); } // END RESULTS FOR TEST sampleTest.setResults(testResults); sampleTest.setReleasedDate(analysis.getReleasedDate()); //there is a requirement that there is at least one result for a test if (testResults.size() > 0) { sampleTests.add(sampleTest); } } sample.setTests(sampleTests); message.setSample(sample); message.setUhl(uhl); try { // castorMapping.loadMapping(url); castorMapping.loadMapping(source); // Marshaller marshaller = new Marshaller( // new OutputStreamWriter(System.out)); Marshaller marshaller = new Marshaller(); marshaller.setMapping(castorMapping); Writer writer = new StringWriter(); marshaller.setWriter(writer); marshaller.marshal(message); xmlString = writer.toString(); xmlString = convertToDisplayableXML(xmlString); } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SampleXMLByTestProcessAction", "performAction()", e.toString()); } // this writes a default mapping to oc4j's // j2ee/home directory /* * try { MappingTool tool = new MappingTool(); * tool.setForceIntrospection(false); * tool.addClass("us.mn.state.health.lims.patient.valueholder.Patient"); * tool.write(new * FileWriter("XMLTestMapping.xml")); } * catch(MappingException ex){ * System.out.println("Error" + * ex.getLocalizedMessage());} catch(IOException * ex){ System.out.println("Error" + * ex.getLocalizedMessage());} */ } } else if (domain != null && domain.equals(animalDomain)) { // go to animal view // System.out.println("Going to animal view"); } else { // go toother view } } } } catch (LIMSRuntimeException lre) { // if error then forward to fail and don't update to blank // page // = false //bugzilla 2154 LogEvent.logError("SampleXMLByTestProcessAction", "performAction()", lre.toString()); errors = new ActionMessages(); ActionError error = null; error = new ActionError("errors.GetException", null, null); errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); request.setAttribute(ALLOW_EDITS_KEY, "false"); return mapping.findForward(FWD_FAIL); } } // END PROCESS // initialize the form dynaForm.initialize(mapping); PropertyUtils.setProperty(dynaForm, "testSections", testSections); PropertyUtils.setProperty(dynaForm, "methods", methods); PropertyUtils.setProperty(dynaForm, "tests", tests); PropertyUtils.setProperty(dynaForm, "selectedTestSectionId", selectedTestSectionId); PropertyUtils.setProperty(dynaForm, "selectedMethodId", selectedMethodId); PropertyUtils.setProperty(dynaForm, "selectedTestId", selectedTestId); // PropertyUtils.setProperty(dynaForm, "xmlString", // "<ajdf>asdfasdf</ajdf>"); PropertyUtils.setProperty(dynaForm, "xmlString", xmlString); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.result.action.AmendedResultsEntryUpdateAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); String amendedAnalysisId = null; if (request.getParameter(ANALYSIS_ID) != null) { amendedAnalysisId = (String) request.getParameter(ANALYSIS_ID); }/*from w w w . j av a 2 s .c o m*/ BaseActionForm dynaForm = (BaseActionForm) form; List testTestAnalytes = (List) dynaForm.get("testTestAnalytes"); String accessionNumber = (String) dynaForm.get("accessionNumber"); Timestamp sampleLastupdated = (Timestamp) dynaForm.get("sampleLastupdated"); ActionMessages errors = null; // initialize the form dynaForm.initialize(mapping); // 1926 get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); if (!StringUtil.isNullorNill(amendedAnalysisId)) { ResultDAO resultDAO = new ResultDAOImpl(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); NoteDAO noteDAO = new NoteDAOImpl(); SampleDAO sampleDAO = new SampleDAOImpl(); AnalysisQaEventDAO analysisQaEventDAO = new AnalysisQaEventDAOImpl(); AnalysisQaEventActionDAO analysisQaEventActionDAO = new AnalysisQaEventActionDAOImpl(); try { // get old analysis and copy to new one Analysis analysisToAmend = new Analysis(); analysisToAmend.setId(amendedAnalysisId); analysisDAO.getData(analysisToAmend); Analysis amendedAnalysis = new Analysis(); PropertyUtils.copyProperties(amendedAnalysis, analysisToAmend); amendedAnalysis.setId(null); amendedAnalysis.setLastupdated(null); amendedAnalysis.setSysUserId(sysUserId); String revisionString = analysisToAmend.getRevision(); int revision = 0; if (!StringUtil.isNullorNill(revisionString)) { try { revision = Integer.parseInt(revisionString); } catch (NumberFormatException nfe) { //bugzilla 2154 LogEvent.logError("AmendedResultsEntryUpdateAction", "performAction()", nfe.toString()); } } amendedAnalysis.setRevision(String.valueOf(++revision)); amendedAnalysis.setStatus(SystemConfiguration.getInstance().getAnalysisStatusResultCompleted()); amendedAnalysis.setPrintedDate(null); //bugzilla 2013 added duplicateCheck parameter analysisDAO.insertData(amendedAnalysis, false); //find qa events attached to analysisToAmend and clone them to the amenedAnalysis AnalysisQaEvent analysisQaEventToAmend = new AnalysisQaEvent(); analysisQaEventToAmend.setAnalysis(analysisToAmend); List qaEvents = analysisQaEventDAO.getAnalysisQaEventsByAnalysis(analysisQaEventToAmend); if (qaEvents != null && qaEvents.size() > 0) { for (int y = 0; y < qaEvents.size(); y++) { analysisQaEventToAmend = (AnalysisQaEvent) qaEvents.get(y); AnalysisQaEvent amendedAnalysisQaEvent = new AnalysisQaEvent(); AnalysisQaEventAction analysisQaEventActionToAmend = new AnalysisQaEventAction(); analysisQaEventActionToAmend.setAnalysisQaEvent(analysisQaEventToAmend); List qaEventActionsToAmend = analysisQaEventActionDAO .getAnalysisQaEventActionsByAnalysisQaEvent(analysisQaEventActionToAmend); PropertyUtils.copyProperties(amendedAnalysisQaEvent, analysisQaEventToAmend); amendedAnalysisQaEvent.setId(null); amendedAnalysisQaEvent.setAnalysis(amendedAnalysis); amendedAnalysisQaEvent.setLastupdated(null); amendedAnalysisQaEvent.setSysUserId(sysUserId); analysisQaEventDAO.insertData(amendedAnalysisQaEvent); //get actions also if (qaEventActionsToAmend != null && qaEventActionsToAmend.size() > 0) { for (int z = 0; z < qaEventActionsToAmend.size(); z++) { analysisQaEventActionToAmend = (AnalysisQaEventAction) qaEventActionsToAmend.get(z); AnalysisQaEventAction amendedAnalysisQaEventAction = new AnalysisQaEventAction(); PropertyUtils.copyProperties(amendedAnalysisQaEventAction, analysisQaEventActionToAmend); amendedAnalysisQaEventAction.setId(null); amendedAnalysisQaEventAction.setAnalysisQaEvent(amendedAnalysisQaEvent); amendedAnalysisQaEventAction.setLastupdated(null); amendedAnalysisQaEventAction.setSysUserId(sysUserId); analysisQaEventActionDAO.insertData(amendedAnalysisQaEventAction); } } } } //create copies of results List resultsToAmend = resultDAO.getResultsByAnalysis(analysisToAmend); for (int i = 0; i < resultsToAmend.size(); i++) { Result resultToAmend = (Result) resultsToAmend.get(i); Result amendedResult = new Result(); PropertyUtils.copyProperties(amendedResult, resultToAmend); amendedResult.setId(null); amendedResult.setAnalysis(amendedAnalysis); amendedResult.setLastupdated(null); amendedResult.setSysUserId(sysUserId); resultDAO.insertData(amendedResult); //find other analyses on this sample that have this result/analysis as a parent and unlink/link to this one List childAnalyses = analysisDAO.getAllChildAnalysesByResult(resultToAmend); for (int j = 0; j < childAnalyses.size(); j++) { Analysis childAnalysis = (Analysis) childAnalyses.get(j); childAnalysis.setParentAnalysis(amendedAnalysis); childAnalysis.setParentResult(amendedResult); childAnalysis.setSysUserId(sysUserId); //this is for optimistic locking - we need the correct lastupdated for (int x = 0; x < testTestAnalytes.size(); x++) { Test_TestAnalyte test_testAnalyte = (Test_TestAnalyte) testTestAnalytes.get(x); Analysis analysis = test_testAnalyte.getAnalysis(); if (analysis.getId().equals(childAnalysis.getId())) { childAnalysis.setLastupdated(analysis.getLastupdated()); break; } } analysisDAO.updateData(childAnalysis); } //create copies of notes (attached to new results) Note note = new Note(); //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info ReferenceTables referenceTables = new ReferenceTables(); referenceTables.setId(SystemConfiguration.getInstance().getResultReferenceTableId()); note.setReferenceTables(referenceTables); note.setReferenceId(resultToAmend.getId()); List notesByResult = noteDAO.getAllNotesByRefIdRefTable(note); for (int x = 0; x < notesByResult.size(); x++) { Note noteToAmend = (Note) notesByResult.get(x); Note amendedNote = new Note(); PropertyUtils.copyProperties(amendedNote, noteToAmend); amendedNote.setId(null); amendedNote.setReferenceId(amendedResult.getId()); amendedNote.setLastupdated(null); //per Nancy retain user id of original author of note // Also!!!! Note needs to have systemUser (for Note mapping) AND sysUserId (for audit trail) set!!!! amendedNote.setSystemUser(noteToAmend.getSystemUser()); amendedNote.setSysUserId(sysUserId); noteDAO.insertData(amendedNote); } } //update sample status Sample sample = sampleDAO.getSampleByAccessionNumber(accessionNumber); //this is for optimistic locking...(sampleLastupdated was stored in form from initial read) sample.setLastupdated(sampleLastupdated); sample.setSysUserId(sysUserId); sample.setStatus(SystemConfiguration.getInstance().getSampleStatusEntry2Complete()); sampleDAO.updateData(sample); tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("AmendedResultsEntryUpdateAction", "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.InsertException", null, null); } errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); forward = FWD_FAIL; } finally { HibernateUtil.closeSession(); } } else { forward = FWD_FAIL; } return getForward(mapping.findForward(forward), accessionNumber); }
From source file:us.mn.state.health.lims.result.action.BatchResultsEntryAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // The first job is to determine if we are coming to this action with an // ID parameter in the request. If there is no parameter, we are // creating a new Result. // If there is a parameter present, we should bring up an existing // Result to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "false"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); DynaActionForm dynaForm = (DynaActionForm) form; //Get tests/testsections by user system id //bugzilla 2160 UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl(); List testSections = userTestSectionDAO.getAllUserTestSections(request); //bugzilla 2291 List tests = userTestSectionDAO.getAllUserTests(request, true); // get 3 drop down selections so we can repopulate String selectedTestSectionId = (String) dynaForm.get("selectedTestSectionId"); String selectedTestId = (String) dynaForm.get("selectedTestId"); // initialize the form dynaForm.initialize(mapping);//from w ww.j a v a2 s .com // default received date and entered date to today's date Date today = Calendar.getInstance().getTime(); Locale locale = (Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE"); String dateAsText = DateUtil.formatDateAsText(today, locale); String blank = ""; Result result = new Result(); if ((id != null) && (!"0".equals(id))) { // this is an existing // result result.setId(id); ResultDAO resultDAO = new ResultDAOImpl(); resultDAO.getData(result); isNew = false; // this is to set correct page title // do we need to enable next or previous? List results = resultDAO.getNextResultRecord(result.getId()); if (results.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } results = resultDAO.getPreviousResultRecord(result.getId()); if (results.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new result isNew = true; // this is to set correct page title } if (result.getId() != null && !result.getId().equals("0")) { request.setAttribute(ID, result.getId()); } // #1347 sort dropdown values Collections.sort(testSections, TestSectionComparator.NAME_COMPARATOR); //bugzilla 1844 change sort Collections.sort(tests, TestComparator.DESCRIPTION_COMPARATOR); // populate form from valueholder PropertyUtils.copyProperties(form, result); //bgm - bugzilla 1569 changed dateAsText to blank for the receivedDateForDisplay field. PropertyUtils.setProperty(form, "tests", tests); PropertyUtils.setProperty(form, "testSections", testSections); PropertyUtils.setProperty(form, "currentDate", dateAsText); PropertyUtils.setProperty(form, "receivedDateForDisplay", blank); PropertyUtils.setProperty(form, "sample_TestAnalytes", new ArrayList()); PropertyUtils.setProperty(form, "testAnalyte_TestResults", new ArrayList()); //bugzila 2553 removed a line of code from 2187 - not needed return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.result.action.BatchResultsVerificationAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // The first job is to determine if we are coming to this action with an // ID parameter in the request. If there is no parameter, we are // creating a new Result. // If there is a parameter present, we should bring up an existing // Result to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "false"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); DynaActionForm dynaForm = (DynaActionForm) form; //Get tests/testsections by user system id //bugzilla 2160 UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl(); List testSections = userTestSectionDAO.getAllUserTestSections(request); //bugzilla 2291 List tests = userTestSectionDAO.getAllUserTests(request, true); // initialize the form dynaForm.initialize(mapping);//ww w .j a v a2s .c o m Result result = new Result(); if ((id != null) && (!"0".equals(id))) { // this is an existing // result result.setId(id); ResultDAO resultDAO = new ResultDAOImpl(); resultDAO.getData(result); // do we need to enable next or previous? List results = resultDAO.getNextResultRecord(result.getId()); if (results.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } results = resultDAO.getPreviousResultRecord(result.getId()); if (results.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } if (result.getId() != null && !result.getId().equals("0")) { request.setAttribute(ID, result.getId()); } // #1347 sort dropdown values Collections.sort(testSections, TestSectionComparator.NAME_COMPARATOR); //bugzilla 1844 change sort Collections.sort(tests, TestComparator.DESCRIPTION_COMPARATOR); // populate form from valueholder PropertyUtils.copyProperties(form, result); PropertyUtils.setProperty(form, "tests", tests); PropertyUtils.setProperty(form, "testSections", testSections); PropertyUtils.setProperty(form, "sample_TestAnalytes", new ArrayList()); //bugzila 2552 removed a line of code from 2188 - not needed return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.result.action.ResultAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // The first job is to determine if we are coming to this action with an // ID parameter in the request. If there is no parameter, we are // creating a new Result. // If there is a parameter present, we should bring up an existing // Result to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); DynaActionForm dynaForm = (DynaActionForm) form; // initialize the form dynaForm.initialize(mapping);//from w ww .j ava 2 s .com Result result = new Result(); if ((id != null) && (!"0".equals(id))) { // this is an existing // result result.setId(id); ResultDAO resultDAO = new ResultDAOImpl(); resultDAO.getData(result); // initialize analyteId if (result.getAnalyte() != null) { result.setAnalyteId(result.getAnalyte().getId()); } // initialize analysisId if (result.getAnalysis() != null) { result.setAnalysisId(result.getAnalysis().getId()); } // initialize testResultId if (result.getTestResult() != null) { result.setTestResultId(result.getTestResult().getId()); } isNew = false; // this is to set correct page title // do we need to enable next or previous? List results = resultDAO.getNextResultRecord(result.getId()); if (results.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } results = resultDAO.getPreviousResultRecord(result.getId()); if (results.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new result isNew = true; // this is to set correct page title } if (result.getId() != null && !result.getId().equals("0")) { request.setAttribute(ID, result.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, result); AnalyteDAO analyteDAO = new AnalyteDAOImpl(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); TestResultDAO testResultDAO = new TestResultDAOImpl(); List analyses = analysisDAO.getAllAnalyses(); List analytes = analyteDAO.getAllAnalytes(); List testResults = testResultDAO.getAllTestResults(); PropertyUtils.setProperty(form, "analyses", analyses); PropertyUtils.setProperty(form, "analytes", analytes); PropertyUtils.setProperty(form, "testResults", testResults); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.result.action.ResultsEntryAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // The first job is to determine if we are coming to this action with an // ID parameter in the request. If there is no parameter, we are // creating a new Result. // If there is a parameter present, we should bring up an existing // Result to edit. String id = request.getParameter(ID); //bugzilla 2154 LogEvent.logDebug("ResultsEntryAction", "performAction()", "In ResultsEntryAction ID: " + id); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); // bugzilla 1348 - modified in 1774 HttpSession session = request.getSession(); //bugzila 2053 ResultsEntryRoutingSwitchSessionHandler.switchAllOff(session); DynaActionForm dynaForm = (DynaActionForm) form; // initialize the form dynaForm.initialize(mapping);/* ww w.jav a2 s . co m*/ Result result = new Result(); if ((id != null) && (!"0".equals(id))) { // this is an existing // result result.setId(id); ResultDAO resultDAO = new ResultDAOImpl(); resultDAO.getData(result); isNew = false; // this is to set correct page title // do we need to enable next or previous? List results = resultDAO.getNextResultRecord(result.getId()); if (results.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } results = resultDAO.getPreviousResultRecord(result.getId()); if (results.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new result isNew = true; // this is to set correct page title } if (result.getId() != null && !result.getId().equals("0")) { request.setAttribute(ID, result.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, result); PropertyUtils.setProperty(form, "testTestAnalytes", new ArrayList()); PropertyUtils.setProperty(form, "organization", new Organization()); PropertyUtils.setProperty(form, "project", new Project()); PropertyUtils.setProperty(form, "typeOfSample", new TypeOfSample()); PropertyUtils.setProperty(form, "sourceOfSample", new SourceOfSample()); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.result.action.ResultUpdateAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // The first job is to determine if we are coming to this action with an // ID parameter in the request. If there is no parameter, we are // creating a new Result. // If there is a parameter present, we should bring up an existing // Result to edit. String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "false"); request.setAttribute(NEXT_DISABLED, "false"); String id = request.getParameter(ID); if (StringUtil.isNullorNill(id) || "0".equals(id)) { isNew = true;// w ww. j a va2s . co m } else { isNew = false; } BaseActionForm dynaForm = (BaseActionForm) form; // server-side validation (validation.xml) ActionMessages errors = dynaForm.validate(mapping, request); try { errors = validateAll(request, errors, dynaForm); } catch (Exception e) { //bugzilla 2154 LogEvent.logError("ResultUpdateAction", "performAction()", e.toString()); ActionError error = new ActionError("errors.ValidationException", null, null); errors.add(ActionMessages.GLOBAL_MESSAGE, error); } if (errors != null && errors.size() > 0) { saveErrors(request, errors); return mapping.findForward(FWD_FAIL); } String start = (String) request.getParameter("startingRecNo"); String direction = (String) request.getParameter("direction"); // System.out.println("This is ID from request " + id); Result result = new Result(); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); Analyte analyte = new Analyte(); String analyteId = (String) dynaForm.get("analyteId"); analyte.setId(analyteId); AnalyteDAO analyteDAO = new AnalyteDAOImpl(); analyteDAO.getData(analyte); Analysis analysis = new Analysis(); String analysisId = (String) dynaForm.get("analysisId"); analysis.setId(analysisId); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); analysisDAO.getData(analysis); TestResult testResult = new TestResult(); String testResultId = (String) dynaForm.get("testResultId"); testResult.setId(testResultId); TestResultDAO testResultDAO = new TestResultDAOImpl(); testResultDAO.getData(testResult); // populate valueholder from form PropertyUtils.copyProperties(result, dynaForm); result.setAnalyte(analyte); result.setAnalysis(analysis); result.setTestResult(testResult); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); result.setSysUserId(sysUserId); try { ResultDAO resultDAO = new ResultDAOImpl(); if (!isNew) { // UPDATE resultDAO.updateData(result); if (FWD_NEXT.equals(direction)) { List results = resultDAO.getNextResultRecord(result.getId()); if (results != null && results.size() > 0) { result = (Result) results.get(0); resultDAO.getData(result); if (results.size() < 2) { // disable next button request.setAttribute(NEXT_DISABLED, "true"); } id = result.getId(); } else { // just disable next button request.setAttribute(NEXT_DISABLED, "true"); } forward = FWD_NEXT; } if (FWD_PREVIOUS.equals(direction)) { List results = resultDAO.getPreviousResultRecord(result.getId()); if (results != null && results.size() > 0) { result = (Result) results.get(0); resultDAO.getData(result); if (results.size() < 2) { // disable previous button request.setAttribute(PREVIOUS_DISABLED, "true"); } id = result.getId(); } else { // just disable next button request.setAttribute(PREVIOUS_DISABLED, "true"); } forward = FWD_PREVIOUS; } } else { // INSERT resultDAO.insertData(result); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("ResultUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { // how can I get popup instead of struts error at the top of // page? // ActionMessages errors = dynaForm.validate(mapping, request); 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"); // disable previous and next request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); forward = FWD_FAIL; } finally { HibernateUtil.closeSession(); } if (forward.equals(FWD_FAIL)) return mapping.findForward(forward); // initialize the form dynaForm.initialize(mapping); // repopulate the form from valueholder PropertyUtils.copyProperties(dynaForm, result); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (result.getId() != null && !result.getId().equals("0")) { request.setAttribute(ID, result.getId()); } //bugzilla 1400 if (isNew) forward = FWD_SUCCESS_INSERT; return getForward(mapping.findForward(forward), id, start); }