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: temporary patch for CDC delay in updating submitted status #395

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import uk.nhs.hee.tis.revalidation.entity.RecommendationType;
import uk.nhs.hee.tis.revalidation.exception.RecommendationException;
import uk.nhs.hee.tis.revalidation.repository.DoctorsForDBRepository;
import uk.nhs.hee.tis.revalidation.repository.RecommendationElasticSearchRepository;
import uk.nhs.hee.tis.revalidation.repository.RecommendationRepository;

@Slf4j
Expand Down Expand Up @@ -90,6 +91,9 @@ public class RecommendationServiceImpl implements RecommendationService {
@Autowired
private RabbitTemplate rabbitTemplate;

@Autowired
private RecommendationElasticSearchRepository recommendationElasticSearchRepository;

@Value("${app.rabbit.reval.exchange}")
private String revalExchange;

Expand Down Expand Up @@ -261,6 +265,7 @@ public boolean submitRecommendation(String recommendationId, String gmcNumber,
doctor.setDoctorStatus(getRecommendationStatusForTrainee(gmcNumber)
);
doctorsForDBRepository.save(doctor);
setElasticsearchStatusesForSubmittedRecommendation(doctor.getGmcReferenceNumber());
return true;
} else {
final var responseCode = GmcResponseCode.fromCode(returnCode);
Expand Down Expand Up @@ -343,17 +348,17 @@ public List<RecommendationStatusCheckDto> getRecommendationStatusCheckDtos() {
List<RecommendationStatusCheckDto> recommendationStatusCheckDtos = new ArrayList<>();
recommendationRepository
.findAllByRecommendationStatus(RecommendationStatus.SUBMITTED_TO_GMC).forEach(rec -> {
final var doctorsForDB = doctorsForDBRepository.findById(rec.getGmcNumber());
if (doctorsForDB.isPresent() && rec.getGmcRevalidationId() != null) {
final var recommendationStatusDto = RecommendationStatusCheckDto.builder()
.designatedBodyId(doctorsForDB.get().getDesignatedBodyCode())
.gmcReferenceNumber(rec.getGmcNumber())
.gmcRecommendationId(rec.getGmcRevalidationId())
.recommendationId(rec.getId())
.build();
recommendationStatusCheckDtos.add(recommendationStatusDto);
}
});
final var doctorsForDB = doctorsForDBRepository.findById(rec.getGmcNumber());
if (doctorsForDB.isPresent() && rec.getGmcRevalidationId() != null) {
final var recommendationStatusDto = RecommendationStatusCheckDto.builder()
.designatedBodyId(doctorsForDB.get().getDesignatedBodyCode())
.gmcReferenceNumber(rec.getGmcNumber())
.gmcRecommendationId(rec.getGmcRevalidationId())
.recommendationId(rec.getId())
.build();
recommendationStatusCheckDtos.add(recommendationStatusDto);
}
});
return recommendationStatusCheckDtos;
}

Expand Down Expand Up @@ -440,9 +445,9 @@ private void isSaveRecommendationPermitted(final String gmcNumber,
recommendationRepository.findByGmcNumber(gmcNumber).stream()
.filter(inProgressFilter)
.findFirst().ifPresent(r -> {
throw new RecommendationException(
"Trainee already has a recommendation in draft or waiting for approval from GMC.");
});
throw new RecommendationException(
"Trainee already has a recommendation in draft or waiting for approval from GMC.");
});
}

private TraineeRecommendationRecordDto buildTraineeRecommendationRecordDto(String gmcNumber,
Expand Down Expand Up @@ -477,6 +482,17 @@ private boolean checkIfPastCompletedRecommendation(Recommendation recommendation
return approved && underNotice && notRecent;
}

// TODO: this is a bit of a hack, need a better solution for mitigating CDC delay
private void setElasticsearchStatusesForSubmittedRecommendation(String gmcNumber) {
var document = recommendationElasticSearchRepository
.findByGmcReferenceNumber(gmcNumber).get(0);

document.setGmcStatus(UNDER_REVIEW.getOutcome());
document.setTisStatus(SUBMITTED_TO_GMC.toString());

recommendationElasticSearchRepository.save(document);
}

/**
* This predicate evaluates whether a recommendation is "In Progress". This includes those with a
* `COMPLETED` status of {@link RecommendationStatus} and excludes a {@link Recommendation} with
Expand Down