Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ntn): curricula date filtering #454

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "uk.nhs.hee.trainee.details"
version = "1.3.0"
version = "1.3.1"

configurations {
compileOnly {
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/uk/nhs/hee/trainee/details/service/NtnGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ private String getSouthWestParentOrganization(ProgrammeMembership programmeMembe
*/
private String getSpecialtyConcat(ProgrammeMembership programmeMembership) {
log.info("Calculating specialty concat.");
List<Curriculum> curricula = programmeMembership.getCurricula();
List<Curriculum> sortedCurricula = filterAndSortCurricula(curricula);
List<Curriculum> sortedCurricula = filterAndSortCurricula(programmeMembership);

StringBuilder sb = new StringBuilder();

Expand Down Expand Up @@ -199,8 +198,7 @@ private String getSuffix(ProgrammeMembership programmeMembership) {
case "CCT" -> "C";
case "CESR" -> "CP";
default -> {
List<Curriculum> curricula = programmeMembership.getCurricula();
List<Curriculum> sortedCurricula = filterAndSortCurricula(curricula);
List<Curriculum> sortedCurricula = filterAndSortCurricula(programmeMembership);
String firstSpecialtyCode = sortedCurricula.get(0).getCurriculumSpecialtyCode();
log.info("Using specialty code '{}' to calculate suffix.", trainingPathway);

Expand All @@ -213,19 +211,21 @@ private String getSuffix(ProgrammeMembership programmeMembership) {
}

/**
* Filter the given curricula to only those that are current and sort them alphanumerically.
* Filter a programme membership's curricula and sort them alphanumerically.
*
* @param curricula The curricula to filter and sort.
* @return The current curricula, sorted alphanumerically by subtype and code.
* @param programmeMembership The programme membership to filter and sort the curricula of.
* @return The NTN valid curricula for this PM, sorted alphanumerically by subtype and code.
*/
private List<Curriculum> filterAndSortCurricula(List<Curriculum> curricula) {
private List<Curriculum> filterAndSortCurricula(ProgrammeMembership programmeMembership) {
LocalDate startDate = programmeMembership.getStartDate();
LocalDate now = LocalDate.now();
LocalDate filterDate = startDate.isAfter(now) ? startDate : now;

return curricula.stream()
return programmeMembership.getCurricula().stream()
.filter(c ->
c.getCurriculumSpecialtyCode() != null && !c.getCurriculumSpecialtyCode().isBlank())
.filter(c -> c.getCurriculumStartDate().isBefore(now))
.filter(c -> c.getCurriculumEndDate().isAfter(now))
.filter(c -> !c.getCurriculumStartDate().isAfter(filterDate))
.filter(c -> !c.getCurriculumEndDate().isBefore(filterDate))
.sorted(Comparator
.comparing(Curriculum::getCurriculumSubType)
.reversed()
Expand Down Expand Up @@ -287,7 +287,7 @@ private boolean isExcluded(ProgrammeMembership programmeMembership) {
return true;
}

List<Curriculum> validCurricula = filterAndSortCurricula(programmeMembership.getCurricula());
List<Curriculum> validCurricula = filterAndSortCurricula(programmeMembership);
if (validCurricula.isEmpty()) {
log.info("Skipping NTN population as there are no valid curricula.");
return true;
Expand Down
Loading
Loading