List of usage examples for org.joda.time DateTime withTimeAtStartOfDay
public DateTime withTimeAtStartOfDay()
From source file:com.marand.thinkmed.medications.task.impl.MedicationsTasksProviderImpl.java
License:Open Source License
@Override public Map<String, List<TherapyTaskSimpleDto>> findSimpleTasksForTherapies(final String patientId, final Collection<String> therapyIds, final DateTime when) { final List<String> taskKeys = new ArrayList<>(); taskKeys.add(DoctorReviewTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId))); taskKeys.add(SwitchToOralTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId))); taskKeys.add(SupplyReviewTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId))); taskKeys.add(SupplyReminderTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId))); taskKeys.add(PerfusionSyringeStartPreparationTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId))); taskKeys.add(/*from ww w.j av a 2 s . com*/ PerfusionSyringeCompletePreparationTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId))); taskKeys.add( PerfusionSyringeDispenseMedicationTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId))); final Map<String, TaskDto> doctorReviewTasks = new HashMap<>(); final Map<String, TaskDto> switchToOralTasks = new HashMap<>(); final Map<String, TaskDto> supplyReviewTasks = new HashMap<>(); final Map<String, TaskDto> supplyReminderTasks = new HashMap<>(); final Map<String, TaskDto> perfusionSyringeTasks = new HashMap<>(); final PartialList<TaskDto> tasks = processService.findTasks(null, null, null, false, null, null, taskKeys, EnumSet.of(TaskDetailsEnum.VARIABLES)); if (tasks != null) { for (final TaskDto task : tasks) { final String therapyId = (String) task.getVariables() .get(TherapyTaskDef.ORIGINAL_THERAPY_ID.getName()); if (task.getTaskExecutionStrategyId().equals(TaskTypeEnum.DOCTOR_REVIEW.getName())) { //don't show future tasks if (!task.getDueTime().withTimeAtStartOfDay().isAfter(when.withTimeAtStartOfDay())) { doctorReviewTasks.put(therapyId, task); } } else if (task.getTaskExecutionStrategyId().equals(TaskTypeEnum.SWITCH_TO_ORAL.getName())) { //don't show future tasks if (!task.getDueTime().withTimeAtStartOfDay().isAfter(when.withTimeAtStartOfDay())) { switchToOralTasks.put(therapyId, task); } } else if (task.getTaskExecutionStrategyId().equals(TaskTypeEnum.SUPPLY_REVIEW.getName())) { supplyReviewTasks.put(therapyId, task); } else if (task.getTaskExecutionStrategyId().equals(TaskTypeEnum.SUPPLY_REMINDER.getName())) { final Boolean isDismissed = (Boolean) task.getVariables() .get(SupplyReminderTaskDef.IS_DISMISSED.getName()); if (isDismissed == null || !isDismissed) { supplyReminderTasks.put(therapyId, task); } } else if (task.getTaskExecutionStrategyId().equals(TaskTypeEnum.PERFUSION_SYRINGE_START.getName()) || task.getTaskExecutionStrategyId() .equals(TaskTypeEnum.PERFUSION_SYRINGE_COMPLETE.getName()) || task.getTaskExecutionStrategyId() .equals(TaskTypeEnum.PERFUSION_SYRINGE_DISPENSE.getName())) { perfusionSyringeTasks.put(therapyId, task); } } } final Map<String, List<TherapyTaskSimpleDto>> tasksMap = new HashMap<>(); for (final String therapyId : therapyIds) { tasksMap.put(therapyId, new ArrayList<>()); if (doctorReviewTasks.containsKey(therapyId)) { final TherapyTaskSimpleDto doctorReviewTask = buildTherapyTaskSimpleDto( doctorReviewTasks.get(therapyId), TaskTypeEnum.DOCTOR_REVIEW); tasksMap.get(therapyId).add(doctorReviewTask); } if (switchToOralTasks.containsKey(therapyId)) { final TherapyTaskSimpleDto switchToOralTask = buildTherapyTaskSimpleDto( switchToOralTasks.get(therapyId), TaskTypeEnum.SWITCH_TO_ORAL); tasksMap.get(therapyId).add(switchToOralTask); } if (supplyReviewTasks.containsKey(therapyId)) { final TherapyTaskSimpleDto supplyReviewTask = buildTherapyTaskSimpleDto( supplyReviewTasks.get(therapyId), TaskTypeEnum.SUPPLY_REVIEW); tasksMap.get(therapyId).add(supplyReviewTask); } if (supplyReminderTasks.containsKey(therapyId)) { final TherapyTaskSimpleDto supplyReminderTask = buildTherapyTaskSimpleDto( supplyReminderTasks.get(therapyId), TaskTypeEnum.SUPPLY_REMINDER); tasksMap.get(therapyId).add(supplyReminderTask); } if (perfusionSyringeTasks.containsKey(therapyId)) { final TaskDto perfusionSyringeTaskDto = perfusionSyringeTasks.get(therapyId); final TherapyTaskSimpleDto perfusionSyringeTaskSimple = buildTherapyTaskSimpleDto( perfusionSyringeTasks.get(therapyId), TaskTypeEnum.getByName(perfusionSyringeTaskDto.getTaskExecutionStrategyId())); tasksMap.get(therapyId).add(perfusionSyringeTaskSimple); } } return tasksMap; }
From source file:com.marand.thinkmed.medications.therapy.impl.TherapyUpdaterImpl.java
License:Open Source License
private void createReminders(final TherapyDto therapyDto, final String therapyId, final Integer reviewReminderDays, final String patientId, final Locale locale) { final Long mainMedicationId = therapyDto.getMainMedicationId(); final MedicationHolderDto medicationHolderDto = medicationsValueHolder.getValue().get(mainMedicationId); final DateTime therapyStart = therapyDto.getStart(); if (medicationHolderDto != null && medicationHolderDto.isSuggestSwitchToOral()) { if (therapyDto.getRoutes().size() == 1 && therapyDto.getRoutes().get(0).getType() == MedicationRouteTypeEnum.IV) { final DateTime dueDate = therapyStart.withTimeAtStartOfDay().plusDays(2); //TODO TMC-7170 antibiotic - from preference (care provider) final NewTaskRequestDto taskRequest = new NewTaskRequestDto(SwitchToOralTaskDef.INSTANCE, SwitchToOralTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId)), "Switch to oral medication " + dueDate.toString(DateTimeFormatters.shortDate(locale)), "Switch to oral medication " + dueDate.toString(DateTimeFormatters.shortDate(locale)), TherapyAssigneeEnum.DOCTOR.name(), dueDate, null, Pair.of(MedsTaskDef.PATIENT_ID, patientId), Pair.of(TherapyTaskDef.ORIGINAL_THERAPY_ID, therapyId)); processService.createTasks(taskRequest); }/* w w w . j a v a 2s .c om*/ } if (reviewReminderDays != null) { final DateTime dueDate = therapyStart.withTimeAtStartOfDay().plusDays(reviewReminderDays); final NewTaskRequestDto taskRequest = new NewTaskRequestDto(DoctorReviewTaskDef.INSTANCE, DoctorReviewTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId)), "Doctor review task " + dueDate.toString(DateTimeFormatters.shortDate(locale)), "Doctor review task " + dueDate.toString(DateTimeFormatters.shortDate(locale)), TherapyAssigneeEnum.DOCTOR.name(), dueDate, null, Pair.of(MedsTaskDef.PATIENT_ID, patientId), Pair.of(TherapyTaskDef.ORIGINAL_THERAPY_ID, therapyId)); processService.createTasks(taskRequest); } }
From source file:com.marand.thinkmed.medications.therapy.impl.TherapyUpdaterImpl.java
License:Open Source License
private void handleTherapyTasksOnModify(final String patientId, final TherapyDto therapy, final MedicationInstructionInstruction instruction, final String therapyId, final DateTime when) { final List<String> taskKeys = new ArrayList<>(); taskKeys.add(DoctorReviewTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId))); taskKeys.add(SwitchToOralTaskDef.getTaskTypeEnum().buildKey(String.valueOf(patientId))); //noinspection unchecked final PartialList<TaskDto> tasks = processService.findTasks(TherapyAssigneeEnum.DOCTOR.name(), null, null, false, null, null, taskKeys, EnumSet.of(TaskDetailsEnum.VARIABLES)); final List<Link> originLinks = MedicationsEhrUtils.getLinksOfType(instruction, EhrLinkType.ORIGIN); final String originalTherapyId = originLinks.isEmpty() ? therapyId : TherapyIdUtils.getTherapyIdFromLink(originLinks.get(0)); if (tasks != null) { for (final TaskDto task : tasks) { final String taskTherapyId = (String) task.getVariables() .get(TherapyTaskDef.ORIGINAL_THERAPY_ID.getName()); if (originalTherapyId.equals(taskTherapyId)) { if (task.getTaskExecutionStrategyId().equals(TaskTypeEnum.DOCTOR_REVIEW.getName())) { if (!when.withTimeAtStartOfDay().isBefore(task.getDueTime().withTimeAtStartOfDay())) { processService.completeTasks(task.getId()); }// ww w .j a v a 2s .co m } else { if (task.getTaskExecutionStrategyId().equals(TaskTypeEnum.SWITCH_TO_ORAL.getName())) { final boolean ivRouteExists = therapy.getRoutes().stream() .filter(route -> route.getType() == MedicationRouteTypeEnum.IV) .anyMatch(Objects::nonNull); if (!ivRouteExists) { processService.completeTasks(task.getId()); } } } } } } }
From source file:com.netflix.dynomitemanager.sidecore.backup.S3Restore.java
License:Apache License
private long restoreTime(String dateString) { logger.info("Date to restore to: " + dateString); DateTimeFormatter formatter = null; try {// ww w.j ava 2 s.c o m formatter = DateTimeFormat.forPattern("yyyyMMdd"); } catch (Exception e) { logger.error("Restore fast property not formatted properly " + e.getMessage()); return -1; } DateTime dt = formatter.parseDateTime(dateString); DateTime dateBackup = dt.withTimeAtStartOfDay(); return dateBackup.getMillis(); }
From source file:com.netflix.dynomitemanager.sidecore.backup.SnapshotTask.java
License:Apache License
public void execute() throws Exception { this.state.setFirstBackup(false); if (!state.isRestoring() && !state.isBootstrapping()) { /** Iterate five times until storage (Redis) is ready. * We need storage to be ready to dumb the data, * otherwise we may backup older data. Another case, * is that the thread that starts Dynomite has not * started Redis yet./*from ww w . j a va2 s . c om*/ */ int i = 0; for (i = 0; i < this.storageRetries; i++) { if (!this.state.isStorageAlive()) { //sleep 2 seconds to make sure Dynomite process is up, Storage process is up. sleeper.sleepQuietly(2000); } else { this.state.setBackingup(true); /** * Set the status of the backup to false every time we start a backup. * This will ensure that prior to backup we recapture the status of the backup. */ this.state.setBackUpStatus(false); // the storage proxy takes a snapshot or compacts data boolean snapshot = this.storageProxy.takeSnapshot(); File file = null; if (config.isAof()) { file = new File(config.getPersistenceLocation() + "/appendonly.aof"); } else { file = new File(config.getPersistenceLocation() + "/nfredis.rdb"); } // upload the data to S3 if (file.length() > 0 && snapshot == true) { DateTime now = DateTime.now(); DateTime todayStart = now.withTimeAtStartOfDay(); this.state.setBackupTime(todayStart); if (this.backup.upload(file, todayStart)) { this.state.setBackUpStatus(true); logger.info("S3 backup status: Completed!"); } else { logger.error("S3 backup status: Failed!"); } } else { logger.warn("S3 backup: Redis AOF file length is zero - nothing to backup"); } break; } } if (i == this.storageRetries) { logger.error("S3 backup Failed: Redis was not up after " + this.storageRetries + " retries"); } this.state.setBackingup(false); } else { logger.error("S3 backup Failed: Restore is happening"); } }
From source file:com.onboard.service.activity.impl.ActivityServiceImpl.java
License:Apache License
@Override public List<Activity> getByProjectByDate(int projectId, Date date) { Activity sample = new Activity(); sample.setProjectId(projectId);/*from w ww . j a v a 2 s . co m*/ ActivityExample example = new ActivityExample(sample); DateTime dt = new DateTime(date); Date start = dt.withTimeAtStartOfDay().toDate(); Date end = dt.plusDays(1).toDate(); example.getOredCriteria().get(0).andCreatedGreaterThanOrEqualTo(start).andCreatedLessThan(end); return activityMapper.selectByExample(example); }
From source file:com.onboard.service.activity.impl.ActivityServiceImpl.java
License:Apache License
@Override public List<Activity> getByProjectBetweenDates(int projectId, Date start, Date end) { Activity sample = new Activity(); sample.setProjectId(projectId);// w w w .j a va 2 s . c om ActivityExample example = new ActivityExample(sample); DateTime dt = new DateTime(start); start = dt.withTimeAtStartOfDay().toDate(); dt = new DateTime(end); end = dt.withTimeAtStartOfDay().plusDays(1).toDate(); example.getOredCriteria().get(0).andCreatedGreaterThanOrEqualTo(start).andCreatedLessThan(end); example.setOrderByClause("id desc"); return activityMapper.selectByExample(example); }
From source file:com.onboard.service.activity.impl.ActivityServiceImpl.java
License:Apache License
@Override public List<Activity> getByProjectUserBetweenDates(int projectId, int userId, Date start, Date end) { Activity sample = new Activity(); sample.setProjectId(projectId);/*from w w w . ja v a 2 s . c o m*/ sample.setCreatorId(userId); ActivityExample example = new ActivityExample(sample); DateTime dt = new DateTime(start); start = dt.withTimeAtStartOfDay().toDate(); dt = new DateTime(end); end = dt.withTimeAtStartOfDay().plusDays(1).toDate(); example.getOredCriteria().get(0).andCreatedGreaterThanOrEqualTo(start).andCreatedLessThan(end); example.setOrderByClause("id desc"); return activityMapper.selectByExample(example); }
From source file:com.onboard.service.activity.impl.ActivityServiceImpl.java
License:Apache License
private Integer getCountByCompanyUserBetweenDates(int companyId, int userId, Date start, Date end) { Activity sample = new Activity(); sample.setCompanyId(companyId);//from w w w. j av a 2 s . c o m sample.setCreatorId(userId); ActivityExample example = new ActivityExample(sample); DateTime dt = new DateTime(start); start = dt.withTimeAtStartOfDay().toDate(); dt = new DateTime(end); end = dt.withTimeAtStartOfDay().plusDays(1).toDate(); example.getOredCriteria().get(0).andCreatedGreaterThanOrEqualTo(start).andCreatedLessThan(end); example.setOrderByClause("id desc"); return activityMapper.countByExample(example); }
From source file:com.onboard.service.activity.impl.ActivityServiceImpl.java
License:Apache License
@Override public List<Map<String, ?>> getActivityCountForUsersGroupByDate(Integer companyId, Date since, Date until) { List<User> companyUsers = userService.getUserByCompanyId(companyId); List<Map<String, ?>> result = Lists.newArrayList(); Map<Integer, Integer> activityCountMap; DateTime dt = new DateTime(since); dt = dt.withTimeAtStartOfDay(); DateTime end = new DateTime(until); end = end.withTimeAtStartOfDay().plusDays(1).minusMinutes(1); while (dt.toDate().before(end.toDate())) { activityCountMap = Maps.newHashMap(); for (User user : companyUsers) { activityCountMap.put(user.getId(), getCountByCompanyUserBetweenDates(companyId, user.getId(), dt.toDate(), dt.toDate())); }/*from www . java 2 s .c om*/ result.add(ImmutableMap.of("time", dt.toDate().getTime(), "counts", activityCountMap)); dt = dt.plusDays(1); } return result; }