Example usage for org.joda.time Interval getStart

List of usage examples for org.joda.time Interval getStart

Introduction

In this page you can find the example usage for org.joda.time Interval getStart.

Prototype

public DateTime getStart() 

Source Link

Document

Gets the start of this time interval, which is inclusive, as a DateTime.

Usage

From source file:com.marand.thinkmed.medications.pharmacist.impl.PharmacistTaskProviderImpl.java

License:Open Source License

@Override
public List<TaskDto> findPharmacistReminderAndSupplyTasks(final String patientId,
        final Interval searchInterval) {
    final DateTime taskDueAfter = searchInterval != null ? searchInterval.getStart() : null;
    final DateTime taskDueBefore = searchInterval != null ? searchInterval.getEnd() : null;

    final Set<TaskTypeEnum> taskTypes = EnumSet.of(TaskTypeEnum.PHARMACIST_REMINDER,
            TaskTypeEnum.SUPPLY_REMINDER, TaskTypeEnum.SUPPLY_REVIEW, TaskTypeEnum.DISPENSE_MEDICATION);

    final List<String> taskKeys = TherapyTaskUtils
            .getPatientIdKeysForTaskTypes(Collections.singleton(patientId), taskTypes);

    return processService.findTasks(TherapyAssigneeEnum.PHARMACIST.name(), null, null, false, taskDueAfter,
            taskDueBefore, taskKeys, EnumSet.of(TaskDetailsEnum.VARIABLES));
}

From source file:com.marand.thinkmed.medications.pharmacist.impl.PharmacistTaskProviderImpl.java

License:Open Source License

@Override
public List<String> findTaskIds(final Interval searchInterval, final String assignee,
        final Set<String> patientIdsSet, final Set<TaskTypeEnum> taskTypes) {
    if (patientIdsSet.isEmpty()) {
        return Collections.emptyList();
    }//from  www  . j av  a2  s . c om
    final List<String> patientIdKeysForTaskTypes = TherapyTaskUtils.getPatientIdKeysForTaskTypes(patientIdsSet,
            taskTypes);

    final PartialList<TaskDto> tasks = processService.findTasks(assignee, null, null, false,
            searchInterval != null ? searchInterval.getStart() : null,
            searchInterval != null ? searchInterval.getEnd() : null, patientIdKeysForTaskTypes,
            EnumSet.noneOf(TaskDetailsEnum.class));

    return new ArrayList<>(Lists.transform(tasks, input -> {
        Preconditions.checkNotNull(input);
        return input.getId();
    }));
}

From source file:com.marand.thinkmed.medications.pharmacist.impl.PharmacistTaskProviderImpl.java

License:Open Source License

@Override
public List<PatientTaskDto> findPharmacistTasks(final Interval searchInterval,
        final Map<String, PatientDisplayWithLocationDto> patientIdAndPatientWithLocationMap,
        final Set<TaskTypeEnum> taskTypes) {
    final Set<String> patientIdsSet = Sets.newHashSet(patientIdAndPatientWithLocationMap.keySet());
    if (patientIdsSet.isEmpty()) {
        return Collections.emptyList();
    }/*  w  w w.j ava  2  s.  c  om*/
    final List<String> patientIdKeysForTaskTypes = TherapyTaskUtils.getPatientIdKeysForTaskTypes(patientIdsSet,
            taskTypes);

    final List<TaskDto> tasks = processService.findTasks(TherapyAssigneeEnum.PHARMACIST.name(), null, null,
            false, searchInterval != null ? searchInterval.getStart() : null,
            searchInterval != null ? searchInterval.getEnd() : null, patientIdKeysForTaskTypes,
            EnumSet.of(TaskDetailsEnum.VARIABLES));

    return buildPharmacistTasks(tasks, patientIdAndPatientWithLocationMap);
}

From source file:com.marand.thinkmed.medications.pharmacist.impl.PharmacistTaskProviderImpl.java

License:Open Source License

