List of usage examples for org.apache.commons.lang.time DateFormatUtils format
public static String format(Date date, String pattern)
Formats a date/time into a specific pattern.
From source file:org.openmrs.module.emrmonitor.metric.ConfigurableMetricProducerTest.java
@Test public void shouldProduceMultipleMetricsFromShellScript() throws Exception { if (isLinux()) { copyResourceToConfigurationFile("system.info.sh"); ConfigurableMetricProducer producer = new ConfigurableMetricProducer(); Map<String, String> metrics = producer.produceMetrics(); Assert.assertEquals(2, metrics.size()); List<String> keys = new ArrayList<String>(metrics.keySet()); List<String> values = new ArrayList<String>(metrics.values()); Assert.assertEquals("system.info.currentDate", keys.get(0)); Assert.assertEquals(DateFormatUtils.format(new Date(), "yyyy-MM-dd"), values.get(0)); Assert.assertEquals("system.info.myVar", keys.get(1)); Assert.assertEquals("myVal", values.get(1)); }//from w ww.j av a 2s . c om }
From source file:org.openmrs.module.emrmonitor.UptimeLog.java
/** * Rotates the current uptime.log file to a new file with the current datetime *///from w w w. ja v a 2 s . co m public static synchronized File rotate() { Date now = new Date(); String filename = DateFormatUtils.format(now, DATE_FORMAT) + ".log"; File destinationFile = new File(getLogDirectory(), filename); try { writeToLog(now, LOG_COMPLETED_TOKEN); FileUtils.moveFile(getLogFile(), destinationFile); initializeLogFile(now); } catch (IOException e) { throw new IllegalStateException("Unable to rotate log file to destination", e); } return destinationFile; }
From source file:org.openmrs.module.pihmalawi.common.AppointmentInfo.java
@Override public String toString() { List<String> l = new ArrayList<String>(); if (lastEncounterDate != null) { l.add("Last Actual: " + DateFormatUtils.format(lastEncounterDate, "yyyy-MM-dd")); }//from w w w . j a va2 s . com if (nextScheduledDate != null) { l.add("Next Scheduled: " + DateFormatUtils.format(nextScheduledDate, "yyyy-MM-dd")); } return OpenmrsUtil.join(l, ", "); }
From source file:org.oscarehr.consultations.ConsultationAction.java
private ConsultationData convertToConsultationDataObject(ConsultationRequest consult) { //get the data i need to support ConsultationData data = new ConsultationData(); Demographic demo = this.demographicDao.getDemographicById(consult.getDemographicId()); ConsultationServices services = this.consultationServiceDao.find(consult.getServiceId()); data.setStatus(consult.getStatus()); data.setUrgency(paginationUtils.parseInt(consult.getUrgency())); if ("-1".equals(consult.getSendTo())) { data.setSendTo(null);/*w w w. j av a 2 s . co m*/ } else { data.setSendTo(consult.getSendTo()); } data.setPatient(demo.getFormattedName()); String providerId = demo.getProviderNo(); if (providerId != null && !providerId.equals("")) { Provider provider = providerDao.getProvider(providerId); data.setProviderName(provider.getFormattedName()); data.setProviderNo(provider.getProviderNo()); } else { data.setProviderName(null); } data.setServiceId(consult.getServiceId().toString()); data.setServiceDesc(services.getServiceDesc()); if (consult.getProfessionalSpecialist() == null) { data.setSpecialistName(null); } else { ProfessionalSpecialist specialist = consult.getProfessionalSpecialist(); String specialistName = specialist.getLastName() + ", " + specialist.getFirstName(); data.setSpecialistName(specialistName); } data.setDemographicNo(consult.getDemographicId().toString()); if (consult.getReferralDate() != null) { data.setReferralDate(DateFormatUtils.format(consult.getReferralDate(), "yyyy-MM-dd")); } data.setId(consult.getId().toString()); Date apptDate = consult.getAppointmentDate(); Date apptTime = consult.getAppointmentTime(); if (apptDate != null && apptTime != null) { data.setAppointmentDate(DateFormatUtils.format(apptDate, "yyyy-MM-dd") + " " + DateFormatUtils.format(apptTime, "HH:mm")); } data.setPatientWillBook(consult.isPatientWillBook()); apptDate = consult.getFollowUpDate(); if (apptDate != null) { data.setFollowUpDate(DateFormatUtils.format(apptDate, "yyyy-MM-dd")); } return data; }
From source file:org.oscarehr.document.web.SplitDocumentAction.java
public ActionForward split(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {//from www . j av a 2 s .co m String docNum = request.getParameter("document"); String[] commands = request.getParameterValues("page[]"); String queueId = request.getParameter("queueID"); LoggedInInfo loggedInInfo = LoggedInInfo.getLoggedInInfoFromSession(request); String providerNo = loggedInInfo.getLoggedInProviderNo(); Document doc = documentDao.getDocument(docNum); String docdownload = oscar.OscarProperties.getInstance().getProperty("DOCUMENT_DIR"); String newFilename = doc.getDocfilename(); FileInputStream input = null; PDDocument pdf = null; PDDocument newPdf = null; try { input = new FileInputStream(docdownload + doc.getDocfilename()); PDFParser parser = new PDFParser(input); parser.parse(); pdf = parser.getPDDocument(); newPdf = new PDDocument(); List pages = pdf.getDocumentCatalog().getAllPages(); if (commands != null) { for (String c : commands) { String[] command = c.split(","); int pageNum = Integer.parseInt(command[0]); int rotation = Integer.parseInt(command[1]); PDPage p = (PDPage) pages.get(pageNum - 1); p.setRotation(rotation); newPdf.addPage(p); } } //newPdf.save(docdownload + newFilename); if (newPdf.getNumberOfPages() > 0) { EDoc newDoc = new EDoc("", "", newFilename, "", providerNo, doc.getDoccreator(), "", 'A', DateFormatUtils.format(new Date(), "yyyy-MM-dd"), "", "", "demographic", "-1", 0); newDoc.setDocPublic("0"); newDoc.setContentType("application/pdf"); newDoc.setNumberOfPages(newPdf.getNumberOfPages()); String newDocNo = EDocUtil.addDocumentSQL(newDoc); newPdf.save(docdownload + newDoc.getFileName()); newPdf.close(); WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(request.getSession().getServletContext()); ProviderInboxRoutingDao providerInboxRoutingDao = (ProviderInboxRoutingDao) ctx .getBean("providerInboxRoutingDAO"); providerInboxRoutingDao.addToProviderInbox("0", Integer.parseInt(newDocNo), "DOC"); List<ProviderInboxItem> routeList = providerInboxRoutingDao .getProvidersWithRoutingForDocument("DOC", Integer.parseInt(docNum)); for (ProviderInboxItem i : routeList) { providerInboxRoutingDao.addToProviderInbox(i.getProviderNo(), Integer.parseInt(newDocNo), "DOC"); } providerInboxRoutingDao.addToProviderInbox(providerNo, Integer.parseInt(newDocNo), "DOC"); QueueDocumentLinkDao queueDocumentLinkDAO = (QueueDocumentLinkDao) ctx .getBean("queueDocumentLinkDAO"); Integer qid = queueId == null ? 1 : Integer.parseInt(queueId); Integer did = Integer.parseInt(newDocNo.trim()); queueDocumentLinkDAO.addActiveQueueDocumentLink(qid, did); ProviderLabRoutingDao providerLabRoutingDao = (ProviderLabRoutingDao) SpringUtils .getBean("providerLabRoutingDao"); List<ProviderLabRoutingModel> result = providerLabRoutingDao .getProviderLabRoutingDocuments(Integer.parseInt(docNum)); if (!result.isEmpty()) { new ProviderLabRouting().route(newDocNo, result.get(0).getProviderNo(), "DOC"); } PatientLabRoutingDao patientLabRoutingDao = (PatientLabRoutingDao) SpringUtils .getBean("patientLabRoutingDao"); List<PatientLabRouting> result2 = patientLabRoutingDao .findDocByDemographic(Integer.parseInt(docNum)); if (!result2.isEmpty()) { PatientLabRouting newPatientRoute = new PatientLabRouting(); newPatientRoute.setDemographicNo(result2.get(0).getDemographicNo()); newPatientRoute.setLabNo(Integer.parseInt(newDocNo)); newPatientRoute.setLabType("DOC"); patientLabRoutingDao.persist(newPatientRoute); } CtlDocumentDao ctlDocumentDao = SpringUtils.getBean(CtlDocumentDao.class); CtlDocument result3 = ctlDocumentDao.getCtrlDocument(Integer.parseInt(docNum)); if (result3 != null) { CtlDocumentPK ctlDocumentPK = new CtlDocumentPK(Integer.parseInt(newDocNo), "demographic"); CtlDocument newCtlDocument = new CtlDocument(); newCtlDocument.setId(ctlDocumentPK); newCtlDocument.getId().setModuleId(result3.getId().getModuleId()); newCtlDocument.setStatus(result3.getStatus()); documentDao.persist(newCtlDocument); } if (result.isEmpty() || result2.isEmpty()) { String json = "{newDocNum:" + newDocNo + "}"; JSONObject jsonObject = JSONObject.fromObject(json); response.setContentType("application/json"); PrintWriter printWriter = response.getWriter(); printWriter.print(jsonObject); printWriter.flush(); return null; } } } catch (Exception e) { MiscUtils.getLogger().error(e.getMessage(), e); return null; } finally { try { if (pdf != null) pdf.close(); if (input != null) input.close(); } catch (IOException e) { //do nothing } } return mapping.findForward("success"); }
From source file:org.oscarehr.fax.core.FaxImporter.java
private boolean saveAndInsertIntoQueue(FaxConfig faxConfig, FaxJob receivedFax, FaxJob faxFile) { boolean retval = false; String filename = receivedFax.getFile_name().replace("tif", "pdf"); String user = "-1"; EDoc newDoc = new EDoc("", "", filename, "", user, user, "", 'A', DateFormatUtils.format(receivedFax.getStamp(), "yyyy-MM-dd"), "", "", "demographic", "-1", 0); newDoc.setDocPublic("0"); filename = newDoc.getFileName();/*from www. j a v a2 s.com*/ if (Base64.decodeToFile(faxFile.getDocument(), DOCUMENT_DIR + "/" + filename)) { newDoc.setContentType("application/pdf"); newDoc.setNumberOfPages(receivedFax.getNumPages()); String doc_no = EDocUtil.addDocumentSQL(newDoc); Integer queueId = faxConfig.getQueue(); Integer docNum = Integer.parseInt(doc_no); queueDocumentLinkDao.addActiveQueueDocumentLink(queueId, docNum); FaxJob saveFax = new FaxJob(receivedFax); saveFax.setFile_name(filename); faxJobDao.persist(saveFax); retval = true; } return retval; }
From source file:org.oscarehr.integration.mchcv.OnlineHCValidator.java
private String makeDate(int year, int month, int day) { java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.set(year, month - 1, day, 0, 0, 0); return DateFormatUtils.format(calendar, "yyyyMMdd"); }
From source file:org.oscarehr.PMmodule.web.forms.IntegratorPushItem.java
public String getDateCreatedAsString() { return DateFormatUtils.format(getDateCreated(), "yyyy-MM-dd HH:mm:ss"); }
From source file:org.oscarehr.PMmodule.web.forms.IntegratorPushItem.java
public String getEstimatedDateOfCompletionAsString() { if (IntegratorProgress.STATUS_COMPLETED.equals(getStatus())) { return "N/A"; }/* w ww . ja v a2 s. c om*/ return DateFormatUtils.format(getEstimatedDateOfCompletion(), "yyyy-MM-dd HH:mm:ss"); }
From source file:org.oscarehr.ws.rest.ProgramService.java
@GET @Path("/patientList") @Produces("application/json") public AbstractSearchResponse<AdmissionTo1> getPatientList(@QueryParam("programNo") String programNo, @QueryParam("day") String day, @QueryParam("startIndex") Integer startIndex, @QueryParam("numToReturn") Integer numToReturn) throws Exception { AbstractSearchResponse<AdmissionTo1> response = new AbstractSearchResponse<AdmissionTo1>(); if (day == null) { day = DateFormatUtils.format(Calendar.getInstance(), DateUtils.ISO8601_DATE_PATTERN); }//w w w . j ava 2s . c o m Date d = new SimpleDateFormat(DateUtils.ISO8601_DATE_PATTERN).parse(day); if (programNo == null) { //get default ProgramProvider current = null; ProgramProvider pp = programManager.getCurrentProgramInDomain(getLoggedInInfo(), getLoggedInInfo().getLoggedInProviderNo()); if (pp != null) { current = pp; } else { List<ProgramProvider> ppList = programManager.getProgramDomain(getLoggedInInfo(), getLoggedInInfo().getLoggedInProviderNo()); if (ppList.size() > 0) { current = ppList.get(0); } } if (current != null) { programNo = String.valueOf(current.getProgramId()); } } if (programNo == null) { throw new Exception("Can't get a program for this provider to use as default"); } List<AdmissionTo1> transfers = new AdmissionConverter().includeDemographic(true).getAllAsTransferObjects( getLoggedInInfo(), admissionManager.findAdmissionsByProgramAndDate(getLoggedInInfo(), Integer.parseInt(programNo), d, startIndex, numToReturn)); response.setContent(transfers); response.setTotal(admissionManager.findAdmissionsByProgramAndDateAsCount(getLoggedInInfo(), Integer.parseInt(programNo), d)); return response; }