List of usage examples for org.joda.time Interval getEnd
public DateTime getEnd()
From source file:com.marand.thinkmed.medications.business.impl.DefaultMedicationsBo.java
License:Open Source License
private boolean isDischargeTherapy(final Interval therapyInterval, final DateTime centralCaseEnd, final DateTime when) { return Intervals.isEndInfinity(therapyInterval.getEnd()) && therapyInterval.overlaps(Intervals.wholeDay(when)) || !Intervals.isEndInfinity(therapyInterval.getEnd()) && therapyInterval.overlaps(Intervals.wholeDay(centralCaseEnd)); }
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 ava 2s. c o 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>"; }/* ww w . j av a2 s. co m*/ strings.add(formatted); } return strings; }
From source file:com.marand.thinkmed.medications.business.util.MedicationsEhrUtils.java
License:Open Source License
public static List<MedicationActionAction> getInstructionActions(final MedicationOrderComposition composition, final MedicationInstructionInstruction instruction, @Nullable final Interval interval) { final String instructionPath = TdoPathable.pathOfItem(composition, instruction).getCanonicalString(); final List<MedicationActionAction> actionsList = new ArrayList<>(); for (final MedicationActionAction action : composition.getMedicationDetail().getMedicationAction()) { if (action.getInstructionDetails().getInstructionId().getPath().equals(instructionPath)) { if (interval == null || DataValueUtils.getDateTime(action.getTime()).isBefore(interval.getEnd())) { actionsList.add(action); }//from w w w.j a v a 2 s . c o m } } Collections.sort(actionsList, (action1, action2) -> DataValueUtils.getDateTime(action1.getTime()) .compareTo(DataValueUtils.getDateTime(action2.getTime()))); return actionsList; }
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 ww w .ja v a 2s . c om*/ 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);//from ww w .j av a2 s .c o 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);/* w ww. java2 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 w w w.j av 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 a v a 2 s .com 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; }