@Override
public List<MedicationSupplyTaskDto> findSupplyTasks(@Nullable final Interval searchInterval,
        final Map<String, PatientDisplayWithLocationDto> patientIdAndPatientWithLocationMap,
        final Set<TaskTypeEnum> taskTypes, final boolean closedTasksOnly,
        final boolean includeUnverifiedDispenseTasks, final DateTime when, final Locale locale) {
    if (patientIdAndPatientWithLocationMap.isEmpty()) {
        return Collections.emptyList();
    }/*from   ww w .j  a v  a2  s. c o m*/

    final Set<String> patientIdsSet = Sets.newHashSet(patientIdAndPatientWithLocationMap.keySet());

    final List<String> patientIdKeysForTaskTypes = TherapyTaskUtils.getPatientIdKeysForTaskTypes(patientIdsSet,
            taskTypes);
    final List<TaskDto> tasksList = processService.findTasks(TherapyAssigneeEnum.PHARMACIST.name(), //loading optimization
            closedTasksOnly ? MedsTaskDef.GROUP_NAME : null, null, closedTasksOnly,
            searchInterval != null ? searchInterval.getStart() : null,
            searchInterval != null ? searchInterval.getEnd() : null, patientIdKeysForTaskTypes,
            EnumSet.of(TaskDetailsEnum.VARIABLES));

    if (closedTasksOnly) // findTasks loaded closed, opened and deleted tasks ... we want only closed tasks
    {
        removeOpenedAndDeletedTasksFromTaskList(tasksList);
    } else {
        removeDismissedReminderTasks(tasksList);
    }
    return buildSupplyTasks(tasksList, patientIdAndPatientWithLocationMap, includeUnverifiedDispenseTasks,
            closedTasksOnly, when, locale);
}

From source file:com.marand.thinkmed.medications.pharmacist.impl.PharmacistTaskProviderImpl.java

License:Open Source License

@Override
public List<MedicationSupplyTaskSimpleDto> findSupplySimpleTasksForTherapy(
        @Nullable final Interval searchInterval, final Set<String> patientIdsSet,
        final Set<TaskTypeEnum> taskTypes, final String originalTherapyId) {
    if (patientIdsSet.isEmpty()) {
        return Collections.emptyList();
    }// w  w w .  j  ava  2  s.  co  m

    final List<String> patientIdKeysForTaskTypes = TherapyTaskUtils.getPatientIdKeysForTaskTypes(patientIdsSet,
            taskTypes);
    final List<TaskDto> tasksList = processService.findTasks(TherapyAssigneeEnum.PHARMACIST.name(), null, null,
            false, searchInterval != null ? searchInterval.getStart() : null,
            searchInterval != null ? searchInterval.getEnd() : null, patientIdKeysForTaskTypes,
            EnumSet.of(TaskDetailsEnum.VARIABLES),
            Pair.of(TherapyTaskDef.ORIGINAL_THERAPY_ID, originalTherapyId));

    return buildSupplySimpleTasks(tasksList);
}

From source file:com.marand.thinkmed.medications.pharmacist.impl.PharmacistTaskProviderImpl.java

License:Open Source License

