List of usage examples for org.joda.time DateTime withTimeAtStartOfDay
public DateTime withTimeAtStartOfDay()
From source file:com.marand.thinkmed.medications.administration.impl.AdministrationTaskCreatorImpl.java
License:Open Source License
private boolean isInValidDaysOfWeek(final DateTime when, final List<String> daysOfWeek) { if (daysOfWeek == null || daysOfWeek.size() == 7 || daysOfWeek.isEmpty()) { return true; }/*from w ww .j a v a 2 s . c om*/ final DayOfWeek dayOfWeekEnum = MedicationsEhrUtils.dayOfWeekToEhrEnum(when.withTimeAtStartOfDay()); return daysOfWeek.stream().map(DayOfWeek::valueOf).anyMatch(Predicate.isEqual(dayOfWeekEnum)); }
From source file:com.marand.thinkmed.medications.administration.impl.AdministrationTaskCreatorImpl.java
License:Open Source License
private boolean isInValidDaysFrequency(final DateTime start, final DateTime when, final Integer daysFrequency) { return daysFrequency == null || Days.daysBetween(start.withTimeAtStartOfDay(), when.withTimeAtStartOfDay()).getDays() % daysFrequency == 0; }
From source file:com.marand.thinkmed.medications.administration.impl.AdministrationTaskCreatorImpl.java
License:Open Source License
private Pair<DateTime, TherapyDoseDto> getNextAdministrationTimeWithDoseForFrequencyBetweenDoses( final AdministrationTaskCreateActionEnum action, final DateTime therapyStart, final DateTime fromTime, final HourMinuteDto administrationTime, final TherapyDoseDto dose, final int hoursBetweenDoses, final boolean fromTimeIncluded) { DateTime foundTime;//from ww w . j a va 2s .c o m if (action == AdministrationTaskCreateActionEnum.PRESET_TIME_ON_NEW_PRESCRIPTION) { foundTime = fromTime.withTimeAtStartOfDay().plusHours(administrationTime.getHour()) .plusMinutes(administrationTime.getMinute()); if (hoursBetweenDoses >= 24) { while (foundTime.isBefore(fromTime) || (foundTime.equals(fromTime) && !fromTimeIncluded)) { foundTime = foundTime.plusDays(1); } return Pair.of(foundTime, dose); } } else { foundTime = therapyStart; } while (foundTime.isBefore(fromTime) || (foundTime.equals(fromTime) && !fromTimeIncluded)) { foundTime = foundTime.plusHours(hoursBetweenDoses); } return Pair.of(foundTime, dose); }
From source file:com.marand.thinkmed.medications.business.impl.DefaultMedicationsBo.java
License:Open Source License
@Override public int getTherapyConsecutiveDay(final DateTime therapyStart, final DateTime therapyDay, final DateTime currentTime, final Integer pastDaysOfTherapy) { final int pastDays = pastDaysOfTherapy != null ? pastDaysOfTherapy : 0; //today/*from w w w . jav a2 s . co m*/ if (DateUtils.isSameDay(therapyDay.toDate(), currentTime.toDate())) { return Days.daysBetween(therapyStart, currentTime).getDays() + pastDays; } return Days.daysBetween(therapyStart.withTimeAtStartOfDay(), therapyDay.withTimeAtStartOfDay()).getDays() + pastDays; }
From source file:com.marand.thinkmed.medications.business.impl.DefaultMedicationsBo.java
License:Open Source License
@Override public boolean isTherapyActive(final List<String> daysOfWeek, final Integer dosingDaysFrequency, final Interval therapyInterval, final DateTime when) { if (therapyInterval.overlap(Intervals.wholeDay(when)) == null) { return false; }/*from ww w .j ava 2 s .c om*/ if (daysOfWeek != null) { boolean activeDay = false; final String searchDay = MedicationsEhrUtils.dayOfWeekToEhrEnum(when).name(); for (final String day : daysOfWeek) { if (day.equals(searchDay)) { activeDay = true; } } if (!activeDay) { return false; } } if (dosingDaysFrequency != null) { final int daysFromStart = Days .daysBetween(therapyInterval.getStart().withTimeAtStartOfDay(), when.withTimeAtStartOfDay()) .getDays(); if (daysFromStart % dosingDaysFrequency != 0) { return false; } } return true; }
From source file:com.marand.thinkmed.medications.dto.report.TherapyDayReportUtils.java
License:Open Source License
public static String getTherapyApplicationColumnValue(List<AdministrationDto> therapyAdministrations, @Nonnull final TherapyDto order, @Nonnull final Date startDate, final int column, @Nonnull Locale locale) { final DateTime day = new DateTime(startDate).plusDays(column).withTimeAtStartOfDay(); final StringBuilder administrationString = new StringBuilder(); if (therapyAdministrations != null) { Collections.sort(therapyAdministrations, Comparator.comparing(AdministrationDto::getAdministrationTime)); for (final AdministrationDto administration : therapyAdministrations) { final DateTime administrationTime = administration.getAdministrationTime(); if (administrationTime != null && administrationTime.withTimeAtStartOfDay().isEqual(day)) { final StringBuilder dose = new StringBuilder(); if (administration.getAdministrationResult() == AdministrationResultEnum.DEFER) { dose.append(StringUtils.capitalize(getDictionaryEntry("administration.defer", locale))); if (administration.getNotAdministeredReason() != null && administration.getNotAdministeredReason().getName() != null) { dose.append(" - ").append(administration.getNotAdministeredReason().getName()); }/* w ww . j a va 2s .c om*/ } else if (administration.getAdministrationResult() == AdministrationResultEnum.NOT_GIVEN) { dose.append(StringUtils.capitalize(getDictionaryEntry("administration.not.given", locale))); if (administration.getNotAdministeredReason() != null && administration.getNotAdministeredReason().getName() != null) { dose.append(" - ").append(administration.getNotAdministeredReason().getName()); } } else { if (administration instanceof StartAdministrationDto) { final TherapyDoseDto administeredDose = ((StartAdministrationDto) administration) .getAdministeredDose(); if (administeredDose != null && administeredDose.getNumerator() != null && administeredDose.getNumeratorUnit() != null) { try { dose.append(NumberFormatters.doubleFormatter2(locale) .valueToString(administeredDose.getNumerator()) + " " + administeredDose.getNumeratorUnit()); } catch (final ParseException e) { e.printStackTrace(); } } } else if (administration instanceof AdjustInfusionAdministrationDto) { final TherapyDoseDto administeredDose = ((AdjustInfusionAdministrationDto) administration) .getAdministeredDose(); if (administeredDose.getNumerator() != null && administeredDose.getNumeratorUnit() != null) { try { dose.append(NumberFormatters.doubleFormatter2(locale) .valueToString(administeredDose.getNumerator()) + " " + administeredDose.getNumeratorUnit()); } catch (ParseException e) { e.printStackTrace(); } } } else if (administration instanceof InfusionSetChangeDto) { //noinspection SwitchStatement switch (((InfusionSetChangeDto) administration).getInfusionSetChangeEnum()) { case INFUSION_SYRINGE_CHANGE: dose.append(getDictionaryEntry("infusion.syringe.change", locale)); break; case INFUSION_SYSTEM_CHANGE: dose.append(getDictionaryEntry("infusion.system.change", locale)); break; } } else if (administration instanceof StopAdministrationDto) { dose.append(getDictionaryEntry("infusion.stopped", locale)); } } if (administration.getComment() != null) { dose.append(" - ").append(administration.getComment()); } administrationString.append(String.format("<b>%02d:%02d<br></b>%s<br><br>", administrationTime.getHourOfDay(), administrationTime.getMinuteOfHour(), dose)); } } } return administrationString.toString(); }
From source file:com.marand.thinkmed.medications.process.impl.TherapyTaskCreatorImpl.java
License:Open Source License
private DateTime getAdministrationTasksIntervalEnd(final DateTime start, final DateTime end, final RoundsIntervalDto roundsInterval) { final DateTime startOfTodaysRounds = start.withTimeAtStartOfDay().plusHours(roundsInterval.getStartHour()) .plusMinutes(roundsInterval.getStartMinute()); DateTime endTimestamp = start.withTimeAtStartOfDay().plusHours(roundsInterval.getEndHour()) .plusMinutes(roundsInterval.getEndMinute()); if (start.isAfter(startOfTodaysRounds) || start.equals(startOfTodaysRounds)) { endTimestamp = endTimestamp.plusDays(1); }/*from w ww . ja v a 2 s . c o m*/ boolean workingDay = mafDateRuleService.isDateOfType(endTimestamp.withTimeAtStartOfDay(), DayType.WORKING_DAY); while (!workingDay) { endTimestamp = endTimestamp.plusDays(1); workingDay = mafDateRuleService.isDateOfType(endTimestamp.withTimeAtStartOfDay(), DayType.WORKING_DAY); } if (end != null && endTimestamp.isAfter(end)) { endTimestamp = end; } return endTimestamp; }
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. c o 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.process.impl.TherapyTaskCreatorImpl.java
License:Open Source License
private boolean isInValidDaysOfWeek(final DateTime dateTime, final TimingCluster timing) { if (timing == null || timing.getDayOfWeek().size() == 7 || timing.getDayOfWeek().isEmpty()) { return true; }//from w ww . ja v a2s . c o m final DayOfWeek dayOfWeekEnum = MedicationsEhrUtils.dayOfWeekToEhrEnum(dateTime.withTimeAtStartOfDay()); for (final DvCodedText validDay : timing.getDayOfWeek()) { final DayOfWeek validDayEnum = DataValueUtils.getTerminologyEnum(DayOfWeek.class, validDay); if (dayOfWeekEnum == validDayEnum) { return true; } } return false; }
From source file:com.marand.thinkmed.medications.service.impl.MedicationsServiceImpl.java
License:Open Source License
@Override @EhrSessioned/* w ww .j av a 2 s . c o m*/ @Transactional(readOnly = true) @ServiceMethod(auditing = @Auditing(level = Level.FULL)) //for emram, refactor public List<TherapyRowDto> getTherapiesForCurrentCentralCase(@Nonnull final String patientId, @Nonnull final Locale locale) { final DateTime when = RequestContextHolder.getContext().getRequestTimestamp(); final PatientDataForMedicationsDto patientData = medicationsConnector.getPatientData(patientId, when); final MedicationsCentralCaseDto centralCaseDto = patientData.getCentralCaseDto(); if (centralCaseDto == null) { return Collections.emptyList(); } final DateTime fromWhen = centralCaseDto.isOutpatient() ? when.withTimeAtStartOfDay() : centralCaseDto.getCentralCaseEffective().getStart(); final List<Pair<MedicationOrderComposition, MedicationInstructionInstruction>> instructionPairs = medicationsOpenEhrDao .findMedicationInstructions(patientId, Intervals.infiniteFrom(fromWhen), null); return overviewContentProvider.buildTherapyRows(patientId, instructionPairs, Collections.emptyList(), Collections.emptyList(), TherapySortTypeEnum.CREATED_TIME_DESC, false, Collections.emptyList(), null, Intervals.infiniteFrom(fromWhen), null, locale, when); }