Skip to content

Commit

Permalink
feat: generate NTN when PMs are created/updated
Browse files Browse the repository at this point in the history
Generate and store the NTN when a programme membership is created or
updated.
The NTN will still be regenerated when the profile is retrieved, until a
scheduled job is put in place to allow starting/ending curricula to
trigger an update to the stored NTN value.

TIS21-6175
TIS21-6182
  • Loading branch information
Judge40 committed Jun 24, 2024
1 parent 5d199f7 commit 2ae951c
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 161 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.1"
version = "1.4.0"

configurations {
compileOnly {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public void populateNtns(TraineeProfile traineeProfile) {
* @param personalDetails The personal details to use for NTN generation.
* @param programmeMembership The programme membership to generate the NTN for.
*/
private void populateNtn(PersonalDetails personalDetails,
public void populateNtn(PersonalDetails personalDetails,
ProgrammeMembership programmeMembership) {
log.info("Populating NTN for programme membership '{}'.", programmeMembership.getTisId());

if (isExcluded(programmeMembership)) {
if (isExcluded(personalDetails) || isExcluded(programmeMembership)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ public class ProgrammeMembershipService {
"Vascular surgery");

private final TraineeProfileRepository repository;
private final NtnGenerator ntnGenerator;
private final ProgrammeMembershipMapper mapper;
private final CachingDelegate cachingDelegate;

ProgrammeMembershipService(TraineeProfileRepository repository,
ProgrammeMembershipMapper mapper, CachingDelegate cachingDelegate) {
ProgrammeMembershipService(TraineeProfileRepository repository, NtnGenerator ntnGenerator,
ProgrammeMembershipMapper mapper, CachingDelegate cachingDelegate) {
this.repository = repository;
this.ntnGenerator = ntnGenerator;
this.mapper = mapper;
this.cachingDelegate = cachingDelegate;
}
Expand All @@ -105,6 +107,8 @@ public Optional<ProgrammeMembership> updateProgrammeMembershipForTrainee(String
return Optional.empty();
}

ntnGenerator.populateNtn(traineeProfile.getPersonalDetails(), programmeMembership);

List<ProgrammeMembership> existingProgrammeMemberships = traineeProfile
.getProgrammeMemberships();

Expand Down Expand Up @@ -181,7 +185,7 @@ public boolean deleteProgrammeMembershipsForTrainee(String traineeTisId) {
* @return True, or False if a trainee with the ID was not found.
*/
public boolean deleteProgrammeMembershipForTrainee(String traineeTisId,
String programmeMembershipId) {
String programmeMembershipId) {
TraineeProfile traineeProfile = repository.findByTraineeTisId(traineeTisId);

if (traineeProfile == null) {
Expand All @@ -206,7 +210,7 @@ public boolean deleteProgrammeMembershipForTrainee(String traineeTisId,
*
* @param programmeMembershipId The ID of the programme membership for signing COJ.
* @return The updated programme membership or empty if the programme membership with the ID was
* not found.
* not found.
*/
public Optional<ProgrammeMembership> signProgrammeMembershipCoj(
String traineeTisId, String programmeMembershipId) {
Expand Down Expand Up @@ -394,7 +398,7 @@ public TraineeProfile getProfileWithTssProgrammeMemberships(String traineeTisId)
* @param programmeMemberships The list of programme memberships.
* @param programmeMembershipId The programme membership ID.
* @return The programme membership, or null if it is not a candidate because it does not exist,
* it is non-medical, or is of the wrong type.
* it is non-medical, or is of the wrong type.
*/
private ProgrammeMembership getCandidateProgrammeMembership(
List<ProgrammeMembership> programmeMemberships, String programmeMembershipId) {
Expand Down Expand Up @@ -457,8 +461,8 @@ private List<ProgrammeMembership> getPmsMedicalCurricula(List<ProgrammeMembershi
}

/**
* Remove non-TSS curricula from a list of programme memberships. Returned programme
* memberships will each contain at least one TSS curriculum.
* Remove non-TSS curricula from a list of programme memberships. Returned programme memberships
* will each contain at least one TSS curriculum.
*
* @param pms The list of programme memberships.
* @return The filtered list of programme memberships containing TSS-applicable curricula.
Expand Down Expand Up @@ -501,7 +505,7 @@ private List<ProgrammeMembership> getPmsTssCurricula(List<ProgrammeMembership> p
* @return The programme memberships that comprise intra-deanery transfers or rotas.
*/
private List<ProgrammeMembership> getIntraOrRotaPms(ProgrammeMembership anchorPm,
List<ProgrammeMembership> candidatePms) {
List<ProgrammeMembership> candidatePms) {
List<ProgrammeMembership> newStarterPmsWithSameDeaneryStartedBeforeAnchor =
candidatePms.stream()
.filter(pm -> {
Expand Down Expand Up @@ -548,7 +552,7 @@ private List<ProgrammeMembership> getIntraOrRotaPms(ProgrammeMembership anchorPm
* @return The filtered list.
*/
private List<ProgrammeMembership> getRecentPrecedingPms(ProgrammeMembership anchorPm,
List<ProgrammeMembership> candidatePms) {
List<ProgrammeMembership> candidatePms) {
return
candidatePms.stream()
.filter(pm -> {
Expand Down
Loading

0 comments on commit 2ae951c

Please sign in to comment.