@Override
public List<PerfusionSyringePatientTasksDto> findPerfusionSyringeTasks(
        @Nonnull final Map<String, PatientDisplayWithLocationDto> patientIdAndPatientWithLocationMap,
        final Interval searchInterval, @Nonnull final Set<TaskTypeEnum> taskTypes,
        final boolean closedTasksOnly, @Nonnull final DateTime when, @Nonnull final Locale locale) {
    Preconditions.checkNotNull(patientIdAndPatientWithLocationMap,
            "patientIdAndPatientWithLocationMap is null");
    Preconditions.checkNotNull(taskTypes, "taskTypes is null");
    Preconditions.checkNotNull(when, "when is null");
    Preconditions.checkNotNull(locale, "locale is null");
    Preconditions.checkArgument(!taskTypes.isEmpty(), "taskTypes can not be empty");

    if (patientIdAndPatientWithLocationMap.isEmpty()) {
        return Collections.emptyList();
    }/*from   ww w .  j  ava2s .c o  m*/

    final Set<String> patientIdsSet = Sets.newHashSet(patientIdAndPatientWithLocationMap.keySet());
    final List<String> patientIdKeysForTaskTypes = TherapyTaskUtils.getPatientIdKeysForTaskTypes(patientIdsSet,
            taskTypes);

    final DateTime taskDueAfter = searchInterval != null ? searchInterval.getStart() : null;
    final DateTime taskDueBefore = searchInterval != null ? searchInterval.getEnd() : null;

    final PartialList<TaskDto> tasksList = processService.findTasks(null,
            closedTasksOnly ? MedsTaskDef.GROUP_NAME : null, //loading optimization
            null, closedTasksOnly, taskDueAfter, taskDueBefore, patientIdKeysForTaskTypes,
            EnumSet.of(TaskDetailsEnum.VARIABLES));

    if (closedTasksOnly) // findTasks loaded closed, opened and deleted tasks ... we want only closed tasks
    {
        removeOpenedAndDeletedTasksFromTaskList(tasksList);
    }

    final List<PerfusionSyringePatientTasksDto> perfusionSyringePatientTasksDtos = createPerfusionSyringePatientTasksList(
            tasksList, patientIdAndPatientWithLocationMap, when, locale);

    sortPerfusionSyringePatientTasksList(perfusionSyringePatientTasksDtos);
    return perfusionSyringePatientTasksDtos;
}

From source file:com.marand.thinkmed.medications.process.impl.TherapyTaskCreatorImpl.java

License:Open Source License

private List<NewTaskRequestDto> createTasksForConstantTherapy(final long patientId,
        final MedicationInstructionInstruction instruction, final String compositionUid,
        final Interval taskCreationInterval, final TherapyDoseDto dose,
        final AdministrationTimingDto administrationTiming, final RoundsIntervalDto roundsIntervalDto,
        final boolean therapyStart, final DateTime lastTaskTimestamp, final String linkedTherapyId) {
    final DateTime therapyEnd = DataValueUtils
            .getDateTime(instruction.getOrder().get(0).getMedicationTiming().getStopDate());
    final boolean therapyEndsWithLastTask = taskCreationInterval.getEnd().equals(therapyEnd);
    final DosingFrequencyDto dosingFrequency = MedicationFromEhrConverter
            .getDosingFrequency(instruction.getOrder().get(0).getMedicationTiming());

    final List<NewTaskRequestDto> taskRequests = new ArrayList<>();

    final DateTime calculationBaseTimestamp = therapyStart ? taskCreationInterval.getStart()
            : lastTaskTimestamp;/*from w ww.  j  a  v  a 2s .c o  m*/
    if (therapyStart) {
        final NewTaskRequestDto startTaskRequest = createMedicationTaskRequest(instruction, compositionUid,
                patientId, AdministrationTypeEnum.START, taskCreationInterval.getStart(), dose);
        taskRequests.add(startTaskRequest);
    }
    if (dosingFrequency != null && dosingFrequency.getType() != DosingFrequencyTypeEnum.ONCE_THEN_EX) {
        List<HourMinuteDto> defaultAdministrationTimes = getPossibleAdministrations(administrationTiming,
                dosingFrequency.getKey());
        if (defaultAdministrationTimes == null
                && dosingFrequency.getType() == DosingFrequencyTypeEnum.DAILY_COUNT) {
            defaultAdministrationTimes = calculatePossibleAdministrationsForDailyCount(
                    dosingFrequency.getValue(), roundsIntervalDto, calculationBaseTimestamp);
        }
        final DateTime nextTime = getNextAdministrationTime(calculationBaseTimestamp,
                defaultAdministrationTimes, dosingFrequency);

        DateTime time = calculationBaseTimestamp;

        if (therapyStart && dosingFrequency.getType() != DosingFrequencyTypeEnum.BETWEEN_DOSES
                && Minutes.minutesBetween(time, nextTime).getMinutes() < 30) {
            time = getNextAdministrationTime(nextTime, defaultAdministrationTimes, dosingFrequency);
        } else {
            time = nextTime;
        }

        while (!time.isAfter(taskCreationInterval.getEnd())) {
            if (time.isAfter(taskCreationInterval.getStart())) {
                taskRequests.add(createMedicationTaskRequest(instruction, compositionUid, patientId,
                        AdministrationTypeEnum.START, time, dose));
            }
            time = getNextAdministrationTime(time, defaultAdministrationTimes, dosingFrequency);
        }
    } else if (MedicationsEhrUtils.isContinuousInfusion(instruction)) {
        if (therapyEnd != null && !therapyEnd.isAfter(taskCreationInterval.getEnd())) {
            final NewTaskRequestDto endTaskRequest = createMedicationTaskRequest(instruction, compositionUid,
                    patientId, AdministrationTypeEnum.STOP, therapyEnd, dose);
            taskRequests.add(endTaskRequest);
        }
    }

    if (therapyEndsWithLastTask) {
        final NewTaskRequestDto lastTask = taskRequests.get(taskRequests.size() - 1);
        lastTask.getVariables().add(Pair.of(MedicationTaskDef.TRIGGERS_THERAPY_ID, linkedTherapyId));
    }
    return taskRequests;
}

