// 处理某个任务
  private void doOneTask0(Task task) {
    logger.error("doOneTask0...");

    try {
      Runnable runnable = (Runnable) Class.forName(task.getClz()).newInstance();
      if (runnable != null) {
        Thread thread = new Thread(runnable);
        task.setThread(thread);

        // 计算出此任务下一次的执行时间点
        String nextWorkTime = null;
        if (task.getUnit().equalsIgnoreCase("DAYS")) {
          nextWorkTime =
              sdf.format(DateUtils.addDays(new Date(), Integer.valueOf(task.getSleep())));
        } else if (task.getUnit().equalsIgnoreCase("HOURS")) {
          nextWorkTime =
              sdf.format(DateUtils.addHours(new Date(), Integer.valueOf(task.getSleep())));
        } else if (task.getUnit().equalsIgnoreCase("MINUTES")) {
          nextWorkTime =
              sdf.format(DateUtils.addMinutes(new Date(), Integer.valueOf(task.getSleep())));
        } else if (task.getUnit().equalsIgnoreCase("SECONDS")) {
          nextWorkTime =
              sdf.format(DateUtils.addSeconds(new Date(), Integer.valueOf(task.getSleep())));
        } else if (task.getUnit().equalsIgnoreCase("MILLISECONDS")) {
          nextWorkTime =
              sdf.format(DateUtils.addMilliseconds(new Date(), Integer.valueOf(task.getSleep())));
        }
        task.setNextWorkTime(nextWorkTime);
        task.setCurrentStatus(Task.task_currentStatus_wait);

        thread.setDaemon(true);
        thread.setName(task.getCode());
        thread.start();
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private boolean shouldBeClosed(Visit visit) {

    if (visit.getStopDatetime() != null) {
      return false; // already closed
    }

    VisitDomainWrapper visitDomainWrapper = domainWrapperFactory.newVisitDomainWrapper(visit);

    if (visitDomainWrapper.isAdmitted() || visitDomainWrapper.isAwaitingAdmission()) {
      return false; // don't close the visit if patient is admitted or waiting admission
    }

    Disposition mostRecentDisposition = visitDomainWrapper.getMostRecentDisposition();
    if (mostRecentDisposition != null
        && mostRecentDisposition.getKeepsVisitOpen() != null
        && mostRecentDisposition.getKeepsVisitOpen()) {
      return false; // don't close the visit if the most recent disposition is one that keeps visit
                    // opens
    }

    Date now = new Date();
    Date mustHaveSomethingAfter = DateUtils.addHours(now, -emrApiProperties.getVisitExpireHours());

    if (OpenmrsUtil.compare(visit.getStartDatetime(), mustHaveSomethingAfter) >= 0) {
      return false;
    }

    if (visit.getEncounters() != null) {
      for (Encounter candidate : visit.getEncounters()) {
        if (OpenmrsUtil.compare(candidate.getEncounterDatetime(), mustHaveSomethingAfter) >= 0) {
          return false;
        }
      }
    }

    return true;
  }
Example #3
0
 static Date getDateFromHours(Settings settings, String propertyKey) {
   int hours = settings.getInt(propertyKey);
   return DateUtils.addHours(new Date(), -hours);
 }