Skip to content

Commit

Permalink
EA-212: Add Support for Fetching first and latest encounter from Inpa…
Browse files Browse the repository at this point in the history
…tient Admission and Inpatient Request (#256)
  • Loading branch information
mogoodrich authored Dec 4, 2024
1 parent 71cec6f commit 7cabb05
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
* Represents a hospital Admission
Expand Down Expand Up @@ -103,4 +104,18 @@ private Comparator<Encounter> getEncounterComparator() {
.thenComparing(Encounter::getDateCreated)
.thenComparing(Encounter::getEncounterId);
}

public List<Encounter> getAllEncounters() {
return Collections.unmodifiableList(visit.getEncounters().stream().filter(e -> !e.getVoided()).sorted(getEncounterComparator()).collect(Collectors.toList()));
}

public Encounter getFirstEncounter() {
List<Encounter> encounters = getAllEncounters();
return encounters.isEmpty() ? null : encounters.get(0);
}

public Encounter getLatestEncounter() {
List<Encounter> encounters = getAllEncounters();
return encounters.isEmpty() ? null : encounters.get(encounters.size() - 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import org.openmrs.Visit;
import org.openmrs.module.emrapi.disposition.DispositionType;

import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
* Represents and Admission, Discharge, or Transfer request
Expand All @@ -23,4 +27,24 @@ public class InpatientRequest {
private Obs dispositionObsGroup;
private Concept disposition;
private Location dispositionLocation;

public List<Encounter> getAllEncounters() {
return Collections.unmodifiableList(visit.getEncounters().stream().filter(e -> !e.getVoided()).sorted(getEncounterComparator()).collect(Collectors.toList()));
}

public Encounter getFirstEncounter() {
List<Encounter> encounters = getAllEncounters();
return encounters.isEmpty() ? null : encounters.get(0);
}

public Encounter getLatestEncounter() {
List<Encounter> encounters = getAllEncounters();
return encounters.isEmpty() ? null : encounters.get(encounters.size() - 1);
}

private Comparator<Encounter> getEncounterComparator() {
return Comparator.comparing(Encounter::getEncounterDatetime)
.thenComparing(Encounter::getDateCreated)
.thenComparing(Encounter::getEncounterId);
}
}

0 comments on commit 7cabb05

Please sign in to comment.