From source file:com.marand.thinkmed.medications.process.impl.TherapyTaskCreatorImpl.java

License:Open Source License

private List<NewTaskRequestDto> createTasksForVariableTherapy(final long patientId,
        final MedicationInstructionInstruction instruction, final String compositionUid,
        final Interval taskCreationInterval, final Map<HourMinuteDto, TherapyDoseDto> administrationTimesMap,
        final boolean therapyStart) {
    final List<NewTaskRequestDto> taskRequests = new ArrayList<>();

    Pair<DateTime, TherapyDoseDto> timeWithDose = getNextAdministrationTimeWithDose(
            therapyStart ? taskCreationInterval.getStart().minusMinutes(30) : taskCreationInterval.getStart(),
            administrationTimesMap);/*from  w w w. ja va 2s .co m*/
    if (therapyStart) {
        final NewTaskRequestDto startTaskRequest = createMedicationTaskRequest(instruction, compositionUid,
                patientId, AdministrationTypeEnum.START, taskCreationInterval.getStart(),
                timeWithDose.getSecond());
        taskRequests.add(startTaskRequest);
        if (Minutes.minutesBetween(taskCreationInterval.getStart(), timeWithDose.getFirst())
                .getMinutes() < 30) {
            timeWithDose = getNextAdministrationTimeWithDose(taskCreationInterval.getStart(),
                    administrationTimesMap);
        }
    }
    final boolean isContinuousInfusion = MedicationsEhrUtils.isContinuousInfusion(instruction);
    if (therapyStart || !isContinuousInfusion) //don't create tasks on review if continuous infusion
    {
        while (!timeWithDose.getFirst().isAfter(taskCreationInterval.getEnd())) {
            if (timeWithDose.getFirst().isAfter(taskCreationInterval.getStart())) {
                final NewTaskRequestDto medicationTaskRequest = createMedicationTaskRequest(instruction,
                        compositionUid, patientId,
                        isContinuousInfusion ? AdministrationTypeEnum.ADJUST_INFUSION
                                : AdministrationTypeEnum.START,
                        timeWithDose.getFirst(), timeWithDose.getSecond());
                taskRequests.add(medicationTaskRequest);
            }
            timeWithDose = getNextAdministrationTimeWithDose(timeWithDose.getFirst(), administrationTimesMap);

            if (MedicationsEhrUtils.isContinuousInfusion(instruction) && !timeWithDose.getFirst()
                    .withTimeAtStartOfDay().equals(taskCreationInterval.getStart().withTimeAtStartOfDay())) {
                break;
            }
        }
    }

    if (MedicationsEhrUtils.isContinuousInfusion(instruction)) {
        final DateTime therapyEnd = DataValueUtils
                .getDateTime(instruction.getOrder().get(0).getMedicationTiming().getStopDate());
        if (therapyEnd != null && !therapyEnd.isAfter(taskCreationInterval.getEnd())) {
            final NewTaskRequestDto endTaskRequest = createMedicationTaskRequest(instruction, compositionUid,
                    patientId, AdministrationTypeEnum.STOP, therapyEnd, timeWithDose.getSecond());
            taskRequests.add(endTaskRequest);
        }
    }
    return taskRequests;
}

