List of usage examples for org.joda.time Interval getStart
public DateTime getStart()
From source file:com.marand.thinkmed.medications.business.impl.DefaultMedicationsBo.java
License:Open Source License
@Override public List<TherapySurgeryReportElementDto> getTherapySurgeryReportElements(@Nonnull final String patientId, final Double patientHeight, @Nonnull final DateTime searchStart, @Nonnull final RoundsIntervalDto roundsIntervalDto, @Nonnull final Locale locale, @Nonnull final DateTime when) { Preconditions.checkNotNull(patientId, "patientId"); Preconditions.checkNotNull(searchStart, "searchStart"); Preconditions.checkNotNull(roundsIntervalDto, "roundsIntervalDto"); Preconditions.checkNotNull(locale, "locale"); Preconditions.checkNotNull(when, "when"); final DateTime roundsStart = new DateTime(searchStart.getYear(), searchStart.getMonthOfYear(), searchStart.getDayOfMonth(), roundsIntervalDto.getStartHour(), roundsIntervalDto.getStartMinute()); final List<Pair<MedicationOrderComposition, MedicationInstructionInstruction>> instructionsList = medicationsOpenEhrDao .findMedicationInstructions(patientId, Intervals.infiniteFrom(roundsStart), null); final Double referenceWeight = medicationsOpenEhrDao.getPatientLastReferenceWeight(patientId, Intervals.infiniteTo(searchStart)); final List<TherapySurgeryReportElementDto> elements = new ArrayList<>(); final Map<Long, MedicationDataForTherapyDto> medicationsMap = getMedicationDataForTherapies( instructionsList, null);// w w w .ja v a2 s. c o m for (final Pair<MedicationOrderComposition, MedicationInstructionInstruction> instructionPair : instructionsList) { final MedicationOrderComposition composition = instructionPair.getFirst(); final MedicationInstructionInstruction instruction = instructionPair.getSecond(); final MedicationTimingCluster medicationTiming = instruction.getOrder().get(0).getMedicationTiming(); final Interval instructionInterval = MedicationsEhrUtils.getInstructionInterval(medicationTiming); final boolean onlyOnce = isOnlyOnceThenEx(medicationTiming); if (instructionInterval.overlaps(Intervals.infiniteFrom(searchStart)) || onlyOnce && instructionInterval.getStart().isAfter(searchStart.minusHours(1))) { final List<MedicationActionAction> actions = MedicationsEhrUtils.getInstructionActions(composition, instruction); if (!isTherapyCanceledAbortedOrSuspended(actions)) { final TherapyDto therapy = getTherapyFromMedicationInstruction(composition, instruction, referenceWeight, patientHeight, when); therapyDisplayProvider.fillDisplayValues(therapy, false, true, false, locale, true); final boolean containsAntibiotics = getMedicationIds( MedicationsEhrUtils.getRepresentingOrderActivity(instruction)).stream().anyMatch( id -> medicationsMap.containsKey(id) && medicationsMap.get(id).isAntibiotic()); if (containsAntibiotics) { final int consecutiveDays = getTherapyConsecutiveDay( getOriginalTherapyStart(patientId, composition), when, when, therapy.getPastDaysOfTherapy()); elements.add(new TherapySurgeryReportElementDto(therapy.getFormattedTherapyDisplay(), consecutiveDays)); } else { elements.add(new TherapySurgeryReportElementDto(therapy.getFormattedTherapyDisplay())); } } } } return elements; }
From source file:com.marand.thinkmed.medications.business.impl.DefaultMedicationsBo.java
License:Open Source License
DocumentationTherapiesDto getTherapiesForDocumentation(final String patientId, final String centralCaseId, final Interval centralCaseEffective, final List<Pair<MedicationOrderComposition, MedicationInstructionInstruction>> instructionPairs, final Map<Long, MedicationDataForTherapyDto> medicationsDataMap, final boolean isOutpatient, final DateTime when, final Locale locale) { final List<TherapyDocumentationData> therapies = new ArrayList<>(); final List<TherapyDocumentationData> dischargeTherapies = new ArrayList<>(); final List<TherapyDocumentationData> admissionTherapies = new ArrayList<>(); final List<TherapyDto> taggedTherapiesForPrescription = new ArrayList<>(); if (!isOutpatient) { //use taggedTherapiesForPrescription to display medication on discharge list for EMRAM final List<MedicationOnDischargeComposition> dischargeCompositions = medicationsOpenEhrDao .findMedicationOnDischargeCompositions(patientId, centralCaseEffective); for (final MedicationOnDischargeComposition dischargeComposition : dischargeCompositions) { final TherapyDto convertedTherapy = convertInstructionToTherapyDtoWithDisplayValues( dischargeComposition, dischargeComposition.getMedicationDetail().getMedicationInstruction().get(0), null, null, when, true, locale); taggedTherapiesForPrescription.add(convertedTherapy); }//from w ww. j ava2s. co m } final Set<TherapyDocumentationData> alreadyHandled = new HashSet<>(); final boolean isOutpatientOrLastsOneDay = isOutpatient || Intervals.durationInDays(centralCaseEffective) <= 1; for (final Pair<MedicationOrderComposition, MedicationInstructionInstruction> instructionPair : instructionPairs) { final DateTime therapyStart = DataValueUtils.getDateTime( instructionPair.getSecond().getOrder().get(0).getMedicationTiming().getStartDate()); final DateTime therapyEnd = DataValueUtils .getDateTime(instructionPair.getSecond().getOrder().get(0).getMedicationTiming().getStopDate()); final TherapyDto convertedTherapy = convertInstructionToTherapyDtoWithDisplayValues( instructionPair.getFirst(), instructionPair.getSecond(), null, null, when, true, locale); if (!areAllIngredientsSolutions(convertedTherapy)) { final Interval therapyInterval = new Interval(therapyStart, therapyEnd != null ? therapyEnd : Intervals.INFINITE.getEnd()); final boolean handled = handleSimilarAndLinkedTherapies(admissionTherapies, dischargeTherapies, therapies, alreadyHandled, instructionPair, convertedTherapy, medicationsDataMap, therapyInterval, centralCaseEffective.getEnd(), when); final TherapyDocumentationData therapy = createTherapyData(instructionPair, convertedTherapy, therapyInterval); alreadyHandled.add(therapy); if (!handled) { if (isOutpatientOrLastsOneDay) { if (therapyInterval.overlaps(Intervals.wholeDay(centralCaseEffective.getStart()))) { therapies.add(therapy); } } else { boolean isAdmission = false; if (therapyInterval.overlaps(Intervals.wholeDay(centralCaseEffective.getStart()))) { admissionTherapies.add(therapy); isAdmission = true; } boolean isDischarge = false; if (isDischargeTherapy(therapyInterval, centralCaseEffective.getEnd(), when)) { dischargeTherapies.add(therapy); isDischarge = true; } if (!isAdmission && !isDischarge) { if (therapyInterval.overlaps(centralCaseEffective)) { therapies.add(therapy); } } } } } } return new DocumentationTherapiesDto(getTherapyDisplayValuesForDocumentation(therapies, locale), getTherapyDisplayValuesForDocumentation(dischargeTherapies, locale), getTherapyDisplayValuesForDocumentation(admissionTherapies, locale), getTherapyDisplayValues(taggedTherapiesForPrescription, locale)); }
From source file:com.marand.thinkmed.medications.business.impl.DefaultMedicationsBo.java
License:Open Source License
private boolean handleSimilarAndLinkedTherapies(final List<TherapyDocumentationData> admissionTherapies, final List<TherapyDocumentationData> dischargeTherapies, final List<TherapyDocumentationData> therapies, final Set<TherapyDocumentationData> alreadyHandled, final Pair<MedicationOrderComposition, MedicationInstructionInstruction> therapyToCompare, final TherapyDto convertedTherapy, final Map<Long, MedicationDataForTherapyDto> medicationsDataMap, final Interval therapyInterval, final DateTime centralCaseEnd, final DateTime when) { final Pair<TherapyLinkType, TherapyDocumentationData> pair = getLinkedToTherapyPair(admissionTherapies, therapies, therapyToCompare); if (pair.getFirst() == TherapyLinkType.REGULAR_LINK) { final TherapyDocumentationData linkedToTherapy = pair.getSecond(); final Interval interval = linkedToTherapy.findIntervalForId( TherapyIdUtils.createTherapyId(linkedToTherapy.getTherapy().getCompositionUid(), linkedToTherapy.getTherapy().getEhrOrderName())); if (isDischargeTherapy(therapyInterval, centralCaseEnd, when)) { if (therapies.contains(linkedToTherapy)) { therapies.remove(linkedToTherapy); }/* ww w.j a va 2s . co m*/ if (admissionTherapies.contains(linkedToTherapy)) { admissionTherapies.remove(linkedToTherapy); } final TherapyDocumentationData dischargeTherapy = createTherapyData(therapyToCompare, convertedTherapy, new Interval(interval.getStart(), therapyInterval.getEnd())); dischargeTherapies.add(dischargeTherapy); } else { final Interval newInterval = new Interval(interval.getStart(), therapyInterval.getEnd()); linkedToTherapy.addInterval(TherapyIdUtils.createTherapyId(convertedTherapy.getCompositionUid(), convertedTherapy.getEhrOrderName()), newInterval); linkedToTherapy.removeInterval( TherapyIdUtils.createTherapyId(linkedToTherapy.getTherapy().getCompositionUid(), linkedToTherapy.getTherapy().getEhrOrderName()), interval); linkedToTherapy.setTherapy(convertedTherapy); } return true; } if (pair.getFirst() == TherapyLinkType.LINKED_TO_ADMISSION_THERAPY && alreadyHandled.contains(pair.getSecond())) { if (isDischargeTherapy(therapyInterval, centralCaseEnd, when)) { final TherapyDocumentationData newDischargeTherapy = createTherapyData(therapyToCompare, convertedTherapy, therapyInterval); dischargeTherapies.add(newDischargeTherapy); } else { final TherapyDocumentationData linkedToTherapy = pair.getSecond(); final Interval interval = linkedToTherapy.findIntervalForId( TherapyIdUtils.createTherapyId(linkedToTherapy.getTherapy().getCompositionUid(), linkedToTherapy.getTherapy().getEhrOrderName())); final Interval newInterval = new Interval(interval.getStart(), therapyInterval.getEnd()); linkedToTherapy.addInterval(TherapyIdUtils.createTherapyId(convertedTherapy.getCompositionUid(), convertedTherapy.getEhrOrderName()), newInterval); linkedToTherapy.removeInterval( TherapyIdUtils.createTherapyId(linkedToTherapy.getTherapy().getCompositionUid(), linkedToTherapy.getTherapy().getEhrOrderName()), interval); } return true; } final Pair<TherapySimilarityType, TherapyDocumentationData> similarityTypePair = getSimilarTherapyPair( admissionTherapies, therapies, therapyToCompare, medicationsDataMap); if (similarityTypePair.getFirst() == TherapySimilarityType.SIMILAR_TO_ADMISSION_THERAPY) { final TherapyDocumentationData similarTherapy = similarityTypePair.getSecond(); if (isDischargeTherapy(therapyInterval, centralCaseEnd, when)) { final TherapyDocumentationData newTherapy = createTherapyData(therapyToCompare, convertedTherapy, therapyInterval); dischargeTherapies.add(newTherapy); } else { similarTherapy.addInterval(TherapyIdUtils.createTherapyId(convertedTherapy.getCompositionUid(), convertedTherapy.getEhrOrderName()), therapyInterval); } return true; } if (similarityTypePair.getFirst() == TherapySimilarityType.SIMILAR) { final TherapyDocumentationData similarTherapy = similarityTypePair.getSecond(); if (isDischargeTherapy(therapyInterval, centralCaseEnd, when)) { if (therapies.contains(similarTherapy)) { therapies.remove(similarTherapy); } if (admissionTherapies.contains(similarTherapy)) { admissionTherapies.remove(similarTherapy); } final TherapyDocumentationData dischargeTherapy = createTherapyData(therapyToCompare, convertedTherapy, therapyInterval); for (final Pair<String, Interval> pair1 : similarTherapy.getIntervals()) { dischargeTherapy.addInterval(pair1.getFirst(), pair1.getSecond()); } dischargeTherapies.add(dischargeTherapy); } else { similarTherapy.addInterval(TherapyIdUtils.createTherapyId(convertedTherapy.getCompositionUid(), convertedTherapy.getEhrOrderName()), therapyInterval); similarTherapy.setTherapy(convertedTherapy); } return true; } return false; }
From source file:com.marand.thinkmed.medications.business.impl.DefaultMedicationsBo.java
License:Open Source License
private List<String> getTherapyDisplayValuesForDocumentation(final List<TherapyDocumentationData> therapyList, final Locale locale) { final List<String> strings = new ArrayList<>(); for (final TherapyDocumentationData therapy : therapyList) { therapyDisplayProvider.fillDisplayValues(therapy.getTherapy(), true, false, locale); String formatted = therapy.getTherapy().getFormattedTherapyDisplay(); for (final Pair<String, Interval> pair : therapy.getIntervals()) { final Interval interval = pair.getSecond(); final String endDate = Intervals.isEndInfinity(interval.getEnd()) ? "..." : DateTimeFormatters.shortDateTime(locale).print(interval.getEnd()); formatted = formatted + " " + DateTimeFormatters.shortDateTime(locale).print(interval.getStart()) + " – " + endDate + "<br>"; }/*from w w w . ja v a2 s . co m*/ strings.add(formatted); } return strings; }
From source file:com.marand.thinkmed.medications.dao.openehr.MedicationsOpenEhrDao.java
License:Open Source License
private void appendMedicationTimingIntervalCriterion(final StringBuilder stringBuilder, final Interval searchInterval) { //(medication_start <= start && (medication_end > start || medication_end == null)) || (medication_start >= start && medication_start < end) stringBuilder.append(" AND (") .append("i/activities[at0001]/description[at0002]/items[at0010]/items[at0012]/value <= ") .append(getAqlDateTimeQuoted(searchInterval.getStart())) .append("AND (i/activities[at0001]/description[at0002]/items[at0010]/items[at0013]/value > ") .append(getAqlDateTimeQuoted(searchInterval.getStart())) .append("OR NOT EXISTS i/activities[at0001]/description[at0002]/items[at0010]/items[at0013]/value)") .append("OR (i/activities[at0001]/description[at0002]/items[at0010]/items[at0012]/value >= ") .append(getAqlDateTimeQuoted(searchInterval.getStart())) .append(" AND i/activities[at0001]/description[at0002]/items[at0010]/items[at0012]/value < ") .append(getAqlDateTimeQuoted(searchInterval.getEnd())).append(')').append(')'); }
From source file:com.marand.thinkmed.medications.dao.openehr.MedicationsOpenEhrDao.java
License:Open Source License
private void addTherapyAdministrations(@Nonnull final String ehrId, @Nonnull final Map<String, List<MedicationAdministrationComposition>> administrationsMap, @Nonnull final Map<Pair<String, String>, String> locatableRefs, @Nonnull final List<String> compositionUids, final Interval searchInterval, final boolean clinicalInterventions) { final StringBuilder sb = new StringBuilder(); sb.append("SELECT c FROM EHR[ehr_id/value='").append(ehrId).append("']") .append(" CONTAINS Composition c[openEHR-EHR-COMPOSITION.encounter.v1]"); if (clinicalInterventions) { sb.append(" CONTAINS Action a[openEHR-EHR-ACTION.procedure-zn.v1]"); } else {//from w w w . ja v a 2s . c o m sb.append(" CONTAINS Action a[openEHR-EHR-ACTION.medication.v1]"); } sb.append(" WHERE c/name/value = 'Medication Administration'") .append(" AND a/instruction_details/instruction_id/id/value matches {" + getAqlQuoted(compositionUids) + '}'); if (searchInterval != null) { sb.append(" AND a/time >= ").append(getAqlDateTimeQuoted(searchInterval.getStart())) .append(" AND a/time <= ").append(getAqlDateTimeQuoted(searchInterval.getEnd())); } queryEhrContent(sb.toString(), (ResultRowProcessor<Object[], Void>) (resultRow, hasNext) -> { final MedicationAdministrationComposition administration = RmoToTdoConverter .convert(MedicationAdministrationComposition.class, (RmObject) resultRow[0]); final Action action; if (!administration.getMedicationDetail().getMedicationAction().isEmpty()) { action = administration.getMedicationDetail().getMedicationAction().get(0); } else if (!administration.getMedicationDetail().getClinicalIntervention().isEmpty()) { action = administration.getMedicationDetail().getClinicalIntervention().get(0); } else { throw new IllegalArgumentException( "MedicationAdministrationComposition must have MedicationActions or ClinicalIntervention"); } final LocatableRef locatableRef = action.getInstructionDetails().getInstructionId(); final Pair<String, String> instructionId = Pair.of(locatableRef.getId().getValue(), locatableRef.getPath()); if (locatableRefs.containsKey(instructionId)) { final String therapyId = locatableRefs.get(instructionId); if (!administrationsMap.containsKey(therapyId)) { administrationsMap.put(therapyId, new ArrayList<>()); } administrationsMap.get(therapyId).add(administration); } return null; }); }
From source file:com.marand.thinkmed.medications.dao.openehr.MedicationsOpenEhrDao.java
License:Open Source License
public Double getPatientLastReferenceWeight(final String patientId, final Interval searchInterval) { final String ehrId = currentSession().findEhr(patientId); if (!StringUtils.isEmpty(ehrId)) { currentSession().useEhr(ehrId);/* www. jav a2 s . co m*/ final StringBuilder sb = new StringBuilder(); sb.append("SELECT o/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value") .append(" FROM EHR[ehr_id/value='").append(ehrId).append("']") .append(" CONTAINS Observation o[openEHR-EHR-OBSERVATION.body_weight.v1]") .append(" WHERE o/name/value = 'Medication reference body weight'") .append(" AND o/data[at0002]/events[at0003]/time >= ") .append(getAqlDateTimeQuoted(searchInterval.getStart())) .append(" AND o/data[at0002]/events[at0003]/time <= ") .append(getAqlDateTimeQuoted(searchInterval.getEnd())) .append(" ORDER BY o/data[at0002]/events[at0003]/time DESC").append(" FETCH 1"); final List<Double> weights = query(sb.toString(), (resultRow, hasNext) -> { final DvQuantity weight = (DvQuantity) resultRow[0]; return weight.getMagnitude(); }); return weights.isEmpty() ? null : weights.get(0); } return null; }
From source file:com.marand.thinkmed.medications.dao.openehr.MedicationsOpenEhrDao.java
License:Open Source License
public List<MedicationOnDischargeComposition> findMedicationOnDischargeCompositions(final String patientId, final Interval interval) { final String ehrId = currentSession().findEhr(patientId); if (!StringUtils.isEmpty(ehrId)) { currentSession().useEhr(ehrId);//from w ww. j a v a 2 s. com final StringBuilder sb = new StringBuilder(); sb.append("SELECT c FROM EHR[ehr_id/value='").append(ehrId).append("']") .append(" CONTAINS Composition c[openEHR-EHR-COMPOSITION.encounter.v1]") .append(" WHERE c/name/value = 'Medication on discharge'") .append(" AND c/context/start_time > " + getAqlDateTimeQuoted(interval.getStart())) .append(" AND c/context/start_time < " + getAqlDateTimeQuoted(interval.getEnd())) .append(" ORDER BY c/context/start_time DESC"); return queryEhrContent(sb.toString(), MedicationOnDischargeComposition.class); } return Lists.newArrayList(); }
From source file:com.marand.thinkmed.medications.dao.openehr.MedicationsOpenEhrDao.java
License:Open Source License
private String getConsentFormQuery(final String ehrId, final Interval interval, final Integer fetchCount) { final StringBuilder query = new StringBuilder().append("SELECT c FROM EHR[ehr_id/value='").append(ehrId) .append("']").append(" CONTAINS Composition c[openEHR-EHR-COMPOSITION.encounter.v1]") .append(" WHERE c/name/value = 'Medication consent form'"); if (interval != null) { query.append(" AND c/context/start_time > " + getAqlDateTimeQuoted(interval.getStart())) .append(" AND c/context/start_time < " + getAqlDateTimeQuoted(interval.getEnd())); }/*from ww w .j a v a 2 s . co m*/ query.append(" ORDER BY c/context/start_time DESC"); if (fetchCount != null) { query.append(" FETCH " + fetchCount); } return query.toString(); }
From source file:com.marand.thinkmed.medications.dao.openehr.OpenEhrMedicationsDao.java
License:Open Source License
@Override public Double getPatientLastReferenceWeight(final Long patientId, final Interval searchInterval) { final String ehrId = currentSession().findEhr(patientId); if (!StringUtils.isEmpty(ehrId)) { currentSession().useEhr(ehrId);/*from w w w . j av a 2 s . c o m*/ final StringBuilder sb = new StringBuilder(); sb.append( "SELECT o/data[at0002]/events[at0003 and name/value='Any event']/data[at0001]/items[at0004]/value") .append(" FROM EHR[ehr_id/value='").append(ehrId).append("']") .append(" CONTAINS Observation o[openEHR-EHR-OBSERVATION.body_weight.v1]") .append(" WHERE o/name/value = 'Medication reference body weight'") .append(" AND o/data[at0002]/events[at0003]/time >= ") .append(getAqlDateTimeQuoted(searchInterval.getStart())) .append(" AND o/data[at0002]/events[at0003]/time <= ") .append(getAqlDateTimeQuoted(searchInterval.getEnd())) .append(" ORDER BY o/data[at0002]/events[at0003]/time DESC").append(" FETCH 1"); final List<Double> weights = query(sb.toString(), new ResultRowProcessor<Object[], Double>() { @Override public Double process(final Object[] resultRow, final boolean hasNext) throws ProcessingException { final DvQuantity weight = (DvQuantity) resultRow[0]; return weight.getMagnitude(); } }); return weights.isEmpty() ? null : weights.get(0); } return null; }