List of usage examples for org.joda.time Interval Interval
public Interval(Object interval, Chronology chronology)
From source file:com.marand.thinkmed.medications.pharmacist.impl.PharmacistTaskHandlerImpl.java
License:Open Source License
private PrescriptionChangeTypeEnum getPharmacistTherapyChangeType(final String patientId, final DateTime hospitalizationStart, final DateTime when) { if (hospitalizationStart == null) { return PrescriptionChangeTypeEnum.NEW_ADMISSION_PRESCRIPTION; }// w w w.j a v a 2s. co m return medicationsOpenEhrDao .findMedicationInstructions(patientId, new Interval(hospitalizationStart, Days.THREE), null) .stream().filter(Objects::nonNull).findFirst().map(Pair::getFirst) .map(c -> new Interval(DataValueUtils.getDateTime(c.getCompositionEventContext().getStartTime()), Hours.ONE)) .map(interval -> interval.contains(when) ? PrescriptionChangeTypeEnum.NEW_ADMISSION_PRESCRIPTION : PrescriptionChangeTypeEnum.ADDITION_TO_EXISTING_PRESCRIPTION) .orElse(PrescriptionChangeTypeEnum.NEW_ADMISSION_PRESCRIPTION); }
From source file:com.marand.thinkmed.medications.process.impl.TherapyTaskCreatorImpl.java
License:Open Source License
private List<Interval> removeInactiveTherapyDaysFromTasksInterval(final DateTime start, final DateTime end, final RoundsIntervalDto roundsInterval, final TimingCluster timing) { final List<Interval> intervals = new ArrayList<>(); DateTime tasksStart = new DateTime(start); final DateTime startOfTodaysRounds = start.withTimeAtStartOfDay().plusHours(roundsInterval.getStartHour()) .plusMinutes(roundsInterval.getStartMinute()); DateTime tasksEnd = start.withTimeAtStartOfDay().plusHours(roundsInterval.getEndHour()) .plusMinutes(roundsInterval.getEndMinute()); if (start.isAfter(startOfTodaysRounds) && tasksEnd.isBefore(end)) { if (tasksEnd.plusDays(1).isAfter(end)) { tasksEnd = end;/*w ww . java 2 s. co m*/ } else { tasksEnd = tasksEnd.plusDays(1); } } int daysFrequency = 1; if (timing != null && timing.getInterval() != null) { final int days = DataValueUtils.getPeriod(timing.getInterval()).getDays(); if (days > 0) { daysFrequency = days; } } boolean previousDayWasValid = isInValidDaysOfWeek(tasksStart, timing); if (!previousDayWasValid) { tasksStart = startOfTodaysRounds.plusDays(1); } int dayIndex = 1; while (tasksEnd.isBefore(end) || tasksEnd.equals(end)) { final boolean validDayOfWeek = isInValidDaysOfWeek(tasksEnd, timing); final boolean validFrequency = dayIndex % daysFrequency == 0; if (validDayOfWeek && validFrequency) { previousDayWasValid = true; } else { final DateTime startOfRounds = tasksEnd.withTimeAtStartOfDay() .plusHours(roundsInterval.getStartHour()).plusMinutes(roundsInterval.getStartMinute()); if (previousDayWasValid) { intervals.add(new Interval(tasksStart, startOfRounds)); } previousDayWasValid = false; tasksStart = startOfRounds.plusDays(1); } tasksEnd = tasksEnd.plusDays(1); dayIndex++; } if (previousDayWasValid && dayIndex > 1 || tasksEnd.minusDays(1).isBefore(end)) { if (!tasksStart.isAfter(end)) { intervals.add(new Interval(tasksStart, end)); } } return intervals; }
From source file:com.marand.thinkmed.medications.service.impl.MedicationsServiceImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)//from w w w . j a va 2 s. c o m @ServiceMethod(auditing = @Auditing(level = Level.FULL)) @EhrSessioned public TherapyViewPatientDto getTherapyViewPatientData(@Nonnull final String patientId) { StringUtils.checkNotBlank(patientId, "patientId required"); final DateTime requestTimestamp = RequestContextHolder.getContext().getRequestTimestamp(); final TherapyViewPatientDto therapyViewPatientDto = new TherapyViewPatientDto(); final PatientDataForMedicationsDto patientData = patientDataProvider.getPatientData(patientId, requestTimestamp); therapyViewPatientDto.setPatientData(patientData); final MedicationsCentralCaseDto centralCaseDto = patientData.getCentralCaseDto(); final String careProviderId = centralCaseDto != null && centralCaseDto.getCareProvider() != null ? centralCaseDto.getCareProvider().getId() : null; final boolean inpatient = centralCaseDto != null && !centralCaseDto.isOutpatient(); final Interval referenceWeightSearchInterval; if (inpatient) { referenceWeightSearchInterval = new Interval(centralCaseDto.getCentralCaseEffective().getStart(), requestTimestamp); final Interval recentHospitalizationInterval = new Interval(requestTimestamp.minusHours(12), requestTimestamp); therapyViewPatientDto.setRecentHospitalization( recentHospitalizationInterval.contains(centralCaseDto.getCentralCaseEffective().getStart())); } else { referenceWeightSearchInterval = new Interval(requestTimestamp.minusHours(24), requestTimestamp); } final Double referenceWeight = medicationsOpenEhrDao.getPatientLastReferenceWeight(patientId, referenceWeightSearchInterval); therapyViewPatientDto.setReferenceWeight(referenceWeight); if (careProviderId != null) { final List<String> customGroups = medicationsDao.getCustomGroupNames(careProviderId); therapyViewPatientDto.setCustomGroups(customGroups); } final AdministrationTimingDto administrationTiming = MedicationPreferencesUtil .getAdministrationTiming(careProviderId); therapyViewPatientDto.setAdministrationTiming(administrationTiming); final RoundsIntervalDto roundsInterval = MedicationPreferencesUtil.getRoundsInterval(careProviderId); therapyViewPatientDto.setRoundsInterval(roundsInterval); final Long patientIdLong = MedicationsConnectorUtils.getId(patientId); if (patientIdLong != null) { final String lastLinkName = medicationsDao.getPatientLastLinkName(patientIdLong); therapyViewPatientDto.setLastLinkName(lastLinkName); } return therapyViewPatientDto; }
From source file:com.marand.thinkmed.medications.service.impl.MedicationsServiceImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)/*ww w. j a va2 s . c o m*/ @ServiceMethod(auditing = @Auditing(level = Level.FULL)) @EhrSessioned public List<TherapyDto> getLastTherapiesForPreviousHospitalization(final String patientId, final Double patientHeight, final Locale locale) { final DateTime when = RequestContextHolder.getContext().getRequestTimestamp(); final Interval lastDischargedCentralCaseInterval = medicationsConnector .getLastDischargedCentralCaseEffectiveInterval(patientId); if (lastDischargedCentralCaseInterval != null) { final Interval lastDayBeforeDischarge = new Interval( lastDischargedCentralCaseInterval.getEnd().minusHours(24), lastDischargedCentralCaseInterval.getEnd().plusMinutes(1)); final Interval referenceWeightInterval = Intervals.infiniteTo(when); final Double referenceWeight = medicationsOpenEhrDao.getPatientLastReferenceWeight(patientId, referenceWeightInterval); //?? //final Double height = patientDataForMedicationsProvider.getPatientLastHeight(patientId, new Interval(Intervals.INFINITE.getStart(), when)); final List<TherapyDto> therapies = medicationsBo.getTherapies(patientId, lastDayBeforeDischarge, null, patientHeight, null, when); fillDisplayValuesAndInfusionRateForTherapies(patientHeight, locale, referenceWeight, therapies); return therapies; } return new ArrayList<>(); }
From source file:com.marand.thinkmed.medications.service.impl.MedicationsServiceImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)/*from www . j a v a 2s .c o m*/ @ServiceMethod(auditing = @Auditing(level = Level.WITHOUT_OUTPUT_RESULTS)) @EhrSessioned public List<MedicationOnDischargeGroupDto> getTherapiesOnDischargeGroups(final String patientId, final Double patientHeight, @Nullable final DateTime saveDateTime, final DateTime lastHospitalizationStart, final boolean hospitalizationActive, @Nullable final Locale locale) { Preconditions.checkNotNull(patientId, "patientId must not be null"); Preconditions.checkNotNull(lastHospitalizationStart, "lastHospitalizationStart must not be null"); final DateTime when = saveDateTime == null ? RequestContextHolder.getContext().getRequestTimestamp() : saveDateTime; final Interval referenceWeightInterval = Intervals.infiniteTo(when); if (hospitalizationActive) { final Interval searchInterval = Intervals.infiniteFrom(when); final Double referenceWeight = medicationsOpenEhrDao.getPatientLastReferenceWeight(patientId, referenceWeightInterval); return medicationsBo.getMedicationOnDischargeGroups(patientId, lastHospitalizationStart, searchInterval, referenceWeight, patientHeight, locale, when); } else { final Interval lastDischargedCentralCaseInterval = medicationsConnector .getLastDischargedCentralCaseEffectiveInterval(patientId); final Interval lastHourBeforeDischarge = lastDischargedCentralCaseInterval == null ? null : new Interval(lastDischargedCentralCaseInterval.getEnd().minusHours(1), lastDischargedCentralCaseInterval.getEnd().plusMinutes(1)); final Double referenceWeight = medicationsOpenEhrDao.getPatientLastReferenceWeight(patientId, referenceWeightInterval); return medicationsBo.getMedicationOnDischargeGroups(patientId, lastHospitalizationStart, lastHourBeforeDischarge, referenceWeight, patientHeight, locale, when); } }
From source file:com.marand.thinkmed.medications.service.impl.MedicationsServiceImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)//from w w w . j a v a 2s . c o m @ServiceMethod(auditing = @Auditing(level = Level.FULL)) @EhrSessioned public List<AdministrationPatientTaskDto> getAdministrationTasks(final Opt<Collection<String>> careProviderIds, final Opt<Collection<String>> patientIds, @Nonnull final Locale locale) { Preconditions.checkNotNull(locale, "locale is required"); final Map<String, PatientDisplayWithLocationDto> patientIdAndPatientWithLocationMap = getPatientDisplayWithLocationDtoMap( careProviderIds, patientIds); final AdministrationPatientTaskLimitsDto administrationLimits = MedicationPreferencesUtil .getAdministrationPatientTaskLimitsPreference(); final DateTime when = RequestContextHolder.getContext().getRequestTimestamp(); final Interval searchInterval = new Interval(when.minusMinutes(administrationLimits.getDueTaskOffset()), when.plusMinutes(administrationLimits.getFutureTaskOffset())); return medicationsTasksProvider.findAdministrationTasks(patientIdAndPatientWithLocationMap, searchInterval, administrationLimits.getMaxNumberOfTasks(), locale, when); }
From source file:com.marand.thinkmed.medications.service.impl.MedicationsServiceImpl.java
License:Open Source License
@Override @Transactional//from w ww . j a v a 2 s . c om @ServiceMethod(auditing = @Auditing(level = Level.FULL)) public boolean finishedPerfusionSyringeRequestsExistInLastHours(@Nonnull final String patientId, @Nonnull final String originalTherapyId, final int hours) { Preconditions.checkNotNull(patientId, "patientId is null"); Preconditions.checkNotNull(originalTherapyId, "originalTherapyId is null"); final DateTime requestTimestamp = RequestContextHolder.getContext().getRequestTimestamp(); return pharmacistTaskProvider.therapyHasTasksClosedInInterval(patientId, originalTherapyId, Collections.singleton(TaskTypeEnum.PERFUSION_SYRINGE_DISPENSE), new Interval(requestTimestamp.minusHours(hours), requestTimestamp)); }
From source file:com.metamx.common.Granularity.java
License:Apache License
/** * Return a granularity-sized Interval containing a particular DateTime. */// www. j a va 2s. co m public final Interval bucket(DateTime t) { DateTime start = truncate(t); return new Interval(start, increment(start)); }
From source file:com.metamx.common.Granularity.java
License:Apache License
/** * Round out Interval such that it becomes granularity-aligned and nonempty. *//* w ww . ja v a 2 s .c o m*/ public final Interval widen(Interval interval) { final DateTime start = truncate(interval.getStart()); final DateTime end; if (interval.getEnd().equals(start)) { // Empty with aligned start/end; expand into a granularity-sized interval end = increment(start); } else if (truncate(interval.getEnd()).equals(interval.getEnd())) { // Non-empty with aligned end; keep the same end end = interval.getEnd(); } else { // Non-empty with non-aligned end; push it out end = increment(truncate(interval.getEnd())); } return new Interval(start, end); }
From source file:com.metamx.common.Granularity.java
License:Apache License
public Iterable<Interval> getIterable(final DateTime start, final DateTime end) { return getIterable(new Interval(start, end)); }