@Override
  public void run() {
    LoggedInInfo.setLoggedInInfoToCurrentClassAndMethod();
    try {
      log.debug("start bed program discharge task");

      Program[] bedPrograms = programManager.getBedPrograms();

      if (bedPrograms == null) {
        log.error("getBedPrograms returned null");
        return;
      }

      for (Program bedProgram : bedPrograms) {
        MiscUtilsOld.checkShutdownSignaled();

        Date dischargeTime = DateTimeFormatUtils.getTimeFromString(DISCHARGE_TIME);
        Date previousExecutionTime =
            DateTimeFormatUtils.getTimeFromLong(scheduledExecutionTime() - PERIOD);
        Date currentExecutionTime = DateTimeFormatUtils.getTimeFromLong(scheduledExecutionTime());

        // previousExecutionTime < dischargeTime <= currentExecutionTime
        if (previousExecutionTime.before(dischargeTime)
            && (dischargeTime.equals(currentExecutionTime)
                || dischargeTime.before(currentExecutionTime))) {
          Bed[] reservedBeds = bedManager.getBedsByProgram(bedProgram.getId(), true);

          if (reservedBeds == null) {
            log.error(
                "getBedsByProgram returned null for bed program with id: " + bedProgram.getId());
            continue;
          }

          for (Bed reservedBed : reservedBeds) {
            MiscUtilsOld.checkShutdownSignaled();

            BedDemographic bedDemographic =
                bedDemographicManager.getBedDemographicByBed(reservedBed.getId());

            if (bedDemographic != null
                && bedDemographic.getId() != null
                && bedDemographic.isExpired()) {
              try {
                admissionManager.processDischargeToCommunity(
                    Program.DEFAULT_COMMUNITY_PROGRAM_ID,
                    bedDemographic.getId().getDemographicNo(),
                    Provider.SYSTEM_PROVIDER_NO,
                    "bed reservation ended - automatically discharged",
                    "0",
                    null);
              } catch (AdmissionException e) {
                log.error("Error discharging to community", e);
              }
            }
          }
        }
      }

      log.debug("finish bed program discharge task");
    } catch (ShutdownException e) {
      log.debug("BedProgramDischargeTask noticed shutdown signaled.");
    } finally {
      LoggedInInfo.loggedInInfo.remove();
      DbConnectionFilter.releaseAllThreadDbResources();
    }
  }
  @Override
  public void run() {
    LoggedInInfo.setLoggedInInfoToCurrentClassAndMethod();
    try {
      logger.info("start ocan submission task");

      OcanProcess process = ocanDataProcessor.createOcanProcess();

      if (useTestData) {

        ocanDataProcessor.createOcanRecord(
            process,
            new FileInputStream(testDataPath + "/client.xml"),
            new FileInputStream(testDataPath + "/staff.xml"),
            "1001");
      } else {

        Calendar after = new GregorianCalendar();
        after.roll(Calendar.MONTH, -1);

        List<Map<String, String>> intakes = genericIntakeManager.getIntakeListforOcan(after);

        if (intakes == null || intakes.size() == 0) {
          logger.warn(
              "getIntakeListforOcan() returned null or empty list - no data for submission.");
          return;
        }

        for (Map<String, String> intakeMap : intakes) {
          MiscUtilsOld.checkShutdownSignaled();

          try {
            ocanDataProcessor.createOcanRecord(
                process,
                new ByteArrayInputStream(intakeMap.get("client").getBytes()),
                new ByteArrayInputStream(intakeMap.get("staff").getBytes()),
                intakeMap.get("clientId"));

          } catch (Exception e) {
            logger.error("createOcanRecord() thrown an exception, skipping the record.", e);
            continue;
          }
        }
      }

      ocanDataProcessor.finishOcanProcess(process);

      logger.info("finish ocan submission task");

    } catch (ShutdownException e) {
      logger.debug("OcanSubmissionTask noticed shutdown signaled.");
    } catch (FileNotFoundException e) {
      logger.error("finishOcanProcess() thrown an exception, terminating the submission.", e);
    } catch (JAXBException e) {
      logger.error("finishOcanProcess() thrown an exception, terminating the submission.", e);
    } catch (NumberFormatException e) {
      logger.error("finishOcanProcess() thrown an exception, terminating the submission.", e);
    } catch (ParseException e) {
      logger.error("finishOcanProcess() thrown an exception, terminating the submission.", e);
    } finally {
      LoggedInInfo.loggedInInfo.remove();
      DbConnectionFilter.releaseAllThreadDbResources();
    }
  }