Skip to content

Commit

Permalink
Merge pull request #454 from Health-Education-England/feat/generateNtn
Browse files Browse the repository at this point in the history
fix(ntn): curricula date filtering
  • Loading branch information
Judge40 authored Jun 21, 2024
2 parents 34d6658 + b7bf7da commit 26227ac
Show file tree
Hide file tree
Showing 3 changed files with 487 additions and 98 deletions.
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

0 comments on commit 26227ac

Please sign in to comment.