From source file:com.marand.thinkmed.medications.process.impl.TherapyTaskProviderImpl.java

License:Open Source License

@Override
public List<TherapyTaskDto> findTherapyTasks(final Long patientId, final String therapyId,
        final Interval searchInterval) {
    final List<Pair<TaskVariable, Object>> taskVariables = new ArrayList<>();
    if (patientId != null) {
        taskVariables.add(Pair.<TaskVariable, Object>of(MedicationTaskDef.PATIENT_ID, patientId));
    }/*from w  w  w  . ja v  a2s .c  o m*/
    if (therapyId != null) {
        taskVariables.add(Pair.<TaskVariable, Object>of(MedicationTaskDef.THERAPY_ID, therapyId));
    }
    final List<TaskDto> allTasks = processService.findTasks(null, null, null, true,
            searchInterval != null ? searchInterval.getStart() : null,
            searchInterval != null ? searchInterval.getEnd() : null,
            taskVariables.toArray(new Pair[taskVariables.size()]));

    final List<TherapyTaskDto> therapyTasks = new ArrayList<>();
    for (final TaskDto task : allTasks) {
        if (task.getCompletedType() != TaskCompletedType.DELETED) {
            final TherapyTaskDto therapyTaskDto = new TherapyTaskDto();
            therapyTaskDto.setTaskId(task.getId());
            therapyTaskDto
                    .setTherapyId((String) task.getVariables().get(MedicationTaskDef.THERAPY_ID.getName()));
            therapyTaskDto.setPlannedAdministrationTime(task.getDueTime());
            therapyTaskDto.setAdministrationTypeEnum(AdministrationTypeEnum.valueOf(
                    (String) task.getVariables().get(MedicationTaskDef.ADMINISTRATION_TYPE.getName())));
            therapyTaskDto.setAdministrationId(
                    (String) task.getVariables().get(MedicationTaskDef.THERAPY_ADMINISTRATION_ID.getName()));
            therapyTaskDto.setTriggersTherapyId(
                    (String) task.getVariables().get(MedicationTaskDef.TRIGGERS_THERAPY_ID.getName()));
            if (therapyTaskDto.getAdministrationTypeEnum() != AdministrationTypeEnum.STOP) {
                final TherapyDoseDto therapyDoseDto = TherapyTaskUtils.buildTherapyDoseDtoFromTask(task);
                therapyTaskDto.setTherapyDoseDto(therapyDoseDto);
            }
            therapyTasks.add(therapyTaskDto);
        }
    }
    return therapyTasks;
}

From source file:com.marand.thinkmed.medications.task.impl.MedicationsTasksProviderImpl.java

License:Open Source License

@Override
public List<AdministrationTaskDto> findAdministrationTasks(final String patientId,
        final Collection<String> therapyIds, final Interval searchInterval, final boolean findHistoric) {
    if (therapyIds.isEmpty()) {
        return new ArrayList<>();
    }/*from w  w w.j  av a  2  s .c o m*/
    final List<TaskDto> tasks = findAdministrationTasks(
            Collections.singletonList(AdministrationTaskDef.getTaskTypeEnum().buildKey(patientId)), therapyIds,
            searchInterval != null ? searchInterval.getStart() : null,
            searchInterval != null ? searchInterval.getEnd() : null, null, findHistoric);

    return tasks.stream().map(task -> administrationTaskConverter.convertTaskToAdministrationTask(task))
            .collect(Collectors.toList());
}